On Mon, Apr 14, 2025 at 7:42 PM Thomas Munro <thomas.mu...@gmail.com> wrote: > > tidbitmap.c's operations loop over all the bits, but could leap over > zeros with bitmap instructions like bitmapset.c. Hard to imagine that > matters, but I think it also comes out easier to read?
Interesting idea -- I toyed with something like this when TID store was being developed. Most of it looks more readable at a glance, although tbm_advance_schunkbit() may be a wash. +bmw_pop_rightmost_one(bitmapword *word) +{ + int position = bmw_rightmost_one_pos(*word); + + *word &= ~((bitmapword) 1 << position); + + return position; +} There's a more succinct way to write the second statement, since here we only care about the rightmost bit: *word &= *word - 1; That has a bonus in that we don't need to know "position" beforehand, so the CPU can schedule that independently of the bitscan, which is 3 or 4 cycles on modern hardware, but like you said, I'm not sure if that matters. -- John Naylor Amazon Web Services