Skip to content

Commit 5980f18

Browse files
committed
Update configure probes for CFLAGS needed for ARM CRC instructions.
On ARM platforms where the baseline CPU target lacks CRC instructions, we need to supply a -march flag to persuade the compiler to compile such instructions. It turns out that our existing choice of "-march=armv8-a+crc" has not worked for some time, because recent gcc will interpret that as selecting software floating point, and then will spit up if the platform requires hard-float ABI, as most do nowadays. The end result was to silently fall back to software CRC, which isn't very desirable since in practice almost all currently produced ARM chips do have hardware CRC. We can fix this by using "-march=armv8-a+crc+simd" to enable the correct ABI choice. (This has no impact on the code actually generated, since neither of the files we compile with this flag does any floating-point stuff, let alone SIMD.) Keep the test for "-march=armv8-a+crc" since that's required for soft-float ABI, but try that second since most platforms we're likely to build on use hard-float. Since this isn't working as-intended on the last several years' worth of gcc releases, back-patch to all supported branches. Discussion: https://postgr.es/m/4496616.iHFcN1HehY@portable-bastien
1 parent 4570b22 commit 5980f18

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

configure

+45-2
Original file line numberDiff line numberDiff line change
@@ -17482,7 +17482,8 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
1748217482
# Check for ARMv8 CRC Extension intrinsics to do CRC calculations.
1748317483
#
1748417484
# First check if __crc32c* intrinsics can be used with the default compiler
17485-
# flags. If not, check if adding -march=armv8-a+crc flag helps.
17485+
# flags. If not, check if adding "-march=armv8-a+crc+simd" flag helps.
17486+
# On systems using soft-float ABI, "-march=armv8-a+crc" is required instead.
1748617487
# CFLAGS_CRC is set if the extra flag is required.
1748717488
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=" >&5
1748817489
$as_echo_n "checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=... " >&6; }
@@ -17525,7 +17526,48 @@ if test x"$pgac_cv_armv8_crc32c_intrinsics_" = x"yes"; then
1752517526
fi
1752617527

1752717528
if test x"$pgac_armv8_crc32c_intrinsics" != x"yes"; then
17528-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc" >&5
17529+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc+simd" >&5
17530+
$as_echo_n "checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc+simd... " >&6; }
17531+
if ${pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd+:} false; then :
17532+
$as_echo_n "(cached) " >&6
17533+
else
17534+
pgac_save_CFLAGS=$CFLAGS
17535+
CFLAGS="$pgac_save_CFLAGS -march=armv8-a+crc+simd"
17536+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
17537+
/* end confdefs.h. */
17538+
#include <arm_acle.h>
17539+
int
17540+
main ()
17541+
{
17542+
unsigned int crc = 0;
17543+
crc = __crc32cb(crc, 0);
17544+
crc = __crc32ch(crc, 0);
17545+
crc = __crc32cw(crc, 0);
17546+
crc = __crc32cd(crc, 0);
17547+
/* return computed value, to prevent the above being optimized away */
17548+
return crc == 0;
17549+
;
17550+
return 0;
17551+
}
17552+
_ACEOF
17553+
if ac_fn_c_try_link "$LINENO"; then :
17554+
pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd=yes
17555+
else
17556+
pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd=no
17557+
fi
17558+
rm -f core conftest.err conftest.$ac_objext \
17559+
conftest$ac_exeext conftest.$ac_ext
17560+
CFLAGS="$pgac_save_CFLAGS"
17561+
fi
17562+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd" >&5
17563+
$as_echo "$pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd" >&6; }
17564+
if test x"$pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd" = x"yes"; then
17565+
CFLAGS_CRC="-march=armv8-a+crc+simd"
17566+
pgac_armv8_crc32c_intrinsics=yes
17567+
fi
17568+
17569+
if test x"$pgac_armv8_crc32c_intrinsics" != x"yes"; then
17570+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc" >&5
1752917571
$as_echo_n "checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc... " >&6; }
1753017572
if ${pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrc+:} false; then :
1753117573
$as_echo_n "(cached) " >&6
@@ -17565,6 +17607,7 @@ if test x"$pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrc" = x"yes"; then
1756517607
pgac_armv8_crc32c_intrinsics=yes
1756617608
fi
1756717609

17610+
fi
1756817611
fi
1756917612

1757017613
# Check for LoongArch CRC intrinsics to do CRC calculations.

configure.ac

+6-2
Original file line numberDiff line numberDiff line change
@@ -2088,11 +2088,15 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
20882088
# Check for ARMv8 CRC Extension intrinsics to do CRC calculations.
20892089
#
20902090
# First check if __crc32c* intrinsics can be used with the default compiler
2091-
# flags. If not, check if adding -march=armv8-a+crc flag helps.
2091+
# flags. If not, check if adding "-march=armv8-a+crc+simd" flag helps.
2092+
# On systems using soft-float ABI, "-march=armv8-a+crc" is required instead.
20922093
# CFLAGS_CRC is set if the extra flag is required.
20932094
PGAC_ARMV8_CRC32C_INTRINSICS([])
20942095
if test x"$pgac_armv8_crc32c_intrinsics" != x"yes"; then
2095-
PGAC_ARMV8_CRC32C_INTRINSICS([-march=armv8-a+crc])
2096+
PGAC_ARMV8_CRC32C_INTRINSICS([-march=armv8-a+crc+simd])
2097+
if test x"$pgac_armv8_crc32c_intrinsics" != x"yes"; then
2098+
PGAC_ARMV8_CRC32C_INTRINSICS([-march=armv8-a+crc])
2099+
fi
20962100
fi
20972101

20982102
# Check for LoongArch CRC intrinsics to do CRC calculations.

meson.build

+7
Original file line numberDiff line numberDiff line change
@@ -2284,6 +2284,13 @@ int main(void)
22842284
# Use ARM CRC Extension unconditionally
22852285
cdata.set('USE_ARMV8_CRC32C', 1)
22862286
have_optimized_crc = true
2287+
elif cc.links(prog, name: '__crc32cb, __crc32ch, __crc32cw, and __crc32cd with -march=armv8-a+crc+simd',
2288+
args: test_c_args + ['-march=armv8-a+crc+simd'])
2289+
# Use ARM CRC Extension, with runtime check
2290+
cflags_crc += '-march=armv8-a+crc+simd'
2291+
cdata.set('USE_ARMV8_CRC32C', false)
2292+
cdata.set('USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK', 1)
2293+
have_optimized_crc = true
22872294
elif cc.links(prog, name: '__crc32cb, __crc32ch, __crc32cw, and __crc32cd with -march=armv8-a+crc',
22882295
args: test_c_args + ['-march=armv8-a+crc'])
22892296
# Use ARM CRC Extension, with runtime check

0 commit comments

Comments
 (0)