diff options
author | Hendiadyoin1 <leon.a@serenityos.org> | 2022-04-01 13:46:15 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-02 18:37:38 +0200 |
commit | b1db1e4e4f90e4574888230b699d2191607d33b6 (patch) | |
tree | 8e03065716dc1ed667e26b6354c012d505a0ba56 /AK | |
parent | 50c4ba07563c32dc023a9805e5e643a089ebcca0 (diff) | |
download | serenity-b1db1e4e4f90e4574888230b699d2191607d33b6.zip |
AK: Add rsqrt and a SSE specific implementation for sqrt
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Math.h | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -107,6 +107,40 @@ constexpr T sqrt(T x) } 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) { CONSTEXPR_STATE(cbrt, x); |