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]

[RFA: 3.2] MMIX: Fix gcc.c-torture/execute/ieee/mzero2.c (committedtrunk + testcase branch)


In August, gcc.c-torture/execute/ieee/mzero2.c started to break
for mmix-knuth-mmixware.  Apparently "-1.00 * pzero" is now
translated to "-pzero", trigging the negdf2 pattern.  It's not
IEEE-compliant to expand it as "0-op1" in negdf2.  Oops.
However, it *is* IEEE-compliant (wrt. signalling NaNs) to flip
the sign bit, xor:ing it with (1 << 63) (YMMV), says
<URL:http://gcc.gnu.org/ml/gcc/2002-08/msg00454.html> and
<URL:http://gcc.gnu.org/ml/gcc/2002-08/msg00456.html>.  The
define_expand method used is the same as on CRIS for negsf2 and
on Alpha for negtf2.  I don't like subregs, but if anyone knows
of a reason to prefer the subreg method used elsewhere, I'm
interested.

Question: Given that "-1.00 * pzero" can signal when using
multiplication, but a negation is allowed not to, is it really
correct to now translate it to a negation?

For the 3.2-branch, gcc.c-torture/execute/ieee/mzero2.c doesn't
trig the error, since it doesn't turn "-1.00 * pzero" into
"-pzero".  I'm adding gcc.c-torture/execute/ieee/mzero3.c to the
trunk and branch to keep the bug exposed.  (Testsuite changes
that are applied to the trunk can be applied to the branch
without branch maintainer approval, see previous messages.)

The bug is well-contained and only affects one target.  FWIW,
for mmix-knuth-mmixware, the blanket criteria that the bug must
be a regression to be applied to the 3.2 branch cannot be
fulfilled for any target-specific bug, given that 3.1 (first
release with this target) is target-wise the same as 3.2.
I ask for approval for the 3.2 branch.

Mark, ok for 3.2?

gcc:
	* config/mmix/mmix.md ("negdf2"): Rewrite.
	("*expanded_negdf2"): New.

gcc/testsuite:
	* gcc.c-torture/execute/ieee/mzero3.c: New test.

Index: gcc.c-torture/execute/ieee/mzero3.c
===================================================================
RCS file: gcc.c-torture/execute/ieee/mzero3.c
diff -N gcc.c-torture/execute/ieee/mzero3.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc.c-torture/execute/ieee/mzero3.c	20 Sep 2002 03:00:11 -0000
***************
*** 0 ****
--- 1,51 ----
+ /* Copyright (C) 2002  Free Software Foundation.
+    by Hans-Peter Nilsson  <hp@bitrange.com>, derived from mzero2.c
+
+    In the MMIX port, negdf2 was bogusly expanding -x into 0 - x.  */
+
+ double nzerod = -0.0;
+ float nzerof = -0.0;
+ double zerod = 0.0;
+ float zerof = 0.0;
+
+ void expectd (double, double);
+ void expectf (float, float);
+ double negd (double);
+ float negf (float);
+
+ main ()
+ {
+   expectd (negd (zerod), nzerod);
+   expectf (negf (zerof), nzerof);
+   expectd (negd (nzerod), zerod);
+   expectf (negf (nzerof), zerof);
+   exit (0);
+ }
+
+ void
+ expectd (double value, double expected)
+ {
+   if (value != expected
+       || memcmp ((void *)&value, (void *) &expected, sizeof (double)) != 0)
+     abort ();
+ }
+
+ void
+ expectf (float value, float expected)
+ {
+   if (value != expected
+       || memcmp ((void *)&value, (void *) &expected, sizeof (float)) != 0)
+     abort ();
+ }
+
+ double
+ negd (double v)
+ {
+   return -v;
+ }
+
+ float
+ negf (float v)
+ {
+   return -v;
+ }

Index: mmix.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mmix/mmix.md,v
retrieving revision 1.16
diff -p -c -r1.16 mmix.md
*** mmix.md	12 Aug 2002 21:32:01 -0000	1.16
--- mmix.md	17 Sep 2002 18:24:26 -0000
*************** DIVU %1,%1,%2\;GET %0,:rR\;NEGU %2,0,%0\
*** 348,360 ****
    ""
    "NEGU %0,0,%1")

- ;; FIXME: GCC should be able to synthesize this by itself as "0.0 - x".
  (define_expand "negdf2"
    [(set (match_operand:DF 0 "register_operand" "=r")
! 	(minus:DF (match_dup 2)
! 		(match_operand:DF 1 "register_operand" "r")))]
    ""
!   "operands[2] = force_reg (DFmode, CONST0_RTX (DFmode));")

  ;; FIXME: define_expand for absdi2?

--- 348,369 ----
    ""
    "NEGU %0,0,%1")

  (define_expand "negdf2"
+   [(parallel [(set (match_operand:DF 0 "register_operand" "=r")
+                    (neg:DF (match_operand:DF 1 "register_operand" "r")))
+               (use (match_dup 2))])]
+   ""
+ {
+   /* Emit bit-flipping sequence to be IEEE-safe wrt. -+0.  */
+   operands[2] = force_reg (DImode, GEN_INT ((HOST_WIDE_INT) 1 << 63));
+ })
+
+ (define_insn "*expanded_negdf2"
    [(set (match_operand:DF 0 "register_operand" "=r")
!         (neg:DF (match_operand:DF 1 "register_operand" "r")))
!    (use (match_operand:DI 2 "register_operand" "r"))]
    ""
!   "XOR %0,%1,%2")

  ;; FIXME: define_expand for absdi2?


brgds, H-P


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