about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2015-10-14 21:13:42 +0000
committerJoseph Myers <joseph@codesourcery.com>2015-10-14 21:13:42 +0000
commit0c25f5b5bb48a9d550b5fb403b9a801ba04c146f (patch)
tree1924b1f2087eacccee4837bcdbf16f8dad8d0814
parent1fae5a6800b07d0a8225664ac65a628bbe98cae7 (diff)
downloadglibc-0c25f5b5bb48a9d550b5fb403b9a801ba04c146f.tar.gz
glibc-0c25f5b5bb48a9d550b5fb403b9a801ba04c146f.tar.xz
glibc-0c25f5b5bb48a9d550b5fb403b9a801ba04c146f.zip
Fix powerpc32 lround, lroundf spurious exceptions (bug 19134).
The powerpc32 implementation of lround and lroundf can produce
spurious exceptions from adding 0.5 then converting to integer.  This
includes "inexact" from the conversion to integer (not allowed for
integer arguments to these functions), and, for larger integer
arguments, "inexact", and "overflow" when rounding upward, from the
addition.  In addition, "inexact" is not allowed together with
"invalid" and so inexact addition must be avoided when the integer
will be out of range of 32-bit long, whether or not the argument is an
integer.

This patch fixes these problems.  As in the powerpc64 llround
implementation, a check is added for too-large arguments; in the
powerpc64 case that means arguments at least 2^52 in magnitude (so
that 0.5 cannot be added exactly), while in this case it means
arguments for which the result would overflow "long".  In those cases
a suitable overflowing value is used for the integer conversion
without adding 0.5, while for smaller arguments it's tested whether
the argument is an integer (by adding and subtracting 2^52 to the
absolute value and comparing with the original absolute value) to
avoid adding 0.5 to integers and generating spurious "inexact".

This code is not used when the power5+ sysdeps directories are used,
as there's a separate power5+ version of these functions..

