VapourSynth-llvmexpr
Loading...
Searching...
No Matches
MathFunctionImpl< VectorWidth, MathOp::Cos > 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::Cos >

Definition at line 476 of file Math.hpp.

Member Function Documentation

◆ generate()

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

Definition at line 477 of file Math.hpp.

477 {
478 constexpr auto OP_INFO = get_math_op_info(MathOp::Cos);
479 // https://github.com/vapoursynth/vapoursynth/blob/2a3d3657320ca505c784b98f10e7cd9649d6169a/src/core/expr/jitcompiler_x86.cpp#L813
480 return gen->createFunction(
481 OP_INFO.name, OP_INFO.arity,
483 auto* x = args[0];
484 auto* float_ty = gen->getFloatType();
485 auto* int32_ty = gen->getInt32Type();
486 auto* float_invpi =
487 gen->getConstant(std::numbers::inv_pi_v<float>);
488 // NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers)
489 auto* float_pi1 = gen->getConstant(3.140625F);
490 auto* float_pi2 = gen->getConstant(0.0009670257568359375F);
491 auto* float_pi3 = gen->getConstant(1.984187252998352e-07F);
492 auto* float_pi4 = gen->getConstant(1.273533813134432e-11F);
493 auto* float_cos_c2 = gen->getConstant(-0.4999999701976776F);
494 auto* float_cos_c4 = gen->getConstant(0.04166652262210846F);
495 auto* float_cos_c6 = gen->getConstant(-0.001388676579343155F);
496 auto* float_cos_c8 = gen->getConstant(2.4390448881604243e-05F);
497 // NOLINTEND(cppcoreguidelines-avoid-magic-numbers)
498 auto* one_float = gen->getConstant(1.0F);
499 llvm::Value* sign = gen->getInt32Constant(0);
500 llvm::Value* t1 =
501 gen->createIntrinsicCall(llvm::Intrinsic::fabs, {x});
502 llvm::Value* t2 = gen->builder.CreateFMul(t1, float_invpi);
504 gen->createIntrinsicCall(llvm::Intrinsic::nearbyint, {t2});
506 gen->builder.CreateFPToSI(t2_rounded, int32_ty);
507 llvm::Value* t4 = gen->builder.CreateShl(
508 t2i, 31); // NOLINT(cppcoreguidelines-avoid-magic-numbers)
509 sign = gen->builder.CreateXor(sign, t4);
510 t2 = gen->builder.CreateSIToFP(t2i, float_ty);
511 t1 = gen->createIntrinsicCall(
513 {t2, gen->builder.CreateFNeg(float_pi1), t1});
514 t1 = gen->createIntrinsicCall(
516 {t2, gen->builder.CreateFNeg(float_pi2), t1});
517 t1 = gen->createIntrinsicCall(
519 {t2, gen->builder.CreateFNeg(float_pi3), t1});
520 t1 = gen->createIntrinsicCall(
522 {t2, gen->builder.CreateFNeg(float_pi4), t1});
523 t2 = gen->builder.CreateFMul(t1, t1);
524 llvm::Value* t3 = gen->createIntrinsicCall(
526 t3 = gen->createIntrinsicCall(llvm::Intrinsic::fma,
527 {t3, t2, float_cos_c4});
528 t3 = gen->createIntrinsicCall(llvm::Intrinsic::fma,
529 {t3, t2, float_cos_c2});
530 t1 = gen->createIntrinsicCall(llvm::Intrinsic::fma,
531 {t3, t2, one_float});
533 gen->builder.CreateBitCast(t1, int32_ty);
535 gen->builder.CreateXor(sign, t1_as_int);
536 return gen->builder.CreateBitCast(result_as_int, float_ty);
537 });
538 }
constexpr MathopInfo get_math_op_info(MathOp op)
Definition Math.hpp:86

References Cos, and get_math_op_info().


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