[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: native code for bitwise operators in LUA
- From: Patrick Rapin <toupie300@...>
- Date: Fri, 4 Nov 2011 10:20:16 +0100
> local idx = param[4] & 7
> TileCache[idx] = {
> Format = TextureFormat[param[1] >> 5],
> Size = (param[1] >> 3) & 3,
> Line = ((param[1] & 3) << 7) | (param[2] >> 1),
> TMem = ((param[2] & 1) << 8) | param[3],
> Palette = param[5] >> 4,
> TFlags = (param[5] >> 2) & 3,
> TMask = ((param[5] & 3) << 2) | (param[6] >> 6),
> TShift = (param[6] >> 2) & 15,
> SFlags = param[6] & 3,
> SMask = param[7] >> 4,
> SShift = param[7] & 0xF }
>
> Trying to port it to using the
> bit library is very error-prone and makes the code even more ugly and
> hard to follow.
Not necessarily. Using bit32.extract, I even think it may because
easier to understand.
Supposing that param[1] contains the 4 high bytes and param[2] the low
bytes, your code become:
local extract = bit32.extract
local idx = extract(param[2], 0, 3)
TileCache[idx] = {
Format = TextureFormat[extract(param[1], 29, 3)],
Size = extract(param[1], 27, 2),
Line = extract(param[1], 17, 8),
TMem = extract(param[1], 8, 9),
Palette = extract(param[2], 28, 4),
TFlags = extract(param[2], 26, 2),
TMask = extract(param[2], 22, 4),
TShift = extract(param[2], 18, 4),
SFlags = extract(param[2], 16, 2),
SMask = extract(param[2], 12, 4),
SShift = extract(param[2], 8, 4)}