Tested for powerpc.  This gets test-float (for a default powerpc32
hard-float build without any --with-cpu) back to the point where it
should pass once powerpc ulps are regenerated; test-double still needs
another problem with exceptions fixed to get back to that point (and I
haven't looked lately at what default powerpc64 results are like).

	[BZ #19134]
	* sysdeps/powerpc/powerpc32/fpu/s_lround.S (.LC1): New object.
	(.LC2): Likewise.
	(.LC3): Likewise.
	(__lround): Do not add 0.5 to integer or out-of-range arguments.
-rw-r--r--ChangeLog8
-rw-r--r--NEWS2
-rw-r--r--sysdeps/powerpc/powerpc32/fpu/s_lround.S43
3 files changed, 50 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 8a308891ea..997ad1381f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2015-10-14  Joseph Myers  <joseph@codesourcery.com>
+
+	[BZ #19134]
+	* sysdeps/powerpc/powerpc32/fpu/s_lround.S (.LC1): New object.
+	(.LC2): Likewise.
+	(.LC3): Likewise.
+	(__lround): Do not add 0.5 to integer or out-of-range arguments.
+
 2015-10-14  Szabolcs Nagy  <szabolcs.nagy@arm.com>
 
 	[BZ #19129]
diff --git a/NEWS b/NEWS
index fd33e079f6..d4e8b4adf2 100644
--- a/NEWS
+++ b/NEWS
@@ -20,7 +20,7 @@ Version 2.23
   18966, 18967, 18969, 18970, 18977, 18980, 18981, 18985, 19003, 19007,
   19012, 19016, 19018, 19032, 19046, 19049, 19050, 19059, 19071, 19074,
   19076, 19077, 19078, 19079, 19085, 19086, 19088, 19094, 19095, 19124,
-  19125, 19129
+  19125, 19129, 19134
 
 * The obsolete header <regexp.h> has been removed.  Programs that require
   this header must be updated to use <regex.h> instead.
diff --git a/sysdeps/powerpc/powerpc32/fpu/s_lround.S b/sysdeps/powerpc/powerpc32/fpu/s_lround.S
index 231d5e4f45..5dd3618524 100644
--- a/sysdeps/powerpc/powerpc32/fpu/s_lround.S
+++ b/sysdeps/powerpc/powerpc32/fpu/s_lround.S
@@ -23,6 +23,16 @@
 	.align	2
 .LC0:	/* 0.5 */
 	.long 0x3f000000
+.LC1:	/* 2^52.  */
+	.long 0x59800000
+	.section	.rodata.cst8,"aM",@progbits,8
+	.align	3
+.LC2:	/* 0x7fffffff.8p0.  */
+	.long 0x41dfffff
+	.long 0xffe00000
+.LC3:	/* -0x80000000.8p0.  */
+	.long 0xc1e00000
+	.long 0x00100000
 	.section	".text"
 
 /* long [r3] lround (float x [fp1])
@@ -45,19 +55,40 @@ ENTRY (__lround)
 	mflr	r11
 	cfi_register(lr,r11)
 	SETUP_GOT_ACCESS(r9,got_label)
-	addis	r9,r9,.LC0-got_label@ha
-	lfs	fp10,.LC0-got_label@l(r9)
+	addis	r10,r9,.LC0-got_label@ha
+	lfs	fp10,.LC0-got_label@l(r10)
+	addis	r10,r9,.LC1-got_label@ha
+	lfs	fp11,.LC1-got_label@l(r10)
+	addis	r10,r9,.LC2-got_label@ha
+	lfd	fp9,.LC2-got_label@l(r10)
+	addis	r10,r9,.LC3-got_label@ha
+	lfd	fp8,.LC3-got_label@l(r10)
 	mtlr	r11
 	cfi_same_value (lr)
 #else
 	lis	r9,.LC0@ha
 	lfs	fp10,.LC0@l(r9)
+	lis	r9,.LC1@ha
+	lfs	fp11,.LC1@l(r9)
+	lis	r9,.LC2@ha
+	lfd	fp9,.LC2@l(r9)
+	lis	r9,.LC3@ha
+	lfd	fp8,.LC3@l(r9)
 #endif
 	fabs	fp2, fp1	/* Get the absolute value of x.  */
 	fsub	fp12,fp10,fp10	/* Compute 0.0.  */
 	fcmpu	cr6, fp2, fp10	/* if |x| < 0.5  */
+	fcmpu	cr5, fp1, fp9	/* if x >= 0x7fffffff.8p0  */
+	fcmpu	cr1, fp1, fp8	/* if x <= -0x80000000.8p0  */
 	fcmpu	cr7, fp1, fp12	/* x is negative? x < 0.0  */
 	blt-	cr6,.Lretzero
+	bge-	cr5,.Loflow
+	ble-	cr1,.Loflow
+	/* Test whether an integer to avoid spurious "inexact".  */
+	fadd	fp3,fp2,fp11
+	fsub	fp3,fp3,fp11
+	fcmpu	cr5, fp2, fp3
+	beq	cr5,.Lnobias
 	fadd	fp3,fp2,fp10	/* |x|+=0.5 bias to prepare to round.  */
 	bge	cr7,.Lconvert	/* x is positive so don't negate x.  */
 	fnabs	fp3,fp3		/* -(|x|+=0.5)  */
@@ -74,6 +105,14 @@ ENTRY (__lround)
 .Lretzero:			/* when 0.5 > x > -0.5  */
 	li	r3,0		/* return 0.  */
 	b	.Lout
+.Lnobias:
+	fmr	fp3,fp1
+	b	.Lconvert
+.Loflow:
+	fmr	fp3,fp11
+	bge	cr7,.Lconvert
+	fnabs	fp3,fp3
+	b	.Lconvert
 	END (__lround)
 
 weak_alias (__lround, lround)