|
15 | 15 | #ifdef _MSC_VER |
16 | 16 | #include <intrin.h> |
17 | 17 | #include <stdexcept> |
| 18 | +#include "cpu_x86.h" |
| 19 | +void cpu_x86::cpuid(int32_t out[4], int32_t eax, int32_t ecx) { |
| 20 | + __cpuidex(out, eax, ecx); |
| 21 | +} |
| 22 | +__int64 xgetbv(unsigned int x) { |
| 23 | + return _xgetbv(x); |
| 24 | +} |
18 | 25 | #else |
19 | 26 | #include <x86intrin.h> |
| 27 | +#include <cpuid.h> |
| 28 | +#include <stdint.h> |
| 29 | +void cpuid(int32_t cpuInfo[4], int32_t eax, int32_t ecx) { |
| 30 | + __cpuid_count(eax, ecx, cpuInfo[0], cpuInfo[1], cpuInfo[2], cpuInfo[3]); |
| 31 | +} |
| 32 | +uint64_t xgetbv(unsigned int index) { |
| 33 | + uint32_t eax, edx; |
| 34 | + __asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index)); |
| 35 | + return ((uint64_t)edx << 32) | eax; |
| 36 | +} |
20 | 37 | #endif |
21 | 38 |
|
22 | 39 | #if defined(USE_AVX512) |
|
30 | 47 | #define PORTABLE_ALIGN32 __declspec(align(32)) |
31 | 48 | #define PORTABLE_ALIGN64 __declspec(align(64)) |
32 | 49 | #endif |
33 | | -#endif |
34 | | - |
35 | | -#include <queue> |
36 | | -#include <vector> |
37 | | -#include <iostream> |
38 | | -#include <string.h> |
39 | 50 |
|
40 | 51 | // Adapted from https://github.com/Mysticial/FeatureDetector |
41 | 52 | #define _XCR_XFEATURE_ENABLED_MASK 0 |
42 | | -#ifdef _WIN32 |
43 | | -void cpuid(int32_t out[4], int32_t eax, int32_t ecx){ |
44 | | - __cpuidex(out, eax, ecx); |
45 | | -} |
46 | | -__int64 xgetbv(unsigned int x){ |
47 | | - return _xgetbv(x); |
48 | | -} |
49 | | -#else |
50 | | -#include <cpuid.h> |
51 | | -#include <stdint.h> |
52 | | -void cpuid(int32_t cpuInfo[4], int32_t eax, int32_t ecx) { |
53 | | - __cpuid_count(eax, ecx, cpuInfo[0], cpuInfo[1], cpuInfo[2], cpuInfo[3]); |
54 | | -} |
55 | | - |
56 | | -uint64_t xgetbv(unsigned int index) { |
57 | | - uint32_t eax, edx; |
58 | | - __asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index)); |
59 | | - return ((uint64_t)edx << 32) | eax; |
60 | | -} |
61 | | -#endif |
62 | 53 |
|
63 | 54 | bool AVXCapable() { |
64 | 55 | int cpuInfo[4]; |
@@ -115,6 +106,12 @@ bool AVX512Capable() { |
115 | 106 | } |
116 | 107 | return HW_AVX512F && avx512Supported; |
117 | 108 | } |
| 109 | +#endif |
| 110 | + |
| 111 | +#include <queue> |
| 112 | +#include <vector> |
| 113 | +#include <iostream> |
| 114 | +#include <string.h> |
118 | 115 |
|
119 | 116 | namespace hnswlib { |
120 | 117 | typedef size_t labeltype; |
|
0 commit comments