9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] BUG!!! in Plan9 compiler!
@ 2010-04-22 15:29 tlaronde
  2010-04-22 17:03 ` Bakul Shah
  0 siblings, 1 reply; 20+ messages in thread
From: tlaronde @ 2010-04-22 15:29 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

So I have finally narrow down and compare the calculus under
NetBSD/i386/gcc and Plan9/i386/ken-cc. And this has nothing to do with
div versus shift...

ken-cc is at fault here and it seems deep; it has apparently to deal
with registerization.

Data:
Under NetBSD/gcc, I have the following values:

	before: x1:=5440, x2:=-5843, x3:=78909
	after: x1:=5440, x2:=-201, x3:=18166, r:=6827 t:=30232

Under Plan9/gcc, I have the following values:

	before: x1:=5440, x2:=-5843, x3:=78909
	after: x1:=5440, x2:=2147483447, x3:=1073759990, r:=6827 t:=-1073711592

Uhm... seems to have a `slight' divergence...

In fact, all wrong values depend upon x2, that has the "correct"
value... with 2^31 complement. A positive when it should be negative,
since the offending code is the following:

      x2 = half ( x1 + x2 + xicorr ) ;

	  that is :
		x2 = (5440 - 5843 + 1) / 2;

Not exactly pushing things to the limit! And yes, the expected result is
indeed -201.

In fact, if you just extract this kind of expression, and compile a
test, there is no problem.

But the calling function is teratologic: it has 10 parameters and 18
automatic variables.

Since the problem arises in this context, but not if you just add
this isolated in a test program, and call it with these very 3
values (5440, -5843, 1), it is clear that's the way the computation
is handled with huge number of parameters and auto variables
that wreaks havoc.

If I declare all the auto volatile, this does nothing: same result.

If I do the addition, and afterwards take the half, that works:

x2 += x1 + xicorr;
x2 = half(x2);	/* works! */

Problem: this is not a solution, but a hack, since this kind of 3
variables handling is common. This one fails. And the others?

Is there a limit about the number of parameters?
--
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                      http://www.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C



^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2010-04-25  0:31 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-22 15:29 [9fans] BUG!!! in Plan9 compiler! tlaronde
2010-04-22 17:03 ` Bakul Shah
2010-04-22 17:36   ` tlaronde
2010-04-22 17:50     ` tlaronde
2010-04-22 19:08       ` geoff
2010-04-22 19:32         ` tlaronde
2010-04-22 20:07           ` Bakul Shah
2010-04-22 21:15             ` tlaronde
2010-04-22 21:26               ` tlaronde
2010-04-22 22:49               ` Bakul Shah
2010-04-23  7:42                 ` tlaronde
2010-04-23 18:53                 ` C H Forsyth
2010-04-23 18:51                   ` tlaronde
2010-04-23 20:08                   ` Bakul Shah
2010-04-23 20:46                     ` ron minnich
2010-04-23 21:44                       ` erik quanstrom
2010-04-23 22:34                       ` erik quanstrom
2010-04-24 18:59                         ` Bakul Shah
2010-04-24 21:47                           ` Charles Forsyth
2010-04-25  0:31                           ` erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).