On Sat, 31 Jan 2026 at 15:48, John Naylor <johncnaylorls@gmail.com> wrote:
> + res += __builtin_ctz(~bits[bytenum]);
> If bits[bytenum] is 255, then __builtin_ctz(0) is undefined. The top
> of the function says
Oops, I forgot to cast the byte to uint32 before the bitwise-not. I've
fixed locally. Still processing Andres' comments.
> + * We expect that 'bits' contains at least one 0 bit somewhere in the mask,
> + * not necessarily < natts.
>
> ...in which case it should be well defined everywhere. Am I missing
> something? If we need to handle the 255 case, this should work:
>
> pg_rightmost_one_pos32(~((uint32) bits[bytenum]))
I'd rather handle that in a single byte as the fallback path in that
function requires byte-at-a-time processing.
David