Skip to content

Commit

Permalink
Make HAVE_ATTRIBUTE_TARGET check also check SSSE3 intrinsics work
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmarshall committed Feb 9, 2025
1 parent c814d39 commit 1682e5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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__' >> $@
Expand Down
21 changes: 15 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])
])
Expand Down
2 changes: 1 addition & 1 deletion sam_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1682e5e

Please sign in to comment.