From ad92c3b0255cac7978a0a1f345c2a3a06a398111 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 6 Oct 2018 15:13:55 +0300 Subject: [PATCH] Add ASM detection for builds without libcpuid. --- src/common/cpu/BasicCpuInfo.cpp | 25 +++++++++++++++++++++++-- src/common/cpu/BasicCpuInfo.h | 4 ++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/common/cpu/BasicCpuInfo.cpp b/src/common/cpu/BasicCpuInfo.cpp index 66af53cc..cb1e6d1d 100644 --- a/src/common/cpu/BasicCpuInfo.cpp +++ b/src/common/cpu/BasicCpuInfo.cpp @@ -71,7 +71,7 @@ static inline void cpuid(int level, int output[4]) { static inline 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) { @@ -86,7 +86,7 @@ static inline void cpu_brand_string(char* s) { static inline 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) != 0; @@ -94,11 +94,32 @@ static inline bool has_aes_ni() xmrig::BasicCpuInfo::BasicCpuInfo() : + m_assembly(ASM_NONE), m_aes(has_aes_ni()), m_brand(), m_threads(std::thread::hardware_concurrency()) { cpu_brand_string(m_brand); + +# ifndef XMRIG_NO_ASM + if (hasAES()) { + 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) { + m_assembly = ASM_INTEL; + } + else if (memcmp(vendor, "AuthenticAMD", 12) == 0) { + m_assembly = ASM_RYZEN; + } + } +# endif } diff --git a/src/common/cpu/BasicCpuInfo.h b/src/common/cpu/BasicCpuInfo.h index f9d710d6..911674ea 100644 --- a/src/common/cpu/BasicCpuInfo.h +++ b/src/common/cpu/BasicCpuInfo.h @@ -7,7 +7,6 @@ * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , * - * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -40,7 +39,7 @@ public: protected: size_t optimalThreadsCount(size_t memSize, int maxCpuUsage) const override; - inline Assembly assembly() const override { return ASM_NONE; } + inline Assembly assembly() const override { return m_assembly; } inline bool hasAES() const override { return m_aes; } inline bool isSupported() const override { return true; } inline const char *brand() const override { return m_brand; } @@ -58,6 +57,7 @@ protected: # endif private: + Assembly m_assembly; bool m_aes; char m_brand[64]; int32_t m_threads;