lua-users home
lua-l archive

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


Mike Pall wrote:
> Also, considering the readability aspect, what does this do:
>   bit.bshift(x, -8)  ??
> Shift right by 8? Shift left by 8? I'm sure I'm not the only one
> who had to look it up in the manual.
> ...
>  bit.lshift(x, 8)  vs.  bit.rshift(x, 8) 
> Readibility is important. And having two functions avoids an
> unpredictable branch, too. Ditto for rotates.

I agree.

> Summary:
> - Inputs to bit operations need to be converted in a consistent and
>   platform-independent way, respecting modular arithmetic requirements.
> - Outputs of bit operations need to be signed.
> - Shift and rotate instructions need to be explicitly named.
> -*Shift counts should be masked by the bit width.
> - Arithmetic right shift is not optional.
> - Ignoring the naming conventions defined by the most popular
>   existing libraries is unwise, because it forces all users to
>   rewrite their code (FYI: BitOp inherited the names from lbitlib).

A much better rant, IMO.

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).

Doug

______________________________________________________________________________________
The information contained in this email transmission may contain proprietary and business 
sensitive information.  If you are not the intended recipient, you are hereby notified that 
any review, dissemination, distribution or duplication of this communication is strictly 
prohibited.  Unauthorized interception of this e-mail is a violation of law.  If you are not 
the intended recipient, please contact the sender by reply email and immediately destroy all 
copies of the original message.

Any technical data and/or information provided with or in this email may be subject to U.S. 
export controls law.  Export, diversion or disclosure contrary to U.S. law is prohibited.  
Such technical data or information is not to be exported from the U.S. or given to any foreign
person in the U.S. without prior written authorization of Elbit Systems of America and the 
appropriate U.S. Government agency.