From b02f4ff1633be8c40bf6ee6a0c1c2f69e9cf3ea0 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 5 Oct 2018 15:58:33 +0300 Subject: [PATCH] Autodetect ASM without libcpuid. --- cpu_stub.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/cpu_stub.c b/cpu_stub.c index 83d5efc3..7e1b4209 100644 --- a/cpu_stub.c +++ b/cpu_stub.c @@ -24,7 +24,11 @@ #include #include #include +#include + + #include "cpu.h" +#include "options.h" #define VENDOR_ID (0) @@ -53,7 +57,7 @@ static inline void cpuid(int level, int output[4]) { static void cpu_brand_string(char* s) { - int cpu_info[4] = { 0 }; + int32_t cpu_info[4] = { 0 }; cpuid(VENDOR_ID, cpu_info); if (cpu_info[EAX_Reg] >= 4) { @@ -68,7 +72,7 @@ static void cpu_brand_string(char* s) { static bool has_aes_ni() { - int cpu_info[4] = { 0 }; + int32_t cpu_info[4] = { 0 }; cpuid(PROCESSOR_INFO, cpu_info); return cpu_info[ECX_Reg] & bit_AES; @@ -76,7 +80,7 @@ static bool has_aes_ni() static bool has_bmi2() { - int cpu_info[4] = { 0 }; + int32_t cpu_info[4] = { 0 }; cpuid(EXTENDED_FEATURES, cpu_info); return cpu_info[EBX_Reg] & bit_BMI2; @@ -93,6 +97,24 @@ void cpu_init_common() { if (has_aes_ni()) { cpu_info.flags |= CPU_FLAG_AES; + +# ifndef XMRIG_NO_ASM + char vendor[13] = { 0 }; + int32_t data[4] = { 0 }; + + cpuid(0, data); + + memcpy(vendor + 0, &data[1], 4); + memcpy(vendor + 4, &data[3], 4); + memcpy(vendor + 8, &data[2], 4); + + if (memcmp(vendor, "GenuineIntel", 12) == 0) { + cpu_info.assembly = ASM_INTEL; + } + else if (memcmp(vendor, "AuthenticAMD", 12) == 0) { + cpu_info.assembly = ASM_RYZEN; + } +# endif } if (has_bmi2()) {