Skip to content

Commit ac472dc

Browse files
committed
Detect AVX512 on Darwin use GetDarwinSysCtlByName("hw.optional.avx512f")
1 parent 7ed0b0e commit ac472dc

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/cpuinfo_x86.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,19 @@ static void ParseLeaf4(const int max_cpuid_leaf, CacheInfo* info) {
11641164
}
11651165
}
11661166

1167+
#if defined(CPU_FEATURES_OS_DARWIN)
1168+
#if defined(CPU_FEATURES_MOCK_CPUID_X86)
1169+
extern bool GetDarwinSysCtlByName(const char*);
1170+
#else // CPU_FEATURES_MOCK_CPUID_X86
1171+
static bool GetDarwinSysCtlByName(const char* name) {
1172+
int enabled;
1173+
size_t enabled_len = sizeof(enabled);
1174+
const int failure = sysctlbyname(name, &enabled, &enabled_len, NULL, 0);
1175+
return failure ? false : enabled;
1176+
}
1177+
#endif
1178+
#endif // CPU_FEATURES_OS_DARWIN
1179+
11671180
// Internal structure to hold the OS support for vector operations.
11681181
// Avoid to recompute them since each call to cpuid is ~100 cycles.
11691182
typedef struct {
@@ -1189,7 +1202,11 @@ static OsSupport CheckOsSupport(const uint32_t max_cpuid_leaf) {
11891202
const uint32_t xcr0_eax = GetXCR0Eax();
11901203
os_support.have_sse_via_cpuid = HasXmmOsXSave(xcr0_eax);
11911204
os_support.have_avx = HasYmmOsXSave(xcr0_eax);
1205+
#if defined(CPU_FEATURES_OS_DARWIN)
1206+
os_support.have_avx512 = GetDarwinSysCtlByName("hw.optional.avx512f");
1207+
#else
11921208
os_support.have_avx512 = HasZmmOsXSave(xcr0_eax);
1209+
#endif // CPU_FEATURES_OS_DARWIN
11931210
os_support.have_amx = HasTmmOsXSave(xcr0_eax);
11941211
} else {
11951212
// Atom based or older cpus need to ask the OS for sse support.
@@ -1209,19 +1226,6 @@ static bool GetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature) {
12091226
#endif
12101227
#endif // CPU_FEATURES_OS_WINDOWS
12111228

1212-
#if defined(CPU_FEATURES_OS_DARWIN)
1213-
#if defined(CPU_FEATURES_MOCK_CPUID_X86)
1214-
extern bool GetDarwinSysCtlByName(const char*);
1215-
#else // CPU_FEATURES_MOCK_CPUID_X86
1216-
static bool GetDarwinSysCtlByName(const char* name) {
1217-
int enabled;
1218-
size_t enabled_len = sizeof(enabled);
1219-
const int failure = sysctlbyname(name, &enabled, &enabled_len, NULL, 0);
1220-
return failure ? false : enabled;
1221-
}
1222-
#endif
1223-
#endif // CPU_FEATURES_OS_DARWIN
1224-
12251229
static void DetectSseViaOs(X86Features* features) {
12261230
#if defined(CPU_FEATURES_OS_WINDOWS)
12271231
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent

0 commit comments

Comments
 (0)