mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Add rsqrt and a SSE specific implementation for sqrt
This commit is contained in:
parent
50c4ba0756
commit
b1db1e4e4f
Notes:
sideshowbarker
2024-07-17 16:19:38 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/b1db1e4e4f Pull-request: https://github.com/SerenityOS/serenity/pull/13405
1 changed files with 34 additions and 0 deletions
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