Skip to content

Commit adf9c71

Browse files
authored
Fix intrin_compat.h to work for MinGW (#671)
1 parent 93e98fa commit adf9c71

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

Dependencies/Utility/Utility/intrin_compat.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ static inline uint32_t _lrotl(uint32_t value, int shift)
8787
#ifdef _WIN32
8888
#include <intrin.h>
8989
#pragma intrinsic(__rdtsc)
90-
#endif
91-
90+
#endif // _WIN32
91+
#endif // _rdtsc
92+
#ifndef _rdtsc
9293
static inline uint64_t _rdtsc()
9394
{
94-
#if _WIN32
95+
#ifdef _WIN32
9596
return __rdtsc();
9697
#elif defined(__has_builtin) && __has_builtin(__builtin_readcyclecounter)
9798
return __builtin_readcyclecounter();
@@ -101,9 +102,9 @@ static inline uint64_t _rdtsc()
101102
#error "No implementation for _rdtsc"
102103
#endif
103104
}
104-
#endif
105+
#endif // _rdtsc
105106

106-
#ifdef _MSC_VER
107+
#ifdef _WIN32
107108
#include <intrin.h>
108109
#pragma intrinsic(_ReturnAddress)
109110
#elif defined(__has_builtin)
@@ -132,17 +133,20 @@ static inline uint64_t _rdtsc()
132133
#endif
133134

134135
#ifndef cpuid
135-
#if defined(_MSC_VER)
136+
#if (defined _M_IX86 || defined _M_X64 || defined __i386__ || defined __amd64__)
137+
#ifdef _WIN32
136138
#include <intrin.h>
137139
#define cpuid(regs, cpuid_type) __cpuid(reinterpret_cast<int *>(regs), cpuid_type)
138-
#elif (defined __clang__ || defined __GNUC__) && (defined __i386__ || defined __amd64__)
140+
#elif (defined __clang__ || defined __GNUC__)
139141
#include <cpuid.h>
140142
#define cpuid(regs, cpuid_type) __cpuid(cpuid_type, regs[0], regs[1], regs[2], regs[3])
141-
#else
142-
/* Just return 0 for everything if its not x86 */
143+
#endif
144+
#endif // (defined _M_IX86 || defined _M_X64 || defined __i386__ || defined __amd64__)
145+
#endif // cpuid
146+
#ifndef cpuid
147+
/* Just return 0 for everything if its not x86 or as fallback */
143148
#include <string.h>
144149
#define cpuid(regs, cpuid_type) memset(regs, 0, 16)
145-
#endif
146-
#endif //cpuid
150+
#endif // cpuid
147151

148-
#endif // defined(_MSC_VER) && _MSC_VER < 1300
152+
#endif // !(defined(_MSC_VER) && _MSC_VER < 1300)

0 commit comments

Comments
 (0)