Skip to content

Commit 1682e5e

Browse files
committed
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.
1 parent c814d39 commit 1682e5e

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ config.h:
309309
echo '#define HAVE_ATTRIBUTE_CONSTRUCTOR 1' >> $@
310310
echo '#endif' >> $@
311311
echo '#if (defined(__x86_64__) || defined(_M_X64))' >> $@
312-
echo '#define HAVE_ATTRIBUTE_TARGET 1' >> $@
312+
echo '#define HAVE_ATTRIBUTE_TARGET_SSSE3 1' >> $@
313313
echo '#define HAVE_BUILTIN_CPU_SUPPORT_SSSE3 1' >> $@
314314
echo '#endif' >> $@
315315
echo '#if defined __linux__' >> $@

configure.ac

+15-6
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,25 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([],[
174174
])
175175
176176
dnl Check for function attribute used in conjunction with __builtin_cpu_supports
177-
AC_MSG_CHECKING([for __attribute__((target))])
177+
dnl and that it does enable the corresponding intrinsics (which is broken on ancient GCCs)
178+
AC_MSG_CHECKING([for working __attribute__((target("ssse3")))])
178179
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
180+
#ifdef __x86_64__
181+
#include "x86intrin.h"
182+
179183
__attribute__((target("ssse3")))
180-
int zero(void) {
181-
return 0;
184+
void shuffle(char *aptr, char *bptr) {
185+
__m128i a = _mm_lddqu_si128((__m128i *)aptr);
186+
__m128i b = _mm_shuffle_epi8(a, a);
187+
_mm_storeu_si128((__m128i *)bptr, b);
182188
}
183-
]], [[zero();]])], [
189+
#else
190+
void shuffle(char *aptr, char *bptr) { }
191+
#endif
192+
]], [[shuffle(0, 0);]])], [
184193
AC_MSG_RESULT([yes])
185-
AC_DEFINE([HAVE_ATTRIBUTE_TARGET], 1,
186-
[Define if __attribute__((target(...))) is available.])
194+
AC_DEFINE([HAVE_ATTRIBUTE_TARGET_SSSE3], 1,
195+
[Define if __attribute__((target("ssse3"))) works.])
187196
], [
188197
AC_MSG_RESULT([no])
189198
])

sam_internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static inline void nibble2base_default(uint8_t *nib, char *seq, int len) {
100100
}
101101

102102
#if defined HAVE_ATTRIBUTE_CONSTRUCTOR && \
103-
((defined __x86_64__ && defined HAVE_ATTRIBUTE_TARGET && defined HAVE_BUILTIN_CPU_SUPPORT_SSSE3) || \
103+
((defined __x86_64__ && defined HAVE_ATTRIBUTE_TARGET_SSSE3 && defined HAVE_BUILTIN_CPU_SUPPORT_SSSE3) || \
104104
(defined __ARM_NEON))
105105
#define BUILDING_SIMD_NIBBLE2BASE
106106
#endif

0 commit comments

Comments
 (0)