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 spurious "inexact" exceptions from x86 pow with NaN argument (bug 16167)


Bug 16167 is x86 / x86_64 pow functions wrongly raising the "inexact"
exception for some cases of NaN input, when according to ISO C NaN
inputs returning NaN outputs should generally raise no exceptions at
all.  This patch adds appropriate tests for this case to the
implementations.

Tested x86_64 and x86, together with my separate patch to make
libm-test.inc check this ISO C requirement (intended to go in
immediately after this one).

2013-11-13  Joseph Myers  <joseph@codesourcery.com>

	[BZ #16167]
	* sysdeps/i386/fpu/e_pow.S (__ieee754_pow): Check for first
	argument being NaN and avoid computations with second argument in
	that case.
	* sysdeps/i386/fpu/e_powf.S (__ieee754_powf): Likewise.
	* sysdeps/i386/fpu/e_powl.S (__ieee754_powl): Likewise.
	* sysdeps/x86_64/fpu/e_powl.S (__ieee754_powl): Likewise.

diff --git a/sysdeps/i386/fpu/e_pow.S b/sysdeps/i386/fpu/e_pow.S
index 109c395..835c39b 100644
--- a/sysdeps/i386/fpu/e_pow.S
+++ b/sysdeps/i386/fpu/e_pow.S
@@ -98,6 +98,9 @@ ENTRY(__ieee754_pow)
 	cmpb	$0x05, %ah
 	je	15f		// x is ħinf
 
+	cmpb	$0x01, %ah
+	je	32f		// x is NaN
+
 	fxch			// y : x
 
 	/* fistpll raises invalid exception for |y| >= 1L<<63.  */
@@ -166,6 +169,12 @@ ENTRY(__ieee754_pow)
 	ret
 
 	cfi_adjust_cfa_offset (8)
+32:	addl	$8, %esp
+	cfi_adjust_cfa_offset (-8)
+	fstp	%st(1)
+	ret
+
+	cfi_adjust_cfa_offset (8)
 	.align ALIGNARG(4)
 2:	// y is a large integer (absolute value at least 1L<<10), but
 	// may be odd unless at least 1L<<64.  So it may be necessary
diff --git a/sysdeps/i386/fpu/e_powf.S b/sysdeps/i386/fpu/e_powf.S
index 7fad90f..90d3d0c 100644
--- a/sysdeps/i386/fpu/e_powf.S
+++ b/sysdeps/i386/fpu/e_powf.S
@@ -95,6 +95,9 @@ ENTRY(__ieee754_powf)
 	cmpb	$0x05, %ah
 	je	15f		// x is ħinf
 
+	cmpb	$0x01, %ah
+	je	32f		// x is NaN
+
 	fxch			// y : x
 
 	/* fistpl raises invalid exception for |y| >= 1L<<31.  */
@@ -180,7 +183,7 @@ ENTRY(__ieee754_powf)
 	f2xm1			// 2^fract(y*log2(x))-1 : int(y*log2(x))
 	faddl	MO(one)		// 2^fract(y*log2(x)) : int(y*log2(x))
 	fscale			// 2^fract(y*log2(x))*2^int(y*log2(x)) : int(y*log2(x))
-	addl	$4, %esp
+32:	addl	$4, %esp
 	cfi_adjust_cfa_offset (-4)
 	fstp	%st(1)		// 2^fract(y*log2(x))*2^int(y*log2(x))
 	ret
diff --git a/sysdeps/i386/fpu/e_powl.S b/sysdeps/i386/fpu/e_powl.S
index 3c23117..91e22c8 100644
--- a/sysdeps/i386/fpu/e_powl.S
+++ b/sysdeps/i386/fpu/e_powl.S
@@ -104,6 +104,9 @@ ENTRY(__ieee754_powl)
 	cmpb	$0x05, %ah
 	je	15f		// x is ħinf
 
+	cmpb	$0x01, %ah
+	je	32f		// x is NaN
+
 	fxch			// y : x
 
 	/* fistpll raises invalid exception for |y| >= 1L<<63.  */
@@ -188,6 +191,12 @@ ENTRY(__ieee754_powl)
 	ret
 
 	cfi_adjust_cfa_offset (8)
+32:	addl	$8, %esp
+	cfi_adjust_cfa_offset (-8)
+	fstp	%st(1)
+	ret
+
+	cfi_adjust_cfa_offset (8)
 	.align ALIGNARG(4)
 2:	// y is a large integer (absolute value at least 8), but
 	// may be odd unless at least 1L<<64.  So it may be necessary
diff --git a/sysdeps/x86_64/fpu/e_powl.S b/sysdeps/x86_64/fpu/e_powl.S
index e101726..590223b 100644
--- a/sysdeps/x86_64/fpu/e_powl.S
+++ b/sysdeps/x86_64/fpu/e_powl.S
@@ -96,6 +96,9 @@ ENTRY(__ieee754_powl)
 	cmpb	$0x05, %ah
 	je	15f		// x is ħinf
 
+	cmpb	$0x01, %ah
+	je	31f		// x is NaN
+
 	fxch			// y : x
 
 	/* fistpll raises invalid exception for |y| >= 1L<<63.  */

-- 
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]