From: John Naylor <john.naylor@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Compute CRC32C using AVX-512 instructions where available
Date: Sun, 06 Apr 2025 07:07:15 +0000
Message-ID: <E1u1K67-002vUq-11@gemulon.postgresql.org> (raw)
Compute CRC32C using AVX-512 instructions where available
The previous implementation of CRC32C on x86 relied on the native
CRC32 instruction from the SSE 4.2 extension, which operates on
up to 8 bytes at a time. We can get a substantial speedup by using
carryless multiplication on SIMD registers, processing 64 bytes per
loop iteration. Shorter inputs fall back to ordinary CRC instructions.
On Intel Tiger Lake hardware (2020), CRC is now 50% faster for inputs
between 64 and 112 bytes, and 3x faster for 256 bytes.
The VPCLMULQDQ instruction on 512-bit registers has been available
on Intel hardware since 2019 and AMD since 2022. There is an older
variant for 128-bit registers, but at least on Zen 2 it performs worse
than normal CRC instructions for short inputs.
We must now do a runtime check, even for builds that target SSE
4.2. This doesn't matter in practice for WAL (arguably the most
critical case), because since commit e2809e3a1 the final computation
with the 20-byte WAL header is inlined and unrolled when targeting
that extension. Compared with two direct function calls, testing
showed equal or slightly faster performance in performing an indirect
function call on several dozen bytes followed by inlined instructions
on constant input of 20 bytes.
The MIT-licensed implementation was generated with the "generate"
program from
https://github.com/corsix/fast-crc32/
Based on: "Fast CRC Computation for Generic Polynomials Using PCLMULQDQ
Instruction" V. Gopal, E. Ozturk, et al., 2009
Co-authored-by: Raghuveer Devulapalli <raghuveer.devulapalli@intel.com>
Co-authored-by: Paul Amonson <paul.d.amonson@intel.com>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de> (earlier version)
Reviewed-by: Matthew Sterrett <matthewsterrett2@gmail.com> (earlier version)
Tested-by: Raghuveer Devulapalli <raghuveer.devulapalli@intel.com>
Tested-by: David Rowley <<dgrowleyml@gmail.com>> (earlier version)
Discussion: https://postgr.es/m/BL1PR11MB530401FA7E9B1CA432CF9DC3DC192@BL1PR11MB5304.namprd11.prod.outlook.com
Discussion: https://postgr.es/m/PH8PR11MB82869FF741DFA4E9A029FF13FBF72@PH8PR11MB8286.namprd11.prod.outlook.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/3c6e8c123896584f1be1fe69aaf68dcb5eb094d5
Modified Files
--------------
config/c-compiler.m4 | 37 ++++++++++++++
configure | 91 +++++++++++++++++++++++++++++----
configure.ac | 41 ++++++++++-----
meson.build | 58 +++++++++++++++++----
src/include/pg_config.h.in | 3 ++
src/include/port/pg_crc32c.h | 39 +++++++++++----
src/port/meson.build | 1 +
src/port/pg_crc32c_sse42.c | 94 ++++++++++++++++++++++++++++++++++-
src/port/pg_crc32c_sse42_choose.c | 75 ++++++++++++++++++++++------
src/test/regress/expected/strings.out | 24 +++++++++
src/test/regress/sql/strings.sql | 5 ++
11 files changed, 408 insertions(+), 60 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: john.naylor@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Compute CRC32C using AVX-512 instructions where available
In-Reply-To: <E1u1K67-002vUq-11@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox