Skip to content

Commit c5cc49c

Browse files
committed
[ZH] Fixes to intrin_compat.h
1 parent feba1d3 commit c5cc49c

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
@@ -68,11 +68,12 @@ static inline uint32_t _lrotl(uint32_t value, int shift)
6868
#ifdef _WIN32
6969
#include <intrin.h>
7070
#pragma intrinsic(__rdtsc)
71-
#endif
72-
71+
#endif // _WIN32
72+
#endif // _rdtsc
73+
#ifndef _rdtsc
7374
static inline uint64_t _rdtsc()
7475
{
75-
#if _WIN32
76+
#ifdef _WIN32
7677
return __rdtsc();
7778
#elif defined(__has_builtin) && __has_builtin(__builtin_readcyclecounter)
7879
return __builtin_readcyclecounter();
@@ -82,9 +83,9 @@ static inline uint64_t _rdtsc()
8283
#error "No implementation for _rdtsc"
8384
#endif
8485
}
85-
#endif
86+
#endif // _rdtsc
8687

87-
#ifdef _MSC_VER
88+
#ifdef _WIN32
8889
#include <intrin.h>
8990
#pragma intrinsic(_ReturnAddress)
9091
#elif defined(__has_builtin)
@@ -113,17 +114,20 @@ static inline uint64_t _rdtsc()
113114
#endif
114115

115116
#ifndef cpuid
116-
#if defined(_MSC_VER)
117+
#if (defined _M_IX86 || defined _M_X64 || defined __i386__ || defined __amd64__)
118+
#ifdef _WIN32
117119
#include <intrin.h>
118120
#define cpuid(regs, cpuid_type) __cpuid(reinterpret_cast<int *>(regs), cpuid_type)
119-
#elif (defined __clang__ || defined __GNUC__) && (defined __i386__ || defined __amd64__)
121+
#elif (defined __clang__ || defined __GNUC__)
120122
#include <cpuid.h>
121123
#define cpuid(regs, cpuid_type) __cpuid(cpuid_type, regs[0], regs[1], regs[2], regs[3])
122-
#else
123-
/* Just return 0 for everything if its not x86 */
124+
#endif
125+
#endif // (defined __i386__ || defined __amd64__)
126+
#endif // cpuid
127+
#ifndef cpuid
128+
/* Just return 0 for everything if its not x86 or as fallback */
124129
#include <string.h>
125130
#define cpuid(regs, cpuid_type) memset(regs, 0, 16)
126-
#endif
127-
#endif //cpuid
131+
#endif // cpuid
128132

129-
#endif // defined(_MSC_VER) && _MSC_VER < 1300
133+
#endif // !(defined(_MSC_VER) && _MSC_VER < 1300)

0 commit comments

Comments
 (0)