mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Use ARMv8 CRC instructions where available.
ARMv8 introduced special CPU instructions for calculating CRC-32C. Use them, when available, for speed. Like with the similar Intel CRC instructions, several factors affect whether the instructions can be used. The compiler intrinsics for them must be supported by the compiler, and the instructions must be supported by the target architecture. If the compilation target architecture does not support the instructions, but adding "-march=armv8-a+crc" makes them available, then we compile the code with a runtime check to determine if the host we're running on supports them or not. For the runtime check, use glibc getauxval() function. Unfortunately, that's not very portable, but I couldn't find any more portable way to do it. If getauxval() is not available, the CRC instructions will still be used if the target architecture supports them without any additional compiler flags, but the runtime check will not be available. Original patch by Yuqi Gu, heavily modified by me. Reviewed by Andres Freund, Thomas Munro. Discussion: https://www.postgresql.org/message-id/HE1PR0801MB1323D171938EABC04FFE7FA9E3110%40HE1PR0801MB1323.eurprd08.prod.outlook.com
This commit is contained in:
@ -667,3 +667,37 @@ if test x"$Ac_cachevar" = x"yes"; then
|
||||
fi
|
||||
undefine([Ac_cachevar])dnl
|
||||
])# PGAC_SSE42_CRC32_INTRINSICS
|
||||
|
||||
|
||||
# PGAC_ARMV8_CRC32C_INTRINSICS
|
||||
# -----------------------
|
||||
# Check if the compiler supports the CRC32C instructions using the __crc32cb,
|
||||
# __crc32ch, __crc32cw, and __crc32cd intrinsic functions. These instructions
|
||||
# were first introduced in ARMv8 in the optional CRC Extension, and became
|
||||
# mandatory in ARMv8.1.
|
||||
#
|
||||
# An optional compiler flag can be passed as argument (e.g.
|
||||
# -march=armv8-a+crc). If the intrinsics are supported, sets
|
||||
# pgac_armv8_crc32c_intrinsics, and CFLAGS_ARMV8_CRC32C.
|
||||
AC_DEFUN([PGAC_ARMV8_CRC32C_INTRINSICS],
|
||||
[define([Ac_cachevar], [AS_TR_SH([pgac_cv_armv8_crc32c_intrinsics_$1])])dnl
|
||||
AC_CACHE_CHECK([for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=$1], [Ac_cachevar],
|
||||
[pgac_save_CFLAGS=$CFLAGS
|
||||
CFLAGS="$pgac_save_CFLAGS $1"
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <arm_acle.h>],
|
||||
[unsigned int crc = 0;
|
||||
crc = __crc32cb(crc, 0);
|
||||
crc = __crc32ch(crc, 0);
|
||||
crc = __crc32cw(crc, 0);
|
||||
crc = __crc32cd(crc, 0);
|
||||
/* return computed value, to prevent the above being optimized away */
|
||||
return crc == 0;])],
|
||||
[Ac_cachevar=yes],
|
||||
[Ac_cachevar=no])
|
||||
CFLAGS="$pgac_save_CFLAGS"])
|
||||
if test x"$Ac_cachevar" = x"yes"; then
|
||||
CFLAGS_ARMV8_CRC32C="$1"
|
||||
pgac_armv8_crc32c_intrinsics=yes
|
||||
fi
|
||||
undefine([Ac_cachevar])dnl
|
||||
])# PGAC_ARMV8_CRC32C_INTRINSICS
|
||||
|
Reference in New Issue
Block a user