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: portable signed right shift


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.


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