This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: fix for parsing hex floats


Joseph Myers wrote:
> On Wed, 31 Oct 2007, Ben Elliston wrote:
> 
> > This patch, authored by Ulrich Weigand, improves parsing of  hexadecimal
> > floating point constants on targets with various rounding modes.  Tested
> > with a bootstrap and regression testsuite run on powerpc-linux.  OK for
> > the trunk?
> 
> Could we have a testcase (newly added by the patch, or already in the 
> testsuite) that failed before and passed after the patch on some 
> identified host and target?

Actually, the problem isn't visible in current mainline; it only occurs
after switching the literal parser to respect the SPU's round-towards-zero
mode as done by Trevor's patch (still under discussion):
http://gcc.gnu.org/ml/gcc-patches/2007-10/msg01459.html

With this patch, the test case below starts to fail.  The patch posted
by Ben will fix it again.

The problem is how constants like __FLT_MIN__ are parsed.  On the SPU
(like with IEEE single-precision float), __FLT_MIN__ has the value 2^-126,
i.e. sign bit is 0, (biased) exponent is 1, and mantissa is 0.

This value in decimal is about 1.175494350822287508e-38, which gets
rounded by the default logic in builtin_define_with_hex_fp_value to
1.17549435e-38F.  Note that is is slightly smaller than the real
value.

When this define is used is source code, the parser converts it back
to a numerical representation.  By default, the parser uses a round-to-
nearest mode, so it recomputes the correct 2^-126 value.

However, once the parser uses round-to-zero, this string will actually
convert to a different result (some denormal).  This is particularly
bad on the SPU as denormal values are treated as 0 by all arithmetic
operations,  ...

Bye,
Ulrich


--- /dev/null	2007-10-11 21:52:47.626146058 +0200
+++ gcc/testsuite/gcc.target/spu/flt-round.c	2007-11-02 17:31:10.946613447 +0100
@@ -0,0 +1,25 @@
+/* { dg-do run } */
+
+/* This test case verifies that the __FLT_MIN__ constant is parsed correctly,
+   even when the parser's rounding mode is round-towards-zero.  */
+
+extern void exit (int);
+
+volatile union uf { float f; struct { unsigned int s: 1, e : 8, m : 23; } c; } uf;
+
+int main (void)
+{
+  uf.f = __FLT_MIN__;
+
+  if (uf.c.s != 0)
+    exit (1);
+
+  if (uf.c.e != 1)
+    exit (1);
+
+  if (uf.c.m != 0)
+    exit (1);
+
+  exit (0);
+}
+



-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]