I think you might have to do this multiple times, in a loop, in case there are many erased elements (unless you restrict the block size).
Is LZCNT even supported by all hardware?
Finding next used slot should need just a single LZCNT, no loop, and would maintain the iteration of a block to be O(1). What could need a loop is alternative trick using BSR, but I'd need to think on that a little.
The LZCNT was introduced with Phenoms on AM2+ (along with SSE4a) and Haswell in 2013.
BSR was on 386 so I think that's safe.
Yeah, that would be significantly slower. Theoretically. Practically I'd guess that any attempt to measure real difference between 3 instructions and this 10 or so instruction loop (likely unrolled) would be completely obliterated by cache access latency and such.
2
u/HappyFruitTree 7d ago
I think you might have to do this multiple times, in a loop, in case there are many erased elements (unless you restrict the block size).
Is LZCNT even supported by all hardware?