Re: refactor architecture-specific popcount code

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: John Naylor <johncnaylorls(at)gmail(dot)com>
Cc: Greg Burd <greg(at)burd(dot)me>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: refactor architecture-specific popcount code
Date: 2026-02-20 21:33:34
Message-ID: aZjTLiA9xFjQpJ7G@nathan
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Feb 20, 2026 at 09:39:38AM -0600, Nathan Bossart wrote:
> I spent some time looking at how clang/gcc compiled the plain-C version on
> various architectures [0], and I was pleasantly surprised to discover that
> at some point in recent history they started automatically converting it to
> special popcount instructions. I suspect that you'd see better results on
> ppc64le if you upgraded the compiler...

If we're willing to rely on this behavior, we could even remove
pg_popcount64_neon() and pg_popcount64_sse42(). We still need to add
"pg_attribute_target("popcnt")" and a corresponding configure check for the
x86 stuff, so it's not as impressive from a code-removal standpoint, but it
at least allows us to remove some uses of intrinsics and inline assembly.

--
nathan

Attachment Content-Type Size
v15-0001-Remove-uses-of-popcount-builtins.patch text/plain 17.9 KB
v15-0002-Make-use-of-pg_popcount-in-more-places.patch text/plain 3.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2026-02-20 21:34:47 Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access)
Previous Message Heikki Linnakangas 2026-02-20 21:03:09 Re: PGPROC alignment (was Re: pgsql: Separate RecoveryConflictReasons from procsignals)