From b583726deb1a1a52e6752227223bff0b94c8c405 Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Mon, 5 Jul 2021 16:56:06 +0200 Subject: [PATCH] LibM: Use assembly for all atan versions --- Userland/Libraries/LibM/math.cpp | 57 +++++++++++++++++++------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/Userland/Libraries/LibM/math.cpp b/Userland/Libraries/LibM/math.cpp index dbc953b1fd..6599f9d9ed 100644 --- a/Userland/Libraries/LibM/math.cpp +++ b/Userland/Libraries/LibM/math.cpp @@ -729,50 +729,61 @@ float coshf(float x) NOEXCEPT long double atan2l(long double y, long double x) NOEXCEPT { - if (x == 0) { - if (y > 0) - return M_PI_2; - if (y < 0) - return -M_PI_2; - return 0; - } - long double result = 0; //atanl(y / x); - __asm__("fpatan" - : "=t"(result) - : "0"(x), "u"(y) - : "st(1)"); + asm("fpatan" + : "=t"(result) + : "0"(x), "u"(y) + : "st(1)"); return result; } double atan2(double y, double x) NOEXCEPT { - return (double)atan2l(y, x); + double result = 0; //atanl(y / x); + asm("fpatan" + : "=t"(result) + : "0"(x), "u"(y) + : "st(1)"); + return result; } - float atan2f(float y, float x) NOEXCEPT { - return (float)atan2l(y, x); + float result = 0; //atanl(y / x); + asm("fpatan" + : "=t"(result) + : "0"(x), "u"(y) + : "st(1)"); + return result; } long double atanl(long double x) NOEXCEPT { - if (x < 0) - return -atanl(-x); - if (x > 1) - return M_PI_2 - atanl(1 / x); - long double squared = x * x; - return x / (1 + 1 * 1 * squared / (3 + 2 * 2 * squared / (5 + 3 * 3 * squared / (7 + 4 * 4 * squared / (9 + 5 * 5 * squared / (11 + 6 * 6 * squared / (13 + 7 * 7 * squared))))))); + asm( + "fld1\n" + "fpatan\n" + : "=t"(x) + : "0"(x)); + return x; } double atan(double x) NOEXCEPT { - return (double)atanl(x); + asm( + "fld1\n" + "fpatan\n" + : "=t"(x) + : "0"(x)); + return x; } float atanf(float x) NOEXCEPT { - return (float)atanl(x); + asm( + "fld1\n" + "fpatan\n" + : "=t"(x) + : "0"(x)); + return x; } long double asinl(long double x) NOEXCEPT