[cairo] Re: Some other bits...
behdad at cs.toronto.edu
Thu Aug 18 15:42:37 PDT 2005
On Thu, 18 Aug 2005, [ISO-8859-1] Kristian Høgsberg wrote:
> There's a standard trick for this, though. If you want to guarantee
> arithmetic (signed) right shift, you can say:
> a = (b >> shift) | ~(-1 >> shift);
> On architectures that implement >> as arithmetic right shift, the last
> part of the expression, ~(-1 >> shift), should optimize to 0 and not
> cause any overhead. On architectures that implement >> as logical
> shift, the ~(-1 >> shift) evaluates to exactly the missing bits.
Then you fall into another hole: it assumes 2-complete arithmetic ;).
> It does feel a bit like a theoretical exercise, though.
More information about the cairo