From 957f89ce4abb6ad2228b882cf4dde40325ee1ce0 Mon Sep 17 00:00:00 2001 From: Timon Kruiper Date: Thu, 13 Apr 2023 19:17:34 +0200 Subject: [PATCH] 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. --- AK/Math.h | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/AK/Math.h b/AK/Math.h index 982ae5c89a5..f67c86c6e15 100644 --- a/AK/Math.h +++ b/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 }