From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Edelsohn To: Jay Monkman Cc: egcs@cygnus.com Subject: Re: Is this a bug? Date: Thu, 07 May 1998 23:40:00 -0000 Message-id: <9805080331.AA22786@rios1.watson.ibm.com> References: <199805072118.QAA05795@winslow.net66.net> X-SW-Source: 1998-05/msg00266.html >>>>> Jay Monkman writes: Jay> For the second add (temp=base + (unsigned long)0x8000;) the compiler Jay> seems to want to do a Jay> signed addition even though all the variables are unsigned. Jay> temp=base + (unsigned long)0x8000; Jay> // lwz 9,8(31) Load R9 with base Jay> // addis 11,9,0x1 add 0x10000 and store in R11 - why is Jay> this instruction here? Jay> // addi 0,11,-32768 add 0x8000 and store in R0 Jay> // stw 0,12(31) store R0 as temp in stack frame This is not a bug. If you actually look at the results produced on PowerPC, they are correct. On PowerPC, additions by constants always are signed, so GCC needs to compensate when performing an unsigned addition by biasing the carry so that the result will be correct. You also should mention that GCC only produces this sequence of instructions for this example when not optimizing. David =============================================================================== David Edelsohn T.J. Watson Research Center dje@watson.ibm.com P.O. Box 218 +1 914 945 4364 (TL 862) Yorktown Heights, NY 10598