summaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2016-06-23 22:17:41 +0000
committerJoseph Myers <joseph@codesourcery.com>2016-06-23 22:17:41 +0000
commit40244be3729149ff440caf18e445ec17b0d0b511 (patch)
tree17752b5c0173889687263d735f6f259909e31c5a /sysdeps
parent7ed84b89f344c54dbf8665cb1cd29044bec62d18 (diff)
downloadglibc-40244be3729149ff440caf18e445ec17b0d0b511.tar.gz
Fix i386/x86_64 scalbl with sNaN input (bug 20296).
The x86_64 and i386 versions of scalbl return sNaN for some cases of sNaN input and are missing "invalid" exceptions for other cases. This results from overly complicated code that either returns a NaN input, or discards both inputs when one is NaN and loads a NaN from memory. This patch fixes this by simplifying the code to add the arguments when either one is NaN. Tested for x86_64 and x86. [BZ #20296] * sysdeps/i386/fpu/e_scalbl.S (__ieee754_scalbl): Add arguments when either argument is a NaN. * sysdeps/x86_64/fpu/e_scalbl.S (__ieee754_scalbl): Likewise. * math/libm-test.inc (scalb_test_data): Add sNaN tests.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/i386/fpu/e_scalbl.S16
-rw-r--r--sysdeps/x86_64/fpu/e_scalbl.S13
2 files changed, 6 insertions, 23 deletions
diff --git a/sysdeps/i386/fpu/e_scalbl.S b/sysdeps/i386/fpu/e_scalbl.S
index d10b22ea83..896f599cb0 100644
--- a/sysdeps/i386/fpu/e_scalbl.S
+++ b/sysdeps/i386/fpu/e_scalbl.S
@@ -45,7 +45,7 @@ ENTRY(__ieee754_scalbl)
fnstsw
andl $0x4500, %eax
cmpl $0x0100, %eax
- je 3f
+ je 2f
fld %st(1)
frndint
fcomp %st(2)
@@ -76,18 +76,8 @@ ENTRY(__ieee754_scalbl)
fldl MOX(zero_nan, %eax, 1)
ret
- /* The result is NaN, but we must not raise an exception.
- So use a variable. */
-2: fstp %st
- fstp %st
-#ifdef PIC
- LOAD_PIC_REG (cx)
-#endif
- fldl MO(nan)
- ret
-
- /* The first parameter is a NaN. Return it. */
-3: fstp %st(1)
+ /* The result is NaN; raise an exception for sNaN arguments. */
+2: faddp
ret
/* Return NaN and raise the invalid exception. */
diff --git a/sysdeps/x86_64/fpu/e_scalbl.S b/sysdeps/x86_64/fpu/e_scalbl.S
index 331bee580c..2982dc3b9e 100644
--- a/sysdeps/x86_64/fpu/e_scalbl.S
+++ b/sysdeps/x86_64/fpu/e_scalbl.S
@@ -44,7 +44,7 @@ ENTRY(__ieee754_scalbl)
fnstsw
andl $0x4500, %eax
cmpl $0x0100, %eax
- je 3f
+ je 2f
fld %st(1)
frndint
fcomip %st(2), %st
@@ -75,15 +75,8 @@ ENTRY(__ieee754_scalbl)
#endif
ret
- /* The result is NaN, but we must not raise an exception.
- So use a variable. */
-2: fstp %st
- fstp %st
- fldl MO(nan)
- ret
-
- /* The first parameter is a NaN. Return it. */
-3: fstp %st(1)
+ /* The result is NaN; raise an exception for sNaN arguments. */
+2: faddp
ret
/* Return NaN and raise the invalid exception. */