Re: Add RISC-V Zbb popcount optimization

From: "Greg Burd" <greg(at)burd(dot)me>
To: "Andres Freund" <andres(at)anarazel(dot)de>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add RISC-V Zbb popcount optimization
Date: 2026-03-21 18:49:22
Message-ID: b372e6c4-f68a-40be-bb25-a34f23725f25@app.fastmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On Sat, Mar 21, 2026, at 2:36 PM, Andres Freund wrote:
> Hi,
>
> On 2026-03-21 12:54:10 -0400, Greg Burd 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.
>
> Maybe I'm missing something: How is the latter approach safe without a runtime
> check? Just because it compiled on the build machine with -march=rv64gc_zbb
> added doesn't mean it runs on either the build machine or any other machine?
>
> If this worked, the compiler could just always specify -march=rv64gc_zbb, no?

Hey Andres, thanks for taking a look.

You are correct, mea culpa for not catching this before I sent it out. If the second test succeeds the patch will add `-march=rv64gc_zbb` to `CFLAGS` globally, which means without the runtime check the binary will crash with SIGILL on systems without Zbb.

I'll rework... :)

> Greetings,
>
> Andres Freund

best.

-greg

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-03-21 19:31:10 Re: pg_waldump: support decoding of WAL inside tarfile
Previous Message Javier Gutierrez-Maturana sanchez 2026-03-21 18:44:42 Proposal: Implementing Botan as an alternative TLS backend for PostgreSQL