From df4532d9a134add0b5a6960190db15baf24403ef Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 27 Aug 2021 12:36:08 +0700 Subject: [PATCH] Cleanup ARM code. --- cmake/cpu.cmake | 25 ++++++++++--------- cmake/flags.cmake | 8 +++--- cmake/os.cmake | 23 +++++++---------- src/backend/cpu/platform/BasicCpuInfo_arm.cpp | 5 ++-- src/crypto/randomx/randomx.cpp | 6 ++--- src/crypto/randomx/randomx.h | 4 +-- 6 files changed, 33 insertions(+), 38 deletions(-) diff --git a/cmake/cpu.cmake b/cmake/cpu.cmake index a37f10662..14b17763e 100644 --- a/cmake/cpu.cmake +++ b/cmake/cpu.cmake @@ -1,9 +1,16 @@ +if (CMAKE_SIZEOF_VOID_P EQUAL 8) + set(XMRIG_64_BIT ON) + add_definitions(-DXMRIG_64_BIT) +else() + set(XMRIG_64_BIT OFF) +endif() + if (NOT CMAKE_SYSTEM_PROCESSOR) message(WARNING "CMAKE_SYSTEM_PROCESSOR not defined") endif() -if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$" AND CMAKE_SIZEOF_VOID_P EQUAL 8) - add_definitions(/DRAPIDJSON_SSE2) +if (XMRIG_64_BIT AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$") + add_definitions(-DRAPIDJSON_SSE2) else() set(WITH_SSE4_1 OFF) endif() @@ -17,31 +24,25 @@ if (NOT ARM_TARGET) endif() if (ARM_TARGET AND ARM_TARGET GREATER 6) - set(XMRIG_ARM ON) - add_definitions(/DXMRIG_ARM) + set(XMRIG_ARM ON) + add_definitions(-DXMRIG_ARM=${ARM_TARGET}) message(STATUS "Use ARM_TARGET=${ARM_TARGET} (${CMAKE_SYSTEM_PROCESSOR})") include(CheckCXXCompilerFlag) if (ARM_TARGET EQUAL 8) - set(XMRIG_ARMv8 ON) - add_definitions(/DXMRIG_ARMv8) - CHECK_CXX_COMPILER_FLAG(-march=armv8-a+crypto XMRIG_ARM_CRYPTO) if (XMRIG_ARM_CRYPTO) - add_definitions(/DXMRIG_ARM_CRYPTO) + add_definitions(-DXMRIG_ARM_CRYPTO) set(ARM8_CXX_FLAGS "-march=armv8-a+crypto") else() set(ARM8_CXX_FLAGS "-march=armv8-a") endif() - elseif (ARM_TARGET EQUAL 7) - set(XMRIG_ARMv7 ON) - add_definitions(/DXMRIG_ARMv7) endif() endif() if (WITH_SSE4_1) - add_definitions(/DXMRIG_FEATURE_SSE4_1) + add_definitions(-DXMRIG_FEATURE_SSE4_1) endif() diff --git a/cmake/flags.cmake b/cmake/flags.cmake index cb4e0610c..ff5943a13 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -22,10 +22,10 @@ if (CMAKE_CXX_COMPILER_ID MATCHES GNU) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fexceptions -fno-rtti -Wno-strict-aliasing -Wno-class-memaccess") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -s") - if (XMRIG_ARMv8) + if (ARM_TARGET EQUAL 8) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM8_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM8_CXX_FLAGS} -flax-vector-conversions") - elseif (XMRIG_ARMv7) + elseif (ARM_TARGET EQUAL 7) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -flax-vector-conversions") else() @@ -80,10 +80,10 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fexceptions -fno-rtti -Wno-missing-braces") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -funroll-loops -fmerge-all-constants") - if (XMRIG_ARMv8) + if (ARM_TARGET EQUAL 8) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM8_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM8_CXX_FLAGS}") - elseif (XMRIG_ARMv7) + elseif (ARM_TARGET EQUAL 7) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon -march=${CMAKE_SYSTEM_PROCESSOR}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -march=${CMAKE_SYSTEM_PROCESSOR}") else() diff --git a/cmake/os.cmake b/cmake/os.cmake index 6516c1f7a..02a787dff 100644 --- a/cmake/os.cmake +++ b/cmake/os.cmake @@ -1,7 +1,3 @@ -if (CMAKE_SIZEOF_VOID_P EQUAL 8) - add_definitions(/DXMRIG_64_BIT) -endif() - if (WIN32) set(XMRIG_OS_WIN ON) elseif (APPLE) @@ -26,32 +22,31 @@ endif() if (XMRIG_OS_WIN) - add_definitions(/DWIN32) - add_definitions(/DXMRIG_OS_WIN) + add_definitions(-DWIN32 -DXMRIG_OS_WIN) elseif(XMRIG_OS_APPLE) - add_definitions(/DXMRIG_OS_APPLE) + add_definitions(-DXMRIG_OS_APPLE) if (XMRIG_OS_IOS) - add_definitions(/DXMRIG_OS_IOS) + add_definitions(-DXMRIG_OS_IOS) else() - add_definitions(/DXMRIG_OS_MACOS) + add_definitions(-DXMRIG_OS_MACOS) endif() if (XMRIG_ARM) set(WITH_SECURE_JIT ON) endif() elseif(XMRIG_OS_UNIX) - add_definitions(/DXMRIG_OS_UNIX) + add_definitions(-DXMRIG_OS_UNIX) if (XMRIG_OS_ANDROID) - add_definitions(/DXMRIG_OS_ANDROID) + add_definitions(-DXMRIG_OS_ANDROID) elseif (XMRIG_OS_LINUX) - add_definitions(/DXMRIG_OS_LINUX) + add_definitions(-DXMRIG_OS_LINUX) elseif (XMRIG_OS_FREEBSD) - add_definitions(/DXMRIG_OS_FREEBSD) + add_definitions(-DXMRIG_OS_FREEBSD) endif() endif() if (WITH_SECURE_JIT) - add_definitions(/DXMRIG_SECURE_JIT) + add_definitions(-DXMRIG_SECURE_JIT) endif() diff --git a/src/backend/cpu/platform/BasicCpuInfo_arm.cpp b/src/backend/cpu/platform/BasicCpuInfo_arm.cpp index ad24e10b0..b90138d83 100644 --- a/src/backend/cpu/platform/BasicCpuInfo_arm.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo_arm.cpp @@ -16,7 +16,6 @@ * along with this program. If not, see . */ - #include "base/tools/String.h" @@ -63,7 +62,7 @@ xmrig::BasicCpuInfo::BasicCpuInfo() : m_units[i] = i; } -# ifdef XMRIG_ARMv8 +# if (XMRIG_ARM == 8) memcpy(m_brand, "ARMv8", 5); # else memcpy(m_brand, "ARMv7", 5); @@ -128,7 +127,7 @@ rapidjson::Value xmrig::BasicCpuInfo::toJSON(rapidjson::Document &doc) const out.AddMember("msr", "none", allocator); out.AddMember("assembly", "none", allocator); -# ifdef XMRIG_ARMv8 +# if (XMRIG_ARM == 8) out.AddMember("arch", "aarch64", allocator); # else out.AddMember("arch", "aarch32", allocator); diff --git a/src/crypto/randomx/randomx.cpp b/src/crypto/randomx/randomx.cpp index fe438b61e..ed351e44e 100644 --- a/src/crypto/randomx/randomx.cpp +++ b/src/crypto/randomx/randomx.cpp @@ -37,7 +37,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(_M_X64) || defined(__x86_64__) #include "crypto/randomx/jit_compiler_x86_static.hpp" -#elif defined(XMRIG_ARMv8) +#elif (XMRIG_ARM == 8) #include "crypto/randomx/jit_compiler_a64_static.hpp" #endif @@ -180,7 +180,7 @@ RandomX_ConfigurationBase::RandomX_ConfigurationBase() # endif } -#ifdef XMRIG_ARMv8 +#if (XMRIG_ARM == 8) static uint32_t Log2(size_t value) { return (value > 1) ? (Log2(value / 2) + 1) : 0; } #endif @@ -254,7 +254,7 @@ typedef void(randomx::JitCompilerX86::* InstructionGeneratorX86_2)(const randomx memcpy(randomx::JitCompilerX86::engine + k, &p, sizeof(p)); \ } while (0) -#elif defined(XMRIG_ARMv8) +#elif (XMRIG_ARM == 8) Log2_ScratchpadL1 = Log2(ScratchpadL1_Size); Log2_ScratchpadL2 = Log2(ScratchpadL2_Size); diff --git a/src/crypto/randomx/randomx.h b/src/crypto/randomx/randomx.h index 937a0844c..91efcb28a 100644 --- a/src/crypto/randomx/randomx.h +++ b/src/crypto/randomx/randomx.h @@ -132,13 +132,13 @@ struct RandomX_ConfigurationBase uint32_t ScratchpadL3Mask_Calculated; uint32_t ScratchpadL3Mask64_Calculated; -#if defined(XMRIG_ARMv8) +# if (XMRIG_ARM == 8) uint32_t Log2_ScratchpadL1; uint32_t Log2_ScratchpadL2; uint32_t Log2_ScratchpadL3; uint32_t Log2_DatasetBaseSize; uint32_t Log2_CacheSize; -#endif +# endif }; struct RandomX_ConfigurationMonero : public RandomX_ConfigurationBase {};