diff options
author | John Naylor <john.naylor@postgresql.org> | 2023-08-10 11:36:15 +0700 |
---|---|---|
committer | John Naylor <john.naylor@postgresql.org> | 2023-08-10 11:36:15 +0700 |
commit | 4d14ccd6af6e788a7b79ff3ed77bda5bc71d2edc (patch) | |
tree | bef29664090f4cad6db22352d3c8a401bf724c27 /config/c-compiler.m4 | |
parent | fa2e874946c5b9f23394358c131e987df7cc8ffb (diff) | |
download | postgresql-4d14ccd6af6e788a7b79ff3ed77bda5bc71d2edc.tar.gz postgresql-4d14ccd6af6e788a7b79ff3ed77bda5bc71d2edc.zip |
Use native CRC instructions on 64-bit LoongArch
As with the Intel and Arm CRC instructions, compiler intrinsics for
them must be supported by the compiler. In contrast, no runtime check
is needed. Aligned memory access is faster, so use the Arm coding as
a model.
YANG Xudong
Discussion: https://postgr.es/m/b522a0c5-e3b2-99cc-6387-58134fb88cbe%40ymatrix.cn
Diffstat (limited to 'config/c-compiler.m4')
-rw-r--r-- | config/c-compiler.m4 | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4 index 5be8f0f08dc..5db02b2ab75 100644 --- a/config/c-compiler.m4 +++ b/config/c-compiler.m4 @@ -661,3 +661,36 @@ if test x"$Ac_cachevar" = x"yes"; then fi undefine([Ac_cachevar])dnl ])# PGAC_ARMV8_CRC32C_INTRINSICS + +# PGAC_LOONGARCH_CRC32C_INTRINSICS +# --------------------------- +# Check if the compiler supports the LoongArch CRCC instructions, using +# __builtin_loongarch_crcc_w_b_w, __builtin_loongarch_crcc_w_h_w, +# __builtin_loongarch_crcc_w_w_w and __builtin_loongarch_crcc_w_d_w +# intrinsic functions. +# +# We test for the 8-byte variant since platforms capable of running +# Postgres are 64-bit only (as of PG17), and we know CRC instructions +# are available there without a runtime check. +# +# If the intrinsics are supported, sets pgac_loongarch_crc32c_intrinsics. +AC_DEFUN([PGAC_LOONGARCH_CRC32C_INTRINSICS], +[define([Ac_cachevar], [AS_TR_SH([pgac_cv_loongarch_crc32c_intrinsics])])dnl +AC_CACHE_CHECK( + [for __builtin_loongarch_crcc_w_b_w, __builtin_loongarch_crcc_w_h_w, __builtin_loongarch_crcc_w_w_w and __builtin_loongarch_crcc_w_d_w], + [Ac_cachevar], +[AC_LINK_IFELSE([AC_LANG_PROGRAM([], + [unsigned int crc = 0; + crc = __builtin_loongarch_crcc_w_b_w(0, crc); + crc = __builtin_loongarch_crcc_w_h_w(0, crc); + crc = __builtin_loongarch_crcc_w_w_w(0, crc); + crc = __builtin_loongarch_crcc_w_d_w(0, crc); + /* return computed value, to prevent the above being optimized away */ + return crc == 0;])], + [Ac_cachevar=yes], + [Ac_cachevar=no])]) +if test x"$Ac_cachevar" = x"yes"; then + pgac_loongarch_crc32c_intrinsics=yes +fi +undefine([Ac_cachevar])dnl +])# PGAC_LOONGARCH_CRC32C_INTRINSICS |