olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1457177-3.patch

ce426f
Backport of this upstream commit (with libm-test.inc adjustments):
ce426f
ce426f
commit 98fb27a373f37554232e0060eef1a5bb00a07eb0
ce426f
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
ce426f
Date:   Fri Mar 14 12:27:52 2014 -0500
ce426f
ce426f
    PowerPC: remove wrong nearbyintl implementation for PPC64
ce426f
    
ce426f
    The nearbyintl assembly implementation
ce426f
    (sysdeps/powerpc/powerpc64/fpu/s_nearbyintl.S)
ce426f
    returns wrong results for some inputs where first double is a exact
ce426f
    integer and the precision is determined by second long double.
ce426f
    
ce426f
    Checking on implementation comments and history, I am very confident the
ce426f
    assembly implementation was based on a version before commit
ce426f
    5c68d401698a58cf7da150d9cce769fa6679ba5f that fixes BZ#2423 (Errors in
ce426f
    long double (ldbl-128ibm) rounding functions in glibc-2.4).
ce426f
    
ce426f
    By just removing the implementation and make the build select
ce426f
    sysdeps/ieee754/ldbl-128ibm/s_nearbyintl.c instead fixes the failing
ce426f
    math.
ce426f
    
ce426f
    Fixes BZ#16706.
ce426f
ce426f
Index: b/math/libm-test.inc
ce426f
===================================================================
ce426f
--- a/math/libm-test.inc
ce426f
+++ b/math/libm-test.inc
ce426f
@@ -7619,6 +7619,16 @@ nearbyint_test (void)
ce426f
   TEST_f_f (nearbyint, -562949953421312.75, -562949953421313.0);
ce426f
   TEST_f_f (nearbyint, -1125899906842624.75, -1125899906842625.0);
ce426f
 #endif
ce426f
+#ifdef TEST_LDOUBLE
ce426f
+    /* Check cases where first double is a exact integer higher than 2^52 and
ce426f
+       the precision is determined by second long double for IBM long double.  */
ce426f
+    TEST_f_f (nearbyint,  34503599627370498.515625L, 34503599627370499.0L);
ce426f
+    TEST_f_f (nearbyint, -34503599627370498.515625L, -34503599627370499.0L);
ce426f
+# if LDBL_MANT_DIG >= 106
ce426f
+    TEST_f_f (nearbyint,  1192568192774434123539907640624.484375L, 1192568192774434123539907640624.0L);
ce426f
+    TEST_f_f (nearbyint, -1192568192774434123539907640624.484375L, -1192568192774434123539907640624.0L);
ce426f
+# endif
ce426f
+#endif
ce426f
 
ce426f
   END (nearbyint);
ce426f
 }
