| From: | Nathan Bossart <nathandbossart(at)gmail(dot)com> |
|---|---|
| To: | John Naylor <johncnaylorls(at)gmail(dot)com> |
| Cc: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: refactor architecture-specific popcount code |
| Date: | 2026-01-26 15:41:35 |
| Message-ID: | aXeLLydy1lxMwcCv@nathan |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Thu, Jan 22, 2026 at 11:50:38AM -0600, Nathan Bossart wrote:
> On Thu, Jan 22, 2026 at 04:50:26PM +0700, John Naylor wrote:
>> 1) Nowadays, the only global call sites of the word-sized functions
>> are select_best_grantor() and in bitmapsets. The latter calls the
>> word-sized functions in a loop (could be just one word). It may be
>> more efficient to calculate the size in bytes and call pg_popcount().
>
> Yeah, these seem like obvious places to use pg_popcount(). Note that
> bms_member_index() does a final popcount on a masked version of the last
> word. We could swap that with pg_popcount(), too, but it might be slower
> than just calling the word-sized function. However, it could be hard to
> tell the difference, as we'd be trading a function or function pointer call
> with an inlined loop over pg_number_of_ones. And even if it is slower, I'm
> not sure it matters all that much in the grand scheme of things.
I added a 0003 that swaps that final popcount with pg_popcount().
>> Then we could get rid of all the pointer indirection for the
>> word-sized functions.
>
> Do you mean that we'd just keep the portable ones around? I see some code
> in pgvector that might be negatively impacted by that, but if I understand
> correctly it would require an unusual setup.
I added a 0004 that removes the architecture-specific word-sized functions.
--
nathan
| Attachment | Content-Type | Size |
|---|---|---|
| v4-0001-Make-use-of-pg_popcount-in-more-places.patch | text/plain | 2.1 KB |
| v4-0002-Remove-unnecessary-32-bit-optimizations-and-align.patch | text/plain | 2.5 KB |
| v4-0003-Remove-bmw_popcount.patch | text/plain | 1.7 KB |
| v4-0004-Remove-specialized-word-length-popcount-implement.patch | text/plain | 9.1 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Andres Freund | 2026-01-26 15:41:02 | Re: AIX support |