mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
AK+Everywhere: Add sincos and use it in some places
Calculating sin and cos at once is quite a bit cheaper than calculating them individually. x87 has even a dedicated instruction for it: `fsincos`.
This commit is contained in:
parent
47fe911196
commit
cd21e03225
6 changed files with 30 additions and 10 deletions
15
AK/Math.h
15
AK/Math.h
|
@ -203,6 +203,20 @@ constexpr T cos(T angle)
|
|||
#endif
|
||||
}
|
||||
|
||||
template<FloatingPoint T>
|
||||
constexpr void sincos(T angle, T& sin_val, T& cos_val)
|
||||
{
|
||||
if (is_constant_evaluated()) {
|
||||
sin_val = sin(angle);
|
||||
cos_val = cos(angle);
|
||||
return;
|
||||
}
|
||||
asm(
|
||||
"fsincos"
|
||||
: "=t"(cos_val), "=u"(sin_val)
|
||||
: "0"(angle));
|
||||
}
|
||||
|
||||
template<FloatingPoint T>
|
||||
constexpr T tan(T angle)
|
||||
{
|
||||
|
@ -303,6 +317,7 @@ using Trigonometry::atan2;
|
|||
using Trigonometry::cos;
|
||||
using Trigonometry::hypot;
|
||||
using Trigonometry::sin;
|
||||
using Trigonometry::sincos;
|
||||
using Trigonometry::tan;
|
||||
|
||||
namespace Exponentials {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue