Re: centralize CPU feature detection

From: John Naylor <johncnaylorls(at)gmail(dot)com>
To: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, root <tenistarkim(at)gmail(dot)com>, Nathan Bossart <nathandbossart(at)gmail(dot)com>
Subject: Re: centralize CPU feature detection
Date: 2026-02-17 13:14:38
Message-ID: CANWCAZbzmbCmKiCCWNGuC4FLymYfraJ+f1ZiWK3iOUnv9V9_Lg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Feb 17, 2026 at 3:15 AM Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> wrote:
>
> Hello!
>
> Seems like a file (checksum_block_internal.h) is missing from the patch?

Should work now, and thanks for looking.

> For the entire src/include/port/pg_x86_feature.h:
>
> Shouldn't it have an
>
> +#if defined(USE_SSE2) || defined(__i386__)
> ...
> #endif
>
> block around the file, to skip everything on other platforms?

Done. I haven't tried Arm support yet, but now I realize the header
should be named generically, so it's now "pg_cpu.h". Then it can be
included everywhere.

I've also gone with "pg_cpu_x86.c" for better consistency within this
directory, and used the plural for the array name.

> In src/include/port/pg_x86_feature.h:33
>
> +
> +extern PGDLLEXPORT bool X86Feature[];
> +
>
> Shouldn't that be PGDLLIMPORT?

Fixed.

> +typedef enum X86FeatureId
> +{
> + init,
> +
> + PG_SSE4_2,
> + PG_POPCNT,
>
>
> Shouldn't that be INIT?

I don't know. The instruction family names are conventionally all in
caps, but this is just our signal that we've populated the array. That
said, a less generic name would better for grep-ability.

I added some quick comments here where the instruction families are
split apart. I'm not sure what info is relevent, but it seemed good to
separate them.

--
John Naylor
Amazon Web Services

Attachment Content-Type Size
v2-0002-Centralize-detection-of-CPU-features.patch text/x-patch 9.8 KB
v2-0001-Rename-CRC-choose-files-for-future-general-purpos.patch text/x-patch 4.4 KB
v2-0004-Enable-autovectorizing-page-checksums-with-AVX2-w.patch text/x-patch 14.3 KB
v2-0003-Refactor-the-detection-of-ZMM-registers.patch text/x-patch 3.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2026-02-17 13:39:15 Re: index prefetching
Previous Message Aditya Kamath 2026-02-17 12:42:13 RE: AIX support