This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix x86 / x86_64 expl, exp10l missing underflows (bug 16361) [committed]


Similar to various other bugs in this area, the x86 and x86_64
implementations of expl / exp10l can fail to produce underflow
exceptions when the unscaled result has trailing 0 bits so the scaling
down to subnormal precision is exact.  This patch fixes this by
forcing the exception in the case of tiny results.

Tested for x86_64 and x86.  Committed.

(auto-libm-test-out diffs omitted below.)

2015-06-21  Joseph Myers  <joseph@codesourcery.com>

	[BZ #16361]
	* sysdeps/i386/fpu/e_expl.S [!USE_AS_EXPM1L] (cmin): New object.
	[!USE_AS_EXPM1L] (IEEE754_EXPL): Force underflow exception for
	tiny results.
	* sysdeps/x86_64/fpu/e_expl.S [!USE_AS_EXPM1L] (cmin): New object.
	[!USE_AS_EXPM1L] (IEEE754_EXPL): Force underflow exception for
	tiny results.
	* math/auto-libm-test-in: Add more tests of exp and exp10.  Do not
	mark underflow exceptions as possibly missing for bug 16361.
	* math/auto-libm-test-out: Regenerated.

diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in
index 6ec4bc6..e8e4da6 100644
--- a/math/auto-libm-test-in
+++ b/math/auto-libm-test-in
@@ -1191,6 +1191,7 @@ exp -7.4444006192138124e+02
 exp -0x1.75f113c30b1c8p+9
 exp -max
 exp -11342.8125
+exp -0x2.c5b2319c4843acc0p12
 exp 0x1p-10
 exp -0x1p-10
 exp 0x1p-20
@@ -1223,8 +1224,8 @@ exp10 305
 exp10 -305
 # GCC bug 59666: results on directed rounding may be incorrect.
 exp10 4932 xfail-rounding:ldbl-128ibm
-# Bug 16361: underflow exception may be misssing
-exp10 -4932 missing-underflow:ldbl-96-intel:x86 missing-underflow:ldbl-96-intel:x86_64
+exp10 -4932
+exp10 -0x1.343793004f503232p12
 # GCC bug 59666: results on directed rounding may be incorrect.
 exp10 1e5 xfail-rounding:ldbl-128ibm
 exp10 -1e5
diff --git a/sysdeps/i386/fpu/e_expl.S b/sysdeps/i386/fpu/e_expl.S
index c7e4373..74968bb 100644
--- a/sysdeps/i386/fpu/e_expl.S
+++ b/sysdeps/i386/fpu/e_expl.S
@@ -65,6 +65,10 @@ c1:	.byte 0x20, 0xfa, 0xee, 0xc2, 0x5f, 0x70, 0xa5, 0xec, 0xed, 0x3f
 csat:	.byte 0, 0, 0, 0, 0, 0, 0, 0x80, 0x0e, 0x40
 	.byte 0, 0, 0, 0, 0, 0
 	ASM_SIZE_DIRECTIVE(csat)
+	.type cmin,@object
+cmin:	.byte 0, 0, 0, 0, 0, 0, 0, 0x80, 0x1, 0
+	.byte 0, 0, 0, 0, 0, 0
+	ASM_SIZE_DIRECTIVE(cmin)
 #endif
 
 #ifdef PIC
@@ -189,8 +193,18 @@ ENTRY(IEEE754_EXPL)
 	fstp	%st(1)		/* 2  */
 	fscale			/* 2 scale factor is st(1); base^x */
 	fstp	%st(1)		/* 1  */
+	/* Ensure underflow for tiny result.  */
+	fldt	MO(cmin)	/* 2 cmin  */
+	fld	%st(1)		/* 3  */
+	fcompp			/* 1  */
+	fnstsw
+	sahf
+	jnc	6f
+	fld	%st
+	fmul	%st
+	fstp	%st
 #endif
-	fstp	%st(1)		/* 0  */
+6:	fstp	%st(1)		/* 0  */
 	jmp	2f
 1:
 #ifdef USE_AS_EXPM1L
diff --git a/sysdeps/x86_64/fpu/e_expl.S b/sysdeps/x86_64/fpu/e_expl.S
index 0ebe388..866bad2 100644
--- a/sysdeps/x86_64/fpu/e_expl.S
+++ b/sysdeps/x86_64/fpu/e_expl.S
@@ -65,6 +65,10 @@ c1:	.byte 0x20, 0xfa, 0xee, 0xc2, 0x5f, 0x70, 0xa5, 0xec, 0xed, 0x3f
 csat:	.byte 0, 0, 0, 0, 0, 0, 0, 0x80, 0x0e, 0x40
 	.byte 0, 0, 0, 0, 0, 0
 	ASM_SIZE_DIRECTIVE(csat)
+	.type cmin,@object
+cmin:	.byte 0, 0, 0, 0, 0, 0, 0, 0x80, 0x1, 0
+	.byte 0, 0, 0, 0, 0, 0
+	ASM_SIZE_DIRECTIVE(cmin)
 #endif
 
 #ifdef PIC
@@ -182,8 +186,17 @@ ENTRY(IEEE754_EXPL)
 	fstp	%st(1)		/* 2  */
 	fscale			/* 2 scale factor is st(1); base^x */
 	fstp	%st(1)		/* 1  */
+	/* Ensure underflow for tiny result.  */
+	fldt	MO(cmin)	/* 2 cmin  */
+	fld	%st(1)		/* 3  */
+	fcomip	%st(1), %st	/* 2  */
+	fstp	%st		/* 1  */
+	jnc	6f
+	fld	%st
+	fmul	%st
+	fstp	%st
 #endif
-	fstp	%st(1)		/* 0  */
+6:	fstp	%st(1)		/* 0  */
 	jmp	2f
 1:
 #ifdef USE_AS_EXPM1L

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]