mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
math: move x86_64 fabs, fabsf to C with inline asm
This commit is contained in:
parent
33338ebc85
commit
87026f6843
4 changed files with 20 additions and 16 deletions
10
src/math/x86_64/fabs.c
Normal file
10
src/math/x86_64/fabs.c
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -1,9 +0,0 @@
|
||||||
.global fabs
|
|
||||||
.type fabs,@function
|
|
||||||
fabs:
|
|
||||||
xor %eax,%eax
|
|
||||||
dec %rax
|
|
||||||
shr %rax
|
|
||||||
movq %rax,%xmm1
|
|
||||||
andpd %xmm1,%xmm0
|
|
||||||
ret
|
|
10
src/math/x86_64/fabsf.c
Normal file
10
src/math/x86_64/fabsf.c
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
.global fabsf
|
|
||||||
.type fabsf,@function
|
|
||||||
fabsf:
|
|
||||||
mov $0x7fffffff,%eax
|
|
||||||
movq %rax,%xmm1
|
|
||||||
andps %xmm1,%xmm0
|
|
||||||
ret
|
|
Loading…
Add table
Reference in a new issue