ce426f
Index: b/sysdeps/powerpc/powerpc64/fpu/s_nearbyintl.S
ce426f
===================================================================
ce426f
--- a/sysdeps/powerpc/powerpc64/fpu/s_nearbyintl.S
ce426f
+++ /dev/null
ce426f
@@ -1,113 +0,0 @@
ce426f
-/* nearbyint long double.
ce426f
-   IBM extended format long double version.
ce426f
-   Copyright (C) 2004, 2006 Free Software Foundation, Inc.
ce426f
-   This file is part of the GNU C Library.
ce426f
-
ce426f
-   The GNU C Library is free software; you can redistribute it and/or
ce426f
-   modify it under the terms of the GNU Lesser General Public
ce426f
-   License as published by the Free Software Foundation; either
ce426f
-   version 2.1 of the License, or (at your option) any later version.
ce426f
-
ce426f
-   The GNU C Library is distributed in the hope that it will be useful,
ce426f
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
-   Lesser General Public License for more details.
ce426f
-
ce426f
-   You should have received a copy of the GNU Lesser General Public
ce426f
-   License along with the GNU C Library; if not, see
ce426f
-   <http://www.gnu.org/licenses/>.  */
ce426f
-
ce426f
-#include <sysdep.h>
ce426f
-#include <math_ldbl_opt.h>
ce426f
-
ce426f
-	.section	".toc","aw"
ce426f
-.LC0:	/* 2**52 */
ce426f
-	.tc FD_43300000_0[TC],0x4330000000000000
ce426f
-	.section	".text"
ce426f
-
ce426f
-/* long double [fp1,fp2] nearbyintl (long double x [fp1,fp2])
ce426f
-   IEEE 1003.1 nearbyintl function.  nearbyintl is simular to the rintl
ce426f
-   but does raise the "inexact" exception.  This implementation is
ce426f
-   based on rintl but explicitly maskes the inexact exception on entry
ce426f
-   and clears any pending inexact before restoring the exception mask
ce426f
-   on exit.
ce426f
-
ce426f
-   PowerPC64 long double uses the IBM extended format which is
ce426f
-   represented two 64-floating point double values. The values are
ce426f
-   non-overlapping giving an effective precision of 106 bits. The first
ce426f
-   double contains the high order bits of mantisa and is always rounded
ce426f
-   to represent a normal rounding of long double to double. Since the
ce426f
-   long double value is sum of the high and low values, the low double
ce426f
-   normally has the opposite sign to compensate for the this rounding.
ce426f
-
ce426f
-   For long double there are two cases:
ce426f
-   1) |x| < 2**52, all the integer bits are in the high double.
ce426f
-      floor the high double and set the low double to -0.0.
ce426f
-   2) |x| >= 2**52, Rounding involves both doubles.
ce426f
-      See the comment before lable .L2 for details.
ce426f
-   */
ce426f
-ENTRY (__nearbyintl)
ce426f
-	mffs	fp11		/* Save current FPSCR.  */
ce426f
-	lfd	fp13,.LC0@toc(2)
ce426f
-	fabs	fp0,fp1
ce426f
-	mtfsb0  28		/* Disable "inexact" exceptions.  */
ce426f
-	fsub	fp12,fp13,fp13	/* generate 0.0  */
ce426f
-	fabs	fp9,fp2
ce426f
-	fcmpu	cr7,fp0,fp13	/* if (fabs(x) > TWO52)  */
ce426f
-	fcmpu	cr6,fp1,fp12	/* if (x > 0.0)  */
ce426f
-	bnl-	cr7,.L2
ce426f
-	fmr	fp2,fp12
ce426f
-	bng-	cr6,.L4
ce426f
-	fadd	fp1,fp1,fp13	/* x+= TWO52;  */
ce426f
-	fsub	fp1,fp1,fp13	/* x-= TWO52;  */
ce426f
-	b	.L9
ce426f
-.L4:
ce426f
-	bnl-	cr6,.L9		/* if (x < 0.0)  */
ce426f
-	fsub	fp1,fp13,fp1	/* x = TWO52 - x;  */
ce426f
-	fsub	fp0,fp1,fp13	/* x = - (x - TWO52);  */
ce426f
-	fneg	fp1,fp0
ce426f
-.L9:
ce426f
-	mtfsb0	6		/* Clear any pending "inexact" exceptions.  */
ce426f
-	mtfsf	0x01,fp11	/* restore exception mask.  */
ce426f
-	blr
ce426f
-
ce426f
-/* The high double is > TWO52 so we need to round the low double and
ce426f
-   perhaps the high double.  This gets a bit tricky so we use the
ce426f
-   following algorithm:
ce426f
-
ce426f
-   tau = floor(x_high/TWO52);
ce426f
-   x0 = x_high - tau;
ce426f
-   x1 = x_low + tau;
ce426f
-   r1 = nearbyint(x1);
ce426f
-   y_high = x0 + r1;
ce426f
-   y_low = r1 - tau;
ce426f
-   return y;  */
ce426f
-.L2:
ce426f
-	fcmpu	cr7,fp9,fp13	/* if (|x_low| > TWO52)  */
ce426f
-	fcmpu	cr0,fp9,fp12	/* || (|x_low| == 0.0)  */
ce426f
-	bge-	cr7,.L9		/*   return x;	*/
ce426f
-	beq-  cr0,.L9
ce426f
-	fdiv	fp8,fp1,fp13	/* x_high/TWO52  */
ce426f
-	fctidz	fp0,fp8
ce426f
-	fcfid	fp8,fp0		/* tau = floor(x_high/TWO52);  */
ce426f
-	fsub	fp3,fp1,fp8	/* x0 = x_high - tau;  */
ce426f
-	fadd	fp4,fp2,fp8	/* x1 = x_low + tau;  */
ce426f
-
ce426f
-	fcmpu	cr6,fp4,fp12	/* if (x1 > 0.0)  */
ce426f
-	bng-	cr6,.L8
ce426f
-	fadd	fp5,fp4,fp13	/* r1 = x1 + TWO52;  */
ce426f
-	fsub	fp5,fp5,fp13	/* r1 = r1 - TWO52;  */
ce426f
-	b	.L6
ce426f
-.L8:
ce426f
-	fmr	fp5,fp4
ce426f
-	bge-	cr6,.L6		/* if (x1 < 0.0)  */
ce426f
-	fsub	fp5,fp13,fp4	/* r1 = TWO52 - x1;  */
ce426f
-	fsub	fp0,fp5,fp13	/* r1 = - (r1 - TWO52);  */
ce426f
-	fneg	fp5,fp0
ce426f
-.L6:
ce426f
-	fadd	fp1,fp3,fp5	/* y_high = x0 + r1;  */
ce426f
-	fsub	fp2,fp5,fp8	/* y_low = r1 - tau;  */
ce426f
-	b	.L9
ce426f
-END (__nearbyintl)
ce426f
-
ce426f
-long_double_symbol (libm, __nearbyintl, nearbyintl)