From aa1b4dff45788f8205e32ea01da243fe09568aa8 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 18 Mar 2012 23:17:28 -0400 Subject: [PATCH] fix broken exponential asm infinities were getting converted into nans. the new code simply tests for infinity and replaces it with a large magnitude value of the same sign. also, the fcomi instruction is apparently not part of the i387 instruction set, so avoid using it. --- src/math/i386/exp.s | 9 +++++++++ src/math/i386/expm1.s | 13 ++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/math/i386/exp.s b/src/math/i386/exp.s index 18f6cd67..f4769d59 100644 --- a/src/math/i386/exp.s +++ b/src/math/i386/exp.s @@ -34,6 +34,15 @@ exp: .type exp2,@function exp2: fldl 4(%esp) +1: fxam + fnstsw %ax + sahf + jnp 1f + jnc 1f + fstps 4(%esp) + mov $0xfe,%al + and %al,7(%esp) + flds 4(%esp) 1: fld %st(0) frndint fxch %st(1) diff --git a/src/math/i386/expm1.s b/src/math/i386/expm1.s index d6d511ef..bbb5d12e 100644 --- a/src/math/i386/expm1.s +++ b/src/math/i386/expm1.s @@ -14,12 +14,23 @@ expm1l: .type expm1,@function expm1: fldl 4(%esp) +1: fxam + fnstsw %ax + sahf + jnp 1f + jnc 1f + fstps 4(%esp) + mov $0xfe,%al + and %al,7(%esp) + flds 4(%esp) 1: fldl2e fmulp fld %st(0) frndint fldz - fcompi + fcomp + fnstsw %ax + sahf jnz 1f fstp %st(0) f2xm1 -- 2.25.1