1
+ #if defined(_MSC_VER)
2
+ #define XSS_ATTRIBUTE_CONSTRUCTOR
3
+ #else
4
+ #define XSS_ATTRIBUTE_CONSTRUCTOR __attribute__ ((constructor))
5
+ #endif
1
6
#include " x86simdsort.h"
2
7
#include " x86simdsort-internal.h"
3
8
#include " x86simdsort-scalar.h"
9
+ #include " x86simdsortcpuid.h"
4
10
#include < algorithm>
5
11
#include < iostream>
6
12
#include < string>
@@ -12,23 +18,19 @@ static int check_cpu_feature_support(std::string_view cpufeature)
12
18
if ((cpufeature == " avx512_spr" ) && (!disable_avx512))
13
19
#if defined(__FLT16_MAX__) && !defined(__INTEL_LLVM_COMPILER) \
14
20
&& (!defined (__clang_major__) || __clang_major__ >= 18 )
15
- return __builtin_cpu_supports (" avx512f" )
16
- && __builtin_cpu_supports (" avx512fp16" )
17
- && __builtin_cpu_supports (" avx512vbmi2" );
21
+ return xss_cpu_supports (" avx512f" ) && xss_cpu_supports (" avx512fp16" )
22
+ && xss_cpu_supports (" avx512vbmi2" );
18
23
#else
19
24
return 0 ;
20
25
#endif
21
26
else if ((cpufeature == " avx512_icl" ) && (!disable_avx512))
22
- return __builtin_cpu_supports (" avx512f" )
23
- && __builtin_cpu_supports (" avx512vbmi2" )
24
- && __builtin_cpu_supports (" avx512bw" )
25
- && __builtin_cpu_supports (" avx512vl" );
27
+ return xss_cpu_supports (" avx512f" ) && xss_cpu_supports (" avx512vbmi2" )
28
+ && xss_cpu_supports (" avx512bw" ) && xss_cpu_supports (" avx512vl" );
26
29
else if ((cpufeature == " avx512_skx" ) && (!disable_avx512))
27
- return __builtin_cpu_supports (" avx512f" )
28
- && __builtin_cpu_supports (" avx512dq" )
29
- && __builtin_cpu_supports (" avx512vl" );
30
+ return xss_cpu_supports (" avx512f" ) && xss_cpu_supports (" avx512dq" )
31
+ && xss_cpu_supports (" avx512vl" );
30
32
else if (cpufeature == " avx2" )
31
- return __builtin_cpu_supports (" avx2" );
33
+ return xss_cpu_supports (" avx2" );
32
34
33
35
return 0 ;
34
36
}
@@ -121,11 +123,11 @@ constexpr bool IS_TYPE_FLOAT16()
121
123
122
124
/* runtime dispatch mechanism */
123
125
#define DISPATCH (func, TYPE, ISA ) \
124
- DECLARE_INTERNAL_##func(TYPE) static __attribute__ ((constructor)) void \
125
- CAT( CAT(resolve_, func), TYPE)(void ) \
126
+ DECLARE_INTERNAL_##func(TYPE) static XSS_ATTRIBUTE_CONSTRUCTOR void CAT ( \
127
+ CAT (resolve_, func), TYPE)(void ) \
126
128
{ \
127
129
CAT (CAT (internal_, func), TYPE) = &xss::scalar::func<TYPE>; \
128
- __builtin_cpu_init (); \
130
+ xss_cpu_init (); \
129
131
std::string_view preferred_cpu = find_preferred_cpu (ISA); \
130
132
if constexpr (dispatch_requested (" avx512" , ISA)) { \
131
133
if (preferred_cpu.find (" avx512" ) != std::string_view::npos) { \
@@ -248,12 +250,12 @@ DISPATCH_ALL(argselect,
248
250
}
249
251
250
252
#define DISPATCH_KV_FUNC (func, TYPE1, TYPE2, ISA ) \
251
- static __attribute__ ((constructor)) void CAT( \
253
+ static XSS_ATTRIBUTE_CONSTRUCTOR void CAT ( \
252
254
CAT (CAT(CAT(resolve_, func), _), TYPE1), TYPE2)(void ) \
253
255
{ \
254
256
CAT (CAT (CAT (CAT (internal_, func), _), TYPE1), TYPE2) \
255
257
= &xss::scalar::func<TYPE1, TYPE2>; \
256
- __builtin_cpu_init (); \
258
+ xss_cpu_init (); \
257
259
std::string_view preferred_cpu = find_preferred_cpu (ISA); \
258
260
if constexpr (dispatch_requested (" avx512" , ISA)) { \
259
261
if (preferred_cpu.find (" avx512" ) != std::string_view::npos) { \
0 commit comments