pgsql: Use __attribute__((target(...))) for AVX-512 support. - Mailing list pgsql-committers

From Nathan Bossart
Subject pgsql: Use __attribute__((target(...))) for AVX-512 support.
Date
Msg-id E1t98fp-000foW-O1@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Use __attribute__((target(...))) for AVX-512 support.

Presently, we check for compiler support for the required
intrinsics both with and without extra compiler flags (e.g.,
-mxsave), and then depending on the results of those checks, we
pick which files to compile with which flags.  This is tedious and
complicated, and it results in unsustainable coding patterns such
as separate files for each portion of code may need to be built
with different compiler flags.

This commit introduces support for __attribute__((target(...))) and
uses it for the AVX-512 code.  This simplifies both the
configure-time checks and the build scripts, and it allows us to
place the functions that use the intrinsics in files that we
otherwise do not want to build with special CPU instructions.  We
are careful to avoid using __attribute__((target(...))) on
compilers that do not understand it, but we still perform the
configure-time checks in case the compiler allows using the
intrinsics without it (e.g., MSVC).

A similar change could likely be made for some of the CRC-32C code,
but that is left as a future exercise.

Suggested-by: Andres Freund
Reviewed-by: Raghuveer Devulapalli, Andres Freund
Discussion: https://postgr.es/m/20240731205254.vfpap7uxwmebqeaf%40awork3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f78667bd910ed5af90d927bbef30b181bc798ef7

Modified Files
--------------
config/c-compiler.m4                 |  64 +++++++-------
configure                            | 167 +++++++++--------------------------
configure.ac                         |  17 +---
meson.build                          |  21 ++---
src/Makefile.global.in               |   5 --
src/include/c.h                      |  12 +++
src/makefiles/meson.build            |   4 +-
src/port/Makefile                    |  12 +--
src/port/meson.build                 |   7 +-
src/port/pg_popcount_avx512.c        |  86 +++++++++++++++++-
src/port/pg_popcount_avx512_choose.c | 102 ---------------------
11 files changed, 185 insertions(+), 312 deletions(-)


pgsql-committers by date:

Previous
From: Álvaro Herrera
Date:
Subject: pgsql: doc: Reword ALTER TABLE ATTACH restriction on NO INHERIT constra
Next
From: Nathan Bossart
Date:
Subject: pgsql: Fix __attribute__((target(...))) usage.