178df3
Backport of this upstream commit (with libm-test.inc adjustments):
178df3
178df3
commit 374f7f61214967bb4e2257695aeeeecc2a77f369
178df3
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
178df3
Date:   Fri Mar 14 07:35:43 2014 -0500
178df3
178df3
    PowerPC: remove wrong ceill implementation for PowerPC64
178df3
    
178df3
    The ceill assembly implementation (sysdeps/powerpc/powerpc64/fpu/s_ceill.S)
178df3
    returns wrong results for some inputs where first double is a exact
178df3
    integer and the precision is determined by second long double.
178df3
    
178df3
    Checking on implementation comments and history, I am very confident the
178df3
    assembly implementation was based on a version before commit
178df3
    5c68d401698a58cf7da150d9cce769fa6679ba5f that fixes BZ#2423 (Errors in
178df3
    long double (ldbl-128ibm) rounding functions in glibc-2.4).
178df3
    
178df3
    By just removing the implementation and make the build select
178df3
    sysdeps/ieee754/ldbl-128ibm/s_ceill.c instead fixes the failing math.
178df3
    
178df3
    Fixes BZ#16701.
178df3
178df3
Index: b/math/libm-test.inc
178df3
===================================================================
178df3
--- a/math/libm-test.inc
178df3
+++ b/math/libm-test.inc
178df3
@@ -2241,6 +2241,15 @@ ceil_test (void)
178df3
   TEST_f_f (ceil, -72057594037927936.75L, -72057594037927936.0L);
178df3
   TEST_f_f (ceil, -72057594037927937.5L, -72057594037927937.0L);
178df3
 
178df3
+  /* Check cases where first double is a exact integer higher than 2^52 and
178df3
+     the precision is determined by second long double for IBM long double.  */
178df3
+  TEST_f_f (ceil,  34503599627370498.515625L, 34503599627370499.0L);
178df3
+  TEST_f_f (ceil, -34503599627370498.515625L, -34503599627370498.0L);
178df3
+# if LDBL_MANT_DIG >= 106
178df3
+  TEST_f_f (ceil,  1192568192774434123539907640624.484375L, 1192568192774434123539907640625.0L);
178df3
+  TEST_f_f (ceil, -1192568192774434123539907640624.484375L, -1192568192774434123539907640624.0L);
178df3
+# endif
178df3
+
178df3
   TEST_f_f (ceil, 10141204801825835211973625643007.5L, 10141204801825835211973625643008.0L);
178df3
   TEST_f_f (ceil, 10141204801825835211973625643008.25L, 10141204801825835211973625643009.0L);
178df3
   TEST_f_f (ceil, 10141204801825835211973625643008.5L, 10141204801825835211973625643009.0L);
