summaryrefslogtreecommitdiff
path: root/sysdeps/i386/fpu
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2012-05-07 19:13:08 +0000
committerJoseph Myers <joseph@codesourcery.com>2012-05-07 19:13:08 +0000
commit495fd99f3a119e5c0c542ccc6cf9c93b1fb9e892 (patch)
tree946a0ea8ff908e0770368c1d85e8d4355b5da415 /sysdeps/i386/fpu
parent6693d69429d92682bdb85d36ae8e4335c393c467 (diff)
downloadglibc-495fd99f3a119e5c0c542ccc6cf9c93b1fb9e892.tar.gz
Fix x86/x86_64 expm1l inaccuracy and exceptions (bugs 13885, 13923).
Diffstat (limited to 'sysdeps/i386/fpu')
-rw-r--r--sysdeps/i386/fpu/e_expl.S45
-rw-r--r--sysdeps/i386/fpu/libm-test-ulps64
-rw-r--r--sysdeps/i386/fpu/s_expm1l.S91
3 files changed, 68 insertions, 132 deletions
diff --git a/sysdeps/i386/fpu/e_expl.S b/sysdeps/i386/fpu/e_expl.S
index 9adf2a489e..bab0a081b8 100644
--- a/sysdeps/i386/fpu/e_expl.S
+++ b/sysdeps/i386/fpu/e_expl.S
@@ -28,6 +28,10 @@
# define IEEE754_EXPL __ieee754_exp10l
# define EXPL_FINITE __exp10l_finite
# define FLDLOG fldl2t
+#elif defined USE_AS_EXPM1L
+# define IEEE754_EXPL __expm1l
+# undef EXPL_FINITE
+# define FLDLOG fldl2e
#else
# define IEEE754_EXPL __ieee754_expl
# define EXPL_FINITE __expl_finite
@@ -69,6 +73,12 @@ csat: .byte 0, 0, 0, 0, 0, 0, 0, 0x80, 0x0e, 0x40
.text
ENTRY(IEEE754_EXPL)
+#ifdef USE_AS_EXPM1L
+ movzwl 4+8(%esp), %eax
+ xorb $0x80, %ah // invert sign bit (now 1 is "positive")
+ cmpl $0xc006, %eax // is num positive and exp >= 6 (number is >= 128.0)?
+ jae HIDDEN_JUMPTARGET (__expl) // (if num is denormal, it is at least >= 64.0)
+#endif
fldt 4(%esp)
/* I added the following ugly construct because expl(+-Inf) resulted
in NaN. The ugliness results from the bright minds at Intel.
@@ -78,7 +88,9 @@ ENTRY(IEEE754_EXPL)
#ifdef PIC
LOAD_PIC_REG (cx)
#endif
+#ifndef USE_AS_EXPM1L
movzwl 4+8(%esp), %eax
+#endif
andl $0x7fff, %eax
cmpl $0x400d, %eax
jle 3f
@@ -96,7 +108,16 @@ ENTRY(IEEE754_EXPL)
andb $2, %ah
jz 3f
fchs
-3: FLDLOG /* 1 log2(base) */
+3:
+#ifdef USE_AS_EXPM1L
+ /* Test for +-0 as argument. */
+ fstsw %ax
+ movb $0x45, %dh
+ andb %ah, %dh
+ cmpb $0x40, %dh
+ je 2f
+#endif
+ FLDLOG /* 1 log2(base) */
fmul %st(1), %st /* 1 x log2(base) */
frndint /* 1 i */
fld %st(1) /* 2 x */
@@ -114,17 +135,39 @@ ENTRY(IEEE754_EXPL)
fmul %st(4), %st /* 4 c1 * x */
faddp %st, %st(1) /* 3 f = f + c1 * x */
f2xm1 /* 3 2^(fract(x * log2(base))) - 1 */
+#ifdef USE_AS_EXPM1L
+ fstp %st(1) /* 2 */
+ fscale /* 2 scale factor is st(1); base^x - 2^i */
+ fxch /* 2 i */
+ fld1 /* 3 1.0 */
+ fscale /* 3 2^i */
+ fld1 /* 4 1.0 */
+ fsubrp %st, %st(1) /* 3 2^i - 1.0 */
+ fstp %st(1) /* 2 */
+ faddp %st, %st(1) /* 1 base^x - 1.0 */
+#else
fld1 /* 4 1.0 */
faddp /* 3 2^(fract(x * log2(base))) */
fstp %st(1) /* 2 */
fscale /* 2 scale factor is st(1); base^x */
fstp %st(1) /* 1 */
+#endif
fstp %st(1) /* 0 */
jmp 2f
1: testl $0x200, %eax /* Test sign. */
jz 2f /* If positive, jump. */
fstp %st
+#ifdef USE_AS_EXPM1L
+ fld1
+ fchs
+#else
fldz /* Set result to 0. */
+#endif
2: ret
END(IEEE754_EXPL)
+#ifdef USE_AS_EXPM1L
+libm_hidden_def (__expm1l)
+weak_alias (__expm1l, expm1l)
+#else
strong_alias (IEEE754_EXPL, EXPL_FINITE)
+#endif
diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps
index 63235537e0..cdc26a0c63 100644
--- a/sysdeps/i386/fpu/libm-test-ulps
+++ b/sysdeps/i386/fpu/libm-test-ulps
@@ -1008,10 +1008,6 @@ Test "cos_upward (9) == -0.9111302618846769883682947111811653112463":
ildouble: 1
ldouble: 1
-# cosh
-Test "cosh (0.75) == 1.29468328467684468784170818539018176":
-ildouble: 1
-
# cosh_downward
Test "cosh_downward (22) == 1792456423.065795780980053377632656584997":
double: 1
@@ -1899,29 +1895,20 @@ double: 1
float: 1
idouble: 1
ifloat: 1
-ildouble: 4
-ldouble: 4
+ildouble: 2
+ldouble: 2
Test "sinh_downward (23) == 4872401723.124451299966006944252978187305":
double: 1
float: 1
idouble: 1
ifloat: 1
+ildouble: 2
+ldouble: 2
Test "sinh_downward (24) == 13244561064.92173614705070540368454568168":
float: 1
ifloat: 1
-ildouble: 5
-ldouble: 5
-
-# sinh_tonearest
-Test "sinh_tonearest (22) == 1792456423.065795780701106568345764104225":
-ildouble: 3
-ldouble: 3
-Test "sinh_tonearest (23) == 4872401723.124451299966006944252978187305":
-ildouble: 1
-ldouble: 1
-Test "sinh_tonearest (24) == 13244561064.92173614705070540368454568168":
-ildouble: 6
-ldouble: 6
+ildouble: 2
+ldouble: 2
# sinh_towardzero
Test "sinh_towardzero (22) == 1792456423.065795780701106568345764104225":
@@ -1929,31 +1916,31 @@ double: 1
float: 1
idouble: 1
ifloat: 1
-ildouble: 4
-ldouble: 4
+ildouble: 2
+ldouble: 2
Test "sinh_towardzero (23) == 4872401723.124451299966006944252978187305":
double: 1
float: 1
idouble: 1
ifloat: 1
+ildouble: 2
+ldouble: 2
Test "sinh_towardzero (24) == 13244561064.92173614705070540368454568168":
float: 1
ifloat: 1
-ildouble: 5
-ldouble: 5
+ildouble: 2
+ldouble: 2
# sinh_upward
Test "sinh_upward (22) == 1792456423.065795780701106568345764104225":
-ildouble: 16
-ldouble: 16
+ildouble: 1
+ldouble: 1
Test "sinh_upward (23) == 4872401723.124451299966006944252978187305":
-ildouble: 27
-ldouble: 27
+ildouble: 1
+ldouble: 1
Test "sinh_upward (24) == 13244561064.92173614705070540368454568168":
double: 1
idouble: 1
-ildouble: 7
-ldouble: 7
# tan
Test "tan (0x1p16383) == 0.422722393732022337800504160054440141575":
@@ -2587,9 +2574,6 @@ ifloat: 1
ildouble: 1
ldouble: 1
-Function: "cosh":
-ildouble: 1
-
Function: "cosh_downward":
double: 1
float: 1
@@ -2862,26 +2846,22 @@ double: 1
float: 1
idouble: 1
ifloat: 1
-ildouble: 5
-ldouble: 5
-
-Function: "sinh_tonearest":
-ildouble: 6
-ldouble: 6
+ildouble: 2
+ldouble: 2
Function: "sinh_towardzero":
double: 1
float: 1
idouble: 1
ifloat: 1
-ildouble: 5
-ldouble: 5
+ildouble: 2
+ldouble: 2
Function: "sinh_upward":
double: 1
idouble: 1
-ildouble: 27
-ldouble: 27
+ildouble: 1
+ldouble: 1
Function: "tan":
double: 1
diff --git a/sysdeps/i386/fpu/s_expm1l.S b/sysdeps/i386/fpu/s_expm1l.S
index e91f18b694..7fbd99b0db 100644
--- a/sysdeps/i386/fpu/s_expm1l.S
+++ b/sysdeps/i386/fpu/s_expm1l.S
@@ -1,89 +1,2 @@
-/* ix87 specific implementation of exp(x)-1.
- Copyright (C) 1996-1997, 2002, 2005, 2008, 2012 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
- Based on code by John C. Bowman <bowman@ipp-garching.mpg.de>.
- Corrections by H.J. Lu (hjl@gnu.ai.mit.edu), 1997.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
-
- /* Using: e^x - 1 = 2^(x * log2(e)) - 1 */
-
-#include <sysdep.h>
-#include <machine/asm.h>
-
- .section .rodata
-
- .align ALIGNARG(4)
- ASM_TYPE_DIRECTIVE(minus1,@object)
-minus1: .double -1.0
- ASM_SIZE_DIRECTIVE(minus1)
- ASM_TYPE_DIRECTIVE(one,@object)
-one: .double 1.0
- ASM_SIZE_DIRECTIVE(one)
- ASM_TYPE_DIRECTIVE(l2e,@object)
-l2e: .tfloat 1.442695040888963407359924681002
- ASM_SIZE_DIRECTIVE(l2e)
-
-#ifdef PIC
-#define MO(op) op##@GOTOFF(%edx)
-#else
-#define MO(op) op
-#endif
-
- .text
-ENTRY(__expm1l)
- movzwl 4+8(%esp), %eax // load sign bit and 15-bit exponent
- xorb $0x80, %ah // invert sign bit (now 1 is "positive")
- cmpl $0xc006, %eax // is num positive and exp >= 6 (number is >= 128.0)?
- jae HIDDEN_JUMPTARGET (__expl) // (if num is denormal, it is at least >= 64.0)
-
- fldt 4(%esp) // x
- fxam // Is NaN or +-Inf?
- fstsw %ax
- movb $0x45, %ch
- andb %ah, %ch
- cmpb $0x40, %ch
- je 3f // If +-0, jump.
-#ifdef PIC
- LOAD_PIC_REG (dx)
-#endif
- cmpb $0x05, %ch
- je 2f // If +-Inf, jump.
-
- fldt MO(l2e) // log2(e) : x
- fmulp // log2(e)*x
- fld %st // log2(e)*x : log2(e)*x
- frndint // int(log2(e)*x) : log2(e)*x
- fsubr %st, %st(1) // int(log2(e)*x) : fract(log2(e)*x)
- fxch // fract(log2(e)*x) : int(log2(e)*x)
- f2xm1 // 2^fract(log2(e)*x)-1 : int(log2(e)*x)
- fscale // 2^(log2(e)*x)-2^int(log2(e)*x) : int(log2(e)*x)
- fxch // int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
- fldl MO(one) // 1 : int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
- fscale // 2^int(log2(e)*x) : int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
- fsubrl MO(one) // 1-2^int(log2(e)*x) : int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
- fstp %st(1) // 1-2^int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
- fsubrp %st, %st(1) // 2^(log2(e)*x)
- ret
-
-2: testl $0x200, %eax // Test sign.
- jz 3f // If positive, jump.
- fstp %st
- fldl MO(minus1) // Set result to -1.0.
-3: ret
-END(__expm1l)
-libm_hidden_def (__expm1l)
-weak_alias (__expm1l, expm1l)
+#define USE_AS_EXPM1L
+#include <e_expl.S>