17
17
#include <stdatomic.h>
18
18
#endif
19
19
20
+ /*
21
+ Clang-6 does not enable proper -march flags for assembly modules
22
+ which leads to "error: instruction requires: AVX-512 ISA"
23
+ at the assembler phase.
24
+
25
+ Apple LLVM version 10.0.0 (clang-1000.11.45.5) is based on clang-6
26
+ https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
27
+ and it's the latest available version on macOS 10.13.
28
+
29
+ Disable AVX-512 instructions as they are most likely not supported
30
+ on the hardware running clang-6.
31
+ */
32
+ #if !((defined(__apple_build_version__ ) && __apple_build_version__ <= 10001145 ) \
33
+ || (defined(__clang_major__ ) && __clang_major__ <= 6 ))
34
+ #define COMPILER_SUPPORTS_AVX512
35
+ #endif
36
+
37
+
38
+ #if defined(__x86_64__ ) && defined(COMPILER_SUPPORTS_AVX512 )
20
39
bool has_avx512_vl_bw () {
21
- #if defined( __x86_64__ ) && ( __GNUC__ >= 6 || defined(__clang_major__ ) )
40
+ #if __GNUC__ >= 6 || defined(__clang_major__ )
22
41
uint32_t eax = 0 , ebx = 0 , ecx = 0 , edx = 0 ;
23
42
__get_cpuid_count (7 , 0 , & eax , & ebx , & ecx , & edx );
24
43
// https://en.wikipedia.org/wiki/CPUID#EAX=7,_ECX=0:_Extended_Features
@@ -30,6 +49,7 @@ bool has_avx512_vl_bw() {
30
49
return false;
31
50
#endif
32
51
}
52
+ #endif
33
53
34
54
/*
35
55
measure_off_naive / measure_off_avx / measure_off_sse
@@ -68,7 +88,7 @@ static inline const ssize_t measure_off_naive(const uint8_t *src, const uint8_t
68
88
return cnt == 0 ? (ssize_t )(srcend - src ) : (ssize_t )(- cnt );
69
89
}
70
90
71
- #ifdef __x86_64__
91
+ #if defined( __x86_64__ ) && defined( COMPILER_SUPPORTS_AVX512 )
72
92
__attribute__((target ("avx512vl,avx512bw" )))
73
93
static const ssize_t measure_off_avx (const uint8_t * src , const uint8_t * srcend , size_t cnt )
74
94
{
@@ -146,7 +166,7 @@ ssize_t _hs_text_measure_off(const uint8_t *src, size_t off, size_t len, size_t
146
166
static _Atomic measure_off_t s_impl = (measure_off_t )NULL ;
147
167
measure_off_t impl = atomic_load_explicit (& s_impl , memory_order_relaxed );
148
168
if (!impl ) {
149
- #ifdef __x86_64__
169
+ #if defined( __x86_64__ ) && defined( COMPILER_SUPPORTS_AVX512 )
150
170
impl = has_avx512_vl_bw () ? measure_off_avx : measure_off_sse ;
151
171
#else
152
172
impl = measure_off_sse ;
0 commit comments