00db10
commit 38f3458175ecf7c3588bd5b6e465f4d9205fbe1c
00db10
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
00db10
Date:   Wed Jan 8 05:10:41 2014 -0600
00db10
00db10
    PowerPC: remove wrong truncl implementation for PowerPC64
00db10
    
00db10
    The truncl assembly implementation (sysdeps/powerpc/powerpc64/fpu/s_truncl.S)
00db10
    returns wrong results for some inputs where first double is a exact integer
00db10
    and the precision is determined by second long double.
00db10
    
00db10
    Checking on implementation comments and history, I am very confident the
00db10
    assembly implementation was based on a version before commit
00db10
    5c68d401698a58cf7da150d9cce769fa6679ba5f that fixes BZ#2423 (Errors in
00db10
    long double (ldbl-128ibm) rounding functions in glibc-2.4).
00db10
    
00db10
    By just removing the implementation and make the build select
00db10
    sysdeps/ieee754/ldbl-128ibm/s_truncl.c instead it fixes tgammal
00db10
    issues regarding wrong result sign.
00db10
00db10
Index: b/sysdeps/ieee754/ldbl-128ibm/s_truncl.c
00db10
===================================================================
00db10
--- a/sysdeps/ieee754/ldbl-128ibm/s_truncl.c
00db10
+++ b/sysdeps/ieee754/ldbl-128ibm/s_truncl.c
00db10
@@ -17,9 +17,6 @@
00db10
    License along with the GNU C Library; if not, see
00db10
    <http://www.gnu.org/licenses/>.  */
00db10
 
00db10
-/* This has been coded in assembler because GCC makes such a mess of it
00db10
-   when it's coded in C.  */
00db10
-
00db10
 #include <math.h>
00db10
 #include <math_ldbl_opt.h>
00db10
 #include <float.h>
