mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
AK: Add very naive implementation of {sin,cos,tan} for aarch64
The {sin,cos,tan} functions in AK are used as the implementation of the same function in libm. We cannot use the __builtin_foo functions as these would just call the libc functions. This was causing an infinite loop. Fix this by adding a very naive implementation of AK::{sin, cos,tan}, that is only valid for small inputs. For the other functions in this file, I added a TODO() such that we'll crash, instead of infinite looping.
This commit is contained in:
parent
9ed04bdb33
commit
957f89ce4a
Notes:
sideshowbarker
2024-07-17 18:38:54 +09:00
Author: https://github.com/FireFox317 Commit: https://github.com/SerenityOS/serenity/commit/957f89ce4a Pull-request: https://github.com/SerenityOS/serenity/pull/18354 Reviewed-by: https://github.com/nico ✅
1 changed files with 27 additions and 3 deletions
30
AK/Math.h
30
AK/Math.h
|
@ -90,6 +90,8 @@ constexpr T fmod(T x, T y)
|
|||
} while (fpu_status & 0x400);
|
||||
return x;
|
||||
#else
|
||||
// TODO: Add implementation for this function.
|
||||
TODO();
|
||||
return __builtin_fmod(x, y);
|
||||
#endif
|
||||
}
|
||||
|
@ -109,6 +111,8 @@ constexpr T remainder(T x, T y)
|
|||
} while (fpu_status & 0x400);
|
||||
return x;
|
||||
#else
|
||||
// TODO: Add implementation for this function.
|
||||
TODO();
|
||||
return __builtin_fmod(x, y);
|
||||
#endif
|
||||
}
|
||||
|
@ -244,7 +248,9 @@ constexpr T sin(T angle)
|
|||
: "0"(angle));
|
||||
return ret;
|
||||
#else
|
||||
return __builtin_sin(angle);
|
||||
// FIXME: This is a very naive implementation, and is only valid for small x.
|
||||
// Probably a good idea to use a better algorithm in the future, such as a taylor approximation.
|
||||
return angle;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -261,7 +267,9 @@ constexpr T cos(T angle)
|
|||
: "0"(angle));
|
||||
return ret;
|
||||
#else
|
||||
return __builtin_cos(angle);
|
||||
// FIXME: This is a very naive implementation, and is only valid for small x.
|
||||
// Probably a good idea to use a better algorithm in the future, such as a taylor approximation.
|
||||
return 1 - ((angle * angle) / 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -298,7 +306,9 @@ constexpr T tan(T angle)
|
|||
|
||||
return ret;
|
||||
#else
|
||||
return __builtin_tan(angle);
|
||||
// FIXME: This is a very naive implementation, and is only valid for small x.
|
||||
// Probably a good idea to use a better algorithm in the future, such as a taylor approximation.
|
||||
return angle;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -316,6 +326,8 @@ constexpr T atan(T value)
|
|||
: "0"(value));
|
||||
return ret;
|
||||
#else
|
||||
// TODO: Add implementation for this function.
|
||||
TODO();
|
||||
return __builtin_atan(value);
|
||||
#endif
|
||||
}
|
||||
|
@ -371,6 +383,8 @@ constexpr T atan2(T y, T x)
|
|||
: "st(1)");
|
||||
return ret;
|
||||
#else
|
||||
// TODO: Add implementation for this function.
|
||||
TODO();
|
||||
return __builtin_atan2(y, x);
|
||||
#endif
|
||||
}
|
||||
|
@ -404,6 +418,8 @@ constexpr T log(T x)
|
|||
: "0"(x));
|
||||
return ret;
|
||||
#else
|
||||
// TODO: Add implementation for this function.
|
||||
TODO();
|
||||
return __builtin_log(x);
|
||||
#endif
|
||||
}
|
||||
|
@ -423,6 +439,8 @@ constexpr T log2(T x)
|
|||
: "0"(x));
|
||||
return ret;
|
||||
#else
|
||||
// TODO: Add implementation for this function.
|
||||
TODO();
|
||||
return __builtin_log2(x);
|
||||
#endif
|
||||
}
|
||||
|
@ -442,6 +460,8 @@ constexpr T log10(T x)
|
|||
: "0"(x));
|
||||
return ret;
|
||||
#else
|
||||
// TODO: Add implementation for this function.
|
||||
TODO();
|
||||
return __builtin_log10(x);
|
||||
#endif
|
||||
}
|
||||
|
@ -466,6 +486,8 @@ constexpr T exp(T exponent)
|
|||
: "0"(exponent));
|
||||
return res;
|
||||
#else
|
||||
// TODO: Add implementation for this function.
|
||||
TODO();
|
||||
return __builtin_exp(exponent);
|
||||
#endif
|
||||
}
|
||||
|
@ -488,6 +510,8 @@ constexpr T exp2(T exponent)
|
|||
: "0"(exponent));
|
||||
return res;
|
||||
#else
|
||||
// TODO: Add implementation for this function.
|
||||
TODO();
|
||||
return __builtin_exp2(exponent);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue