Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit d4520e6

Browse files
committed
Fix cpuid error on Mac arm-silicon
1 parent 6e96a08 commit d4520e6

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

utils/nitro_utils.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@
1010
#include <ostream>
1111
#include <regex>
1212
#include <vector>
13-
14-
#if defined(__GNUC__) || defined(__clang__)
15-
#include <cpuid.h>
16-
#elif defined(_MSC_VER)
17-
#include <intrin.h>
18-
#endif
19-
13+
// Include platform-specific headers
2014
#ifdef _WIN32
2115
#include <winsock2.h>
2216
#include <windows.h>
@@ -180,14 +174,18 @@ inline std::string generate_random_string(std::size_t length) {
180174
return random_string;
181175
}
182176

183-
inline bool isAVX2Supported() {
184-
#if defined(__GNUC__) || defined(__clang__)
177+
#if (defined(__GNUC__) || defined(__clang__)) && (defined(__x86_64__) || defined(__i386__))
178+
#include <cpuid.h>
179+
inline bool isAVX2Supported() {
185180
unsigned eax, ebx, ecx, edx;
186181
if (__get_cpuid_max(0, nullptr) < 7) return false;
187182

188183
__get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
189184
return (ebx & (1 << 5)) != 0;
190-
#elif defined(_MSC_VER)
185+
}
186+
#elif defined(_MSC_VER) && (defined(__x86_64__) || defined(__i386__))
187+
#include <intrin.h>
188+
inline bool isAVX2Supported() {
191189
int cpuInfo[4];
192190
__cpuid(cpuInfo, 0);
193191
int nIds = cpuInfo[0];
@@ -196,8 +194,8 @@ inline bool isAVX2Supported() {
196194
return (cpuInfo[1] & (1 << 5)) != 0;
197195
}
198196
return false;
197+
}
199198
#endif
200-
}
201199

202200
inline void nitro_logo() {
203201
std::string rainbowColors[] = {

0 commit comments

Comments
 (0)