8000 Backport htslib fix: configure checks for broken SIMD intrinsics · pysam-developers/pysam@3e3c8b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e3c8b0

Browse files
committed
Backport htslib fix: configure checks for broken SIMD intrinsics
Apply PR samtools/htslib#1886. 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.
1 parent c52203a commit 3e3c8b0

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

htslib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ config.h:
302302
echo '#define HAVE_ATTRIBUTE_CONSTRUCTOR 1' >> $@
303303
echo '#endif' >> $@
304304
echo '#if (defined(__x86_64__) || defined(_M_X64))' >> $@
305-
echo '#define HAVE_ATTRIBUTE_TARGET 1' >> $@
305+
echo '#define HAVE_ATTRIBUTE_TARGET_SSSE3 1' >> $@
306306
echo '#define HAVE_BUILTIN_CPU_SUPPORT_SSSE3 1' >> $@
307307
echo '#endif' >> $@
308308

htslib/config.h.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
/* Define if __attribute__((constructor)) is available. */
2323
#undef HAVE_ATTRIBUTE_CONSTRUCTOR
2424

25-
/* Define if __attribute__((target(...))) is available. */
26-
#undef HAVE_ATTRIBUTE_TARGET
25+
/* Define if __attribute__((target("ssse3"))) works. */
26+
#undef HAVE_ATTRIBUTE_TARGET_SSSE3
2727

2828
/* Defined to 1 if rANS source using AVX2 can be compiled. */
2929
#undef HAVE_AVX2

htslib/configure

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4686,20 +4686,28 @@ fi
46864686
rm -f core conftest.err conftest.$ac_objext conftest.beam \
46874687
conftest$ac_exeext conftest.$ac_ext
46884688

4689-
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __attribute__((target))" >&5
4690-
printf %s "checking for __attribute__((target))... " >&6; }
4689+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for working __attribute__((target(\"ssse3\")))" >&5
4690+
printf %s "checking for working __attribute__((target(\"ssse3\")))... " >&6; }
46914691
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
46924692
/* end confdefs.h. */
46934693
4694+
#ifdef __x86_64__
4695+
#include "x86intrin.h"
4696+
46944697
__attribute__((target("ssse3")))
4695-
int zero(void) {
4696-
return 0;
4698+
void shuffle(char *aptr, char *bptr) {
4699+
__m128i a = _mm_lddqu_si128((__m128i *)aptr);
4700+
__m128i b = _mm_shuffle_epi8(a, a);
4701+
_mm_storeu_si128((__m128i *)bptr, b);
46974702
}
4703+
#else
4704+
void shuffle(char *aptr, char *bptr) { }
4705+
#endif
46984706
46994707
int
47004708
main (void)
47014709
{
4702-
zero();
4710+
shuffle(0, 0);
47034711
;
47044712
return 0;
47054713
}
@@ -4710,7 +4718,7 @@ then :
47104718
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
47114719
printf "%s\n" "yes" >&6; }
47124720

4713-
printf "%s\n" "#define HAVE_ATTRIBUTE_TARGET 1" >>confdefs.h
4721+
printf "%s\n" "#define HAVE_ATTRIBUTE_TARGET_SSSE3 1" >>confdefs.h
47144722

47154723

47164724
else case e in #(

htslib/configure.ac

Lines changed: 15 additions & 6 deletions
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
])

htslib/sam_internal.h

Lines changed: 1 addition & 1 deletion
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)
0