178df3
Index: b/sysdeps/powerpc/powerpc64/fpu/s_ceill.S
178df3
===================================================================
178df3
--- a/sysdeps/powerpc/powerpc64/fpu/s_ceill.S
178df3
+++ /dev/null
178df3
@@ -1,132 +0,0 @@
178df3
-/* s_ceill.S IBM extended format long double version.
178df3
-   Copyright (C) 2004, 2006 Free Software Foundation, Inc.
178df3
-   This file is part of the GNU C Library.
178df3
-
178df3
-   The GNU C Library is free software; you can redistribute it and/or
178df3
-   modify it under the terms of the GNU Lesser General Public
178df3
-   License as published by the Free Software Foundation; either
178df3
-   version 2.1 of the License, or (at your option) any later version.
178df3
-
178df3
-   The GNU C Library is distributed in the hope that it will be useful,
178df3
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
178df3
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
178df3
-   Lesser General Public License for more details.
178df3
-
178df3
-   You should have received a copy of the GNU Lesser General Public
178df3
-   License along with the GNU C Library; if not, see
178df3
-   <http://www.gnu.org/licenses/>.  */
178df3
-
178df3
-#include <sysdep.h>
178df3
-#include <math_ldbl_opt.h>
178df3
-
178df3
-	.section	".toc","aw"
178df3
-.LC0:	/* 2**52 */
178df3
-	.tc FD_43300000_0[TC],0x4330000000000000
178df3
-
178df3
-	.section	".text"
178df3
-
178df3
-/* long double [fp1,fp2] ceill (long double x [fp1,fp2])
178df3
-   IEEE 1003.1 ceil function.
178df3
-
178df3
-   PowerPC64 long double uses the IBM extended format which is
178df3
-   represented two 64-floating point double values. The values are
178df3
-   non-overlapping giving an effective precision of 106 bits. The first
178df3
-   double contains the high order bits of mantisa and is always ceiled
178df3
-   to represent a normal ceiling of long double to double. Since the
178df3
-   long double value is sum of the high and low values, the low double
178df3
-   normally has the opposite sign to compensate for the this ceiling.
178df3
-
178df3
-   For long double there are two cases:
178df3
-   1) |x| < 2**52, all the integer bits are in the high double.
178df3
-      ceil the high double and set the low double to -0.0.
178df3
-   2) |x| >= 2**52, ceiling involves both doubles.
178df3
-      See the comment before lable .L2 for details.
178df3
-   */
178df3
-
178df3
-ENTRY (__ceill)
178df3
-	mffs	fp11		/* Save current FPU rounding mode.  */
178df3
-	lfd	fp13,.LC0@toc(2)
178df3
-	fabs	fp0,fp1
178df3
-	fabs	fp9,fp2
178df3
-	fsub	fp12,fp13,fp13	/* generate 0.0  */
178df3
-	fcmpu	cr7,fp0,fp13	/* if (fabs(x) > TWO52)  */
178df3
-	fcmpu	cr6,fp1,fp12	/* if (x > 0.0)  */
178df3
-	bnl-	cr7,.L2
178df3
-	mtfsfi	7,2		/* Set rounding mode toward +inf.  */
178df3
-	fneg	fp2,fp12
178df3
-	ble-	cr6,.L1
178df3
-	fadd	fp1,fp1,fp13	/* x+= TWO52;  */
178df3
-	fsub	fp1,fp1,fp13	/* x-= TWO52;  */
178df3
-	fabs	fp1,fp1		/* if (x == 0.0)  */
178df3
-.L0:
178df3
-	mtfsf	0x01,fp11	/* restore previous rounding mode.  */
178df3
-	blr			/* x = 0.0; */
178df3
-.L1:
178df3
-	bge-	cr6,.L0		/* if (x < 0.0)  */
178df3
-	fsub	fp1,fp1,fp13	/* x-= TWO52;  */
178df3
-	fadd	fp1,fp1,fp13	/* x+= TWO52;  */
178df3
-	fcmpu	cr5,fp1,fp12	/* if (x > 0.0)  */
178df3
-	mtfsf	0x01,fp11	/* restore previous rounding mode.  */
178df3
-	fnabs	fp1,fp1		/* if (x == 0.0)  */
178df3
-	blr			/* x = -0.0; */
178df3
-	
178df3
-/* The high double is > TWO52 so we need to round the low double and
178df3
-   perhaps the high double.  In this case we have to round the low
178df3
-   double and handle any adjustment to the high double that may be
178df3
-   caused by rounding (up).  This is complicated by the fact that the
178df3
-   high double may already be rounded and the low double may have the
178df3
-   opposite sign to compensate.This gets a bit tricky so we use the
178df3
-   following algorithm:
178df3
-
178df3
-   tau = floor(x_high/TWO52);
178df3
-   x0 = x_high - tau;
178df3
-   x1 = x_low + tau;
178df3
-   r1 = rint(x1);
178df3
-   y_high = x0 + r1;
178df3
-   y_low = x0 - y_high + r1;
178df3
-   return y;  */
178df3
-.L2:
178df3
-	fcmpu	cr7,fp9,fp13	/* if (|x_low| > TWO52)  */
178df3
-	fcmpu	cr0,fp9,fp12	/* || (|x_low| == 0.0)  */
178df3
-	fcmpu	cr5,fp2,fp12	/* if (x_low > 0.0)  */
178df3
-	bgelr-	cr7		/*   return x;	*/
178df3
-	beqlr-  cr0
178df3
-	mtfsfi	7,2		/* Set rounding mode toward +inf.  */
178df3
-	fdiv	fp8,fp1,fp13	/* x_high/TWO52  */
178df3
-	
178df3
-	bng-	cr6,.L6		/* if (x > 0.0)  */
178df3
-	fctidz	fp0,fp8
178df3
-	fcfid	fp8,fp0		/* tau = floor(x_high/TWO52);  */
178df3
-	bng	cr5,.L4		/* if (x_low > 0.0)  */
178df3
-	fmr	fp3,fp1
178df3
-	fmr	fp4,fp2
178df3
-	b	.L5
178df3
-.L4:				/* if (x_low < 0.0)  */
178df3
-	fsub	fp3,fp1,fp8	/* x0 = x_high - tau;  */
178df3
-	fadd	fp4,fp2,fp8	/* x1 = x_low + tau;  */
178df3
-.L5:
178df3
-	fadd	fp5,fp4,fp13	/* r1 = r1 + TWO52;  */
178df3
-	fsub	fp5,fp5,fp13	/* r1 = r1 - TWO52;  */
178df3
-	b	.L9
178df3
-.L6:				/* if (x < 0.0)  */
178df3
-	fctidz	fp0,fp8
178df3
-	fcfid	fp8,fp0		/* tau = floor(x_high/TWO52);  */	
178df3
-	bnl	cr5,.L7		/* if (x_low < 0.0)  */
178df3
-	fmr	fp3,fp1
178df3
-	fmr	fp4,fp2
178df3
-	b	.L8
178df3
-.L7:				/* if (x_low > 0.0)  */
178df3
-	fsub	fp3,fp1,fp8	/* x0 = x_high - tau;  */
178df3
-	fadd	fp4,fp2,fp8	/* x1 = x_low + tau;  */
178df3
-.L8:
178df3
-	fsub	fp5,fp4,fp13	/* r1-= TWO52;  */
178df3
-	fadd	fp5,fp5,fp13	/* r1+= TWO52;  */
178df3
-.L9:
178df3
-	mtfsf	0x01,fp11	/* restore previous rounding mode.  */
178df3
-	fadd	fp1,fp3,fp5	/* y_high = x0 + r1;  */
178df3
-	fsub	fp2,fp3,fp1	/* y_low = x0 - y_high + r1;  */
178df3
-	fadd	fp2,fp2,fp5
178df3
-	blr
178df3
-END (__ceill)
178df3
-
178df3
-long_double_symbol (libm, __ceill, ceill)