[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Possible Bug in bitlib under Windows?
- From: Mike Pall <mikelu-0812@...>
- Date: Sat, 13 Dec 2008 20:35:19 +0100
Tim Channon wrote:
> I know it is creep-ism, not something I like.
Yes, that's why I dropped some bitfield functions I had originally
intended to add (IMHO this functionality is better left to a
struct (un)packing library).
> It would be good to include a few best-done-at-machine-level set operations.
>
> include(set, x)
> exclude(set, x)
> in(set, x)
Well, it's not that much longer to write this:
set = bor(set, lshift(1, x))
set = band(set, rol(-2, x))
(band(set, lshift(1, x)) ~= 0)
(and LJ2 knows how to turn it into the optimal machine code)
> count(set) (number of bits at 1)
Also called popcount. I know this one is ugly, but it's also rare.
And the sum-of-bitmasks solution is the best you can do right now,
anyway. Ok, so Intel added popcnt to SSE4.2 and the first CPU with
it is on the market since a few weeks. But I'm not convinced it
should be part of a general-purpose Lua bit operations library.
Recently I found myself needing find-last-set-bit quite often, but
then I wrote a register allocator (in C, not Lua). :-) Not sure
this is popular enough.
--Mike
- References:
- Re: Possible Bug in bitlib under Windows?, duck
- Re: Possible Bug in bitlib under Windows?, Andrew Gorges
- Re: Possible Bug in bitlib under Windows?, KHMan
- RE: Possible Bug in bitlib under Windows?, Jeff Wise
- Re: Possible Bug in bitlib under Windows?, KHMan
- Re: Possible Bug in bitlib under Windows?, David Manura
- Re: Possible Bug in bitlib under Windows?, Mike Pall
- Re: Possible Bug in bitlib under Windows?, Tim Channon
- Re: Possible Bug in bitlib under Windows?, Mike Pall
- Re: Possible Bug in bitlib under Windows?, Tim Channon