This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Invalid right shift in genautomata.c
- From: Vladimir Makarov <vmakarov at redhat dot com>
- To: Neil Booth <neil at daikokuya dot demon dot co dot uk>, gcc-bugs at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Thu, 23 May 2002 17:59:55 -0400
- Subject: Re: Invalid right shift in genautomata.c
- References: <20020523180203.GA22190@daikokuya.demon.co.uk> <3CED40CB.996EDF35@redhat.com> <20020523193210.GB23277@daikokuya.demon.co.uk> <3CED4631.EA8DFC08@redhat.com>
Vladimir Makarov wrote:
>
> Neil Booth wrote:
> >
> > Vladimir Makarov wrote:-
> >
> > > Actually this is not a bug, Neil. The shift is not used when compiler
> > > generates the message (it is even gone after dead code elimination).
> > >
> > > To speed up genautomata, all bit operations are executed on
> > > HOST_WIDE_INT. This type is used also to hash the bitstring. Htab uses
> > > unsigned as a hash key. So I need to convert HOST_WIDE_INT into
> > > unsigned. I could make it by `(unsigned) key'. But that would result
> > > in bad hash keys when the number units > sizeof (unsigned) * CHAR_BIT.
> > > Therefore I hash HOST_WIDE_INT using the shift. But it is made only
> > > when sizeof (unsigned) < sizeof (HOST_WIDE_INT).
> >
> > Ah, OK. It's a shame we still get the message.
> >
>
> Ok, I'll try fix it in another way.
Here is the patch fixing the warning. I think it generates the better
hash too. I've committed it into the mainline.
Vlad
2002-05-23 Vladimir Makarov <vmakarov@redhat.com>
* genautomata.c (reserv_sets_hash_value): Use shift equal to 3/4
of size of unsigned.
Index: genautomata.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/genautomata.c,v
retrieving revision 1.13
diff -c -p -r1.13 genautomata.c
*** genautomata.c 21 May 2002 23:27:04 -0000 1.13
--- genautomata.c 23 May 2002 21:53:38 -0000
*************** reserv_sets_hash_value (reservs)
*** 3413,3422 ****
if (sizeof (set_el_t) <= sizeof (unsigned))
return hash_value;
result = 0;
! for (i = sizeof (set_el_t); i > 0; i -= sizeof (unsigned))
{
result += (unsigned) hash_value;
! hash_value >>= sizeof (unsigned) * CHAR_BIT;
}
return result;
}
--- 3413,3422 ----
if (sizeof (set_el_t) <= sizeof (unsigned))
return hash_value;
result = 0;
! for (i = sizeof (set_el_t); i > 0; i -= sizeof (unsigned) - 1)
{
result += (unsigned) hash_value;
! hash_value >>= (sizeof (unsigned) - 1) * CHAR_BIT;
}
return result;
}