From 7e92710d7cbc3ec66fc72a7de4657b71b4e654c9 Mon Sep 17 00:00:00 2001 From: topilski Date: Thu, 17 May 2018 08:50:42 +0300 Subject: [PATCH 1/2] Review --- libcpuid/asm-bits.c | 20 +++++++++++++++----- libcpuid/asm-bits.h | 6 +++++- libcpuid/libcpuid.h | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/libcpuid/asm-bits.c b/libcpuid/asm-bits.c index b8e3228..c1fa39d 100644 --- a/libcpuid/asm-bits.c +++ b/libcpuid/asm-bits.c @@ -32,7 +32,7 @@ int cpuid_exists_by_eflags(void) #if defined(PLATFORM_X64) return 1; /* CPUID is always present on the x86_64 */ #elif defined(PLATFORM_X86) -# if defined(COMPILER_GCC) +# if defined(COMPILER_GCC) || defined(COMPILER_CLANG) int result; __asm __volatile( " pushfl\n" @@ -70,6 +70,8 @@ int cpuid_exists_by_eflags(void) # else return 0; # endif /* COMPILER_MICROSOFT */ +#elif defined(PLATFORM_ARM) + return 0; #else return 0; #endif /* PLATFORM_X86 */ @@ -82,7 +84,7 @@ int cpuid_exists_by_eflags(void) */ void exec_cpuid(uint32_t *regs) { -#ifdef COMPILER_GCC +#if defined(COMPILER_GCC) || defined(COMPILER_CLANG) # ifdef PLATFORM_X64 __asm __volatile( " mov %0, %%rdi\n" @@ -109,7 +111,7 @@ void exec_cpuid(uint32_t *regs) :"m"(regs) :"memory", "eax", "rdi" ); -# else +# elif defined(PLATFORM_X86) __asm __volatile( " mov %0, %%edi\n" @@ -135,6 +137,7 @@ void exec_cpuid(uint32_t *regs) :"m"(regs) :"memory", "eax", "edi" ); +# elif defined(PLATFORM_ARM) # endif /* COMPILER_GCC */ #else # ifdef COMPILER_MICROSOFT @@ -173,13 +176,18 @@ void exec_cpuid(uint32_t *regs) void cpu_rdtsc(uint64_t* result) { 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 ( " rdtsc\n" " mov %%eax, %0\n" " mov %%edx, %1\n" :"=m"(low_part), "=m"(hi_part)::"memory", "eax", "edx" ); +#endif #else # ifdef COMPILER_MICROSOFT __asm { @@ -198,12 +206,14 @@ void cpu_rdtsc(uint64_t* result) #ifdef INLINE_ASM_SUPPORTED void busy_sse_loop(int cycles) { -#ifdef COMPILER_GCC +#if defined(COMPILER_GCC) || defined(COMPILER_CLANG) #ifndef __APPLE__ # define XALIGN ".balign 16\n" #else # define XALIGN ".align 4\n" #endif +#ifdef PLATFORM_ARM +#else __asm __volatile ( " xorps %%xmm0, %%xmm0\n" " xorps %%xmm1, %%xmm1\n" diff --git a/libcpuid/asm-bits.h b/libcpuid/asm-bits.h index 3a03e11..cc47342 100644 --- a/libcpuid/asm-bits.h +++ b/libcpuid/asm-bits.h @@ -32,6 +32,8 @@ # define COMPILER_MICROSOFT #elif defined(__GNUC__) # define COMPILER_GCC +#elif defined(__clang__) +# define COMPILER_CLANG #endif /* Determine Platform */ @@ -39,10 +41,12 @@ # define PLATFORM_X64 #elif defined(__i386__) || defined(_M_IX86) # define PLATFORM_X86 +#elif defined(__ARMEL__) +# define PLATFORM_ARM #endif /* 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) # define INLINE_ASM_SUPPORTED #endif diff --git a/libcpuid/libcpuid.h b/libcpuid/libcpuid.h index 2bf445f..053b014 100644 --- a/libcpuid/libcpuid.h +++ b/libcpuid/libcpuid.h @@ -1141,7 +1141,7 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename); int cpu_msr_driver_close(struct msr_driver_t* handle); #ifdef __cplusplus -}; /* extern "C" */ +} /* extern "C" */ #endif From 7d8819905f812c0143bc067fc9360e691f5a3931 Mon Sep 17 00:00:00 2001 From: topilski Date: Thu, 17 May 2018 09:19:14 +0300 Subject: [PATCH 2/2] Less warnings --- libcpuid/asm-bits.c | 7 ++++--- libcpuid/asm-bits.h | 14 +++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libcpuid/asm-bits.c b/libcpuid/asm-bits.c index c1fa39d..e881668 100644 --- a/libcpuid/asm-bits.c +++ b/libcpuid/asm-bits.c @@ -84,7 +84,7 @@ int cpuid_exists_by_eflags(void) */ void exec_cpuid(uint32_t *regs) { -#if defined(COMPILER_GCC) || defined(COMPILER_CLANG) +# if defined(COMPILER_GCC) || defined(COMPILER_CLANG) # ifdef PLATFORM_X64 __asm __volatile( " mov %0, %%rdi\n" @@ -206,7 +206,7 @@ void cpu_rdtsc(uint64_t* result) #ifdef INLINE_ASM_SUPPORTED void busy_sse_loop(int cycles) { -#if defined(COMPILER_GCC) || defined(COMPILER_CLANG) +# if defined(COMPILER_GCC) || defined(COMPILER_CLANG) #ifndef __APPLE__ # define XALIGN ".balign 16\n" #else @@ -520,6 +520,7 @@ void busy_sse_loop(int cycles) " jnz 1b\n" ::"a"(cycles) ); +#endif #else # ifdef COMPILER_MICROSOFT __asm { @@ -832,4 +833,4 @@ bsLoop: # endif /* COMPILER_MICROSOFT */ #endif /* COMPILER_GCC */ } -#endif /* INLINE_ASSEMBLY_SUPPORTED */ +#endif /* INLINE_ASSEMBLY_SUPPORTED */ \ No newline at end of file diff --git a/libcpuid/asm-bits.h b/libcpuid/asm-bits.h index cc47342..af8ed7a 100644 --- a/libcpuid/asm-bits.h +++ b/libcpuid/asm-bits.h @@ -29,24 +29,36 @@ /* Determine Compiler: */ #if defined(_MSC_VER) +#if !defined(COMPILER_MICROSOFT) # define COMPILER_MICROSOFT +#endif #elif defined(__GNUC__) +#if !defined(COMPILER_GCC) # define COMPILER_GCC +#endif #elif defined(__clang__) +#if !defined(COMPILER_CLANG) # define COMPILER_CLANG #endif +#endif /* Determine Platform */ #if defined(__x86_64__) || defined(_M_AMD64) +#if !defined(PLATFORM_X64) # define PLATFORM_X64 +#endif #elif defined(__i386__) || defined(_M_IX86) +#if !defined(PLATFORM_X86) # define PLATFORM_X86 +#endif #elif defined(__ARMEL__) +#if !defined(PLATFORM_ARM) # define PLATFORM_ARM #endif +#endif /* Under Windows/AMD64 with MSVC, inline assembly isn't supported */ -#if ((defined(COMPILER_GCC) || defined(COMPILER_CLANG))) && defined(PLATFORM_X64)) || defined(PLATFORM_X86) || defined(PLATFORM_ARM) +#if ((defined(COMPILER_GCC) || defined(COMPILER_CLANG))) && (defined(PLATFORM_X64) || defined(PLATFORM_X86) || defined(PLATFORM_ARM)) # define INLINE_ASM_SUPPORTED #endif