Re: Using pg_bitutils.h in tidbitmap.c. - Mailing list pgsql-hackers

From John Naylor
Subject Re: Using pg_bitutils.h in tidbitmap.c.
Date
Msg-id CANWCAZaH_SvFJMGaLspXN+HwyiMoGvVOTL8+UJQ9MXajOR65JA@mail.gmail.com
Whole thread Raw
In response to Using pg_bitutils.h in tidbitmap.c.  (Thomas Munro <thomas.munro@gmail.com>)
List pgsql-hackers
On Mon, Apr 14, 2025 at 7:42 PM Thomas Munro <thomas.munro@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



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: AIO v2.5
Next
From: jian he
Date:
Subject: Re: support ALTER COLUMN SET EXPRESSION over virtual generated column with check constraint