00db10
Index: b/sysdeps/powerpc/powerpc64/fpu/s_truncl.S
00db10
===================================================================
00db10
--- a/sysdeps/powerpc/powerpc64/fpu/s_truncl.S
00db10
+++ /dev/null
00db10
@@ -1,120 +0,0 @@
00db10
-/* long double trunc function.
00db10
-   IBM extended format long double version.
00db10
-   Copyright (C) 2004, 2006 Free Software Foundation, Inc.
00db10
-   This file is part of the GNU C Library.
00db10
-
00db10
-   The GNU C Library is free software; you can redistribute it and/or
00db10
-   modify it under the terms of the GNU Lesser General Public
00db10
-   License as published by the Free Software Foundation; either
00db10
-   version 2.1 of the License, or (at your option) any later version.
00db10
-
00db10
-   The GNU C Library is distributed in the hope that it will be useful,
00db10
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
-   Lesser General Public License for more details.
00db10
-
00db10
-   You should have received a copy of the GNU Lesser General Public
00db10
-   License along with the GNU C Library; if not, see
00db10
-   <http://www.gnu.org/licenses/>.  */
00db10
-
00db10
-#include <sysdep.h>
00db10
-#include <math_ldbl_opt.h>
00db10
-
00db10
-	.section	".toc","aw"
00db10
-.LC0:	/* 2**52 */
00db10
-	.tc FD_43300000_0[TC],0x4330000000000000
00db10
-.LC1:	/* 0.5 */
00db10
-	.tc FD_3fe00000_0[TC],0x3fe0000000000000
00db10
-	.section	".text"
00db10
-
00db10
-/* long double [fp1,fp2] truncl (long double x [fp1,fp2])  */
00db10
-
00db10
-ENTRY (__truncl)
00db10
-	mffs	fp11		/* Save current FPU rounding mode.  */
00db10
-	lfd	fp13,.LC0@toc(2)
00db10
-	fabs	fp0,fp1
00db10
-	fabs	fp9,fp2
00db10
-	fsub	fp12,fp13,fp13	/* generate 0.0  */
00db10
-	fcmpu	cr7,fp0,fp13	/* if (fabs(x) > TWO52)  */
00db10
-	fcmpu	cr6,fp1,fp12	/* if (x > 0.0)  */
00db10
-	bnl-	cr7,.L2
00db10
-	mtfsfi	7,1		/* Set rounding mode toward 0.  */
00db10
-	ble-	cr6,.L1
00db10
-	fneg	fp2,fp12
00db10
-	fadd	fp1,fp1,fp13	/* x+= TWO52;  */
00db10
-	fsub	fp1,fp1,fp13	/* x-= TWO52;  */
00db10
-	fabs	fp1,fp1		/* if (x == 0.0) x = 0.0;  */
00db10
-.L0:
00db10
-	mtfsf	0x01,fp11	/* restore previous rounding mode.  */
00db10
-	blr
00db10
-.L1:
00db10
-	fneg	fp2,fp12
00db10
-	bge-	cr6,.L0		/* if (x < 0.0)  */
00db10
-	fsub	fp1,fp1,fp13	/* x-= TWO52;  */
00db10
-	fadd	fp1,fp1,fp13	/* x+= TWO52;  */
00db10
-	fnabs	fp1,fp1		/* if (x == 0.0) x = -0.0;  */
00db10
-	mtfsf	0x01,fp11	/* restore previous rounding mode.  */
00db10
-	blr
00db10
-
00db10
-/* The high double is > TWO52 so we need to round the low double and
00db10
-   perhaps the high double.  In this case we have to round the low
00db10
-   double and handle any adjustment to the high double that may be
00db10
-   caused by rounding (up).  This is complicated by the fact that the
00db10
-   high double may already be rounded and the low double may have the
00db10
-   opposite sign to compensate.This gets a bit tricky so we use the
00db10
-   following algorithm:
00db10
-
00db10
-   tau = floor(x_high/TWO52);
00db10
-   x0 = x_high - tau;
00db10
-   x1 = x_low + tau;
00db10
-   r1 = rint(x1);
00db10
-   y_high = x0 + r1;
00db10
-   y_low = x0 - y_high + r1;
00db10
-   return y;  */
00db10
-.L2:
00db10
-	fcmpu	cr7,fp9,fp13	/* if (|x_low| > TWO52)  */
00db10
-	fcmpu	cr0,fp9,fp12	/* || (|x_low| == 0.0)  */
00db10
-	fcmpu	cr5,fp2,fp12	/* if (x_low > 0.0)  */
00db10
-	bgelr-	cr7		/*   return x;	*/
00db10
-	beqlr-  cr0
00db10
-	mtfsfi	7,1		/* Set rounding mode toward 0.  */
00db10
-	fdiv	fp8,fp1,fp13	/* x_high/TWO52  */
00db10
-	
00db10
-	bng-	cr6,.L6		/* if (x > 0.0)  */
00db10
-	fctidz	fp0,fp8
00db10
-	fcfid	fp8,fp0		/* tau = floor(x_high/TWO52);  */
00db10
-	fadd	fp8,fp8,fp8	/* tau++; Make tau even  */
00db10
-	bng	cr5,.L4		/* if (x_low > 0.0)  */
00db10
-	fmr	fp3,fp1
00db10
-	fmr	fp4,fp2
00db10
-	b	.L5
00db10
-.L4:				/* if (x_low < 0.0)  */
00db10
-	fsub	fp3,fp1,fp8	/* x0 = x_high - tau;  */
00db10
-	fadd	fp4,fp2,fp8	/* x1 = x_low + tau;  */
00db10
-.L5:
00db10
-	fadd	fp5,fp4,fp13	/* r1 = r1 + TWO52;  */
00db10
-	fsub	fp5,fp5,fp13	/* r1 = r1 - TWO52;  */
00db10
-	b	.L9
00db10
-.L6:				/* if (x < 0.0)  */
00db10
-	fctidz	fp0,fp8
00db10
-	fcfid	fp8,fp0		/* tau = floor(x_high/TWO52);  */
00db10
-	fadd	fp8,fp8,fp8	/* tau++; Make tau even  */	
00db10
-	bnl	cr5,.L7		/* if (x_low < 0.0)  */
00db10
-	fmr	fp3,fp1
00db10
-	fmr	fp4,fp2
00db10
-	b	.L8
00db10
-.L7:				/* if (x_low > 0.0)  */
00db10
-	fsub	fp3,fp1,fp8	/* x0 = x_high - tau;  */
00db10
-	fadd	fp4,fp2,fp8	/* x1 = x_low + tau;  */
00db10
-.L8:
00db10
-	fsub	fp5,fp4,fp13	/* r1-= TWO52;  */
00db10
-	fadd	fp5,fp5,fp13	/* r1+= TWO52;  */
00db10
-.L9:
00db10
-	mtfsf	0x01,fp11	/* restore previous rounding mode.  */
00db10
-	fadd	fp1,fp3,fp5	/* y_high = x0 + r1;  */
00db10
-	fsub	fp2,fp3,fp1	/* y_low = x0 - y_high + r1;  */
00db10
-	fadd	fp2,fp2,fp5
00db10
-	blr
00db10
-END (__truncl)
00db10
-
00db10
-long_double_symbol (libm, __truncl, truncl)