lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Doug Rogers wrote:
> I'll need to go back and read your original reasoning on (*) 'Shift
> counts should be masked by the bit width', because I would think the
> masking should occur only for rotates. For shifts, the return value of a
> overshift should be zero (or all ones, a.k.a. -1 according to the
> Summary, for a sign-extended right shift with a sign bit of one).

Just check your own code base for usage examples of bit shifts.
I've used shift count masking more often than any other specific
treatment (whether in C or Assembler or Lua).

The masking behavior makes sense for *both* shifts and rotates.
And it doesn't need a special case for arithmetic right shift.

On some CPUs (e.g. x86) the mask operation can even be optimized
away by the C compiler or a Lua compiler. And as I've mentioned,
it doesn't need a branch ...

--Mike