centralize CPU feature detection
John Naylor <johncnaylorls@gmail.com>
From: John Naylor <johncnaylorls@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: root <tenistarkim@gmail.com>, Nathan Bossart <nathandbossart@gmail.com>
Date: 2026-02-15T13:04:01Z
Lists: pgsql-hackers
Attachments
- v1-0001-Rename-CRC-choose-files-for-future-general-purpos.patch (application/x-patch) patch v1-0001
- v1-0003-Refactor-the-detection-of-ZMM-registers.patch (application/x-patch) patch v1-0003
- v1-0002-Centralize-detection-of-CPU-features.patch (application/x-patch) patch v1-0002
- v1-0004-Enable-autovectorizing-page-checksums-with-AVX2-w.patch (application/x-patch) patch v1-0004
We have accrued duplicate bits of hardware detection logic in different places, and the the AVX2 page checksum patch is about to add more. It seems like a good time to try again to centralize things, before that happens. The attached only touches x86, but that's enough to demonstrate, and there's no point in trying to do everything at once. Arm should get the same treatment at some point. 0001 starts by renaming pg_crc32c_sse42_choose.c to something more general and does just enough to fix the build. Without a separate rename step, there's too much change for git to call it a rename. Humans can still see some carryover, so it seems right to keep git history continuous. 0002 adds an array of bool indexed by an enum of feature names, and adjusts the CRC and popcount code to use it. 0003 refactors detection of support for ZMM registers in preparation of doing same for YMM (needed by AVX2). 0004 rebases the latest page checksum patch on top of the above for demonstration (review of that is happening in its own thread [1]). Not counting autoconf/meson and the pointer juggling, the additional feature detection is now only 2 lines of code, which is nice. For PG20, we can build on this to simplify the rat's nest of #ifdefs that a couple of src/include/port headers have. We should also be able to arrange so that packagers that pass relevant flags to common compilers will automatically get some branches/indirection eliminated via the compiler's standard dead code elimination, in a simple way, rather than our having to kluge it together in multiple places. That will make irrelevant the question that occasionally come up about moving hardware requirements. Anyway, 0001-3 is doable for PG19. [1] https://postgr.es/m/CA%2BvA85_5GTu%2BHHniSbvvP%2B8k3%3DxZO%3DWE84NPwiKyxztqvpfZ3Q%40mail.gmail.com -- John Naylor Amazon Web Services
Commits
-
Remove extraneous PGDLLIMPORT
- ec5981c3816e 19 (unreleased) landed
-
Refactor detection of x86 ZMM registers
- 51bb4a58ed23 19 (unreleased) landed
-
Centralize detection of x86 CPU features
- 16743db061e4 19 (unreleased) landed
-
Fix USE_SLICING_BY_8_CRC32C builds on x86
- 3322f01a11b7 19 (unreleased) landed
-
Rename pg_crc32c_sse42_choose.c for general purpose
- b9278871f991 19 (unreleased) landed