From 4f82c6722e72a95b0421a7371090d74bd2f46272 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Mon, 22 Apr 2024 13:36:00 +0200 Subject: [PATCH] Improve compiler compatibility of nibble2base_ssse3 --- htslib/hts_defs.h | 18 ++++++++++++++++++ sam_internal.h | 5 +++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/htslib/hts_defs.h b/htslib/hts_defs.h index e714e8fda..0c5f8957a 100644 --- a/htslib/hts_defs.h +++ b/htslib/hts_defs.h @@ -34,6 +34,10 @@ DEALINGS IN THE SOFTWARE. */ #define HTS_COMPILER_HAS(attribute) __has_attribute(attribute) #endif +#ifdef __has_builtin +#define HTS_COMPILER_HAS_BUILTIN(function) __has_builtin(function) +#endif + #elif defined __GNUC__ #define HTS_GCC_AT_LEAST(major, minor) \ (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) @@ -42,6 +46,10 @@ DEALINGS IN THE SOFTWARE. */ #ifndef HTS_COMPILER_HAS #define HTS_COMPILER_HAS(attribute) 0 #endif +#ifndef HTS_COMPILER_HAS_BUILTIN +#define HTS_COMPILER_HAS_BUILTIN(function) 0 +#endif + #ifndef HTS_GCC_AT_LEAST #define HTS_GCC_AT_LEAST(major, minor) 0 #endif @@ -118,6 +126,16 @@ DEALINGS IN THE SOFTWARE. */ #define HTS_FORMAT(type, idx, first) #endif +#define HTS_COMPILER_HAS_TARGET_AND_BUILTIN_CPU_SUPPORTS \ + ((HTS_COMPILER_HAS(target) && HTS_COMPILER_HAS_BUILTIN(__builtin_cpu_supports)) \ + || HTS_GCC_AT_LEAST(4, 8)) + +#if (defined(__x86_64__) || defined(_M_X64)) +#define HTS_BUILD_IS_X86_64 1 +#else +#define HTS_BUILD_IS_X86_64 0 +#endif + #if defined(_WIN32) || defined(__CYGWIN__) #if defined(HTS_BUILDING_LIBRARY) #define HTSLIB_EXPORT __declspec(dllexport) diff --git a/sam_internal.h b/sam_internal.h index f901070b6..e4c553d58 100644 --- a/sam_internal.h +++ b/sam_internal.h @@ -99,7 +99,8 @@ static inline void nibble2base_default(uint8_t *nib, char *seq, int len) { seq[i] = seq_nt16_str[bam_seqi(nib, i)]; } -#if HTS_GCC_AT_LEAST(4,8) +#if HTS_BUILD_IS_X86_64 && HTS_COMPILER_HAS_TARGET_AND_BUILTIN_CPU_SUPPORTS +#include "immintrin.h" /* * Convert a nibble encoded BAM sequence to a string of bases. * @@ -108,7 +109,7 @@ static inline void nibble2base_default(uint8_t *nib, char *seq, int len) { * be converted to the IUPAC characters. * It falls back on the nibble2base_default function for the remainder. */ -#include "tmmintrin.h" + __attribute__((target("ssse3"))) static inline void nibble2base_ssse3(uint8_t *nib, char *seq, int len) { seq[0] = 0;