about summary refs log tree commit diff
path: root/src/math/x86_64/fabsf.c
diff options
context:
space:
mode:
authorAlexander Monakov <amonakov@ispras.ru>2020-01-05 18:47:02 +0300
committerRich Felker <dalias@aerifal.cx>2020-03-24 16:27:06 -0400
commit87026f6843f45573d6ac93c791c0597ba7f4e693 (patch)
tree100b2f71cceb6e64a3b492b3fe2727616de458e4 /src/math/x86_64/fabsf.c
parent33338ebc853d37c80f0f236cc7a92cb0acc6aace (diff)
downloadmusl-87026f6843f45573d6ac93c791c0597ba7f4e693.tar.gz
musl-87026f6843f45573d6ac93c791c0597ba7f4e693.tar.xz
musl-87026f6843f45573d6ac93c791c0597ba7f4e693.zip
math: move x86_64 fabs, fabsf to C with inline asm
Diffstat (limited to 'src/math/x86_64/fabsf.c')
-rw-r--r--src/math/x86_64/fabsf.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/math/x86_64/fabsf.c b/src/math/x86_64/fabsf.c
new file mode 100644
index 00000000..36ea7481
--- /dev/null
+++ b/src/math/x86_64/fabsf.c
@@ -0,0 +1,10 @@
+#include <math.h>
+
+float fabsf(float x)
+{
+	float t;
+	__asm__ ("pcmpeqd %0, %0" : "=x"(t));          // t = ~0
+	__asm__ ("psrld   $1, %0" : "+x"(t));          // t >>= 1
+	__asm__ ("andps   %1, %0" : "+x"(x) : "x"(t)); // x &= t
+	return x;
+}