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: Scott A Crosby <crosby at qwes dot math dot cmu dot edu>
- Date: Tue, 27 Mar 2001 23:20:40 -0500 (EST)
- cc: nbecker at fred dot net, gcc at gcc dot gnu dot org, tm2 at best dot com
On Tue, 27 Mar 2001 dewar@gnat.com wrote:
> <<Sorry, I meant right shift of 2's complement signed number.
> >>
>
> I know, and that was my example
>
> -5 = 11111111111111011
>
> -2 = 11111111111111110
>
> Most people would expect either
> 11111111111111101 (if sign extension)
> 01111111111111101 (if no sign extension)
>
> and the divide will typically give
>
> 11111111111111110
>
Ah... I wasn't thinking of this... I guess it's sorta of an issue as to
what you intend when dividing? Round-to-negative, or round-to-zero.
If you use division, you get the effect of round-to-zero.
Your other example of a sign-extending shift to the right is an example of
round-to-negative.
I guess it depends on what semantics you want.
Scott.