math: move trivial x86-family sqrt functions to C with inline asm
authorAlexander Monakov <amonakov@ispras.ru>
Mon, 6 Jan 2020 16:35:57 +0000 (19:35 +0300)
committerRich Felker <dalias@aerifal.cx>
Tue, 24 Mar 2020 20:27:38 +0000 (16:27 -0400)
src/math/i386/sqrtl.c [new file with mode: 0644]
src/math/i386/sqrtl.s [deleted file]
src/math/x86_64/sqrt.c [new file with mode: 0644]
src/math/x86_64/sqrt.s [deleted file]
src/math/x86_64/sqrtf.c [new file with mode: 0644]
src/math/x86_64/sqrtf.s [deleted file]
src/math/x86_64/sqrtl.c [new file with mode: 0644]
src/math/x86_64/sqrtl.s [deleted file]

diff --git a/src/math/i386/sqrtl.c b/src/math/i386/sqrtl.c
new file mode 100644 (file)
index 0000000..864cfcc
--- /dev/null
@@ -0,0 +1,7 @@
+#include <math.h>
+
+long double sqrtl(long double x)
+{
+       __asm__ ("fsqrt" : "+t"(x));
+       return x;
+}
diff --git a/src/math/i386/sqrtl.s b/src/math/i386/sqrtl.s
deleted file mode 100644 (file)
index e0d4261..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-.global sqrtl
-.type sqrtl,@function
-sqrtl: fldt 4(%esp)
-       fsqrt
-       ret
diff --git a/src/math/x86_64/sqrt.c b/src/math/x86_64/sqrt.c
new file mode 100644 (file)
index 0000000..657e09e
--- /dev/null
@@ -0,0 +1,7 @@
+#include <math.h>
+
+double sqrt(double x)
+{
+       __asm__ ("sqrtsd %1, %0" : "=x"(x) : "x"(x));
+       return x;
+}
diff --git a/src/math/x86_64/sqrt.s b/src/math/x86_64/sqrt.s
deleted file mode 100644 (file)
index d3c609f..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-.global sqrt
-.type sqrt,@function
-sqrt:  sqrtsd %xmm0, %xmm0
-       ret
diff --git a/src/math/x86_64/sqrtf.c b/src/math/x86_64/sqrtf.c
new file mode 100644 (file)
index 0000000..720baec
--- /dev/null
@@ -0,0 +1,7 @@
+#include <math.h>
+
+float sqrtf(float x)
+{
+       __asm__ ("sqrtss %1, %0" : "=x"(x) : "x"(x));
+       return x;
+}
diff --git a/src/math/x86_64/sqrtf.s b/src/math/x86_64/sqrtf.s
deleted file mode 100644 (file)
index eec48c6..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-.global sqrtf
-.type sqrtf,@function
-sqrtf:  sqrtss %xmm0, %xmm0
-       ret
diff --git a/src/math/x86_64/sqrtl.c b/src/math/x86_64/sqrtl.c
new file mode 100644 (file)
index 0000000..864cfcc
--- /dev/null
@@ -0,0 +1,7 @@
+#include <math.h>
+
+long double sqrtl(long double x)
+{
+       __asm__ ("fsqrt" : "+t"(x));
+       return x;
+}
diff --git a/src/math/x86_64/sqrtl.s b/src/math/x86_64/sqrtl.s
deleted file mode 100644 (file)
index 23cd687..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-.global sqrtl
-.type sqrtl,@function
-sqrtl: fldt 8(%rsp)
-       fsqrt
-       ret