From 286d690575f9b086947a0be282a8bde42e90803a Mon Sep 17 00:00:00 2001 From: Mika Lindqvist Date: Fri, 27 Dec 2019 15:48:03 +0200 Subject: [PATCH] Rename cn-pico/tlo to cn-ultra/tlo and add CN_ULTRA as new algorithm. --- CMakeLists.txt | 5 + doc/build/CMAKE_OPTIONS.md | 1 + src/backend/cpu/CpuConfig.cpp | 1 + src/backend/cpu/CpuConfig_gen.h | 13 +- src/backend/cpu/CpuWorker.cpp | 18 +- src/backend/cpu/platform/AdvancedCpuInfo.cpp | 8 +- src/backend/cpu/platform/BasicCpuInfo.cpp | 6 + src/backend/cpu/platform/HwlocCpuInfo.cpp | 8 +- src/backend/cuda/CudaConfig.cpp | 1 + src/backend/cuda/CudaConfig_gen.h | 13 +- src/backend/opencl/OclConfig.cpp | 1 + src/backend/opencl/OclConfig_gen.h | 13 +- src/backend/opencl/cl/cn/algorithm.cl | 7 +- .../generators/ocl_vega_cn_generator.cpp | 2 +- src/backend/opencl/runners/OclCnRunner.cpp | 2 +- src/crypto/cn/CnAlgo.h | 25 +- src/crypto/cn/CnHash.cpp | 67 +- src/crypto/cn/CryptoNight_test.h | 27 +- src/crypto/cn/CryptoNight_x86.h | 22 +- src/crypto/common/Algorithm.cpp | 670 +++++++++--------- src/crypto/common/Algorithm.h | 5 +- 21 files changed, 502 insertions(+), 413 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d7084e7..1162cb0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ option(WITH_HWLOC "Enable hwloc support" ON) option(WITH_CN_LITE "Enable CryptoNight-Lite algorithms family" ON) option(WITH_CN_HEAVY "Enable CryptoNight-Heavy algorithms family" ON) option(WITH_CN_PICO "Enable CryptoNight-Pico algorithm" ON) +option(WITH_CN_ULTRA "Enable CryptoNight-Ultra algorithm" ON) option(WITH_CN_GPU "Enable CryptoNight-GPU algorithm" ON) option(WITH_RANDOMX "Enable RandomX algorithms family" ON) option(WITH_ARGON2 "Enable Argon2 algorithms family" ON) @@ -192,6 +193,10 @@ if (WITH_CN_PICO) add_definitions(/DXMRIG_ALGO_CN_PICO) endif() +if (WITH_CN_ULTRA) + add_definitions(/DXMRIG_ALGO_CN_ULTRA) +endif() + if (WITH_EMBEDDED_CONFIG) add_definitions(/DXMRIG_FEATURE_EMBEDDED_CONFIG) endif() diff --git a/doc/build/CMAKE_OPTIONS.md b/doc/build/CMAKE_OPTIONS.md index 654299de..fbc5e5c4 100644 --- a/doc/build/CMAKE_OPTIONS.md +++ b/doc/build/CMAKE_OPTIONS.md @@ -6,6 +6,7 @@ * **`-DWITH_CN_LITE=OFF`** disable all CryptoNight-Lite algorithms (`cn-lite/0`, `cn-lite/1`). * **`-DWITH_CN_HEAVY=OFF`** disable all CryptoNight-Heavy algorithms (`cn-heavy/0`, `cn-heavy/xhv`, `cn-heavy/tube`). * **`-DWITH_CN_PICO=OFF`** disable CryptoNight-Pico algorithm (`cn-pico`). +* **`-DWITH_CN_ULTRA=OFF`** disable CryptoNight-Ultra algorithm (`cn-ultra`). * **`-DWITH_CN_GPU=OFF`** disable CryptoNight-GPU algorithm (`cn/gpu`). * **`-DWITH_RANDOMX=OFF`** disable RandomX algorithms (`rx/loki`, `rx/wow`). * **`-DWITH_ARGON2=OFF`** disable Argon2 algorithms (`argon2/chukwa`, `argon2/wrkz`). diff --git a/src/backend/cpu/CpuConfig.cpp b/src/backend/cpu/CpuConfig.cpp index a9e10338..db6e92d7 100644 --- a/src/backend/cpu/CpuConfig.cpp +++ b/src/backend/cpu/CpuConfig.cpp @@ -163,6 +163,7 @@ void xmrig::CpuConfig::generate() count += xmrig::generate(m_threads, m_limit); count += xmrig::generate(m_threads, m_limit); count += xmrig::generate(m_threads, m_limit); + count += xmrig::generate(m_threads, m_limit); count += xmrig::generate(m_threads, m_limit); count += xmrig::generate(m_threads, m_limit); diff --git a/src/backend/cpu/CpuConfig_gen.h b/src/backend/cpu/CpuConfig_gen.h index 8eb69e11..c58a3006 100644 --- a/src/backend/cpu/CpuConfig_gen.h +++ b/src/backend/cpu/CpuConfig_gen.h @@ -99,12 +99,15 @@ size_t inline generate(Threads &threads, uint32 template<> size_t inline generate(Threads &threads, uint32_t limit) { - size_t count = 0; + return generate("cn-pico", threads, Algorithm::CN_PICO_0, limit); +} +#endif - count += generate("cn-pico", threads, Algorithm::CN_PICO_0, limit); - count += generate("cn-pico/tlo", threads, Algorithm::CN_PICO_TLO, limit); - - return count; +#ifdef XMRIG_ALGO_CN_ULTRA +template<> +size_t inline generate(Threads &threads, uint32_t limit) +{ + return generate("cn-ultra", threads, Algorithm::CN_ULTRA_0, limit); } #endif diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp index ad04097f..f0cbd255 100644 --- a/src/backend/cpu/CpuWorker.cpp +++ b/src/backend/cpu/CpuWorker.cpp @@ -154,8 +154,13 @@ bool xmrig::CpuWorker::selfTest() # ifdef XMRIG_ALGO_CN_PICO if (m_algorithm.family() == Algorithm::CN_PICO) { - return verify(Algorithm::CN_PICO_0, test_output_pico_trtl) && - verify(Algorithm::CN_PICO_TLO, test_output_pico_tlo); + return verify(Algorithm::CN_PICO_0, test_output_pico_trtl); + } +# endif + +# ifdef XMRIG_ALGO_CN_ULTRA + if (m_algorithm.family() == Algorithm::CN_ULTRA) { + return verify(Algorithm::CN_ULTRA_0, test_output_ultra_tlo); } # endif @@ -252,9 +257,6 @@ void xmrig::CpuWorker::start() template bool xmrig::CpuWorker::verify(const Algorithm &algorithm, const uint8_t *referenceValue) { - // FIXME: Disabled until 'cn-pico/tlo' test code added - return true; - cn_hash_fun func = fn(algorithm); if (!func) { return false; @@ -268,9 +270,6 @@ bool xmrig::CpuWorker::verify(const Algorithm &algorithm, const uint8_t *refe template bool xmrig::CpuWorker::verify2(const Algorithm &algorithm, const uint8_t *referenceValue) { - // FIXME: Disabled until 'cn-pico/tlo' test code added - return true; - cn_hash_fun func = fn(algorithm); if (!func) { return false; @@ -300,9 +299,6 @@ namespace xmrig { template<> bool CpuWorker<1>::verify2(const Algorithm &algorithm, const uint8_t *referenceValue) { - // FIXME: Disabled until 'cn-pico/tlo' test code added - return true; - cn_hash_fun func = fn(algorithm); if (!func) { return false; diff --git a/src/backend/cpu/platform/AdvancedCpuInfo.cpp b/src/backend/cpu/platform/AdvancedCpuInfo.cpp index caab150e..d94c5adb 100644 --- a/src/backend/cpu/platform/AdvancedCpuInfo.cpp +++ b/src/backend/cpu/platform/AdvancedCpuInfo.cpp @@ -195,7 +195,13 @@ xmrig::CpuThreads xmrig::AdvancedCpuInfo::threads(const Algorithm &algorithm, ui uint32_t intensity = algorithm.maxIntensity() == 1 ? 0 : 1; # ifdef XMRIG_ALGO_CN_PICO - if ((algorithm == Algorithm::CN_PICO_0 || algorithm == Algorithm::CN_PICO_TLO) && (count / cores()) >= 2) { + if (algorithm == Algorithm::CN_PICO_0 && (count / cores()) >= 2) { + intensity = 2; + } +# endif + +# ifdef XMRIG_ALGO_CN_ULTRA + if (algorithm == Algorithm::CN_ULTRA_0 && (count / cores()) >= 2) { intensity = 2; } # endif diff --git a/src/backend/cpu/platform/BasicCpuInfo.cpp b/src/backend/cpu/platform/BasicCpuInfo.cpp index 1dfede21..8716f706 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo.cpp @@ -225,6 +225,12 @@ xmrig::CpuThreads xmrig::BasicCpuInfo::threads(const Algorithm &algorithm, uint3 } # endif +# ifdef XMRIG_ALGO_CN_ULTRA + if (algorithm.family() == Algorithm::CN_ULTRA) { + return CpuThreads(count, 2); + } +# endif + # ifdef XMRIG_ALGO_CN_HEAVY if (algorithm.family() == Algorithm::CN_HEAVY) { return CpuThreads(std::max(count / 4, 1), 1); diff --git a/src/backend/cpu/platform/HwlocCpuInfo.cpp b/src/backend/cpu/platform/HwlocCpuInfo.cpp index 1cc7b1b0..0a3aa5fe 100644 --- a/src/backend/cpu/platform/HwlocCpuInfo.cpp +++ b/src/backend/cpu/platform/HwlocCpuInfo.cpp @@ -307,7 +307,13 @@ void xmrig::HwlocCpuInfo::processTopLevelCache(hwloc_obj_t cache, const Algorith size_t cacheHashes = ((L3 + extra) + (scratchpad / 2)) / scratchpad; # ifdef XMRIG_ALGO_CN_PICO - if ((algorithm == Algorithm::CN_PICO_0 || algorithm == Algorithm::CN_PICO_TLO) && (cacheHashes / PUs) >= 2) { + if (algorithm == Algorithm::CN_PICO_0 && (cacheHashes / PUs) >= 2) { + intensity = 2; + } +# endif + +# ifdef XMRIG_ALGO_CN_ULTRA + if (algorithm == Algorithm::CN_ULTRA_0 && (cacheHashes / PUs) >= 2) { intensity = 2; } # endif diff --git a/src/backend/cuda/CudaConfig.cpp b/src/backend/cuda/CudaConfig.cpp index dbad4220..9bdb4302 100644 --- a/src/backend/cuda/CudaConfig.cpp +++ b/src/backend/cuda/CudaConfig.cpp @@ -179,6 +179,7 @@ void xmrig::CudaConfig::generate() count += xmrig::generate(m_threads, devices); count += xmrig::generate(m_threads, devices); count += xmrig::generate(m_threads, devices); + count += xmrig::generate(m_threads, devices); count += xmrig::generate(m_threads, devices); generated = true; diff --git a/src/backend/cuda/CudaConfig_gen.h b/src/backend/cuda/CudaConfig_gen.h index 8174932d..84378ac9 100644 --- a/src/backend/cuda/CudaConfig_gen.h +++ b/src/backend/cuda/CudaConfig_gen.h @@ -101,12 +101,15 @@ size_t inline generate(Threads &threads, const template<> size_t inline generate(Threads &threads, const std::vector &devices) { - size_t count = 0; + return generate("cn-pico", threads, Algorithm::CN_PICO_0, devices); +} +#endif - count += generate("cn-pico", threads, Algorithm::CN_PICO_0, devices); - count += generate("cn-pico/tlo", threads, Algorithm::CN_PICO_TLO, devices); - - return count; +#ifdef XMRIG_ALGO_CN_ULTRA +template<> +size_t inline generate(Threads &threads, const std::vector &devices) +{ + return generate("cn-ultra", threads, Algorithm::CN_ULTRA_0, devices); } #endif diff --git a/src/backend/opencl/OclConfig.cpp b/src/backend/opencl/OclConfig.cpp index ec01adaf..6030f194 100644 --- a/src/backend/opencl/OclConfig.cpp +++ b/src/backend/opencl/OclConfig.cpp @@ -193,6 +193,7 @@ void xmrig::OclConfig::generate() count += xmrig::generate(m_threads, devices); count += xmrig::generate(m_threads, devices); count += xmrig::generate(m_threads, devices); + count += xmrig::generate(m_threads, devices); count += xmrig::generate(m_threads, devices); m_shouldSave = count > 0; diff --git a/src/backend/opencl/OclConfig_gen.h b/src/backend/opencl/OclConfig_gen.h index 6f0a178f..28851995 100644 --- a/src/backend/opencl/OclConfig_gen.h +++ b/src/backend/opencl/OclConfig_gen.h @@ -100,12 +100,15 @@ size_t inline generate(Threads &threads, const template<> size_t inline generate(Threads &threads, const std::vector &devices) { - size_t count = 0; + return generate("cn-pico", threads, Algorithm::CN_PICO_0, devices); +} +#endif - count += generate("cn-pico", threads, Algorithm::CN_PICO_0, devices); - count += generate("cn-pico/tlo", threads, Algorithm::CN_PICO_TLO, devices); - - return count; +#ifdef XMRIG_ALGO_CN_ULTRA +template<> +size_t inline generate(Threads &threads, const std::vector &devices) +{ + return generate("cn-ultra", threads, Algorithm::CN_ULTRA_0, devices); } #endif diff --git a/src/backend/opencl/cl/cn/algorithm.cl b/src/backend/opencl/cl/cn/algorithm.cl index 7677f4e0..a6be0f0b 100644 --- a/src/backend/opencl/cl/cn/algorithm.cl +++ b/src/backend/opencl/cl/cn/algorithm.cl @@ -16,7 +16,7 @@ #define ALGO_CN_HEAVY_TUBE 15 #define ALGO_CN_HEAVY_XHV 16 #define ALGO_CN_PICO_0 17 -#define ALGO_CN_PICO_TLO 18 +#define ALGO_CN_ULTRA_0 18 #define ALGO_RX_0 19 #define ALGO_RX_WOW 20 #define ALGO_RX_LOKI 21 @@ -31,5 +31,6 @@ #define FAMILY_CN_LITE 2 #define FAMILY_CN_HEAVY 3 #define FAMILY_CN_PICO 4 -#define FAMILY_RANDOM_X 5 -#define FAMILY_ARGON2 6 +#define FAMILY_CN_ULTRA 5 +#define FAMILY_RANDOM_X 6 +#define FAMILY_ARGON2 7 diff --git a/src/backend/opencl/generators/ocl_vega_cn_generator.cpp b/src/backend/opencl/generators/ocl_vega_cn_generator.cpp index dbaba1c5..82378e26 100644 --- a/src/backend/opencl/generators/ocl_vega_cn_generator.cpp +++ b/src/backend/opencl/generators/ocl_vega_cn_generator.cpp @@ -88,7 +88,7 @@ static inline uint32_t getIntensity(const OclDevice &device, const Algorithm &al static inline uint32_t getWorksize(const Algorithm &algorithm) { - if (algorithm.family() == Algorithm::CN_PICO) { + if (algorithm.family() == Algorithm::CN_PICO || algorithm.family() == Algorithm::CN_ULTRA) { return 64; } diff --git a/src/backend/opencl/runners/OclCnRunner.cpp b/src/backend/opencl/runners/OclCnRunner.cpp index a1f4d5cb..55545cd3 100644 --- a/src/backend/opencl/runners/OclCnRunner.cpp +++ b/src/backend/opencl/runners/OclCnRunner.cpp @@ -43,7 +43,7 @@ xmrig::OclCnRunner::OclCnRunner(size_t index, const OclLaunchData &data) : OclBa if (data.device.vendorId() == OCL_VENDOR_NVIDIA) { stridedIndex = 0; } - else if (stridedIndex == 1 && (m_algorithm.family() == Algorithm::CN_PICO || (m_algorithm.family() == Algorithm::CN && CnAlgo<>::base(m_algorithm) == Algorithm::CN_2))) { + else if (stridedIndex == 1 && (m_algorithm.family() == Algorithm::CN_PICO || m_algorithm.family() == Algorithm::CN_ULTRA || (m_algorithm.family() == Algorithm::CN && CnAlgo<>::base(m_algorithm) == Algorithm::CN_2))) { stridedIndex = 2; } diff --git a/src/crypto/cn/CnAlgo.h b/src/crypto/cn/CnAlgo.h index 68976f77..8d62c7c9 100644 --- a/src/crypto/cn/CnAlgo.h +++ b/src/crypto/cn/CnAlgo.h @@ -66,6 +66,9 @@ public: case Algorithm::CN_PICO: return CN_MEMORY / 8; + case Algorithm::CN_ULTRA: + return CN_MEMORY / 8; + default: break; } @@ -111,7 +114,11 @@ public: # ifdef XMRIG_ALGO_CN_PICO case Algorithm::CN_PICO_0: - case Algorithm::CN_PICO_TLO: + return CN_ITER / 8; +# endif + +# ifdef XMRIG_ALGO_CN_ULTRA + case Algorithm::CN_ULTRA_0: return CN_ITER / 8; # endif @@ -133,7 +140,11 @@ public: # ifdef XMRIG_ALGO_CN_PICO if (algo == Algorithm::CN_PICO_0) { return 0x1FFF0; - } else if (algo == Algorithm::CN_PICO_TLO) { + } +# endif + +# ifdef XMRIG_ALGO_CN_ULTRA + if (algo == Algorithm::CN_ULTRA_0) { return 0x3FFF0; } # endif @@ -174,7 +185,9 @@ public: case Algorithm::CN_DOUBLE: # ifdef XMRIG_ALGO_CN_PICO case Algorithm::CN_PICO_0: - case Algorithm::CN_PICO_TLO: +# endif +# ifdef XMRIG_ALGO_CN_ULTRA + case Algorithm::CN_ULTRA_0: # endif return Algorithm::CN_2; @@ -221,7 +234,7 @@ template<> constexpr inline uint32_t CnAlgo::iterations() con template<> constexpr inline uint32_t CnAlgo::iterations() const { return 0x60000; } template<> constexpr inline uint32_t CnAlgo::iterations() const { return 0xC000; } template<> constexpr inline uint32_t CnAlgo::iterations() const { return CN_ITER / 8; } -template<> constexpr inline uint32_t CnAlgo::iterations() const { return CN_ITER / 8; } +template<> constexpr inline uint32_t CnAlgo::iterations() const { return CN_ITER / 8; } template<> constexpr inline size_t CnAlgo::memory() const { return CN_MEMORY / 2; } @@ -230,12 +243,12 @@ template<> constexpr inline size_t CnAlgo::memory() const template<> constexpr inline size_t CnAlgo::memory() const { return CN_MEMORY * 2; } template<> constexpr inline size_t CnAlgo::memory() const { return CN_MEMORY * 2; } template<> constexpr inline size_t CnAlgo::memory() const { return CN_MEMORY / 8; } -template<> constexpr inline size_t CnAlgo::memory() const { return CN_MEMORY / 8; } +template<> constexpr inline size_t CnAlgo::memory() const { return CN_MEMORY / 8; } template<> constexpr inline uint32_t CnAlgo::mask() const { return 0x1FFFC0; } template<> constexpr inline uint32_t CnAlgo::mask() const { return 0x1FFF0; } -template<> constexpr inline uint32_t CnAlgo::mask() const { return 0x3FFF0; } +template<> constexpr inline uint32_t CnAlgo::mask() const { return 0x3FFF0; } } /* namespace xmrig */ diff --git a/src/crypto/cn/CnHash.cpp b/src/crypto/cn/CnHash.cpp index 9ea66f2f..fbbbffb6 100644 --- a/src/crypto/cn/CnHash.cpp +++ b/src/crypto/cn/CnHash.cpp @@ -79,6 +79,11 @@ cn_mainloop_fun cn_trtl_mainloop_ryzen_asm = nullptr; cn_mainloop_fun cn_trtl_mainloop_bulldozer_asm = nullptr; cn_mainloop_fun cn_trtl_double_mainloop_sandybridge_asm = nullptr; +cn_mainloop_fun cn_tlo_mainloop_ivybridge_asm = nullptr; +cn_mainloop_fun cn_tlo_mainloop_ryzen_asm = nullptr; +cn_mainloop_fun cn_tlo_mainloop_bulldozer_asm = nullptr; +cn_mainloop_fun cn_tlo_double_mainloop_sandybridge_asm = nullptr; + cn_mainloop_fun cn_zls_mainloop_ivybridge_asm = nullptr; cn_mainloop_fun cn_zls_mainloop_ryzen_asm = nullptr; cn_mainloop_fun cn_zls_mainloop_bulldozer_asm = nullptr; @@ -128,30 +133,37 @@ static void patchCode(T dst, U src, const uint32_t iterations, const uint32_t ma static void patchAsmVariants() { - const int allocation_size = 65536; + const int allocation_size = 81920; auto 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); - cn_half_mainloop_bulldozer_asm = reinterpret_cast (base + 0x2000); - cn_half_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0x3000); + cn_half_mainloop_ivybridge_asm = reinterpret_cast (base + 0x00000); + cn_half_mainloop_ryzen_asm = reinterpret_cast (base + 0x01000); + cn_half_mainloop_bulldozer_asm = reinterpret_cast (base + 0x02000); + cn_half_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0x03000); # ifdef XMRIG_ALGO_CN_PICO - cn_trtl_mainloop_ivybridge_asm = reinterpret_cast (base + 0x4000); - cn_trtl_mainloop_ryzen_asm = reinterpret_cast (base + 0x5000); - cn_trtl_mainloop_bulldozer_asm = reinterpret_cast (base + 0x6000); - cn_trtl_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0x7000); + cn_trtl_mainloop_ivybridge_asm = reinterpret_cast (base + 0x04000); + cn_trtl_mainloop_ryzen_asm = reinterpret_cast (base + 0x05000); + cn_trtl_mainloop_bulldozer_asm = reinterpret_cast (base + 0x06000); + cn_trtl_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0x07000); # endif - cn_zls_mainloop_ivybridge_asm = reinterpret_cast (base + 0x8000); - cn_zls_mainloop_ryzen_asm = reinterpret_cast (base + 0x9000); - cn_zls_mainloop_bulldozer_asm = reinterpret_cast (base + 0xA000); - cn_zls_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0xB000); +# ifdef XMRIG_ALGO_CN_ULTRA + cn_tlo_mainloop_ivybridge_asm = reinterpret_cast (base + 0x08000); + cn_tlo_mainloop_ryzen_asm = reinterpret_cast (base + 0x09000); + cn_tlo_mainloop_bulldozer_asm = reinterpret_cast (base + 0x0A000); + cn_tlo_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0x0B000); +# endif - cn_double_mainloop_ivybridge_asm = reinterpret_cast (base + 0xC000); - cn_double_mainloop_ryzen_asm = reinterpret_cast (base + 0xD000); - cn_double_mainloop_bulldozer_asm = reinterpret_cast (base + 0xE000); - cn_double_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0xF000); + cn_zls_mainloop_ivybridge_asm = reinterpret_cast (base + 0x0C000); + cn_zls_mainloop_ryzen_asm = reinterpret_cast (base + 0x0D000); + cn_zls_mainloop_bulldozer_asm = reinterpret_cast (base + 0x0E000); + cn_zls_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0x0F000); + + cn_double_mainloop_ivybridge_asm = reinterpret_cast (base + 0x10000); + cn_double_mainloop_ryzen_asm = reinterpret_cast (base + 0x11000); + cn_double_mainloop_bulldozer_asm = reinterpret_cast (base + 0x12000); + cn_double_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0x13000); { constexpr uint32_t ITER = CnAlgo().iterations(); @@ -172,15 +184,17 @@ static void patchAsmVariants() patchCode(cn_trtl_mainloop_bulldozer_asm, cnv2_mainloop_bulldozer_asm, ITER, MASK); patchCode(cn_trtl_double_mainloop_sandybridge_asm, cnv2_double_mainloop_sandybridge_asm, ITER, MASK); } +# endif +# ifdef XMRIG_ALGO_CN_ULTRA { - constexpr uint32_t ITER = CnAlgo().iterations(); - constexpr uint32_t MASK = CnAlgo().mask(); + constexpr uint32_t ITER = CnAlgo().iterations(); + constexpr uint32_t MASK = CnAlgo().mask(); - patchCode(cn_trtl_mainloop_ivybridge_asm, cnv2_mainloop_ivybridge_asm, ITER, MASK); - patchCode(cn_trtl_mainloop_ryzen_asm, cnv2_mainloop_ryzen_asm, ITER, MASK); - patchCode(cn_trtl_mainloop_bulldozer_asm, cnv2_mainloop_bulldozer_asm, ITER, MASK); - patchCode(cn_trtl_double_mainloop_sandybridge_asm, cnv2_double_mainloop_sandybridge_asm, ITER, MASK); + patchCode(cn_tlo_mainloop_ivybridge_asm, cnv2_mainloop_ivybridge_asm, ITER, MASK); + patchCode(cn_tlo_mainloop_ryzen_asm, cnv2_mainloop_ryzen_asm, ITER, MASK); + patchCode(cn_tlo_mainloop_bulldozer_asm, cnv2_mainloop_bulldozer_asm, ITER, MASK); + patchCode(cn_tlo_double_mainloop_sandybridge_asm, cnv2_double_mainloop_sandybridge_asm, ITER, MASK); } # endif @@ -254,8 +268,11 @@ xmrig::CnHash::CnHash() # ifdef XMRIG_ALGO_CN_PICO ADD_FN(Algorithm::CN_PICO_0); ADD_FN_ASM(Algorithm::CN_PICO_0); - ADD_FN(Algorithm::CN_PICO_TLO); - ADD_FN_ASM(Algorithm::CN_PICO_TLO); +# endif + +# ifdef XMRIG_ALGO_CN_ULTRA + ADD_FN(Algorithm::CN_ULTRA_0); + ADD_FN_ASM(Algorithm::CN_ULTRA_0); # endif # ifdef XMRIG_ALGO_ARGON2 diff --git a/src/crypto/cn/CryptoNight_test.h b/src/crypto/cn/CryptoNight_test.h index e492553a..1cb20518 100644 --- a/src/crypto/cn/CryptoNight_test.h +++ b/src/crypto/cn/CryptoNight_test.h @@ -338,21 +338,20 @@ const static uint8_t test_output_pico_trtl[160] = { 0xA1, 0xE7, 0x53, 0x85, 0xFB, 0x72, 0xDD, 0x75, 0x90, 0x39, 0xB2, 0x3D, 0xC3, 0x08, 0x2C, 0xD5, 0x01, 0x08, 0x27, 0x75, 0x86, 0xB9, 0xBB, 0x9B, 0xDF, 0xEA, 0x49, 0xDE, 0x46, 0xCB, 0x83, 0x45 }; +#endif - -// FIXME: Needs working test code -// "cn-pico/tlo" -const static uint8_t test_output_pico_tlo[160] = { - 0x08, 0xF4, 0x21, 0xD7, 0x83, 0x31, 0x17, 0x30, 0x0E, 0xDA, 0x66, 0xE9, 0x8F, 0x4A, 0x25, 0x69, - 0x09, 0x3D, 0xF3, 0x00, 0x50, 0x01, 0x73, 0x94, 0x4E, 0xFC, 0x40, 0x1E, 0x9A, 0x4A, 0x17, 0xAF, - 0xB2, 0x17, 0x2E, 0xC9, 0x46, 0x6E, 0x1A, 0xEE, 0x70, 0xEC, 0x85, 0x72, 0xA1, 0x4C, 0x23, 0x3E, - 0xE3, 0x54, 0x58, 0x2B, 0xCB, 0x93, 0xF8, 0x69, 0xD4, 0x29, 0x74, 0x4D, 0xE5, 0x72, 0x6A, 0x26, - 0x4E, 0xFD, 0x28, 0xFC, 0xD3, 0x74, 0x8A, 0x83, 0xF3, 0xCA, 0x92, 0x84, 0xE7, 0x4E, 0x10, 0xC2, - 0x05, 0x62, 0xC7, 0xBE, 0x99, 0x73, 0xED, 0x90, 0xB5, 0x6F, 0xDA, 0x64, 0x71, 0x2D, 0x99, 0x39, - 0x29, 0xDB, 0x22, 0x2B, 0x97, 0xB6, 0x37, 0x0E, 0x9A, 0x03, 0x65, 0xCC, 0xF7, 0xD0, 0x9A, 0xB7, - 0x68, 0xCE, 0x07, 0x3E, 0x15, 0x40, 0x3C, 0xCE, 0x8C, 0x63, 0x16, 0x72, 0xB5, 0x74, 0x84, 0xF4, - 0xA1, 0xE7, 0x53, 0x85, 0xFB, 0x72, 0xDD, 0x75, 0x90, 0x39, 0xB2, 0x3D, 0xC3, 0x08, 0x2C, 0xD5, - 0x01, 0x08, 0x27, 0x75, 0x86, 0xB9, 0xBB, 0x9B, 0xDF, 0xEA, 0x49, 0xDE, 0x46, 0xCB, 0x83, 0x45 +#ifdef XMRIG_ALGO_CN_ULTRA +const static uint8_t test_output_ultra_tlo[160] = { + 0x99, 0x75, 0xF2, 0xC1, 0xB3, 0xB4, 0x54, 0x34, 0xA4, 0x93, 0x86, 0x21, 0x30, 0x97, 0xF3, 0x1B, + 0xB4, 0xB9, 0xA6, 0x58, 0x6A, 0x7E, 0x81, 0xF4, 0x42, 0x9F, 0x6D, 0x5F, 0x65, 0xC3, 0x8D, 0x1A, + 0xFC, 0x67, 0xDF, 0xCC, 0xB5, 0xFC, 0x90, 0xD7, 0x85, 0x5A, 0xE9, 0x03, 0x36, 0x1E, 0xAB, 0xD7, + 0x6F, 0x1E, 0x40, 0xA2, 0x2A, 0x72, 0xAD, 0x3E, 0xF2, 0xD6, 0xAD, 0x27, 0xB5, 0xA6, 0x0C, 0xE5, + 0x1C, 0xB1, 0x53, 0xE9, 0x70, 0x7D, 0x69, 0xF1, 0xE1, 0x55, 0x28, 0x45, 0xF5, 0x76, 0x56, 0xE5, + 0x10, 0x0D, 0xEA, 0xFD, 0xD9, 0xD6, 0xAF, 0x0F, 0x47, 0x0C, 0x0D, 0xA2, 0x10, 0x16, 0x43, 0xEE, + 0x25, 0x2C, 0x07, 0x3A, 0x64, 0x29, 0x16, 0xFF, 0xF5, 0xA5, 0x0B, 0xA2, 0xE0, 0xBD, 0xDC, 0xCE, + 0x93, 0x3F, 0xEF, 0x6B, 0x08, 0xF4, 0x4D, 0x6A, 0x6E, 0x14, 0x13, 0x10, 0x98, 0x11, 0xE1, 0x13, + 0xF6, 0x9D, 0x3D, 0x31, 0xC4, 0x3A, 0xA9, 0x44, 0x4C, 0x38, 0xAB, 0xB5, 0x4B, 0xD9, 0xFB, 0xE6, + 0x98, 0xB9, 0x46, 0xE2, 0x00, 0xEB, 0x56, 0x33, 0x1E, 0xBC, 0xEB, 0xF1, 0xF6, 0x88, 0xD3, 0xF0 }; #endif diff --git a/src/crypto/cn/CryptoNight_x86.h b/src/crypto/cn/CryptoNight_x86.h index 1bb412de..d8ee0ebc 100644 --- a/src/crypto/cn/CryptoNight_x86.h +++ b/src/crypto/cn/CryptoNight_x86.h @@ -868,7 +868,7 @@ inline void cryptonight_single_hash_asm(const uint8_t *__restrict__ input, size_ } } # ifdef XMRIG_ALGO_CN_PICO - else if (ALGO == Algorithm::CN_PICO_0 || ALGO == Algorithm::CN_PICO_TLO) { + else if (ALGO == Algorithm::CN_PICO_0) { if (ASM == Assembly::INTEL) { cn_trtl_mainloop_ivybridge_asm(ctx); } @@ -879,6 +879,19 @@ inline void cryptonight_single_hash_asm(const uint8_t *__restrict__ input, size_ cn_trtl_mainloop_bulldozer_asm(ctx); } } +# endif +# ifdef XMRIG_ALGO_CN_ULTRA + else if (ALGO == Algorithm::CN_ULTRA_0) { + if (ASM == Assembly::INTEL) { + cn_tlo_mainloop_ivybridge_asm(ctx); + } + else if (ASM == Assembly::RYZEN) { + cn_tlo_mainloop_ryzen_asm(ctx); + } + else { + cn_tlo_mainloop_bulldozer_asm(ctx); + } + } # endif else if (ALGO == Algorithm::CN_RWZ) { cnv2_rwz_mainloop_asm(ctx); @@ -941,9 +954,14 @@ inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_ cn_half_double_mainloop_sandybridge_asm(ctx); } # ifdef XMRIG_ALGO_CN_PICO - else if (ALGO == Algorithm::CN_PICO_0 || ALGO == Algorithm::CN_PICO_TLO) { + else if (ALGO == Algorithm::CN_PICO_0) { cn_trtl_double_mainloop_sandybridge_asm(ctx); } +# endif +# ifdef XMRIG_ALGO_CN_ULTRA + else if (ALGO == Algorithm::CN_ULTRA_0) { + cn_tlo_double_mainloop_sandybridge_asm(ctx); + } # endif else if (ALGO == Algorithm::CN_RWZ) { cnv2_rwz_double_mainloop_asm(ctx); diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index 11981873..189671e4 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -1,331 +1,339 @@ -/* 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 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 "crypto/common/Algorithm.h" - - -#include "crypto/cn/CnAlgo.h" -#include "rapidjson/document.h" - - -#include -#include -#include -#include - - -#ifdef _MSC_VER -# define strcasecmp _stricmp -#endif - - -namespace xmrig { - - -struct AlgoName -{ - const char *name; - const char *shortName; - const Algorithm::Id id; -}; - - -static AlgoName const algorithm_names[] = { - { "cryptonight/0", "cn/0", Algorithm::CN_0 }, - { "cryptonight", "cn", Algorithm::CN_0 }, - { "cryptonight/1", "cn/1", Algorithm::CN_1 }, - { "cryptonight-monerov7", nullptr, Algorithm::CN_1 }, - { "cryptonight_v7", nullptr, Algorithm::CN_1 }, - { "cryptonight/2", "cn/2", Algorithm::CN_2 }, - { "cryptonight-monerov8", nullptr, Algorithm::CN_2 }, - { "cryptonight_v8", nullptr, Algorithm::CN_2 }, - { "cryptonight/r", "cn/r", Algorithm::CN_R }, - { "cryptonight_r", nullptr, Algorithm::CN_R }, - { "cryptonight/fast", "cn/fast", Algorithm::CN_FAST }, - { "cryptonight/msr", "cn/msr", Algorithm::CN_FAST }, - { "cryptonight/half", "cn/half", Algorithm::CN_HALF }, - { "cryptonight/xao", "cn/xao", Algorithm::CN_XAO }, - { "cryptonight_alloy", nullptr, Algorithm::CN_XAO }, - { "cryptonight/rto", "cn/rto", Algorithm::CN_RTO }, - { "cryptonight/rwz", "cn/rwz", Algorithm::CN_RWZ }, - { "cryptonight/zls", "cn/zls", Algorithm::CN_ZLS }, - { "cryptonight/double", "cn/double", Algorithm::CN_DOUBLE }, -# ifdef XMRIG_ALGO_CN_GPU - { "cryptonight/gpu", "cn/gpu", Algorithm::CN_GPU }, - { "cryptonight_gpu", nullptr, Algorithm::CN_GPU }, -# endif -# ifdef XMRIG_ALGO_CN_LITE - { "cryptonight-lite/0", "cn-lite/0", Algorithm::CN_LITE_0 }, - { "cryptonight-lite/1", "cn-lite/1", Algorithm::CN_LITE_1 }, - { "cryptonight-lite", "cn-lite", Algorithm::CN_LITE_1 }, - { "cryptonight-light", "cn-light", Algorithm::CN_LITE_1 }, - { "cryptonight_lite", nullptr, Algorithm::CN_LITE_1 }, - { "cryptonight-aeonv7", nullptr, Algorithm::CN_LITE_1 }, - { "cryptonight_lite_v7", nullptr, Algorithm::CN_LITE_1 }, -# endif -# ifdef XMRIG_ALGO_CN_HEAVY - { "cryptonight-heavy/0", "cn-heavy/0", Algorithm::CN_HEAVY_0 }, - { "cryptonight-heavy", "cn-heavy", Algorithm::CN_HEAVY_0 }, - { "cryptonight_heavy", nullptr, Algorithm::CN_HEAVY_0 }, - { "cryptonight-heavy/xhv", "cn-heavy/xhv", Algorithm::CN_HEAVY_XHV }, - { "cryptonight_haven", nullptr, Algorithm::CN_HEAVY_XHV }, - { "cryptonight-heavy/tube", "cn-heavy/tube", Algorithm::CN_HEAVY_TUBE }, - { "cryptonight-bittube2", nullptr, Algorithm::CN_HEAVY_TUBE }, -# endif -# ifdef XMRIG_ALGO_CN_PICO - { "cryptonight-pico", "cn-pico", Algorithm::CN_PICO_0 }, - { "cryptonight-pico/trtl", "cn-pico/trtl", Algorithm::CN_PICO_0 }, - { "cryptonight-turtle", "cn-trtl", Algorithm::CN_PICO_0 }, - { "cryptonight-ultralite", "cn-ultralite", Algorithm::CN_PICO_0 }, - { "cryptonight_turtle", "cn_turtle", Algorithm::CN_PICO_0 }, - { "cryptonight-pico/tlo", "cn-pico/tlo", Algorithm::CN_PICO_TLO }, - { "cryptonight-talleo", "cn-talleo", Algorithm::CN_PICO_TLO }, - { "cryptonight_talleo", "cn_talleo", Algorithm::CN_PICO_TLO }, -# endif -# ifdef XMRIG_ALGO_RANDOMX - { "randomx/0", "rx/0", Algorithm::RX_0 }, - { "randomx/test", "rx/test", Algorithm::RX_0 }, - { "RandomX", "rx", Algorithm::RX_0 }, - { "randomx/wow", "rx/wow", Algorithm::RX_WOW }, - { "RandomWOW", nullptr, Algorithm::RX_WOW }, - { "randomx/loki", "rx/loki", Algorithm::RX_LOKI }, - { "RandomXL", nullptr, Algorithm::RX_LOKI }, - { "randomx/arq", "rx/arq", Algorithm::RX_ARQ }, - { "RandomARQ", nullptr, Algorithm::RX_ARQ }, - { "randomx/sfx", "rx/sfx", Algorithm::RX_SFX }, - { "RandomSFX", nullptr, Algorithm::RX_SFX }, - { "randomx/v", "rx/v", Algorithm::RX_V }, - { "RandomV", nullptr, Algorithm::RX_V }, -# endif -# ifdef XMRIG_ALGO_ARGON2 - { "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA }, - { "chukwa", nullptr, Algorithm::AR2_CHUKWA }, - { "argon2/wrkz", nullptr, Algorithm::AR2_WRKZ }, -# endif -}; - - -} /* namespace xmrig */ - - -rapidjson::Value xmrig::Algorithm::toJSON() const -{ - using namespace rapidjson; - - return isValid() ? Value(StringRef(shortName())) : Value(kNullType); -} - - -size_t xmrig::Algorithm::l2() const -{ -# ifdef XMRIG_ALGO_RANDOMX - switch (m_id) { - case RX_0: - case RX_LOKI: - case RX_SFX: - case RX_V: - return 0x40000; - - case RX_WOW: - return 0x20000; - - case RX_ARQ: - return 0x10000; - - default: - break; - } -# endif - - return 0; -} - - -size_t xmrig::Algorithm::l3() const -{ -# if defined(XMRIG_ALGO_RANDOMX) || defined(XMRIG_ALGO_ARGON2) - constexpr size_t oneMiB = 0x100000; -# endif - - const Family f = family(); - assert(f != UNKNOWN); - - if (f < RANDOM_X) { - return CnAlgo<>::memory(m_id); - } - -# ifdef XMRIG_ALGO_RANDOMX - if (f == RANDOM_X) { - switch (m_id) { - case RX_0: - case RX_LOKI: - case RX_SFX: - case RX_V: - return oneMiB * 2; - - case RX_WOW: - return oneMiB; - - case RX_ARQ: - return oneMiB / 4; - - default: - break; - } - } -# endif - -# ifdef XMRIG_ALGO_ARGON2 - if (f == ARGON2) { - switch (m_id) { - case AR2_CHUKWA: - return oneMiB / 2; - - case AR2_WRKZ: - return oneMiB / 4; - - default: - break; - } - } -# endif - - return 0; -} - - -uint32_t xmrig::Algorithm::maxIntensity() const -{ -# ifdef XMRIG_ALGO_RANDOMX - if (family() == RANDOM_X) { - return 1; - } -# endif - -# ifdef XMRIG_ALGO_ARGON2 - if (family() == ARGON2) { - return 1; - } -# endif - -# ifdef XMRIG_ALGO_CN_GPU - if (m_id == CN_GPU) { - return 1; - } -# endif - - return 5; -} - - -xmrig::Algorithm::Family xmrig::Algorithm::family(Id id) -{ - switch (id) { - case CN_0: - case CN_1: - case CN_2: - case CN_R: - case CN_FAST: - case CN_HALF: - case CN_XAO: - case CN_RTO: - case CN_RWZ: - case CN_ZLS: - case CN_DOUBLE: -# ifdef XMRIG_ALGO_CN_GPU - case CN_GPU: -# endif - return CN; - -# ifdef XMRIG_ALGO_CN_LITE - case CN_LITE_0: - case CN_LITE_1: - return CN_LITE; -# endif - -# ifdef XMRIG_ALGO_CN_HEAVY - case CN_HEAVY_0: - case CN_HEAVY_TUBE: - case CN_HEAVY_XHV: - return CN_HEAVY; -# endif - -# ifdef XMRIG_ALGO_CN_PICO - case CN_PICO_0: - case CN_PICO_TLO: - return CN_PICO; -# endif - -# ifdef XMRIG_ALGO_RANDOMX - case RX_0: - case RX_WOW: - case RX_LOKI: - case RX_ARQ: - case RX_SFX: - case RX_V: - return RANDOM_X; -# endif - -# ifdef XMRIG_ALGO_ARGON2 - case AR2_CHUKWA: - case AR2_WRKZ: - return ARGON2; -# endif - - default: - break; - } - - return UNKNOWN; -} - - -xmrig::Algorithm::Id xmrig::Algorithm::parse(const char *name) -{ - if (name == nullptr || strlen(name) < 1) { - return INVALID; - } - - for (const AlgoName &item : algorithm_names) { - if ((strcasecmp(name, item.name) == 0) || (item.shortName != nullptr && strcasecmp(name, item.shortName) == 0)) { - return item.id; - } - } - - return INVALID; -} - - -const char *xmrig::Algorithm::name(bool shortName) const -{ - for (const AlgoName &item : algorithm_names) { - if (item.id == m_id) { - return (shortName && item.shortName) ? item.shortName : item.name; - } - } - - return "invalid"; -} +/* 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 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 "crypto/common/Algorithm.h" + + +#include "crypto/cn/CnAlgo.h" +#include "rapidjson/document.h" + + +#include +#include +#include +#include + + +#ifdef _MSC_VER +# define strcasecmp _stricmp +#endif + + +namespace xmrig { + + +struct AlgoName +{ + const char *name; + const char *shortName; + const Algorithm::Id id; +}; + + +static AlgoName const algorithm_names[] = { + { "cryptonight/0", "cn/0", Algorithm::CN_0 }, + { "cryptonight", "cn", Algorithm::CN_0 }, + { "cryptonight/1", "cn/1", Algorithm::CN_1 }, + { "cryptonight-monerov7", nullptr, Algorithm::CN_1 }, + { "cryptonight_v7", nullptr, Algorithm::CN_1 }, + { "cryptonight/2", "cn/2", Algorithm::CN_2 }, + { "cryptonight-monerov8", nullptr, Algorithm::CN_2 }, + { "cryptonight_v8", nullptr, Algorithm::CN_2 }, + { "cryptonight/r", "cn/r", Algorithm::CN_R }, + { "cryptonight_r", nullptr, Algorithm::CN_R }, + { "cryptonight/fast", "cn/fast", Algorithm::CN_FAST }, + { "cryptonight/msr", "cn/msr", Algorithm::CN_FAST }, + { "cryptonight/half", "cn/half", Algorithm::CN_HALF }, + { "cryptonight/xao", "cn/xao", Algorithm::CN_XAO }, + { "cryptonight_alloy", nullptr, Algorithm::CN_XAO }, + { "cryptonight/rto", "cn/rto", Algorithm::CN_RTO }, + { "cryptonight/rwz", "cn/rwz", Algorithm::CN_RWZ }, + { "cryptonight/zls", "cn/zls", Algorithm::CN_ZLS }, + { "cryptonight/double", "cn/double", Algorithm::CN_DOUBLE }, +# ifdef XMRIG_ALGO_CN_GPU + { "cryptonight/gpu", "cn/gpu", Algorithm::CN_GPU }, + { "cryptonight_gpu", nullptr, Algorithm::CN_GPU }, +# endif +# ifdef XMRIG_ALGO_CN_LITE + { "cryptonight-lite/0", "cn-lite/0", Algorithm::CN_LITE_0 }, + { "cryptonight-lite/1", "cn-lite/1", Algorithm::CN_LITE_1 }, + { "cryptonight-lite", "cn-lite", Algorithm::CN_LITE_1 }, + { "cryptonight-light", "cn-light", Algorithm::CN_LITE_1 }, + { "cryptonight_lite", nullptr, Algorithm::CN_LITE_1 }, + { "cryptonight-aeonv7", nullptr, Algorithm::CN_LITE_1 }, + { "cryptonight_lite_v7", nullptr, Algorithm::CN_LITE_1 }, +# endif +# ifdef XMRIG_ALGO_CN_HEAVY + { "cryptonight-heavy/0", "cn-heavy/0", Algorithm::CN_HEAVY_0 }, + { "cryptonight-heavy", "cn-heavy", Algorithm::CN_HEAVY_0 }, + { "cryptonight_heavy", nullptr, Algorithm::CN_HEAVY_0 }, + { "cryptonight-heavy/xhv", "cn-heavy/xhv", Algorithm::CN_HEAVY_XHV }, + { "cryptonight_haven", nullptr, Algorithm::CN_HEAVY_XHV }, + { "cryptonight-heavy/tube", "cn-heavy/tube", Algorithm::CN_HEAVY_TUBE }, + { "cryptonight-bittube2", nullptr, Algorithm::CN_HEAVY_TUBE }, +# endif +# ifdef XMRIG_ALGO_CN_PICO + { "cryptonight-pico", "cn-pico", Algorithm::CN_PICO_0 }, + { "cryptonight-pico/trtl", "cn-pico/trtl", Algorithm::CN_PICO_0 }, + { "cryptonight-turtle", "cn-trtl", Algorithm::CN_PICO_0 }, + { "cryptonight-ultralite", "cn-ultralite", Algorithm::CN_PICO_0 }, + { "cryptonight_turtle", "cn_turtle", Algorithm::CN_PICO_0 }, +# endif +# ifdef XMRIG_ALGO_CN_ULTRA + { "cryptonight-ultra", "cn-ultra", Algorithm::CN_ULTRA_0 }, + { "cryptonight-ultra/tlo", "cn-ultra/tlo", Algorithm::CN_ULTRA_0 }, + { "cryptonight-talleo", "cn-talleo", Algorithm::CN_ULTRA_0 }, + { "cryptonight_talleo", "cn_talleo", Algorithm::CN_ULTRA_0 }, + { "cryptonight/ultra", "cn/ultra", Algorithm::CN_ULTRA_0 }, +# endif +# ifdef XMRIG_ALGO_RANDOMX + { "randomx/0", "rx/0", Algorithm::RX_0 }, + { "randomx/test", "rx/test", Algorithm::RX_0 }, + { "RandomX", "rx", Algorithm::RX_0 }, + { "randomx/wow", "rx/wow", Algorithm::RX_WOW }, + { "RandomWOW", nullptr, Algorithm::RX_WOW }, + { "randomx/loki", "rx/loki", Algorithm::RX_LOKI }, + { "RandomXL", nullptr, Algorithm::RX_LOKI }, + { "randomx/arq", "rx/arq", Algorithm::RX_ARQ }, + { "RandomARQ", nullptr, Algorithm::RX_ARQ }, + { "randomx/sfx", "rx/sfx", Algorithm::RX_SFX }, + { "RandomSFX", nullptr, Algorithm::RX_SFX }, + { "randomx/v", "rx/v", Algorithm::RX_V }, + { "RandomV", nullptr, Algorithm::RX_V }, +# endif +# ifdef XMRIG_ALGO_ARGON2 + { "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA }, + { "chukwa", nullptr, Algorithm::AR2_CHUKWA }, + { "argon2/wrkz", nullptr, Algorithm::AR2_WRKZ }, +# endif +}; + + +} /* namespace xmrig */ + + +rapidjson::Value xmrig::Algorithm::toJSON() const +{ + using namespace rapidjson; + + return isValid() ? Value(StringRef(shortName())) : Value(kNullType); +} + + +size_t xmrig::Algorithm::l2() const +{ +# ifdef XMRIG_ALGO_RANDOMX + switch (m_id) { + case RX_0: + case RX_LOKI: + case RX_SFX: + case RX_V: + return 0x40000; + + case RX_WOW: + return 0x20000; + + case RX_ARQ: + return 0x10000; + + default: + break; + } +# endif + + return 0; +} + + +size_t xmrig::Algorithm::l3() const +{ +# if defined(XMRIG_ALGO_RANDOMX) || defined(XMRIG_ALGO_ARGON2) + constexpr size_t oneMiB = 0x100000; +# endif + + const Family f = family(); + assert(f != UNKNOWN); + + if (f < RANDOM_X) { + return CnAlgo<>::memory(m_id); + } + +# ifdef XMRIG_ALGO_RANDOMX + if (f == RANDOM_X) { + switch (m_id) { + case RX_0: + case RX_LOKI: + case RX_SFX: + case RX_V: + return oneMiB * 2; + + case RX_WOW: + return oneMiB; + + case RX_ARQ: + return oneMiB / 4; + + default: + break; + } + } +# endif + +# ifdef XMRIG_ALGO_ARGON2 + if (f == ARGON2) { + switch (m_id) { + case AR2_CHUKWA: + return oneMiB / 2; + + case AR2_WRKZ: + return oneMiB / 4; + + default: + break; + } + } +# endif + + return 0; +} + + +uint32_t xmrig::Algorithm::maxIntensity() const +{ +# ifdef XMRIG_ALGO_RANDOMX + if (family() == RANDOM_X) { + return 1; + } +# endif + +# ifdef XMRIG_ALGO_ARGON2 + if (family() == ARGON2) { + return 1; + } +# endif + +# ifdef XMRIG_ALGO_CN_GPU + if (m_id == CN_GPU) { + return 1; + } +# endif + + return 5; +} + + +xmrig::Algorithm::Family xmrig::Algorithm::family(Id id) +{ + switch (id) { + case CN_0: + case CN_1: + case CN_2: + case CN_R: + case CN_FAST: + case CN_HALF: + case CN_XAO: + case CN_RTO: + case CN_RWZ: + case CN_ZLS: + case CN_DOUBLE: +# ifdef XMRIG_ALGO_CN_GPU + case CN_GPU: +# endif + return CN; + +# ifdef XMRIG_ALGO_CN_LITE + case CN_LITE_0: + case CN_LITE_1: + return CN_LITE; +# endif + +# ifdef XMRIG_ALGO_CN_HEAVY + case CN_HEAVY_0: + case CN_HEAVY_TUBE: + case CN_HEAVY_XHV: + return CN_HEAVY; +# endif + +# ifdef XMRIG_ALGO_CN_PICO + case CN_PICO_0: + return CN_PICO; +# endif + +# ifdef XMRIG_ALGO_CN_ULTRA + case CN_ULTRA_0: + return CN_ULTRA; +# endif + +# ifdef XMRIG_ALGO_RANDOMX + case RX_0: + case RX_WOW: + case RX_LOKI: + case RX_ARQ: + case RX_SFX: + case RX_V: + return RANDOM_X; +# endif + +# ifdef XMRIG_ALGO_ARGON2 + case AR2_CHUKWA: + case AR2_WRKZ: + return ARGON2; +# endif + + default: + break; + } + + return UNKNOWN; +} + + +xmrig::Algorithm::Id xmrig::Algorithm::parse(const char *name) +{ + if (name == nullptr || strlen(name) < 1) { + return INVALID; + } + + for (const AlgoName &item : algorithm_names) { + if ((strcasecmp(name, item.name) == 0) || (item.shortName != nullptr && strcasecmp(name, item.shortName) == 0)) { + return item.id; + } + } + + return INVALID; +} + + +const char *xmrig::Algorithm::name(bool shortName) const +{ + for (const AlgoName &item : algorithm_names) { + if (item.id == m_id) { + return (shortName && item.shortName) ? item.shortName : item.name; + } + } + + return "invalid"; +} diff --git a/src/crypto/common/Algorithm.h b/src/crypto/common/Algorithm.h index b0594f55..76f8f54e 100644 --- a/src/crypto/common/Algorithm.h +++ b/src/crypto/common/Algorithm.h @@ -63,7 +63,7 @@ public: CN_HEAVY_TUBE, // "cn-heavy/tube" CryptoNight-Heavy (modified, TUBE only). CN_HEAVY_XHV, // "cn-heavy/xhv" CryptoNight-Heavy (modified, Haven Protocol only). CN_PICO_0, // "cn-pico" CryptoNight Turtle (TRTL) - CN_PICO_TLO, // "cn-pico/tlo" CryptoNight Talleo (TLO) + CN_ULTRA_0, // "cn-ultra" CryptoNight Talleo (TLO) RX_0, // "rx/0" RandomX (reference configuration). RX_WOW, // "rx/wow" RandomWOW (Wownero). RX_LOKI, // "rx/loki" RandomXL (Loki). @@ -81,6 +81,7 @@ public: CN_LITE, CN_HEAVY, CN_PICO, + CN_ULTRA, RANDOM_X, ARGON2 }; @@ -89,7 +90,7 @@ public: inline Algorithm(const char *algo) : m_id(parse(algo)) {} inline Algorithm(Id id) : m_id(id) {} - inline bool isCN() const { auto f = family(); return f == CN || f == CN_LITE || f == CN_HEAVY || f == CN_PICO; } + inline bool isCN() const { auto f = family(); return f == CN || f == CN_LITE || f == CN_HEAVY || f == CN_PICO || f == CN_ULTRA; } inline bool isEqual(const Algorithm &other) const { return m_id == other.m_id; } inline bool isValid() const { return m_id != INVALID; } inline const char *name() const { return name(false); }