public inbox for [email protected]  
help / color / mirror / Atom feed
From: John Naylor <[email protected]>
To: Thomas Munro <[email protected]>
Cc: pgsql-hackers <[email protected]>
Subject: Re: Using pg_bitutils.h in tidbitmap.c.
Date: Thu, 24 Apr 2025 08:47:13 +0700
Message-ID: <CANWCAZaH_SvFJMGaLspXN+HwyiMoGvVOTL8+UJQ9MXajOR65JA@mail.gmail.com> (raw)
In-Reply-To: <CA+hUKGLRN4_8sPHrwr4HDRV-_+_MddOyJ_Wc=2C2j6Hc0kkNig@mail.gmail.com>
References: <CA+hUKGLRN4_8sPHrwr4HDRV-_+_MddOyJ_Wc=2C2j6Hc0kkNig@mail.gmail.com>

On Mon, Apr 14, 2025 at 7:42 PM Thomas Munro <[email protected]> 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





view thread (3+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Using pg_bitutils.h in tidbitmap.c.
  In-Reply-To: <CANWCAZaH_SvFJMGaLspXN+HwyiMoGvVOTL8+UJQ9MXajOR65JA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox