lua-users home
lua-l archive

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

On Wed, Jul 10, 2013 at 3:50 PM, Doug Currie <> wrote:

> Well, as a programmer weaned on embedded control in tiny hardware,

All the 6502 weenies on the list are trying to decide how tiny is
tiny. :-) OK, a 68HC11 is pretty luxurious...

> a number is just one way to interpret a bit pattern. There are a lot of interesting things that can be done with these bit patterns that blur the distinction between numbers and "non-numbers," whatever those are.
> Examples (in C) of things I've found useful in my work:
> - isolate the rightmost set bit: x & (-x)
> - sign extend a field: ((x ^ N) - N) -- where N is the numeric representation of the sign bit, e.g., 32768 for 16 bits
> - integer log base 2:

Let me second to
those who have not seen it.

On the other hand many of those tricks are especially useful in tight
loops and vectorized/pipelined. In PUC-Rio liblua, interpreter
overhead can swamp the actual bitops, (consider all the unpredicted
branches etc). A call to a C function like bit32.extract can be cheap
if it performs multiple steps. Even if some of those steps are
unnecessary, they're cheaper than dispatching more bytecode.

LuaJIT is different, but the spirit of LuaJIT is to give you both
diamond and obsidian knives to cut (yourself) with.