From 87026f6843f45573d6ac93c791c0597ba7f4e693 Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Sun, 5 Jan 2020 18:47:02 +0300 Subject: math: move x86_64 fabs, fabsf to C with inline asm --- src/math/x86_64/fabsf.c | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/math/x86_64/fabsf.c (limited to 'src/math/x86_64/fabsf.c') 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 + +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; +} -- cgit v1.2.1