From 1682e5e2110ce6e219b108d657ee4ad960885ae8 Mon Sep 17 00:00:00 2001 From: John Marshall Date: Sun, 9 Feb 2025 20:20:45 +1300 Subject: [PATCH] Make HAVE_ATTRIBUTE_TARGET check also check SSSE3 intrinsics work GCC 4.8.5 and earlier accept SSSE3 intrinsics with -mssse3; these compiler versions also accept __attribute__((target("ssse3"))) but the attribute fails to enable compilation of the intrinsics. Refactor the check to HAVE_ATTRIBUTE_TARGET_SSSE3, and check both the attribute and that the SSSE3 intrinsics used (in simd.c) are in fact compilable in a function with the attribute. Fixes #1838. --- Makefile | 2 +- configure.ac | 21 +++++++++++++++------ sam_internal.h | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index f32b0cc7b..7c9c26b59 100644 --- a/Makefile +++ b/Makefile @@ -309,7 +309,7 @@ config.h: echo '#define HAVE_ATTRIBUTE_CONSTRUCTOR 1' >> $@ echo '#endif' >> $@ echo '#if (defined(__x86_64__) || defined(_M_X64))' >> $@ - echo '#define HAVE_ATTRIBUTE_TARGET 1' >> $@ + echo '#define HAVE_ATTRIBUTE_TARGET_SSSE3 1' >> $@ echo '#define HAVE_BUILTIN_CPU_SUPPORT_SSSE3 1' >> $@ echo '#endif' >> $@ echo '#if defined __linux__' >> $@ diff --git a/configure.ac b/configure.ac index d860a74fe..d19bea255 100644 --- a/configure.ac +++ b/configure.ac @@ -174,16 +174,25 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ ]) dnl Check for function attribute used in conjunction with __builtin_cpu_supports -AC_MSG_CHECKING([for __attribute__((target))]) +dnl and that it does enable the corresponding intrinsics (which is broken on ancient GCCs) +AC_MSG_CHECKING([for working __attribute__((target("ssse3")))]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + #ifdef __x86_64__ + #include "x86intrin.h" + __attribute__((target("ssse3"))) - int zero(void) { - return 0; + void shuffle(char *aptr, char *bptr) { + __m128i a = _mm_lddqu_si128((__m128i *)aptr); + __m128i b = _mm_shuffle_epi8(a, a); + _mm_storeu_si128((__m128i *)bptr, b); } -]], [[zero();]])], [ + #else + void shuffle(char *aptr, char *bptr) { } + #endif +]], [[shuffle(0, 0);]])], [ AC_MSG_RESULT([yes]) - AC_DEFINE([HAVE_ATTRIBUTE_TARGET], 1, - [Define if __attribute__((target(...))) is available.]) + AC_DEFINE([HAVE_ATTRIBUTE_TARGET_SSSE3], 1, + [Define if __attribute__((target("ssse3"))) works.]) ], [ AC_MSG_RESULT([no]) ]) diff --git a/sam_internal.h b/sam_internal.h index 750c597b2..135b881b1 100644 --- a/sam_internal.h +++ b/sam_internal.h @@ -100,7 +100,7 @@ static inline void nibble2base_default(uint8_t *nib, char *seq, int len) { } #if defined HAVE_ATTRIBUTE_CONSTRUCTOR && \ - ((defined __x86_64__ && defined HAVE_ATTRIBUTE_TARGET && defined HAVE_BUILTIN_CPU_SUPPORT_SSSE3) || \ + ((defined __x86_64__ && defined HAVE_ATTRIBUTE_TARGET_SSSE3 && defined HAVE_BUILTIN_CPU_SUPPORT_SSSE3) || \ (defined __ARM_NEON)) #define BUILDING_SIMD_NIBBLE2BASE #endif