AK: Add rsqrt and a SSE specific implementation for sqrt

This commit is contained in:
Hendiadyoin1 2022-04-01 13:46:15 +02:00 committed by Andreas Kling
parent 50c4ba0756
commit b1db1e4e4f

View file

@ -106,6 +106,40 @@ constexpr T sqrt(T x)
#endif
}
template<FloatingPoint T>
constexpr T rsqrt(T x)
{
return (T)1. / sqrt(x);
}
#ifdef __SSE__
template<>
constexpr float sqrt(float x)
{
if (is_constant_evaluated())
return __builtin_sqrtf(x);
float res;
asm("sqrtss %1, %0"
: "=x"(res)
: "x"(x));
return res;
}
template<>
constexpr float rsqrt(float x)
{
if (is_constant_evaluated())
return 1.f / __builtin_sqrtf(x);
float res;
asm("rsqrtss %1, %0"
: "=x"(res)
: "x"(x));
return res;
}
#endif
template<FloatingPoint T>
constexpr T cbrt(T x)
{