Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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__' >> $@
Expand Down
33 changes: 31 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cpuid.h>]])

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([[
Expand Down Expand Up @@ -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 <fcntl.h>
#include <sys/stat.h>
],[
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])
Expand Down
31 changes: 29 additions & 2 deletions hts_probe_cc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion sam_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions simd.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ DEALINGS IN THE SOFTWARE. */
#include "htslib/sam.h"
#include "sam_internal.h"

#if defined __x86_64__
#include <immintrin.h>
#if defined __x86_64__ && defined HAVE_X86INTRIN_H && HAVE_X86INTRIN_H
#include <x86intrin.h>
#elif defined __ARM_NEON
#include <arm_neon.h>
#endif
Expand Down