This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: portable signed right shift
- To: dewar at gnat dot com
- Subject: Re: portable signed right shift
- From: nbecker at fred dot net
- Date: 27 Mar 2001 22:01:37 -0500
- Cc: crosby at qwes dot math dot cmu dot edu, tm2 at best dot com, gcc at gcc dot gnu dot org
- References: <20010328025131.CF0DDF28A2@nile.gnat.com>
>>>>> "dewar" == dewar <dewar@gnat.com> writes:
dewar> <<y = x / (1<< N)
dewar> And trust the compiler to optimize it into a right-shift if that's
dewar> appropriate for the architecture?
>>>
dewar> Well in twos complement, that is not most peoples definition of a shift right
dewar> for example,
dewar> Consider that -5 = 11111111111111011
dewar> And -4 = 11111111111111100
dewar> and -2 = 11111111111111110
dewar> the result to most people of -5/2 = -2 would not seem like a shift :-)
dewar> Of course there is no clear definition of what a right shift of a signed
dewar> quantity means in the first place, and the original author did not give
dewar> us a definition, so in a sense your definition is as good as another :-)
Sorry, I meant right shift of 2's complement signed number.
So I guess the only efficient thing to do is use autoconf and #ifdefs.