Basic math functions¶
abs
function¶
template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)>
T1 abs(const T1 &x)
Returns the absolute value of x.
Source code
template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)>
KFR_INTRINSIC T1 abs(const T1& x)
{
return intrinsics::abs(x);
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/abs.hpp#L39
template <typename E1,
KFR_ENABLE_IF(is_input_expression<E1>)>
internal::expression_function<fn::abs, E1> abs(E1 &&x)
Returns template expression that returns the absolute value of x.
Source code
template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>)>
KFR_INTRINSIC internal::expression_function<fn::abs, E1> abs(E1&& x)
{
return { fn::abs(), std::forward<E1>(x) };
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/abs.hpp#L48
absmax
function¶
template <typename T1, typename T2,
KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = common_type<T1, T2>>
Tout absmax(const T1 &x, const T2 &y)
Returns the greater in magnitude of two values.
Source code
template <typename T1, typename T2, KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = common_type<T1, T2>>
KFR_INTRINSIC Tout absmax(const T1& x, const T2& y)
{
return intrinsics::absmax(x, y);
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/min_max.hpp#L97
template <typename E1, typename E2,
KFR_ENABLE_IF(is_input_expressions<E1, E2>)>
internal::expression_function<fn::absmax, E1, E2>
absmax(E1 &&x, E2 &&y)
Returns the greater in magnitude of two values. Accepts and returns expressions.
Source code
template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>)>
KFR_INTRINSIC internal::expression_function<fn::absmax, E1, E2> absmax(E1&& x, E2&& y)
{
return { fn::absmax(), std::forward<E1>(x), std::forward<E2>(y) };
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/min_max.hpp#L106
absmin
function¶
template <typename T1, typename T2,
KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = common_type<T1, T2>>
Tout absmin(const T1 &x, const T2 &y)
Returns the smaller in magnitude of two values.
Source code
template <typename T1, typename T2, KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = common_type<T1, T2>>
KFR_INTRINSIC Tout absmin(const T1& x, const T2& y)
{
return intrinsics::absmin(x, y);
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/min_max.hpp#L78
template <typename E1, typename E2,
KFR_ENABLE_IF(is_input_expressions<E1, E2>)>
internal::expression_function<fn::absmin, E1, E2>
absmin(E1 &&x, E2 &&y)
Returns the smaller in magnitude of two values. Accepts and returns expressions.
Source code
template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>)>
KFR_INTRINSIC internal::expression_function<fn::absmin, E1, E2> absmin(E1&& x, E2&& y)
{
return { fn::absmin(), std::forward<E1>(x), std::forward<E2>(y) };
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/min_max.hpp#L87
add
function¶
template <typename T1, typename T2, typename... Ts,
KFR_ENABLE_IF(is_numeric_args<T1, T2, Ts...>)>
constexpr common_type<T1, T2, Ts...>
add(const T1 &x, const T2 &y, const Ts &...rest)
Returns sum of all the arguments passed to a function.
Source code
template <typename T1, typename T2, typename... Ts, KFR_ENABLE_IF(is_numeric_args<T1, T2, Ts...>)>
constexpr KFR_INTRINSIC common_type<T1, T2, Ts...> add(const T1& x, const T2& y, const Ts&... rest)
{
return x + add(y, rest...);
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L296
template <typename... E,
KFR_ENABLE_IF((is_input_expressions<E...>)&&true)>
internal::expression_function<fn::add, E...> add(E &&...x)
Returns template expression that returns sum of all the arguments passed to a function.
Source code
template <typename... E, KFR_ENABLE_IF((is_input_expressions<E...>)&&true)>
KFR_INTRINSIC internal::expression_function<fn::add, E...> add(E&&... x)
{
return { fn::add(), std::forward<E>(x)... };
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L311
bitwiseand
function¶
template <typename T1, typename T2>
common_type<T1, T2> bitwiseand(const T1 &x, const T2 &y)
Bitwise And
Source code
template <typename T1, typename T2>
KFR_INTRINSIC common_type<T1, T2> bitwiseand(const T1& x, const T2& y)
{
return x & y;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L204
bitwiseandnot
function¶
template <typename T1, typename T2>
common_type<T1, T2> bitwiseandnot(const T1 &x, const T2 &y)
Bitwise And-Not
Source code
template <typename T1, typename T2>
KFR_INTRINSIC common_type<T1, T2> bitwiseandnot(const T1& x, const T2& y)
{
return x & ~y;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L217
bitwisenot
function¶
template <typename T1> T1 bitwisenot(const T1 &x)
Bitwise Not
Source code
template <typename T1>
KFR_INTRINSIC T1 bitwisenot(const T1& x)
{
return ~x;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L196
bitwiseor
function¶
template <typename T1, typename T2>
common_type<T1, T2> bitwiseor(const T1 &x, const T2 &y)
Bitwise Or
Source code
template <typename T1, typename T2>
KFR_INTRINSIC common_type<T1, T2> bitwiseor(const T1& x, const T2& y)
{
return x | y;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L230
bitwisexor
function¶
template <typename T1, typename T2>
common_type<T1, T2> bitwisexor(const T1 &x, const T2 &y)
Bitwise Xor (Exclusive Or)
Source code
template <typename T1, typename T2>
KFR_INTRINSIC common_type<T1, T2> bitwisexor(const T1& x, const T2& y)
{
return x ^ y;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L243
clamp
function¶
template <typename T1, typename T2, typename T3,
KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>),
typename Tout = common_type<T1, T2, T3>>
Tout clamp(const T1 &x, const T2 &lo, const T3 &hi)
Returns the first argument clamped to a range [lo, hi]
Source code
template <typename T1, typename T2, typename T3, KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>),
typename Tout = common_type<T1, T2, T3>>
KFR_INTRINSIC Tout clamp(const T1& x, const T2& lo, const T3& hi)
{
return intrinsics::clamp(static_cast<Tout>(x), static_cast<Tout>(lo), static_cast<Tout>(hi));
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/clamp.hpp#L38
template <typename E1, typename E2, typename E3,
KFR_ENABLE_IF(is_input_expressions<E1, E2, E3>)>
internal::expression_function<fn::clamp, E1, E2, E3>
clamp(E1 &&x, E2 &&lo, E3 &&hi)
Creates an expression that returns the first argument clamped to a range [lo, hi]
Source code
template <typename E1, typename E2, typename E3, KFR_ENABLE_IF(is_input_expressions<E1, E2, E3>)>
KFR_INTRINSIC internal::expression_function<fn::clamp, E1, E2, E3> clamp(E1&& x, E2&& lo, E3&& hi)
{
return { fn::clamp(), std::forward<E1>(x), std::forward<E2>(lo), std::forward<E3>(hi) };
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/clamp.hpp#L45
template <typename T1, typename T2,
KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = common_type<T1, T2>>
Tout clamp(const T1 &x, const T2 &hi)
Returns the first argument clamped to a range [0, hi]
Source code
template <typename T1, typename T2, KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = common_type<T1, T2>>
KFR_INTRINSIC Tout clamp(const T1& x, const T2& hi)
{
return intrinsics::clamp(static_cast<Tout>(x), static_cast<Tout>(hi));
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/clamp.hpp#L53
template <typename E1, typename E2,
KFR_ENABLE_IF(is_input_expressions<E1, E2>)>
internal::expression_function<fn::clamp, E1, E2>
clamp(E1 &&x, E2 &&hi)
Creates an expression that returns the first argument clamped to a range [0, hi]
Source code
template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>)>
KFR_INTRINSIC internal::expression_function<fn::clamp, E1, E2> clamp(E1&& x, E2&& hi)
{
return { fn::clamp(), std::forward<E1>(x), std::forward<E2>(hi) };
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/clamp.hpp#L60
cub
function¶
template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)>
constexpr inline T1 cub(const T1 &x)
Returns cube of x.
Source code
template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)>
constexpr inline T1 cub(const T1& x)
{
return sqr(x) * x;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L388
template <typename E1,
KFR_ENABLE_IF(is_input_expression<E1>)>
internal::expression_function<fn::cub, E1> cub(E1 &&x)
Returns template expression that returns cube of x.
Source code
template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>)>
KFR_INTRINSIC internal::expression_function<fn::cub, E1> cub(E1&& x)
{
return { fn::cub(), std::forward<E1>(x) };
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L398
div
function¶
template <typename T1, typename T2,
typename Tout = common_type<T1, T2>>
Tout div(const T1 &x, const T2 &y)
Division
Source code
template <typename T1, typename T2, typename Tout = common_type<T1, T2>>
KFR_INTRINSIC Tout div(const T1& x, const T2& y)
{
return static_cast<Tout>(x) / static_cast<Tout>(y);
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L499
fmadd
function¶
template <typename T1, typename T2, typename T3>
constexpr common_type<T1, T2, T3>
fmadd(const T1 &x, const T2 &y, const T3 &z)
Fused Multiply-Add
Source code
template <typename T1, typename T2, typename T3>
KFR_INTRINSIC constexpr common_type<T1, T2, T3> fmadd(const T1& x, const T2& y, const T3& z)
{
return x * y + z;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L523
fmsub
function¶
template <typename T1, typename T2, typename T3>
constexpr common_type<T1, T2, T3>
fmsub(const T1 &x, const T2 &y, const T3 &z)
Fused Multiply-Sub
Source code
template <typename T1, typename T2, typename T3>
KFR_INTRINSIC constexpr common_type<T1, T2, T3> fmsub(const T1& x, const T2& y, const T3& z)
{
return x * y - z;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L529
horner
function¶
template <typename T1, typename... Ts,
KFR_ENABLE_IF(is_numeric_args<T1, Ts...>)>
constexpr common_type<T1, Ts...> horner(const T1 &x,
const Ts &...c)
Calculate polynomial using Horner's method
horner(x, 1, 2, 3)
is equivalent to \(3x^2 + 2x + 1\)
Source code
template <typename T1, typename... Ts, KFR_ENABLE_IF(is_numeric_args<T1, Ts...>)>
constexpr KFR_INTRINSIC common_type<T1, Ts...> horner(const T1& x, const Ts&... c)
{
return intrinsics::horner(x, c...);
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L614
horner_even
function¶
template <typename T1, typename... Ts,
KFR_ENABLE_IF(is_numeric_args<T1, Ts...>)>
constexpr common_type<T1, Ts...> horner_even(const T1 &x,
const Ts &...c)
Calculate polynomial using Horner's method (even powers)
horner_even(x, 1, 2, 3)
is equivalent to \(3x^4 + 2x^2 + 1\)
Source code
template <typename T1, typename... Ts, KFR_ENABLE_IF(is_numeric_args<T1, Ts...>)>
constexpr KFR_INTRINSIC common_type<T1, Ts...> horner_even(const T1& x, const Ts&... c)
{
return intrinsics::horner_even(x, c...);
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L630
horner_odd
function¶
template <typename T1, typename... Ts,
KFR_ENABLE_IF(is_numeric_args<T1, Ts...>)>
constexpr common_type<T1, Ts...> horner_odd(const T1 &x,
const Ts &...c)
Calculate polynomial using Horner's method (odd powers)
horner_odd(x, 1, 2, 3)
is equivalent to \(3x^5 + 2x^3 + 1x\)
Source code
template <typename T1, typename... Ts, KFR_ENABLE_IF(is_numeric_args<T1, Ts...>)>
constexpr KFR_INTRINSIC common_type<T1, Ts...> horner_odd(const T1& x, const Ts&... c)
{
return intrinsics::horner_odd(x, c...);
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L646
ipow
function¶
template <typename T>
constexpr inline T ipow(const T &x, int base)
Raise x to the power base \(x^{base}\)
CHECK( ipow( 10, 3 ) == 1000 );
CHECK( ipow( 0.5, 2 ) == 0.25 );
Source code
template <typename T>
constexpr inline T ipow(const T& x, int base)
{
T xx = x;
T result = T(1);
while (base)
{
if (base & 1)
result *= xx;
base >>= 1;
xx *= xx;
}
return result;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L458
matrix
matrix
class¶
template <typename T> matrix
2D matrix
Source code
template <typename T>
struct matrix
{
union {
vec<T, 6> v;
struct
{
T a, b, c, d, e, f;
};
};
matrix() : v{ 1, 0, 0, 1, 0, 0 } {}
matrix(T a, T b, T c, T d, T e, T f) : v{ a, b, c, d, e, f } {}
static matrix translate(T x, T y) { return matrix{ 1, 0, 0, 1, x, y }; }
static matrix scale(T x, T y) { return matrix{ x, 0, 0, y, 0, 0 }; }
static matrix rotate(T angle) { return matrix{ cos(angle), sin(angle), -sin(angle), cos(angle), 0, 0 }; }
static matrix rotate90(int angle)
{
static const matrix m[4] = {
{ 1, 0, 0, 1, 0, 0 }, { 0, 1, -1, 0, 0, 0 }, { -1, 0, 0, -1, 0, 0 }, { 0, -1, 1, 0, 0, 0 }
};
return m[angle % 4];
}
std::array<std::array<T, 3>, 3> full() const
{
return { { { a, b, T() }, { c, d, T() }, { e, f, T(1) } } };
}
friend matrix<T> operator*(const matrix<T>& m, const matrix<T>& n)
{
const std::array<std::array<T, 3>, 3> mm = m.full();
const std::array<std::array<T, 3>, 3> nn = n.full();
std::array<std::array<T, 3>, 3> a;
for (size_t i = 0; i < 3; i++)
{
for (size_t j = 0; j < 3; j++)
{
T sum = 0;
for (size_t k = 0; k < 3; k++)
{
sum += mm[i][k] * nn[k][j];
}
a[i][j] = sum;
}
}
return { a[0][0], a[0][1], a[1][0], a[1][1], a[2][0], a[2][1] };
}
friend point<T> operator*(const point<T>& pt, const matrix<T>& m)
{
return { pt.x * m.a + pt.y * m.c + m.e, pt.y * m.d + pt.x * m.b + m.f };
}
}
https://github.com/kfrlib/kfr/blob//include/kfr/graphics/geometry.hpp#L423
max
function¶
template <typename T1, typename T2,
KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = common_type<T1, T2>>
Tout max(const T1 &x, const T2 &y)
Returns the greater of two values.
Source code
template <typename T1, typename T2, KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = common_type<T1, T2>>
KFR_INTRINSIC Tout max(const T1& x, const T2& y)
{
return intrinsics::max(x, y);
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/min_max.hpp#L59
template <typename E1, typename E2,
KFR_ENABLE_IF(is_input_expressions<E1, E2>)>
internal::expression_function<fn::max, E1, E2> max(E1 &&x,
E2 &&y)
Returns the greater of two values. Accepts and returns expressions.
Source code
template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>)>
KFR_INTRINSIC internal::expression_function<fn::max, E1, E2> max(E1&& x, E2&& y)
{
return { fn::max(), std::forward<E1>(x), std::forward<E2>(y) };
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/min_max.hpp#L68
min
function¶
template <typename T1, typename T2,
KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = common_type<T1, T2>>
Tout min(const T1 &x, const T2 &y)
Returns the smaller of two values.
Source code
template <typename T1, typename T2, KFR_ENABLE_IF(is_numeric_args<T1, T2>),
typename Tout = common_type<T1, T2>>
KFR_INTRINSIC Tout min(const T1& x, const T2& y)
{
return intrinsics::min(x, y);
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/min_max.hpp#L40
template <typename E1, typename E2,
KFR_ENABLE_IF(is_input_expressions<E1, E2>)>
internal::expression_function<fn::min, E1, E2> min(E1 &&x,
E2 &&y)
Returns the smaller of two values. Accepts and returns expressions.
Source code
template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>)>
KFR_INTRINSIC internal::expression_function<fn::min, E1, E2> min(E1&& x, E2&& y)
{
return { fn::min(), std::forward<E1>(x), std::forward<E2>(y) };
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/min_max.hpp#L49
mix
function¶
template <typename T1, typename T2, typename T3,
KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>)>
constexpr common_type<T1, T2, T3>
mix(const T1 &c, const T2 &x, const T3 &y)
Linear blend of x
and y
(c
must be in the range 0...+1)
Returns x + ( y - x ) * c
Source code
template <typename T1, typename T2, typename T3, KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>)>
KFR_INTRINSIC constexpr common_type<T1, T2, T3> mix(const T1& c, const T2& x, const T3& y)
{
return fmadd(c, y - x, x);
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L539
mixs
function¶
template <typename T1, typename T2, typename T3,
KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>)>
constexpr common_type<T1, T2, T3>
mixs(const T1 &c, const T2 &x, const T3 &y)
Linear blend of x
and y
(c
must be in the range -1...+1)
Source code
template <typename T1, typename T2, typename T3, KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>)>
KFR_INTRINSIC constexpr common_type<T1, T2, T3> mixs(const T1& c, const T2& x, const T3& y)
{
return mix(fmadd(c, 0.5, 0.5), x, y);
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L546
mul
function¶
template <typename T1, typename T2, typename... Ts>
constexpr common_type<T1, T2, Ts...>
mul(const T1 &x, const T2 &y, const Ts &...rest)
Returns product of all the arguments passed to a function.
Source code
template <typename T1, typename T2, typename... Ts>
constexpr KFR_INTRINSIC common_type<T1, T2, Ts...> mul(const T1& x, const T2& y, const Ts&... rest)
{
return x * mul(y, rest...);
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L344
template <typename... E,
KFR_ENABLE_IF(is_input_expressions<E...>)>
internal::expression_function<fn::mul, E...> mul(E &&...x)
Returns template expression that returns product of all the arguments passed to a function.
Source code
template <typename... E, KFR_ENABLE_IF(is_input_expressions<E...>)>
KFR_INTRINSIC internal::expression_function<fn::mul, E...> mul(E&&... x)
{
return { fn::mul(), std::forward<E>(x)... };
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L360
neg
function¶
template <typename T1> inline T1 neg(const T1 &x)
Negation
Source code
template <typename T1>
inline T1 neg(const T1& x)
{
return -x;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L515
reciprocal
function¶
template <typename T> constexpr T reciprocal(const T &x)
Calculate Multiplicative Inverse of x
Returns 1/x
Source code
template <typename T>
constexpr KFR_INTRINSIC T reciprocal(const T& x)
{
static_assert(is_floating_point<subtype<T>>, "T must be floating point type");
return subtype<T>(1) / x;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L661
rem
function¶
template <typename T1, typename T2,
typename Tout = common_type<T1, T2>>
Tout rem(const T1 &x, const T2 &y)
Remainder
Source code
template <typename T1, typename T2, typename Tout = common_type<T1, T2>>
KFR_INTRINSIC Tout rem(const T1& x, const T2& y)
{
return static_cast<Tout>(x) % static_cast<Tout>(y);
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L507
rol
function¶
template <typename T1, typename T2>
T1 rol(const T1 &left, const T2 &right)
Bitwise Left Rotate
Source code
template <typename T1, typename T2>
KFR_INTRINSIC T1 rol(const T1& left, const T2& right)
{
return shl(left, right) | shr(left, (static_cast<subtype<T1>>(typebits<T1>::bits) - right));
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L272
ror
function¶
template <typename T1, typename T2>
T1 ror(const T1 &left, const T2 &right)
Bitwise Right Rotate
Source code
template <typename T1, typename T2>
KFR_INTRINSIC T1 ror(const T1& left, const T2& right)
{
return shr(left, right) | shl(left, (static_cast<subtype<T1>>(typebits<T1>::bits) - right));
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L280
select
function¶
template <typename T1, size_t N, typename T2, typename T3,
KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>),
typename Tout = subtype<common_type<T2, T3>>>
vec<Tout, N> select(const mask<T1, N> &m, const T2 &x,
const T3 &y)
Returns x if m is true, otherwise return y. Order of the arguments is same as in ternary operator.
return m ? x : y
Source code
template <typename T1, size_t N, typename T2, typename T3, KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>),
typename Tout = subtype<common_type<T2, T3>>>
KFR_INTRINSIC vec<Tout, N> select(const mask<T1, N>& m, const T2& x, const T3& y)
{
static_assert(sizeof(T1) == sizeof(Tout), "select: incompatible types");
return intrinsics::select(bitcast<Tout>(m.asvec()).asmask(), innercast<Tout>(x), innercast<Tout>(y));
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/select.hpp#L43
template <typename E1, typename E2, typename E3,
KFR_ENABLE_IF(is_input_expressions<E1, E2, E3>)>
internal::expression_function<fn::select, E1, E2, E3>
select(E1 &&m, E2 &&x, E3 &&y)
Returns template expression that returns x if m is true, otherwise return y. Order of the arguments is same as in ternary operator.
Source code
template <typename E1, typename E2, typename E3, KFR_ENABLE_IF(is_input_expressions<E1, E2, E3>)>
KFR_INTRINSIC internal::expression_function<fn::select, E1, E2, E3> select(E1&& m, E2&& x, E3&& y)
{
return { fn::select(), std::forward<E1>(m), std::forward<E2>(x), std::forward<E3>(y) };
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/select.hpp#L54
shl
function¶
template <typename T1, typename T2>
T1 shl(const T1 &left, const T2 &right)
Bitwise Left shift
Source code
template <typename T1, typename T2>
KFR_INTRINSIC T1 shl(const T1& left, const T2& right)
{
return left << right;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L256
shr
function¶
template <typename T1, typename T2>
T1 shr(const T1 &left, const T2 &right)
Bitwise Right shift
Source code
template <typename T1, typename T2>
KFR_INTRINSIC T1 shr(const T1& left, const T2& right)
{
return left >> right;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L264
sqr
function¶
template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)>
constexpr inline T1 sqr(const T1 &x)
Returns square of x.
Source code
template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)>
constexpr inline T1 sqr(const T1& x)
{
return x * x;
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L369
template <typename E1,
KFR_ENABLE_IF(is_input_expression<E1>)>
internal::expression_function<fn::sqr, E1> sqr(E1 &&x)
Returns template expression that returns square of x.
Source code
template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>)>
KFR_INTRINSIC internal::expression_function<fn::sqr, E1> sqr(E1&& x)
{
return { fn::sqr(), std::forward<E1>(x) };
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L379
sqrsum
function¶
template <typename T1, typename... Ts>
constexpr inline common_type<T1, Ts...>
sqrsum(const T1 &x, const Ts &...rest)
Return square of the sum of all arguments
CHECK(sqrsum(1,2,3) == 36);
Source code
template <typename T1, typename... Ts>
constexpr inline common_type<T1, Ts...> sqrsum(const T1& x, const Ts&... rest)
{
return sqr(add(x, rest...));
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L484
sqrt
function¶
template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)>
flt_type<T1> sqrt(const T1 &x)
Returns the positive square root of the x. \(\sqrt{x}\)
Source code
template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)>
KFR_INTRINSIC flt_type<T1> sqrt(const T1& x)
{
return intrinsics::sqrt(x);
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/sqrt.hpp#L39
template <typename E1,
KFR_ENABLE_IF(is_input_expression<E1>)>
internal::expression_function<fn::sqrt, E1> sqrt(E1 &&x)
Returns template expression that returns the positive square root of the x. \(\sqrt{x}\)
Source code
template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>)>
KFR_INTRINSIC internal::expression_function<fn::sqrt, E1> sqrt(E1&& x)
{
return { fn::sqrt(), std::forward<E1>(x) };
}
https://github.com/kfrlib/kfr/blob//include/kfr/math/sqrt.hpp#L48
swapbyteorder
function¶
template <typename T, size_t N,
KFR_ENABLE_IF(sizeof(vec<T, N>) > 8)>
vec<T, N> swapbyteorder(const vec<T, N> &x)
Swap byte order
Source code
template <typename T, size_t N, KFR_ENABLE_IF(sizeof(vec<T, N>) > 8)>
KFR_INTRINSIC vec<T, N> swapbyteorder(const vec<T, N>& x)
{
return bitcast<T>(swap<sizeof(T)>(bitcast<u8>(x)));
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/operators.hpp#L683
Auto-generated from sources, Revision , https://github.com/kfrlib/kfr/blob//include/kfr/