Skip to content

Commit 2fc0199

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 17d081a commit 2fc0199

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

configure

+45-2
Original file line numberDiff line numberDiff line change
@@ -18651,7 +18651,8 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
1865118651
# Check for ARMv8 CRC Extension intrinsics to do CRC calculations.
1865218652
#
1865318653
# First check if __crc32c* intrinsics can be used with the default compiler
18654-
# flags. If not, check if adding -march=armv8-a+crc flag helps.
18654+
# flags. If not, check if adding "-march=armv8-a+crc+simd" flag helps.
18655+
# On systems using soft-float ABI, "-march=armv8-a+crc" is required instead.
1865518656
# CFLAGS_ARMV8_CRC32C is set if the extra flag is required.
1865618657
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=" >&5
1865718658
$as_echo_n "checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=... " >&6; }
@@ -18694,7 +18695,48 @@ if test x"$pgac_cv_armv8_crc32c_intrinsics_" = x"yes"; then
1869418695
fi
1869518696

1869618697
if test x"$pgac_armv8_crc32c_intrinsics" != x"yes"; then
18697-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc" >&5
18698+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc+simd" >&5
18699+
$as_echo_n "checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc+simd... " >&6; }
18700+
if ${pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd+:} false; then :
18701+
$as_echo_n "(cached) " >&6
18702+
else
18703+
pgac_save_CFLAGS=$CFLAGS
18704+
CFLAGS="$pgac_save_CFLAGS -march=armv8-a+crc+simd"
18705+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
18706+
/* end confdefs.h. */
18707+
#include <arm_acle.h>
18708+
int
18709+
main ()
18710+
{
18711+
unsigned int crc = 0;
18712+
crc = __crc32cb(crc, 0);
18713+
crc = __crc32ch(crc, 0);
18714+
crc = __crc32cw(crc, 0);
18715+
crc = __crc32cd(crc, 0);
18716+
/* return computed value, to prevent the above being optimized away */
18717+
return crc == 0;
18718+
;
18719+
return 0;
18720+
}
18721+
_ACEOF
18722+
if ac_fn_c_try_link "$LINENO"; then :
18723+
pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd=yes
18724+
else
18725+
pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd=no
18726+
fi
18727+
rm -f core conftest.err conftest.$ac_objext \
18728+
conftest$ac_exeext conftest.$ac_ext
18729+
CFLAGS="$pgac_save_CFLAGS"
18730+
fi
18731+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd" >&5
18732+
$as_echo "$pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd" >&6; }
18733+
if test x"$pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd" = x"yes"; then
18734+
CFLAGS_ARMV8_CRC32C="-march=armv8-a+crc+simd"
18735+
pgac_armv8_crc32c_intrinsics=yes
18736+
fi
18737+
18738+
if test x"$pgac_armv8_crc32c_intrinsics" != x"yes"; then
18739+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc" >&5
1869818740
$as_echo_n "checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc... " >&6; }
1869918741
if ${pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrc+:} false; then :
1870018742
$as_echo_n "(cached) " >&6
@@ -18734,6 +18776,7 @@ if test x"$pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrc" = x"yes"; then
1873418776
pgac_armv8_crc32c_intrinsics=yes
1873518777
fi
1873618778

18779+
fi
1873718780
fi
1873818781

1873918782

configure.ac

+6-2
Original file line numberDiff line numberDiff line change
@@ -2166,11 +2166,15 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
21662166
# Check for ARMv8 CRC Extension intrinsics to do CRC calculations.
21672167
#
21682168
# First check if __crc32c* intrinsics can be used with the default compiler
2169-
# flags. If not, check if adding -march=armv8-a+crc flag helps.
2169+
# flags. If not, check if adding "-march=armv8-a+crc+simd" flag helps.
2170+
# On systems using soft-float ABI, "-march=armv8-a+crc" is required instead.
21702171
# CFLAGS_ARMV8_CRC32C is set if the extra flag is required.
21712172
PGAC_ARMV8_CRC32C_INTRINSICS([])
21722173
if test x"$pgac_armv8_crc32c_intrinsics" != x"yes"; then
2173-
PGAC_ARMV8_CRC32C_INTRINSICS([-march=armv8-a+crc])
2174+
PGAC_ARMV8_CRC32C_INTRINSICS([-march=armv8-a+crc+simd])
2175+
if test x"$pgac_armv8_crc32c_intrinsics" != x"yes"; then
2176+
PGAC_ARMV8_CRC32C_INTRINSICS([-march=armv8-a+crc])
2177+
fi
21742178
fi
21752179
AC_SUBST(CFLAGS_ARMV8_CRC32C)
21762180

0 commit comments

Comments
 (0)