|
10 | 10 | #include "zbuild.h" |
11 | 11 | #include "x86_features.h" |
12 | 12 |
|
13 | | -#ifdef _MSC_VER |
14 | | -# include <intrin.h> |
15 | | -#else |
| 13 | + |
| 14 | +#if defined(HAVE_CPUID_MS) |
| 15 | +# include <intrin.h> |
| 16 | +#elif defined(HAVE_CPUID_GNU) |
16 | 17 | // Newer versions of GCC and clang come with cpuid.h |
17 | 18 | # include <cpuid.h> |
18 | 19 | # ifdef X86_HAVE_XSAVE_INTRIN |
|
27 | 28 | #include <string.h> |
28 | 29 |
|
29 | 30 | static inline void cpuid(int info, unsigned* eax, unsigned* ebx, unsigned* ecx, unsigned* edx) { |
30 | | -#ifdef _MSC_VER |
| 31 | +#if defined(HAVE_CPUID_MS) |
31 | 32 | unsigned int registers[4]; |
32 | 33 | __cpuid((int *)registers, info); |
33 | 34 |
|
34 | 35 | *eax = registers[0]; |
35 | 36 | *ebx = registers[1]; |
36 | 37 | *ecx = registers[2]; |
37 | 38 | *edx = registers[3]; |
38 | | -#else |
| 39 | +#elif defined(HAVE_CPUID_GNU) |
39 | 40 | *eax = *ebx = *ecx = *edx = 0; |
40 | 41 | __cpuid(info, *eax, *ebx, *ecx, *edx); |
| 42 | +#else |
| 43 | + /* When using this fallback, the faster SSE/AVX code is disabled */ |
| 44 | + *eax = *ebx = *ecx = *edx = 0; |
41 | 45 | #endif |
42 | 46 | } |
43 | 47 |
|
44 | 48 | static inline void cpuidex(int info, int subinfo, unsigned* eax, unsigned* ebx, unsigned* ecx, unsigned* edx) { |
45 | | -#ifdef _MSC_VER |
| 49 | +#if defined(HAVE_CPUID_MS) |
46 | 50 | unsigned int registers[4]; |
47 | 51 | __cpuidex((int *)registers, info, subinfo); |
48 | 52 |
|
49 | 53 | *eax = registers[0]; |
50 | 54 | *ebx = registers[1]; |
51 | 55 | *ecx = registers[2]; |
52 | 56 | *edx = registers[3]; |
53 | | -#else |
| 57 | +#elif defined(HAVE_CPUID_GNU) |
54 | 58 | *eax = *ebx = *ecx = *edx = 0; |
55 | 59 | __cpuid_count(info, subinfo, *eax, *ebx, *ecx, *edx); |
| 60 | +#else |
| 61 | + /* When using this fallback, the faster SSE/AVX code is disabled */ |
| 62 | + *eax = *ebx = *ecx = *edx = 0; |
56 | 63 | #endif |
57 | 64 | } |
58 | 65 |
|
59 | 66 | static inline uint64_t xgetbv(unsigned int xcr) { |
60 | 67 | #if defined(_MSC_VER) || defined(X86_HAVE_XSAVE_INTRIN) |
61 | 68 | return _xgetbv(xcr); |
62 | | -#else |
| 69 | +#elif defined(__GNUC__) |
63 | 70 | uint32_t eax, edx; |
64 | 71 | __asm__ ( ".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c"(xcr)); |
65 | 72 | return (uint64_t)(edx) << 32 | eax; |
| 73 | +#else |
| 74 | + /* When using this fallback, some of the faster code is disabled */ |
| 75 | + return 0; |
66 | 76 | #endif |
67 | 77 | } |
68 | 78 |
|
|
0 commit comments