math: move i386 sqrtf to C with inline asm
authorAlexander Monakov <amonakov@ispras.ru>
Mon, 6 Jan 2020 17:31:47 +0000 (20:31 +0300)
committerRich Felker <dalias@aerifal.cx>
Tue, 24 Mar 2020 20:31:36 +0000 (16:31 -0400)
src/math/i386/sqrtf.c [new file with mode: 0644]
src/math/i386/sqrtf.s [deleted file]

diff --git a/src/math/i386/sqrtf.c b/src/math/i386/sqrtf.c
new file mode 100644 (file)
index 0000000..41c65c2
--- /dev/null
@@ -0,0 +1,12 @@
+#include <math.h>
+
+float sqrtf(float x)
+{
+       long double t;
+       /* The long double result has sufficient precision so that
+        * second rounding to float still keeps the returned value
+        * correctly rounded, see Pierre Roux, "Innocuous Double
+        * Rounding of Basic Arithmetic Operations". */
+       __asm__ ("fsqrt" : "=t"(t) : "0"(x));
+       return (float)t;
+}
diff --git a/src/math/i386/sqrtf.s b/src/math/i386/sqrtf.s
deleted file mode 100644 (file)
index 9e944f4..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-.global sqrtf
-.type sqrtf,@function
-sqrtf: flds 4(%esp)
-       fsqrt
-       fstps 4(%esp)
-       flds 4(%esp)
-       ret