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

Definition at line 683 of file Math.hpp.

Member Function Documentation

◆ generate()

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

Definition at line 684 of file Math.hpp.

684 {
685 constexpr auto OP_INFO = get_math_op_info(MathOp::Acos);
686 // https://forwardscattering.org/post/66
687 // TODO: Switch to another implementation that doesn't has licensing issues.
688 return gen->createFunction(
689 OP_INFO.name, OP_INFO.arity,
691 auto* x = args[0];
692 auto* pi = gen->getConstant(std::numbers::pi_v<float>);
693 auto* ax = gen->createIntrinsicCall(llvm::Intrinsic::fabs, {x});
694 // NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers)
695 auto* term1_mul = gen->getConstant(-0.124605335F);
696 auto* term1_add = gen->getConstant(0.1570634F);
697 auto* term1 = gen->createIntrinsicCall(
699
700 auto* term2_sub = gen->getConstant(0.99418175F);
701 auto* term2 = gen->builder.CreateFSub(term2_sub, ax);
702
703 auto* poly_part = gen->builder.CreateFMul(term1, term2);
704
705 auto* two = gen->getConstant(2.0F);
706 auto* neg_two = gen->getConstant(-2.0F);
707 // NOLINTEND(cppcoreguidelines-avoid-magic-numbers)
708 auto* sqrt_arg = gen->createIntrinsicCall(llvm::Intrinsic::fma,
709 {ax, neg_two, two});
710 auto* sqrt_part =
711 gen->createIntrinsicCall(llvm::Intrinsic::sqrt, {sqrt_arg});
712
713 auto* res_pos = gen->builder.CreateFAdd(poly_part, sqrt_part);
714
715 auto* zero = gen->getConstant(0.0F);
716 auto* is_neg = gen->builder.CreateFCmpOLT(x, zero);
717
718 auto* res_neg = gen->builder.CreateFSub(pi, res_pos);
719
720 return gen->builder.CreateSelect(is_neg, res_neg, res_pos);
721 });
722 }
constexpr MathopInfo get_math_op_info(MathOp op)
Definition Math.hpp:86

References Acos, and get_math_op_info().


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