Skip to content

Commit

Permalink
Make cpuid instruction compatible with msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
iver56 committed Jan 29, 2024
1 parent 6b7e753 commit b437c40
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions numpy_minmax/_minmax.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#include <cpuid.h>
#include <float.h>
#include <immintrin.h>
#include <stdbool.h>

#ifdef _MSC_VER
#include <intrin.h> // MSVC
#else
#include <cpuid.h> // GCC and Clang
#endif

#ifndef bit_AVX512F
#define bit_AVX512F (1 << 16)
#endif

typedef struct {
float min_val;
float max_val;
Expand All @@ -14,9 +23,17 @@ bool system_supports_avx512() {
unsigned int eax, ebx, ecx, edx;

// EAX=7, ECX=0: Extended Features
__cpuid_count(7, 0, eax, ebx, ecx, edx);

// Check the AVX512F bit (bit 16 of EBX)
#ifdef _MSC_VER
// MSVC
int cpuInfo[4];
__cpuid(cpuInfo, 7);
ebx = cpuInfo[1];
#else
// GCC, Clang
__cpuid(7, eax, ebx, ecx, edx);
#endif

// Check the AVX512F bit in EBX
return (ebx & bit_AVX512F) != 0;
}

Expand Down

0 comments on commit b437c40

Please sign in to comment.