ce426f
Backport of this upstream commit (with libm-test.inc adjustments):
ce426f
ce426f
commit 374f7f61214967bb4e2257695aeeeecc2a77f369
ce426f
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
ce426f
Date:   Fri Mar 14 07:35:43 2014 -0500
ce426f
ce426f
    PowerPC: remove wrong ceill implementation for PowerPC64
ce426f
    
ce426f
    The ceill assembly implementation (sysdeps/powerpc/powerpc64/fpu/s_ceill.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_ceill.c instead fixes the failing math.
ce426f
    
ce426f
    Fixes BZ#16701.
ce426f
ce426f
Index: b/math/libm-test.inc
ce426f
===================================================================
ce426f
--- a/math/libm-test.inc
ce426f
+++ b/math/libm-test.inc
ce426f
@@ -2241,6 +2241,15 @@ ceil_test (void)
ce426f
   TEST_f_f (ceil, -72057594037927936.75L, -72057594037927936.0L);
ce426f
   TEST_f_f (ceil, -72057594037927937.5L, -72057594037927937.0L);
ce426f
 
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 (ceil,  34503599627370498.515625L, 34503599627370499.0L);
ce426f
+  TEST_f_f (ceil, -34503599627370498.515625L, -34503599627370498.0L);
ce426f
+# if LDBL_MANT_DIG >= 106
ce426f
+  TEST_f_f (ceil,  1192568192774434123539907640624.484375L, 1192568192774434123539907640625.0L);
ce426f
+  TEST_f_f (ceil, -1192568192774434123539907640624.484375L, -1192568192774434123539907640624.0L);
ce426f
+# endif
ce426f
+
ce426f
   TEST_f_f (ceil, 10141204801825835211973625643007.5L, 10141204801825835211973625643008.0L);
ce426f
   TEST_f_f (ceil, 10141204801825835211973625643008.25L, 10141204801825835211973625643009.0L);
ce426f
   TEST_f_f (ceil, 10141204801825835211973625643008.5L, 10141204801825835211973625643009.0L);
ce426f
Index: b/sysdeps/powerpc/powerpc64/fpu/s_ceill.S
ce426f
===================================================================
ce426f
--- a/sysdeps/powerpc/powerpc64/fpu/s_ceill.S
ce426f
+++ /dev/null
ce426f
@@ -1,132 +0,0 @@
ce426f
-/* s_ceill.S 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
-
ce426f
-	.section	".text"
ce426f
-
ce426f
-/* long double [fp1,fp2] ceill (long double x [fp1,fp2])
ce426f
-   IEEE 1003.1 ceil function.
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 ceiled
ce426f
-   to represent a normal ceiling 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 ceiling.
ce426f
-
ce426f
-   For long double there are two cases:
ce426f
-   1) |x| < 2**52, all the integer bits are in the high double.
ce426f
-      ceil the high double and set the low double to -0.0.
ce426f
-   2) |x| >= 2**52, ceiling involves both doubles.
ce426f
-      See the comment before lable .L2 for details.
ce426f
-   */
ce426f
-
ce426f
-ENTRY (__ceill)
ce426f
-	mffs	fp11		/* Save current FPU rounding mode.  */
ce426f
-	lfd	fp13,.LC0@toc(2)
ce426f
-	fabs	fp0,fp1
ce426f
-	fabs	fp9,fp2
ce426f
-	fsub	fp12,fp13,fp13	/* generate 0.0  */
ce426f
-	fcmpu	cr7,fp0,fp13	/* if (fabs(x) > TWO52)  */
ce426f
-	fcmpu	cr6,fp1,fp12	/* if (x > 0.0)  */
ce426f
-	bnl-	cr7,.L2
ce426f
-	mtfsfi	7,2		/* Set rounding mode toward +inf.  */
ce426f
-	fneg	fp2,fp12
ce426f
-	ble-	cr6,.L1
ce426f
-	fadd	fp1,fp1,fp13	/* x+= TWO52;  */
ce426f
-	fsub	fp1,fp1,fp13	/* x-= TWO52;  */
ce426f
-	fabs	fp1,fp1		/* if (x == 0.0)  */
ce426f
-.L0:
ce426f
-	mtfsf	0x01,fp11	/* restore previous rounding mode.  */
ce426f
-	blr			/* x = 0.0; */
ce426f
-.L1:
ce426f
-	bge-	cr6,.L0		/* if (x < 0.0)  */
ce426f
-	fsub	fp1,fp1,fp13	/* x-= TWO52;  */
ce426f
-	fadd	fp1,fp1,fp13	/* x+= TWO52;  */
ce426f
-	fcmpu	cr5,fp1,fp12	/* if (x > 0.0)  */
ce426f
-	mtfsf	0x01,fp11	/* restore previous rounding mode.  */
ce426f
-	fnabs	fp1,fp1		/* if (x == 0.0)  */
ce426f
-	blr			/* x = -0.0; */
ce426f
-	
ce426f
-/* The high double is > TWO52 so we need to round the low double and
ce426f
-   perhaps the high double.  In this case we have to round the low
ce426f
-   double and handle any adjustment to the high double that may be
ce426f
-   caused by rounding (up).  This is complicated by the fact that the
ce426f
-   high double may already be rounded and the low double may have the
ce426f
-   opposite sign to compensate.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 = rint(x1);
ce426f
-   y_high = x0 + r1;
ce426f
-   y_low = x0 - y_high + r1;
ce426f
-   return y;  */
ce426f
-.L2:
ce426f
-	fcmpu	cr7,fp9,fp13	/* if (|x_low| > TWO52)  */
ce426f
-	fcmpu	cr0,fp9,fp12	/* || (|x_low| == 0.0)  */
ce426f
-	fcmpu	cr5,fp2,fp12	/* if (x_low > 0.0)  */
ce426f
-	bgelr-	cr7		/*   return x;	*/
ce426f
-	beqlr-  cr0
ce426f
-	mtfsfi	7,2		/* Set rounding mode toward +inf.  */
ce426f
-	fdiv	fp8,fp1,fp13	/* x_high/TWO52  */
ce426f
-	
ce426f
-	bng-	cr6,.L6		/* if (x > 0.0)  */
ce426f
-	fctidz	fp0,fp8
ce426f
-	fcfid	fp8,fp0		/* tau = floor(x_high/TWO52);  */
ce426f
-	bng	cr5,.L4		/* if (x_low > 0.0)  */
ce426f
-	fmr	fp3,fp1
ce426f
-	fmr	fp4,fp2
ce426f
-	b	.L5
ce426f
-.L4:				/* if (x_low < 0.0)  */
ce426f
-	fsub	fp3,fp1,fp8	/* x0 = x_high - tau;  */
ce426f
-	fadd	fp4,fp2,fp8	/* x1 = x_low + tau;  */
ce426f
-.L5:
ce426f
-	fadd	fp5,fp4,fp13	/* r1 = r1 + TWO52;  */
ce426f
-	fsub	fp5,fp5,fp13	/* r1 = r1 - TWO52;  */
ce426f
-	b	.L9
ce426f
-.L6:				/* if (x < 0.0)  */
ce426f
-	fctidz	fp0,fp8
ce426f
-	fcfid	fp8,fp0		/* tau = floor(x_high/TWO52);  */	
ce426f
-	bnl	cr5,.L7		/* if (x_low < 0.0)  */
ce426f
-	fmr	fp3,fp1
ce426f
-	fmr	fp4,fp2
ce426f
-	b	.L8
ce426f
-.L7:				/* if (x_low > 0.0)  */
ce426f
-	fsub	fp3,fp1,fp8	/* x0 = x_high - tau;  */
ce426f
-	fadd	fp4,fp2,fp8	/* x1 = x_low + tau;  */
ce426f
-.L8:
ce426f
-	fsub	fp5,fp4,fp13	/* r1-= TWO52;  */
ce426f
-	fadd	fp5,fp5,fp13	/* r1+= TWO52;  */
ce426f
-.L9:
ce426f
-	mtfsf	0x01,fp11	/* restore previous rounding mode.  */
ce426f
-	fadd	fp1,fp3,fp5	/* y_high = x0 + r1;  */
ce426f
-	fsub	fp2,fp3,fp1	/* y_low = x0 - y_high + r1;  */
ce426f
-	fadd	fp2,fp2,fp5
ce426f
-	blr
ce426f
-END (__ceill)
ce426f
-
ce426f
-long_double_symbol (libm, __ceill, ceill)