diff --git a/Makefile b/Makefile index 0bbb078d6..1bdeb4338 100644 --- a/Makefile +++ b/Makefile @@ -328,13 +328,18 @@ config.h: if [ "x$(HTS_BUILD_AVX512)" != "x" ] ; then \ echo '#define HAVE_AVX512 1' >> $@ ; \ fi + echo '#if defined __x86_64__ && (defined HAVE_SSSE3 || defined HAVE_AVX2 || defined HAVE_AVX512)' >> $@ + echo '#define HAVE_X86INTRIN_H 1' >> $@ + echo '#endif' >> $@ echo '#if defined __x86_64__ || defined __arm__ || defined __aarch64__' >> $@ echo '#define HAVE_ATTRIBUTE_CONSTRUCTOR 1' >> $@ echo '#endif' >> $@ - echo '#if (defined(__x86_64__) || defined(_M_X64))' >> $@ - echo '#define HAVE_ATTRIBUTE_TARGET_SSSE3 1' >> $@ - echo '#define HAVE_BUILTIN_CPU_SUPPORT_SSSE3 1' >> $@ - echo '#endif' >> $@ + if [ "x$(HTS_HAVE_SSSE3_BUILTINS)" != "x" ]; then \ + echo '#if (defined(__x86_64__) || defined(_M_X64))' >> $@ ; \ + echo '#define HAVE_ATTRIBUTE_TARGET_SSSE3 1' >> $@ ; \ + echo '#define HAVE_BUILTIN_CPU_SUPPORT_SSSE3 1' >> $@ ; \ + echo '#endif' >> $@ ; \ + fi echo '#if defined __linux__' >> $@ echo '#define HAVE_GETAUXVAL' >> $@ echo '#elif defined __FreeBSD__' >> $@ diff --git a/configure.ac b/configure.ac index 9fb221216..c50635968 100644 --- a/configure.ac +++ b/configure.ac @@ -83,14 +83,16 @@ AC_CHECK_DECL([_XOPEN_SOURCE], [], [AC_DEFINE([_XOPEN_SOURCE], [700], [Specify X/Open requirements])], []) -dnl Check that we have cpuid, and if so run the x86 SIMD checks +dnl Check that we have cpuid and x86intrin.h, and if so run the x86 SIMD checks AC_CHECK_DECLS([__get_cpuid_max, __cpuid_count], [ hts_have_cpuid=yes ], [ hts_have_cpuid=no ], [[#include ]]) -AS_IF(test "x$hts_have_cpuid" = "xyes", [ +AC_CHECK_HEADERS([x86intrin.h]) + +AS_IF([test "x$hts_have_cpuid" = "xyes" && test "x$ac_cv_header_x86intrin_h" = "xyes"], [ dnl Options for rANS32x16 sse4.1 version - sse4.1 HTS_CHECK_COMPILE_FLAGS_NEEDED([sse4.1], [-msse4.1 -mssse3 -mpopcnt], [AC_LANG_PROGRAM([[ @@ -666,6 +668,33 @@ Linux, FreeBSD, MacOS, and other BSD derivatives]) ]) ]) +# Check for a working fstatat interface +AS_IF([test "$ref_cache" = enabled],[ + AC_MSG_CHECKING([for fstatat]) + AC_LINK_IFELSE([ + AC_LANG_PROGRAM([ + #include + #include + ],[ + struct stat statbuf; + return fstatat(AT_FDCWD, "/", &statbuf, AT_SYMLINK_NOFOLLOW); + ]) + ], [ + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([no]) + ref_cache="disabled" + AS_IF([test "x$enable_ref_cache" = xcheck], [ + AC_MSG_WARN([ref-cache not enabled: missing fstatat()]) + ],[ + MSG_ERROR([ref-cache not enabled + +ref-cache is not supported on this configuration, as the fstatat() interface +cannot be found.]) + ]) + ]) +]) + # Check how to get a working cmsg interface AS_IF([test "$ref_cache" = enabled],[ AC_MSG_CHECKING([for CMSG_LEN]) diff --git a/hts_probe_cc.sh b/hts_probe_cc.sh index c9fc0a821..b7401dfff 100755 --- a/hts_probe_cc.sh +++ b/hts_probe_cc.sh @@ -60,9 +60,11 @@ run_test () rm -f conftest conftest.err conftest.c cat - > conftest.c if run_compiler ; then - echo "$2 =" + if test "x$2" != x ; then + echo "$2 =" + fi echo "$3 = 1" - elif run_compiler "$1" ; then + elif test "x$1" != x && run_compiler "$1" ; then echo "$2 = $1" echo "$3 = 1" else @@ -140,4 +142,29 @@ int main(int argc, char **argv) { return 0; } #endif EOF +# Check for __builtin_cpu_supports("ssse3") and __attribute__((target("ssse3"))) + +run_test '' '' HTS_HAVE_SSSE3_BUILTINS <<'EOF' +#ifdef __x86_64__ +#include "x86intrin.h" +__attribute__((target("ssse3"))) +static void shuffle(char *aptr, char *bptr) { + if (__builtin_cpu_supports("ssse3")) { + __m128i a = _mm_lddqu_si128((__m128i *)aptr); + __m128i b = _mm_shuffle_epi8(a, a); + _mm_storeu_si128((__m128i *)bptr, b); + } +} + +int main(int argc, char **argv) { + char in[sizeof(__m128i)] = { 0 }, out[sizeof(__m128i)] = { 0 }; + in[0] = argv[0][0]; + shuffle(in, out); + return out[0]; +} +#else +int main(int argc, char **argv) { return 0; } +#endif +EOF + rm -f conftest.c diff --git a/sam_internal.h b/sam_internal.h index 135b881b1..161782aa3 100644 --- a/sam_internal.h +++ b/sam_internal.h @@ -100,7 +100,10 @@ static inline void nibble2base_default(uint8_t *nib, char *seq, int len) { } #if defined HAVE_ATTRIBUTE_CONSTRUCTOR && \ - ((defined __x86_64__ && defined HAVE_ATTRIBUTE_TARGET_SSSE3 && defined HAVE_BUILTIN_CPU_SUPPORT_SSSE3) || \ + ((defined __x86_64__ && \ + defined HAVE_X86INTRIN_H && HAVE_X86INTRIN_H && \ + defined HAVE_ATTRIBUTE_TARGET_SSSE3 && \ + defined HAVE_BUILTIN_CPU_SUPPORT_SSSE3) || \ (defined __ARM_NEON)) #define BUILDING_SIMD_NIBBLE2BASE #endif diff --git a/simd.c b/simd.c index 014a370d6..62a2e7766 100644 --- a/simd.c +++ b/simd.c @@ -34,8 +34,8 @@ DEALINGS IN THE SOFTWARE. */ #include "htslib/sam.h" #include "sam_internal.h" -#if defined __x86_64__ -#include +#if defined __x86_64__ && defined HAVE_X86INTRIN_H && HAVE_X86INTRIN_H +#include #elif defined __ARM_NEON #include #endif