diff options
Diffstat (limited to 'src/math/i386')
68 files changed, 292 insertions, 292 deletions
diff --git a/src/math/i386/acos.s b/src/math/i386/acos.s index 47f365ef..af423a2f 100644 --- a/src/math/i386/acos.s +++ b/src/math/i386/acos.s @@ -1,22 +1,10 @@ # use acos(x) = atan2(fabs(sqrt((1-x)*(1+x))), x) -.global acosf -.type acosf,@function -acosf: - flds 4(%esp) - jmp 1f - -.global acosl -.type acosl,@function -acosl: - fldt 4(%esp) - jmp 1f - .global acos .type acos,@function acos: fldl 4(%esp) -1: fld %st(0) + fld %st(0) fld1 fsub %st(0),%st(1) fadd %st(2) @@ -25,4 +13,6 @@ acos: fabs # fix sign of zero (matters in downward rounding mode) fxch %st(1) fpatan + fstpl 4(%esp) + fldl 4(%esp) ret diff --git a/src/math/i386/acosf.s b/src/math/i386/acosf.s index 6c95509f..d2cdfdbf 100644 --- a/src/math/i386/acosf.s +++ b/src/math/i386/acosf.s @@ -1 +1,16 @@ -# see acos.s +.global acosf +.type acosf,@function +acosf: + flds 4(%esp) + fld %st(0) + fld1 + fsub %st(0),%st(1) + fadd %st(2) + fmulp + fsqrt + fabs # fix sign of zero (matters in downward rounding mode) + fxch %st(1) + fpatan + fstps 4(%esp) + flds 4(%esp) + ret diff --git a/src/math/i386/acosl.s b/src/math/i386/acosl.s index 6c95509f..599c8230 100644 --- a/src/math/i386/acosl.s +++ b/src/math/i386/acosl.s @@ -1 +1,14 @@ -# see acos.s +.global acosl +.type acosl,@function +acosl: + fldt 4(%esp) + fld %st(0) + fld1 + fsub %st(0),%st(1) + fadd %st(2) + fmulp + fsqrt + fabs # fix sign of zero (matters in downward rounding mode) + fxch %st(1) + fpatan + ret diff --git a/src/math/i386/asin.s b/src/math/i386/asin.s index 920d967a..2bc8356f 100644 --- a/src/math/i386/asin.s +++ b/src/math/i386/asin.s @@ -1,23 +1,3 @@ -.global asinf -.type asinf,@function -asinf: - flds 4(%esp) - mov 4(%esp),%eax - add %eax,%eax - cmp $0x01000000,%eax - jae 1f - # subnormal x, return x with underflow - fld %st(0) - fmul %st(1) - fstps 4(%esp) - ret - -.global asinl -.type asinl,@function -asinl: - fldt 4(%esp) - jmp 1f - .global asin .type asin,@function asin: @@ -25,15 +5,17 @@ asin: mov 8(%esp),%eax add %eax,%eax cmp $0x00200000,%eax - jae 1f - # subnormal x, return x with underflow - fsts 4(%esp) - ret -1: fld %st(0) + jb 1f + fld %st(0) fld1 fsub %st(0),%st(1) fadd %st(2) fmulp fsqrt fpatan + fstpl 4(%esp) + fldl 4(%esp) + ret + # subnormal x, return x with underflow +1: fsts 4(%esp) ret diff --git a/src/math/i386/asinf.s b/src/math/i386/asinf.s index e07bf599..05909753 100644 --- a/src/math/i386/asinf.s +++ b/src/math/i386/asinf.s @@ -1 +1,23 @@ -# see asin.s +.global asinf +.type asinf,@function +asinf: + flds 4(%esp) + mov 4(%esp),%eax + add %eax,%eax + cmp $0x01000000,%eax + jb 1f + fld %st(0) + fld1 + fsub %st(0),%st(1) + fadd %st(2) + fmulp + fsqrt + fpatan + fstps 4(%esp) + flds 4(%esp) + ret + # subnormal x, return x with underflow +1: fld %st(0) + fmul %st(1) + fstps 4(%esp) + ret diff --git a/src/math/i386/asinl.s b/src/math/i386/asinl.s index e07bf599..e973fc85 100644 --- a/src/math/i386/asinl.s +++ b/src/math/i386/asinl.s @@ -1 +1,12 @@ -# see asin.s +.global asinl +.type asinl,@function +asinl: + fldt 4(%esp) + fld %st(0) + fld1 + fsub %st(0),%st(1) + fadd %st(2) + fmulp + fsqrt + fpatan + ret diff --git a/src/math/i386/atan.s b/src/math/i386/atan.s index a26feae1..2c57f6b3 100644 --- a/src/math/i386/atan.s +++ b/src/math/i386/atan.s @@ -8,6 +8,8 @@ atan: jb 1f fld1 fpatan + fstpl 4(%esp) + fldl 4(%esp) ret # subnormal x, return x with underflow 1: fsts 4(%esp) diff --git a/src/math/i386/atan2.s b/src/math/i386/atan2.s index 76b95f31..8bc441b1 100644 --- a/src/math/i386/atan2.s +++ b/src/math/i386/atan2.s @@ -4,7 +4,8 @@ atan2: fldl 4(%esp) fldl 12(%esp) fpatan - fstl 4(%esp) + fstpl 4(%esp) + fldl 4(%esp) mov 8(%esp),%eax add %eax,%eax cmp $0x00200000,%eax diff --git a/src/math/i386/atan2f.s b/src/math/i386/atan2f.s index c9408a90..3908c86d 100644 --- a/src/math/i386/atan2f.s +++ b/src/math/i386/atan2f.s @@ -4,7 +4,8 @@ atan2f: flds 4(%esp) flds 8(%esp) fpatan - fsts 4(%esp) + fstps 4(%esp) + flds 4(%esp) mov 4(%esp),%eax add %eax,%eax cmp $0x01000000,%eax diff --git a/src/math/i386/atanf.s b/src/math/i386/atanf.s index 893beac5..c2cbe2e0 100644 --- a/src/math/i386/atanf.s +++ b/src/math/i386/atanf.s @@ -8,6 +8,8 @@ atanf: jb 1f fld1 fpatan + fstps 4(%esp) + flds 4(%esp) ret # subnormal x, return x with underflow 1: fld %st(0) diff --git a/src/math/i386/exp2.s b/src/math/i386/exp2.s deleted file mode 100644 index f335a3e5..00000000 --- a/src/math/i386/exp2.s +++ /dev/null @@ -1 +0,0 @@ -# see exp.s diff --git a/src/math/i386/exp2f.s b/src/math/i386/exp2f.s deleted file mode 100644 index f335a3e5..00000000 --- a/src/math/i386/exp2f.s +++ /dev/null @@ -1 +0,0 @@ -# see exp.s diff --git a/src/math/i386/exp2l.s b/src/math/i386/exp2l.s index f335a3e5..8125761d 100644 --- a/src/math/i386/exp2l.s +++ b/src/math/i386/exp2l.s @@ -1 +1 @@ -# see exp.s +# see exp_ld.s diff --git a/src/math/i386/exp.s b/src/math/i386/exp_ld.s index df87c497..99cba01f 100644 --- a/src/math/i386/exp.s +++ b/src/math/i386/exp_ld.s @@ -1,35 +1,8 @@ -.global expm1f -.type expm1f,@function -expm1f: - flds 4(%esp) - mov 4(%esp),%eax - add %eax,%eax - cmp $0x01000000,%eax - jae 1f - # subnormal x, return x with underflow - fld %st(0) - fmul %st(1) - fstps 4(%esp) - ret - .global expm1l .type expm1l,@function expm1l: fldt 4(%esp) - jmp 1f - -.global expm1 -.type expm1,@function -expm1: - fldl 4(%esp) - mov 8(%esp),%eax - add %eax,%eax - cmp $0x00200000,%eax - jae 1f - # subnormal x, return x with underflow - fsts 4(%esp) - ret -1: fldl2e + fldl2e fmulp mov $0xc2820000,%eax push %eax @@ -59,12 +32,6 @@ expm1: fsubrp ret -.global exp2f -.type exp2f,@function -exp2f: - flds 4(%esp) - jmp 1f - .global exp2l .global __exp2l .hidden __exp2l @@ -72,26 +39,6 @@ exp2f: exp2l: __exp2l: fldt 4(%esp) - jmp 1f - -.global expf -.type expf,@function -expf: - flds 4(%esp) - jmp 2f - -.global exp -.type exp,@function -exp: - fldl 4(%esp) -2: fldl2e - fmulp - jmp 1f - -.global exp2 -.type exp2,@function -exp2: - fldl 4(%esp) 1: sub $12,%esp fld %st(0) fstpt (%esp) diff --git a/src/math/i386/expf.s b/src/math/i386/expf.s deleted file mode 100644 index f335a3e5..00000000 --- a/src/math/i386/expf.s +++ /dev/null @@ -1 +0,0 @@ -# see exp.s diff --git a/src/math/i386/expm1.s b/src/math/i386/expm1.s deleted file mode 100644 index f335a3e5..00000000 --- a/src/math/i386/expm1.s +++ /dev/null @@ -1 +0,0 @@ -# see exp.s diff --git a/src/math/i386/expm1f.s b/src/math/i386/expm1f.s deleted file mode 100644 index f335a3e5..00000000 --- a/src/math/i386/expm1f.s +++ /dev/null @@ -1 +0,0 @@ -# see exp.s diff --git a/src/math/i386/expm1l.s b/src/math/i386/expm1l.s index f335a3e5..8125761d 100644 --- a/src/math/i386/expm1l.s +++ b/src/math/i386/expm1l.s @@ -1 +1 @@ -# see exp.s +# see exp_ld.s diff --git a/src/math/i386/fabs.c b/src/math/i386/fabs.c new file mode 100644 index 00000000..39672786 --- /dev/null +++ b/src/math/i386/fabs.c @@ -0,0 +1,7 @@ +#include <math.h> + +double fabs(double x) +{ + __asm__ ("fabs" : "+t"(x)); + return x; +} diff --git a/src/math/i386/fabs.s b/src/math/i386/fabs.s deleted file mode 100644 index d66ea9a1..00000000 --- a/src/math/i386/fabs.s +++ /dev/null @@ -1,6 +0,0 @@ -.global fabs -.type fabs,@function -fabs: - fldl 4(%esp) - fabs - ret diff --git a/src/math/i386/fabsf.c b/src/math/i386/fabsf.c new file mode 100644 index 00000000..d882eee3 --- /dev/null +++ b/src/math/i386/fabsf.c @@ -0,0 +1,7 @@ +#include <math.h> + +float fabsf(float x) +{ + __asm__ ("fabs" : "+t"(x)); + return x; +} diff --git a/src/math/i386/fabsf.s b/src/math/i386/fabsf.s deleted file mode 100644 index a981c422..00000000 --- a/src/math/i386/fabsf.s +++ /dev/null @@ -1,6 +0,0 @@ -.global fabsf -.type fabsf,@function -fabsf: - flds 4(%esp) - fabs - ret diff --git a/src/math/i386/fabsl.c b/src/math/i386/fabsl.c new file mode 100644 index 00000000..cc1c9ed9 --- /dev/null +++ b/src/math/i386/fabsl.c @@ -0,0 +1,7 @@ +#include <math.h> + +long double fabsl(long double x) +{ + __asm__ ("fabs" : "+t"(x)); + return x; +} diff --git a/src/math/i386/fabsl.s b/src/math/i386/fabsl.s deleted file mode 100644 index ceef9e4c..00000000 --- a/src/math/i386/fabsl.s +++ /dev/null @@ -1,6 +0,0 @@ -.global fabsl -.type fabsl,@function -fabsl: - fldt 4(%esp) - fabs - ret diff --git a/src/math/i386/fmod.c b/src/math/i386/fmod.c new file mode 100644 index 00000000..ea0c58d9 --- /dev/null +++ b/src/math/i386/fmod.c @@ -0,0 +1,10 @@ +#include <math.h> + +double fmod(double x, double y) +{ + unsigned short fpsr; + // fprem does not introduce excess precision into x + do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); + while (fpsr & 0x400); + return x; +} diff --git a/src/math/i386/fmod.s b/src/math/i386/fmod.s deleted file mode 100644 index 2113b3c5..00000000 --- a/src/math/i386/fmod.s +++ /dev/null @@ -1,11 +0,0 @@ -.global fmod -.type fmod,@function -fmod: - fldl 12(%esp) - fldl 4(%esp) -1: fprem - fnstsw %ax - sahf - jp 1b - fstp %st(1) - ret diff --git a/src/math/i386/fmodf.c b/src/math/i386/fmodf.c new file mode 100644 index 00000000..90b56ab0 --- /dev/null +++ b/src/math/i386/fmodf.c @@ -0,0 +1,10 @@ +#include <math.h> + +float fmodf(float x, float y) +{ + unsigned short fpsr; + // fprem does not introduce excess precision into x + do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); + while (fpsr & 0x400); + return x; +} diff --git a/src/math/i386/fmodf.s b/src/math/i386/fmodf.s deleted file mode 100644 index e04e2a56..00000000 --- a/src/math/i386/fmodf.s +++ /dev/null @@ -1,11 +0,0 @@ -.global fmodf -.type fmodf,@function -fmodf: - flds 8(%esp) - flds 4(%esp) -1: fprem - fnstsw %ax - sahf - jp 1b - fstp %st(1) - ret diff --git a/src/math/i386/fmodl.c b/src/math/i386/fmodl.c new file mode 100644 index 00000000..3daeab06 --- /dev/null +++ b/src/math/i386/fmodl.c @@ -0,0 +1,9 @@ +#include <math.h> + +long double fmodl(long double x, long double y) +{ + unsigned short fpsr; + do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); + while (fpsr & 0x400); + return x; +} diff --git a/src/math/i386/fmodl.s b/src/math/i386/fmodl.s deleted file mode 100644 index 0cb3fe9b..00000000 --- a/src/math/i386/fmodl.s +++ /dev/null @@ -1,11 +0,0 @@ -.global fmodl -.type fmodl,@function -fmodl: - fldt 16(%esp) - fldt 4(%esp) -1: fprem - fnstsw %ax - sahf - jp 1b - fstp %st(1) - ret diff --git a/src/math/i386/llrint.c b/src/math/i386/llrint.c new file mode 100644 index 00000000..aa400817 --- /dev/null +++ b/src/math/i386/llrint.c @@ -0,0 +1,8 @@ +#include <math.h> + +long long llrint(double x) +{ + long long r; + __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st"); + return r; +} diff --git a/src/math/i386/llrint.s b/src/math/i386/llrint.s deleted file mode 100644 index 8e89cd91..00000000 --- a/src/math/i386/llrint.s +++ /dev/null @@ -1,8 +0,0 @@ -.global llrint -.type llrint,@function -llrint: - fldl 4(%esp) - fistpll 4(%esp) - mov 4(%esp),%eax - mov 8(%esp),%edx - ret diff --git a/src/math/i386/llrintf.c b/src/math/i386/llrintf.c new file mode 100644 index 00000000..c41a317b --- /dev/null +++ b/src/math/i386/llrintf.c @@ -0,0 +1,8 @@ +#include <math.h> + +long long llrintf(float x) +{ + long long r; + __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st"); + return r; +} diff --git a/src/math/i386/llrintf.s b/src/math/i386/llrintf.s deleted file mode 100644 index aa850c6c..00000000 --- a/src/math/i386/llrintf.s +++ /dev/null @@ -1,9 +0,0 @@ -.global llrintf -.type llrintf,@function -llrintf: - sub $8,%esp - flds 12(%esp) - fistpll (%esp) - pop %eax - pop %edx - ret diff --git a/src/math/i386/llrintl.c b/src/math/i386/llrintl.c new file mode 100644 index 00000000..c439ef28 --- /dev/null +++ b/src/math/i386/llrintl.c @@ -0,0 +1,8 @@ +#include <math.h> + +long long llrintl(long double x) +{ + long long r; + __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st"); + return r; +} diff --git a/src/math/i386/llrintl.s b/src/math/i386/llrintl.s deleted file mode 100644 index 1cfb56f1..00000000 --- a/src/math/i386/llrintl.s +++ /dev/null @@ -1,8 +0,0 @@ -.global llrintl -.type llrintl,@function -llrintl: - fldt 4(%esp) - fistpll 4(%esp) - mov 4(%esp),%eax - mov 8(%esp),%edx - ret diff --git a/src/math/i386/log.s b/src/math/i386/log.s index fcccf030..08c59924 100644 --- a/src/math/i386/log.s +++ b/src/math/i386/log.s @@ -4,4 +4,6 @@ log: fldln2 fldl 4(%esp) fyl2x + fstpl 4(%esp) + fldl 4(%esp) ret diff --git a/src/math/i386/log10.s b/src/math/i386/log10.s index 28eb5b2f..120e91ec 100644 --- a/src/math/i386/log10.s +++ b/src/math/i386/log10.s @@ -4,4 +4,6 @@ log10: fldlg2 fldl 4(%esp) fyl2x + fstpl 4(%esp) + fldl 4(%esp) ret diff --git a/src/math/i386/log10f.s b/src/math/i386/log10f.s index c0c0c67e..b055493a 100644 --- a/src/math/i386/log10f.s +++ b/src/math/i386/log10f.s @@ -4,4 +4,6 @@ log10f: fldlg2 flds 4(%esp) fyl2x + fstps 4(%esp) + flds 4(%esp) ret diff --git a/src/math/i386/log1p.s b/src/math/i386/log1p.s index 354f391a..f3c95f83 100644 --- a/src/math/i386/log1p.s +++ b/src/math/i386/log1p.s @@ -10,10 +10,14 @@ log1p: cmp $0x00100000,%eax jb 2f fyl2xp1 + fstpl 4(%esp) + fldl 4(%esp) ret 1: fld1 faddp fyl2x + fstpl 4(%esp) + fldl 4(%esp) ret # subnormal x, return x with underflow 2: fsts 4(%esp) diff --git a/src/math/i386/log1pf.s b/src/math/i386/log1pf.s index 4d3484cd..9f13d95f 100644 --- a/src/math/i386/log1pf.s +++ b/src/math/i386/log1pf.s @@ -10,10 +10,14 @@ log1pf: cmp $0x00800000,%eax jb 2f fyl2xp1 + fstps 4(%esp) + flds 4(%esp) ret 1: fld1 faddp fyl2x + fstps 4(%esp) + flds 4(%esp) ret # subnormal x, return x with underflow 2: fxch diff --git a/src/math/i386/log2.s b/src/math/i386/log2.s index 15088037..7eff0b61 100644 --- a/src/math/i386/log2.s +++ b/src/math/i386/log2.s @@ -4,4 +4,6 @@ log2: fld1 fldl 4(%esp) fyl2x + fstpl 4(%esp) + fldl 4(%esp) ret diff --git a/src/math/i386/log2f.s b/src/math/i386/log2f.s index 00cdce75..b32fa2f7 100644 --- a/src/math/i386/log2f.s +++ b/src/math/i386/log2f.s @@ -4,4 +4,6 @@ log2f: fld1 flds 4(%esp) fyl2x + fstps 4(%esp) + flds 4(%esp) ret diff --git a/src/math/i386/logf.s b/src/math/i386/logf.s index da7ff3ae..4d0346a4 100644 --- a/src/math/i386/logf.s +++ b/src/math/i386/logf.s @@ -4,4 +4,6 @@ logf: fldln2 flds 4(%esp) fyl2x + fstps 4(%esp) + flds 4(%esp) ret diff --git a/src/math/i386/lrint.c b/src/math/i386/lrint.c new file mode 100644 index 00000000..89563ab2 --- /dev/null +++ b/src/math/i386/lrint.c @@ -0,0 +1,8 @@ +#include <math.h> + +long lrint(double x) +{ + long r; + __asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); + return r; +} diff --git a/src/math/i386/lrint.s b/src/math/i386/lrint.s deleted file mode 100644 index 02b83d9f..00000000 --- a/src/math/i386/lrint.s +++ /dev/null @@ -1,7 +0,0 @@ -.global lrint -.type lrint,@function -lrint: - fldl 4(%esp) - fistpl 4(%esp) - mov 4(%esp),%eax - ret diff --git a/src/math/i386/lrintf.c b/src/math/i386/lrintf.c new file mode 100644 index 00000000..0bbf29de --- /dev/null +++ b/src/math/i386/lrintf.c @@ -0,0 +1,8 @@ +#include <math.h> + +long lrintf(float x) +{ + long r; + __asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); + return r; +} diff --git a/src/math/i386/lrintf.s b/src/math/i386/lrintf.s deleted file mode 100644 index 907aac29..00000000 --- a/src/math/i386/lrintf.s +++ /dev/null @@ -1,7 +0,0 @@ -.global lrintf -.type lrintf,@function -lrintf: - flds 4(%esp) - fistpl 4(%esp) - mov 4(%esp),%eax - ret diff --git a/src/math/i386/lrintl.c b/src/math/i386/lrintl.c new file mode 100644 index 00000000..eb8c0902 --- /dev/null +++ b/src/math/i386/lrintl.c @@ -0,0 +1,8 @@ +#include <math.h> + +long lrintl(long double x) +{ + long r; + __asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); + return r; +} diff --git a/src/math/i386/lrintl.s b/src/math/i386/lrintl.s deleted file mode 100644 index 3ae05aac..00000000 --- a/src/math/i386/lrintl.s +++ /dev/null @@ -1,7 +0,0 @@ -.global lrintl -.type lrintl,@function -lrintl: - fldt 4(%esp) - fistpl 4(%esp) - mov 4(%esp),%eax - ret diff --git a/src/math/i386/remainder.c b/src/math/i386/remainder.c new file mode 100644 index 00000000..c083df90 --- /dev/null +++ b/src/math/i386/remainder.c @@ -0,0 +1,12 @@ +#include <math.h> + +double remainder(double x, double y) +{ + unsigned short fpsr; + // fprem1 does not introduce excess precision into x + do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); + while (fpsr & 0x400); + return x; +} + +weak_alias(remainder, drem); diff --git a/src/math/i386/remainder.s b/src/math/i386/remainder.s deleted file mode 100644 index ab1da95d..00000000 --- a/src/math/i386/remainder.s +++ /dev/null @@ -1,14 +0,0 @@ -.global remainder -.type remainder,@function -remainder: -.weak drem -.type drem,@function -drem: - fldl 12(%esp) - fldl 4(%esp) -1: fprem1 - fnstsw %ax - sahf - jp 1b - fstp %st(1) - ret diff --git a/src/math/i386/remainderf.c b/src/math/i386/remainderf.c new file mode 100644 index 00000000..280207d2 --- /dev/null +++ b/src/math/i386/remainderf.c @@ -0,0 +1,12 @@ +#include <math.h> + +float remainderf(float x, float y) +{ + unsigned short fpsr; + // fprem1 does not introduce excess precision into x + do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); + while (fpsr & 0x400); + return x; +} + +weak_alias(remainderf, dremf); diff --git a/src/math/i386/remainderf.s b/src/math/i386/remainderf.s deleted file mode 100644 index 6a7378a3..00000000 --- a/src/math/i386/remainderf.s +++ /dev/null @@ -1,14 +0,0 @@ -.global remainderf -.type remainderf,@function -remainderf: -.weak dremf -.type dremf,@function -dremf: - flds 8(%esp) - flds 4(%esp) -1: fprem1 - fnstsw %ax - sahf - jp 1b - fstp %st(1) - ret diff --git a/src/math/i386/remainderl.c b/src/math/i386/remainderl.c new file mode 100644 index 00000000..8cf75071 --- /dev/null +++ b/src/math/i386/remainderl.c @@ -0,0 +1,9 @@ +#include <math.h> + +long double remainderl(long double x, long double y) +{ + unsigned short fpsr; + do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); + while (fpsr & 0x400); + return x; +} diff --git a/src/math/i386/remainderl.s b/src/math/i386/remainderl.s deleted file mode 100644 index b41518ed..00000000 --- a/src/math/i386/remainderl.s +++ /dev/null @@ -1,11 +0,0 @@ -.global remainderl -.type remainderl,@function -remainderl: - fldt 16(%esp) - fldt 4(%esp) -1: fprem1 - fnstsw %ax - sahf - jp 1b - fstp %st(1) - ret diff --git a/src/math/i386/rint.c b/src/math/i386/rint.c new file mode 100644 index 00000000..a5276a60 --- /dev/null +++ b/src/math/i386/rint.c @@ -0,0 +1,7 @@ +#include <math.h> + +double rint(double x) +{ + __asm__ ("frndint" : "+t"(x)); + return x; +} diff --git a/src/math/i386/rint.s b/src/math/i386/rint.s deleted file mode 100644 index bb99a11c..00000000 --- a/src/math/i386/rint.s +++ /dev/null @@ -1,6 +0,0 @@ -.global rint -.type rint,@function -rint: - fldl 4(%esp) - frndint - ret diff --git a/src/math/i386/rintf.c b/src/math/i386/rintf.c new file mode 100644 index 00000000..bb4121a4 --- /dev/null +++ b/src/math/i386/rintf.c @@ -0,0 +1,7 @@ +#include <math.h> + +float rintf(float x) +{ + __asm__ ("frndint" : "+t"(x)); + return x; +} diff --git a/src/math/i386/rintf.s b/src/math/i386/rintf.s deleted file mode 100644 index bce4c5a6..00000000 --- a/src/math/i386/rintf.s +++ /dev/null @@ -1,6 +0,0 @@ -.global rintf -.type rintf,@function -rintf: - flds 4(%esp) - frndint - ret diff --git a/src/math/i386/rintl.c b/src/math/i386/rintl.c new file mode 100644 index 00000000..e1a92077 --- /dev/null +++ b/src/math/i386/rintl.c @@ -0,0 +1,7 @@ +#include <math.h> + +long double rintl(long double x) +{ + __asm__ ("frndint" : "+t"(x)); + return x; +} diff --git a/src/math/i386/rintl.s b/src/math/i386/rintl.s deleted file mode 100644 index cd2bf9a9..00000000 --- a/src/math/i386/rintl.s +++ /dev/null @@ -1,6 +0,0 @@ -.global rintl -.type rintl,@function -rintl: - fldt 4(%esp) - frndint - ret diff --git a/src/math/i386/sqrt.c b/src/math/i386/sqrt.c new file mode 100644 index 00000000..934fbcca --- /dev/null +++ b/src/math/i386/sqrt.c @@ -0,0 +1,15 @@ +#include "libm.h" + +double sqrt(double x) +{ + union ldshape ux; + unsigned fpsr; + __asm__ ("fsqrt; fnstsw %%ax": "=t"(ux.f), "=a"(fpsr) : "0"(x)); + if ((ux.i.m & 0x7ff) != 0x400) + return (double)ux.f; + /* Rounding to double would have encountered an exact halfway case. + Adjust mantissa downwards if fsqrt rounded up, else upwards. + (result of fsqrt could not have been exact) */ + ux.i.m ^= (fpsr & 0x200) + 0x300; + return (double)ux.f; +} diff --git a/src/math/i386/sqrt.s b/src/math/i386/sqrt.s deleted file mode 100644 index 57837e25..00000000 --- a/src/math/i386/sqrt.s +++ /dev/null @@ -1,21 +0,0 @@ -.global sqrt -.type sqrt,@function -sqrt: fldl 4(%esp) - fsqrt - fnstsw %ax - sub $12,%esp - fld %st(0) - fstpt (%esp) - mov (%esp),%ecx - and $0x7ff,%ecx - cmp $0x400,%ecx - jnz 1f - and $0x200,%eax - sub $0x100,%eax - sub %eax,(%esp) - fstp %st(0) - fldt (%esp) -1: add $12,%esp - fstpl 4(%esp) - fldl 4(%esp) - ret diff --git a/src/math/i386/sqrtf.c b/src/math/i386/sqrtf.c new file mode 100644 index 00000000..41c65c2b --- /dev/null +++ b/src/math/i386/sqrtf.c @@ -0,0 +1,12 @@ +#include <math.h> + +float sqrtf(float x) +{ + long double t; + /* The long double result has sufficient precision so that + * second rounding to float still keeps the returned value + * correctly rounded, see Pierre Roux, "Innocuous Double + * Rounding of Basic Arithmetic Operations". */ + __asm__ ("fsqrt" : "=t"(t) : "0"(x)); + return (float)t; +} diff --git a/src/math/i386/sqrtf.s b/src/math/i386/sqrtf.s deleted file mode 100644 index 9e944f45..00000000 --- a/src/math/i386/sqrtf.s +++ /dev/null @@ -1,7 +0,0 @@ -.global sqrtf -.type sqrtf,@function -sqrtf: flds 4(%esp) - fsqrt - fstps 4(%esp) - flds 4(%esp) - ret diff --git a/src/math/i386/sqrtl.c b/src/math/i386/sqrtl.c new file mode 100644 index 00000000..864cfcc4 --- /dev/null +++ b/src/math/i386/sqrtl.c @@ -0,0 +1,7 @@ +#include <math.h> + +long double sqrtl(long double x) +{ + __asm__ ("fsqrt" : "+t"(x)); + return x; +} diff --git a/src/math/i386/sqrtl.s b/src/math/i386/sqrtl.s deleted file mode 100644 index e0d42616..00000000 --- a/src/math/i386/sqrtl.s +++ /dev/null @@ -1,5 +0,0 @@ -.global sqrtl -.type sqrtl,@function -sqrtl: fldt 4(%esp) - fsqrt - ret |