Skip to content

Commit

Permalink
Improve compiler compatibility of nibble2base_ssse3
Browse files Browse the repository at this point in the history
  • Loading branch information
rhpvorderman authored and jkbonfield committed May 9, 2024
1 parent 1b1b8ae commit 292a35d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions htslib/hts_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions sam_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
Expand Down

0 comments on commit 292a35d

Please sign in to comment.