This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: right shift of signed type



  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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]