right shift of signed type

Jeffrey A Law law@cygnus.com
Sun Apr 9 10:48:00 GMT 2000


  In message < 38F0A167.7994F57@codesourcery.com >you write:
  > Hi,
  > 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.  


jeff



More information about the Gcc mailing list