Skip to content

Commit 67c869b

Browse files
author
Tony Kuo
committed
fixed windows build errors
1 parent f7ce7cc commit 67c869b

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

hnswlib/hnswlib.h

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,25 @@
1515
#ifdef _MSC_VER
1616
#include <intrin.h>
1717
#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+
}
1825
#else
1926
#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+
}
2037
#endif
2138

2239
#if defined(USE_AVX512)
@@ -30,35 +47,9 @@
3047
#define PORTABLE_ALIGN32 __declspec(align(32))
3148
#define PORTABLE_ALIGN64 __declspec(align(64))
3249
#endif
33-
#endif
34-
35-
#include <queue>
36-
#include <vector>
37-
#include <iostream>
38-
#include <string.h>
3950

4051
// Adapted from https://github.com/Mysticial/FeatureDetector
4152
#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
6253

6354
bool AVXCapable() {
6455
int cpuInfo[4];
@@ -115,6 +106,12 @@ bool AVX512Capable() {
115106
}
116107
return HW_AVX512F && avx512Supported;
117108
}
109+
#endif
110+
111+
#include <queue>
112+
#include <vector>
113+
#include <iostream>
114+
#include <string.h>
118115

119116
namespace hnswlib {
120117
typedef size_t labeltype;

0 commit comments

Comments
 (0)