Re: Add RISC-V Zbb popcount optimization - Mailing list pgsql-hackers

From Greg Burd
Subject Re: Add RISC-V Zbb popcount optimization
Date
Msg-id ec81011b-c502-4702-b041-e4bdd2aa346f@app.fastmail.com
Whole thread Raw
In response to Re: Add RISC-V Zbb popcount optimization  (John Naylor <johncnaylorls@gmail.com>)
Responses Re: Add RISC-V Zbb popcount optimization
List pgsql-hackers
On Sat, Mar 21, 2026, at 10:14 PM, John Naylor wrote:
> On Sat, Mar 21, 2026 at 11:56 PM Greg Burd <greg@burd.me> wrote:
>> Attached is a small patch that enables hardware popcount on RISC-V when available and also sets the arch flag to
'rv64gc_zbb'flag when appropriate. 
>
> I have to ask what the point is -- isn't that like putting a 4-inch
> exhaust tip on a go-kart?

Hey John,

The point is to go fast, right? And to look cool (with awesome 4-inch exhaust tips) if possible! ;-P

gburd@rv:~/ws/postgres$ gcc -O2 -o popcnt-wo-zbb riscv-popcnt.c
gburd@rv:~/ws/postgres$ gcc -O2 -march=rv64gc_zbb -o popcnt-zbb riscv-popcnt.c
gburd@rv:~/ws/postgres$ ./popcnt-wo-zbb && ./popcnt-zbb
sw popcount:    0.196 sec  (    510.08 MB/s)
hw popcount:    0.293 sec  (    341.48 MB/s)

diff: 0.67x
match: 406261900 bits counted
sw popcount:    0.182 sec  (    548.86 MB/s)
hw popcount:    0.044 sec  (   2279.89 MB/s)

diff: 4.15x
match: 406261900 bits counted

But my first email/patch was incomplete/rushed, I should have followed the pattern used for similar ARM-specific logic.
v2 attached along with a test program. 

> --
> John Naylor
> Amazon Web Services

best.

-greg

Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: pg_waldump: support decoding of WAL inside tarfile
Next
From: Andres Freund
Date:
Subject: Re: Add RISC-V Zbb popcount optimization