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

Definition at line 643 of file Math.hpp.

Member Function Documentation

◆ generate()

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

Definition at line 644 of file Math.hpp.

644 {
645 constexpr auto OP_INFO = get_math_op_info(MathOp::Atan2);
646 return gen->createFunction(
647 OP_INFO.name, OP_INFO.arity,
649 auto* var_y = args[0];
650 auto* var_x = args[1];
651 auto* atan_func =
652 MathFunctionImpl<VectorWidth, MathOp::Atan>::generate(gen);
653 auto* zero = gen->getConstant(0.0F);
654 auto* pi = gen->getConstant(std::numbers::pi_v<float>);
655 auto* pi_div_2 = gen->getConstant(
656 1.5707963267948966F); // NOLINT(cppcoreguidelines-avoid-magic-numbers)
657 auto* y_div_x = gen->builder.CreateFDiv(var_y, var_x);
658 auto* atan_y_div_x =
659 gen->builder.CreateCall(atan_func, {y_div_x});
660 auto* res_x_gt_0 = atan_y_div_x;
661 auto* signed_pi = gen->createIntrinsicCall(
663 auto* res_x_lt_0 =
664 gen->builder.CreateFAdd(atan_y_div_x, signed_pi);
665 auto* res_x_eq_0 = gen->createIntrinsicCall(
667 auto* x_gt_0 = gen->builder.CreateFCmpOGT(var_x, zero);
668 auto* x_lt_0 = gen->builder.CreateFCmpOLT(var_x, zero);
669 auto* result =
670 gen->builder.CreateSelect(x_gt_0, res_x_gt_0, res_x_lt_0);
671 result = gen->builder.CreateSelect(
673 gen->builder.CreateSelect(x_gt_0, res_x_gt_0, res_x_eq_0));
674 auto* x_is_zero = gen->builder.CreateFCmpOEQ(var_x, zero);
675 auto* y_is_zero = gen->builder.CreateFCmpOEQ(var_y, zero);
676 auto* both_zero = gen->builder.CreateAnd(x_is_zero, y_is_zero);
677 result = gen->builder.CreateSelect(both_zero, zero, result);
678 return result;
679 });
680 }
constexpr MathopInfo get_math_op_info(MathOp op)
Definition Math.hpp:86

References Atan2, and get_math_op_info().


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