fix alpha c++ failures

John David Anglin dave@hiauly1.hia.nrc.ca
Mon Jul 9 08:50:00 GMT 2001


> On Sun, Jul 08, 2001 at 01:56:54PM -0400, John David Anglin wrote:
> > >               emit_cmp_and_jump_insns (new_index,
> > > !                                      convert_modes (mode, imode,
> > > !                                        expand_expr (new_bound, NULL_RTX,
> > > !                                                     mode, 0),
> > > !                                        unsignedp),
> > 					   ^^^^^^^^^
> > 
> > Shouldn't this be `1'?  Consider the case where low and high are signed
> > and high - low is negative.
> 
> I don't think so, but I'll be glad to be shown wrong.
> 
> If both are extended unsigned, then the values are in the range
> 0000...00ff.  If both are extended signed, then the values are in
> the split range 0000...007f + ff80...ffff.  Either option works.

An unsigned comparison is used.  The split range is a problem when
we convert index_type to a larger mode.  For example if LOW and HIGH
are signed 8 bit, INDEX signed 16 bit, and say

LOW = -3 = 0xfd
HIGH = 126 = 0x7e
INDEX = 127 = 0x007f

then
NEW_BOUND = HIGH - LOW = 0x81
NEW_INDEX = INDEX - (sign extended to 16 bit mode)LOW = 130 = 0x0082

If the NEW_BOUND result is extended signed, the unsigned GT comparison
will fail and we won't branch to default_label.  However, INDEX is not
in the LOW to HIGH range and we should branch.

Because the tree is sorted, we know that LOW <= HIGH.  Thus, we don't
have to worry whether there was a carry or borrow in computing the
difference HIGH - LOW if the result is treated as unsigned.  This is
also true when HIGH and LOW are unsigned.  Thus, we should extend
NEW_BOUND as unsigned.  Another way to see that this is correct is
to extend HIGH and LOW before computing HIGH - LOW and INDEX - LOW.

> If, however, you extend one signed and one unsigned, then the 
> values don't come from the same range and you get a garbage result.
> Thus I believe NEW_BOUND must be extended as by UNSIGNEDP, since
> that is presumably how NEW_INDEX was extended.

Only LOW is extended in the calculation of NEW_INDEX.  There is an
implicit assumption that INDEX is signed if index_type is signed.
For example, if LOW = -1 and HIGH = 1, an INDEX value of 65535 would
test as being in the LOW to HIGH range.  Traditional K&R C requires
that the switch expression evaluate to int but gcc doesn't warn about an
unsigned switch expression.  Thus, possibly we need to be more careful
regarding the signedness of INDEX.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)



More information about the Gcc-patches mailing list