From 92bada1a32c7ebd5f5b4438bd85bb003d20bd046 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 14 Mar 2010 11:16:25 +0100 Subject: [PATCH] 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 --- src/bitcount.h | 14 -------------- src/types.h | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/bitcount.h b/src/bitcount.h index 7a05970d..43895180 100644 --- a/src/bitcount.h +++ b/src/bitcount.h @@ -29,8 +29,6 @@ #if defined(__INTEL_COMPILER) && defined(USE_POPCNT) // Intel compiler -#include - inline bool cpu_has_popcnt() { int CPUInfo[4] = {-1}; @@ -42,8 +40,6 @@ inline bool cpu_has_popcnt() { #elif defined(_MSC_VER) && defined(USE_POPCNT) // Microsoft compiler -#include - inline bool cpu_has_popcnt() { int CPUInfo[4] = {-1}; @@ -55,16 +51,6 @@ inline bool cpu_has_popcnt() { #elif defined(__GNUC__) && defined(USE_POPCNT) // Gcc compiler -inline void __cpuid(unsigned int op, - unsigned int *eax, unsigned int *ebx, - unsigned int *ecx, unsigned int *edx) -{ - *eax = op; - *ecx = 0; - __asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) - : "0" (*eax), "2" (*ecx)); -} - inline bool cpu_has_popcnt() { unsigned int eax, ebx, ecx, edx; diff --git a/src/types.h b/src/types.h index 0d0d8485..d91009df 100644 --- a/src/types.h +++ b/src/types.h @@ -73,4 +73,22 @@ typedef uint64_t Bitboard; #define CACHE_LINE_ALIGNMENT __attribute__ ((aligned(64))) #endif +// Define a __cpuid() function for gcc compilers, for Intel and MSVC +// is already available as an intrinsic. +#if defined(__INTEL_COMPILER) +#include +#elif defined(_MSC_VER) +#include +#elif defined(__GNUC__) +inline void __cpuid(unsigned int op, + unsigned int *eax, unsigned int *ebx, + unsigned int *ecx, unsigned int *edx) +{ + *eax = op; + *ecx = 0; + __asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) + : "0" (*eax), "2" (*ecx)); +} +#endif + #endif // !defined(TYPES_H_INCLUDED) -- 2.39.2