1+ #if defined(_MSC_VER)
2+ #define XSS_ATTRIBUTE_CONSTRUCTOR
3+ #else
4+ #define XSS_ATTRIBUTE_CONSTRUCTOR __attribute__ ((constructor))
5+ #endif
16#include " x86simdsort.h"
27#include " x86simdsort-internal.h"
38#include " x86simdsort-scalar.h"
9+ #include " x86simdsortcpuid.h"
410#include < algorithm>
511#include < iostream>
612#include < string>
@@ -12,23 +18,19 @@ static int check_cpu_feature_support(std::string_view cpufeature)
1218 if ((cpufeature == " avx512_spr" ) && (!disable_avx512))
1319#if defined(__FLT16_MAX__) && !defined(__INTEL_LLVM_COMPILER) \
1420 && (!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" );
1823#else
1924 return 0 ;
2025#endif
2126 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" );
2629 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" );
3032 else if (cpufeature == " avx2" )
31- return __builtin_cpu_supports (" avx2" );
33+ return xss_cpu_supports (" avx2" );
3234
3335 return 0 ;
3436}
@@ -121,11 +123,11 @@ constexpr bool IS_TYPE_FLOAT16()
121123
122124/* runtime dispatch mechanism */
123125#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 ) \
126128 { \
127129 CAT (CAT (internal_, func), TYPE) = &xss::scalar::func<TYPE>; \
128- __builtin_cpu_init (); \
130+ xss_cpu_init (); \
129131 std::string_view preferred_cpu = find_preferred_cpu (ISA); \
130132 if constexpr (dispatch_requested (" avx512" , ISA)) { \
131133 if (preferred_cpu.find (" avx512" ) != std::string_view::npos) { \
@@ -248,12 +250,12 @@ DISPATCH_ALL(argselect,
248250 }
249251
250252#define DISPATCH_KV_FUNC (func, TYPE1, TYPE2, ISA ) \
251- static __attribute__ ((constructor)) void CAT( \
253+ static XSS_ATTRIBUTE_CONSTRUCTOR void CAT ( \
252254 CAT (CAT(CAT(resolve_, func), _), TYPE1), TYPE2)(void ) \
253255 { \
254256 CAT (CAT (CAT (CAT (internal_, func), _), TYPE1), TYPE2) \
255257 = &xss::scalar::func<TYPE1, TYPE2>; \
256- __builtin_cpu_init (); \
258+ xss_cpu_init (); \
257259 std::string_view preferred_cpu = find_preferred_cpu (ISA); \
258260 if constexpr (dispatch_requested (" avx512" , ISA)) { \
259261 if (preferred_cpu.find (" avx512" ) != std::string_view::npos) { \
0 commit comments