Skip to content

Commit 92bada1

Browse files
committed
Move __cpuid() definition for gcc in types.h
This will allow to use the function also for other purposes then detecting POPCNT. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
1 parent eaed535 commit 92bada1

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

src/bitcount.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
#if defined(__INTEL_COMPILER) && defined(USE_POPCNT) // Intel compiler
3131

32-
#include <nmmintrin.h>
33-
3432
inline bool cpu_has_popcnt() {
3533

3634
int CPUInfo[4] = {-1};
@@ -42,8 +40,6 @@ inline bool cpu_has_popcnt() {
4240

4341
#elif defined(_MSC_VER) && defined(USE_POPCNT) // Microsoft compiler
4442

45-
#include <intrin.h>
46-
4743
inline bool cpu_has_popcnt() {
4844

4945
int CPUInfo[4] = {-1};
@@ -55,16 +51,6 @@ inline bool cpu_has_popcnt() {
5551

5652
#elif defined(__GNUC__) && defined(USE_POPCNT) // Gcc compiler
5753

58-
inline void __cpuid(unsigned int op,
59-
unsigned int *eax, unsigned int *ebx,
60-
unsigned int *ecx, unsigned int *edx)
61-
{
62-
*eax = op;
63-
*ecx = 0;
64-
__asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
65-
: "0" (*eax), "2" (*ecx));
66-
}
67-
6854
inline bool cpu_has_popcnt() {
6955

7056
unsigned int eax, ebx, ecx, edx;

src/types.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,22 @@ typedef uint64_t Bitboard;
7373
#define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(64)))
7474
#endif
7575

76+
// Define a __cpuid() function for gcc compilers, for Intel and MSVC
77+
// is already available as an intrinsic.
78+
#if defined(__INTEL_COMPILER)
79+
#include <nmmintrin.h>
80+
#elif defined(_MSC_VER)
81+
#include <intrin.h>
82+
#elif defined(__GNUC__)
83+
inline void __cpuid(unsigned int op,
84+
unsigned int *eax, unsigned int *ebx,
85+
unsigned int *ecx, unsigned int *edx)
86+
{
87+
*eax = op;
88+
*ecx = 0;
89+
__asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
90+
: "0" (*eax), "2" (*ecx));
91+
}
92+
#endif
93+
7694
#endif // !defined(TYPES_H_INCLUDED)

0 commit comments

Comments
 (0)