VapourSynth-llvmexpr
Loading...
Searching...
No Matches
MathFunctionImpl< VectorWidth, MathOp::Sin > Struct Template Reference

#include <llvmexpr/codegen/llvm/Math.hpp>

Static Public Member Functions

static llvm::Function * generate (MathFunctionGenerator< VectorWidth > *gen)

Detailed Description

template<int VectorWidth>
struct MathFunctionImpl< VectorWidth, MathOp::Sin >

Definition at line 409 of file Math.hpp.

Member Function Documentation

◆ generate()

template<int VectorWidth>
llvm::Function * MathFunctionImpl< VectorWidth, MathOp::Sin >::generate ( MathFunctionGenerator< VectorWidth > * gen)
inlinestatic

Definition at line 410 of file Math.hpp.

410 {
411 constexpr auto OP_INFO = get_math_op_info(MathOp::Sin);
412 // https://github.com/vapoursynth/vapoursynth/blob/2a3d3657320ca505c784b98f10e7cd9649d6169a/src/core/expr/jitcompiler_x86.cpp#L813
413 return gen->createFunction(
414 OP_INFO.name, OP_INFO.arity,
416 auto* x = args[0];
417 auto* float_ty = gen->getFloatType();
418 auto* int32_ty = gen->getInt32Type();
419 auto* float_invpi =
420 gen->getConstant(std::numbers::inv_pi_v<float>);
421 // NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers)
422 auto* float_pi1 = gen->getConstant(3.140625F);
423 auto* float_pi2 = gen->getConstant(0.0009670257568359375F);
424 auto* float_pi3 = gen->getConstant(1.984187252998352e-07F);
425 auto* float_pi4 = gen->getConstant(1.273533813134432e-11F);
426 auto* float_sin_c3 = gen->getConstant(-0.1666666567325592F);
427 auto* float_sin_c5 = gen->getConstant(0.00833307858556509F);
428 auto* float_sin_c7 = gen->getConstant(-0.00019807418575510383F);
429 auto* float_sin_c9 = gen->getConstant(2.6019030363451748e-06F);
430 auto* signmask = gen->getInt32Constant(0x80000000);
431 // NOLINTEND(cppcoreguidelines-avoid-magic-numbers)
432 llvm::Value* sign = gen->builder.CreateBitCast(x, int32_ty);
433 sign = gen->builder.CreateAnd(sign, signmask);
434 llvm::Value* t1 =
435 gen->createIntrinsicCall(llvm::Intrinsic::fabs, {x});
436 llvm::Value* t2 = gen->builder.CreateFMul(t1, float_invpi);
438 gen->createIntrinsicCall(llvm::Intrinsic::nearbyint, {t2});
440 gen->builder.CreateFPToSI(t2_rounded, int32_ty);
441 llvm::Value* t4 = gen->builder.CreateShl(
442 t2i, 31); // NOLINT(cppcoreguidelines-avoid-magic-numbers)
443 sign = gen->builder.CreateXor(sign, t4);
444 t2 = gen->builder.CreateSIToFP(t2i, float_ty);
445 t1 = gen->createIntrinsicCall(
447 {t2, gen->builder.CreateFNeg(float_pi1), t1});
448 t1 = gen->createIntrinsicCall(
450 {t2, gen->builder.CreateFNeg(float_pi2), t1});
451 t1 = gen->createIntrinsicCall(
453 {t2, gen->builder.CreateFNeg(float_pi3), t1});
454 t1 = gen->createIntrinsicCall(
456 {t2, gen->builder.CreateFNeg(float_pi4), t1});
457 t2 = gen->builder.CreateFMul(t1, t1);
458 llvm::Value* t3 = gen->createIntrinsicCall(
460 t3 = gen->createIntrinsicCall(llvm::Intrinsic::fma,
461 {t3, t2, float_sin_c5});
462 t3 = gen->createIntrinsicCall(llvm::Intrinsic::fma,
463 {t3, t2, float_sin_c3});
464 t3 = gen->builder.CreateFMul(t3, t2);
465 t3 = gen->builder.CreateFMul(t3, t1);
466 t1 = gen->builder.CreateFAdd(t1, t3);
468 gen->builder.CreateBitCast(t1, int32_ty);
470 gen->builder.CreateXor(sign, t1_as_int);
471 return gen->builder.CreateBitCast(result_as_int, float_ty);
472 });
473 }
constexpr MathopInfo get_math_op_info(MathOp op)
Definition Math.hpp:86

References get_math_op_info(), and Sin.


The documentation for this struct was generated from the following file: