Browse Source

math: move trivial x86-family sqrt functions to C with inline asm

master
Alexander Monakov 6 years ago
committed by Rich Felker
parent
commit
41b290ba39
  1. 7
      src/math/i386/sqrtl.c
  2. 5
      src/math/i386/sqrtl.s
  3. 7
      src/math/x86_64/sqrt.c
  4. 4
      src/math/x86_64/sqrt.s
  5. 7
      src/math/x86_64/sqrtf.c
  6. 4
      src/math/x86_64/sqrtf.s
  7. 7
      src/math/x86_64/sqrtl.c
  8. 5
      src/math/x86_64/sqrtl.s

7
src/math/i386/sqrtl.c

@ -0,0 +1,7 @@
#include <math.h>
long double sqrtl(long double x)
{
__asm__ ("fsqrt" : "+t"(x));
return x;
}

5
src/math/i386/sqrtl.s

@ -1,5 +0,0 @@
.global sqrtl
.type sqrtl,@function
sqrtl: fldt 4(%esp)
fsqrt
ret

7
src/math/x86_64/sqrt.c

@ -0,0 +1,7 @@
#include <math.h>
double sqrt(double x)
{
__asm__ ("sqrtsd %1, %0" : "=x"(x) : "x"(x));
return x;
}

4
src/math/x86_64/sqrt.s

@ -1,4 +0,0 @@
.global sqrt
.type sqrt,@function
sqrt: sqrtsd %xmm0, %xmm0
ret

7
src/math/x86_64/sqrtf.c

@ -0,0 +1,7 @@
#include <math.h>
float sqrtf(float x)
{
__asm__ ("sqrtss %1, %0" : "=x"(x) : "x"(x));
return x;
}

4
src/math/x86_64/sqrtf.s

@ -1,4 +0,0 @@
.global sqrtf
.type sqrtf,@function
sqrtf: sqrtss %xmm0, %xmm0
ret

7
src/math/x86_64/sqrtl.c

@ -0,0 +1,7 @@
#include <math.h>
long double sqrtl(long double x)
{
__asm__ ("fsqrt" : "+t"(x));
return x;
}

5
src/math/x86_64/sqrtl.s

@ -1,5 +0,0 @@
.global sqrtl
.type sqrtl,@function
sqrtl: fldt 8(%rsp)
fsqrt
ret
Loading…
Cancel
Save