mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-04 15:09:40 +00:00
AK: Add rsqrt and a SSE specific implementation for sqrt
This commit is contained in:
parent
50c4ba0756
commit
b1db1e4e4f
34
AK/Math.h
34
AK/Math.h
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue