From cfe8fdd5aaf1937563278ac6a30d57593df24c7c Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Fri, 9 Aug 2019 23:23:01 +0300 Subject: [PATCH] LibM: Implement sqrt() Use the x87 fsqrt instruction for that. We cannot use __builtin_sqrt(), since GCC expands it into a sqrt() call, so we just loop endlessly. --- Libraries/LibM/math.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Libraries/LibM/math.cpp b/Libraries/LibM/math.cpp index 8d0cc11135..52170f23dc 100644 --- a/Libraries/LibM/math.cpp +++ b/Libraries/LibM/math.cpp @@ -58,9 +58,11 @@ double tan(double angle) return ampsin(angle) / ampsin(M_PI_2 + angle); } -double sqrt(double) +double sqrt(double x) { - ASSERT_NOT_REACHED(); + double res; + __asm__("fsqrt" : "=t"(res) : "0"(x)); + return res; } double sinh(double)