Update libcpuid to recent git version.

This commit is contained in:
XMRig 2018-09-23 13:05:03 +03:00
parent cf76d9254a
commit 1f609c7ebd
8 changed files with 991 additions and 929 deletions

View file

@ -32,7 +32,7 @@ int cpuid_exists_by_eflags(void)
#if defined(PLATFORM_X64) #if defined(PLATFORM_X64)
return 1; /* CPUID is always present on the x86_64 */ return 1; /* CPUID is always present on the x86_64 */
#elif defined(PLATFORM_X86) #elif defined(PLATFORM_X86)
# if defined(COMPILER_GCC) # if defined(COMPILER_GCC) || defined(COMPILER_CLANG)
int result; int result;
__asm __volatile( __asm __volatile(
" pushfl\n" " pushfl\n"
@ -70,6 +70,8 @@ int cpuid_exists_by_eflags(void)
# else # else
return 0; return 0;
# endif /* COMPILER_MICROSOFT */ # endif /* COMPILER_MICROSOFT */
#elif defined(PLATFORM_ARM)
return 0;
#else #else
return 0; return 0;
#endif /* PLATFORM_X86 */ #endif /* PLATFORM_X86 */
@ -82,7 +84,7 @@ int cpuid_exists_by_eflags(void)
*/ */
void exec_cpuid(uint32_t *regs) void exec_cpuid(uint32_t *regs)
{ {
#ifdef COMPILER_GCC # if defined(COMPILER_GCC) || defined(COMPILER_CLANG)
# ifdef PLATFORM_X64 # ifdef PLATFORM_X64
__asm __volatile( __asm __volatile(
" mov %0, %%rdi\n" " mov %0, %%rdi\n"
@ -109,7 +111,7 @@ void exec_cpuid(uint32_t *regs)
:"m"(regs) :"m"(regs)
:"memory", "eax", "rdi" :"memory", "eax", "rdi"
); );
# else # elif defined(PLATFORM_X86)
__asm __volatile( __asm __volatile(
" mov %0, %%edi\n" " mov %0, %%edi\n"
@ -135,6 +137,7 @@ void exec_cpuid(uint32_t *regs)
:"m"(regs) :"m"(regs)
:"memory", "eax", "edi" :"memory", "eax", "edi"
); );
# elif defined(PLATFORM_ARM)
# endif /* COMPILER_GCC */ # endif /* COMPILER_GCC */
#else #else
# ifdef COMPILER_MICROSOFT # ifdef COMPILER_MICROSOFT
@ -173,13 +176,18 @@ void exec_cpuid(uint32_t *regs)
void cpu_rdtsc(uint64_t* result) void cpu_rdtsc(uint64_t* result)
{ {
uint32_t low_part, hi_part; uint32_t low_part, hi_part;
#ifdef COMPILER_GCC #if defined(COMPILER_GCC) || defined(COMPILER_CLANG)
#ifdef PLATFORM_ARM
low_part = 0;
hi_part = 0;
#else
__asm __volatile ( __asm __volatile (
" rdtsc\n" " rdtsc\n"
" mov %%eax, %0\n" " mov %%eax, %0\n"
" mov %%edx, %1\n" " mov %%edx, %1\n"
:"=m"(low_part), "=m"(hi_part)::"memory", "eax", "edx" :"=m"(low_part), "=m"(hi_part)::"memory", "eax", "edx"
); );
#endif
#else #else
# ifdef COMPILER_MICROSOFT # ifdef COMPILER_MICROSOFT
__asm { __asm {
@ -198,12 +206,14 @@ void cpu_rdtsc(uint64_t* result)
#ifdef INLINE_ASM_SUPPORTED #ifdef INLINE_ASM_SUPPORTED
void busy_sse_loop(int cycles) void busy_sse_loop(int cycles)
{ {
#ifdef COMPILER_GCC # if defined(COMPILER_GCC) || defined(COMPILER_CLANG)
#ifndef __APPLE__ #ifndef __APPLE__
# define XALIGN ".balign 16\n" # define XALIGN ".balign 16\n"
#else #else
# define XALIGN ".align 4\n" # define XALIGN ".align 4\n"
#endif #endif
#ifdef PLATFORM_ARM
#else
__asm __volatile ( __asm __volatile (
" xorps %%xmm0, %%xmm0\n" " xorps %%xmm0, %%xmm0\n"
" xorps %%xmm1, %%xmm1\n" " xorps %%xmm1, %%xmm1\n"
@ -510,6 +520,7 @@ void busy_sse_loop(int cycles)
" jnz 1b\n" " jnz 1b\n"
::"a"(cycles) ::"a"(cycles)
); );
#endif
#else #else
# ifdef COMPILER_MICROSOFT # ifdef COMPILER_MICROSOFT
__asm { __asm {

View file

@ -29,20 +29,38 @@
/* Determine Compiler: */ /* Determine Compiler: */
#if defined(_MSC_VER) #if defined(_MSC_VER)
#if !defined(COMPILER_MICROSOFT)
# define COMPILER_MICROSOFT # define COMPILER_MICROSOFT
#endif
#elif defined(__GNUC__) #elif defined(__GNUC__)
#if !defined(COMPILER_GCC)
# define COMPILER_GCC # define COMPILER_GCC
#endif #endif
#elif defined(__clang__)
#if !defined(COMPILER_CLANG)
# define COMPILER_CLANG
#endif
#endif
/* Determine Platform */ /* Determine Platform */
#if defined(__x86_64__) || defined(_M_AMD64) #if defined(__x86_64__) || defined(_M_AMD64)
#if !defined(PLATFORM_X64)
# define PLATFORM_X64 # define PLATFORM_X64
#endif
#elif defined(__i386__) || defined(_M_IX86) #elif defined(__i386__) || defined(_M_IX86)
#if !defined(PLATFORM_X86)
# define PLATFORM_X86 # define PLATFORM_X86
#endif #endif
#elif defined(__ARMEL__)
#if !defined(PLATFORM_ARM)
# define PLATFORM_ARM
#endif
#endif
/* Under Windows/AMD64 with MSVC, inline assembly isn't supported */ /* Under Windows/AMD64 with MSVC, inline assembly isn't supported */
#if (defined(COMPILER_GCC) && defined(PLATFORM_X64)) || defined(PLATFORM_X86) #if (((defined(COMPILER_GCC) || defined(COMPILER_CLANG))) && \
(defined(PLATFORM_X64) || defined(PLATFORM_X86) || defined(PLATFORM_ARM))) || \
(defined(COMPILER_MICROSOFT) && defined(PLATFORM_X86))
# define INLINE_ASM_SUPPORTED # define INLINE_ASM_SUPPORTED
#endif #endif

View file

@ -82,6 +82,7 @@
*/ */
/** @defgroup libcpuid LibCPUID /** @defgroup libcpuid LibCPUID
* @brief LibCPUID provides CPU identification
@{ */ @{ */
/* Include some integer type specifications: */ /* Include some integer type specifications: */
@ -535,23 +536,23 @@ typedef enum {
* @brief Describes common library error codes * @brief Describes common library error codes
*/ */
typedef enum { typedef enum {
ERR_OK = 0, /*!< "No error" */ ERR_OK = 0, /*!< No error */
ERR_NO_CPUID = -1, /*!< "CPUID instruction is not supported" */ ERR_NO_CPUID = -1, /*!< CPUID instruction is not supported */
ERR_NO_RDTSC = -2, /*!< "RDTSC instruction is not supported" */ ERR_NO_RDTSC = -2, /*!< RDTSC instruction is not supported */
ERR_NO_MEM = -3, /*!< "Memory allocation failed" */ ERR_NO_MEM = -3, /*!< Memory allocation failed */
ERR_OPEN = -4, /*!< "File open operation failed" */ ERR_OPEN = -4, /*!< File open operation failed */
ERR_BADFMT = -5, /*!< "Bad file format" */ ERR_BADFMT = -5, /*!< Bad file format */
ERR_NOT_IMP = -6, /*!< "Not implemented" */ ERR_NOT_IMP = -6, /*!< Not implemented */
ERR_CPU_UNKN = -7, /*!< "Unsupported processor" */ ERR_CPU_UNKN = -7, /*!< Unsupported processor */
ERR_NO_RDMSR = -8, /*!< "RDMSR instruction is not supported" */ ERR_NO_RDMSR = -8, /*!< RDMSR instruction is not supported */
ERR_NO_DRIVER= -9, /*!< "RDMSR driver error (generic)" */ ERR_NO_DRIVER= -9, /*!< RDMSR driver error (generic) */
ERR_NO_PERMS = -10, /*!< "No permissions to install RDMSR driver" */ ERR_NO_PERMS = -10, /*!< No permissions to install RDMSR driver */
ERR_EXTRACT = -11, /*!< "Cannot extract RDMSR driver (read only media?)" */ ERR_EXTRACT = -11, /*!< Cannot extract RDMSR driver (read only media?) */
ERR_HANDLE = -12, /*!< "Bad handle" */ ERR_HANDLE = -12, /*!< Bad handle */
ERR_INVMSR = -13, /*!< "Invalid MSR" */ ERR_INVMSR = -13, /*!< Invalid MSR */
ERR_INVCNB = -14, /*!< "Invalid core number" */ ERR_INVCNB = -14, /*!< Invalid core number */
ERR_HANDLE_R = -15, /*!< "Error on handle read" */ ERR_HANDLE_R = -15, /*!< Error on handle read */
ERR_INVRANGE = -16, /*!< "Invalid given range" */ ERR_INVRANGE = -16, /*!< Invalid given range */
} cpu_error_t; } cpu_error_t;
/** /**
@ -668,7 +669,7 @@ struct cpu_epc_t cpuid_get_epc(int index, const struct cpu_raw_data_t* raw);
const char* cpuid_lib_version(void); const char* cpuid_lib_version(void);
#ifdef __cplusplus #ifdef __cplusplus
}; /* extern "C" */ } /* extern "C" */
#endif #endif

View file

@ -75,8 +75,9 @@ enum _intel_bits_t {
_3 = LBIT( 14 ), _3 = LBIT( 14 ),
_5 = LBIT( 15 ), _5 = LBIT( 15 ),
_7 = LBIT( 16 ), _7 = LBIT( 16 ),
XEON_ = LBIT( 17 ), _9 = LBIT( 17 ),
ATOM_ = LBIT( 18 ), XEON_ = LBIT( 18 ),
ATOM_ = LBIT( 19 ),
}; };
typedef enum _intel_bits_t intel_bits_t; typedef enum _intel_bits_t intel_bits_t;

View file

@ -32,6 +32,32 @@
#ifndef __LIBCPUID_TYPES_H__ #ifndef __LIBCPUID_TYPES_H__
#define __LIBCPUID_TYPES_H__ #define __LIBCPUID_TYPES_H__
#include <stdint.h> #if !defined(_MSC_VER) || _MSC_VER >= 1600
# include <stdint.h>
#else
/* we have to provide our own: */
# if !defined(__int32_t_defined)
typedef int int32_t;
# endif
# if !defined(__uint32_t_defined)
typedef unsigned uint32_t;
# endif
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
#if (defined _MSC_VER) && (_MSC_VER <= 1300)
/* MSVC 6.0: no long longs ... */
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
/* all other sane compilers: */
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
#endif
#endif
#endif /* __LIBCPUID_TYPES_H__ */ #endif /* __LIBCPUID_TYPES_H__ */

View file

@ -49,6 +49,10 @@ enum _amd_model_codes_t {
_1400, _1400,
_1500, _1500,
_1600, _1600,
_1900,
_2400,
_2500,
_2700,
}; };
static void load_amd_features(struct cpu_raw_data_t* raw, struct cpu_id_t* data) static void load_amd_features(struct cpu_raw_data_t* raw, struct cpu_id_t* data)

View file

@ -376,7 +376,7 @@ static intel_code_and_bits_t get_brand_code_and_bits(struct cpu_id_t* data)
bits |= bit_matchtable[i].bit; bits |= bit_matchtable[i].bit;
} }
if ((i = match_pattern(bs, "Core(TM) [im][357]")) != 0) { if ((i = match_pattern(bs, "Core(TM) [im][3579]")) != 0) {
bits |= CORE_; bits |= CORE_;
i--; i--;
switch (bs[i + 9]) { switch (bs[i + 9]) {
@ -387,6 +387,7 @@ static intel_code_and_bits_t get_brand_code_and_bits(struct cpu_id_t* data)
case '3': bits |= _3; break; case '3': bits |= _3; break;
case '5': bits |= _5; break; case '5': bits |= _5; break;
case '7': bits |= _7; break; case '7': bits |= _7; break;
case '9': bits |= _9; break;
} }
} }
for (i = 0; i < COUNT_OF(matchtable); i++) for (i = 0; i < COUNT_OF(matchtable); i++)