summaryrefslogtreecommitdiff
path: root/src/math/x86_64/fabs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/x86_64/fabs.c')
-rw-r--r--src/math/x86_64/fabs.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/math/x86_64/fabs.c b/src/math/x86_64/fabs.c
new file mode 100644
index 00000000..16562477
--- /dev/null
+++ b/src/math/x86_64/fabs.c
@@ -0,0 +1,10 @@
+#include <math.h>
+
+double fabs(double x)
+{
+ double t;
+ __asm__ ("pcmpeqd %0, %0" : "=x"(t)); // t = ~0
+ __asm__ ("psrlq $1, %0" : "+x"(t)); // t >>= 1
+ __asm__ ("andps %1, %0" : "+x"(x) : "x"(t)); // x &= t
+ return x;
+}