This is the mail archive of the
mailing list for the GCC project.
Re: right shift of signed type
- To: Nathan Sidwell <nathan at codesourcery dot com>
- Subject: Re: right shift of signed type
- From: Jeffrey A Law <law at cygnus dot com>
- Date: Sun, 09 Apr 2000 10:40:46 -0600
- cc: gcc at gcc dot gnu dot org
- Reply-To: law at cygnus dot com
In message <38F0A167.7994F57@codesourcery.com>you write:
> A right shift of a negative signed type is implementation defined. I'm
> trying to determine whether gcc implements this as an arithmetic shift
> (which is quite common). I think it does, but I can't find a definitive
> statement -- extend.texi doesn't mention it for instance.
It's pretty simple.
An arithmetic left shift is equivalent to a logical left shift
(as far as GCC is concerned).
For right shifts, if the type is signed, then we use an arithmetic shift;
if the type is unsigned then we use a logical.
At the tree level, we have access to the type information, so we only
need RSHIFT & LSHIFT exprs. When we convert the tree to rtl, we examine
the type and generate an appropriate shift for rtl (which does not carry
around type information).
At the RTL level we have ASHIFT which is a shift left (remember arith and
logical shift left is the same for GCC) and we have ASHIFTRT/LSHIFTRT for
arithmetic & logical shift right.
> /* Right shift operations, for machines where these are not the same
> as left shifting with a negative argument. */
I believe this comment is out of date.