This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: portable signed right shift
- To: Toshi Morita <tm2 at best 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 21:34:24 -0500 (EST)
- cc: nbecker at fred dot net, gcc at gcc dot gnu dot org
On Tue, 27 Mar 2001, Toshi Morita wrote:
> >
> > OK, great. So what is an efficient, portable way to get a signed
> > right shift?
> >
>
> Cast to unsigned, shift(s) right, set the high bit(s) if orignially negative,
> then cast to signed.
>
Wouldn't it be easier to do:
y = x / (1<< N)
And trust the compiler to optimize it into a right-shift if that's
appropriate for the architecture?
Scott.