Skip to content

Commit 74734d2

Browse files
committed
Workaround to avoid using an #ifdef block inside a C macro
1 parent c710732 commit 74734d2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/x86simdsort.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ namespace x86simdsort {
108108
return (*internal_argselect##TYPE)(arr, k, arrsize, hasnan); \
109109
}
110110

111+
/* simple constexpr function as a way around having #ifdef __FLT16_MAX__ block
112+
* within the DISPATCH macro */
113+
template <typename T>
114+
constexpr bool IS_TYPE_FLOAT16()
115+
{
116+
#ifdef __FLT16_MAX__
117+
if constexpr (std::is_same_v<T, _Float16>) { return true; }
118+
#endif
119+
return false;
120+
}
121+
111122
/* runtime dispatch mechanism */
112123
#define DISPATCH(func, TYPE, ISA) \
113124
DECLARE_INTERNAL_##func(TYPE) static __attribute__((constructor)) void \
@@ -118,7 +129,7 @@ namespace x86simdsort {
118129
std::string_view preferred_cpu = find_preferred_cpu(ISA); \
119130
if constexpr (dispatch_requested("avx512", ISA)) { \
120131
if (preferred_cpu.find("avx512") != std::string_view::npos) { \
121-
if constexpr (std::is_same_v<TYPE, _Float16>) { \
132+
if constexpr (IS_TYPE_FLOAT16<TYPE>()) { \
122133
if (preferred_cpu.find("avx512_spr") \
123134
!= std::string_view::npos) { \
124135
CAT(CAT(internal_, func), TYPE) \

0 commit comments

Comments
 (0)