Re: Proposal for enabling auto-vectorization for checksum calculations
John Naylor <johncnaylorls@gmail.com>
From: John Naylor <johncnaylorls@gmail.com>
To: Andrew Kim <tenistarkim@gmail.com>
Cc: Oleg Tselebrovskiy <o.tselebrovskiy@postgrespro.ru>,
pgsql-hackers@lists.postgresql.org
Date: 2026-03-17T02:23:25Z
Lists: pgsql-hackers
Attachments
- v12-0001-Benchmark-code-for-postgres-checksums.patch (text/x-patch) patch v12-0001
- v12-0002-Adjust-benchmark-to-use-core-checksum.patch (text/x-patch) patch v12-0002
- v12-0003-Enable-autovectorizing-page-checksums-with-AVX2-.patch (text/x-patch) patch v12-0003
On Mon, Mar 16, 2026 at 3:00 PM Andrew Kim <tenistarkim@gmail.com> wrote:
>
> It looks like your PostgreSQL build on Cirrus CI is failing during the
> Meson configuration phase because it cannot find the libedit
> libraries.
> Should we add these to the pacman installation command in our CI
> scripts, or is there a preferred way to handle terminal library
> dependencies for the Windows Meson builds?
I'll leave that to the people who maintain it. Sometimes intermittent
glitches happen. And please don't top-post.
I've attached v12 which is just a rebase over the new centralized
feature detection. I also have some review:
+# Check if the compiler supports AVX2 target attribute.
+# This is used for optimized checksum calculations with runtime detection.
It could possibly be used for other things, in which case this will
get out of date. It's most reliable to grep for the symbol to see
where something is used.
Also, the first statement is not true:
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdint.h>
+ #if defined(__has_attribute) && __has_attribute (target)
+ __attribute__((target("avx2")))
+ static int avx2_test(void)
+ {
+ return 0;
+ }
+ #endif],
With these guards, I think any compiler will pass the test, and CI
does show it passes on MSVC:
[01:09:52.888] Checking if "AVX2 support" links: YES
The consequence is that two functions get built with identical
non-AVX2 contents. Then at runtime we pick one of them, but it doesn't
matter which. This needs to test what it says it's testing.
--
John Naylor
Amazon Web Services
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Use AVX2 for calculating page checksums where available
- 5e13b0f24039 19 (unreleased) landed
-
Refactor checksumming code to make it easier to use externally.
- f04216341dd1 9.3.0 cited