Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e266a0e

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 f979197 commit e266a0e

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
@@ -17809,7 +17809,8 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
1780917809
# Check for ARMv8 CRC Extension intrinsics to do CRC calculations.
1781017810
#
1781117811
# First check if __crc32c* intrinsics can be used with the default compiler
17812-
# flags. If not, check if adding -march=armv8-a+crc flag helps.
17812+
# flags. If not, check if adding "-march=armv8-a+crc+simd" flag helps.
17813+
# On systems using soft-float ABI, "-march=armv8-a+crc" is required instead.
1781317814
# CFLAGS_CRC is set if the extra flag is required.
1781417815
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=" >&5
1781517816
$as_echo_n "checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=... " >&6; }
@@ -17852,7 +17853,48 @@ if test x"$pgac_cv_armv8_crc32c_intrinsics_" = x"yes"; then
1785217853
fi
1785317854

1785417855
if test x"$pgac_armv8_crc32c_intrinsics" != x"yes"; then
17855-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc" >&5
17856+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc+simd" >&5
17857+
$as_echo_n "checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc+simd... " >&6; }
17858+
if ${pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd+:} false; then :
17859+
$as_echo_n "(cached) " >&6
17860+
else
17861+
pgac_save_CFLAGS=$CFLAGS
17862+
CFLAGS="$pgac_save_CFLAGS -march=armv8-a+crc+simd"
17863+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
17864+
/* end confdefs.h. */
17865+
#include <arm_acle.h>
17866+
int
17867+
main ()
17868+
{
17869+
unsigned int crc = 0;
17870+
crc = __crc32cb(crc, 0);
17871+
crc = __crc32ch(crc, 0);
17872+
crc = __crc32cw(crc, 0);
17873+
crc = __crc32cd(crc, 0);
17874+
/* return computed value, to prevent the above being optimized away */
17875+
return crc == 0;
17876+
;
17877+
return 0;
17878+
}
17879+
_ACEOF
17880+
if ac_fn_c_try_link "$LINENO"; then :
17881+
pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd=yes
17882+
else
17883+
pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd=no
17884+
fi
17885+
rm -f core conftest.err conftest.$ac_objext \
17886+
conftest$ac_exeext conftest.$ac_ext
17887+
CFLAGS="$pgac_save_CFLAGS"
17888+
fi
17889+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd" >&5
17890+
$as_echo "$pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd" >&6; }
17891+
if test x"$pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrcpsimd" = x"yes"; then
17892+
CFLAGS_CRC="-march=armv8-a+crc+simd"
17893+
pgac_armv8_crc32c_intrinsics=yes
17894+
fi
17895+
17896+
if test x"$pgac_armv8_crc32c_intrinsics" != x"yes"; then
17897+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc" >&5
1785617898
$as_echo_n "checking for __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS=-march=armv8-a+crc... " >&6; }
1785717899
if ${pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrc+:} false; then :
1785817900
$as_echo_n "(cached) " >&6
@@ -17892,6 +17934,7 @@ if test x"$pgac_cv_armv8_crc32c_intrinsics__march_armv8_apcrc" = x"yes"; then
1789217934
pgac_armv8_crc32c_intrinsics=yes
1789317935
fi
1789417936

17937+
fi
1789517938
fi
1789617939

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

configure.ac

+6-2
Original file line numberDiff line numberDiff line change
@@ -2137,11 +2137,15 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
21372137
# Check for ARMv8 CRC Extension intrinsics to do CRC calculations.
21382138
#
21392139
# First check if __crc32c* intrinsics can be used with the default compiler
2140-
# flags. If not, check if adding -march=armv8-a+crc flag helps.
2140+
# flags. If not, check if adding "-march=armv8-a+crc+simd" flag helps.
2141+
# On systems using soft-float ABI, "-march=armv8-a+crc" is required instead.
21412142
# CFLAGS_CRC is set if the extra flag is required.
21422143
PGAC_ARMV8_CRC32C_INTRINSICS([])
21432144
if test x"$pgac_armv8_crc32c_intrinsics" != x"yes"; then
2144-
PGAC_ARMV8_CRC32C_INTRINSICS([-march=armv8-a+crc])
2145+
PGAC_ARMV8_CRC32C_INTRINSICS([-march=armv8-a+crc+simd])
2146+
if test x"$pgac_armv8_crc32c_intrinsics" != x"yes"; then
2147+
PGAC_ARMV8_CRC32C_INTRINSICS([-march=armv8-a+crc])
2148+
fi
21452149
fi
21462150

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

meson.build

+7
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,13 @@ int main(void)
23032303
# Use ARM CRC Extension unconditionally
23042304
cdata.set('USE_ARMV8_CRC32C', 1)
23052305
have_optimized_crc = true
2306+
elif cc.links(prog, name: '__crc32cb, __crc32ch, __crc32cw, and __crc32cd with -march=armv8-a+crc+simd',
2307+
args: test_c_args + ['-march=armv8-a+crc+simd'])
2308+
# Use ARM CRC Extension, with runtime check
2309+
cflags_crc += '-march=armv8-a+crc+simd'
2310+
cdata.set('USE_ARMV8_CRC32C', false)
2311+
cdata.set('USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK', 1)
2312+
have_optimized_crc = true
23062313
elif cc.links(prog, name: '__crc32cb, __crc32ch, __crc32cw, and __crc32cd with -march=armv8-a+crc',
23072314
args: test_c_args + ['-march=armv8-a+crc'])
23082315
# Use ARM CRC Extension, with runtime check

0 commit comments

Comments
 (0)