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 asinh missing underflows (bug 16350) [committed]


Similar to various other bugs in this area, some asinh implementations
do not raise the underflow exception for subnormal arguments, when the
result is tiny and inexact.  This patch forces the exception in a
similar way to previous fixes.

Tested for x86_64, x86 and mips64.  Committed.

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

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

	[BZ #16350]
	* sysdeps/i386/fpu/s_asinh.S (__asinh): Force underflow exception
	for arguments with small absolute value.
	* sysdeps/i386/fpu/s_asinhf.S (__asinhf): Likewise.
	* sysdeps/i386/fpu/s_asinhl.S (__asinhl): Likewise.
	* sysdeps/ieee754/dbl-64/s_asinh.c: Include <float.h>.
	(__asinh): Force underflow exception for arguments with small
	absolute value.
	* sysdeps/ieee754/flt-32/s_asinhf.c: Include <float.h>.
	(__asinhf): Force underflow exception for arguments with small
	absolute value.
	* sysdeps/ieee754/ldbl-128/s_asinhl.c: Include <float.h>.
	(__asinhl): Force underflow exception for arguments with small
	absolute value.
	* sysdeps/ieee754/ldbl-128ibm/s_asinhl.c: Include <float.h>.
	(__asinhl): Force underflow exception for arguments with small
	absolute value.
	* sysdeps/ieee754/ldbl-96/s_asinhl.c: Include <float.h>.
	(__asinhl): Force underflow exception for arguments with small
	absolute value.
	* math/auto-libm-test-in: Do not mark underflow exceptions as
	possibly missing for bug 16350.
	* math/auto-libm-test-out: Regenerated.

diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in
index 7546cca..6ec4bc6 100644
--- a/math/auto-libm-test-in
+++ b/math/auto-libm-test-in
@@ -218,13 +218,12 @@ asinh 0x7.d8e5a8p-4
 asinh -0x7.63a06320c42e4p-4
 asinh 0x6.f4a93p-4
 asinh -0x7.88bcc8p-4
-# Bug 16350: underflow exception may be missing.
-asinh 0x1p-500 missing-underflow
-asinh 0x1p-5000 missing-underflow
-asinh min missing-underflow
-asinh -min missing-underflow
-asinh min_subnorm missing-underflow
-asinh -min_subnorm missing-underflow
+asinh 0x1p-500
+asinh 0x1p-5000
+asinh min
+asinh -min
+asinh min_subnorm
+asinh -min_subnorm
 asinh max no-test-inline
 asinh -max no-test-inline
 
diff --git a/sysdeps/i386/fpu/s_asinh.S b/sysdeps/i386/fpu/s_asinh.S
index e4c0c67..7123772 100644
--- a/sysdeps/i386/fpu/s_asinh.S
+++ b/sysdeps/i386/fpu/s_asinh.S
@@ -100,7 +100,16 @@ ENTRY(__asinh)
 4:	fld	%st			// x : x
 	faddl	MO(huge)		// huge+x : x
 	fstp	%st(0)			// x
-	ret
+	cmpl	$0x00100000, %eax
+	jae	8f
+	subl	$8, %esp
+	cfi_adjust_cfa_offset (8)
+	fld	%st(0)
+	fmul	%st(0)
+	fstpl	(%esp)
+	addl	$8, %esp
+	cfi_adjust_cfa_offset (-8)
+8:	ret
 
 	// |x| > 2^28 => y = sign(x) * (log(|x|) + log(2))
 	.align ALIGNARG(4)
diff --git a/sysdeps/i386/fpu/s_asinhf.S b/sysdeps/i386/fpu/s_asinhf.S
index b1a28e7..77ebae4 100644
--- a/sysdeps/i386/fpu/s_asinhf.S
+++ b/sysdeps/i386/fpu/s_asinhf.S
@@ -100,7 +100,16 @@ ENTRY(__asinhf)
 4:	fld	%st			// x : x
 	faddl	MO(huge)		// huge+x : x
 	fstp	%st(0)			// x
-	ret
+	cmpl	$0x00800000, %eax
+	jae	8f
+	subl	$4, %esp
+	cfi_adjust_cfa_offset (4)
+	fld	%st(0)
+	fmul	%st(0)
+	fstps	(%esp)
+	addl	$4, %esp
+	cfi_adjust_cfa_offset (-4)
+8:	ret
 
 	// |x| > 2^14 => y = sign(x) * (log(|x|) + log(2))
 	.align ALIGNARG(4)
diff --git a/sysdeps/i386/fpu/s_asinhl.S b/sysdeps/i386/fpu/s_asinhl.S
index 6a5defe..8799da6 100644
--- a/sysdeps/i386/fpu/s_asinhl.S
+++ b/sysdeps/i386/fpu/s_asinhl.S
@@ -108,7 +108,12 @@ ENTRY(__asinhl)
 	fldt	MO(huge)		// huge : x : x
 	faddp				// huge+x : x
 	fstp	%st(0)			// x
-	ret
+	cmpl	$0x0001, %eax
+	jae	8f
+	fld	%st(0)
+	fmul	%st(0)
+	fstp	%st(0)
+8:	ret
 
 	// |x| > 2^34 => y = sign(x) * (log(|x|) + log(2))
 	.align ALIGNARG(4)
diff --git a/sysdeps/ieee754/dbl-64/s_asinh.c b/sysdeps/ieee754/dbl-64/s_asinh.c
index a33758d..ebe4710 100644
--- a/sysdeps/ieee754/dbl-64/s_asinh.c
+++ b/sysdeps/ieee754/dbl-64/s_asinh.c
@@ -21,6 +21,7 @@
  *		 := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
  */
 
+#include <float.h>
 #include <math.h>
 #include <math_private.h>
 
@@ -38,6 +39,11 @@ __asinh (double x)
   ix = hx & 0x7fffffff;
   if (__glibc_unlikely (ix < 0x3e300000))                  /* |x|<2**-28 */
     {
+      if (fabs (x) < DBL_MIN)
+	{
+	  double force_underflow = x * x;
+	  math_force_eval (force_underflow);
+	}
       if (huge + x > one)
 	return x;                       /* return x inexact except 0 */
     }
diff --git a/sysdeps/ieee754/flt-32/s_asinhf.c b/sysdeps/ieee754/flt-32/s_asinhf.c
index b7fa2b4..697faa8 100644
--- a/sysdeps/ieee754/flt-32/s_asinhf.c
+++ b/sysdeps/ieee754/flt-32/s_asinhf.c
@@ -13,6 +13,7 @@
  * ====================================================
  */
 
+#include <float.h>
 #include <math.h>
 #include <math_private.h>
 
@@ -29,6 +30,11 @@ __asinhf(float x)
 	GET_FLOAT_WORD(hx,x);
 	ix = hx&0x7fffffff;
 	if(__builtin_expect(ix< 0x38000000, 0)) {	/* |x|<2**-14 */
+	    if (fabsf (x) < FLT_MIN)
+	      {
+		float force_underflow = x * x;
+		math_force_eval (force_underflow);
+	      }
 	    if(huge+x>one) return x;	/* return x inexact except 0 */
 	}
 	if(__builtin_expect(ix>0x47000000, 0)) {	/* |x| > 2**14 */
diff --git a/sysdeps/ieee754/ldbl-128/s_asinhl.c b/sysdeps/ieee754/ldbl-128/s_asinhl.c
index e5a3636..8d5721a 100644
--- a/sysdeps/ieee754/ldbl-128/s_asinhl.c
+++ b/sysdeps/ieee754/ldbl-128/s_asinhl.c
@@ -29,6 +29,7 @@ static char rcsid[] = "$NetBSD: $";
  *                := signl(x)*log1pl(|x| + x^2/(1 + sqrtl(1+x^2)))
  */
 
+#include <float.h>
 #include <math.h>
 #include <math_private.h>
 
@@ -51,6 +52,11 @@ __asinhl (long double x)
     return x + x;		/* x is inf or NaN */
   if (ix < 0x3fc70000)
     {				/* |x| < 2^ -56 */
+      if (fabsl (x) < LDBL_MIN)
+	{
+	  long double force_underflow = x * x;
+	  math_force_eval (force_underflow);
+	}
       if (huge + x > one)
 	return x;		/* return x inexact except 0 */
     }
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_asinhl.c b/sysdeps/ieee754/ldbl-128ibm/s_asinhl.c
index b76e114..dda7f78 100644
--- a/sysdeps/ieee754/ldbl-128ibm/s_asinhl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/s_asinhl.c
@@ -25,6 +25,7 @@ static char rcsid[] = "$NetBSD: s_asinh.c,v 1.9 1995/05/12 04:57:37 jtc Exp $";
  *		 := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
  */
 
+#include <float.h>
 #include <math.h>
 #include <math_private.h>
 #include <math_ldbl_opt.h>
@@ -45,6 +46,11 @@ long double __asinhl(long double x)
 	ix = hx&0x7fffffffffffffffLL;
 	if(ix>=0x7ff0000000000000LL) return x+x;	/* x is inf or NaN */
 	if(ix< 0x3c70000000000000LL) {	/* |x|<2**-56 */
+	    if (fabsl (x) < LDBL_MIN)
+	      {
+		long double force_underflow = x * x;
+		math_force_eval (force_underflow);
+	      }
 	    if(huge+x>one) return x;	/* return x inexact except 0 */
 	}
 	if(ix>0x4370000000000000LL) {	/* |x| > 2**56 */
diff --git a/sysdeps/ieee754/ldbl-96/s_asinhl.c b/sysdeps/ieee754/ldbl-96/s_asinhl.c
index 5e679bd..75e47c7 100644
--- a/sysdeps/ieee754/ldbl-96/s_asinhl.c
+++ b/sysdeps/ieee754/ldbl-96/s_asinhl.c
@@ -29,6 +29,7 @@ static char rcsid[] = "$NetBSD: $";
  *		  := signl(x)*log1pl(|x| + x^2/(1 + sqrtl(1+x^2)))
  */
 
+#include <float.h>
 #include <math.h>
 #include <math_private.h>
 
@@ -44,6 +45,11 @@ long double __asinhl(long double x)
 	GET_LDOUBLE_EXP(hx,x);
 	ix = hx&0x7fff;
 	if(__builtin_expect(ix< 0x3fde, 0)) {	/* |x|<2**-34 */
+	    if (fabsl (x) < LDBL_MIN)
+	      {
+		long double force_underflow = x * x;
+		math_force_eval (force_underflow);
+	      }
 	    if(huge+x>one) return x;	/* return x inexact except 0 */
 	}
 	if(__builtin_expect(ix>0x4020,0)) {		/* |x| > 2**34 */

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