From 4b3592f60f30bdbac8d294e4057a2a35145ed803 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 2 Jun 2019 15:03:26 +0700 Subject: [PATCH 01/26] v2.15.5-evo --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index 35831361c..eb204f7df 100644 --- a/src/version.h +++ b/src/version.h @@ -28,7 +28,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "2.15.4-beta" +#define APP_VERSION "2.15.5-evo" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com" @@ -36,7 +36,7 @@ #define APP_VER_MAJOR 2 #define APP_VER_MINOR 15 -#define APP_VER_PATCH 4 +#define APP_VER_PATCH 5 #ifdef _MSC_VER # if (_MSC_VER >= 1920) From fc655d1b8dc41b44066bc72fbd56576460d89967 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 2 Jun 2019 19:43:56 +0700 Subject: [PATCH 02/26] Moved common memory primitives to new VirtualMemory class. --- CMakeLists.txt | 5 +- src/Mem.cpp | 5 +- src/Mem.h | 4 -- src/Mem_unix.cpp | 38 ++--------- src/Mem_win.cpp | 26 ++------ src/crypto/CryptonightR_gen.cpp | 13 ++-- src/crypto/common/VirtualMemory.h | 53 +++++++++++++++ src/crypto/common/VirtualMemory_unix.cpp | 84 ++++++++++++++++++++++++ src/crypto/common/VirtualMemory_win.cpp | 79 ++++++++++++++++++++++ src/workers/CpuThread.cpp | 7 +- 10 files changed, 242 insertions(+), 72 deletions(-) create mode 100644 src/crypto/common/VirtualMemory.h create mode 100644 src/crypto/common/VirtualMemory_unix.cpp create mode 100644 src/crypto/common/VirtualMemory_win.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c7098f373..46ad3bd46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ set(HEADERS src/core/config/ConfigTransform.h src/core/config/usage.h src/core/Controller.h + src/crypto/common/VirtualMemory.h src/interfaces/IJobResultListener.h src/interfaces/IThread.h src/interfaces/IWorker.h @@ -115,6 +116,7 @@ if (WIN32) src/App_win.cpp src/common/Platform_win.cpp src/Mem_win.cpp + src/crypto/common/VirtualMemory_win.cpp ) add_definitions(/DWIN32) @@ -125,13 +127,14 @@ elseif (APPLE) src/App_unix.cpp src/common/Platform_mac.cpp src/Mem_unix.cpp + src/crypto/common/VirtualMemory_unix.cpp ) else() set(SOURCES_OS "${SOURCES_OS}" src/App_unix.cpp src/common/Platform_unix.cpp - src/Mem_unix.cpp + src/crypto/common/VirtualMemory_unix.cpp ) if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD) diff --git a/src/Mem.cpp b/src/Mem.cpp index 01a2157b3..9d52b379a 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -25,8 +25,9 @@ #include "common/utils/mm_malloc.h" -#include "crypto/CryptoNight.h" +#include "crypto/common/VirtualMemory.h" #include "crypto/CryptoNight_constants.h" +#include "crypto/CryptoNight.h" #include "Mem.h" @@ -51,7 +52,7 @@ MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count) cryptonight_ctx *c = static_cast(_mm_malloc(sizeof(cryptonight_ctx), 4096)); c->memory = info.memory + (i * cn_select_memory(algorithm)); - uint8_t* p = reinterpret_cast(allocateExecutableMemory(0x4000)); + uint8_t* p = reinterpret_cast(xmrig::VirtualMemory::allocateExecutableMemory(0x4000)); c->generated_code = reinterpret_cast(p); c->generated_code_double = reinterpret_cast(p + 0x2000); diff --git a/src/Mem.h b/src/Mem.h index 9e39e963c..bfb36b002 100644 --- a/src/Mem.h +++ b/src/Mem.h @@ -60,10 +60,6 @@ public: static void init(bool enabled); static void release(cryptonight_ctx **ctx, size_t count, MemInfo &info); - static void *allocateExecutableMemory(size_t size); - static void protectExecutableMemory(void *p, size_t size); - static void flushInstructionCache(void *p, size_t size); - static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; } private: diff --git a/src/Mem_unix.cpp b/src/Mem_unix.cpp index 3506c2d14..d18b563ec 100644 --- a/src/Mem_unix.cpp +++ b/src/Mem_unix.cpp @@ -31,6 +31,7 @@ #include "base/io/log/Log.h" #include "common/utils/mm_malloc.h" #include "common/xmrig.h" +#include "crypto/common/VirtualMemory.h" #include "crypto/CryptoNight.h" #include "Mem.h" @@ -56,15 +57,8 @@ void Mem::allocate(MemInfo &info, bool enabled) return; } -# if defined(__APPLE__) - info.memory = static_cast(mmap(0, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0)); -# elif defined(__FreeBSD__) - info.memory = static_cast(mmap(0, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0)); -# else - info.memory = static_cast(mmap(0, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0)); -# endif - - if (info.memory == MAP_FAILED) { + info.memory = static_cast(xmrig::VirtualMemory::allocateLargePagesMemory(info.size)); + if (!info.memory) { return allocate(info, false);; } @@ -87,33 +81,9 @@ void Mem::release(MemInfo &info) munlock(info.memory, info.size); } - munmap(info.memory, info.size); + xmrig::VirtualMemory::freeLargePagesMemory(info.memory, info.size); } else { _mm_free(info.memory); } } - - -void *Mem::allocateExecutableMemory(size_t size) -{ -# if defined(__APPLE__) - return mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0); -# else - return mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); -# endif -} - - -void Mem::protectExecutableMemory(void *p, size_t size) -{ - mprotect(p, size, PROT_READ | PROT_EXEC); -} - - -void Mem::flushInstructionCache(void *p, size_t size) -{ -# ifndef __FreeBSD__ - __builtin___clear_cache(reinterpret_cast(p), reinterpret_cast(p) + size); -# endif -} diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index e7afb5d3f..b0af61bb4 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -33,8 +33,9 @@ #include "base/io/log/Log.h" #include "common/utils/mm_malloc.h" #include "common/xmrig.h" -#include "crypto/CryptoNight.h" +#include "crypto/common/VirtualMemory.h" #include "crypto/CryptoNight_constants.h" +#include "crypto/CryptoNight.h" #include "Mem.h" @@ -163,7 +164,7 @@ void Mem::allocate(MemInfo &info, bool enabled) return; } - info.memory = static_cast(VirtualAlloc(nullptr, info.size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE)); + info.memory = static_cast(xmrig::VirtualMemory::allocateLargePagesMemory(info.size)); if (info.memory) { info.hugePages = info.pages; @@ -177,28 +178,9 @@ void Mem::allocate(MemInfo &info, bool enabled) void Mem::release(MemInfo &info) { if (info.hugePages) { - VirtualFree(info.memory, 0, MEM_RELEASE); + xmrig::VirtualMemory::freeLargePagesMemory(info.memory, info.size); } else { _mm_free(info.memory); } } - - -void *Mem::allocateExecutableMemory(size_t size) -{ - return VirtualAlloc(nullptr, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); -} - - -void Mem::protectExecutableMemory(void *p, size_t size) -{ - DWORD oldProtect; - VirtualProtect(p, size, PAGE_EXECUTE_READ, &oldProtect); -} - - -void Mem::flushInstructionCache(void *p, size_t size) -{ - ::FlushInstructionCache(GetCurrentProcess(), p, size); -} diff --git a/src/crypto/CryptonightR_gen.cpp b/src/crypto/CryptonightR_gen.cpp index 3fba49cd9..5352cf0a3 100644 --- a/src/crypto/CryptonightR_gen.cpp +++ b/src/crypto/CryptonightR_gen.cpp @@ -29,6 +29,7 @@ typedef void(*void_func)(); #include "crypto/asm/CryptonightR_template.h" +#include "crypto/common/VirtualMemory.h" #include "Mem.h" @@ -109,7 +110,7 @@ void wow_compile_code(const V4_Instruction* code, int code_size, void* machine_c *(int*)(p - 4) = static_cast((((const uint8_t*)CryptonightWOW_template_mainloop) - ((const uint8_t*)CryptonightWOW_template_part1)) - (p - p0)); add_code(p, CryptonightWOW_template_part3, CryptonightWOW_template_end); - Mem::flushInstructionCache(machine_code, p - p0); + xmrig::VirtualMemory::flushInstructionCache(machine_code, p - p0); } void v4_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) @@ -123,7 +124,7 @@ void v4_compile_code(const V4_Instruction* code, int code_size, void* machine_co *(int*)(p - 4) = static_cast((((const uint8_t*)CryptonightR_template_mainloop) - ((const uint8_t*)CryptonightR_template_part1)) - (p - p0)); add_code(p, CryptonightR_template_part3, CryptonightR_template_end); - Mem::flushInstructionCache(machine_code, p - p0); + xmrig::VirtualMemory::flushInstructionCache(machine_code, p - p0); } void wow_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) @@ -139,7 +140,7 @@ void wow_compile_code_double(const V4_Instruction* code, int code_size, void* ma *(int*)(p - 4) = static_cast((((const uint8_t*)CryptonightWOW_template_double_mainloop) - ((const uint8_t*)CryptonightWOW_template_double_part1)) - (p - p0)); add_code(p, CryptonightWOW_template_double_part4, CryptonightWOW_template_double_end); - Mem::flushInstructionCache(machine_code, p - p0); + xmrig::VirtualMemory::flushInstructionCache(machine_code, p - p0); } void v4_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) @@ -155,7 +156,7 @@ void v4_compile_code_double(const V4_Instruction* code, int code_size, void* mac *(int*)(p - 4) = static_cast((((const uint8_t*)CryptonightR_template_double_mainloop) - ((const uint8_t*)CryptonightR_template_double_part1)) - (p - p0)); add_code(p, CryptonightR_template_double_part4, CryptonightR_template_double_end); - Mem::flushInstructionCache(machine_code, p - p0); + xmrig::VirtualMemory::flushInstructionCache(machine_code, p - p0); } void wow_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) @@ -169,7 +170,7 @@ void wow_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* *(int*)(p - 4) = static_cast((((const uint8_t*)CryptonightWOW_soft_aes_template_mainloop) - ((const uint8_t*)CryptonightWOW_soft_aes_template_part1)) - (p - p0)); add_code(p, CryptonightWOW_soft_aes_template_part3, CryptonightWOW_soft_aes_template_end); - Mem::flushInstructionCache(machine_code, p - p0); + xmrig::VirtualMemory::flushInstructionCache(machine_code, p - p0); } void v4_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) @@ -183,5 +184,5 @@ void v4_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* m *(int*)(p - 4) = static_cast((((const uint8_t*)CryptonightR_soft_aes_template_mainloop) - ((const uint8_t*)CryptonightR_soft_aes_template_part1)) - (p - p0)); add_code(p, CryptonightR_soft_aes_template_part3, CryptonightR_soft_aes_template_end); - Mem::flushInstructionCache(machine_code, p - p0); + xmrig::VirtualMemory::flushInstructionCache(machine_code, p - p0); } diff --git a/src/crypto/common/VirtualMemory.h b/src/crypto/common/VirtualMemory.h new file mode 100644 index 000000000..262b732a6 --- /dev/null +++ b/src/crypto/common/VirtualMemory.h @@ -0,0 +1,53 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2018-2019 SChernykh + * Copyright 2018-2019 tevador + * Copyright 2016-2019 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_VIRTUALMEMORY_H +#define XMRIG_VIRTUALMEMORY_H + + +#include +#include + + +namespace xmrig { + + +class VirtualMemory +{ +public: + static void *allocateExecutableMemory(size_t size); + static void *allocateLargePagesMemory(size_t size); + static void flushInstructionCache(void *p, size_t size); + static void freeLargePagesMemory(void *p, size_t size); + static void protectExecutableMemory(void *p, size_t size); +}; + + +} /* namespace xmrig */ + + + +#endif /* XMRIG_VIRTUALMEMORY_H */ diff --git a/src/crypto/common/VirtualMemory_unix.cpp b/src/crypto/common/VirtualMemory_unix.cpp new file mode 100644 index 000000000..b40a9c7bf --- /dev/null +++ b/src/crypto/common/VirtualMemory_unix.cpp @@ -0,0 +1,84 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2018-2019 SChernykh + * Copyright 2018-2019 tevador + * Copyright 2016-2019 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include +#include + + +#include "crypto/common/VirtualMemory.h" + + +#if defined(__APPLE__) +# include +#endif + + + +void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size) +{ +# if defined(__APPLE__) + void *mem = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0); +# else + void *mem = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +# endif + + return mem == MAP_FAILED ? nullptr : mem; +} + + +void *xmrig::VirtualMemory::allocateLargePagesMemory(size_t size) +{ +# if defined(__APPLE__) + void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0); +# elif defined(__FreeBSD__) + void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0); +# else + void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0); +# endif + + return mem == MAP_FAILED ? nullptr : mem; +} + + +void xmrig::VirtualMemory::flushInstructionCache(void *p, size_t size) +{ +# ifndef __FreeBSD__ + __builtin___clear_cache(reinterpret_cast(p), reinterpret_cast(p) + size); +# endif +} + + +void xmrig::VirtualMemory::freeLargePagesMemory(void *p, size_t size) +{ + munmap(memory, size); +} + + +void xmrig::VirtualMemory::protectExecutableMemory(void *p, size_t size) +{ + mprotect(p, size, PROT_READ | PROT_EXEC); +} diff --git a/src/crypto/common/VirtualMemory_win.cpp b/src/crypto/common/VirtualMemory_win.cpp new file mode 100644 index 000000000..43b02f38c --- /dev/null +++ b/src/crypto/common/VirtualMemory_win.cpp @@ -0,0 +1,79 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2018-2019 SChernykh + * Copyright 2018-2019 tevador + * Copyright 2016-2019 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include +#include + + +#include "crypto/common/VirtualMemory.h" + + +namespace xmrig { + +constexpr size_t align(size_t pos, size_t align) { + return ((pos - 1) / align + 1) * align; +} + +} + + +void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size) +{ + return VirtualAlloc(nullptr, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); +} + + +void *xmrig::VirtualMemory::allocateLargePagesMemory(size_t size) +{ + const size_t min = GetLargePageMinimum(); + void *mem = nullptr; + + if (min > 0) { + mem = VirtualAlloc(nullptr, align(size, min), MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE); + } + + return mem; +} + + +void xmrig::VirtualMemory::flushInstructionCache(void *p, size_t size) +{ + ::FlushInstructionCache(GetCurrentProcess(), p, size); +} + + +void xmrig::VirtualMemory::freeLargePagesMemory(void *p, size_t) +{ + VirtualFree(p, 0, MEM_RELEASE); +} + + +void xmrig::VirtualMemory::protectExecutableMemory(void *p, size_t size) +{ + DWORD oldProtect; + VirtualProtect(p, size, PAGE_EXECUTE_READ, &oldProtect); +} diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 2481162ce..fbdd8b646 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -28,6 +28,7 @@ #include "base/io/log/Log.h" #include "common/cpu/Cpu.h" #include "crypto/Asm.h" +#include "crypto/common/VirtualMemory.h" #include "Mem.h" #include "rapidjson/document.h" #include "workers/CpuThread.h" @@ -120,7 +121,7 @@ xmrig::CpuThread::cn_mainloop_fun cn_double_double_mainloop_sandybridge_a void xmrig::CpuThread::patchAsmVariants() { const int allocation_size = 65536; - uint8_t *base = static_cast(Mem::allocateExecutableMemory(allocation_size)); + uint8_t *base = static_cast(VirtualMemory::allocateExecutableMemory(allocation_size)); cn_half_mainloop_ivybridge_asm = reinterpret_cast (base + 0x0000); cn_half_mainloop_ryzen_asm = reinterpret_cast (base + 0x1000); @@ -162,8 +163,8 @@ void xmrig::CpuThread::patchAsmVariants() patchCode(cn_double_mainloop_bulldozer_asm, cnv2_mainloop_bulldozer_asm, xmrig::CRYPTONIGHT_DOUBLE_ITER, xmrig::CRYPTONIGHT_MASK); patchCode(cn_double_double_mainloop_sandybridge_asm, cnv2_double_mainloop_sandybridge_asm, xmrig::CRYPTONIGHT_DOUBLE_ITER, xmrig::CRYPTONIGHT_MASK); - Mem::protectExecutableMemory(base, allocation_size); - Mem::flushInstructionCache(base, allocation_size); + VirtualMemory::protectExecutableMemory(base, allocation_size); + VirtualMemory::flushInstructionCache(base, allocation_size); } #endif From 8dc586283fd482ca1bd1a4c98030e0c412bff6c5 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 2 Jun 2019 19:58:16 +0700 Subject: [PATCH 03/26] Fixed Linux build. --- CMakeLists.txt | 1 + src/crypto/common/VirtualMemory_unix.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46ad3bd46..282faa874 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,6 +134,7 @@ else() "${SOURCES_OS}" src/App_unix.cpp src/common/Platform_unix.cpp + src/Mem_unix.cpp src/crypto/common/VirtualMemory_unix.cpp ) diff --git a/src/crypto/common/VirtualMemory_unix.cpp b/src/crypto/common/VirtualMemory_unix.cpp index b40a9c7bf..9ae2bdf3c 100644 --- a/src/crypto/common/VirtualMemory_unix.cpp +++ b/src/crypto/common/VirtualMemory_unix.cpp @@ -74,7 +74,7 @@ void xmrig::VirtualMemory::flushInstructionCache(void *p, size_t size) void xmrig::VirtualMemory::freeLargePagesMemory(void *p, size_t size) { - munmap(memory, size); + munmap(p, size); } From ba94c08bf57ea752672fa7d909ac20f6d293ec77 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 2 Jun 2019 20:57:49 +0700 Subject: [PATCH 04/26] Moved mm_malloc.h --- CMakeLists.txt | 8 +-- src/Mem.cpp | 2 +- src/Mem_unix.cpp | 2 +- src/Mem_win.cpp | 2 +- src/common/utils/mm_malloc.h | 43 ---------------- .../common/portable/mm_malloc.h} | 50 +++++++++++-------- 6 files changed, 35 insertions(+), 72 deletions(-) delete mode 100644 src/common/utils/mm_malloc.h rename src/{3rdparty/aligned_malloc.h => crypto/common/portable/mm_malloc.h} (57%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 282faa874..983eed865 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,6 @@ set(HEADERS src/common/crypto/keccak.h src/common/interfaces/ICpuInfo.h src/common/Platform.h - src/common/utils/mm_malloc.h src/common/xmrig.h src/core/config/Config_default.h src/core/config/Config_platform.h @@ -37,7 +36,6 @@ set(HEADERS src/core/config/ConfigTransform.h src/core/config/usage.h src/core/Controller.h - src/crypto/common/VirtualMemory.h src/interfaces/IJobResultListener.h src/interfaces/IThread.h src/interfaces/IWorker.h @@ -57,19 +55,21 @@ set(HEADERS ) set(HEADERS_CRYPTO + src/crypto/asm/CryptonightR_template.h src/crypto/c_blake256.h src/crypto/c_groestl.h src/crypto/c_jh.h src/crypto/c_skein.h - src/crypto/CryptoNight.h + src/crypto/common/portable/mm_malloc.h + src/crypto/common/VirtualMemory.h src/crypto/CryptoNight_constants.h src/crypto/CryptoNight_monero.h src/crypto/CryptoNight_test.h + src/crypto/CryptoNight.h src/crypto/groestl_tables.h src/crypto/hash.h src/crypto/skein_port.h src/crypto/soft_aes.h - src/crypto/asm/CryptonightR_template.h ) if (XMRIG_ARM) diff --git a/src/Mem.cpp b/src/Mem.cpp index 9d52b379a..714e35a1d 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -24,7 +24,7 @@ */ -#include "common/utils/mm_malloc.h" +#include "crypto/common/portable/mm_malloc.h" #include "crypto/common/VirtualMemory.h" #include "crypto/CryptoNight_constants.h" #include "crypto/CryptoNight.h" diff --git a/src/Mem_unix.cpp b/src/Mem_unix.cpp index d18b563ec..d9c3e31f3 100644 --- a/src/Mem_unix.cpp +++ b/src/Mem_unix.cpp @@ -29,8 +29,8 @@ #include "base/io/log/Log.h" -#include "common/utils/mm_malloc.h" #include "common/xmrig.h" +#include "crypto/common/portable/mm_malloc.h" #include "crypto/common/VirtualMemory.h" #include "crypto/CryptoNight.h" #include "Mem.h" diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index b0af61bb4..3e8b6ee78 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -31,8 +31,8 @@ #include "base/io/log/Log.h" -#include "common/utils/mm_malloc.h" #include "common/xmrig.h" +#include "crypto/common/portable/mm_malloc.h" #include "crypto/common/VirtualMemory.h" #include "crypto/CryptoNight_constants.h" #include "crypto/CryptoNight.h" diff --git a/src/common/utils/mm_malloc.h b/src/common/utils/mm_malloc.h deleted file mode 100644 index 30c721a34..000000000 --- a/src/common/utils/mm_malloc.h +++ /dev/null @@ -1,43 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __MM_MALLOC_PORTABLE_H__ -#define __MM_MALLOC_PORTABLE_H__ - - -#ifdef _WIN32 -# ifdef __GNUC__ -# include -# else -# include -# endif -#else -# if defined(XMRIG_ARM) && !defined(__clang__) -# include "aligned_malloc.h" -# else -# include -# endif -#endif - - -#endif /* __MM_MALLOC_PORTABLE_H__ */ diff --git a/src/3rdparty/aligned_malloc.h b/src/crypto/common/portable/mm_malloc.h similarity index 57% rename from src/3rdparty/aligned_malloc.h rename to src/crypto/common/portable/mm_malloc.h index 0b74b17e0..34ca7d48b 100644 --- a/src/3rdparty/aligned_malloc.h +++ b/src/crypto/common/portable/mm_malloc.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -21,45 +22,50 @@ * along with this program. If not, see . */ -#ifndef __ALIGNED_MALLOC_H__ -#define __ALIGNED_MALLOC_H__ +#ifndef XMRIG_MM_MALLOC_PORTABLE_H +#define XMRIG_MM_MALLOC_PORTABLE_H +#if defined(XMRIG_ARM) && !defined(__clang__) #include #ifndef __cplusplus -extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size); +extern #else -// Some systems (e.g. those with GNU libc) declare posix_memalign with an -// exception specifier. Via an "egregious workaround" in -// Sema::CheckEquivalentExceptionSpec, Clang accepts the following as a valid -// redeclaration of glibc's declaration. -extern "C" int posix_memalign(void **__memptr, size_t __alignment, size_t __size); +extern "C" #endif +int posix_memalign(void **__memptr, size_t __alignment, size_t __size); static __inline__ void *__attribute__((__always_inline__, __malloc__)) _mm_malloc(size_t __size, size_t __align) { - if (__align == 1) { - return malloc(__size); - } + if (__align == 1) { + return malloc(__size); + } - if (!(__align & (__align - 1)) && __align < sizeof(void *)) - __align = sizeof(void *); + if (!(__align & (__align - 1)) && __align < sizeof(void *)) { + __align = sizeof(void *); + } - void *__mallocedMemory; - if (posix_memalign(&__mallocedMemory, __align, __size)) { - return 0; - } + void *__mallocedMemory; + if (posix_memalign(&__mallocedMemory, __align, __size)) { + return nullptr; + } - return __mallocedMemory; + return __mallocedMemory; } static __inline__ void __attribute__((__always_inline__)) _mm_free(void *__p) { - free(__p); + free(__p); } +#elif defined(_WIN32) && !defined(__GNUC__) +# include +#else +# include +#endif -#endif /* __ALIGNED_MALLOC_H__ */ + +#endif /* XMRIG_MM_MALLOC_PORTABLE_H */ From 36fcdf3f9d0d368f8da1dab5de201af397cbe29f Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 2 Jun 2019 21:06:30 +0700 Subject: [PATCH 05/26] Fixed ARM build. --- src/crypto/CryptoNight_arm.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index d762929c2..7be8c53ff 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -29,10 +29,10 @@ #include "common/crypto/keccak.h" -#include "common/utils/mm_malloc.h" -#include "crypto/CryptoNight.h" +#include "crypto/common/portable/mm_malloc.h" #include "crypto/CryptoNight_constants.h" #include "crypto/CryptoNight_monero.h" +#include "crypto/CryptoNight.h" #include "crypto/soft_aes.h" From 242ece722230a9800b11172307056a11741c0e39 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 2 Jun 2019 23:38:02 +0700 Subject: [PATCH 06/26] Simplified cn/r code. --- src/Mem.cpp | 11 +++++------ src/crypto/CryptoNight.h | 12 +++++++----- src/crypto/CryptoNight_x86.h | 10 +++++----- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Mem.cpp b/src/Mem.cpp index 714e35a1d..2c78e10dc 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -24,6 +24,9 @@ */ +#include + + #include "crypto/common/portable/mm_malloc.h" #include "crypto/common/VirtualMemory.h" #include "crypto/CryptoNight_constants.h" @@ -52,13 +55,9 @@ MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count) cryptonight_ctx *c = static_cast(_mm_malloc(sizeof(cryptonight_ctx), 4096)); c->memory = info.memory + (i * cn_select_memory(algorithm)); - uint8_t* p = reinterpret_cast(xmrig::VirtualMemory::allocateExecutableMemory(0x4000)); - c->generated_code = reinterpret_cast(p); - c->generated_code_double = reinterpret_cast(p + 0x2000); - + c->generated_code = reinterpret_cast(xmrig::VirtualMemory::allocateExecutableMemory(0x4000)); c->generated_code_data.variant = xmrig::VARIANT_MAX; - c->generated_code_data.height = (uint64_t)(-1); - c->generated_code_double_data = c->generated_code_data; + c->generated_code_data.height = std::numeric_limits::max(); ctx[i] = c; } diff --git a/src/crypto/CryptoNight.h b/src/crypto/CryptoNight.h index b1ec2371d..f50966ed2 100644 --- a/src/crypto/CryptoNight.h +++ b/src/crypto/CryptoNight.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett + * Copyright 2018-2019 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -30,14 +31,16 @@ #include #if defined _MSC_VER || defined XMRIG_ARM -#define ABI_ATTRIBUTE +# define ABI_ATTRIBUTE #else -#define ABI_ATTRIBUTE __attribute__((ms_abi)) +# define ABI_ATTRIBUTE __attribute__((ms_abi)) #endif + struct cryptonight_ctx; typedef void(*cn_mainloop_fun_ms_abi)(cryptonight_ctx**) ABI_ATTRIBUTE; + struct cryptonight_r_data { int variant; uint64_t height; @@ -45,17 +48,16 @@ struct cryptonight_r_data { bool match(const int v, const uint64_t h) const { return (v == variant) && (h == height); } }; + struct cryptonight_ctx { alignas(16) uint8_t state[224]; alignas(16) uint8_t *memory; uint8_t unused[40]; - const uint32_t* saes_table; + const uint32_t *saes_table; cn_mainloop_fun_ms_abi generated_code; - cn_mainloop_fun_ms_abi generated_code_double; cryptonight_r_data generated_code_data; - cryptonight_r_data generated_code_double_data; }; diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 202b662a2..390f203b1 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -895,12 +895,12 @@ inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_ { constexpr size_t MEM = xmrig::cn_select_memory(); - if (xmrig::cn_is_cryptonight_r() && !ctx[0]->generated_code_double_data.match(VARIANT, height)) { + if (xmrig::cn_is_cryptonight_r() && !ctx[0]->generated_code_data.match(VARIANT, height)) { V4_Instruction code[256]; const int code_size = v4_random_math_init(code, height); - cn_r_compile_code_double(code, code_size, reinterpret_cast(ctx[0]->generated_code_double), ASM); - ctx[0]->generated_code_double_data.variant = VARIANT; - ctx[0]->generated_code_double_data.height = height; + cn_r_compile_code_double(code, code_size, reinterpret_cast(ctx[0]->generated_code), ASM); + ctx[0]->generated_code_data.variant = VARIANT; + ctx[0]->generated_code_data.height = height; } xmrig::keccak(input, size, ctx[0]->state); @@ -928,7 +928,7 @@ inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_ cn_double_double_mainloop_sandybridge_asm(ctx); } else if (xmrig::cn_is_cryptonight_r()) { - ctx[0]->generated_code_double(ctx); + ctx[0]->generated_code(ctx); } cn_implode_scratchpad(reinterpret_cast<__m128i*>(ctx[0]->memory), reinterpret_cast<__m128i*>(ctx[0]->state)); From f620ffe8990dd94bc063778f59f101488153fb99 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 3 Jun 2019 18:40:12 +0700 Subject: [PATCH 07/26] #1026 Probably fixed iOS build. --- cmake/flags.cmake | 7 +++++++ src/common/cpu/BasicCpuInfo_arm.cpp | 7 ++++++- src/crypto/common/VirtualMemory_unix.cpp | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cmake/flags.cmake b/cmake/flags.cmake index d50b5c84b..d00366282 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -81,3 +81,10 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) endif() endif() + +if (NOT WIN32) + check_symbol_exists("__builtin___clear_cache" "stdlib.h" HAVE_BUILTIN_CLEAR_CACHE) + if (HAVE_BUILTIN_CLEAR_CACHE) + add_definitions(/DHAVE_BUILTIN_CLEAR_CACHE) + endif() +endif() diff --git a/src/common/cpu/BasicCpuInfo_arm.cpp b/src/common/cpu/BasicCpuInfo_arm.cpp index 339613466..dea8de734 100644 --- a/src/common/cpu/BasicCpuInfo_arm.cpp +++ b/src/common/cpu/BasicCpuInfo_arm.cpp @@ -25,7 +25,8 @@ #include #include -#if __ARM_FEATURE_CRYPTO + +#if __ARM_FEATURE_CRYPTO && !defined(__APPLE__) # include # include #endif @@ -47,7 +48,11 @@ xmrig::BasicCpuInfo::BasicCpuInfo() : # endif # if __ARM_FEATURE_CRYPTO +# if !defined(__APPLE__) m_aes = getauxval(AT_HWCAP) & HWCAP_AES; +# else + m_aes = true; +# endif # endif } diff --git a/src/crypto/common/VirtualMemory_unix.cpp b/src/crypto/common/VirtualMemory_unix.cpp index 9ae2bdf3c..0297520a1 100644 --- a/src/crypto/common/VirtualMemory_unix.cpp +++ b/src/crypto/common/VirtualMemory_unix.cpp @@ -66,7 +66,7 @@ void *xmrig::VirtualMemory::allocateLargePagesMemory(size_t size) void xmrig::VirtualMemory::flushInstructionCache(void *p, size_t size) { -# ifndef __FreeBSD__ +# ifdef HAVE_BUILTIN_CLEAR_CACHE __builtin___clear_cache(reinterpret_cast(p), reinterpret_cast(p) + size); # endif } From ac43cd4f9cfb4f1c50d696f31979e6444140bb7d Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 4 Jun 2019 15:48:32 +0700 Subject: [PATCH 08/26] Added unprotectExecutableMemory for future use. --- src/crypto/common/VirtualMemory.h | 1 + src/crypto/common/VirtualMemory_unix.cpp | 6 ++++++ src/crypto/common/VirtualMemory_win.cpp | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/src/crypto/common/VirtualMemory.h b/src/crypto/common/VirtualMemory.h index 262b732a6..e8acb017e 100644 --- a/src/crypto/common/VirtualMemory.h +++ b/src/crypto/common/VirtualMemory.h @@ -43,6 +43,7 @@ public: static void flushInstructionCache(void *p, size_t size); static void freeLargePagesMemory(void *p, size_t size); static void protectExecutableMemory(void *p, size_t size); + static void unprotectExecutableMemory(void *p, size_t size); }; diff --git a/src/crypto/common/VirtualMemory_unix.cpp b/src/crypto/common/VirtualMemory_unix.cpp index 0297520a1..beac976d0 100644 --- a/src/crypto/common/VirtualMemory_unix.cpp +++ b/src/crypto/common/VirtualMemory_unix.cpp @@ -82,3 +82,9 @@ void xmrig::VirtualMemory::protectExecutableMemory(void *p, size_t size) { mprotect(p, size, PROT_READ | PROT_EXEC); } + + +void xmrig::VirtualMemory::unprotectExecutableMemory(void *p, size_t size) +{ + mprotect(p, size, PROT_WRITE | PROT_EXEC); +} diff --git a/src/crypto/common/VirtualMemory_win.cpp b/src/crypto/common/VirtualMemory_win.cpp index 43b02f38c..dd6be14f4 100644 --- a/src/crypto/common/VirtualMemory_win.cpp +++ b/src/crypto/common/VirtualMemory_win.cpp @@ -77,3 +77,10 @@ void xmrig::VirtualMemory::protectExecutableMemory(void *p, size_t size) DWORD oldProtect; VirtualProtect(p, size, PAGE_EXECUTE_READ, &oldProtect); } + + +void xmrig::VirtualMemory::unprotectExecutableMemory(void *p, size_t size) +{ + DWORD oldProtect; + VirtualProtect(p, size, PAGE_EXECUTE_READWRITE, &oldProtect); +} From d587eebaf28c3f9085ae49ca3e4602137ec5f6ef Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 4 Jun 2019 19:20:33 +0700 Subject: [PATCH 09/26] Move files. --- CMakeLists.txt | 38 +++++++++---------- cmake/asm.cmake | 18 ++++----- cmake/cn-gpu.cmake | 10 ++--- src/App.cpp | 1 - src/Mem.cpp | 4 +- src/Mem_unix.cpp | 2 +- src/Mem_win.cpp | 4 +- src/Summary.cpp | 2 +- src/core/config/Config.cpp | 4 +- src/crypto/{ => cn}/Asm.cpp | 2 +- src/crypto/{ => cn}/Asm.h | 0 src/crypto/{ => cn}/CryptoNight.h | 0 src/crypto/{ => cn}/CryptoNight_arm.h | 16 ++++---- src/crypto/{ => cn}/CryptoNight_constants.h | 0 src/crypto/{ => cn}/CryptoNight_monero.h | 2 +- src/crypto/{ => cn}/CryptoNight_test.h | 0 src/crypto/{ => cn}/CryptoNight_x86.h | 16 ++++---- src/crypto/{ => cn}/SSE2NEON.h | 0 .../asm/CryptonightR_soft_aes_template.inc | 0 .../CryptonightR_soft_aes_template_win.inc | 0 .../{ => cn}/asm/CryptonightR_template.S | 0 .../{ => cn}/asm/CryptonightR_template.asm | 0 .../{ => cn}/asm/CryptonightR_template.h | 0 .../{ => cn}/asm/CryptonightR_template.inc | 0 .../asm/CryptonightR_template_win.inc | 0 .../asm/CryptonightWOW_soft_aes_template.inc | 0 .../CryptonightWOW_soft_aes_template_win.inc | 0 .../{ => cn}/asm/CryptonightWOW_template.inc | 0 .../asm/CryptonightWOW_template_win.inc | 0 .../cn2/cnv2_double_main_loop_sandybridge.inc | 0 .../asm/cn2/cnv2_main_loop_bulldozer.inc | 0 .../asm/cn2/cnv2_main_loop_ivybridge.inc | 0 .../{ => cn}/asm/cn2/cnv2_main_loop_ryzen.inc | 0 .../asm/cn2/cnv2_rwz_double_main_loop.inc | 0 .../{ => cn}/asm/cn2/cnv2_rwz_main_loop.inc | 0 src/crypto/{ => cn}/asm/cn_main_loop.S | 0 src/crypto/{ => cn}/asm/cn_main_loop.asm | 0 .../CryptonightR_soft_aes_template_win.inc | 0 .../asm/win64/CryptonightR_template.asm | 0 .../asm/win64/CryptonightR_template_win.inc | 0 .../CryptonightWOW_soft_aes_template_win.inc | 0 .../asm/win64/CryptonightWOW_template_win.inc | 0 .../cn2/cnv2_double_main_loop_sandybridge.inc | 0 .../win64/cn2/cnv2_main_loop_bulldozer.inc | 0 .../win64/cn2/cnv2_main_loop_ivybridge.inc | 0 .../asm/win64/cn2/cnv2_main_loop_ryzen.inc | 0 .../win64/cn2/cnv2_rwz_double_main_loop.inc | 0 .../asm/win64/cn2/cnv2_rwz_main_loop.inc | 0 src/crypto/{ => cn}/asm/win64/cn_main_loop.S | 0 .../{ => cn}/asm/win64/cn_main_loop.asm | 0 src/crypto/{ => cn}/c_blake256.c | 0 src/crypto/{ => cn}/c_blake256.h | 0 src/crypto/{ => cn}/c_groestl.c | 0 src/crypto/{ => cn}/c_groestl.h | 0 src/crypto/{ => cn}/c_jh.c | 0 src/crypto/{ => cn}/c_jh.h | 0 src/crypto/{ => cn}/c_skein.c | 0 src/crypto/{ => cn}/c_skein.h | 0 src/crypto/{ => cn/gpu}/cn_gpu_arm.cpp | 0 src/crypto/{ => cn/gpu}/cn_gpu_avx.cpp | 2 +- src/crypto/{ => cn/gpu}/cn_gpu_ssse3.cpp | 2 +- src/crypto/{ => cn}/groestl_tables.h | 0 src/crypto/{ => cn}/hash.h | 0 src/crypto/{ => cn/r}/CryptonightR_gen.cpp | 4 +- src/crypto/{ => cn/r}/variant4_random_math.h | 2 +- src/crypto/{ => cn}/skein_port.h | 0 src/crypto/{ => cn}/soft_aes.h | 0 src/workers/CpuThread.cpp | 6 +-- src/workers/MultiWorker.cpp | 2 +- src/workers/Workers.cpp | 2 +- 70 files changed, 69 insertions(+), 70 deletions(-) rename src/crypto/{ => cn}/Asm.cpp (98%) rename src/crypto/{ => cn}/Asm.h (100%) rename src/crypto/{ => cn}/CryptoNight.h (100%) rename src/crypto/{ => cn}/CryptoNight_arm.h (99%) rename src/crypto/{ => cn}/CryptoNight_constants.h (100%) rename src/crypto/{ => cn}/CryptoNight_monero.h (99%) rename src/crypto/{ => cn}/CryptoNight_test.h (100%) rename src/crypto/{ => cn}/CryptoNight_x86.h (99%) rename src/crypto/{ => cn}/SSE2NEON.h (100%) rename src/crypto/{ => cn}/asm/CryptonightR_soft_aes_template.inc (100%) rename src/crypto/{ => cn}/asm/CryptonightR_soft_aes_template_win.inc (100%) rename src/crypto/{ => cn}/asm/CryptonightR_template.S (100%) rename src/crypto/{ => cn}/asm/CryptonightR_template.asm (100%) rename src/crypto/{ => cn}/asm/CryptonightR_template.h (100%) rename src/crypto/{ => cn}/asm/CryptonightR_template.inc (100%) rename src/crypto/{ => cn}/asm/CryptonightR_template_win.inc (100%) rename src/crypto/{ => cn}/asm/CryptonightWOW_soft_aes_template.inc (100%) rename src/crypto/{ => cn}/asm/CryptonightWOW_soft_aes_template_win.inc (100%) rename src/crypto/{ => cn}/asm/CryptonightWOW_template.inc (100%) rename src/crypto/{ => cn}/asm/CryptonightWOW_template_win.inc (100%) rename src/crypto/{ => cn}/asm/cn2/cnv2_double_main_loop_sandybridge.inc (100%) rename src/crypto/{ => cn}/asm/cn2/cnv2_main_loop_bulldozer.inc (100%) rename src/crypto/{ => cn}/asm/cn2/cnv2_main_loop_ivybridge.inc (100%) rename src/crypto/{ => cn}/asm/cn2/cnv2_main_loop_ryzen.inc (100%) rename src/crypto/{ => cn}/asm/cn2/cnv2_rwz_double_main_loop.inc (100%) rename src/crypto/{ => cn}/asm/cn2/cnv2_rwz_main_loop.inc (100%) rename src/crypto/{ => cn}/asm/cn_main_loop.S (100%) rename src/crypto/{ => cn}/asm/cn_main_loop.asm (100%) rename src/crypto/{ => cn}/asm/win64/CryptonightR_soft_aes_template_win.inc (100%) rename src/crypto/{ => cn}/asm/win64/CryptonightR_template.asm (100%) rename src/crypto/{ => cn}/asm/win64/CryptonightR_template_win.inc (100%) rename src/crypto/{ => cn}/asm/win64/CryptonightWOW_soft_aes_template_win.inc (100%) rename src/crypto/{ => cn}/asm/win64/CryptonightWOW_template_win.inc (100%) rename src/crypto/{ => cn}/asm/win64/cn2/cnv2_double_main_loop_sandybridge.inc (100%) rename src/crypto/{ => cn}/asm/win64/cn2/cnv2_main_loop_bulldozer.inc (100%) rename src/crypto/{ => cn}/asm/win64/cn2/cnv2_main_loop_ivybridge.inc (100%) rename src/crypto/{ => cn}/asm/win64/cn2/cnv2_main_loop_ryzen.inc (100%) rename src/crypto/{ => cn}/asm/win64/cn2/cnv2_rwz_double_main_loop.inc (100%) rename src/crypto/{ => cn}/asm/win64/cn2/cnv2_rwz_main_loop.inc (100%) rename src/crypto/{ => cn}/asm/win64/cn_main_loop.S (100%) rename src/crypto/{ => cn}/asm/win64/cn_main_loop.asm (100%) rename src/crypto/{ => cn}/c_blake256.c (100%) rename src/crypto/{ => cn}/c_blake256.h (100%) rename src/crypto/{ => cn}/c_groestl.c (100%) rename src/crypto/{ => cn}/c_groestl.h (100%) rename src/crypto/{ => cn}/c_jh.c (100%) rename src/crypto/{ => cn}/c_jh.h (100%) rename src/crypto/{ => cn}/c_skein.c (100%) rename src/crypto/{ => cn}/c_skein.h (100%) rename src/crypto/{ => cn/gpu}/cn_gpu_arm.cpp (100%) rename src/crypto/{ => cn/gpu}/cn_gpu_avx.cpp (99%) rename src/crypto/{ => cn/gpu}/cn_gpu_ssse3.cpp (99%) rename src/crypto/{ => cn}/groestl_tables.h (100%) rename src/crypto/{ => cn}/hash.h (100%) rename src/crypto/{ => cn/r}/CryptonightR_gen.cpp (98%) rename src/crypto/{ => cn/r}/variant4_random_math.h (99%) rename src/crypto/{ => cn}/skein_port.h (100%) rename src/crypto/{ => cn}/soft_aes.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 983eed865..3a764b224 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,27 +55,27 @@ set(HEADERS ) set(HEADERS_CRYPTO - src/crypto/asm/CryptonightR_template.h - src/crypto/c_blake256.h - src/crypto/c_groestl.h - src/crypto/c_jh.h - src/crypto/c_skein.h + src/crypto/cn/asm/CryptonightR_template.h + src/crypto/cn/c_blake256.h + src/crypto/cn/c_groestl.h + src/crypto/cn/c_jh.h + src/crypto/cn/c_skein.h + src/crypto/cn/CryptoNight_constants.h + src/crypto/cn/CryptoNight_monero.h + src/crypto/cn/CryptoNight_test.h + src/crypto/cn/CryptoNight.h + src/crypto/cn/groestl_tables.h + src/crypto/cn/hash.h + src/crypto/cn/skein_port.h + src/crypto/cn/soft_aes.h src/crypto/common/portable/mm_malloc.h src/crypto/common/VirtualMemory.h - src/crypto/CryptoNight_constants.h - src/crypto/CryptoNight_monero.h - src/crypto/CryptoNight_test.h - src/crypto/CryptoNight.h - src/crypto/groestl_tables.h - src/crypto/hash.h - src/crypto/skein_port.h - src/crypto/soft_aes.h ) if (XMRIG_ARM) - set(HEADERS_CRYPTO "${HEADERS_CRYPTO}" src/crypto/CryptoNight_arm.h) + set(HEADERS_CRYPTO "${HEADERS_CRYPTO}" src/crypto/cn/CryptoNight_arm.h) else() - set(HEADERS_CRYPTO "${HEADERS_CRYPTO}" src/crypto/CryptoNight_x86.h) + set(HEADERS_CRYPTO "${HEADERS_CRYPTO}" src/crypto/cn/CryptoNight_x86.h) endif() set(SOURCES @@ -103,10 +103,10 @@ set(SOURCES ) set(SOURCES_CRYPTO - src/crypto/c_groestl.c - src/crypto/c_blake256.c - src/crypto/c_jh.c - src/crypto/c_skein.c + src/crypto/cn/c_groestl.c + src/crypto/cn/c_blake256.c + src/crypto/cn/c_jh.c + src/crypto/cn/c_skein.c ) if (WIN32) diff --git a/cmake/asm.cmake b/cmake/asm.cmake index 389f67231..25ccceadf 100644 --- a/cmake/asm.cmake +++ b/cmake/asm.cmake @@ -6,13 +6,13 @@ if (WITH_ASM AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8) if (MSVC_TOOLSET_VERSION GREATER_EQUAL 141) set(XMRIG_ASM_FILES - "src/crypto/asm/cn_main_loop.asm" - "src/crypto/asm/CryptonightR_template.asm" + "src/crypto/cn/asm/cn_main_loop.asm" + "src/crypto/cn/asm/CryptonightR_template.asm" ) else() set(XMRIG_ASM_FILES - "src/crypto/asm/win64/cn_main_loop.asm" - "src/crypto/asm/win64/CryptonightR_template.asm" + "src/crypto/cn/asm/win64/cn_main_loop.asm" + "src/crypto/cn/asm/win64/CryptonightR_template.asm" ) endif() @@ -22,13 +22,13 @@ if (WITH_ASM AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8) if (WIN32 AND CMAKE_C_COMPILER_ID MATCHES GNU) set(XMRIG_ASM_FILES - "src/crypto/asm/win64/cn_main_loop.S" - "src/crypto/asm/CryptonightR_template.S" + "src/crypto/cn/asm/win64/cn_main_loop.S" + "src/crypto/cn/asm/CryptonightR_template.S" ) else() set(XMRIG_ASM_FILES - "src/crypto/asm/cn_main_loop.S" - "src/crypto/asm/CryptonightR_template.S" + "src/crypto/cn/asm/cn_main_loop.S" + "src/crypto/cn/asm/CryptonightR_template.S" ) endif() @@ -36,7 +36,7 @@ if (WITH_ASM AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8) endif() add_library(${XMRIG_ASM_LIBRARY} STATIC ${XMRIG_ASM_FILES}) - set(XMRIG_ASM_SOURCES src/crypto/Asm.h src/crypto/Asm.cpp src/crypto/CryptonightR_gen.cpp) + set(XMRIG_ASM_SOURCES src/crypto/cn/Asm.h src/crypto/cn/Asm.cpp src/crypto/cn/r/CryptonightR_gen.cpp) set_property(TARGET ${XMRIG_ASM_LIBRARY} PROPERTY LINKER_LANGUAGE C) else() set(XMRIG_ASM_SOURCES "") diff --git a/cmake/cn-gpu.cmake b/cmake/cn-gpu.cmake index b529f0b2d..8f107bf00 100644 --- a/cmake/cn-gpu.cmake +++ b/cmake/cn-gpu.cmake @@ -4,16 +4,16 @@ if (WITH_CN_GPU AND CMAKE_SIZEOF_VOID_P EQUAL 8) set(CN_GPU_SOURCES src/crypto/cn_gpu_arm.cpp) if (CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang) - set_source_files_properties(src/crypto/cn_gpu_arm.cpp PROPERTIES COMPILE_FLAGS "-O3") + set_source_files_properties(src/crypto/cn/gpu/cn_gpu_arm.cpp PROPERTIES COMPILE_FLAGS "-O3") endif() else() - set(CN_GPU_SOURCES src/crypto/cn_gpu_avx.cpp src/crypto/cn_gpu_ssse3.cpp) + set(CN_GPU_SOURCES src/crypto/cn/gpu/cn_gpu_avx.cpp src/crypto/cn/gpu/cn_gpu_ssse3.cpp) if (CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang) - set_source_files_properties(src/crypto/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "-O3 -mavx2") - set_source_files_properties(src/crypto/cn_gpu_ssse3.cpp PROPERTIES COMPILE_FLAGS "-O3") + set_source_files_properties(src/crypto/cn/gpu/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "-O3 -mavx2") + set_source_files_properties(src/crypto/cn/gpu/cn_gpu_ssse3.cpp PROPERTIES COMPILE_FLAGS "-O3") elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC) - set_source_files_properties(src/crypto/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX") + set_source_files_properties(src/crypto/cn/gpu/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX") endif() endif() else() diff --git a/src/App.cpp b/src/App.cpp index 38e335c28..66662eb1e 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -37,7 +37,6 @@ #include "common/Platform.h" #include "core/config/Config.h" #include "core/Controller.h" -#include "crypto/CryptoNight.h" #include "Mem.h" #include "net/Network.h" #include "Summary.h" diff --git a/src/Mem.cpp b/src/Mem.cpp index 2c78e10dc..b9e0fbf96 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -27,10 +27,10 @@ #include +#include "crypto/cn/CryptoNight_constants.h" +#include "crypto/cn/CryptoNight.h" #include "crypto/common/portable/mm_malloc.h" #include "crypto/common/VirtualMemory.h" -#include "crypto/CryptoNight_constants.h" -#include "crypto/CryptoNight.h" #include "Mem.h" diff --git a/src/Mem_unix.cpp b/src/Mem_unix.cpp index d9c3e31f3..9bdce0f5a 100644 --- a/src/Mem_unix.cpp +++ b/src/Mem_unix.cpp @@ -32,7 +32,7 @@ #include "common/xmrig.h" #include "crypto/common/portable/mm_malloc.h" #include "crypto/common/VirtualMemory.h" -#include "crypto/CryptoNight.h" +#include "crypto/cn/CryptoNight.h" #include "Mem.h" diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index 3e8b6ee78..76cbf4345 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -34,8 +34,8 @@ #include "common/xmrig.h" #include "crypto/common/portable/mm_malloc.h" #include "crypto/common/VirtualMemory.h" -#include "crypto/CryptoNight_constants.h" -#include "crypto/CryptoNight.h" +#include "crypto/cn/CryptoNight_constants.h" +#include "crypto/cn/CryptoNight.h" #include "Mem.h" diff --git a/src/Summary.cpp b/src/Summary.cpp index 697e23736..2b28f98de 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -33,7 +33,7 @@ #include "common/cpu/Cpu.h" #include "core/config/Config.h" #include "core/Controller.h" -#include "crypto/Asm.h" +#include "crypto/cn/Asm.h" #include "Mem.h" #include "Summary.h" #include "version.h" diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index 88ddbb72f..a3612ed85 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -32,8 +32,8 @@ #include "base/kernel/interfaces/IJsonReader.h" #include "common/cpu/Cpu.h" #include "core/config/Config.h" -#include "crypto/Asm.h" -#include "crypto/CryptoNight_constants.h" +#include "crypto/cn/Asm.h" +#include "crypto/cn/CryptoNight_constants.h" #include "rapidjson/document.h" #include "rapidjson/filewritestream.h" #include "rapidjson/prettywriter.h" diff --git a/src/crypto/Asm.cpp b/src/crypto/cn/Asm.cpp similarity index 98% rename from src/crypto/Asm.cpp rename to src/crypto/cn/Asm.cpp index 88812c6c1..331c133dd 100644 --- a/src/crypto/Asm.cpp +++ b/src/crypto/cn/Asm.cpp @@ -33,7 +33,7 @@ #endif -#include "crypto/Asm.h" +#include "crypto/cn/Asm.h" #include "rapidjson/document.h" diff --git a/src/crypto/Asm.h b/src/crypto/cn/Asm.h similarity index 100% rename from src/crypto/Asm.h rename to src/crypto/cn/Asm.h diff --git a/src/crypto/CryptoNight.h b/src/crypto/cn/CryptoNight.h similarity index 100% rename from src/crypto/CryptoNight.h rename to src/crypto/cn/CryptoNight.h diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/cn/CryptoNight_arm.h similarity index 99% rename from src/crypto/CryptoNight_arm.h rename to src/crypto/cn/CryptoNight_arm.h index 7be8c53ff..e08c02ded 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/cn/CryptoNight_arm.h @@ -30,18 +30,18 @@ #include "common/crypto/keccak.h" #include "crypto/common/portable/mm_malloc.h" -#include "crypto/CryptoNight_constants.h" -#include "crypto/CryptoNight_monero.h" -#include "crypto/CryptoNight.h" -#include "crypto/soft_aes.h" +#include "crypto/cn/CryptoNight_constants.h" +#include "crypto/cn/CryptoNight_monero.h" +#include "crypto/cn/CryptoNight.h" +#include "crypto/cn/soft_aes.h" extern "C" { -#include "crypto/c_groestl.h" -#include "crypto/c_blake256.h" -#include "crypto/c_jh.h" -#include "crypto/c_skein.h" +#include "crypto/cn/c_groestl.h" +#include "crypto/cn/c_blake256.h" +#include "crypto/cn/c_jh.h" +#include "crypto/cn/c_skein.h" } diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/cn/CryptoNight_constants.h similarity index 100% rename from src/crypto/CryptoNight_constants.h rename to src/crypto/cn/CryptoNight_constants.h diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/cn/CryptoNight_monero.h similarity index 99% rename from src/crypto/CryptoNight_monero.h rename to src/crypto/cn/CryptoNight_monero.h index 4e84ac5d0..94a18c458 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/cn/CryptoNight_monero.h @@ -179,7 +179,7 @@ #endif #include "common/xmrig.h" -#include "variant4_random_math.h" +#include "crypto/cn/r/variant4_random_math.h" #define VARIANT4_RANDOM_MATH_INIT(part) \ uint32_t r##part[9]; \ diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/cn/CryptoNight_test.h similarity index 100% rename from src/crypto/CryptoNight_test.h rename to src/crypto/cn/CryptoNight_test.h diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/cn/CryptoNight_x86.h similarity index 99% rename from src/crypto/CryptoNight_x86.h rename to src/crypto/cn/CryptoNight_x86.h index 390f203b1..c3a89dac5 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/cn/CryptoNight_x86.h @@ -37,18 +37,18 @@ #include "common/cpu/Cpu.h" #include "common/crypto/keccak.h" -#include "crypto/CryptoNight.h" -#include "crypto/CryptoNight_constants.h" -#include "crypto/CryptoNight_monero.h" -#include "crypto/soft_aes.h" +#include "crypto/cn/CryptoNight.h" +#include "crypto/cn/CryptoNight_constants.h" +#include "crypto/cn/CryptoNight_monero.h" +#include "crypto/cn/soft_aes.h" extern "C" { -#include "crypto/c_groestl.h" -#include "crypto/c_blake256.h" -#include "crypto/c_jh.h" -#include "crypto/c_skein.h" +#include "crypto/cn/c_groestl.h" +#include "crypto/cn/c_blake256.h" +#include "crypto/cn/c_jh.h" +#include "crypto/cn/c_skein.h" } diff --git a/src/crypto/SSE2NEON.h b/src/crypto/cn/SSE2NEON.h similarity index 100% rename from src/crypto/SSE2NEON.h rename to src/crypto/cn/SSE2NEON.h diff --git a/src/crypto/asm/CryptonightR_soft_aes_template.inc b/src/crypto/cn/asm/CryptonightR_soft_aes_template.inc similarity index 100% rename from src/crypto/asm/CryptonightR_soft_aes_template.inc rename to src/crypto/cn/asm/CryptonightR_soft_aes_template.inc diff --git a/src/crypto/asm/CryptonightR_soft_aes_template_win.inc b/src/crypto/cn/asm/CryptonightR_soft_aes_template_win.inc similarity index 100% rename from src/crypto/asm/CryptonightR_soft_aes_template_win.inc rename to src/crypto/cn/asm/CryptonightR_soft_aes_template_win.inc diff --git a/src/crypto/asm/CryptonightR_template.S b/src/crypto/cn/asm/CryptonightR_template.S similarity index 100% rename from src/crypto/asm/CryptonightR_template.S rename to src/crypto/cn/asm/CryptonightR_template.S diff --git a/src/crypto/asm/CryptonightR_template.asm b/src/crypto/cn/asm/CryptonightR_template.asm similarity index 100% rename from src/crypto/asm/CryptonightR_template.asm rename to src/crypto/cn/asm/CryptonightR_template.asm diff --git a/src/crypto/asm/CryptonightR_template.h b/src/crypto/cn/asm/CryptonightR_template.h similarity index 100% rename from src/crypto/asm/CryptonightR_template.h rename to src/crypto/cn/asm/CryptonightR_template.h diff --git a/src/crypto/asm/CryptonightR_template.inc b/src/crypto/cn/asm/CryptonightR_template.inc similarity index 100% rename from src/crypto/asm/CryptonightR_template.inc rename to src/crypto/cn/asm/CryptonightR_template.inc diff --git a/src/crypto/asm/CryptonightR_template_win.inc b/src/crypto/cn/asm/CryptonightR_template_win.inc similarity index 100% rename from src/crypto/asm/CryptonightR_template_win.inc rename to src/crypto/cn/asm/CryptonightR_template_win.inc diff --git a/src/crypto/asm/CryptonightWOW_soft_aes_template.inc b/src/crypto/cn/asm/CryptonightWOW_soft_aes_template.inc similarity index 100% rename from src/crypto/asm/CryptonightWOW_soft_aes_template.inc rename to src/crypto/cn/asm/CryptonightWOW_soft_aes_template.inc diff --git a/src/crypto/asm/CryptonightWOW_soft_aes_template_win.inc b/src/crypto/cn/asm/CryptonightWOW_soft_aes_template_win.inc similarity index 100% rename from src/crypto/asm/CryptonightWOW_soft_aes_template_win.inc rename to src/crypto/cn/asm/CryptonightWOW_soft_aes_template_win.inc diff --git a/src/crypto/asm/CryptonightWOW_template.inc b/src/crypto/cn/asm/CryptonightWOW_template.inc similarity index 100% rename from src/crypto/asm/CryptonightWOW_template.inc rename to src/crypto/cn/asm/CryptonightWOW_template.inc diff --git a/src/crypto/asm/CryptonightWOW_template_win.inc b/src/crypto/cn/asm/CryptonightWOW_template_win.inc similarity index 100% rename from src/crypto/asm/CryptonightWOW_template_win.inc rename to src/crypto/cn/asm/CryptonightWOW_template_win.inc diff --git a/src/crypto/asm/cn2/cnv2_double_main_loop_sandybridge.inc b/src/crypto/cn/asm/cn2/cnv2_double_main_loop_sandybridge.inc similarity index 100% rename from src/crypto/asm/cn2/cnv2_double_main_loop_sandybridge.inc rename to src/crypto/cn/asm/cn2/cnv2_double_main_loop_sandybridge.inc diff --git a/src/crypto/asm/cn2/cnv2_main_loop_bulldozer.inc b/src/crypto/cn/asm/cn2/cnv2_main_loop_bulldozer.inc similarity index 100% rename from src/crypto/asm/cn2/cnv2_main_loop_bulldozer.inc rename to src/crypto/cn/asm/cn2/cnv2_main_loop_bulldozer.inc diff --git a/src/crypto/asm/cn2/cnv2_main_loop_ivybridge.inc b/src/crypto/cn/asm/cn2/cnv2_main_loop_ivybridge.inc similarity index 100% rename from src/crypto/asm/cn2/cnv2_main_loop_ivybridge.inc rename to src/crypto/cn/asm/cn2/cnv2_main_loop_ivybridge.inc diff --git a/src/crypto/asm/cn2/cnv2_main_loop_ryzen.inc b/src/crypto/cn/asm/cn2/cnv2_main_loop_ryzen.inc similarity index 100% rename from src/crypto/asm/cn2/cnv2_main_loop_ryzen.inc rename to src/crypto/cn/asm/cn2/cnv2_main_loop_ryzen.inc diff --git a/src/crypto/asm/cn2/cnv2_rwz_double_main_loop.inc b/src/crypto/cn/asm/cn2/cnv2_rwz_double_main_loop.inc similarity index 100% rename from src/crypto/asm/cn2/cnv2_rwz_double_main_loop.inc rename to src/crypto/cn/asm/cn2/cnv2_rwz_double_main_loop.inc diff --git a/src/crypto/asm/cn2/cnv2_rwz_main_loop.inc b/src/crypto/cn/asm/cn2/cnv2_rwz_main_loop.inc similarity index 100% rename from src/crypto/asm/cn2/cnv2_rwz_main_loop.inc rename to src/crypto/cn/asm/cn2/cnv2_rwz_main_loop.inc diff --git a/src/crypto/asm/cn_main_loop.S b/src/crypto/cn/asm/cn_main_loop.S similarity index 100% rename from src/crypto/asm/cn_main_loop.S rename to src/crypto/cn/asm/cn_main_loop.S diff --git a/src/crypto/asm/cn_main_loop.asm b/src/crypto/cn/asm/cn_main_loop.asm similarity index 100% rename from src/crypto/asm/cn_main_loop.asm rename to src/crypto/cn/asm/cn_main_loop.asm diff --git a/src/crypto/asm/win64/CryptonightR_soft_aes_template_win.inc b/src/crypto/cn/asm/win64/CryptonightR_soft_aes_template_win.inc similarity index 100% rename from src/crypto/asm/win64/CryptonightR_soft_aes_template_win.inc rename to src/crypto/cn/asm/win64/CryptonightR_soft_aes_template_win.inc diff --git a/src/crypto/asm/win64/CryptonightR_template.asm b/src/crypto/cn/asm/win64/CryptonightR_template.asm similarity index 100% rename from src/crypto/asm/win64/CryptonightR_template.asm rename to src/crypto/cn/asm/win64/CryptonightR_template.asm diff --git a/src/crypto/asm/win64/CryptonightR_template_win.inc b/src/crypto/cn/asm/win64/CryptonightR_template_win.inc similarity index 100% rename from src/crypto/asm/win64/CryptonightR_template_win.inc rename to src/crypto/cn/asm/win64/CryptonightR_template_win.inc diff --git a/src/crypto/asm/win64/CryptonightWOW_soft_aes_template_win.inc b/src/crypto/cn/asm/win64/CryptonightWOW_soft_aes_template_win.inc similarity index 100% rename from src/crypto/asm/win64/CryptonightWOW_soft_aes_template_win.inc rename to src/crypto/cn/asm/win64/CryptonightWOW_soft_aes_template_win.inc diff --git a/src/crypto/asm/win64/CryptonightWOW_template_win.inc b/src/crypto/cn/asm/win64/CryptonightWOW_template_win.inc similarity index 100% rename from src/crypto/asm/win64/CryptonightWOW_template_win.inc rename to src/crypto/cn/asm/win64/CryptonightWOW_template_win.inc diff --git a/src/crypto/asm/win64/cn2/cnv2_double_main_loop_sandybridge.inc b/src/crypto/cn/asm/win64/cn2/cnv2_double_main_loop_sandybridge.inc similarity index 100% rename from src/crypto/asm/win64/cn2/cnv2_double_main_loop_sandybridge.inc rename to src/crypto/cn/asm/win64/cn2/cnv2_double_main_loop_sandybridge.inc diff --git a/src/crypto/asm/win64/cn2/cnv2_main_loop_bulldozer.inc b/src/crypto/cn/asm/win64/cn2/cnv2_main_loop_bulldozer.inc similarity index 100% rename from src/crypto/asm/win64/cn2/cnv2_main_loop_bulldozer.inc rename to src/crypto/cn/asm/win64/cn2/cnv2_main_loop_bulldozer.inc diff --git a/src/crypto/asm/win64/cn2/cnv2_main_loop_ivybridge.inc b/src/crypto/cn/asm/win64/cn2/cnv2_main_loop_ivybridge.inc similarity index 100% rename from src/crypto/asm/win64/cn2/cnv2_main_loop_ivybridge.inc rename to src/crypto/cn/asm/win64/cn2/cnv2_main_loop_ivybridge.inc diff --git a/src/crypto/asm/win64/cn2/cnv2_main_loop_ryzen.inc b/src/crypto/cn/asm/win64/cn2/cnv2_main_loop_ryzen.inc similarity index 100% rename from src/crypto/asm/win64/cn2/cnv2_main_loop_ryzen.inc rename to src/crypto/cn/asm/win64/cn2/cnv2_main_loop_ryzen.inc diff --git a/src/crypto/asm/win64/cn2/cnv2_rwz_double_main_loop.inc b/src/crypto/cn/asm/win64/cn2/cnv2_rwz_double_main_loop.inc similarity index 100% rename from src/crypto/asm/win64/cn2/cnv2_rwz_double_main_loop.inc rename to src/crypto/cn/asm/win64/cn2/cnv2_rwz_double_main_loop.inc diff --git a/src/crypto/asm/win64/cn2/cnv2_rwz_main_loop.inc b/src/crypto/cn/asm/win64/cn2/cnv2_rwz_main_loop.inc similarity index 100% rename from src/crypto/asm/win64/cn2/cnv2_rwz_main_loop.inc rename to src/crypto/cn/asm/win64/cn2/cnv2_rwz_main_loop.inc diff --git a/src/crypto/asm/win64/cn_main_loop.S b/src/crypto/cn/asm/win64/cn_main_loop.S similarity index 100% rename from src/crypto/asm/win64/cn_main_loop.S rename to src/crypto/cn/asm/win64/cn_main_loop.S diff --git a/src/crypto/asm/win64/cn_main_loop.asm b/src/crypto/cn/asm/win64/cn_main_loop.asm similarity index 100% rename from src/crypto/asm/win64/cn_main_loop.asm rename to src/crypto/cn/asm/win64/cn_main_loop.asm diff --git a/src/crypto/c_blake256.c b/src/crypto/cn/c_blake256.c similarity index 100% rename from src/crypto/c_blake256.c rename to src/crypto/cn/c_blake256.c diff --git a/src/crypto/c_blake256.h b/src/crypto/cn/c_blake256.h similarity index 100% rename from src/crypto/c_blake256.h rename to src/crypto/cn/c_blake256.h diff --git a/src/crypto/c_groestl.c b/src/crypto/cn/c_groestl.c similarity index 100% rename from src/crypto/c_groestl.c rename to src/crypto/cn/c_groestl.c diff --git a/src/crypto/c_groestl.h b/src/crypto/cn/c_groestl.h similarity index 100% rename from src/crypto/c_groestl.h rename to src/crypto/cn/c_groestl.h diff --git a/src/crypto/c_jh.c b/src/crypto/cn/c_jh.c similarity index 100% rename from src/crypto/c_jh.c rename to src/crypto/cn/c_jh.c diff --git a/src/crypto/c_jh.h b/src/crypto/cn/c_jh.h similarity index 100% rename from src/crypto/c_jh.h rename to src/crypto/cn/c_jh.h diff --git a/src/crypto/c_skein.c b/src/crypto/cn/c_skein.c similarity index 100% rename from src/crypto/c_skein.c rename to src/crypto/cn/c_skein.c diff --git a/src/crypto/c_skein.h b/src/crypto/cn/c_skein.h similarity index 100% rename from src/crypto/c_skein.h rename to src/crypto/cn/c_skein.h diff --git a/src/crypto/cn_gpu_arm.cpp b/src/crypto/cn/gpu/cn_gpu_arm.cpp similarity index 100% rename from src/crypto/cn_gpu_arm.cpp rename to src/crypto/cn/gpu/cn_gpu_arm.cpp diff --git a/src/crypto/cn_gpu_avx.cpp b/src/crypto/cn/gpu/cn_gpu_avx.cpp similarity index 99% rename from src/crypto/cn_gpu_avx.cpp rename to src/crypto/cn/gpu/cn_gpu_avx.cpp index 9f801c80a..382be5708 100644 --- a/src/crypto/cn_gpu_avx.cpp +++ b/src/crypto/cn/gpu/cn_gpu_avx.cpp @@ -22,7 +22,7 @@ * along with this program. If not, see . */ -#include "crypto/CryptoNight_constants.h" +#include "crypto/cn/CryptoNight_constants.h" #ifdef __GNUC__ # include diff --git a/src/crypto/cn_gpu_ssse3.cpp b/src/crypto/cn/gpu/cn_gpu_ssse3.cpp similarity index 99% rename from src/crypto/cn_gpu_ssse3.cpp rename to src/crypto/cn/gpu/cn_gpu_ssse3.cpp index ce3d19add..42a11a1d3 100644 --- a/src/crypto/cn_gpu_ssse3.cpp +++ b/src/crypto/cn/gpu/cn_gpu_ssse3.cpp @@ -22,7 +22,7 @@ * along with this program. If not, see . */ -#include "crypto/CryptoNight_constants.h" +#include "crypto/cn/CryptoNight_constants.h" #ifdef __GNUC__ # include diff --git a/src/crypto/groestl_tables.h b/src/crypto/cn/groestl_tables.h similarity index 100% rename from src/crypto/groestl_tables.h rename to src/crypto/cn/groestl_tables.h diff --git a/src/crypto/hash.h b/src/crypto/cn/hash.h similarity index 100% rename from src/crypto/hash.h rename to src/crypto/cn/hash.h diff --git a/src/crypto/CryptonightR_gen.cpp b/src/crypto/cn/r/CryptonightR_gen.cpp similarity index 98% rename from src/crypto/CryptonightR_gen.cpp rename to src/crypto/cn/r/CryptonightR_gen.cpp index 5352cf0a3..8491a33bf 100644 --- a/src/crypto/CryptonightR_gen.cpp +++ b/src/crypto/cn/r/CryptonightR_gen.cpp @@ -24,11 +24,11 @@ */ #include -#include "crypto/CryptoNight_monero.h" +#include "crypto/cn/CryptoNight_monero.h" typedef void(*void_func)(); -#include "crypto/asm/CryptonightR_template.h" +#include "crypto/cn/asm/CryptonightR_template.h" #include "crypto/common/VirtualMemory.h" #include "Mem.h" diff --git a/src/crypto/variant4_random_math.h b/src/crypto/cn/r/variant4_random_math.h similarity index 99% rename from src/crypto/variant4_random_math.h rename to src/crypto/cn/r/variant4_random_math.h index 1f3ea0ac3..c384df7a5 100644 --- a/src/crypto/variant4_random_math.h +++ b/src/crypto/cn/r/variant4_random_math.h @@ -3,7 +3,7 @@ extern "C" { - #include "c_blake256.h" + #include "crypto/cn/c_blake256.h" } enum V4_Settings diff --git a/src/crypto/skein_port.h b/src/crypto/cn/skein_port.h similarity index 100% rename from src/crypto/skein_port.h rename to src/crypto/cn/skein_port.h diff --git a/src/crypto/soft_aes.h b/src/crypto/cn/soft_aes.h similarity index 100% rename from src/crypto/soft_aes.h rename to src/crypto/cn/soft_aes.h diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index fbdd8b646..ddcb36f9c 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -27,7 +27,7 @@ #include "base/io/log/Log.h" #include "common/cpu/Cpu.h" -#include "crypto/Asm.h" +#include "crypto/cn/Asm.h" #include "crypto/common/VirtualMemory.h" #include "Mem.h" #include "rapidjson/document.h" @@ -35,9 +35,9 @@ #if defined(XMRIG_ARM) -# include "crypto/CryptoNight_arm.h" +# include "crypto/cn/CryptoNight_arm.h" #else -# include "crypto/CryptoNight_x86.h" +# include "crypto/cn/CryptoNight_x86.h" #endif diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 8b9e0881a..b71ed0762 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -27,7 +27,7 @@ #include -#include "crypto/CryptoNight_test.h" +#include "crypto/cn/CryptoNight_test.h" #include "workers/CpuThread.h" #include "workers/MultiWorker.h" #include "workers/Workers.h" diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 539901354..b95d8b852 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -32,7 +32,7 @@ #include "base/tools/Handle.h" #include "core/config/Config.h" #include "core/Controller.h" -#include "crypto/CryptoNight_constants.h" +#include "crypto/cn/CryptoNight_constants.h" #include "interfaces/IJobResultListener.h" #include "interfaces/IThread.h" #include "Mem.h" From bd8370951f45890483044e1d7a4ec2c9046bab81 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 4 Jun 2019 19:27:51 +0700 Subject: [PATCH 10/26] Fixed ARM build. --- cmake/cn-gpu.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/cn-gpu.cmake b/cmake/cn-gpu.cmake index 8f107bf00..9b8a62dd2 100644 --- a/cmake/cn-gpu.cmake +++ b/cmake/cn-gpu.cmake @@ -1,7 +1,7 @@ if (WITH_CN_GPU AND CMAKE_SIZEOF_VOID_P EQUAL 8) if (XMRIG_ARM) - set(CN_GPU_SOURCES src/crypto/cn_gpu_arm.cpp) + set(CN_GPU_SOURCES src/crypto/cn/gpu/cn_gpu_arm.cpp) if (CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang) set_source_files_properties(src/crypto/cn/gpu/cn_gpu_arm.cpp PROPERTIES COMPILE_FLAGS "-O3") From 09cdddc7f6d751ce273e7a8a33edf379a7122eaf Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 4 Jun 2019 19:49:54 +0700 Subject: [PATCH 11/26] Fixed ARM build, again. --- src/crypto/cn/gpu/cn_gpu_arm.cpp | 2 +- src/crypto/cn/soft_aes.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crypto/cn/gpu/cn_gpu_arm.cpp b/src/crypto/cn/gpu/cn_gpu_arm.cpp index b463dd2ec..a1df0cc75 100644 --- a/src/crypto/cn/gpu/cn_gpu_arm.cpp +++ b/src/crypto/cn/gpu/cn_gpu_arm.cpp @@ -26,7 +26,7 @@ #include -#include "crypto/CryptoNight_constants.h" +#include "crypto/cn/CryptoNight_constants.h" inline void vandq_f32(float32x4_t &v, uint32_t v2) diff --git a/src/crypto/cn/soft_aes.h b/src/crypto/cn/soft_aes.h index 4ad9bdd93..fca31d1c1 100644 --- a/src/crypto/cn/soft_aes.h +++ b/src/crypto/cn/soft_aes.h @@ -28,7 +28,7 @@ #if defined(XMRIG_ARM) -# include "crypto/SSE2NEON.h" +# include "crypto/cn/SSE2NEON.h" #elif defined(__GNUC__) # include #else From d9eb700e035af2e66ad3ed6683525b0115aa2268 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 9 Jun 2019 15:29:26 +0700 Subject: [PATCH 12/26] Renamed macros for enable/disable algorithms. --- CMakeLists.txt | 20 ++++++++------------ cmake/cn-gpu.cmake | 4 +++- src/common/crypto/Algorithm.cpp | 8 ++++---- src/core/config/Config.cpp | 4 ++-- src/core/config/Config.h | 2 +- src/core/config/usage.h | 6 +++--- src/crypto/cn/CryptoNight_arm.h | 4 ++-- src/crypto/cn/CryptoNight_test.h | 8 ++++---- src/crypto/cn/CryptoNight_x86.h | 4 ++-- src/workers/CpuThread.cpp | 10 +++++----- src/workers/MultiWorker.cpp | 8 ++++---- 11 files changed, 38 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a764b224..fbd08aaf0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 2.8) project(xmrig) option(WITH_LIBCPUID "Use Libcpuid" ON) -option(WITH_AEON "CryptoNight-Lite support" ON) -option(WITH_SUMO "CryptoNight-Heavy support" ON) +option(WITH_CN_LITE "CryptoNight-Lite support" ON) +option(WITH_CN_HEAVY "CryptoNight-Heavy support" ON) option(WITH_CN_PICO "CryptoNight-Pico support" ON) option(WITH_CN_GPU "CryptoNight-GPU support" ON) option(WITH_HTTP "HTTP protocol support (client/server)" ON) @@ -182,20 +182,16 @@ include(cmake/OpenSSL.cmake) include(cmake/asm.cmake) include(cmake/cn-gpu.cmake) -if (NOT WITH_AEON) - add_definitions(/DXMRIG_NO_AEON) +if (WITH_CN_LITE) + add_definitions(/DXMRIG_ALGO_CN_LITE) endif() -if (NOT WITH_SUMO) - add_definitions(/DXMRIG_NO_SUMO) +if (WITH_CN_HEAVY) + add_definitions(/DXMRIG_ALGO_CN_HEAVY) endif() -if (NOT WITH_IPBC) - add_definitions(/DXMRIG_NO_IPBC) -endif() - -if (NOT WITH_CN_PICO) - add_definitions(/DXMRIG_NO_CN_PICO) +if (WITH_CN_PICO) + add_definitions(/DXMRIG_ALGO_CN_PICO) endif() if (WITH_EMBEDDED_CONFIG) diff --git a/cmake/cn-gpu.cmake b/cmake/cn-gpu.cmake index 9b8a62dd2..7aa489e6f 100644 --- a/cmake/cn-gpu.cmake +++ b/cmake/cn-gpu.cmake @@ -16,8 +16,10 @@ if (WITH_CN_GPU AND CMAKE_SIZEOF_VOID_P EQUAL 8) set_source_files_properties(src/crypto/cn/gpu/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX") endif() endif() + + add_definitions(/DXMRIG_ALGO_CN_GPU) else() set(CN_GPU_SOURCES "") - add_definitions(/DXMRIG_NO_CN_GPU) + remove_definitions(/DXMRIG_ALGO_CN_GPU) endif() diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index d9d3ead96..10f707507 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -70,21 +70,21 @@ static AlgoData const algorithms[] = { { "cryptonight/zls", "cn/zls", xmrig::CRYPTONIGHT, xmrig::VARIANT_ZLS }, { "cryptonight/double", "cn/double", xmrig::CRYPTONIGHT, xmrig::VARIANT_DOUBLE }, -# ifndef XMRIG_NO_AEON +# ifdef XMRIG_ALGO_CN_LITE { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, { "cryptonight-light", "cn-light", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, { "cryptonight-lite/0", "cn-lite/0", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 }, { "cryptonight-lite/1", "cn-lite/1", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, # endif -# ifndef XMRIG_NO_SUMO +# ifdef XMRIG_ALGO_CN_HEAVY { "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_AUTO }, { "cryptonight-heavy/0", "cn-heavy/0", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, { "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV }, { "cryptonight-heavy/tube", "cn-heavy/tube", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_TUBE }, # endif -# ifndef XMRIG_NO_CN_PICO +# ifdef XMRIG_ALGO_CN_PICO { "cryptonight-pico/trtl", "cn-pico/trtl", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL }, { "cryptonight-pico", "cn-pico", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL }, { "cryptonight-turtle", "cn-trtl", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL }, @@ -92,7 +92,7 @@ static AlgoData const algorithms[] = { { "cryptonight_turtle", "cn_turtle", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL }, # endif -# ifndef XMRIG_NO_CN_GPU +# ifdef XMRIG_ALGO_CN_GPU { "cryptonight/gpu", "cn/gpu", xmrig::CRYPTONIGHT, xmrig::VARIANT_GPU }, # endif }; diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index a3612ed85..c1430e4d5 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -244,7 +244,7 @@ void xmrig::Config::setThreads(const rapidjson::Value &threads) xmrig::AlgoVariant xmrig::Config::getAlgoVariant() const { -# ifndef XMRIG_NO_AEON +# ifdef XMRIG_ALGO_CN_LITE if (m_algorithm.algo() == xmrig::CRYPTONIGHT_LITE) { return getAlgoVariantLite(); } @@ -262,7 +262,7 @@ xmrig::AlgoVariant xmrig::Config::getAlgoVariant() const } -#ifndef XMRIG_NO_AEON +#ifdef XMRIG_ALGO_CN_LITE xmrig::AlgoVariant xmrig::Config::getAlgoVariantLite() const { if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) { diff --git a/src/core/config/Config.h b/src/core/config/Config.h index 861840c77..4bcb8bba3 100644 --- a/src/core/config/Config.h +++ b/src/core/config/Config.h @@ -90,7 +90,7 @@ private: void setThreads(const rapidjson::Value &threads); AlgoVariant getAlgoVariant() const; -# ifndef XMRIG_NO_AEON +# ifdef XMRIG_ALGO_CN_LITE AlgoVariant getAlgoVariantLite() const; # endif diff --git a/src/core/config/usage.h b/src/core/config/usage.h index ce1727780..42cbc24a3 100644 --- a/src/core/config/usage.h +++ b/src/core/config/usage.h @@ -37,15 +37,15 @@ Usage: " APP_ID " [OPTIONS]\n\ Options:\n\ -a, --algo=ALGO specify the algorithm to use\n\ cryptonight\n" -#ifndef XMRIG_NO_AEON +#ifdef XMRIG_ALGO_CN_LITE "\ cryptonight-lite\n" #endif -#ifndef XMRIG_NO_SUMO +#ifdef XMRIG_ALGO_CN_HEAVY "\ cryptonight-heavy\n" #endif -#ifndef XMRIG_NO_CN_PICO +#ifdef XMRIG_ALGO_CN_PICO "\ cryptonight-pico\n" #endif diff --git a/src/crypto/cn/CryptoNight_arm.h b/src/crypto/cn/CryptoNight_arm.h index e08c02ded..d9be454b8 100644 --- a/src/crypto/cn/CryptoNight_arm.h +++ b/src/crypto/cn/CryptoNight_arm.h @@ -284,7 +284,7 @@ static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output) } -#ifndef XMRIG_NO_CN_GPU +#ifdef XMRIG_ALGO_CN_GPU template void cn_explode_scratchpad_gpu(const uint8_t *input, uint8_t *output) { @@ -583,7 +583,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si } -#ifndef XMRIG_NO_CN_GPU +#ifdef XMRIG_ALGO_CN_GPU template void cn_gpu_inner_arm(const uint8_t *spad, uint8_t *lpad); diff --git a/src/crypto/cn/CryptoNight_test.h b/src/crypto/cn/CryptoNight_test.h index 6fa9dd286..2429fc177 100644 --- a/src/crypto/cn/CryptoNight_test.h +++ b/src/crypto/cn/CryptoNight_test.h @@ -272,7 +272,7 @@ const static uint8_t test_output_double[160] = { 0x5E, 0x2E, 0xC1, 0x80, 0x89, 0x39, 0xB3, 0x54, 0x39, 0x52, 0x0E, 0x69, 0x3D, 0xF6, 0xC5, 0x4A }; -#ifndef XMRIG_NO_AEON +#ifdef XMRIG_ALGO_CN_LITE // "cn-lite/0" const static uint8_t test_output_v0_lite[160] = { 0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E, @@ -304,7 +304,7 @@ const static uint8_t test_output_v1_lite[160] = { #endif -#ifndef XMRIG_NO_SUMO +#ifdef XMRIG_ALGO_CN_HEAVY // "cn-heavy/0" const static uint8_t test_output_v0_heavy[160] = { 0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64, @@ -351,7 +351,7 @@ const static uint8_t test_output_tube_heavy[160] = { #endif -#ifndef XMRIG_NO_CN_PICO +#ifdef XMRIG_ALGO_CN_PICO // "cn-pico/trtl" const static uint8_t test_output_pico_trtl[160] = { 0x08, 0xF4, 0x21, 0xD7, 0x83, 0x31, 0x17, 0x30, 0x0E, 0xDA, 0x66, 0xE9, 0x8F, 0x4A, 0x25, 0x69, @@ -368,7 +368,7 @@ const static uint8_t test_output_pico_trtl[160] = { #endif -#ifndef XMRIG_NO_CN_GPU +#ifdef XMRIG_ALGO_CN_GPU // "cn/gpu" const static uint8_t test_output_gpu[160] = { 0xE5, 0x5C, 0xB2, 0x3E, 0x51, 0x64, 0x9A, 0x59, 0xB1, 0x27, 0xB9, 0x6B, 0x51, 0x5F, 0x2B, 0xF7, diff --git a/src/crypto/cn/CryptoNight_x86.h b/src/crypto/cn/CryptoNight_x86.h index c3a89dac5..8d6792d28 100644 --- a/src/crypto/cn/CryptoNight_x86.h +++ b/src/crypto/cn/CryptoNight_x86.h @@ -361,7 +361,7 @@ static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output) } -#ifndef XMRIG_NO_CN_GPU +#ifdef XMRIG_ALGO_CN_GPU template void cn_explode_scratchpad_gpu(const uint8_t *input, uint8_t *output) { @@ -708,7 +708,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si } -#ifndef XMRIG_NO_CN_GPU +#ifdef XMRIG_ALGO_CN_GPU template void cn_gpu_inner_avx(const uint8_t *spad, uint8_t *lpad); diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index ddcb36f9c..5c98a5b36 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -207,7 +207,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a add_asm_func(asm_func_map); add_asm_func(asm_func_map); -# ifndef XMRIG_NO_CN_PICO +# ifdef XMRIG_ALGO_CN_PICO add_asm_func(asm_func_map); # endif @@ -321,7 +321,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TRTL -# ifndef XMRIG_NO_CN_GPU +# ifdef XMRIG_ALGO_CN_GPU cryptonight_single_hash_gpu, nullptr, cryptonight_single_hash_gpu, @@ -391,7 +391,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, -# ifndef XMRIG_NO_AEON +# ifdef XMRIG_ALGO_CN_LITE cryptonight_single_hash, cryptonight_double_hash, cryptonight_single_hash, @@ -449,7 +449,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE # endif -# ifndef XMRIG_NO_SUMO +# ifdef XMRIG_ALGO_CN_HEAVY cryptonight_single_hash, cryptonight_double_hash, cryptonight_single_hash, @@ -519,7 +519,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE # endif -# ifndef XMRIG_NO_CN_PICO +# ifdef XMRIG_ALGO_CN_PICO nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TUBE diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index b71ed0762..e4a5fb0c7 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -68,7 +68,7 @@ bool MultiWorker::selfTest() verify(VARIANT_ZLS, test_output_zls) && verify(VARIANT_DOUBLE, test_output_double); -# ifndef XMRIG_NO_CN_GPU +# ifdef XMRIG_ALGO_CN_GPU if (!rc || N > 1) { return rc; } @@ -79,14 +79,14 @@ bool MultiWorker::selfTest() # endif } -# ifndef XMRIG_NO_AEON +# ifdef XMRIG_ALGO_CN_LITE if (m_thread->algorithm() == CRYPTONIGHT_LITE) { return verify(VARIANT_0, test_output_v0_lite) && verify(VARIANT_1, test_output_v1_lite); } # endif -# ifndef XMRIG_NO_SUMO +# ifdef XMRIG_ALGO_CN_HEAVY if (m_thread->algorithm() == CRYPTONIGHT_HEAVY) { return verify(VARIANT_0, test_output_v0_heavy) && verify(VARIANT_XHV, test_output_xhv_heavy) && @@ -94,7 +94,7 @@ bool MultiWorker::selfTest() } # endif -# ifndef XMRIG_NO_CN_PICO +# ifdef XMRIG_ALGO_CN_PICO if (m_thread->algorithm() == CRYPTONIGHT_PICO) { return verify(VARIANT_TRTL, test_output_pico_trtl); } From b684150336739ffcd1f4d0250ffc3d3bc4438744 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 9 Jun 2019 16:46:44 +0700 Subject: [PATCH 13/26] Moved Algorithm class. --- CMakeLists.txt | 4 ++-- src/base/kernel/interfaces/IConfig.h | 2 +- src/base/kernel/interfaces/IConfigTransform.h | 2 +- src/base/net/stratum/Client.h | 2 +- src/base/net/stratum/Job.h | 2 +- src/base/net/stratum/Pool.h | 2 +- src/{common/crypto => crypto/common}/Algorithm.cpp | 2 +- src/{common/crypto => crypto/common}/Algorithm.h | 0 8 files changed, 8 insertions(+), 8 deletions(-) rename src/{common/crypto => crypto/common}/Algorithm.cpp (99%) rename src/{common/crypto => crypto/common}/Algorithm.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fbd08aaf0..30625d28b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,6 @@ set(HEADERS src/api/interfaces/IApiListener.h src/App.h src/common/cpu/Cpu.h - src/common/crypto/Algorithm.h src/common/crypto/keccak.h src/common/interfaces/ICpuInfo.h src/common/Platform.h @@ -68,6 +67,7 @@ set(HEADERS_CRYPTO src/crypto/cn/hash.h src/crypto/cn/skein_port.h src/crypto/cn/soft_aes.h + src/crypto/common/Algorithm.h src/crypto/common/portable/mm_malloc.h src/crypto/common/VirtualMemory.h ) @@ -82,7 +82,6 @@ set(SOURCES "${SOURCES_BASE}" "${SOURCES_BASE_HTTP}" src/App.cpp - src/common/crypto/Algorithm.cpp src/common/crypto/keccak.cpp src/common/Platform.cpp src/core/config/Config.cpp @@ -107,6 +106,7 @@ set(SOURCES_CRYPTO src/crypto/cn/c_blake256.c src/crypto/cn/c_jh.c src/crypto/cn/c_skein.c + src/crypto/common/Algorithm.cpp ) if (WIN32) diff --git a/src/base/kernel/interfaces/IConfig.h b/src/base/kernel/interfaces/IConfig.h index 07849e35b..3d0407e65 100644 --- a/src/base/kernel/interfaces/IConfig.h +++ b/src/base/kernel/interfaces/IConfig.h @@ -26,7 +26,7 @@ #define XMRIG_ICONFIG_H -#include "common/crypto/Algorithm.h" +#include "crypto/common/Algorithm.h" #include "rapidjson/fwd.h" diff --git a/src/base/kernel/interfaces/IConfigTransform.h b/src/base/kernel/interfaces/IConfigTransform.h index 37ceaba1e..f88543883 100644 --- a/src/base/kernel/interfaces/IConfigTransform.h +++ b/src/base/kernel/interfaces/IConfigTransform.h @@ -26,7 +26,7 @@ #define XMRIG_ICONFIGTRANSFORM_H -#include "common/crypto/Algorithm.h" +#include "crypto/common/Algorithm.h" #include "rapidjson/fwd.h" diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index c7aeabfed..841e0e0b9 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -40,7 +40,7 @@ #include "base/net/stratum/SubmitResult.h" #include "base/net/tools/RecvBuf.h" #include "base/net/tools/Storage.h" -#include "common/crypto/Algorithm.h" +#include "crypto/common/Algorithm.h" typedef struct bio_st BIO; diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index 16e9a8611..5052040a5 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -33,7 +33,7 @@ #include "base/tools/String.h" -#include "common/crypto/Algorithm.h" +#include "crypto/common/Algorithm.h" namespace xmrig { diff --git a/src/base/net/stratum/Pool.h b/src/base/net/stratum/Pool.h index f79877078..5348271ac 100644 --- a/src/base/net/stratum/Pool.h +++ b/src/base/net/stratum/Pool.h @@ -32,7 +32,7 @@ #include "base/tools/String.h" -#include "common/crypto/Algorithm.h" +#include "crypto/common/Algorithm.h" #include "rapidjson/fwd.h" diff --git a/src/common/crypto/Algorithm.cpp b/src/crypto/common/Algorithm.cpp similarity index 99% rename from src/common/crypto/Algorithm.cpp rename to src/crypto/common/Algorithm.cpp index 10f707507..29ca9ecfe 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -30,7 +30,7 @@ #include -#include "common/crypto/Algorithm.h" +#include "crypto/common/Algorithm.h" #ifdef _MSC_VER diff --git a/src/common/crypto/Algorithm.h b/src/crypto/common/Algorithm.h similarity index 100% rename from src/common/crypto/Algorithm.h rename to src/crypto/common/Algorithm.h From 725c767928ac05ec0f003b08489075f5f6daf274 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 9 Jun 2019 16:48:30 +0700 Subject: [PATCH 14/26] v2.99.0-evo --- src/version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/version.h b/src/version.h index eb204f7df..309f88737 100644 --- a/src/version.h +++ b/src/version.h @@ -28,15 +28,15 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "2.15.5-evo" +#define APP_VERSION "2.99.0-evo" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com" #define APP_KIND "cpu" #define APP_VER_MAJOR 2 -#define APP_VER_MINOR 15 -#define APP_VER_PATCH 5 +#define APP_VER_MINOR 99 +#define APP_VER_PATCH 0 #ifdef _MSC_VER # if (_MSC_VER >= 1920) From ac1b554282ae1cc8b432f6e625334300781920fc Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sat, 15 Jun 2019 22:53:03 +0200 Subject: [PATCH 15/26] RandomWOW support --- CMakeLists.txt | 4 +- cmake/FindRandomWOW.cmake | 25 +++++++++++ src/base/net/stratum/Client.cpp | 8 ++++ src/base/net/stratum/DaemonClient.cpp | 2 + src/base/net/stratum/Job.cpp | 11 +++++ src/base/net/stratum/Job.h | 3 ++ src/base/net/stratum/Pool.cpp | 1 + src/common/crypto/Algorithm.cpp | 4 +- src/common/xmrig.h | 1 + src/workers/CpuThread.cpp | 8 ++++ src/workers/MultiWorker.cpp | 16 ++++++- src/workers/MultiWorker.h | 3 ++ src/workers/Workers.cpp | 64 +++++++++++++++++++++++++++ src/workers/Workers.h | 10 +++++ 14 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 cmake/FindRandomWOW.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c7098f373..8f6e9226b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,6 +154,7 @@ add_definitions(/DUNICODE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") find_package(UV REQUIRED) +find_package(RANDOMWOW REQUIRED) include(cmake/flags.cmake) @@ -219,6 +220,7 @@ endif() include_directories(src) include_directories(src/3rdparty) include_directories(${UV_INCLUDE_DIR}) +include_directories(${RANDOMWOW_INCLUDE_DIR}) if (BUILD_STATIC) set(CMAKE_EXE_LINKER_FLAGS " -static") @@ -229,4 +231,4 @@ if (WITH_DEBUG_LOG) endif() add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTP_SOURCES} ${TLS_SOURCES} ${XMRIG_ASM_SOURCES} ${CN_GPU_SOURCES}) -target_link_libraries(${CMAKE_PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${EXTRA_LIBS} ${CPUID_LIB}) +target_link_libraries(${CMAKE_PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${RANDOMWOW_LIBRARIES} ${EXTRA_LIBS} ${CPUID_LIB}) diff --git a/cmake/FindRandomWOW.cmake b/cmake/FindRandomWOW.cmake new file mode 100644 index 000000000..c1db649fa --- /dev/null +++ b/cmake/FindRandomWOW.cmake @@ -0,0 +1,25 @@ +find_path( + RANDOMWOW_INCLUDE_DIR + NAMES randomwow.h + PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" + PATH_SUFFIXES "include" + NO_DEFAULT_PATH +) + +find_path(RANDOMWOW_INCLUDE_DIR NAMES randomwow.h) + +find_library( + RANDOMWOW_LIBRARY + NAMES librandomwow.a randomwow librandomwow + PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" + PATH_SUFFIXES "lib" + NO_DEFAULT_PATH +) + +find_library(RANDOMWOW_LIBRARY NAMES librandomwow.a randomwow librandomwow) + +set(RANDOMWOW_LIBRARIES ${RANDOMWOW_LIBRARY}) +set(RANDOMWOW_INCLUDE_DIRS ${RANDOMWOW_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(RANDOMWOW DEFAULT_MSG RANDOMWOW_LIBRARY RANDOMWOW_INCLUDE_DIR) diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 1d448ddff..4941ca3a0 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -344,6 +344,14 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code) } } + if (params.HasMember("seed_hash")) { + const rapidjson::Value &variant = params["seed_hash"]; + + if (variant.IsString()) { + job.setSeedHash(variant.GetString()); + } + } + if (params.HasMember("height")) { const rapidjson::Value &variant = params["height"]; diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index 769e2116f..e63c3271d 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -220,6 +220,8 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code) return false; } + job.setSeedHash(Json::getString(params, "seed_hash")); + job.setHeight(Json::getUint64(params, kHeight)); job.setDiff(Json::getUint64(params, "difficulty")); job.setId(blocktemplate.data() + blocktemplate.size() - 32); diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index 1f1cd4139..36098bfe9 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -42,6 +42,7 @@ xmrig::Job::Job() : m_diff(0), m_height(0), m_target(0), + m_seedHash(), m_blob() { } @@ -58,6 +59,7 @@ xmrig::Job::Job(int poolId, bool nicehash, const Algorithm &algorithm, const Str m_diff(0), m_height(0), m_target(0), + m_seedHash(), m_blob() { } @@ -175,6 +177,15 @@ void xmrig::Job::setDiff(uint64_t diff) } +bool xmrig::Job::setSeedHash(const char *hash) +{ + if (!hash || (strlen(hash) != sizeof(m_seedHash) * 2)) + return false; + + return Buffer::fromHex(hash, sizeof(m_seedHash) * 2, m_seedHash); +} + + xmrig::Variant xmrig::Job::variant() const { switch (m_algorithm.algo()) { diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index 16e9a8611..1c1b078b8 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -55,6 +55,7 @@ public: bool setTarget(const char *target); void setAlgorithm(const char *algo); void setDiff(uint64_t diff); + bool setSeedHash(const char *hash); inline bool isNicehash() const { return m_nicehash; } inline bool isValid() const { return m_size > 0 && m_diff > 0; } @@ -64,6 +65,7 @@ public: inline const String &id() const { return m_id; } inline const uint32_t *nonce() const { return reinterpret_cast(m_blob + 39); } inline const uint8_t *blob() const { return m_blob; } + inline const uint8_t *seed_hash() const { return m_seedHash; } inline int poolId() const { return m_poolId; } inline int threadId() const { return m_threadId; } inline size_t size() const { return m_size; } @@ -106,6 +108,7 @@ private: uint64_t m_diff; uint64_t m_height; uint64_t m_target; + uint8_t m_seedHash[32]; uint8_t m_blob[kMaxBlobSize]; # ifdef XMRIG_PROXY_PROJECT diff --git a/src/base/net/stratum/Pool.cpp b/src/base/net/stratum/Pool.cpp index f441ba636..d3b4b4a31 100644 --- a/src/base/net/stratum/Pool.cpp +++ b/src/base/net/stratum/Pool.cpp @@ -517,6 +517,7 @@ void xmrig::Pool::rebuild() addVariant(VARIANT_RWZ); addVariant(VARIANT_ZLS); addVariant(VARIANT_DOUBLE); + addVariant(VARIANT_RX_WOW); addVariant(VARIANT_AUTO); # endif } diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index d9d3ead96..af139ae3c 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -69,6 +69,7 @@ static AlgoData const algorithms[] = { { "cryptonight/rwz", "cn/rwz", xmrig::CRYPTONIGHT, xmrig::VARIANT_RWZ }, { "cryptonight/zls", "cn/zls", xmrig::CRYPTONIGHT, xmrig::VARIANT_ZLS }, { "cryptonight/double", "cn/double", xmrig::CRYPTONIGHT, xmrig::VARIANT_DOUBLE }, + { "randomx/wow", "rx/wow", xmrig::CRYPTONIGHT, xmrig::VARIANT_RX_WOW }, # ifndef XMRIG_NO_AEON { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, @@ -138,7 +139,8 @@ static const char *variants[] = { "r", "rwz", "zls", - "double" + "double", + "rx/wow", }; diff --git a/src/common/xmrig.h b/src/common/xmrig.h index e8ca8857e..49a8d1f7e 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -79,6 +79,7 @@ enum Variant { VARIANT_RWZ = 14, // CryptoNight variant 2 with 3/4 iterations and reversed shuffle operation (Graft) VARIANT_ZLS = 15, // CryptoNight variant 2 with 3/4 iterations (Zelerius) VARIANT_DOUBLE = 16, // CryptoNight variant 2 with double iterations (X-CASH) + VARIANT_RX_WOW = 17, // RandomX (Wownero) VARIANT_MAX }; diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 2481162ce..3bce832e0 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -390,6 +390,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW + # ifndef XMRIG_NO_AEON cryptonight_single_hash, cryptonight_double_hash, @@ -428,6 +430,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 @@ -446,6 +449,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW # endif # ifndef XMRIG_NO_SUMO @@ -498,6 +502,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 @@ -516,6 +521,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW # endif # ifndef XMRIG_NO_CN_PICO @@ -547,6 +553,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 @@ -565,6 +572,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW # endif }; diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 8b9e0881a..40caf3806 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -38,6 +38,12 @@ MultiWorker::MultiWorker(ThreadHandle *handle) : Worker(handle) { m_memory = Mem::create(m_ctx, m_thread->algorithm(), N); + + const int flags = RANDOMX_FLAG_LARGE_PAGES | RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT; + m_rx_vm = randomx_create_vm(static_cast(flags), nullptr, Workers::getDataset()); + if (!m_rx_vm) { + m_rx_vm = randomx_create_vm(static_cast(flags - RANDOMX_FLAG_LARGE_PAGES), nullptr, Workers::getDataset()); + } } @@ -45,6 +51,7 @@ template MultiWorker::~MultiWorker() { Mem::release(m_ctx, N, m_memory); + randomx_destroy_vm(m_rx_vm); } @@ -126,7 +133,14 @@ void MultiWorker::start() storeStats(); } - m_thread->fn(m_state.job.algorithm().variant())(m_state.blob, m_state.job.size(), m_hash, m_ctx, m_state.job.height()); + const xmrig::Variant v = m_state.job.algorithm().variant(); + if (v == xmrig::VARIANT_RX_WOW) { + Workers::updateDataset(m_state.job.seed_hash(), m_totalWays); + randomx_calculate_hash(m_rx_vm, m_state.blob, m_state.job.size(), m_hash); + } + else { + m_thread->fn(v)(m_state.blob, m_state.job.size(), m_hash, m_ctx, m_state.job.height()); + } for (size_t i = 0; i < N; ++i) { if (*reinterpret_cast(m_hash + (i * 32) + 24) < m_state.job.target()) { diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index 99d37e442..98acded96 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -31,6 +31,7 @@ #include "Mem.h" #include "net/JobResult.h" #include "workers/Worker.h" +#include "randomwow.h" class Handle; @@ -70,6 +71,8 @@ private: State m_pausedState; State m_state; uint8_t m_hash[N * 32]; + + randomx_vm* m_rx_vm; }; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 539901354..54373cc96 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -59,6 +59,11 @@ uv_mutex_t Workers::m_mutex; uv_rwlock_t Workers::m_rwlock; uv_timer_t *Workers::m_timer = nullptr; xmrig::Controller *Workers::m_controller = nullptr; +uv_rwlock_t Workers::m_rx_dataset_lock; +randomx_cache *Workers::m_rx_cache = nullptr; +randomx_dataset *Workers::m_rx_dataset = nullptr; +uint8_t Workers::m_rx_seed_hash[32] = {}; +std::atomic Workers::m_rx_dataset_init_thread_counter = 0; xmrig::Job Workers::job() @@ -187,6 +192,7 @@ void Workers::start(xmrig::Controller *controller) uv_mutex_init(&m_mutex); uv_rwlock_init(&m_rwlock); + uv_rwlock_init(&m_rx_dataset_lock); m_sequence = 1; m_paused = 1; @@ -356,3 +362,61 @@ void Workers::start(IWorker *worker) worker->start(); } + +void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads) +{ + // Check if we need to update cache and dataset + if (memcmp(m_rx_seed_hash, seed_hash, sizeof(m_rx_seed_hash)) == 0) + return; + + const uint32_t thread_id = m_rx_dataset_init_thread_counter++; + LOG_NOTICE("Thread %u started updating RandomX dataset", thread_id); + + // Wait for all threads to get here + do { + std::this_thread::yield(); + } while (m_rx_dataset_init_thread_counter.load() != num_threads); + + // One of the threads updates cache + uv_rwlock_wrlock(&m_rx_dataset_lock); + if (memcmp(m_rx_seed_hash, seed_hash, sizeof(m_rx_seed_hash)) != 0) { + memcpy(m_rx_seed_hash, seed_hash, sizeof(m_rx_seed_hash)); + randomx_init_cache(m_rx_cache, m_rx_seed_hash, sizeof(m_rx_seed_hash)); + } + uv_rwlock_wrunlock(&m_rx_dataset_lock); + + // All threads update dataset + const uint32_t a = (randomx_dataset_item_count() * thread_id) / num_threads; + const uint32_t b = (randomx_dataset_item_count() * (thread_id + 1)) / num_threads; + randomx_init_dataset(m_rx_dataset, m_rx_cache, a, b - a); + + LOG_NOTICE("Thread %u finished updating RandomX dataset", thread_id); + + // Wait for all threads to complete + --m_rx_dataset_init_thread_counter; + do { + std::this_thread::yield(); + } while (m_rx_dataset_init_thread_counter.load() != 0); +} + +randomx_dataset* Workers::getDataset() +{ + if (m_rx_dataset) + return m_rx_dataset; + + uv_rwlock_wrlock(&m_rx_dataset_lock); + if (!m_rx_dataset) { + randomx_dataset* dataset = randomx_alloc_dataset(RANDOMX_FLAG_LARGE_PAGES); + if (!dataset) { + dataset = randomx_alloc_dataset(RANDOMX_FLAG_DEFAULT); + } + m_rx_cache = randomx_alloc_cache(static_cast(RANDOMX_FLAG_JIT | RANDOMX_FLAG_LARGE_PAGES)); + if (!m_rx_cache) { + m_rx_cache = randomx_alloc_cache(RANDOMX_FLAG_JIT); + } + m_rx_dataset = dataset; + } + uv_rwlock_wrunlock(&m_rx_dataset_lock); + + return m_rx_dataset; +} diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 5b084fc2d..3f6e307d4 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -34,6 +34,7 @@ #include "base/net/stratum/Job.h" #include "net/JobResult.h" #include "rapidjson/fwd.h" +#include "randomwow.h" class Hashrate; @@ -72,6 +73,9 @@ public: static void threadsSummary(rapidjson::Document &doc); # endif + static void updateDataset(const uint8_t* seed_hash, uint32_t num_threads); + static randomx_dataset* getDataset(); + private: static void onReady(void *arg); static void onResult(uv_async_t *handle); @@ -114,6 +118,12 @@ private: static uv_rwlock_t m_rwlock; static uv_timer_t *m_timer; static xmrig::Controller *m_controller; + + static uv_rwlock_t m_rx_dataset_lock; + static randomx_cache *m_rx_cache; + static randomx_dataset *m_rx_dataset; + static uint8_t m_rx_seed_hash[32]; + static std::atomic m_rx_dataset_init_thread_counter; }; From 202d44c14704329c41edc194e1b11ec2e6644071 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sat, 15 Jun 2019 23:29:13 +0200 Subject: [PATCH 16/26] Fixed gcc compilation --- src/workers/Workers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 54373cc96..591f92d03 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -63,7 +63,7 @@ uv_rwlock_t Workers::m_rx_dataset_lock; randomx_cache *Workers::m_rx_cache = nullptr; randomx_dataset *Workers::m_rx_dataset = nullptr; uint8_t Workers::m_rx_seed_hash[32] = {}; -std::atomic Workers::m_rx_dataset_init_thread_counter = 0; +std::atomic Workers::m_rx_dataset_init_thread_counter = {}; xmrig::Job Workers::job() From d0ce60a73aa103dcc00da85d6b19b73c263b116a Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sat, 15 Jun 2019 23:50:31 +0200 Subject: [PATCH 17/26] Fixed auto-config --- src/core/config/Config.cpp | 3 ++- src/crypto/CryptoNight_constants.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index 88ddbb72f..fb3fefaca 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -160,7 +160,8 @@ bool xmrig::Config::finalize() const AlgoVariant av = getAlgoVariant(); m_threads.mode = m_threads.count ? Simple : Automatic; - const size_t size = CpuThread::multiway(av) * cn_select_memory(m_algorithm.algo()) / 1024; + const Variant v = m_algorithm.variant(); + const size_t size = CpuThread::multiway(av) * cn_select_memory(m_algorithm.algo(), v) / 1024; if (!m_threads.count) { m_threads.count = Cpu::info()->optimalThreadsCount(size, m_maxCpuUsage); diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 1bc06a3bb..4a66c16b2 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -70,12 +70,12 @@ template<> inline constexpr size_t cn_select_memory() { retur template<> inline constexpr size_t cn_select_memory() { return CRYPTONIGHT_PICO_MEMORY; } -inline size_t cn_select_memory(Algo algorithm) +inline size_t cn_select_memory(Algo algorithm, Variant v = VARIANT_AUTO) { switch(algorithm) { case CRYPTONIGHT: - return CRYPTONIGHT_MEMORY; + return (v == VARIANT_RX_WOW) ? CRYPTONIGHT_LITE_MEMORY : CRYPTONIGHT_MEMORY; case CRYPTONIGHT_LITE: return CRYPTONIGHT_LITE_MEMORY; From 50ace41766743b3462fe0d02ba982782c1aa2c3b Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sat, 15 Jun 2019 23:52:39 +0200 Subject: [PATCH 18/26] Fixed cmake for Linux --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f6e9226b..0724cfdb9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,7 +154,7 @@ add_definitions(/DUNICODE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") find_package(UV REQUIRED) -find_package(RANDOMWOW REQUIRED) +find_package(RandomWOW REQUIRED) include(cmake/flags.cmake) From 34e39e99466cafec83564ab836d8dcb00cdaacb2 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 18 Jun 2019 05:13:51 +0700 Subject: [PATCH 19/26] Use canonical name for RandomX, because official RandomWOW repo not rename lib or headers, still need some solution to separate it in future. --- CMakeLists.txt | 6 +++--- cmake/FindRandomWOW.cmake | 25 ------------------------- cmake/FindRandomX.cmake | 25 +++++++++++++++++++++++++ src/workers/MultiWorker.h | 4 +++- src/workers/Workers.h | 2 +- 5 files changed, 32 insertions(+), 30 deletions(-) delete mode 100644 cmake/FindRandomWOW.cmake create mode 100644 cmake/FindRandomX.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0724cfdb9..b04a99b86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,7 +154,7 @@ add_definitions(/DUNICODE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") find_package(UV REQUIRED) -find_package(RandomWOW REQUIRED) +find_package(RandomX REQUIRED) include(cmake/flags.cmake) @@ -220,7 +220,7 @@ endif() include_directories(src) include_directories(src/3rdparty) include_directories(${UV_INCLUDE_DIR}) -include_directories(${RANDOMWOW_INCLUDE_DIR}) +include_directories(${RANDOMX_INCLUDE_DIR}) if (BUILD_STATIC) set(CMAKE_EXE_LINKER_FLAGS " -static") @@ -231,4 +231,4 @@ if (WITH_DEBUG_LOG) endif() add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTP_SOURCES} ${TLS_SOURCES} ${XMRIG_ASM_SOURCES} ${CN_GPU_SOURCES}) -target_link_libraries(${CMAKE_PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${RANDOMWOW_LIBRARIES} ${EXTRA_LIBS} ${CPUID_LIB}) +target_link_libraries(${CMAKE_PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${RANDOMX_LIBRARIES} ${EXTRA_LIBS} ${CPUID_LIB}) diff --git a/cmake/FindRandomWOW.cmake b/cmake/FindRandomWOW.cmake deleted file mode 100644 index c1db649fa..000000000 --- a/cmake/FindRandomWOW.cmake +++ /dev/null @@ -1,25 +0,0 @@ -find_path( - RANDOMWOW_INCLUDE_DIR - NAMES randomwow.h - PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" - PATH_SUFFIXES "include" - NO_DEFAULT_PATH -) - -find_path(RANDOMWOW_INCLUDE_DIR NAMES randomwow.h) - -find_library( - RANDOMWOW_LIBRARY - NAMES librandomwow.a randomwow librandomwow - PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" - PATH_SUFFIXES "lib" - NO_DEFAULT_PATH -) - -find_library(RANDOMWOW_LIBRARY NAMES librandomwow.a randomwow librandomwow) - -set(RANDOMWOW_LIBRARIES ${RANDOMWOW_LIBRARY}) -set(RANDOMWOW_INCLUDE_DIRS ${RANDOMWOW_INCLUDE_DIR}) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(RANDOMWOW DEFAULT_MSG RANDOMWOW_LIBRARY RANDOMWOW_INCLUDE_DIR) diff --git a/cmake/FindRandomX.cmake b/cmake/FindRandomX.cmake new file mode 100644 index 000000000..5696d5637 --- /dev/null +++ b/cmake/FindRandomX.cmake @@ -0,0 +1,25 @@ +find_path( + RANDOMX_INCLUDE_DIR + NAMES randomx.h + PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" + PATH_SUFFIXES "include" + NO_DEFAULT_PATH +) + +find_path(RANDOMX_INCLUDE_DIR NAMES randomx.h) + +find_library( + RANDOMX_LIBRARY + NAMES librandomx.a randomx librandomx + PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" + PATH_SUFFIXES "lib" + NO_DEFAULT_PATH +) + +find_library(RANDOMX_LIBRARY NAMES librandomx.a randomx librandomx) + +set(RANDOMX_LIBRARIES ${RANDOMX_LIBRARY}) +set(RANDOMX_INCLUDE_DIRS ${RANDOMX_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(RANDOMX DEFAULT_MSG RANDOMX_LIBRARY RANDOMX_INCLUDE_DIR) diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index 98acded96..874949937 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -27,11 +27,13 @@ #define XMRIG_MULTIWORKER_H +#include + + #include "base/net/stratum/Job.h" #include "Mem.h" #include "net/JobResult.h" #include "workers/Worker.h" -#include "randomwow.h" class Handle; diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 3f6e307d4..3fa1d8181 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -30,11 +30,11 @@ #include #include #include +#include #include "base/net/stratum/Job.h" #include "net/JobResult.h" #include "rapidjson/fwd.h" -#include "randomwow.h" class Hashrate; From 2a07cf391d6b9dd845b6ad26d3239748de8d7843 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 18 Jun 2019 06:11:53 +0700 Subject: [PATCH 20/26] Allow disable RandomX support. --- CMakeLists.txt | 14 ++++++++++++-- src/crypto/common/Algorithm.cpp | 3 +++ src/workers/MultiWorker.cpp | 11 ++++++++++- src/workers/MultiWorker.h | 8 ++++++-- src/workers/Workers.cpp | 13 +++++++++++-- src/workers/Workers.h | 9 ++++++++- 6 files changed, 50 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f515b1ae..697f3da5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ option(WITH_CN_LITE "CryptoNight-Lite support" ON) option(WITH_CN_HEAVY "CryptoNight-Heavy support" ON) option(WITH_CN_PICO "CryptoNight-Pico support" ON) option(WITH_CN_GPU "CryptoNight-GPU support" ON) +option(WITH_RANDOMX "RandomX support" ON) option(WITH_HTTP "HTTP protocol support (client/server)" ON) option(WITH_DEBUG_LOG "Enable debug log output" OFF) option(WITH_TLS "Enable OpenSSL support" ON) @@ -158,7 +159,17 @@ add_definitions(/DUNICODE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") find_package(UV REQUIRED) -find_package(RandomX REQUIRED) + +if (WITH_RANDOMX) + find_package(RandomX REQUIRED) + include_directories(${RANDOMX_INCLUDE_DIR}) + + add_definitions(/DXMRIG_ALGO_RANDOMX) +else() + set(RANDOMX_LIBRARIES "") + + remove_definitions(/DXMRIG_ALGO_RANDOMX) +endif() include(cmake/flags.cmake) @@ -220,7 +231,6 @@ endif() include_directories(src) include_directories(src/3rdparty) include_directories(${UV_INCLUDE_DIR}) -include_directories(${RANDOMX_INCLUDE_DIR}) if (BUILD_STATIC) set(CMAKE_EXE_LINKER_FLAGS " -static") diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index 6d8d9a65a..6f53f6a84 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -69,7 +69,10 @@ static AlgoData const algorithms[] = { { "cryptonight/rwz", "cn/rwz", xmrig::CRYPTONIGHT, xmrig::VARIANT_RWZ }, { "cryptonight/zls", "cn/zls", xmrig::CRYPTONIGHT, xmrig::VARIANT_ZLS }, { "cryptonight/double", "cn/double", xmrig::CRYPTONIGHT, xmrig::VARIANT_DOUBLE }, + +# ifdef XMRIG_ALGO_RANDOMX { "randomx/wow", "rx/wow", xmrig::CRYPTONIGHT, xmrig::VARIANT_RX_WOW }, +# endif # ifdef XMRIG_ALGO_CN_LITE { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index d5a5af27f..e8a406691 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -39,11 +39,13 @@ MultiWorker::MultiWorker(ThreadHandle *handle) { m_memory = Mem::create(m_ctx, m_thread->algorithm(), N); +# ifdef XMRIG_ALGO_RANDOMX const int flags = RANDOMX_FLAG_LARGE_PAGES | RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT; m_rx_vm = randomx_create_vm(static_cast(flags), nullptr, Workers::getDataset()); if (!m_rx_vm) { m_rx_vm = randomx_create_vm(static_cast(flags - RANDOMX_FLAG_LARGE_PAGES), nullptr, Workers::getDataset()); } +# endif } @@ -51,7 +53,10 @@ template MultiWorker::~MultiWorker() { Mem::release(m_ctx, N, m_memory); + +# ifdef XMRIG_ALGO_RANDOMX randomx_destroy_vm(m_rx_vm); +# endif } @@ -134,11 +139,15 @@ void MultiWorker::start() } const xmrig::Variant v = m_state.job.algorithm().variant(); + +# ifdef XMRIG_ALGO_RANDOMX if (v == xmrig::VARIANT_RX_WOW) { Workers::updateDataset(m_state.job.seed_hash(), m_totalWays); randomx_calculate_hash(m_rx_vm, m_state.blob, m_state.job.size(), m_hash); } - else { + else +# endif + { m_thread->fn(v)(m_state.blob, m_state.job.size(), m_hash, m_ctx, m_state.job.height()); } diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index 874949937..63dd78964 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -27,7 +27,9 @@ #define XMRIG_MULTIWORKER_H -#include +#ifdef XMRIG_ALGO_RANDOMX +# include +#endif #include "base/net/stratum/Job.h" @@ -74,7 +76,9 @@ private: State m_state; uint8_t m_hash[N * 32]; - randomx_vm* m_rx_vm; +# ifdef XMRIG_ALGO_RANDOMX + randomx_vm *m_rx_vm = nullptr; +# endif }; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 5a23f6be3..18210b677 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -59,11 +59,14 @@ uv_mutex_t Workers::m_mutex; uv_rwlock_t Workers::m_rwlock; uv_timer_t *Workers::m_timer = nullptr; xmrig::Controller *Workers::m_controller = nullptr; + +#ifdef XMRIG_ALGO_RANDOMX uv_rwlock_t Workers::m_rx_dataset_lock; randomx_cache *Workers::m_rx_cache = nullptr; randomx_dataset *Workers::m_rx_dataset = nullptr; uint8_t Workers::m_rx_seed_hash[32] = {}; std::atomic Workers::m_rx_dataset_init_thread_counter = {}; +#endif xmrig::Job Workers::job() @@ -192,7 +195,10 @@ void Workers::start(xmrig::Controller *controller) uv_mutex_init(&m_mutex); uv_rwlock_init(&m_rwlock); + +# ifdef XMRIG_ALGO_RANDOMX uv_rwlock_init(&m_rx_dataset_lock); +# endif m_sequence = 1; m_paused = 1; @@ -363,6 +369,8 @@ void Workers::start(IWorker *worker) worker->start(); } + +#ifdef XMRIG_ALGO_RANDOMX void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads) { // Check if we need to update cache and dataset @@ -370,7 +378,7 @@ void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads return; const uint32_t thread_id = m_rx_dataset_init_thread_counter++; - LOG_NOTICE("Thread %u started updating RandomX dataset", thread_id); + LOG_DEBUG("Thread %u started updating RandomX dataset", thread_id); // Wait for all threads to get here do { @@ -390,7 +398,7 @@ void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads const uint32_t b = (randomx_dataset_item_count() * (thread_id + 1)) / num_threads; randomx_init_dataset(m_rx_dataset, m_rx_cache, a, b - a); - LOG_NOTICE("Thread %u finished updating RandomX dataset", thread_id); + LOG_DEBUG("Thread %u finished updating RandomX dataset", thread_id); // Wait for all threads to complete --m_rx_dataset_init_thread_counter; @@ -420,3 +428,4 @@ randomx_dataset* Workers::getDataset() return m_rx_dataset; } +#endif diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 3fa1d8181..39f3d5f66 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -30,7 +30,10 @@ #include #include #include -#include + +#ifdef XMRIG_ALGO_RANDOMX +# include +#endif #include "base/net/stratum/Job.h" #include "net/JobResult.h" @@ -73,8 +76,10 @@ public: static void threadsSummary(rapidjson::Document &doc); # endif +# ifdef XMRIG_ALGO_RANDOMX static void updateDataset(const uint8_t* seed_hash, uint32_t num_threads); static randomx_dataset* getDataset(); +# endif private: static void onReady(void *arg); @@ -119,11 +124,13 @@ private: static uv_timer_t *m_timer; static xmrig::Controller *m_controller; +# ifdef XMRIG_ALGO_RANDOMX static uv_rwlock_t m_rx_dataset_lock; static randomx_cache *m_rx_cache; static randomx_dataset *m_rx_dataset; static uint8_t m_rx_seed_hash[32]; static std::atomic m_rx_dataset_init_thread_counter; +# endif }; From e8ac01d289280fdcc400e055b4e62826c89af792 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 18 Jun 2019 19:53:11 +0200 Subject: [PATCH 21/26] RandomX fixes - Fixed possible infinite loop when updating RandomX dataset - Fixed used memory display - Allocate dataset and VM for RandomX only when it's actually used --- src/workers/MultiWorker.cpp | 25 ++++++++++++++++++------- src/workers/MultiWorker.h | 2 ++ src/workers/Workers.cpp | 13 +++++++++++-- src/workers/Workers.h | 4 +++- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 40caf3806..aed38d635 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -36,14 +36,9 @@ template MultiWorker::MultiWorker(ThreadHandle *handle) : Worker(handle) + , m_rx_vm(nullptr) { m_memory = Mem::create(m_ctx, m_thread->algorithm(), N); - - const int flags = RANDOMX_FLAG_LARGE_PAGES | RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT; - m_rx_vm = randomx_create_vm(static_cast(flags), nullptr, Workers::getDataset()); - if (!m_rx_vm) { - m_rx_vm = randomx_create_vm(static_cast(flags - RANDOMX_FLAG_LARGE_PAGES), nullptr, Workers::getDataset()); - } } @@ -51,7 +46,22 @@ template MultiWorker::~MultiWorker() { Mem::release(m_ctx, N, m_memory); - randomx_destroy_vm(m_rx_vm); + if (m_rx_vm) { + randomx_destroy_vm(m_rx_vm); + } +} + + +template +void MultiWorker::allocateRandomX_VM() +{ + if (!m_rx_vm) { + const int flags = RANDOMX_FLAG_LARGE_PAGES | RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT; + m_rx_vm = randomx_create_vm(static_cast(flags), nullptr, Workers::getDataset()); + if (!m_rx_vm) { + m_rx_vm = randomx_create_vm(static_cast(flags - RANDOMX_FLAG_LARGE_PAGES), nullptr, Workers::getDataset()); + } + } } @@ -135,6 +145,7 @@ void MultiWorker::start() const xmrig::Variant v = m_state.job.algorithm().variant(); if (v == xmrig::VARIANT_RX_WOW) { + allocateRandomX_VM(); Workers::updateDataset(m_state.job.seed_hash(), m_totalWays); randomx_calculate_hash(m_rx_vm, m_state.blob, m_state.job.size(), m_hash); } diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index 98acded96..54d8c457f 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -49,6 +49,8 @@ protected: void start() override; private: + void allocateRandomX_VM(); + bool resume(const xmrig::Job &job); bool verify(xmrig::Variant variant, const uint8_t *referenceValue); bool verify2(xmrig::Variant variant, const uint8_t *referenceValue); diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 591f92d03..3819eb491 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -182,6 +182,7 @@ void Workers::start(xmrig::Controller *controller) const std::vector &threads = controller->config()->threads(); m_status.algo = controller->config()->algorithm().algo(); + m_status.variant = controller->config()->algorithm().variant(); m_status.threads = threads.size(); for (const xmrig::IThread *thread : threads) { @@ -246,7 +247,7 @@ void Workers::threadsSummary(rapidjson::Document &doc) { uv_mutex_lock(&m_mutex); const uint64_t pages[2] = { m_status.hugePages, m_status.pages }; - const uint64_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo); + const uint64_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo, m_status.variant); uv_mutex_unlock(&m_mutex); auto &allocator = doc.GetAllocator(); @@ -350,7 +351,7 @@ void Workers::start(IWorker *worker) if (m_status.started == m_status.threads) { const double percent = (double) m_status.hugePages / m_status.pages * 100.0; - const size_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo) / 1024; + const size_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo, m_status.variant) / 1024; LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") "", m_status.threads, m_status.ways, @@ -374,6 +375,10 @@ void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads // Wait for all threads to get here do { + if (m_sequence.load(std::memory_order_relaxed) == 0) { + // Exit immediately if workers were stopped + return; + } std::this_thread::yield(); } while (m_rx_dataset_init_thread_counter.load() != num_threads); @@ -395,6 +400,10 @@ void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads // Wait for all threads to complete --m_rx_dataset_init_thread_counter; do { + if (m_sequence.load(std::memory_order_relaxed) == 0) { + // Exit immediately if workers were stopped + return; + } std::this_thread::yield(); } while (m_rx_dataset_init_thread_counter.load() != 0); } diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 3f6e307d4..08ebed7f4 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -91,7 +91,8 @@ private: started(0), threads(0), ways(0), - algo(xmrig::CRYPTONIGHT) + algo(xmrig::CRYPTONIGHT), + variant(xmrig::VARIANT_AUTO) {} size_t hugePages; @@ -100,6 +101,7 @@ private: size_t threads; size_t ways; xmrig::Algo algo; + xmrig::Variant variant; }; static bool m_active; From 41e0be111d6dec800e5695340eb60986d0a5321e Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 19 Jun 2019 01:18:31 +0700 Subject: [PATCH 22/26] v2.16.0-evo, added RandomWOW, backward compatibility with previous versions not break. --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index 309f88737..3efea229e 100644 --- a/src/version.h +++ b/src/version.h @@ -28,14 +28,14 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "2.99.0-evo" +#define APP_VERSION "2.16.0-evo" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com" #define APP_KIND "cpu" #define APP_VER_MAJOR 2 -#define APP_VER_MINOR 99 +#define APP_VER_MINOR 16 #define APP_VER_PATCH 0 #ifdef _MSC_VER From 187e55e28e0a9a4bf508926962a60b9854405dd7 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 19 Jun 2019 12:45:05 +0200 Subject: [PATCH 23/26] Fixed RandomX for CPUs without AES --- src/workers/MultiWorker.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index aed38d635..392f71e77 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -31,6 +31,7 @@ #include "workers/CpuThread.h" #include "workers/MultiWorker.h" #include "workers/Workers.h" +#include "common/cpu/Cpu.h" template @@ -56,7 +57,10 @@ template void MultiWorker::allocateRandomX_VM() { if (!m_rx_vm) { - const int flags = RANDOMX_FLAG_LARGE_PAGES | RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT; + int flags = RANDOMX_FLAG_LARGE_PAGES | RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT; + if (xmrig::Cpu::info()->hasAES()) + flags |= RANDOMX_FLAG_HARD_AES; + m_rx_vm = randomx_create_vm(static_cast(flags), nullptr, Workers::getDataset()); if (!m_rx_vm) { m_rx_vm = randomx_create_vm(static_cast(flags - RANDOMX_FLAG_LARGE_PAGES), nullptr, Workers::getDataset()); From cf61f4974602cc9af8205975cf7ed7e67dbfe89e Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 23 Jun 2019 14:23:29 +0700 Subject: [PATCH 24/26] Use better source for AES settings in RandomX threads. --- src/core/config/Config.cpp | 11 ++++++++--- src/core/config/Config.h | 2 +- src/workers/MultiWorker.cpp | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index 52a1e5504..450f587e5 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -56,6 +56,12 @@ xmrig::Config::Config() : } +bool xmrig::Config::isHwAES() const +{ + return (m_aesMode == AES_AUTO ? (Cpu::info()->hasAES() ? AES_HW : AES_SOFT) : m_aesMode) == AES_HW; +} + + bool xmrig::Config::read(const IJsonReader &reader, const char *fileName) { if (!BaseConfig::read(reader, fileName)) { @@ -147,11 +153,10 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const bool xmrig::Config::finalize() { if (!m_threads.cpu.empty()) { - m_threads.mode = Advanced; - const bool softAES = (m_aesMode == AES_AUTO ? (Cpu::info()->hasAES() ? AES_HW : AES_SOFT) : m_aesMode) == AES_SOFT; + m_threads.mode = Advanced; for (size_t i = 0; i < m_threads.cpu.size(); ++i) { - m_threads.list.push_back(CpuThread::createFromData(i, m_algorithm.algo(), m_threads.cpu[i], m_priority, softAES)); + m_threads.list.push_back(CpuThread::createFromData(i, m_algorithm.algo(), m_threads.cpu[i], m_priority, !isHwAES())); } return true; diff --git a/src/core/config/Config.h b/src/core/config/Config.h index 4bcb8bba3..1d8a42d91 100644 --- a/src/core/config/Config.h +++ b/src/core/config/Config.h @@ -67,10 +67,10 @@ public: Config(); + bool isHwAES() const; bool read(const IJsonReader &reader, const char *fileName) override; void getJSON(rapidjson::Document &doc) const override; - inline AesMode aesMode() const { return m_aesMode; } inline AlgoVariant algoVariant() const { return m_algoVariant; } inline Assembly assembly() const { return m_assembly; } inline bool isHugePages() const { return m_hugePages; } diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index e15b51b7a..b5f465e4c 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -31,7 +31,6 @@ #include "workers/CpuThread.h" #include "workers/MultiWorker.h" #include "workers/Workers.h" -#include "common/cpu/Cpu.h" template @@ -61,8 +60,9 @@ void MultiWorker::allocateRandomX_VM() { if (!m_rx_vm) { int flags = RANDOMX_FLAG_LARGE_PAGES | RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT; - if (xmrig::Cpu::info()->hasAES()) + if (!m_thread->isSoftAES()) { flags |= RANDOMX_FLAG_HARD_AES; + } m_rx_vm = randomx_create_vm(static_cast(flags), nullptr, Workers::getDataset()); if (!m_rx_vm) { From f7f2c09e89bb615378f74394d4c9883189ba5dd0 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 25 Jun 2019 08:21:40 +0700 Subject: [PATCH 25/26] Move RandowWOW to new global algorithm. --- src/Mem.cpp | 4 ++++ src/Mem.h | 8 ++++---- src/common/xmrig.h | 1 + src/crypto/cn/CryptoNight_constants.h | 5 ++++- src/crypto/common/Algorithm.cpp | 3 ++- src/workers/CpuThread.cpp | 18 ++++++++++++++++++ src/workers/MultiWorker.cpp | 10 +++++++++- src/workers/Workers.cpp | 16 ++++++++++++---- 8 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/Mem.cpp b/src/Mem.cpp index b9e0fbf96..4ae1971ff 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -68,6 +68,10 @@ MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count) void Mem::release(cryptonight_ctx **ctx, size_t count, MemInfo &info) { + if (info.memory == nullptr) { + return; + } + release(info); for (size_t i = 0; i < count; ++i) { diff --git a/src/Mem.h b/src/Mem.h index bfb36b002..629f5baab 100644 --- a/src/Mem.h +++ b/src/Mem.h @@ -39,11 +39,11 @@ struct cryptonight_ctx; struct MemInfo { - alignas(16) uint8_t *memory; + alignas(16) uint8_t *memory = nullptr; - size_t hugePages; - size_t pages; - size_t size; + size_t hugePages = 0; + size_t pages = 0; + size_t size = 0; }; diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 49a8d1f7e..e8aa505a3 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -36,6 +36,7 @@ enum Algo { CRYPTONIGHT_LITE, /* CryptoNight (1 MB) */ CRYPTONIGHT_HEAVY, /* CryptoNight (4 MB) */ CRYPTONIGHT_PICO, /* CryptoNight (256 KB) */ + RANDOM_X, /* RandomX */ ALGO_MAX }; diff --git a/src/crypto/cn/CryptoNight_constants.h b/src/crypto/cn/CryptoNight_constants.h index 4a66c16b2..d06369b4b 100644 --- a/src/crypto/cn/CryptoNight_constants.h +++ b/src/crypto/cn/CryptoNight_constants.h @@ -75,7 +75,7 @@ inline size_t cn_select_memory(Algo algorithm, Variant v = VARIANT_AUTO) switch(algorithm) { case CRYPTONIGHT: - return (v == VARIANT_RX_WOW) ? CRYPTONIGHT_LITE_MEMORY : CRYPTONIGHT_MEMORY; + return CRYPTONIGHT_MEMORY; case CRYPTONIGHT_LITE: return CRYPTONIGHT_LITE_MEMORY; @@ -86,6 +86,9 @@ inline size_t cn_select_memory(Algo algorithm, Variant v = VARIANT_AUTO) case CRYPTONIGHT_PICO: return CRYPTONIGHT_PICO_MEMORY; + case RANDOM_X: + return (v == VARIANT_RX_WOW) ? CRYPTONIGHT_LITE_MEMORY : CRYPTONIGHT_MEMORY; + default: break; } diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index 6f53f6a84..c706ae0cb 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -71,7 +71,8 @@ static AlgoData const algorithms[] = { { "cryptonight/double", "cn/double", xmrig::CRYPTONIGHT, xmrig::VARIANT_DOUBLE }, # ifdef XMRIG_ALGO_RANDOMX - { "randomx/wow", "rx/wow", xmrig::CRYPTONIGHT, xmrig::VARIANT_RX_WOW }, + { "randomx/wow", "rx/wow", xmrig::RANDOM_X, xmrig::VARIANT_RX_WOW }, + { "randomx", "rx", xmrig::RANDOM_X, xmrig::VARIANT_RX_WOW }, # endif # ifdef XMRIG_ALGO_CN_LITE diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 3aece084f..de99a0cdb 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -574,6 +574,24 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW # endif + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0 + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TUBE + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XTL + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_MSR + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XAO + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RTO + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_2 + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_HALF + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TRTL + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_GPU + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_WOW + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_4 + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW }; static_assert(count == sizeof(func_table) / sizeof(func_table[0]), "func_table size mismatch"); diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index b5f465e4c..e1ef12b25 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -37,7 +37,9 @@ template MultiWorker::MultiWorker(ThreadHandle *handle) : Worker(handle) { - m_memory = Mem::create(m_ctx, m_thread->algorithm(), N); + if (m_thread->algorithm() != xmrig::RANDOM_X) { + m_memory = Mem::create(m_ctx, m_thread->algorithm(), N); + } } @@ -125,6 +127,12 @@ bool MultiWorker::selfTest() } # endif +# ifdef XMRIG_ALGO_RANDOMX + if (m_thread->algorithm() == RANDOM_X) { + return true; + } +# endif + return false; } diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 5995dcb97..458db4a51 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -359,10 +359,18 @@ void Workers::start(IWorker *worker) const double percent = (double) m_status.hugePages / m_status.pages * 100.0; const size_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo, m_status.variant) / 1024; - LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") "", - m_status.threads, m_status.ways, - (m_status.hugePages == m_status.pages ? GREEN_BOLD_S : (m_status.hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)), - m_status.hugePages, m_status.pages, percent, memory); +# ifdef XMRIG_ALGO_RANDOMX + if (m_status.algo == xmrig::RANDOM_X) { + LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " memory " CYAN_BOLD("%zu KB") "", + m_status.threads, m_status.ways, memory); + } else +# endif + { + LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") "", + m_status.threads, m_status.ways, + (m_status.hugePages == m_status.pages ? GREEN_BOLD_S : (m_status.hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)), + m_status.hugePages, m_status.pages, percent, memory); + } } uv_mutex_unlock(&m_mutex); From b0a1481909aa0f902cac05932e46d6f0015ea452 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 25 Jun 2019 10:35:10 +0700 Subject: [PATCH 26/26] Sync changes with proxy. --- src/base/net/stratum/Client.cpp | 18 +++------------- src/base/net/stratum/DaemonClient.cpp | 1 - src/base/net/stratum/Job.cpp | 31 ++++++++++++++++----------- src/base/net/stratum/Job.h | 14 ++++++------ src/workers/MultiWorker.cpp | 2 +- 5 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 4941ca3a0..7ee0228b4 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -37,6 +37,7 @@ #endif +#include "base/io/json/Json.h" #include "base/io/json/JsonRequest.h" #include "base/io/log/Log.h" #include "base/kernel/interfaces/IClientListener.h" @@ -344,21 +345,8 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code) } } - if (params.HasMember("seed_hash")) { - const rapidjson::Value &variant = params["seed_hash"]; - - if (variant.IsString()) { - job.setSeedHash(variant.GetString()); - } - } - - if (params.HasMember("height")) { - const rapidjson::Value &variant = params["height"]; - - if (variant.IsUint64()) { - job.setHeight(variant.GetUint64()); - } - } + job.setSeedHash(Json::getString(params, "seed_hash")); + job.setHeight(Json::getUint64(params, "height")); if (!verifyAlgorithm(job.algorithm())) { *code = 6; diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index e63c3271d..70cc9151d 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -221,7 +221,6 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code) } job.setSeedHash(Json::getString(params, "seed_hash")); - job.setHeight(Json::getUint64(params, kHeight)); job.setDiff(Json::getUint64(params, "difficulty")); job.setId(blocktemplate.data() + blocktemplate.size() - 32); diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index 36098bfe9..b4ebb2c03 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -42,8 +42,8 @@ xmrig::Job::Job() : m_diff(0), m_height(0), m_target(0), - m_seedHash(), - m_blob() + m_blob(), + m_seedHash() { } @@ -59,8 +59,8 @@ xmrig::Job::Job(int poolId, bool nicehash, const Algorithm &algorithm, const Str m_diff(0), m_height(0), m_target(0), - m_seedHash(), - m_blob() + m_blob(), + m_seedHash() { } @@ -113,6 +113,20 @@ bool xmrig::Job::setBlob(const char *blob) } +bool xmrig::Job::setSeedHash(const char *hash) +{ + if (!hash || (strlen(hash) != sizeof(m_seedHash) * 2)) { + return false; + } + +# ifdef XMRIG_PROXY_PROJECT + m_rawSeedHash = hash; +# endif + + return Buffer::fromHex(hash, sizeof(m_seedHash) * 2, m_seedHash); +} + + bool xmrig::Job::setTarget(const char *target) { if (!target) { @@ -177,15 +191,6 @@ void xmrig::Job::setDiff(uint64_t diff) } -bool xmrig::Job::setSeedHash(const char *hash) -{ - if (!hash || (strlen(hash) != sizeof(m_seedHash) * 2)) - return false; - - return Buffer::fromHex(hash, sizeof(m_seedHash) * 2, m_seedHash); -} - - xmrig::Variant xmrig::Job::variant() const { switch (m_algorithm.algo()) { diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index 6b63fd14c..bc0ec2ebd 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -52,10 +52,10 @@ public: bool isEqual(const Job &other) const; bool setBlob(const char *blob); + bool setSeedHash(const char *hash); bool setTarget(const char *target); void setAlgorithm(const char *algo); void setDiff(uint64_t diff); - bool setSeedHash(const char *hash); inline bool isNicehash() const { return m_nicehash; } inline bool isValid() const { return m_size > 0 && m_diff > 0; } @@ -65,7 +65,7 @@ public: inline const String &id() const { return m_id; } inline const uint32_t *nonce() const { return reinterpret_cast(m_blob + 39); } inline const uint8_t *blob() const { return m_blob; } - inline const uint8_t *seed_hash() const { return m_seedHash; } + inline const uint8_t *seedHash() const { return m_seedHash; } inline int poolId() const { return m_poolId; } inline int threadId() const { return m_threadId; } inline size_t size() const { return m_size; } @@ -83,9 +83,10 @@ public: inline void setVariant(int variant) { m_algorithm.parseVariant(variant); } # ifdef XMRIG_PROXY_PROJECT - inline char *rawBlob() { return m_rawBlob; } - inline const char *rawBlob() const { return m_rawBlob; } - inline const char *rawTarget() const { return m_rawTarget; } + inline char *rawBlob() { return m_rawBlob; } + inline const char *rawBlob() const { return m_rawBlob; } + inline const char *rawTarget() const { return m_rawTarget; } + inline const String &rawSeedHash() const { return m_rawSeedHash; } # endif static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast(blob + 39); } @@ -108,12 +109,13 @@ private: uint64_t m_diff; uint64_t m_height; uint64_t m_target; - uint8_t m_seedHash[32]; uint8_t m_blob[kMaxBlobSize]; + uint8_t m_seedHash[32]; # ifdef XMRIG_PROXY_PROJECT char m_rawBlob[kMaxBlobSize * 2 + 8]; char m_rawTarget[24]; + String m_rawSeedHash; # endif }; diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index e1ef12b25..d17a2c2e9 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -164,7 +164,7 @@ void MultiWorker::start() # ifdef XMRIG_ALGO_RANDOMX if (v == xmrig::VARIANT_RX_WOW) { allocateRandomX_VM(); - Workers::updateDataset(m_state.job.seed_hash(), m_totalWays); + Workers::updateDataset(m_state.job.seedHash(), m_totalWays); randomx_calculate_hash(m_rx_vm, m_state.blob, m_state.job.size(), m_hash); } else