From 1ea34b31a1c51ee91727cfa15e9d91ca60b51e8a Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 19 Feb 2019 11:26:19 +0700 Subject: [PATCH 01/55] #932 Fixed "cn-pico/trtl" performance. --- src/workers/CpuThread.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 40e61f5a4..6065bc3aa 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -176,7 +176,9 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a add_asm_func(asm_func_map); add_asm_func(asm_func_map); - add_asm_func(asm_func_map); +# ifndef XMRIG_NO_CN_PICO + add_asm_func(asm_func_map); +# endif asm_func_map_initialized = true; } From 1c16cfedfc4e288db7d85d0794e658c7e06c5602 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 20 Feb 2019 09:07:39 +0700 Subject: [PATCH 02/55] v2.13.0-dev --- src/version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/version.h b/src/version.h index 710551a17..0ad8edaa2 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.12.1-dev" +#define APP_VERSION "2.13.0-dev" #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 12 -#define APP_VER_PATCH 1 +#define APP_VER_MINOR 13 +#define APP_VER_PATCH 0 #ifdef _MSC_VER # if (_MSC_VER >= 1910) From ac58ece16eea4180ddb3de0c639d0d53100977c2 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 21 Feb 2019 14:20:23 +0700 Subject: [PATCH 03/55] Allow expired shares. --- src/common/net/Client.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index e87266619..7cd09d46b 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -223,11 +223,6 @@ int64_t xmrig::Client::submit(const JobResult &result) } # endif - const Variant variant = m_job.algorithm().variant(); - if ((variant == VARIANT_WOW || variant == VARIANT_4) && m_job.id() != result.jobId) { - return -1; - } - using namespace rapidjson; # ifdef XMRIG_PROXY_PROJECT From 5bd2b8fd3f9ff901ff8185beaabc31844856a89f Mon Sep 17 00:00:00 2001 From: xmrig Date: Thu, 21 Feb 2019 16:58:42 +0700 Subject: [PATCH 04/55] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9624400f..4eb09e6fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# v2.13.0 +- **[#938](https://github.com/xmrig/xmrig/issues/938) Added support for new algorithm `cryptonight/r`, short alias `cn/r` (also known as CryptoNightR or CryptoNight variant 4), for upcoming [Monero](https://www.getmonero.org/) fork on March 9, thanks [@SChernykh](https://github.com/SChernykh).** +- [#939](https://github.com/xmrig/xmrig/issues/939) Added support for dynamic (runtime) pools reload. +- [#932](https://github.com/xmrig/xmrig/issues/932) Fixed `cn-pico` hashrate drop, regression since v2.11.0. + # v2.12.0 - [#929](https://github.com/xmrig/xmrig/pull/929) Added support for new algorithm `cryptonight/wow`, short alias `cn/wow` (also known as CryptonightR), for upcoming [Wownero](http://wownero.org) fork on February 14. From eec5ca5535ca03e61c7ec1e0e0e41551d9dba273 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 21 Feb 2019 17:37:05 +0700 Subject: [PATCH 05/55] v2.13.0 --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index 0ad8edaa2..36185bf6d 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.13.0-dev" +#define APP_VERSION "2.13.0" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com" From cac240104e6d47b29ee6ffef1c48792ac5a6c7f1 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 21 Feb 2019 19:03:53 +0700 Subject: [PATCH 06/55] Sync changes with AMD miner. --- src/api/ApiRouter.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/api/ApiRouter.cpp b/src/api/ApiRouter.cpp index 69fa15949..bdedac4d3 100644 --- a/src/api/ApiRouter.cpp +++ b/src/api/ApiRouter.cpp @@ -293,13 +293,16 @@ void ApiRouter::getThreads(rapidjson::Document &doc) const const std::vector &threads = m_controller->config()->threads(); rapidjson::Value list(rapidjson::kArrayType); + size_t i = 0; for (const xmrig::IThread *thread : threads) { rapidjson::Value value = thread->toAPI(doc); rapidjson::Value hashrate(rapidjson::kArrayType); - hashrate.PushBack(normalize(hr->calc(thread->index(), Hashrate::ShortInterval)), allocator); - hashrate.PushBack(normalize(hr->calc(thread->index(), Hashrate::MediumInterval)), allocator); - hashrate.PushBack(normalize(hr->calc(thread->index(), Hashrate::LargeInterval)), allocator); + hashrate.PushBack(normalize(hr->calc(i, Hashrate::ShortInterval)), allocator); + hashrate.PushBack(normalize(hr->calc(i, Hashrate::MediumInterval)), allocator); + hashrate.PushBack(normalize(hr->calc(i, Hashrate::LargeInterval)), allocator); + + i++; value.AddMember("hashrate", hashrate, allocator); list.PushBack(value, allocator); From a5dcd6dd1ff8df11febc42cad803f572b8d1e89c Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 23 Feb 2019 10:00:20 +0700 Subject: [PATCH 07/55] v2.13.1-dev --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index 36185bf6d..f30d4d1e7 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.13.0" +#define APP_VERSION "2.13.1-dev" #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 13 -#define APP_VER_PATCH 0 +#define APP_VER_PATCH 1 #ifdef _MSC_VER # if (_MSC_VER >= 1910) From 488cec09dd30cd51e22aff68cd7e642a19dc8d51 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sun, 24 Feb 2019 20:04:09 +0100 Subject: [PATCH 08/55] Optimized soft AES implementations cn-pico: +6.7% cn/half: +6.2% cn/2: +4.3% cn-heavy: +9.1% cn/wow, cn/r: 2.4-2.6 times faster --- src/crypto/CryptoNight.h | 4 + src/crypto/CryptoNight_monero.h | 10 + src/crypto/CryptoNight_x86.h | 153 ++- src/crypto/CryptonightR_gen.cpp | 28 + .../asm/CryptonightR_soft_aes_template.inc | 279 +++++ .../CryptonightR_soft_aes_template_win.inc | 279 +++++ src/crypto/asm/CryptonightR_template.S | 2 + src/crypto/asm/CryptonightR_template.asm | 2 + src/crypto/asm/CryptonightR_template.h | 24 + .../asm/CryptonightWOW_soft_aes_template.inc | 266 +++++ .../CryptonightWOW_soft_aes_template_win.inc | 266 +++++ .../win64/CryptonightR_soft_aes_template.inc | 279 +++++ .../CryptonightR_soft_aes_template_win.inc | 279 +++++ src/crypto/asm/win64/CryptonightR_template.S | 2 + .../asm/win64/CryptonightR_template.asm | 2 + src/crypto/asm/win64/CryptonightR_template.h | 1063 ----------------- .../CryptonightWOW_soft_aes_template.inc | 266 +++++ .../CryptonightWOW_soft_aes_template_win.inc | 266 +++++ 18 files changed, 2380 insertions(+), 1090 deletions(-) create mode 100644 src/crypto/asm/CryptonightR_soft_aes_template.inc create mode 100644 src/crypto/asm/CryptonightR_soft_aes_template_win.inc create mode 100644 src/crypto/asm/CryptonightWOW_soft_aes_template.inc create mode 100644 src/crypto/asm/CryptonightWOW_soft_aes_template_win.inc create mode 100644 src/crypto/asm/win64/CryptonightR_soft_aes_template.inc create mode 100644 src/crypto/asm/win64/CryptonightR_soft_aes_template_win.inc delete mode 100644 src/crypto/asm/win64/CryptonightR_template.h create mode 100644 src/crypto/asm/win64/CryptonightWOW_soft_aes_template.inc create mode 100644 src/crypto/asm/win64/CryptonightWOW_soft_aes_template_win.inc diff --git a/src/crypto/CryptoNight.h b/src/crypto/CryptoNight.h index b92945e4e..91a4c7b71 100644 --- a/src/crypto/CryptoNight.h +++ b/src/crypto/CryptoNight.h @@ -49,6 +49,10 @@ struct cryptonight_r_data { struct cryptonight_ctx { alignas(16) uint8_t state[224]; alignas(16) uint8_t *memory; + + uint8_t unused[40]; + const uint32_t* saes_table; + cn_mainloop_fun_ms_abi generated_code; cn_mainloop_double_fun_ms_abi generated_code_double; cryptonight_r_data generated_code_data; diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index 26c1fff0e..4cfff0f86 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -158,6 +158,16 @@ #define SWAP64LE(x) x #define hash_extra_blake(data, length, hash) blake256_hash((uint8_t*)(hash), (uint8_t*)(data), (length)) +#ifndef NOINLINE +#ifdef __GNUC__ +#define NOINLINE __attribute__ ((noinline)) +#elif _MSC_VER +#define NOINLINE __declspec(noinline) +#else +#define NOINLINE +#endif +#endif + #include "common/xmrig.h" #include "variant4_random_math.h" diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 4c5d4ac04..358f1921d 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -192,31 +192,102 @@ static inline void aes_genkey(const __m128i* memory, __m128i* k0, __m128i* k1, _ } -template -static inline void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2, __m128i* x3, __m128i* x4, __m128i* x5, __m128i* x6, __m128i* x7) +static FORCEINLINE void soft_aesenc(void* __restrict ptr, const void* __restrict key, const uint32_t* __restrict t) { - if (SOFT_AES) { - *x0 = soft_aesenc((uint32_t*)x0, key); - *x1 = soft_aesenc((uint32_t*)x1, key); - *x2 = soft_aesenc((uint32_t*)x2, key); - *x3 = soft_aesenc((uint32_t*)x3, key); - *x4 = soft_aesenc((uint32_t*)x4, key); - *x5 = soft_aesenc((uint32_t*)x5, key); - *x6 = soft_aesenc((uint32_t*)x6, key); - *x7 = soft_aesenc((uint32_t*)x7, key); - } - else { - *x0 = _mm_aesenc_si128(*x0, key); - *x1 = _mm_aesenc_si128(*x1, key); - *x2 = _mm_aesenc_si128(*x2, key); - *x3 = _mm_aesenc_si128(*x3, key); - *x4 = _mm_aesenc_si128(*x4, key); - *x5 = _mm_aesenc_si128(*x5, key); - *x6 = _mm_aesenc_si128(*x6, key); - *x7 = _mm_aesenc_si128(*x7, key); - } + uint32_t x0 = ((const uint32_t*)(ptr))[0]; + uint32_t x1 = ((const uint32_t*)(ptr))[1]; + uint32_t x2 = ((const uint32_t*)(ptr))[2]; + uint32_t x3 = ((const uint32_t*)(ptr))[3]; + + uint32_t y0 = t[x0 & 0xff]; x0 >>= 8; + uint32_t y1 = t[x1 & 0xff]; x1 >>= 8; + uint32_t y2 = t[x2 & 0xff]; x2 >>= 8; + uint32_t y3 = t[x3 & 0xff]; x3 >>= 8; + t += 256; + + y0 ^= t[x1 & 0xff]; x1 >>= 8; + y1 ^= t[x2 & 0xff]; x2 >>= 8; + y2 ^= t[x3 & 0xff]; x3 >>= 8; + y3 ^= t[x0 & 0xff]; x0 >>= 8; + t += 256; + + y0 ^= t[x2 & 0xff]; x2 >>= 8; + y1 ^= t[x3 & 0xff]; x3 >>= 8; + y2 ^= t[x0 & 0xff]; x0 >>= 8; + y3 ^= t[x1 & 0xff]; x1 >>= 8; + t += 256; + + y0 ^= t[x3]; + y1 ^= t[x0]; + y2 ^= t[x1]; + y3 ^= t[x2]; + + ((uint32_t*)ptr)[0] = y0 ^ ((uint32_t*)key)[0]; + ((uint32_t*)ptr)[1] = y1 ^ ((uint32_t*)key)[1]; + ((uint32_t*)ptr)[2] = y2 ^ ((uint32_t*)key)[2]; + ((uint32_t*)ptr)[3] = y3 ^ ((uint32_t*)key)[3]; } +static FORCEINLINE __m128i soft_aesenc(const void* __restrict ptr, const __m128i key, const uint32_t* __restrict t) +{ + uint32_t x0 = ((const uint32_t*)(ptr))[0]; + uint32_t x1 = ((const uint32_t*)(ptr))[1]; + uint32_t x2 = ((const uint32_t*)(ptr))[2]; + uint32_t x3 = ((const uint32_t*)(ptr))[3]; + + uint32_t y0 = t[x0 & 0xff]; x0 >>= 8; + uint32_t y1 = t[x1 & 0xff]; x1 >>= 8; + uint32_t y2 = t[x2 & 0xff]; x2 >>= 8; + uint32_t y3 = t[x3 & 0xff]; x3 >>= 8; + t += 256; + + y0 ^= t[x1 & 0xff]; x1 >>= 8; + y1 ^= t[x2 & 0xff]; x2 >>= 8; + y2 ^= t[x3 & 0xff]; x3 >>= 8; + y3 ^= t[x0 & 0xff]; x0 >>= 8; + t += 256; + + y0 ^= t[x2 & 0xff]; x2 >>= 8; + y1 ^= t[x3 & 0xff]; x3 >>= 8; + y2 ^= t[x0 & 0xff]; x0 >>= 8; + y3 ^= t[x1 & 0xff]; x1 >>= 8; + + y0 ^= t[x3 + 256]; + y1 ^= t[x0 + 256]; + y2 ^= t[x1 + 256]; + y3 ^= t[x2 + 256]; + + return _mm_xor_si128(_mm_set_epi32(y3, y2, y1, y0), key); +} + +template +void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2, __m128i* x3, __m128i* x4, __m128i* x5, __m128i* x6, __m128i* x7); + +template<> +static NOINLINE void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2, __m128i* x3, __m128i* x4, __m128i* x5, __m128i* x6, __m128i* x7) +{ + *x0 = soft_aesenc((uint32_t*)x0, key, (const uint32_t*)saes_table); + *x1 = soft_aesenc((uint32_t*)x1, key, (const uint32_t*)saes_table); + *x2 = soft_aesenc((uint32_t*)x2, key, (const uint32_t*)saes_table); + *x3 = soft_aesenc((uint32_t*)x3, key, (const uint32_t*)saes_table); + *x4 = soft_aesenc((uint32_t*)x4, key, (const uint32_t*)saes_table); + *x5 = soft_aesenc((uint32_t*)x5, key, (const uint32_t*)saes_table); + *x6 = soft_aesenc((uint32_t*)x6, key, (const uint32_t*)saes_table); + *x7 = soft_aesenc((uint32_t*)x7, key, (const uint32_t*)saes_table); +} + +template<> +static FORCEINLINE void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2, __m128i* x3, __m128i* x4, __m128i* x5, __m128i* x6, __m128i* x7) +{ + *x0 = _mm_aesenc_si128(*x0, key); + *x1 = _mm_aesenc_si128(*x1, key); + *x2 = _mm_aesenc_si128(*x2, key); + *x3 = _mm_aesenc_si128(*x3, key); + *x4 = _mm_aesenc_si128(*x4, key); + *x5 = _mm_aesenc_si128(*x5, key); + *x6 = _mm_aesenc_si128(*x6, key); + *x7 = _mm_aesenc_si128(*x7, key); +} inline void mix_and_propagate(__m128i& x0, __m128i& x1, __m128i& x2, __m128i& x3, __m128i& x4, __m128i& x5, __m128i& x6, __m128i& x7) { @@ -478,6 +549,8 @@ static inline void cryptonight_monero_tweak(uint64_t* mem_out, const uint8_t* l, } } +void wow_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); +void v4_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); template inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx, uint64_t height) @@ -498,9 +571,31 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si cn_explode_scratchpad((__m128i*) ctx[0]->state, (__m128i*) ctx[0]->memory); - const uint8_t* l0 = ctx[0]->memory; uint64_t* h0 = reinterpret_cast(ctx[0]->state); +#ifndef XMRIG_NO_ASM + if (SOFT_AES && xmrig::cn_is_cryptonight_r()) + { + if (!ctx[0]->generated_code_data.match(VARIANT, height)) { + V4_Instruction code[256]; + const int code_size = v4_random_math_init(code, height); + + if (VARIANT == xmrig::VARIANT_WOW) + wow_soft_aes_compile_code(code, code_size, reinterpret_cast(ctx[0]->generated_code), xmrig::ASM_NONE); + else if (VARIANT == xmrig::VARIANT_4) + v4_soft_aes_compile_code(code, code_size, reinterpret_cast(ctx[0]->generated_code), xmrig::ASM_NONE); + + ctx[0]->generated_code_data.variant = VARIANT; + ctx[0]->generated_code_data.height = height; + } + + ctx[0]->saes_table = (const uint32_t*)saes_table; + ctx[0]->generated_code(ctx[0]); + } else { +#endif + + const uint8_t* l0 = ctx[0]->memory; + VARIANT1_INIT(0); VARIANT2_INIT(0); VARIANT2_SET_ROUNDING_MODE(); @@ -524,7 +619,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si cx = aes_round_tweak_div(cx, ax0); } else if (SOFT_AES) { - cx = soft_aesenc((uint32_t*)&l0[idx0 & MASK], ax0); + cx = soft_aesenc((uint32_t*)&l0[idx0 & MASK], ax0, (const uint32_t*)saes_table); } else { cx = _mm_aesenc_si128(cx, ax0); @@ -602,6 +697,10 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si bx0 = cx; } +#ifndef XMRIG_NO_ASM + } +#endif + cn_implode_scratchpad((__m128i*) ctx[0]->memory, (__m128i*) ctx[0]->state); xmrig::keccakf(h0, 24); @@ -857,8 +956,8 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si cx1 = aes_round_tweak_div(cx1, ax1); } else if (SOFT_AES) { - cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], ax0); - cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], ax1); + cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], ax0, (const uint32_t*)saes_table); + cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], ax1, (const uint32_t*)saes_table); } else { cx0 = _mm_aesenc_si128(cx0, ax0); @@ -1019,7 +1118,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si c = aes_round_tweak_div(c, a); \ } \ else if (SOFT_AES) { \ - c = soft_aesenc(c, a); \ + c = soft_aesenc(&c, a, (const uint32_t*)saes_table); \ } else { \ c = _mm_aesenc_si128(c, a); \ } \ diff --git a/src/crypto/CryptonightR_gen.cpp b/src/crypto/CryptonightR_gen.cpp index 55f94662c..6e53ef190 100644 --- a/src/crypto/CryptonightR_gen.cpp +++ b/src/crypto/CryptonightR_gen.cpp @@ -159,4 +159,32 @@ void v4_compile_code_double(const V4_Instruction* code, int code_size, void* mac Mem::flushInstructionCache(machine_code, p - p0); } +void wow_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) +{ + uint8_t* p0 = reinterpret_cast(machine_code); + uint8_t* p = p0; + + add_code(p, CryptonightWOW_soft_aes_template_part1, CryptonightWOW_soft_aes_template_part2); + add_random_math(p, code, code_size, instructions, instructions_mov, false, ASM); + add_code(p, CryptonightWOW_soft_aes_template_part2, CryptonightWOW_soft_aes_template_part3); + *(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); +} + +void v4_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) +{ + uint8_t* p0 = reinterpret_cast(machine_code); + uint8_t* p = p0; + + add_code(p, CryptonightR_soft_aes_template_part1, CryptonightR_soft_aes_template_part2); + add_random_math(p, code, code_size, instructions, instructions_mov, false, ASM); + add_code(p, CryptonightR_soft_aes_template_part2, CryptonightR_soft_aes_template_part3); + *(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); +} + #endif diff --git a/src/crypto/asm/CryptonightR_soft_aes_template.inc b/src/crypto/asm/CryptonightR_soft_aes_template.inc new file mode 100644 index 000000000..40c7874d2 --- /dev/null +++ b/src/crypto/asm/CryptonightR_soft_aes_template.inc @@ -0,0 +1,279 @@ +PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_part1) +PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_mainloop) +PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_part2) +PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_part3) +PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_end) + +ALIGN(64) +FN_PREFIX(CryptonightR_soft_aes_template_part1): + mov QWORD PTR [rsp+8], rcx + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 232 + + mov eax, [rcx+96] + mov ebx, [rcx+100] + mov esi, [rcx+104] + mov edx, [rcx+108] + mov [rsp+144], eax + mov [rsp+148], ebx + mov [rsp+152], esi + mov [rsp+156], edx + + mov rax, QWORD PTR [rcx+48] + mov r10, rcx + xor rax, QWORD PTR [rcx+16] + mov r8, QWORD PTR [rcx+32] + xor r8, QWORD PTR [rcx] + mov r9, QWORD PTR [rcx+40] + xor r9, QWORD PTR [rcx+8] + movq xmm4, rax + mov rdx, QWORD PTR [rcx+56] + xor rdx, QWORD PTR [rcx+24] + mov r11, QWORD PTR [rcx+224] + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r10+72] + mov rax, QWORD PTR [r10+80] + movq xmm0, rdx + xor rax, QWORD PTR [r10+64] + + movaps XMMWORD PTR [rsp+16], xmm6 + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+48], xmm8 + movaps XMMWORD PTR [rsp+64], xmm9 + movaps XMMWORD PTR [rsp+80], xmm10 + movaps XMMWORD PTR [rsp+96], xmm11 + movaps XMMWORD PTR [rsp+112], xmm12 + movaps XMMWORD PTR [rsp+128], xmm13 + + movq xmm5, rax + + mov rax, r8 + punpcklqdq xmm4, xmm0 + and eax, 2097136 + movq xmm10, QWORD PTR [r10+96] + movq xmm0, rcx + mov rcx, QWORD PTR [r10+104] + xorps xmm9, xmm9 + mov QWORD PTR [rsp+328], rax + movq xmm12, r11 + mov QWORD PTR [rsp+320], r9 + punpcklqdq xmm5, xmm0 + movq xmm13, rcx + mov r12d, 524288 + + ALIGN(64) +FN_PREFIX(CryptonightR_soft_aes_template_mainloop): + movd xmm11, r12d + mov r12, QWORD PTR [r10+272] + lea r13, QWORD PTR [rax+r11] + mov esi, DWORD PTR [r13] + movq xmm0, r9 + mov r10d, DWORD PTR [r13+4] + movq xmm7, r8 + mov ebp, DWORD PTR [r13+12] + mov r14d, DWORD PTR [r13+8] + mov rdx, QWORD PTR [rsp+328] + movzx ecx, sil + shr esi, 8 + punpcklqdq xmm7, xmm0 + mov r15d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + mov edi, DWORD PTR [r12+rcx*4] + movzx ecx, r14b + shr r14d, 8 + mov ebx, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + shr ebp, 8 + mov r9d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + xor r15d, DWORD PTR [r12+rcx*4+1024] + movzx ecx, r14b + shr r14d, 8 + mov eax, r14d + shr eax, 8 + xor edi, DWORD PTR [r12+rcx*4+1024] + add eax, 256 + movzx ecx, bpl + shr ebp, 8 + xor ebx, DWORD PTR [r12+rcx*4+1024] + movzx ecx, sil + shr esi, 8 + xor r9d, DWORD PTR [r12+rcx*4+1024] + add r12, 2048 + movzx ecx, r10b + shr r10d, 8 + add r10d, 256 + mov r11d, DWORD PTR [r12+rax*4] + xor r11d, DWORD PTR [r12+rcx*4] + xor r11d, r9d + movzx ecx, sil + mov r10d, DWORD PTR [r12+r10*4] + shr esi, 8 + add esi, 256 + xor r10d, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + xor r10d, ebx + shr ebp, 8 + movd xmm1, r11d + add ebp, 256 + movq r11, xmm12 + mov r9d, DWORD PTR [r12+rcx*4] + xor r9d, DWORD PTR [r12+rsi*4] + mov eax, DWORD PTR [r12+rbp*4] + xor r9d, edi + movzx ecx, r14b + movd xmm0, r10d + movd xmm2, r9d + xor eax, DWORD PTR [r12+rcx*4] + mov rcx, rdx + xor eax, r15d + punpckldq xmm2, xmm1 + xor rcx, 16 + movd xmm6, eax + mov rax, rdx + punpckldq xmm6, xmm0 + xor rax, 32 + punpckldq xmm6, xmm2 + xor rdx, 48 + movdqu xmm2, XMMWORD PTR [rcx+r11] + pxor xmm6, xmm2 + pxor xmm6, xmm7 + paddq xmm2, xmm4 + movdqu xmm1, XMMWORD PTR [rax+r11] + movdqu xmm0, XMMWORD PTR [rdx+r11] + pxor xmm6, xmm1 + pxor xmm6, xmm0 + paddq xmm0, xmm5 + movdqu XMMWORD PTR [rcx+r11], xmm0 + movdqu XMMWORD PTR [rax+r11], xmm2 + movq rcx, xmm13 + paddq xmm1, xmm7 + movdqu XMMWORD PTR [rdx+r11], xmm1 + movq rdi, xmm6 + mov r10, rdi + and r10d, 2097136 + movdqa xmm0, xmm6 + pxor xmm0, xmm4 + movdqu XMMWORD PTR [r13], xmm0 + + mov ebx, [rsp+144] + mov ebp, [rsp+152] + add ebx, [rsp+148] + add ebp, [rsp+156] + shl rbp, 32 + or rbx, rbp + + xor rbx, QWORD PTR [r10+r11] + lea r14, QWORD PTR [r10+r11] + mov rbp, QWORD PTR [r14+8] + + mov [rsp+160], rbx + mov [rsp+168], rdi + mov [rsp+176], rbp + mov [rsp+184], r10 + mov r10, rsp + + mov ebx, [rsp+144] + mov esi, [rsp+148] + mov edi, [rsp+152] + mov ebp, [rsp+156] + + movd esp, xmm7 + movaps xmm0, xmm7 + psrldq xmm0, 8 + movd r15d, xmm0 + movd eax, xmm4 + movd edx, xmm5 + movaps xmm0, xmm5 + psrldq xmm0, 8 + movd r9d, xmm0 + +FN_PREFIX(CryptonightR_soft_aes_template_part2): + mov rsp, r10 + mov [rsp+144], ebx + mov [rsp+148], esi + mov [rsp+152], edi + mov [rsp+156], ebp + + mov edi, edi + shl rbp, 32 + or rbp, rdi + xor r8, rbp + + mov ebx, ebx + shl rsi, 32 + or rsi, rbx + xor QWORD PTR [rsp+320], rsi + + mov rbx, [rsp+160] + mov rdi, [rsp+168] + mov rbp, [rsp+176] + mov r10, [rsp+184] + + mov r9, r10 + xor r9, 16 + mov rcx, r10 + xor rcx, 32 + xor r10, 48 + mov rax, rbx + mul rdi + movdqu xmm2, XMMWORD PTR [r9+r11] + movdqu xmm1, XMMWORD PTR [rcx+r11] + pxor xmm6, xmm2 + pxor xmm6, xmm1 + paddq xmm1, xmm7 + add r8, rdx + movdqu xmm0, XMMWORD PTR [r10+r11] + pxor xmm6, xmm0 + paddq xmm0, xmm5 + paddq xmm2, xmm4 + movdqu XMMWORD PTR [r9+r11], xmm0 + movdqa xmm5, xmm4 + mov r9, QWORD PTR [rsp+320] + movdqa xmm4, xmm6 + add r9, rax + movdqu XMMWORD PTR [rcx+r11], xmm2 + movdqu XMMWORD PTR [r10+r11], xmm1 + mov r10, QWORD PTR [rsp+304] + movd r12d, xmm11 + mov QWORD PTR [r14], r8 + xor r8, rbx + mov rax, r8 + mov QWORD PTR [r14+8], r9 + and eax, 2097136 + xor r9, rbp + mov QWORD PTR [rsp+320], r9 + mov QWORD PTR [rsp+328], rax + sub r12d, 1 + jne FN_PREFIX(CryptonightR_soft_aes_template_mainloop) + +FN_PREFIX(CryptonightR_soft_aes_template_part3): + movaps xmm6, XMMWORD PTR [rsp+16] + movaps xmm7, XMMWORD PTR [rsp+32] + movaps xmm8, XMMWORD PTR [rsp+48] + movaps xmm9, XMMWORD PTR [rsp+64] + movaps xmm10, XMMWORD PTR [rsp+80] + movaps xmm11, XMMWORD PTR [rsp+96] + movaps xmm12, XMMWORD PTR [rsp+112] + movaps xmm13, XMMWORD PTR [rsp+128] + + add rsp, 232 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + pop rbx + ret +FN_PREFIX(CryptonightR_soft_aes_template_end): diff --git a/src/crypto/asm/CryptonightR_soft_aes_template_win.inc b/src/crypto/asm/CryptonightR_soft_aes_template_win.inc new file mode 100644 index 000000000..d771f69cf --- /dev/null +++ b/src/crypto/asm/CryptonightR_soft_aes_template_win.inc @@ -0,0 +1,279 @@ +PUBLIC CryptonightR_soft_aes_template_part1 +PUBLIC CryptonightR_soft_aes_template_mainloop +PUBLIC CryptonightR_soft_aes_template_part2 +PUBLIC CryptonightR_soft_aes_template_part3 +PUBLIC CryptonightR_soft_aes_template_end + +ALIGN(64) +CryptonightR_soft_aes_template_part1: + mov QWORD PTR [rsp+8], rcx + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 232 + + mov eax, [rcx+96] + mov ebx, [rcx+100] + mov esi, [rcx+104] + mov edx, [rcx+108] + mov [rsp+144], eax + mov [rsp+148], ebx + mov [rsp+152], esi + mov [rsp+156], edx + + mov rax, QWORD PTR [rcx+48] + mov r10, rcx + xor rax, QWORD PTR [rcx+16] + mov r8, QWORD PTR [rcx+32] + xor r8, QWORD PTR [rcx] + mov r9, QWORD PTR [rcx+40] + xor r9, QWORD PTR [rcx+8] + movq xmm4, rax + mov rdx, QWORD PTR [rcx+56] + xor rdx, QWORD PTR [rcx+24] + mov r11, QWORD PTR [rcx+224] + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r10+72] + mov rax, QWORD PTR [r10+80] + movq xmm0, rdx + xor rax, QWORD PTR [r10+64] + + movaps XMMWORD PTR [rsp+16], xmm6 + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+48], xmm8 + movaps XMMWORD PTR [rsp+64], xmm9 + movaps XMMWORD PTR [rsp+80], xmm10 + movaps XMMWORD PTR [rsp+96], xmm11 + movaps XMMWORD PTR [rsp+112], xmm12 + movaps XMMWORD PTR [rsp+128], xmm13 + + movq xmm5, rax + + mov rax, r8 + punpcklqdq xmm4, xmm0 + and eax, 2097136 + movq xmm10, QWORD PTR [r10+96] + movq xmm0, rcx + mov rcx, QWORD PTR [r10+104] + xorps xmm9, xmm9 + mov QWORD PTR [rsp+328], rax + movq xmm12, r11 + mov QWORD PTR [rsp+320], r9 + punpcklqdq xmm5, xmm0 + movq xmm13, rcx + mov r12d, 524288 + + ALIGN(64) +CryptonightR_soft_aes_template_mainloop: + movd xmm11, r12d + mov r12, QWORD PTR [r10+272] + lea r13, QWORD PTR [rax+r11] + mov esi, DWORD PTR [r13] + movq xmm0, r9 + mov r10d, DWORD PTR [r13+4] + movq xmm7, r8 + mov ebp, DWORD PTR [r13+12] + mov r14d, DWORD PTR [r13+8] + mov rdx, QWORD PTR [rsp+328] + movzx ecx, sil + shr esi, 8 + punpcklqdq xmm7, xmm0 + mov r15d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + mov edi, DWORD PTR [r12+rcx*4] + movzx ecx, r14b + shr r14d, 8 + mov ebx, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + shr ebp, 8 + mov r9d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + xor r15d, DWORD PTR [r12+rcx*4+1024] + movzx ecx, r14b + shr r14d, 8 + mov eax, r14d + shr eax, 8 + xor edi, DWORD PTR [r12+rcx*4+1024] + add eax, 256 + movzx ecx, bpl + shr ebp, 8 + xor ebx, DWORD PTR [r12+rcx*4+1024] + movzx ecx, sil + shr esi, 8 + xor r9d, DWORD PTR [r12+rcx*4+1024] + add r12, 2048 + movzx ecx, r10b + shr r10d, 8 + add r10d, 256 + mov r11d, DWORD PTR [r12+rax*4] + xor r11d, DWORD PTR [r12+rcx*4] + xor r11d, r9d + movzx ecx, sil + mov r10d, DWORD PTR [r12+r10*4] + shr esi, 8 + add esi, 256 + xor r10d, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + xor r10d, ebx + shr ebp, 8 + movd xmm1, r11d + add ebp, 256 + movq r11, xmm12 + mov r9d, DWORD PTR [r12+rcx*4] + xor r9d, DWORD PTR [r12+rsi*4] + mov eax, DWORD PTR [r12+rbp*4] + xor r9d, edi + movzx ecx, r14b + movd xmm0, r10d + movd xmm2, r9d + xor eax, DWORD PTR [r12+rcx*4] + mov rcx, rdx + xor eax, r15d + punpckldq xmm2, xmm1 + xor rcx, 16 + movd xmm6, eax + mov rax, rdx + punpckldq xmm6, xmm0 + xor rax, 32 + punpckldq xmm6, xmm2 + xor rdx, 48 + movdqu xmm2, XMMWORD PTR [rcx+r11] + pxor xmm6, xmm2 + pxor xmm6, xmm7 + paddq xmm2, xmm4 + movdqu xmm1, XMMWORD PTR [rax+r11] + movdqu xmm0, XMMWORD PTR [rdx+r11] + pxor xmm6, xmm1 + pxor xmm6, xmm0 + paddq xmm0, xmm5 + movdqu XMMWORD PTR [rcx+r11], xmm0 + movdqu XMMWORD PTR [rax+r11], xmm2 + movq rcx, xmm13 + paddq xmm1, xmm7 + movdqu XMMWORD PTR [rdx+r11], xmm1 + movq rdi, xmm6 + mov r10, rdi + and r10d, 2097136 + movdqa xmm0, xmm6 + pxor xmm0, xmm4 + movdqu XMMWORD PTR [r13], xmm0 + + mov ebx, [rsp+144] + mov ebp, [rsp+152] + add ebx, [rsp+148] + add ebp, [rsp+156] + shl rbp, 32 + or rbx, rbp + + xor rbx, QWORD PTR [r10+r11] + lea r14, QWORD PTR [r10+r11] + mov rbp, QWORD PTR [r14+8] + + mov [rsp+160], rbx + mov [rsp+168], rdi + mov [rsp+176], rbp + mov [rsp+184], r10 + mov r10, rsp + + mov ebx, [rsp+144] + mov esi, [rsp+148] + mov edi, [rsp+152] + mov ebp, [rsp+156] + + movd esp, xmm7 + movaps xmm0, xmm7 + psrldq xmm0, 8 + movd r15d, xmm0 + movd eax, xmm4 + movd edx, xmm5 + movaps xmm0, xmm5 + psrldq xmm0, 8 + movd r9d, xmm0 + +CryptonightR_soft_aes_template_part2: + mov rsp, r10 + mov [rsp+144], ebx + mov [rsp+148], esi + mov [rsp+152], edi + mov [rsp+156], ebp + + mov edi, edi + shl rbp, 32 + or rbp, rdi + xor r8, rbp + + mov ebx, ebx + shl rsi, 32 + or rsi, rbx + xor QWORD PTR [rsp+320], rsi + + mov rbx, [rsp+160] + mov rdi, [rsp+168] + mov rbp, [rsp+176] + mov r10, [rsp+184] + + mov r9, r10 + xor r9, 16 + mov rcx, r10 + xor rcx, 32 + xor r10, 48 + mov rax, rbx + mul rdi + movdqu xmm2, XMMWORD PTR [r9+r11] + movdqu xmm1, XMMWORD PTR [rcx+r11] + pxor xmm6, xmm2 + pxor xmm6, xmm1 + paddq xmm1, xmm7 + add r8, rdx + movdqu xmm0, XMMWORD PTR [r10+r11] + pxor xmm6, xmm0 + paddq xmm0, xmm5 + paddq xmm2, xmm4 + movdqu XMMWORD PTR [r9+r11], xmm0 + movdqa xmm5, xmm4 + mov r9, QWORD PTR [rsp+320] + movdqa xmm4, xmm6 + add r9, rax + movdqu XMMWORD PTR [rcx+r11], xmm2 + movdqu XMMWORD PTR [r10+r11], xmm1 + mov r10, QWORD PTR [rsp+304] + movd r12d, xmm11 + mov QWORD PTR [r14], r8 + xor r8, rbx + mov rax, r8 + mov QWORD PTR [r14+8], r9 + and eax, 2097136 + xor r9, rbp + mov QWORD PTR [rsp+320], r9 + mov QWORD PTR [rsp+328], rax + sub r12d, 1 + jne CryptonightR_soft_aes_template_mainloop + +CryptonightR_soft_aes_template_part3: + movaps xmm6, XMMWORD PTR [rsp+16] + movaps xmm7, XMMWORD PTR [rsp+32] + movaps xmm8, XMMWORD PTR [rsp+48] + movaps xmm9, XMMWORD PTR [rsp+64] + movaps xmm10, XMMWORD PTR [rsp+80] + movaps xmm11, XMMWORD PTR [rsp+96] + movaps xmm12, XMMWORD PTR [rsp+112] + movaps xmm13, XMMWORD PTR [rsp+128] + + add rsp, 232 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + pop rbx + ret +CryptonightR_soft_aes_template_end: diff --git a/src/crypto/asm/CryptonightR_template.S b/src/crypto/asm/CryptonightR_template.S index 5f3046cb9..d2974d160 100644 --- a/src/crypto/asm/CryptonightR_template.S +++ b/src/crypto/asm/CryptonightR_template.S @@ -531,6 +531,8 @@ PUBLIC FN_PREFIX(CryptonightR_instruction_mov256) #include "CryptonightWOW_template.inc" #include "CryptonightR_template.inc" +#include "CryptonightWOW_soft_aes_template.inc" +#include "CryptonightR_soft_aes_template.inc" FN_PREFIX(CryptonightR_instruction0): imul rbx, rbx diff --git a/src/crypto/asm/CryptonightR_template.asm b/src/crypto/asm/CryptonightR_template.asm index 25b72c3c0..250eca3d0 100644 --- a/src/crypto/asm/CryptonightR_template.asm +++ b/src/crypto/asm/CryptonightR_template.asm @@ -518,6 +518,8 @@ PUBLIC CryptonightR_instruction_mov256 INCLUDE CryptonightWOW_template_win.inc INCLUDE CryptonightR_template_win.inc +INCLUDE CryptonightWOW_soft_aes_template_win.inc +INCLUDE CryptonightR_soft_aes_template_win.inc CryptonightR_instruction0: imul rbx, rbx diff --git a/src/crypto/asm/CryptonightR_template.h b/src/crypto/asm/CryptonightR_template.h index c2054705b..d9159a8f2 100644 --- a/src/crypto/asm/CryptonightR_template.h +++ b/src/crypto/asm/CryptonightR_template.h @@ -26,6 +26,30 @@ extern "C" void CryptonightR_template_double_part4(); void CryptonightR_template_double_end(); + void CryptonightWOW_soft_aes_template_part1(); + void CryptonightWOW_soft_aes_template_mainloop(); + void CryptonightWOW_soft_aes_template_part2(); + void CryptonightWOW_soft_aes_template_part3(); + void CryptonightWOW_soft_aes_template_end(); + void CryptonightWOW_soft_aes_template_double_part1(); + void CryptonightWOW_soft_aes_template_double_mainloop(); + void CryptonightWOW_soft_aes_template_double_part2(); + void CryptonightWOW_soft_aes_template_double_part3(); + void CryptonightWOW_soft_aes_template_double_part4(); + void CryptonightWOW_soft_aes_template_double_end(); + + void CryptonightR_soft_aes_template_part1(); + void CryptonightR_soft_aes_template_mainloop(); + void CryptonightR_soft_aes_template_part2(); + void CryptonightR_soft_aes_template_part3(); + void CryptonightR_soft_aes_template_end(); + void CryptonightR_soft_aes_template_double_part1(); + void CryptonightR_soft_aes_template_double_mainloop(); + void CryptonightR_soft_aes_template_double_part2(); + void CryptonightR_soft_aes_template_double_part3(); + void CryptonightR_soft_aes_template_double_part4(); + void CryptonightR_soft_aes_template_double_end(); + void CryptonightR_instruction0(); void CryptonightR_instruction1(); void CryptonightR_instruction2(); diff --git a/src/crypto/asm/CryptonightWOW_soft_aes_template.inc b/src/crypto/asm/CryptonightWOW_soft_aes_template.inc new file mode 100644 index 000000000..feea3949c --- /dev/null +++ b/src/crypto/asm/CryptonightWOW_soft_aes_template.inc @@ -0,0 +1,266 @@ +PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_part1) +PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_mainloop) +PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_part2) +PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_part3) +PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_end) + +ALIGN(64) +FN_PREFIX(CryptonightWOW_soft_aes_template_part1): + mov QWORD PTR [rsp+8], rcx + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 232 + + mov eax, [rcx+96] + mov ebx, [rcx+100] + mov esi, [rcx+104] + mov edx, [rcx+108] + mov [rsp+144], eax + mov [rsp+148], ebx + mov [rsp+152], esi + mov [rsp+156], edx + + mov rax, QWORD PTR [rcx+48] + mov r10, rcx + xor rax, QWORD PTR [rcx+16] + mov r8, QWORD PTR [rcx+32] + xor r8, QWORD PTR [rcx] + mov r9, QWORD PTR [rcx+40] + xor r9, QWORD PTR [rcx+8] + movq xmm4, rax + mov rdx, QWORD PTR [rcx+56] + xor rdx, QWORD PTR [rcx+24] + mov r11, QWORD PTR [rcx+224] + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r10+72] + mov rax, QWORD PTR [r10+80] + movq xmm0, rdx + xor rax, QWORD PTR [r10+64] + + movaps XMMWORD PTR [rsp+16], xmm6 + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+48], xmm8 + movaps XMMWORD PTR [rsp+64], xmm9 + movaps XMMWORD PTR [rsp+80], xmm10 + movaps XMMWORD PTR [rsp+96], xmm11 + movaps XMMWORD PTR [rsp+112], xmm12 + movaps XMMWORD PTR [rsp+128], xmm13 + + movq xmm5, rax + + mov rax, r8 + punpcklqdq xmm4, xmm0 + and eax, 2097136 + movq xmm10, QWORD PTR [r10+96] + movq xmm0, rcx + mov rcx, QWORD PTR [r10+104] + xorps xmm9, xmm9 + mov QWORD PTR [rsp+328], rax + movq xmm12, r11 + mov QWORD PTR [rsp+320], r9 + punpcklqdq xmm5, xmm0 + movq xmm13, rcx + mov r12d, 524288 + + ALIGN(64) +FN_PREFIX(CryptonightWOW_soft_aes_template_mainloop): + movd xmm11, r12d + mov r12, QWORD PTR [r10+272] + lea r13, QWORD PTR [rax+r11] + mov esi, DWORD PTR [r13] + movq xmm0, r9 + mov r10d, DWORD PTR [r13+4] + movq xmm7, r8 + mov ebp, DWORD PTR [r13+12] + mov r14d, DWORD PTR [r13+8] + mov rdx, QWORD PTR [rsp+328] + movzx ecx, sil + shr esi, 8 + punpcklqdq xmm7, xmm0 + mov r15d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + mov edi, DWORD PTR [r12+rcx*4] + movzx ecx, r14b + shr r14d, 8 + mov ebx, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + shr ebp, 8 + mov r9d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + xor r15d, DWORD PTR [r12+rcx*4+1024] + movzx ecx, r14b + shr r14d, 8 + mov eax, r14d + shr eax, 8 + xor edi, DWORD PTR [r12+rcx*4+1024] + add eax, 256 + movzx ecx, bpl + shr ebp, 8 + xor ebx, DWORD PTR [r12+rcx*4+1024] + movzx ecx, sil + shr esi, 8 + xor r9d, DWORD PTR [r12+rcx*4+1024] + add r12, 2048 + movzx ecx, r10b + shr r10d, 8 + add r10d, 256 + mov r11d, DWORD PTR [r12+rax*4] + xor r11d, DWORD PTR [r12+rcx*4] + xor r11d, r9d + movzx ecx, sil + mov r10d, DWORD PTR [r12+r10*4] + shr esi, 8 + add esi, 256 + xor r10d, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + xor r10d, ebx + shr ebp, 8 + movd xmm1, r11d + add ebp, 256 + movq r11, xmm12 + mov r9d, DWORD PTR [r12+rcx*4] + xor r9d, DWORD PTR [r12+rsi*4] + mov eax, DWORD PTR [r12+rbp*4] + xor r9d, edi + movzx ecx, r14b + movd xmm0, r10d + movd xmm2, r9d + xor eax, DWORD PTR [r12+rcx*4] + mov rcx, rdx + xor eax, r15d + punpckldq xmm2, xmm1 + xor rcx, 16 + movd xmm6, eax + mov rax, rdx + punpckldq xmm6, xmm0 + xor rax, 32 + punpckldq xmm6, xmm2 + xor rdx, 48 + movdqu xmm2, XMMWORD PTR [rcx+r11] + pxor xmm6, xmm7 + paddq xmm2, xmm4 + movdqu xmm1, XMMWORD PTR [rax+r11] + movdqu xmm0, XMMWORD PTR [rdx+r11] + paddq xmm0, xmm5 + movdqu XMMWORD PTR [rcx+r11], xmm0 + movdqu XMMWORD PTR [rax+r11], xmm2 + movq rcx, xmm13 + paddq xmm1, xmm7 + movdqu XMMWORD PTR [rdx+r11], xmm1 + movq rdi, xmm6 + mov r10, rdi + and r10d, 2097136 + movdqa xmm0, xmm6 + pxor xmm0, xmm4 + movdqu XMMWORD PTR [r13], xmm0 + + mov ebx, [rsp+144] + mov ebp, [rsp+152] + add ebx, [rsp+148] + add ebp, [rsp+156] + shl rbp, 32 + or rbx, rbp + + xor rbx, QWORD PTR [r10+r11] + lea r14, QWORD PTR [r10+r11] + mov rbp, QWORD PTR [r14+8] + + mov [rsp+160], rbx + mov [rsp+168], rdi + mov [rsp+176], rbp + mov [rsp+184], r10 + mov r10, rsp + + mov ebx, [rsp+144] + mov esi, [rsp+148] + mov edi, [rsp+152] + mov ebp, [rsp+156] + + movd esp, xmm7 + movaps xmm0, xmm7 + psrldq xmm0, 8 + movd r15d, xmm0 + movd eax, xmm4 + movd edx, xmm5 + +FN_PREFIX(CryptonightWOW_soft_aes_template_part2): + mov rsp, r10 + mov [rsp+144], ebx + mov [rsp+148], esi + mov [rsp+152], edi + mov [rsp+156], ebp + + mov rbx, [rsp+160] + mov rdi, [rsp+168] + mov rbp, [rsp+176] + mov r10, [rsp+184] + + mov r9, r10 + xor r9, 16 + mov rcx, r10 + xor rcx, 32 + xor r10, 48 + mov rax, rbx + mul rdi + movdqu xmm2, XMMWORD PTR [r9+r11] + movdqu xmm1, XMMWORD PTR [rcx+r11] + paddq xmm1, xmm7 + movq xmm0, rax + movq xmm3, rdx + xor rax, QWORD PTR [r11+rcx+8] + xor rdx, QWORD PTR [rcx+r11] + punpcklqdq xmm3, xmm0 + add r8, rdx + movdqu xmm0, XMMWORD PTR [r10+r11] + pxor xmm2, xmm3 + paddq xmm0, xmm5 + paddq xmm2, xmm4 + movdqu XMMWORD PTR [r9+r11], xmm0 + movdqa xmm5, xmm4 + mov r9, QWORD PTR [rsp+320] + movdqa xmm4, xmm6 + add r9, rax + movdqu XMMWORD PTR [rcx+r11], xmm2 + movdqu XMMWORD PTR [r10+r11], xmm1 + mov r10, QWORD PTR [rsp+304] + movd r12d, xmm11 + mov QWORD PTR [r14], r8 + xor r8, rbx + mov rax, r8 + mov QWORD PTR [r14+8], r9 + and eax, 2097136 + xor r9, rbp + mov QWORD PTR [rsp+320], r9 + mov QWORD PTR [rsp+328], rax + sub r12d, 1 + jne FN_PREFIX(CryptonightWOW_soft_aes_template_mainloop) + +FN_PREFIX(CryptonightWOW_soft_aes_template_part3): + movaps xmm6, XMMWORD PTR [rsp+16] + movaps xmm7, XMMWORD PTR [rsp+32] + movaps xmm8, XMMWORD PTR [rsp+48] + movaps xmm9, XMMWORD PTR [rsp+64] + movaps xmm10, XMMWORD PTR [rsp+80] + movaps xmm11, XMMWORD PTR [rsp+96] + movaps xmm12, XMMWORD PTR [rsp+112] + movaps xmm13, XMMWORD PTR [rsp+128] + + add rsp, 232 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + pop rbx + ret +FN_PREFIX(CryptonightWOW_soft_aes_template_end): diff --git a/src/crypto/asm/CryptonightWOW_soft_aes_template_win.inc b/src/crypto/asm/CryptonightWOW_soft_aes_template_win.inc new file mode 100644 index 000000000..6ebad99f6 --- /dev/null +++ b/src/crypto/asm/CryptonightWOW_soft_aes_template_win.inc @@ -0,0 +1,266 @@ +PUBLIC CryptonightWOW_soft_aes_template_part1 +PUBLIC CryptonightWOW_soft_aes_template_mainloop +PUBLIC CryptonightWOW_soft_aes_template_part2 +PUBLIC CryptonightWOW_soft_aes_template_part3 +PUBLIC CryptonightWOW_soft_aes_template_end + +ALIGN(64) +CryptonightWOW_soft_aes_template_part1: + mov QWORD PTR [rsp+8], rcx + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 232 + + mov eax, [rcx+96] + mov ebx, [rcx+100] + mov esi, [rcx+104] + mov edx, [rcx+108] + mov [rsp+144], eax + mov [rsp+148], ebx + mov [rsp+152], esi + mov [rsp+156], edx + + mov rax, QWORD PTR [rcx+48] + mov r10, rcx + xor rax, QWORD PTR [rcx+16] + mov r8, QWORD PTR [rcx+32] + xor r8, QWORD PTR [rcx] + mov r9, QWORD PTR [rcx+40] + xor r9, QWORD PTR [rcx+8] + movq xmm4, rax + mov rdx, QWORD PTR [rcx+56] + xor rdx, QWORD PTR [rcx+24] + mov r11, QWORD PTR [rcx+224] + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r10+72] + mov rax, QWORD PTR [r10+80] + movq xmm0, rdx + xor rax, QWORD PTR [r10+64] + + movaps XMMWORD PTR [rsp+16], xmm6 + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+48], xmm8 + movaps XMMWORD PTR [rsp+64], xmm9 + movaps XMMWORD PTR [rsp+80], xmm10 + movaps XMMWORD PTR [rsp+96], xmm11 + movaps XMMWORD PTR [rsp+112], xmm12 + movaps XMMWORD PTR [rsp+128], xmm13 + + movq xmm5, rax + + mov rax, r8 + punpcklqdq xmm4, xmm0 + and eax, 2097136 + movq xmm10, QWORD PTR [r10+96] + movq xmm0, rcx + mov rcx, QWORD PTR [r10+104] + xorps xmm9, xmm9 + mov QWORD PTR [rsp+328], rax + movq xmm12, r11 + mov QWORD PTR [rsp+320], r9 + punpcklqdq xmm5, xmm0 + movq xmm13, rcx + mov r12d, 524288 + + ALIGN(64) +CryptonightWOW_soft_aes_template_mainloop: + movd xmm11, r12d + mov r12, QWORD PTR [r10+272] + lea r13, QWORD PTR [rax+r11] + mov esi, DWORD PTR [r13] + movq xmm0, r9 + mov r10d, DWORD PTR [r13+4] + movq xmm7, r8 + mov ebp, DWORD PTR [r13+12] + mov r14d, DWORD PTR [r13+8] + mov rdx, QWORD PTR [rsp+328] + movzx ecx, sil + shr esi, 8 + punpcklqdq xmm7, xmm0 + mov r15d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + mov edi, DWORD PTR [r12+rcx*4] + movzx ecx, r14b + shr r14d, 8 + mov ebx, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + shr ebp, 8 + mov r9d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + xor r15d, DWORD PTR [r12+rcx*4+1024] + movzx ecx, r14b + shr r14d, 8 + mov eax, r14d + shr eax, 8 + xor edi, DWORD PTR [r12+rcx*4+1024] + add eax, 256 + movzx ecx, bpl + shr ebp, 8 + xor ebx, DWORD PTR [r12+rcx*4+1024] + movzx ecx, sil + shr esi, 8 + xor r9d, DWORD PTR [r12+rcx*4+1024] + add r12, 2048 + movzx ecx, r10b + shr r10d, 8 + add r10d, 256 + mov r11d, DWORD PTR [r12+rax*4] + xor r11d, DWORD PTR [r12+rcx*4] + xor r11d, r9d + movzx ecx, sil + mov r10d, DWORD PTR [r12+r10*4] + shr esi, 8 + add esi, 256 + xor r10d, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + xor r10d, ebx + shr ebp, 8 + movd xmm1, r11d + add ebp, 256 + movq r11, xmm12 + mov r9d, DWORD PTR [r12+rcx*4] + xor r9d, DWORD PTR [r12+rsi*4] + mov eax, DWORD PTR [r12+rbp*4] + xor r9d, edi + movzx ecx, r14b + movd xmm0, r10d + movd xmm2, r9d + xor eax, DWORD PTR [r12+rcx*4] + mov rcx, rdx + xor eax, r15d + punpckldq xmm2, xmm1 + xor rcx, 16 + movd xmm6, eax + mov rax, rdx + punpckldq xmm6, xmm0 + xor rax, 32 + punpckldq xmm6, xmm2 + xor rdx, 48 + movdqu xmm2, XMMWORD PTR [rcx+r11] + pxor xmm6, xmm7 + paddq xmm2, xmm4 + movdqu xmm1, XMMWORD PTR [rax+r11] + movdqu xmm0, XMMWORD PTR [rdx+r11] + paddq xmm0, xmm5 + movdqu XMMWORD PTR [rcx+r11], xmm0 + movdqu XMMWORD PTR [rax+r11], xmm2 + movq rcx, xmm13 + paddq xmm1, xmm7 + movdqu XMMWORD PTR [rdx+r11], xmm1 + movq rdi, xmm6 + mov r10, rdi + and r10d, 2097136 + movdqa xmm0, xmm6 + pxor xmm0, xmm4 + movdqu XMMWORD PTR [r13], xmm0 + + mov ebx, [rsp+144] + mov ebp, [rsp+152] + add ebx, [rsp+148] + add ebp, [rsp+156] + shl rbp, 32 + or rbx, rbp + + xor rbx, QWORD PTR [r10+r11] + lea r14, QWORD PTR [r10+r11] + mov rbp, QWORD PTR [r14+8] + + mov [rsp+160], rbx + mov [rsp+168], rdi + mov [rsp+176], rbp + mov [rsp+184], r10 + mov r10, rsp + + mov ebx, [rsp+144] + mov esi, [rsp+148] + mov edi, [rsp+152] + mov ebp, [rsp+156] + + movd esp, xmm7 + movaps xmm0, xmm7 + psrldq xmm0, 8 + movd r15d, xmm0 + movd eax, xmm4 + movd edx, xmm5 + +CryptonightWOW_soft_aes_template_part2: + mov rsp, r10 + mov [rsp+144], ebx + mov [rsp+148], esi + mov [rsp+152], edi + mov [rsp+156], ebp + + mov rbx, [rsp+160] + mov rdi, [rsp+168] + mov rbp, [rsp+176] + mov r10, [rsp+184] + + mov r9, r10 + xor r9, 16 + mov rcx, r10 + xor rcx, 32 + xor r10, 48 + mov rax, rbx + mul rdi + movdqu xmm2, XMMWORD PTR [r9+r11] + movdqu xmm1, XMMWORD PTR [rcx+r11] + paddq xmm1, xmm7 + movq xmm0, rax + movq xmm3, rdx + xor rax, QWORD PTR [r11+rcx+8] + xor rdx, QWORD PTR [rcx+r11] + punpcklqdq xmm3, xmm0 + add r8, rdx + movdqu xmm0, XMMWORD PTR [r10+r11] + pxor xmm2, xmm3 + paddq xmm0, xmm5 + paddq xmm2, xmm4 + movdqu XMMWORD PTR [r9+r11], xmm0 + movdqa xmm5, xmm4 + mov r9, QWORD PTR [rsp+320] + movdqa xmm4, xmm6 + add r9, rax + movdqu XMMWORD PTR [rcx+r11], xmm2 + movdqu XMMWORD PTR [r10+r11], xmm1 + mov r10, QWORD PTR [rsp+304] + movd r12d, xmm11 + mov QWORD PTR [r14], r8 + xor r8, rbx + mov rax, r8 + mov QWORD PTR [r14+8], r9 + and eax, 2097136 + xor r9, rbp + mov QWORD PTR [rsp+320], r9 + mov QWORD PTR [rsp+328], rax + sub r12d, 1 + jne CryptonightWOW_soft_aes_template_mainloop + +CryptonightWOW_soft_aes_template_part3: + movaps xmm6, XMMWORD PTR [rsp+16] + movaps xmm7, XMMWORD PTR [rsp+32] + movaps xmm8, XMMWORD PTR [rsp+48] + movaps xmm9, XMMWORD PTR [rsp+64] + movaps xmm10, XMMWORD PTR [rsp+80] + movaps xmm11, XMMWORD PTR [rsp+96] + movaps xmm12, XMMWORD PTR [rsp+112] + movaps xmm13, XMMWORD PTR [rsp+128] + + add rsp, 232 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + pop rbx + ret +CryptonightWOW_soft_aes_template_end: diff --git a/src/crypto/asm/win64/CryptonightR_soft_aes_template.inc b/src/crypto/asm/win64/CryptonightR_soft_aes_template.inc new file mode 100644 index 000000000..c4a0559bd --- /dev/null +++ b/src/crypto/asm/win64/CryptonightR_soft_aes_template.inc @@ -0,0 +1,279 @@ +PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_part1) +PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_mainloop) +PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_part2) +PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_part3) +PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_end) + +ALIGN(64) +FN_PREFIX(CryptonightR_soft_aes_template_part1): + mov QWORD PTR [rsp+8], rcx + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 232 + + mov eax, [rcx+96] + mov ebx, [rcx+100] + mov esi, [rcx+104] + mov edx, [rcx+108] + mov [rsp+144], eax + mov [rsp+148], ebx + mov [rsp+152], esi + mov [rsp+156], edx + + mov rax, QWORD PTR [rcx+48] + mov r10, rcx + xor rax, QWORD PTR [rcx+16] + mov r8, QWORD PTR [rcx+32] + xor r8, QWORD PTR [rcx] + mov r9, QWORD PTR [rcx+40] + xor r9, QWORD PTR [rcx+8] + movd xmm4, rax + mov rdx, QWORD PTR [rcx+56] + xor rdx, QWORD PTR [rcx+24] + mov r11, QWORD PTR [rcx+224] + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r10+72] + mov rax, QWORD PTR [r10+80] + movd xmm0, rdx + xor rax, QWORD PTR [r10+64] + + movaps XMMWORD PTR [rsp+16], xmm6 + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+48], xmm8 + movaps XMMWORD PTR [rsp+64], xmm9 + movaps XMMWORD PTR [rsp+80], xmm10 + movaps XMMWORD PTR [rsp+96], xmm11 + movaps XMMWORD PTR [rsp+112], xmm12 + movaps XMMWORD PTR [rsp+128], xmm13 + + movd xmm5, rax + + mov rax, r8 + punpcklqdq xmm4, xmm0 + and eax, 2097136 + movd xmm10, QWORD PTR [r10+96] + movd xmm0, rcx + mov rcx, QWORD PTR [r10+104] + xorps xmm9, xmm9 + mov QWORD PTR [rsp+328], rax + movd xmm12, r11 + mov QWORD PTR [rsp+320], r9 + punpcklqdq xmm5, xmm0 + movd xmm13, rcx + mov r12d, 524288 + + ALIGN(64) +FN_PREFIX(CryptonightR_soft_aes_template_mainloop): + movd xmm11, r12d + mov r12, QWORD PTR [r10+272] + lea r13, QWORD PTR [rax+r11] + mov esi, DWORD PTR [r13] + movd xmm0, r9 + mov r10d, DWORD PTR [r13+4] + movd xmm7, r8 + mov ebp, DWORD PTR [r13+12] + mov r14d, DWORD PTR [r13+8] + mov rdx, QWORD PTR [rsp+328] + movzx ecx, sil + shr esi, 8 + punpcklqdq xmm7, xmm0 + mov r15d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + mov edi, DWORD PTR [r12+rcx*4] + movzx ecx, r14b + shr r14d, 8 + mov ebx, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + shr ebp, 8 + mov r9d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + xor r15d, DWORD PTR [r12+rcx*4+1024] + movzx ecx, r14b + shr r14d, 8 + mov eax, r14d + shr eax, 8 + xor edi, DWORD PTR [r12+rcx*4+1024] + add eax, 256 + movzx ecx, bpl + shr ebp, 8 + xor ebx, DWORD PTR [r12+rcx*4+1024] + movzx ecx, sil + shr esi, 8 + xor r9d, DWORD PTR [r12+rcx*4+1024] + add r12, 2048 + movzx ecx, r10b + shr r10d, 8 + add r10d, 256 + mov r11d, DWORD PTR [r12+rax*4] + xor r11d, DWORD PTR [r12+rcx*4] + xor r11d, r9d + movzx ecx, sil + mov r10d, DWORD PTR [r12+r10*4] + shr esi, 8 + add esi, 256 + xor r10d, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + xor r10d, ebx + shr ebp, 8 + movd xmm1, r11d + add ebp, 256 + movd r11, xmm12 + mov r9d, DWORD PTR [r12+rcx*4] + xor r9d, DWORD PTR [r12+rsi*4] + mov eax, DWORD PTR [r12+rbp*4] + xor r9d, edi + movzx ecx, r14b + movd xmm0, r10d + movd xmm2, r9d + xor eax, DWORD PTR [r12+rcx*4] + mov rcx, rdx + xor eax, r15d + punpckldq xmm2, xmm1 + xor rcx, 16 + movd xmm6, eax + mov rax, rdx + punpckldq xmm6, xmm0 + xor rax, 32 + punpckldq xmm6, xmm2 + xor rdx, 48 + movdqu xmm2, XMMWORD PTR [rcx+r11] + pxor xmm6, xmm2 + pxor xmm6, xmm7 + paddq xmm2, xmm4 + movdqu xmm1, XMMWORD PTR [rax+r11] + movdqu xmm0, XMMWORD PTR [rdx+r11] + pxor xmm6, xmm1 + pxor xmm6, xmm0 + paddq xmm0, xmm5 + movdqu XMMWORD PTR [rcx+r11], xmm0 + movdqu XMMWORD PTR [rax+r11], xmm2 + movd rcx, xmm13 + paddq xmm1, xmm7 + movdqu XMMWORD PTR [rdx+r11], xmm1 + movd rdi, xmm6 + mov r10, rdi + and r10d, 2097136 + movdqa xmm0, xmm6 + pxor xmm0, xmm4 + movdqu XMMWORD PTR [r13], xmm0 + + mov ebx, [rsp+144] + mov ebp, [rsp+152] + add ebx, [rsp+148] + add ebp, [rsp+156] + shl rbp, 32 + or rbx, rbp + + xor rbx, QWORD PTR [r10+r11] + lea r14, QWORD PTR [r10+r11] + mov rbp, QWORD PTR [r14+8] + + mov [rsp+160], rbx + mov [rsp+168], rdi + mov [rsp+176], rbp + mov [rsp+184], r10 + mov r10, rsp + + mov ebx, [rsp+144] + mov esi, [rsp+148] + mov edi, [rsp+152] + mov ebp, [rsp+156] + + movd esp, xmm7 + movaps xmm0, xmm7 + psrldq xmm0, 8 + movd r15d, xmm0 + movd eax, xmm4 + movd edx, xmm5 + movaps xmm0, xmm5 + psrldq xmm0, 8 + movd r9d, xmm0 + +FN_PREFIX(CryptonightR_soft_aes_template_part2): + mov rsp, r10 + mov [rsp+144], ebx + mov [rsp+148], esi + mov [rsp+152], edi + mov [rsp+156], ebp + + mov edi, edi + shl rbp, 32 + or rbp, rdi + xor r8, rbp + + mov ebx, ebx + shl rsi, 32 + or rsi, rbx + xor QWORD PTR [rsp+320], rsi + + mov rbx, [rsp+160] + mov rdi, [rsp+168] + mov rbp, [rsp+176] + mov r10, [rsp+184] + + mov r9, r10 + xor r9, 16 + mov rcx, r10 + xor rcx, 32 + xor r10, 48 + mov rax, rbx + mul rdi + movdqu xmm2, XMMWORD PTR [r9+r11] + movdqu xmm1, XMMWORD PTR [rcx+r11] + pxor xmm6, xmm2 + pxor xmm6, xmm1 + paddq xmm1, xmm7 + add r8, rdx + movdqu xmm0, XMMWORD PTR [r10+r11] + pxor xmm6, xmm0 + paddq xmm0, xmm5 + paddq xmm2, xmm4 + movdqu XMMWORD PTR [r9+r11], xmm0 + movdqa xmm5, xmm4 + mov r9, QWORD PTR [rsp+320] + movdqa xmm4, xmm6 + add r9, rax + movdqu XMMWORD PTR [rcx+r11], xmm2 + movdqu XMMWORD PTR [r10+r11], xmm1 + mov r10, QWORD PTR [rsp+304] + movd r12d, xmm11 + mov QWORD PTR [r14], r8 + xor r8, rbx + mov rax, r8 + mov QWORD PTR [r14+8], r9 + and eax, 2097136 + xor r9, rbp + mov QWORD PTR [rsp+320], r9 + mov QWORD PTR [rsp+328], rax + sub r12d, 1 + jne FN_PREFIX(CryptonightR_soft_aes_template_mainloop) + +FN_PREFIX(CryptonightR_soft_aes_template_part3): + movaps xmm6, XMMWORD PTR [rsp+16] + movaps xmm7, XMMWORD PTR [rsp+32] + movaps xmm8, XMMWORD PTR [rsp+48] + movaps xmm9, XMMWORD PTR [rsp+64] + movaps xmm10, XMMWORD PTR [rsp+80] + movaps xmm11, XMMWORD PTR [rsp+96] + movaps xmm12, XMMWORD PTR [rsp+112] + movaps xmm13, XMMWORD PTR [rsp+128] + + add rsp, 232 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + pop rbx + ret +FN_PREFIX(CryptonightR_soft_aes_template_end): diff --git a/src/crypto/asm/win64/CryptonightR_soft_aes_template_win.inc b/src/crypto/asm/win64/CryptonightR_soft_aes_template_win.inc new file mode 100644 index 000000000..d6d393a96 --- /dev/null +++ b/src/crypto/asm/win64/CryptonightR_soft_aes_template_win.inc @@ -0,0 +1,279 @@ +PUBLIC CryptonightR_soft_aes_template_part1 +PUBLIC CryptonightR_soft_aes_template_mainloop +PUBLIC CryptonightR_soft_aes_template_part2 +PUBLIC CryptonightR_soft_aes_template_part3 +PUBLIC CryptonightR_soft_aes_template_end + +ALIGN(64) +CryptonightR_soft_aes_template_part1: + mov QWORD PTR [rsp+8], rcx + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 232 + + mov eax, [rcx+96] + mov ebx, [rcx+100] + mov esi, [rcx+104] + mov edx, [rcx+108] + mov [rsp+144], eax + mov [rsp+148], ebx + mov [rsp+152], esi + mov [rsp+156], edx + + mov rax, QWORD PTR [rcx+48] + mov r10, rcx + xor rax, QWORD PTR [rcx+16] + mov r8, QWORD PTR [rcx+32] + xor r8, QWORD PTR [rcx] + mov r9, QWORD PTR [rcx+40] + xor r9, QWORD PTR [rcx+8] + movd xmm4, rax + mov rdx, QWORD PTR [rcx+56] + xor rdx, QWORD PTR [rcx+24] + mov r11, QWORD PTR [rcx+224] + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r10+72] + mov rax, QWORD PTR [r10+80] + movd xmm0, rdx + xor rax, QWORD PTR [r10+64] + + movaps XMMWORD PTR [rsp+16], xmm6 + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+48], xmm8 + movaps XMMWORD PTR [rsp+64], xmm9 + movaps XMMWORD PTR [rsp+80], xmm10 + movaps XMMWORD PTR [rsp+96], xmm11 + movaps XMMWORD PTR [rsp+112], xmm12 + movaps XMMWORD PTR [rsp+128], xmm13 + + movd xmm5, rax + + mov rax, r8 + punpcklqdq xmm4, xmm0 + and eax, 2097136 + movd xmm10, QWORD PTR [r10+96] + movd xmm0, rcx + mov rcx, QWORD PTR [r10+104] + xorps xmm9, xmm9 + mov QWORD PTR [rsp+328], rax + movd xmm12, r11 + mov QWORD PTR [rsp+320], r9 + punpcklqdq xmm5, xmm0 + movd xmm13, rcx + mov r12d, 524288 + + ALIGN(64) +CryptonightR_soft_aes_template_mainloop: + movd xmm11, r12d + mov r12, QWORD PTR [r10+272] + lea r13, QWORD PTR [rax+r11] + mov esi, DWORD PTR [r13] + movd xmm0, r9 + mov r10d, DWORD PTR [r13+4] + movd xmm7, r8 + mov ebp, DWORD PTR [r13+12] + mov r14d, DWORD PTR [r13+8] + mov rdx, QWORD PTR [rsp+328] + movzx ecx, sil + shr esi, 8 + punpcklqdq xmm7, xmm0 + mov r15d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + mov edi, DWORD PTR [r12+rcx*4] + movzx ecx, r14b + shr r14d, 8 + mov ebx, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + shr ebp, 8 + mov r9d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + xor r15d, DWORD PTR [r12+rcx*4+1024] + movzx ecx, r14b + shr r14d, 8 + mov eax, r14d + shr eax, 8 + xor edi, DWORD PTR [r12+rcx*4+1024] + add eax, 256 + movzx ecx, bpl + shr ebp, 8 + xor ebx, DWORD PTR [r12+rcx*4+1024] + movzx ecx, sil + shr esi, 8 + xor r9d, DWORD PTR [r12+rcx*4+1024] + add r12, 2048 + movzx ecx, r10b + shr r10d, 8 + add r10d, 256 + mov r11d, DWORD PTR [r12+rax*4] + xor r11d, DWORD PTR [r12+rcx*4] + xor r11d, r9d + movzx ecx, sil + mov r10d, DWORD PTR [r12+r10*4] + shr esi, 8 + add esi, 256 + xor r10d, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + xor r10d, ebx + shr ebp, 8 + movd xmm1, r11d + add ebp, 256 + movd r11, xmm12 + mov r9d, DWORD PTR [r12+rcx*4] + xor r9d, DWORD PTR [r12+rsi*4] + mov eax, DWORD PTR [r12+rbp*4] + xor r9d, edi + movzx ecx, r14b + movd xmm0, r10d + movd xmm2, r9d + xor eax, DWORD PTR [r12+rcx*4] + mov rcx, rdx + xor eax, r15d + punpckldq xmm2, xmm1 + xor rcx, 16 + movd xmm6, eax + mov rax, rdx + punpckldq xmm6, xmm0 + xor rax, 32 + punpckldq xmm6, xmm2 + xor rdx, 48 + movdqu xmm2, XMMWORD PTR [rcx+r11] + pxor xmm6, xmm2 + pxor xmm6, xmm7 + paddq xmm2, xmm4 + movdqu xmm1, XMMWORD PTR [rax+r11] + movdqu xmm0, XMMWORD PTR [rdx+r11] + pxor xmm6, xmm1 + pxor xmm6, xmm0 + paddq xmm0, xmm5 + movdqu XMMWORD PTR [rcx+r11], xmm0 + movdqu XMMWORD PTR [rax+r11], xmm2 + movd rcx, xmm13 + paddq xmm1, xmm7 + movdqu XMMWORD PTR [rdx+r11], xmm1 + movd rdi, xmm6 + mov r10, rdi + and r10d, 2097136 + movdqa xmm0, xmm6 + pxor xmm0, xmm4 + movdqu XMMWORD PTR [r13], xmm0 + + mov ebx, [rsp+144] + mov ebp, [rsp+152] + add ebx, [rsp+148] + add ebp, [rsp+156] + shl rbp, 32 + or rbx, rbp + + xor rbx, QWORD PTR [r10+r11] + lea r14, QWORD PTR [r10+r11] + mov rbp, QWORD PTR [r14+8] + + mov [rsp+160], rbx + mov [rsp+168], rdi + mov [rsp+176], rbp + mov [rsp+184], r10 + mov r10, rsp + + mov ebx, [rsp+144] + mov esi, [rsp+148] + mov edi, [rsp+152] + mov ebp, [rsp+156] + + movd esp, xmm7 + movaps xmm0, xmm7 + psrldq xmm0, 8 + movd r15d, xmm0 + movd eax, xmm4 + movd edx, xmm5 + movaps xmm0, xmm5 + psrldq xmm0, 8 + movd r9d, xmm0 + +CryptonightR_soft_aes_template_part2: + mov rsp, r10 + mov [rsp+144], ebx + mov [rsp+148], esi + mov [rsp+152], edi + mov [rsp+156], ebp + + mov edi, edi + shl rbp, 32 + or rbp, rdi + xor r8, rbp + + mov ebx, ebx + shl rsi, 32 + or rsi, rbx + xor QWORD PTR [rsp+320], rsi + + mov rbx, [rsp+160] + mov rdi, [rsp+168] + mov rbp, [rsp+176] + mov r10, [rsp+184] + + mov r9, r10 + xor r9, 16 + mov rcx, r10 + xor rcx, 32 + xor r10, 48 + mov rax, rbx + mul rdi + movdqu xmm2, XMMWORD PTR [r9+r11] + movdqu xmm1, XMMWORD PTR [rcx+r11] + pxor xmm6, xmm2 + pxor xmm6, xmm1 + paddq xmm1, xmm7 + add r8, rdx + movdqu xmm0, XMMWORD PTR [r10+r11] + pxor xmm6, xmm0 + paddq xmm0, xmm5 + paddq xmm2, xmm4 + movdqu XMMWORD PTR [r9+r11], xmm0 + movdqa xmm5, xmm4 + mov r9, QWORD PTR [rsp+320] + movdqa xmm4, xmm6 + add r9, rax + movdqu XMMWORD PTR [rcx+r11], xmm2 + movdqu XMMWORD PTR [r10+r11], xmm1 + mov r10, QWORD PTR [rsp+304] + movd r12d, xmm11 + mov QWORD PTR [r14], r8 + xor r8, rbx + mov rax, r8 + mov QWORD PTR [r14+8], r9 + and eax, 2097136 + xor r9, rbp + mov QWORD PTR [rsp+320], r9 + mov QWORD PTR [rsp+328], rax + sub r12d, 1 + jne CryptonightR_soft_aes_template_mainloop + +CryptonightR_soft_aes_template_part3: + movaps xmm6, XMMWORD PTR [rsp+16] + movaps xmm7, XMMWORD PTR [rsp+32] + movaps xmm8, XMMWORD PTR [rsp+48] + movaps xmm9, XMMWORD PTR [rsp+64] + movaps xmm10, XMMWORD PTR [rsp+80] + movaps xmm11, XMMWORD PTR [rsp+96] + movaps xmm12, XMMWORD PTR [rsp+112] + movaps xmm13, XMMWORD PTR [rsp+128] + + add rsp, 232 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + pop rbx + ret +CryptonightR_soft_aes_template_end: diff --git a/src/crypto/asm/win64/CryptonightR_template.S b/src/crypto/asm/win64/CryptonightR_template.S index 5f3046cb9..d2974d160 100644 --- a/src/crypto/asm/win64/CryptonightR_template.S +++ b/src/crypto/asm/win64/CryptonightR_template.S @@ -531,6 +531,8 @@ PUBLIC FN_PREFIX(CryptonightR_instruction_mov256) #include "CryptonightWOW_template.inc" #include "CryptonightR_template.inc" +#include "CryptonightWOW_soft_aes_template.inc" +#include "CryptonightR_soft_aes_template.inc" FN_PREFIX(CryptonightR_instruction0): imul rbx, rbx diff --git a/src/crypto/asm/win64/CryptonightR_template.asm b/src/crypto/asm/win64/CryptonightR_template.asm index 25b72c3c0..250eca3d0 100644 --- a/src/crypto/asm/win64/CryptonightR_template.asm +++ b/src/crypto/asm/win64/CryptonightR_template.asm @@ -518,6 +518,8 @@ PUBLIC CryptonightR_instruction_mov256 INCLUDE CryptonightWOW_template_win.inc INCLUDE CryptonightR_template_win.inc +INCLUDE CryptonightWOW_soft_aes_template_win.inc +INCLUDE CryptonightR_soft_aes_template_win.inc CryptonightR_instruction0: imul rbx, rbx diff --git a/src/crypto/asm/win64/CryptonightR_template.h b/src/crypto/asm/win64/CryptonightR_template.h deleted file mode 100644 index c2054705b..000000000 --- a/src/crypto/asm/win64/CryptonightR_template.h +++ /dev/null @@ -1,1063 +0,0 @@ -// Auto-generated file, do not edit - -extern "C" -{ - void CryptonightWOW_template_part1(); - void CryptonightWOW_template_mainloop(); - void CryptonightWOW_template_part2(); - void CryptonightWOW_template_part3(); - void CryptonightWOW_template_end(); - void CryptonightWOW_template_double_part1(); - void CryptonightWOW_template_double_mainloop(); - void CryptonightWOW_template_double_part2(); - void CryptonightWOW_template_double_part3(); - void CryptonightWOW_template_double_part4(); - void CryptonightWOW_template_double_end(); - - void CryptonightR_template_part1(); - void CryptonightR_template_mainloop(); - void CryptonightR_template_part2(); - void CryptonightR_template_part3(); - void CryptonightR_template_end(); - void CryptonightR_template_double_part1(); - void CryptonightR_template_double_mainloop(); - void CryptonightR_template_double_part2(); - void CryptonightR_template_double_part3(); - void CryptonightR_template_double_part4(); - void CryptonightR_template_double_end(); - - void CryptonightR_instruction0(); - void CryptonightR_instruction1(); - void CryptonightR_instruction2(); - void CryptonightR_instruction3(); - void CryptonightR_instruction4(); - void CryptonightR_instruction5(); - void CryptonightR_instruction6(); - void CryptonightR_instruction7(); - void CryptonightR_instruction8(); - void CryptonightR_instruction9(); - void CryptonightR_instruction10(); - void CryptonightR_instruction11(); - void CryptonightR_instruction12(); - void CryptonightR_instruction13(); - void CryptonightR_instruction14(); - void CryptonightR_instruction15(); - void CryptonightR_instruction16(); - void CryptonightR_instruction17(); - void CryptonightR_instruction18(); - void CryptonightR_instruction19(); - void CryptonightR_instruction20(); - void CryptonightR_instruction21(); - void CryptonightR_instruction22(); - void CryptonightR_instruction23(); - void CryptonightR_instruction24(); - void CryptonightR_instruction25(); - void CryptonightR_instruction26(); - void CryptonightR_instruction27(); - void CryptonightR_instruction28(); - void CryptonightR_instruction29(); - void CryptonightR_instruction30(); - void CryptonightR_instruction31(); - void CryptonightR_instruction32(); - void CryptonightR_instruction33(); - void CryptonightR_instruction34(); - void CryptonightR_instruction35(); - void CryptonightR_instruction36(); - void CryptonightR_instruction37(); - void CryptonightR_instruction38(); - void CryptonightR_instruction39(); - void CryptonightR_instruction40(); - void CryptonightR_instruction41(); - void CryptonightR_instruction42(); - void CryptonightR_instruction43(); - void CryptonightR_instruction44(); - void CryptonightR_instruction45(); - void CryptonightR_instruction46(); - void CryptonightR_instruction47(); - void CryptonightR_instruction48(); - void CryptonightR_instruction49(); - void CryptonightR_instruction50(); - void CryptonightR_instruction51(); - void CryptonightR_instruction52(); - void CryptonightR_instruction53(); - void CryptonightR_instruction54(); - void CryptonightR_instruction55(); - void CryptonightR_instruction56(); - void CryptonightR_instruction57(); - void CryptonightR_instruction58(); - void CryptonightR_instruction59(); - void CryptonightR_instruction60(); - void CryptonightR_instruction61(); - void CryptonightR_instruction62(); - void CryptonightR_instruction63(); - void CryptonightR_instruction64(); - void CryptonightR_instruction65(); - void CryptonightR_instruction66(); - void CryptonightR_instruction67(); - void CryptonightR_instruction68(); - void CryptonightR_instruction69(); - void CryptonightR_instruction70(); - void CryptonightR_instruction71(); - void CryptonightR_instruction72(); - void CryptonightR_instruction73(); - void CryptonightR_instruction74(); - void CryptonightR_instruction75(); - void CryptonightR_instruction76(); - void CryptonightR_instruction77(); - void CryptonightR_instruction78(); - void CryptonightR_instruction79(); - void CryptonightR_instruction80(); - void CryptonightR_instruction81(); - void CryptonightR_instruction82(); - void CryptonightR_instruction83(); - void CryptonightR_instruction84(); - void CryptonightR_instruction85(); - void CryptonightR_instruction86(); - void CryptonightR_instruction87(); - void CryptonightR_instruction88(); - void CryptonightR_instruction89(); - void CryptonightR_instruction90(); - void CryptonightR_instruction91(); - void CryptonightR_instruction92(); - void CryptonightR_instruction93(); - void CryptonightR_instruction94(); - void CryptonightR_instruction95(); - void CryptonightR_instruction96(); - void CryptonightR_instruction97(); - void CryptonightR_instruction98(); - void CryptonightR_instruction99(); - void CryptonightR_instruction100(); - void CryptonightR_instruction101(); - void CryptonightR_instruction102(); - void CryptonightR_instruction103(); - void CryptonightR_instruction104(); - void CryptonightR_instruction105(); - void CryptonightR_instruction106(); - void CryptonightR_instruction107(); - void CryptonightR_instruction108(); - void CryptonightR_instruction109(); - void CryptonightR_instruction110(); - void CryptonightR_instruction111(); - void CryptonightR_instruction112(); - void CryptonightR_instruction113(); - void CryptonightR_instruction114(); - void CryptonightR_instruction115(); - void CryptonightR_instruction116(); - void CryptonightR_instruction117(); - void CryptonightR_instruction118(); - void CryptonightR_instruction119(); - void CryptonightR_instruction120(); - void CryptonightR_instruction121(); - void CryptonightR_instruction122(); - void CryptonightR_instruction123(); - void CryptonightR_instruction124(); - void CryptonightR_instruction125(); - void CryptonightR_instruction126(); - void CryptonightR_instruction127(); - void CryptonightR_instruction128(); - void CryptonightR_instruction129(); - void CryptonightR_instruction130(); - void CryptonightR_instruction131(); - void CryptonightR_instruction132(); - void CryptonightR_instruction133(); - void CryptonightR_instruction134(); - void CryptonightR_instruction135(); - void CryptonightR_instruction136(); - void CryptonightR_instruction137(); - void CryptonightR_instruction138(); - void CryptonightR_instruction139(); - void CryptonightR_instruction140(); - void CryptonightR_instruction141(); - void CryptonightR_instruction142(); - void CryptonightR_instruction143(); - void CryptonightR_instruction144(); - void CryptonightR_instruction145(); - void CryptonightR_instruction146(); - void CryptonightR_instruction147(); - void CryptonightR_instruction148(); - void CryptonightR_instruction149(); - void CryptonightR_instruction150(); - void CryptonightR_instruction151(); - void CryptonightR_instruction152(); - void CryptonightR_instruction153(); - void CryptonightR_instruction154(); - void CryptonightR_instruction155(); - void CryptonightR_instruction156(); - void CryptonightR_instruction157(); - void CryptonightR_instruction158(); - void CryptonightR_instruction159(); - void CryptonightR_instruction160(); - void CryptonightR_instruction161(); - void CryptonightR_instruction162(); - void CryptonightR_instruction163(); - void CryptonightR_instruction164(); - void CryptonightR_instruction165(); - void CryptonightR_instruction166(); - void CryptonightR_instruction167(); - void CryptonightR_instruction168(); - void CryptonightR_instruction169(); - void CryptonightR_instruction170(); - void CryptonightR_instruction171(); - void CryptonightR_instruction172(); - void CryptonightR_instruction173(); - void CryptonightR_instruction174(); - void CryptonightR_instruction175(); - void CryptonightR_instruction176(); - void CryptonightR_instruction177(); - void CryptonightR_instruction178(); - void CryptonightR_instruction179(); - void CryptonightR_instruction180(); - void CryptonightR_instruction181(); - void CryptonightR_instruction182(); - void CryptonightR_instruction183(); - void CryptonightR_instruction184(); - void CryptonightR_instruction185(); - void CryptonightR_instruction186(); - void CryptonightR_instruction187(); - void CryptonightR_instruction188(); - void CryptonightR_instruction189(); - void CryptonightR_instruction190(); - void CryptonightR_instruction191(); - void CryptonightR_instruction192(); - void CryptonightR_instruction193(); - void CryptonightR_instruction194(); - void CryptonightR_instruction195(); - void CryptonightR_instruction196(); - void CryptonightR_instruction197(); - void CryptonightR_instruction198(); - void CryptonightR_instruction199(); - void CryptonightR_instruction200(); - void CryptonightR_instruction201(); - void CryptonightR_instruction202(); - void CryptonightR_instruction203(); - void CryptonightR_instruction204(); - void CryptonightR_instruction205(); - void CryptonightR_instruction206(); - void CryptonightR_instruction207(); - void CryptonightR_instruction208(); - void CryptonightR_instruction209(); - void CryptonightR_instruction210(); - void CryptonightR_instruction211(); - void CryptonightR_instruction212(); - void CryptonightR_instruction213(); - void CryptonightR_instruction214(); - void CryptonightR_instruction215(); - void CryptonightR_instruction216(); - void CryptonightR_instruction217(); - void CryptonightR_instruction218(); - void CryptonightR_instruction219(); - void CryptonightR_instruction220(); - void CryptonightR_instruction221(); - void CryptonightR_instruction222(); - void CryptonightR_instruction223(); - void CryptonightR_instruction224(); - void CryptonightR_instruction225(); - void CryptonightR_instruction226(); - void CryptonightR_instruction227(); - void CryptonightR_instruction228(); - void CryptonightR_instruction229(); - void CryptonightR_instruction230(); - void CryptonightR_instruction231(); - void CryptonightR_instruction232(); - void CryptonightR_instruction233(); - void CryptonightR_instruction234(); - void CryptonightR_instruction235(); - void CryptonightR_instruction236(); - void CryptonightR_instruction237(); - void CryptonightR_instruction238(); - void CryptonightR_instruction239(); - void CryptonightR_instruction240(); - void CryptonightR_instruction241(); - void CryptonightR_instruction242(); - void CryptonightR_instruction243(); - void CryptonightR_instruction244(); - void CryptonightR_instruction245(); - void CryptonightR_instruction246(); - void CryptonightR_instruction247(); - void CryptonightR_instruction248(); - void CryptonightR_instruction249(); - void CryptonightR_instruction250(); - void CryptonightR_instruction251(); - void CryptonightR_instruction252(); - void CryptonightR_instruction253(); - void CryptonightR_instruction254(); - void CryptonightR_instruction255(); - void CryptonightR_instruction256(); - void CryptonightR_instruction_mov0(); - void CryptonightR_instruction_mov1(); - void CryptonightR_instruction_mov2(); - void CryptonightR_instruction_mov3(); - void CryptonightR_instruction_mov4(); - void CryptonightR_instruction_mov5(); - void CryptonightR_instruction_mov6(); - void CryptonightR_instruction_mov7(); - void CryptonightR_instruction_mov8(); - void CryptonightR_instruction_mov9(); - void CryptonightR_instruction_mov10(); - void CryptonightR_instruction_mov11(); - void CryptonightR_instruction_mov12(); - void CryptonightR_instruction_mov13(); - void CryptonightR_instruction_mov14(); - void CryptonightR_instruction_mov15(); - void CryptonightR_instruction_mov16(); - void CryptonightR_instruction_mov17(); - void CryptonightR_instruction_mov18(); - void CryptonightR_instruction_mov19(); - void CryptonightR_instruction_mov20(); - void CryptonightR_instruction_mov21(); - void CryptonightR_instruction_mov22(); - void CryptonightR_instruction_mov23(); - void CryptonightR_instruction_mov24(); - void CryptonightR_instruction_mov25(); - void CryptonightR_instruction_mov26(); - void CryptonightR_instruction_mov27(); - void CryptonightR_instruction_mov28(); - void CryptonightR_instruction_mov29(); - void CryptonightR_instruction_mov30(); - void CryptonightR_instruction_mov31(); - void CryptonightR_instruction_mov32(); - void CryptonightR_instruction_mov33(); - void CryptonightR_instruction_mov34(); - void CryptonightR_instruction_mov35(); - void CryptonightR_instruction_mov36(); - void CryptonightR_instruction_mov37(); - void CryptonightR_instruction_mov38(); - void CryptonightR_instruction_mov39(); - void CryptonightR_instruction_mov40(); - void CryptonightR_instruction_mov41(); - void CryptonightR_instruction_mov42(); - void CryptonightR_instruction_mov43(); - void CryptonightR_instruction_mov44(); - void CryptonightR_instruction_mov45(); - void CryptonightR_instruction_mov46(); - void CryptonightR_instruction_mov47(); - void CryptonightR_instruction_mov48(); - void CryptonightR_instruction_mov49(); - void CryptonightR_instruction_mov50(); - void CryptonightR_instruction_mov51(); - void CryptonightR_instruction_mov52(); - void CryptonightR_instruction_mov53(); - void CryptonightR_instruction_mov54(); - void CryptonightR_instruction_mov55(); - void CryptonightR_instruction_mov56(); - void CryptonightR_instruction_mov57(); - void CryptonightR_instruction_mov58(); - void CryptonightR_instruction_mov59(); - void CryptonightR_instruction_mov60(); - void CryptonightR_instruction_mov61(); - void CryptonightR_instruction_mov62(); - void CryptonightR_instruction_mov63(); - void CryptonightR_instruction_mov64(); - void CryptonightR_instruction_mov65(); - void CryptonightR_instruction_mov66(); - void CryptonightR_instruction_mov67(); - void CryptonightR_instruction_mov68(); - void CryptonightR_instruction_mov69(); - void CryptonightR_instruction_mov70(); - void CryptonightR_instruction_mov71(); - void CryptonightR_instruction_mov72(); - void CryptonightR_instruction_mov73(); - void CryptonightR_instruction_mov74(); - void CryptonightR_instruction_mov75(); - void CryptonightR_instruction_mov76(); - void CryptonightR_instruction_mov77(); - void CryptonightR_instruction_mov78(); - void CryptonightR_instruction_mov79(); - void CryptonightR_instruction_mov80(); - void CryptonightR_instruction_mov81(); - void CryptonightR_instruction_mov82(); - void CryptonightR_instruction_mov83(); - void CryptonightR_instruction_mov84(); - void CryptonightR_instruction_mov85(); - void CryptonightR_instruction_mov86(); - void CryptonightR_instruction_mov87(); - void CryptonightR_instruction_mov88(); - void CryptonightR_instruction_mov89(); - void CryptonightR_instruction_mov90(); - void CryptonightR_instruction_mov91(); - void CryptonightR_instruction_mov92(); - void CryptonightR_instruction_mov93(); - void CryptonightR_instruction_mov94(); - void CryptonightR_instruction_mov95(); - void CryptonightR_instruction_mov96(); - void CryptonightR_instruction_mov97(); - void CryptonightR_instruction_mov98(); - void CryptonightR_instruction_mov99(); - void CryptonightR_instruction_mov100(); - void CryptonightR_instruction_mov101(); - void CryptonightR_instruction_mov102(); - void CryptonightR_instruction_mov103(); - void CryptonightR_instruction_mov104(); - void CryptonightR_instruction_mov105(); - void CryptonightR_instruction_mov106(); - void CryptonightR_instruction_mov107(); - void CryptonightR_instruction_mov108(); - void CryptonightR_instruction_mov109(); - void CryptonightR_instruction_mov110(); - void CryptonightR_instruction_mov111(); - void CryptonightR_instruction_mov112(); - void CryptonightR_instruction_mov113(); - void CryptonightR_instruction_mov114(); - void CryptonightR_instruction_mov115(); - void CryptonightR_instruction_mov116(); - void CryptonightR_instruction_mov117(); - void CryptonightR_instruction_mov118(); - void CryptonightR_instruction_mov119(); - void CryptonightR_instruction_mov120(); - void CryptonightR_instruction_mov121(); - void CryptonightR_instruction_mov122(); - void CryptonightR_instruction_mov123(); - void CryptonightR_instruction_mov124(); - void CryptonightR_instruction_mov125(); - void CryptonightR_instruction_mov126(); - void CryptonightR_instruction_mov127(); - void CryptonightR_instruction_mov128(); - void CryptonightR_instruction_mov129(); - void CryptonightR_instruction_mov130(); - void CryptonightR_instruction_mov131(); - void CryptonightR_instruction_mov132(); - void CryptonightR_instruction_mov133(); - void CryptonightR_instruction_mov134(); - void CryptonightR_instruction_mov135(); - void CryptonightR_instruction_mov136(); - void CryptonightR_instruction_mov137(); - void CryptonightR_instruction_mov138(); - void CryptonightR_instruction_mov139(); - void CryptonightR_instruction_mov140(); - void CryptonightR_instruction_mov141(); - void CryptonightR_instruction_mov142(); - void CryptonightR_instruction_mov143(); - void CryptonightR_instruction_mov144(); - void CryptonightR_instruction_mov145(); - void CryptonightR_instruction_mov146(); - void CryptonightR_instruction_mov147(); - void CryptonightR_instruction_mov148(); - void CryptonightR_instruction_mov149(); - void CryptonightR_instruction_mov150(); - void CryptonightR_instruction_mov151(); - void CryptonightR_instruction_mov152(); - void CryptonightR_instruction_mov153(); - void CryptonightR_instruction_mov154(); - void CryptonightR_instruction_mov155(); - void CryptonightR_instruction_mov156(); - void CryptonightR_instruction_mov157(); - void CryptonightR_instruction_mov158(); - void CryptonightR_instruction_mov159(); - void CryptonightR_instruction_mov160(); - void CryptonightR_instruction_mov161(); - void CryptonightR_instruction_mov162(); - void CryptonightR_instruction_mov163(); - void CryptonightR_instruction_mov164(); - void CryptonightR_instruction_mov165(); - void CryptonightR_instruction_mov166(); - void CryptonightR_instruction_mov167(); - void CryptonightR_instruction_mov168(); - void CryptonightR_instruction_mov169(); - void CryptonightR_instruction_mov170(); - void CryptonightR_instruction_mov171(); - void CryptonightR_instruction_mov172(); - void CryptonightR_instruction_mov173(); - void CryptonightR_instruction_mov174(); - void CryptonightR_instruction_mov175(); - void CryptonightR_instruction_mov176(); - void CryptonightR_instruction_mov177(); - void CryptonightR_instruction_mov178(); - void CryptonightR_instruction_mov179(); - void CryptonightR_instruction_mov180(); - void CryptonightR_instruction_mov181(); - void CryptonightR_instruction_mov182(); - void CryptonightR_instruction_mov183(); - void CryptonightR_instruction_mov184(); - void CryptonightR_instruction_mov185(); - void CryptonightR_instruction_mov186(); - void CryptonightR_instruction_mov187(); - void CryptonightR_instruction_mov188(); - void CryptonightR_instruction_mov189(); - void CryptonightR_instruction_mov190(); - void CryptonightR_instruction_mov191(); - void CryptonightR_instruction_mov192(); - void CryptonightR_instruction_mov193(); - void CryptonightR_instruction_mov194(); - void CryptonightR_instruction_mov195(); - void CryptonightR_instruction_mov196(); - void CryptonightR_instruction_mov197(); - void CryptonightR_instruction_mov198(); - void CryptonightR_instruction_mov199(); - void CryptonightR_instruction_mov200(); - void CryptonightR_instruction_mov201(); - void CryptonightR_instruction_mov202(); - void CryptonightR_instruction_mov203(); - void CryptonightR_instruction_mov204(); - void CryptonightR_instruction_mov205(); - void CryptonightR_instruction_mov206(); - void CryptonightR_instruction_mov207(); - void CryptonightR_instruction_mov208(); - void CryptonightR_instruction_mov209(); - void CryptonightR_instruction_mov210(); - void CryptonightR_instruction_mov211(); - void CryptonightR_instruction_mov212(); - void CryptonightR_instruction_mov213(); - void CryptonightR_instruction_mov214(); - void CryptonightR_instruction_mov215(); - void CryptonightR_instruction_mov216(); - void CryptonightR_instruction_mov217(); - void CryptonightR_instruction_mov218(); - void CryptonightR_instruction_mov219(); - void CryptonightR_instruction_mov220(); - void CryptonightR_instruction_mov221(); - void CryptonightR_instruction_mov222(); - void CryptonightR_instruction_mov223(); - void CryptonightR_instruction_mov224(); - void CryptonightR_instruction_mov225(); - void CryptonightR_instruction_mov226(); - void CryptonightR_instruction_mov227(); - void CryptonightR_instruction_mov228(); - void CryptonightR_instruction_mov229(); - void CryptonightR_instruction_mov230(); - void CryptonightR_instruction_mov231(); - void CryptonightR_instruction_mov232(); - void CryptonightR_instruction_mov233(); - void CryptonightR_instruction_mov234(); - void CryptonightR_instruction_mov235(); - void CryptonightR_instruction_mov236(); - void CryptonightR_instruction_mov237(); - void CryptonightR_instruction_mov238(); - void CryptonightR_instruction_mov239(); - void CryptonightR_instruction_mov240(); - void CryptonightR_instruction_mov241(); - void CryptonightR_instruction_mov242(); - void CryptonightR_instruction_mov243(); - void CryptonightR_instruction_mov244(); - void CryptonightR_instruction_mov245(); - void CryptonightR_instruction_mov246(); - void CryptonightR_instruction_mov247(); - void CryptonightR_instruction_mov248(); - void CryptonightR_instruction_mov249(); - void CryptonightR_instruction_mov250(); - void CryptonightR_instruction_mov251(); - void CryptonightR_instruction_mov252(); - void CryptonightR_instruction_mov253(); - void CryptonightR_instruction_mov254(); - void CryptonightR_instruction_mov255(); - void CryptonightR_instruction_mov256(); -} - -const void_func instructions[257] = { - CryptonightR_instruction0, - CryptonightR_instruction1, - CryptonightR_instruction2, - CryptonightR_instruction3, - CryptonightR_instruction4, - CryptonightR_instruction5, - CryptonightR_instruction6, - CryptonightR_instruction7, - CryptonightR_instruction8, - CryptonightR_instruction9, - CryptonightR_instruction10, - CryptonightR_instruction11, - CryptonightR_instruction12, - CryptonightR_instruction13, - CryptonightR_instruction14, - CryptonightR_instruction15, - CryptonightR_instruction16, - CryptonightR_instruction17, - CryptonightR_instruction18, - CryptonightR_instruction19, - CryptonightR_instruction20, - CryptonightR_instruction21, - CryptonightR_instruction22, - CryptonightR_instruction23, - CryptonightR_instruction24, - CryptonightR_instruction25, - CryptonightR_instruction26, - CryptonightR_instruction27, - CryptonightR_instruction28, - CryptonightR_instruction29, - CryptonightR_instruction30, - CryptonightR_instruction31, - CryptonightR_instruction32, - CryptonightR_instruction33, - CryptonightR_instruction34, - CryptonightR_instruction35, - CryptonightR_instruction36, - CryptonightR_instruction37, - CryptonightR_instruction38, - CryptonightR_instruction39, - CryptonightR_instruction40, - CryptonightR_instruction41, - CryptonightR_instruction42, - CryptonightR_instruction43, - CryptonightR_instruction44, - CryptonightR_instruction45, - CryptonightR_instruction46, - CryptonightR_instruction47, - CryptonightR_instruction48, - CryptonightR_instruction49, - CryptonightR_instruction50, - CryptonightR_instruction51, - CryptonightR_instruction52, - CryptonightR_instruction53, - CryptonightR_instruction54, - CryptonightR_instruction55, - CryptonightR_instruction56, - CryptonightR_instruction57, - CryptonightR_instruction58, - CryptonightR_instruction59, - CryptonightR_instruction60, - CryptonightR_instruction61, - CryptonightR_instruction62, - CryptonightR_instruction63, - CryptonightR_instruction64, - CryptonightR_instruction65, - CryptonightR_instruction66, - CryptonightR_instruction67, - CryptonightR_instruction68, - CryptonightR_instruction69, - CryptonightR_instruction70, - CryptonightR_instruction71, - CryptonightR_instruction72, - CryptonightR_instruction73, - CryptonightR_instruction74, - CryptonightR_instruction75, - CryptonightR_instruction76, - CryptonightR_instruction77, - CryptonightR_instruction78, - CryptonightR_instruction79, - CryptonightR_instruction80, - CryptonightR_instruction81, - CryptonightR_instruction82, - CryptonightR_instruction83, - CryptonightR_instruction84, - CryptonightR_instruction85, - CryptonightR_instruction86, - CryptonightR_instruction87, - CryptonightR_instruction88, - CryptonightR_instruction89, - CryptonightR_instruction90, - CryptonightR_instruction91, - CryptonightR_instruction92, - CryptonightR_instruction93, - CryptonightR_instruction94, - CryptonightR_instruction95, - CryptonightR_instruction96, - CryptonightR_instruction97, - CryptonightR_instruction98, - CryptonightR_instruction99, - CryptonightR_instruction100, - CryptonightR_instruction101, - CryptonightR_instruction102, - CryptonightR_instruction103, - CryptonightR_instruction104, - CryptonightR_instruction105, - CryptonightR_instruction106, - CryptonightR_instruction107, - CryptonightR_instruction108, - CryptonightR_instruction109, - CryptonightR_instruction110, - CryptonightR_instruction111, - CryptonightR_instruction112, - CryptonightR_instruction113, - CryptonightR_instruction114, - CryptonightR_instruction115, - CryptonightR_instruction116, - CryptonightR_instruction117, - CryptonightR_instruction118, - CryptonightR_instruction119, - CryptonightR_instruction120, - CryptonightR_instruction121, - CryptonightR_instruction122, - CryptonightR_instruction123, - CryptonightR_instruction124, - CryptonightR_instruction125, - CryptonightR_instruction126, - CryptonightR_instruction127, - CryptonightR_instruction128, - CryptonightR_instruction129, - CryptonightR_instruction130, - CryptonightR_instruction131, - CryptonightR_instruction132, - CryptonightR_instruction133, - CryptonightR_instruction134, - CryptonightR_instruction135, - CryptonightR_instruction136, - CryptonightR_instruction137, - CryptonightR_instruction138, - CryptonightR_instruction139, - CryptonightR_instruction140, - CryptonightR_instruction141, - CryptonightR_instruction142, - CryptonightR_instruction143, - CryptonightR_instruction144, - CryptonightR_instruction145, - CryptonightR_instruction146, - CryptonightR_instruction147, - CryptonightR_instruction148, - CryptonightR_instruction149, - CryptonightR_instruction150, - CryptonightR_instruction151, - CryptonightR_instruction152, - CryptonightR_instruction153, - CryptonightR_instruction154, - CryptonightR_instruction155, - CryptonightR_instruction156, - CryptonightR_instruction157, - CryptonightR_instruction158, - CryptonightR_instruction159, - CryptonightR_instruction160, - CryptonightR_instruction161, - CryptonightR_instruction162, - CryptonightR_instruction163, - CryptonightR_instruction164, - CryptonightR_instruction165, - CryptonightR_instruction166, - CryptonightR_instruction167, - CryptonightR_instruction168, - CryptonightR_instruction169, - CryptonightR_instruction170, - CryptonightR_instruction171, - CryptonightR_instruction172, - CryptonightR_instruction173, - CryptonightR_instruction174, - CryptonightR_instruction175, - CryptonightR_instruction176, - CryptonightR_instruction177, - CryptonightR_instruction178, - CryptonightR_instruction179, - CryptonightR_instruction180, - CryptonightR_instruction181, - CryptonightR_instruction182, - CryptonightR_instruction183, - CryptonightR_instruction184, - CryptonightR_instruction185, - CryptonightR_instruction186, - CryptonightR_instruction187, - CryptonightR_instruction188, - CryptonightR_instruction189, - CryptonightR_instruction190, - CryptonightR_instruction191, - CryptonightR_instruction192, - CryptonightR_instruction193, - CryptonightR_instruction194, - CryptonightR_instruction195, - CryptonightR_instruction196, - CryptonightR_instruction197, - CryptonightR_instruction198, - CryptonightR_instruction199, - CryptonightR_instruction200, - CryptonightR_instruction201, - CryptonightR_instruction202, - CryptonightR_instruction203, - CryptonightR_instruction204, - CryptonightR_instruction205, - CryptonightR_instruction206, - CryptonightR_instruction207, - CryptonightR_instruction208, - CryptonightR_instruction209, - CryptonightR_instruction210, - CryptonightR_instruction211, - CryptonightR_instruction212, - CryptonightR_instruction213, - CryptonightR_instruction214, - CryptonightR_instruction215, - CryptonightR_instruction216, - CryptonightR_instruction217, - CryptonightR_instruction218, - CryptonightR_instruction219, - CryptonightR_instruction220, - CryptonightR_instruction221, - CryptonightR_instruction222, - CryptonightR_instruction223, - CryptonightR_instruction224, - CryptonightR_instruction225, - CryptonightR_instruction226, - CryptonightR_instruction227, - CryptonightR_instruction228, - CryptonightR_instruction229, - CryptonightR_instruction230, - CryptonightR_instruction231, - CryptonightR_instruction232, - CryptonightR_instruction233, - CryptonightR_instruction234, - CryptonightR_instruction235, - CryptonightR_instruction236, - CryptonightR_instruction237, - CryptonightR_instruction238, - CryptonightR_instruction239, - CryptonightR_instruction240, - CryptonightR_instruction241, - CryptonightR_instruction242, - CryptonightR_instruction243, - CryptonightR_instruction244, - CryptonightR_instruction245, - CryptonightR_instruction246, - CryptonightR_instruction247, - CryptonightR_instruction248, - CryptonightR_instruction249, - CryptonightR_instruction250, - CryptonightR_instruction251, - CryptonightR_instruction252, - CryptonightR_instruction253, - CryptonightR_instruction254, - CryptonightR_instruction255, - CryptonightR_instruction256, -}; - -const void_func instructions_mov[257] = { - CryptonightR_instruction_mov0, - CryptonightR_instruction_mov1, - CryptonightR_instruction_mov2, - CryptonightR_instruction_mov3, - CryptonightR_instruction_mov4, - CryptonightR_instruction_mov5, - CryptonightR_instruction_mov6, - CryptonightR_instruction_mov7, - CryptonightR_instruction_mov8, - CryptonightR_instruction_mov9, - CryptonightR_instruction_mov10, - CryptonightR_instruction_mov11, - CryptonightR_instruction_mov12, - CryptonightR_instruction_mov13, - CryptonightR_instruction_mov14, - CryptonightR_instruction_mov15, - CryptonightR_instruction_mov16, - CryptonightR_instruction_mov17, - CryptonightR_instruction_mov18, - CryptonightR_instruction_mov19, - CryptonightR_instruction_mov20, - CryptonightR_instruction_mov21, - CryptonightR_instruction_mov22, - CryptonightR_instruction_mov23, - CryptonightR_instruction_mov24, - CryptonightR_instruction_mov25, - CryptonightR_instruction_mov26, - CryptonightR_instruction_mov27, - CryptonightR_instruction_mov28, - CryptonightR_instruction_mov29, - CryptonightR_instruction_mov30, - CryptonightR_instruction_mov31, - CryptonightR_instruction_mov32, - CryptonightR_instruction_mov33, - CryptonightR_instruction_mov34, - CryptonightR_instruction_mov35, - CryptonightR_instruction_mov36, - CryptonightR_instruction_mov37, - CryptonightR_instruction_mov38, - CryptonightR_instruction_mov39, - CryptonightR_instruction_mov40, - CryptonightR_instruction_mov41, - CryptonightR_instruction_mov42, - CryptonightR_instruction_mov43, - CryptonightR_instruction_mov44, - CryptonightR_instruction_mov45, - CryptonightR_instruction_mov46, - CryptonightR_instruction_mov47, - CryptonightR_instruction_mov48, - CryptonightR_instruction_mov49, - CryptonightR_instruction_mov50, - CryptonightR_instruction_mov51, - CryptonightR_instruction_mov52, - CryptonightR_instruction_mov53, - CryptonightR_instruction_mov54, - CryptonightR_instruction_mov55, - CryptonightR_instruction_mov56, - CryptonightR_instruction_mov57, - CryptonightR_instruction_mov58, - CryptonightR_instruction_mov59, - CryptonightR_instruction_mov60, - CryptonightR_instruction_mov61, - CryptonightR_instruction_mov62, - CryptonightR_instruction_mov63, - CryptonightR_instruction_mov64, - CryptonightR_instruction_mov65, - CryptonightR_instruction_mov66, - CryptonightR_instruction_mov67, - CryptonightR_instruction_mov68, - CryptonightR_instruction_mov69, - CryptonightR_instruction_mov70, - CryptonightR_instruction_mov71, - CryptonightR_instruction_mov72, - CryptonightR_instruction_mov73, - CryptonightR_instruction_mov74, - CryptonightR_instruction_mov75, - CryptonightR_instruction_mov76, - CryptonightR_instruction_mov77, - CryptonightR_instruction_mov78, - CryptonightR_instruction_mov79, - CryptonightR_instruction_mov80, - CryptonightR_instruction_mov81, - CryptonightR_instruction_mov82, - CryptonightR_instruction_mov83, - CryptonightR_instruction_mov84, - CryptonightR_instruction_mov85, - CryptonightR_instruction_mov86, - CryptonightR_instruction_mov87, - CryptonightR_instruction_mov88, - CryptonightR_instruction_mov89, - CryptonightR_instruction_mov90, - CryptonightR_instruction_mov91, - CryptonightR_instruction_mov92, - CryptonightR_instruction_mov93, - CryptonightR_instruction_mov94, - CryptonightR_instruction_mov95, - CryptonightR_instruction_mov96, - CryptonightR_instruction_mov97, - CryptonightR_instruction_mov98, - CryptonightR_instruction_mov99, - CryptonightR_instruction_mov100, - CryptonightR_instruction_mov101, - CryptonightR_instruction_mov102, - CryptonightR_instruction_mov103, - CryptonightR_instruction_mov104, - CryptonightR_instruction_mov105, - CryptonightR_instruction_mov106, - CryptonightR_instruction_mov107, - CryptonightR_instruction_mov108, - CryptonightR_instruction_mov109, - CryptonightR_instruction_mov110, - CryptonightR_instruction_mov111, - CryptonightR_instruction_mov112, - CryptonightR_instruction_mov113, - CryptonightR_instruction_mov114, - CryptonightR_instruction_mov115, - CryptonightR_instruction_mov116, - CryptonightR_instruction_mov117, - CryptonightR_instruction_mov118, - CryptonightR_instruction_mov119, - CryptonightR_instruction_mov120, - CryptonightR_instruction_mov121, - CryptonightR_instruction_mov122, - CryptonightR_instruction_mov123, - CryptonightR_instruction_mov124, - CryptonightR_instruction_mov125, - CryptonightR_instruction_mov126, - CryptonightR_instruction_mov127, - CryptonightR_instruction_mov128, - CryptonightR_instruction_mov129, - CryptonightR_instruction_mov130, - CryptonightR_instruction_mov131, - CryptonightR_instruction_mov132, - CryptonightR_instruction_mov133, - CryptonightR_instruction_mov134, - CryptonightR_instruction_mov135, - CryptonightR_instruction_mov136, - CryptonightR_instruction_mov137, - CryptonightR_instruction_mov138, - CryptonightR_instruction_mov139, - CryptonightR_instruction_mov140, - CryptonightR_instruction_mov141, - CryptonightR_instruction_mov142, - CryptonightR_instruction_mov143, - CryptonightR_instruction_mov144, - CryptonightR_instruction_mov145, - CryptonightR_instruction_mov146, - CryptonightR_instruction_mov147, - CryptonightR_instruction_mov148, - CryptonightR_instruction_mov149, - CryptonightR_instruction_mov150, - CryptonightR_instruction_mov151, - CryptonightR_instruction_mov152, - CryptonightR_instruction_mov153, - CryptonightR_instruction_mov154, - CryptonightR_instruction_mov155, - CryptonightR_instruction_mov156, - CryptonightR_instruction_mov157, - CryptonightR_instruction_mov158, - CryptonightR_instruction_mov159, - CryptonightR_instruction_mov160, - CryptonightR_instruction_mov161, - CryptonightR_instruction_mov162, - CryptonightR_instruction_mov163, - CryptonightR_instruction_mov164, - CryptonightR_instruction_mov165, - CryptonightR_instruction_mov166, - CryptonightR_instruction_mov167, - CryptonightR_instruction_mov168, - CryptonightR_instruction_mov169, - CryptonightR_instruction_mov170, - CryptonightR_instruction_mov171, - CryptonightR_instruction_mov172, - CryptonightR_instruction_mov173, - CryptonightR_instruction_mov174, - CryptonightR_instruction_mov175, - CryptonightR_instruction_mov176, - CryptonightR_instruction_mov177, - CryptonightR_instruction_mov178, - CryptonightR_instruction_mov179, - CryptonightR_instruction_mov180, - CryptonightR_instruction_mov181, - CryptonightR_instruction_mov182, - CryptonightR_instruction_mov183, - CryptonightR_instruction_mov184, - CryptonightR_instruction_mov185, - CryptonightR_instruction_mov186, - CryptonightR_instruction_mov187, - CryptonightR_instruction_mov188, - CryptonightR_instruction_mov189, - CryptonightR_instruction_mov190, - CryptonightR_instruction_mov191, - CryptonightR_instruction_mov192, - CryptonightR_instruction_mov193, - CryptonightR_instruction_mov194, - CryptonightR_instruction_mov195, - CryptonightR_instruction_mov196, - CryptonightR_instruction_mov197, - CryptonightR_instruction_mov198, - CryptonightR_instruction_mov199, - CryptonightR_instruction_mov200, - CryptonightR_instruction_mov201, - CryptonightR_instruction_mov202, - CryptonightR_instruction_mov203, - CryptonightR_instruction_mov204, - CryptonightR_instruction_mov205, - CryptonightR_instruction_mov206, - CryptonightR_instruction_mov207, - CryptonightR_instruction_mov208, - CryptonightR_instruction_mov209, - CryptonightR_instruction_mov210, - CryptonightR_instruction_mov211, - CryptonightR_instruction_mov212, - CryptonightR_instruction_mov213, - CryptonightR_instruction_mov214, - CryptonightR_instruction_mov215, - CryptonightR_instruction_mov216, - CryptonightR_instruction_mov217, - CryptonightR_instruction_mov218, - CryptonightR_instruction_mov219, - CryptonightR_instruction_mov220, - CryptonightR_instruction_mov221, - CryptonightR_instruction_mov222, - CryptonightR_instruction_mov223, - CryptonightR_instruction_mov224, - CryptonightR_instruction_mov225, - CryptonightR_instruction_mov226, - CryptonightR_instruction_mov227, - CryptonightR_instruction_mov228, - CryptonightR_instruction_mov229, - CryptonightR_instruction_mov230, - CryptonightR_instruction_mov231, - CryptonightR_instruction_mov232, - CryptonightR_instruction_mov233, - CryptonightR_instruction_mov234, - CryptonightR_instruction_mov235, - CryptonightR_instruction_mov236, - CryptonightR_instruction_mov237, - CryptonightR_instruction_mov238, - CryptonightR_instruction_mov239, - CryptonightR_instruction_mov240, - CryptonightR_instruction_mov241, - CryptonightR_instruction_mov242, - CryptonightR_instruction_mov243, - CryptonightR_instruction_mov244, - CryptonightR_instruction_mov245, - CryptonightR_instruction_mov246, - CryptonightR_instruction_mov247, - CryptonightR_instruction_mov248, - CryptonightR_instruction_mov249, - CryptonightR_instruction_mov250, - CryptonightR_instruction_mov251, - CryptonightR_instruction_mov252, - CryptonightR_instruction_mov253, - CryptonightR_instruction_mov254, - CryptonightR_instruction_mov255, - CryptonightR_instruction_mov256, -}; diff --git a/src/crypto/asm/win64/CryptonightWOW_soft_aes_template.inc b/src/crypto/asm/win64/CryptonightWOW_soft_aes_template.inc new file mode 100644 index 000000000..cc273781c --- /dev/null +++ b/src/crypto/asm/win64/CryptonightWOW_soft_aes_template.inc @@ -0,0 +1,266 @@ +PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_part1) +PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_mainloop) +PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_part2) +PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_part3) +PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_end) + +ALIGN(64) +FN_PREFIX(CryptonightWOW_soft_aes_template_part1): + mov QWORD PTR [rsp+8], rcx + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 232 + + mov eax, [rcx+96] + mov ebx, [rcx+100] + mov esi, [rcx+104] + mov edx, [rcx+108] + mov [rsp+144], eax + mov [rsp+148], ebx + mov [rsp+152], esi + mov [rsp+156], edx + + mov rax, QWORD PTR [rcx+48] + mov r10, rcx + xor rax, QWORD PTR [rcx+16] + mov r8, QWORD PTR [rcx+32] + xor r8, QWORD PTR [rcx] + mov r9, QWORD PTR [rcx+40] + xor r9, QWORD PTR [rcx+8] + movd xmm4, rax + mov rdx, QWORD PTR [rcx+56] + xor rdx, QWORD PTR [rcx+24] + mov r11, QWORD PTR [rcx+224] + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r10+72] + mov rax, QWORD PTR [r10+80] + movd xmm0, rdx + xor rax, QWORD PTR [r10+64] + + movaps XMMWORD PTR [rsp+16], xmm6 + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+48], xmm8 + movaps XMMWORD PTR [rsp+64], xmm9 + movaps XMMWORD PTR [rsp+80], xmm10 + movaps XMMWORD PTR [rsp+96], xmm11 + movaps XMMWORD PTR [rsp+112], xmm12 + movaps XMMWORD PTR [rsp+128], xmm13 + + movd xmm5, rax + + mov rax, r8 + punpcklqdq xmm4, xmm0 + and eax, 2097136 + movd xmm10, QWORD PTR [r10+96] + movd xmm0, rcx + mov rcx, QWORD PTR [r10+104] + xorps xmm9, xmm9 + mov QWORD PTR [rsp+328], rax + movd xmm12, r11 + mov QWORD PTR [rsp+320], r9 + punpcklqdq xmm5, xmm0 + movd xmm13, rcx + mov r12d, 524288 + + ALIGN(64) +FN_PREFIX(CryptonightWOW_soft_aes_template_mainloop): + movd xmm11, r12d + mov r12, QWORD PTR [r10+272] + lea r13, QWORD PTR [rax+r11] + mov esi, DWORD PTR [r13] + movd xmm0, r9 + mov r10d, DWORD PTR [r13+4] + movd xmm7, r8 + mov ebp, DWORD PTR [r13+12] + mov r14d, DWORD PTR [r13+8] + mov rdx, QWORD PTR [rsp+328] + movzx ecx, sil + shr esi, 8 + punpcklqdq xmm7, xmm0 + mov r15d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + mov edi, DWORD PTR [r12+rcx*4] + movzx ecx, r14b + shr r14d, 8 + mov ebx, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + shr ebp, 8 + mov r9d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + xor r15d, DWORD PTR [r12+rcx*4+1024] + movzx ecx, r14b + shr r14d, 8 + mov eax, r14d + shr eax, 8 + xor edi, DWORD PTR [r12+rcx*4+1024] + add eax, 256 + movzx ecx, bpl + shr ebp, 8 + xor ebx, DWORD PTR [r12+rcx*4+1024] + movzx ecx, sil + shr esi, 8 + xor r9d, DWORD PTR [r12+rcx*4+1024] + add r12, 2048 + movzx ecx, r10b + shr r10d, 8 + add r10d, 256 + mov r11d, DWORD PTR [r12+rax*4] + xor r11d, DWORD PTR [r12+rcx*4] + xor r11d, r9d + movzx ecx, sil + mov r10d, DWORD PTR [r12+r10*4] + shr esi, 8 + add esi, 256 + xor r10d, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + xor r10d, ebx + shr ebp, 8 + movd xmm1, r11d + add ebp, 256 + movd r11, xmm12 + mov r9d, DWORD PTR [r12+rcx*4] + xor r9d, DWORD PTR [r12+rsi*4] + mov eax, DWORD PTR [r12+rbp*4] + xor r9d, edi + movzx ecx, r14b + movd xmm0, r10d + movd xmm2, r9d + xor eax, DWORD PTR [r12+rcx*4] + mov rcx, rdx + xor eax, r15d + punpckldq xmm2, xmm1 + xor rcx, 16 + movd xmm6, eax + mov rax, rdx + punpckldq xmm6, xmm0 + xor rax, 32 + punpckldq xmm6, xmm2 + xor rdx, 48 + movdqu xmm2, XMMWORD PTR [rcx+r11] + pxor xmm6, xmm7 + paddq xmm2, xmm4 + movdqu xmm1, XMMWORD PTR [rax+r11] + movdqu xmm0, XMMWORD PTR [rdx+r11] + paddq xmm0, xmm5 + movdqu XMMWORD PTR [rcx+r11], xmm0 + movdqu XMMWORD PTR [rax+r11], xmm2 + movd rcx, xmm13 + paddq xmm1, xmm7 + movdqu XMMWORD PTR [rdx+r11], xmm1 + movd rdi, xmm6 + mov r10, rdi + and r10d, 2097136 + movdqa xmm0, xmm6 + pxor xmm0, xmm4 + movdqu XMMWORD PTR [r13], xmm0 + + mov ebx, [rsp+144] + mov ebp, [rsp+152] + add ebx, [rsp+148] + add ebp, [rsp+156] + shl rbp, 32 + or rbx, rbp + + xor rbx, QWORD PTR [r10+r11] + lea r14, QWORD PTR [r10+r11] + mov rbp, QWORD PTR [r14+8] + + mov [rsp+160], rbx + mov [rsp+168], rdi + mov [rsp+176], rbp + mov [rsp+184], r10 + mov r10, rsp + + mov ebx, [rsp+144] + mov esi, [rsp+148] + mov edi, [rsp+152] + mov ebp, [rsp+156] + + movd esp, xmm7 + movaps xmm0, xmm7 + psrldq xmm0, 8 + movd r15d, xmm0 + movd eax, xmm4 + movd edx, xmm5 + +FN_PREFIX(CryptonightWOW_soft_aes_template_part2): + mov rsp, r10 + mov [rsp+144], ebx + mov [rsp+148], esi + mov [rsp+152], edi + mov [rsp+156], ebp + + mov rbx, [rsp+160] + mov rdi, [rsp+168] + mov rbp, [rsp+176] + mov r10, [rsp+184] + + mov r9, r10 + xor r9, 16 + mov rcx, r10 + xor rcx, 32 + xor r10, 48 + mov rax, rbx + mul rdi + movdqu xmm2, XMMWORD PTR [r9+r11] + movdqu xmm1, XMMWORD PTR [rcx+r11] + paddq xmm1, xmm7 + movd xmm0, rax + movd xmm3, rdx + xor rax, QWORD PTR [r11+rcx+8] + xor rdx, QWORD PTR [rcx+r11] + punpcklqdq xmm3, xmm0 + add r8, rdx + movdqu xmm0, XMMWORD PTR [r10+r11] + pxor xmm2, xmm3 + paddq xmm0, xmm5 + paddq xmm2, xmm4 + movdqu XMMWORD PTR [r9+r11], xmm0 + movdqa xmm5, xmm4 + mov r9, QWORD PTR [rsp+320] + movdqa xmm4, xmm6 + add r9, rax + movdqu XMMWORD PTR [rcx+r11], xmm2 + movdqu XMMWORD PTR [r10+r11], xmm1 + mov r10, QWORD PTR [rsp+304] + movd r12d, xmm11 + mov QWORD PTR [r14], r8 + xor r8, rbx + mov rax, r8 + mov QWORD PTR [r14+8], r9 + and eax, 2097136 + xor r9, rbp + mov QWORD PTR [rsp+320], r9 + mov QWORD PTR [rsp+328], rax + sub r12d, 1 + jne FN_PREFIX(CryptonightWOW_soft_aes_template_mainloop) + +FN_PREFIX(CryptonightWOW_soft_aes_template_part3): + movaps xmm6, XMMWORD PTR [rsp+16] + movaps xmm7, XMMWORD PTR [rsp+32] + movaps xmm8, XMMWORD PTR [rsp+48] + movaps xmm9, XMMWORD PTR [rsp+64] + movaps xmm10, XMMWORD PTR [rsp+80] + movaps xmm11, XMMWORD PTR [rsp+96] + movaps xmm12, XMMWORD PTR [rsp+112] + movaps xmm13, XMMWORD PTR [rsp+128] + + add rsp, 232 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + pop rbx + ret +FN_PREFIX(CryptonightWOW_soft_aes_template_end): diff --git a/src/crypto/asm/win64/CryptonightWOW_soft_aes_template_win.inc b/src/crypto/asm/win64/CryptonightWOW_soft_aes_template_win.inc new file mode 100644 index 000000000..682090367 --- /dev/null +++ b/src/crypto/asm/win64/CryptonightWOW_soft_aes_template_win.inc @@ -0,0 +1,266 @@ +PUBLIC CryptonightWOW_soft_aes_template_part1 +PUBLIC CryptonightWOW_soft_aes_template_mainloop +PUBLIC CryptonightWOW_soft_aes_template_part2 +PUBLIC CryptonightWOW_soft_aes_template_part3 +PUBLIC CryptonightWOW_soft_aes_template_end + +ALIGN(64) +CryptonightWOW_soft_aes_template_part1: + mov QWORD PTR [rsp+8], rcx + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 232 + + mov eax, [rcx+96] + mov ebx, [rcx+100] + mov esi, [rcx+104] + mov edx, [rcx+108] + mov [rsp+144], eax + mov [rsp+148], ebx + mov [rsp+152], esi + mov [rsp+156], edx + + mov rax, QWORD PTR [rcx+48] + mov r10, rcx + xor rax, QWORD PTR [rcx+16] + mov r8, QWORD PTR [rcx+32] + xor r8, QWORD PTR [rcx] + mov r9, QWORD PTR [rcx+40] + xor r9, QWORD PTR [rcx+8] + movd xmm4, rax + mov rdx, QWORD PTR [rcx+56] + xor rdx, QWORD PTR [rcx+24] + mov r11, QWORD PTR [rcx+224] + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r10+72] + mov rax, QWORD PTR [r10+80] + movd xmm0, rdx + xor rax, QWORD PTR [r10+64] + + movaps XMMWORD PTR [rsp+16], xmm6 + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+48], xmm8 + movaps XMMWORD PTR [rsp+64], xmm9 + movaps XMMWORD PTR [rsp+80], xmm10 + movaps XMMWORD PTR [rsp+96], xmm11 + movaps XMMWORD PTR [rsp+112], xmm12 + movaps XMMWORD PTR [rsp+128], xmm13 + + movd xmm5, rax + + mov rax, r8 + punpcklqdq xmm4, xmm0 + and eax, 2097136 + movd xmm10, QWORD PTR [r10+96] + movd xmm0, rcx + mov rcx, QWORD PTR [r10+104] + xorps xmm9, xmm9 + mov QWORD PTR [rsp+328], rax + movd xmm12, r11 + mov QWORD PTR [rsp+320], r9 + punpcklqdq xmm5, xmm0 + movd xmm13, rcx + mov r12d, 524288 + + ALIGN(64) +CryptonightWOW_soft_aes_template_mainloop: + movd xmm11, r12d + mov r12, QWORD PTR [r10+272] + lea r13, QWORD PTR [rax+r11] + mov esi, DWORD PTR [r13] + movd xmm0, r9 + mov r10d, DWORD PTR [r13+4] + movd xmm7, r8 + mov ebp, DWORD PTR [r13+12] + mov r14d, DWORD PTR [r13+8] + mov rdx, QWORD PTR [rsp+328] + movzx ecx, sil + shr esi, 8 + punpcklqdq xmm7, xmm0 + mov r15d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + mov edi, DWORD PTR [r12+rcx*4] + movzx ecx, r14b + shr r14d, 8 + mov ebx, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + shr ebp, 8 + mov r9d, DWORD PTR [r12+rcx*4] + movzx ecx, r10b + shr r10d, 8 + xor r15d, DWORD PTR [r12+rcx*4+1024] + movzx ecx, r14b + shr r14d, 8 + mov eax, r14d + shr eax, 8 + xor edi, DWORD PTR [r12+rcx*4+1024] + add eax, 256 + movzx ecx, bpl + shr ebp, 8 + xor ebx, DWORD PTR [r12+rcx*4+1024] + movzx ecx, sil + shr esi, 8 + xor r9d, DWORD PTR [r12+rcx*4+1024] + add r12, 2048 + movzx ecx, r10b + shr r10d, 8 + add r10d, 256 + mov r11d, DWORD PTR [r12+rax*4] + xor r11d, DWORD PTR [r12+rcx*4] + xor r11d, r9d + movzx ecx, sil + mov r10d, DWORD PTR [r12+r10*4] + shr esi, 8 + add esi, 256 + xor r10d, DWORD PTR [r12+rcx*4] + movzx ecx, bpl + xor r10d, ebx + shr ebp, 8 + movd xmm1, r11d + add ebp, 256 + movd r11, xmm12 + mov r9d, DWORD PTR [r12+rcx*4] + xor r9d, DWORD PTR [r12+rsi*4] + mov eax, DWORD PTR [r12+rbp*4] + xor r9d, edi + movzx ecx, r14b + movd xmm0, r10d + movd xmm2, r9d + xor eax, DWORD PTR [r12+rcx*4] + mov rcx, rdx + xor eax, r15d + punpckldq xmm2, xmm1 + xor rcx, 16 + movd xmm6, eax + mov rax, rdx + punpckldq xmm6, xmm0 + xor rax, 32 + punpckldq xmm6, xmm2 + xor rdx, 48 + movdqu xmm2, XMMWORD PTR [rcx+r11] + pxor xmm6, xmm7 + paddq xmm2, xmm4 + movdqu xmm1, XMMWORD PTR [rax+r11] + movdqu xmm0, XMMWORD PTR [rdx+r11] + paddq xmm0, xmm5 + movdqu XMMWORD PTR [rcx+r11], xmm0 + movdqu XMMWORD PTR [rax+r11], xmm2 + movd rcx, xmm13 + paddq xmm1, xmm7 + movdqu XMMWORD PTR [rdx+r11], xmm1 + movd rdi, xmm6 + mov r10, rdi + and r10d, 2097136 + movdqa xmm0, xmm6 + pxor xmm0, xmm4 + movdqu XMMWORD PTR [r13], xmm0 + + mov ebx, [rsp+144] + mov ebp, [rsp+152] + add ebx, [rsp+148] + add ebp, [rsp+156] + shl rbp, 32 + or rbx, rbp + + xor rbx, QWORD PTR [r10+r11] + lea r14, QWORD PTR [r10+r11] + mov rbp, QWORD PTR [r14+8] + + mov [rsp+160], rbx + mov [rsp+168], rdi + mov [rsp+176], rbp + mov [rsp+184], r10 + mov r10, rsp + + mov ebx, [rsp+144] + mov esi, [rsp+148] + mov edi, [rsp+152] + mov ebp, [rsp+156] + + movd esp, xmm7 + movaps xmm0, xmm7 + psrldq xmm0, 8 + movd r15d, xmm0 + movd eax, xmm4 + movd edx, xmm5 + +CryptonightWOW_soft_aes_template_part2: + mov rsp, r10 + mov [rsp+144], ebx + mov [rsp+148], esi + mov [rsp+152], edi + mov [rsp+156], ebp + + mov rbx, [rsp+160] + mov rdi, [rsp+168] + mov rbp, [rsp+176] + mov r10, [rsp+184] + + mov r9, r10 + xor r9, 16 + mov rcx, r10 + xor rcx, 32 + xor r10, 48 + mov rax, rbx + mul rdi + movdqu xmm2, XMMWORD PTR [r9+r11] + movdqu xmm1, XMMWORD PTR [rcx+r11] + paddq xmm1, xmm7 + movd xmm0, rax + movd xmm3, rdx + xor rax, QWORD PTR [r11+rcx+8] + xor rdx, QWORD PTR [rcx+r11] + punpcklqdq xmm3, xmm0 + add r8, rdx + movdqu xmm0, XMMWORD PTR [r10+r11] + pxor xmm2, xmm3 + paddq xmm0, xmm5 + paddq xmm2, xmm4 + movdqu XMMWORD PTR [r9+r11], xmm0 + movdqa xmm5, xmm4 + mov r9, QWORD PTR [rsp+320] + movdqa xmm4, xmm6 + add r9, rax + movdqu XMMWORD PTR [rcx+r11], xmm2 + movdqu XMMWORD PTR [r10+r11], xmm1 + mov r10, QWORD PTR [rsp+304] + movd r12d, xmm11 + mov QWORD PTR [r14], r8 + xor r8, rbx + mov rax, r8 + mov QWORD PTR [r14+8], r9 + and eax, 2097136 + xor r9, rbp + mov QWORD PTR [rsp+320], r9 + mov QWORD PTR [rsp+328], rax + sub r12d, 1 + jne CryptonightWOW_soft_aes_template_mainloop + +CryptonightWOW_soft_aes_template_part3: + movaps xmm6, XMMWORD PTR [rsp+16] + movaps xmm7, XMMWORD PTR [rsp+32] + movaps xmm8, XMMWORD PTR [rsp+48] + movaps xmm9, XMMWORD PTR [rsp+64] + movaps xmm10, XMMWORD PTR [rsp+80] + movaps xmm11, XMMWORD PTR [rsp+96] + movaps xmm12, XMMWORD PTR [rsp+112] + movaps xmm13, XMMWORD PTR [rsp+128] + + add rsp, 232 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + pop rbx + ret +CryptonightWOW_soft_aes_template_end: From d4d0c69b5dcb93e16ef2c0f54d7881ea891181b7 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sun, 24 Feb 2019 20:23:52 +0100 Subject: [PATCH 09/55] Fixed compilation error in Linux --- src/crypto/CryptoNight_x86.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 358f1921d..e53a4dbeb 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -264,7 +264,7 @@ template void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2, __m128i* x3, __m128i* x4, __m128i* x5, __m128i* x6, __m128i* x7); template<> -static NOINLINE void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2, __m128i* x3, __m128i* x4, __m128i* x5, __m128i* x6, __m128i* x7) +NOINLINE void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2, __m128i* x3, __m128i* x4, __m128i* x5, __m128i* x6, __m128i* x7) { *x0 = soft_aesenc((uint32_t*)x0, key, (const uint32_t*)saes_table); *x1 = soft_aesenc((uint32_t*)x1, key, (const uint32_t*)saes_table); @@ -277,7 +277,7 @@ static NOINLINE void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m1 } template<> -static FORCEINLINE void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2, __m128i* x3, __m128i* x4, __m128i* x5, __m128i* x6, __m128i* x7) +FORCEINLINE void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2, __m128i* x3, __m128i* x4, __m128i* x5, __m128i* x6, __m128i* x7) { *x0 = _mm_aesenc_si128(*x0, key); *x1 = _mm_aesenc_si128(*x1, key); From 948f23c7d9f1b114e4b5410403556611b8486bfd Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 25 Feb 2019 15:54:21 +0700 Subject: [PATCH 10/55] Small code cleanups. --- src/App.cpp | 4 ++-- src/common/crypto/Algorithm.cpp | 1 + src/core/Controller.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 96d1688ba..e75766acf 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -55,7 +55,7 @@ xmrig::App::App(Process *process) : m_httpd(nullptr), m_signals(nullptr) { - m_controller = new xmrig::Controller(process); + m_controller = new Controller(process); if (m_controller->init() != 0) { return; } @@ -178,7 +178,7 @@ void xmrig::App::onSignal(int signum) break; default: - break; + return; } close(); diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index dd864705b..7d03acfc1 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -113,6 +113,7 @@ static AlgoData const xmrStakAlgorithms[] = { { "cryptonight_alloy", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO }, // xmr-stak-alloy { "cryptonight_turtle", nullptr, xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL }, { "cryptonight_gpu", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_GPU }, + { "cryptonight_r", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_4 }, }; #endif diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index 1b30b4cdc..7639bfaae 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -99,7 +99,7 @@ int xmrig::Controller::init() { Cpu::init(); - d_ptr->config = xmrig::Config::load(d_ptr->process, this); + d_ptr->config = Config::load(d_ptr->process, this); if (!d_ptr->config) { return 1; } From d6788e4c466e1a2b3593ba2c63af2183a68c0b0b Mon Sep 17 00:00:00 2001 From: xmrig Date: Mon, 25 Feb 2019 21:13:24 +0700 Subject: [PATCH 11/55] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4eb09e6fa..eb7f2378a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# v2.13.1 +[#946](https://github.com/xmrig/xmrig/pull/946) Optimized software AES implementations for CPUs without hardware AES support. `cn/r`, `cn/wow` up to 2.6 times faster, 4-9% improvements for other algorithms. + # v2.13.0 - **[#938](https://github.com/xmrig/xmrig/issues/938) Added support for new algorithm `cryptonight/r`, short alias `cn/r` (also known as CryptoNightR or CryptoNight variant 4), for upcoming [Monero](https://www.getmonero.org/) fork on March 9, thanks [@SChernykh](https://github.com/SChernykh).** - [#939](https://github.com/xmrig/xmrig/issues/939) Added support for dynamic (runtime) pools reload. From fc1bbbba6e26c818d1be8bfcee0915010687c6a9 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 25 Feb 2019 21:23:59 +0700 Subject: [PATCH 12/55] v2.13.1 --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index f30d4d1e7..5b09f86b8 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.13.1-dev" +#define APP_VERSION "2.13.1" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com" From 7e83fb306e82d0e7b5c85542acf9e0905f88a2ce Mon Sep 17 00:00:00 2001 From: osensei Date: Wed, 27 Feb 2019 19:21:17 -0300 Subject: [PATCH 13/55] Properly report ARM architecture on user agent. --- src/common/Platform_unix.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/Platform_unix.cpp b/src/common/Platform_unix.cpp index 901df4be5..3066630ae 100644 --- a/src/common/Platform_unix.cpp +++ b/src/common/Platform_unix.cpp @@ -61,6 +61,10 @@ char *Platform::createUserAgent() # if defined(__x86_64__) length += snprintf(buf + length, max - length, "x86_64) libuv/%s", uv_version_string()); +# elif defined(__aarch64__) + length += snprintf(buf + length, max - length, "aarch64) libuv/%s", uv_version_string()); +# elif defined(__arm__) + length += snprintf(buf + length, max - length, "arm) libuv/%s", uv_version_string()); # else length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string()); # endif From b1700d270ab6082768f9194fb1801385d973ceeb Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 1 Mar 2019 22:00:23 +0700 Subject: [PATCH 14/55] v2.13.2-dev --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index 5b09f86b8..6c8418088 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.13.1" +#define APP_VERSION "2.13.2-dev" #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 13 -#define APP_VER_PATCH 1 +#define APP_VER_PATCH 2 #ifdef _MSC_VER # if (_MSC_VER >= 1910) From a261fe8c751cba94a0887ffd91f672a06b3ce25c Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 1 Mar 2019 22:23:02 +0700 Subject: [PATCH 15/55] #952 Add missing header. --- src/base/kernel/Entry.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/base/kernel/Entry.cpp b/src/base/kernel/Entry.cpp index abdfd1e10..84c4c9718 100644 --- a/src/base/kernel/Entry.cpp +++ b/src/base/kernel/Entry.cpp @@ -23,6 +23,7 @@ */ +#include #include From bde77ebab48efee2a5b991a66744faf11e77fbcb Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 1 Mar 2019 22:59:34 +0700 Subject: [PATCH 16/55] Sync changes. --- src/base/io/Json.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++ src/base/io/Json.h | 6 +++++- src/base/net/Pool.cpp | 4 ++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/base/io/Json.cpp b/src/base/io/Json.cpp index ee5211d8c..b95994e4e 100644 --- a/src/base/io/Json.cpp +++ b/src/base/io/Json.cpp @@ -47,3 +47,47 @@ const char *xmrig::Json::getString(const rapidjson::Value &obj, const char *key, return defaultValue; } + + +int xmrig::Json::getInt(const rapidjson::Value &obj, const char *key, int defaultValue) +{ + auto i = obj.FindMember(key); + if (i != obj.MemberEnd() && i->value.IsInt()) { + return i->value.GetInt(); + } + + return defaultValue; +} + + +int64_t xmrig::Json::getInt64(const rapidjson::Value &obj, const char *key, int64_t defaultValue) +{ + auto i = obj.FindMember(key); + if (i != obj.MemberEnd() && i->value.IsInt64()) { + return i->value.GetInt64(); + } + + return defaultValue; +} + + +uint64_t xmrig::Json::getUint64(const rapidjson::Value &obj, const char *key, uint64_t defaultValue) +{ + auto i = obj.FindMember(key); + if (i != obj.MemberEnd() && i->value.IsUint64()) { + return i->value.GetUint64(); + } + + return defaultValue; +} + + +unsigned xmrig::Json::getUint(const rapidjson::Value &obj, const char *key, unsigned defaultValue) +{ + auto i = obj.FindMember(key); + if (i != obj.MemberEnd() && i->value.IsUint()) { + return i->value.GetUint(); + } + + return defaultValue; +} diff --git a/src/base/io/Json.h b/src/base/io/Json.h index c6cde0d82..28dcf9a37 100644 --- a/src/base/io/Json.h +++ b/src/base/io/Json.h @@ -36,7 +36,11 @@ class Json { public: static bool getBool(const rapidjson::Value &obj, const char *key, bool defaultValue = false); - static const char *getString(const rapidjson::Value &obj, const char *key, const char *defaultValue = nullptr); + static const char *getString(const rapidjson::Value &obj, const char *key, const char *defaultValue = nullptr); + static int getInt(const rapidjson::Value &obj, const char *key, int defaultValue = 0); + static int64_t getInt64(const rapidjson::Value &obj, const char *key, int64_t defaultValue = 0); + static uint64_t getUint64(const rapidjson::Value &obj, const char *key, uint64_t defaultValue = 0); + static unsigned getUint(const rapidjson::Value &obj, const char *key, unsigned defaultValue = 0); static bool get(const char *fileName, rapidjson::Document &doc); static bool save(const char *fileName, const rapidjson::Document &doc); diff --git a/src/base/net/Pool.cpp b/src/base/net/Pool.cpp index f66a8c9b6..dcea9b577 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -45,6 +45,8 @@ #endif +namespace xmrig { + static const char *kEnabled = "enabled"; static const char *kFingerprint = "tls-fingerprint"; static const char *kKeepalive = "keepalive"; @@ -56,6 +58,8 @@ static const char *kUrl = "url"; static const char *kUser = "user"; static const char *kVariant = "variant"; +} + xmrig::Pool::Pool() : m_enabled(true), From d135bdd87ea5b72e078e4d5137c3646e02a6fd6a Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 2 Mar 2019 13:12:38 +0700 Subject: [PATCH 17/55] #957 Added optional embedded JSON config support. --- CMakeLists.txt | 28 ++++++---- src/base/net/Pool.cpp | 1 + src/common/config/ConfigLoader.cpp | 10 ++++ src/config.json | 2 +- src/core/ConfigLoader_default.h | 84 ++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 12 deletions(-) create mode 100644 src/core/ConfigLoader_default.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d2009b84d..f6ccc84bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,18 @@ 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_PICO "CryptoNight-Pico support" ON) -option(WITH_CN_GPU "CryptoNight-GPU support" ON) -option(WITH_HTTPD "HTTP REST API" ON) -option(WITH_DEBUG_LOG "Enable debug log output" OFF) -option(WITH_TLS "Enable OpenSSL support" ON) -option(WITH_ASM "Enable ASM PoW implementations" ON) -option(BUILD_STATIC "Build static binary" OFF) -option(ARM_TARGET "Force use specific ARM target 8 or 7" 0) +option(WITH_LIBCPUID "Use Libcpuid" ON) +option(WITH_AEON "CryptoNight-Lite support" ON) +option(WITH_SUMO "CryptoNight-Heavy support" ON) +option(WITH_CN_PICO "CryptoNight-Pico support" ON) +option(WITH_CN_GPU "CryptoNight-GPU support" ON) +option(WITH_HTTPD "HTTP REST API" ON) +option(WITH_DEBUG_LOG "Enable debug log output" OFF) +option(WITH_TLS "Enable OpenSSL support" ON) +option(WITH_ASM "Enable ASM PoW implementations" ON) +option(BUILD_STATIC "Build static binary" OFF) +option(ARM_TARGET "Force use specific ARM target 8 or 7" 0) +option(WITH_EMBEDDED_CONFIG "Enable internal embedded JSON config" OFF) include (CheckIncludeFile) include (cmake/cpu.cmake) @@ -65,6 +66,7 @@ set(HEADERS src/common/utils/mm_malloc.h src/common/xmrig.h src/core/ConfigLoader_platform.h + src/core/ConfigLoader_default.h src/core/Controller.h src/interfaces/IJobResultListener.h src/interfaces/IThread.h @@ -249,6 +251,10 @@ if (NOT WITH_CN_PICO) add_definitions(/DXMRIG_NO_CN_PICO) endif() +if (WITH_EMBEDDED_CONFIG) + add_definitions(/DXMRIG_FEATURE_EMBEDDED_CONFIG) +endif() + if (WITH_HTTPD) find_package(MHD) diff --git a/src/base/net/Pool.cpp b/src/base/net/Pool.cpp index dcea9b577..8a4d0a0a3 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -132,6 +132,7 @@ xmrig::Pool::Pool(const rapidjson::Value &object) : xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls) : + m_enabled(true), m_nicehash(nicehash), m_tls(tls), m_keepAlive(keepAlive), diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index fd46e7916..7124d121a 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -47,6 +47,7 @@ #include "common/interfaces/IConfig.h" #include "common/Platform.h" #include "core/ConfigCreator.h" +#include "core/ConfigLoader_default.h" #include "core/ConfigLoader_platform.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" @@ -180,6 +181,15 @@ xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigCreator *crea loadFromFile(config, process->location(Process::ExeLocation, "config.json")); } +# ifdef XMRIG_FEATURE_EMBEDDED_CONFIG + if (!config->finalize()) { + delete config; + + config = m_creator->create(); + loadFromJSON(config, default_config); + } +# endif + if (!config->finalize()) { if (!config->algorithm().isValid()) { fprintf(stderr, "No valid algorithm specified. Exiting.\n"); diff --git a/src/config.json b/src/config.json index f6646c110..5018db514 100644 --- a/src/config.json +++ b/src/config.json @@ -39,5 +39,5 @@ "safe": false, "threads": null, "user-agent": null, - "watch": false + "watch": true } \ No newline at end of file diff --git a/src/core/ConfigLoader_default.h b/src/core/ConfigLoader_default.h new file mode 100644 index 000000000..8fd0502b7 --- /dev/null +++ b/src/core/ConfigLoader_default.h @@ -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-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 . + */ + +#ifndef XMRIG_CONFIGLOADER_DEFAULT_H +#define XMRIG_CONFIGLOADER_DEFAULT_H + + +namespace xmrig { + + +#ifdef XMRIG_FEATURE_EMBEDDED_CONFIG +const static char *default_config = +R"===( +{ + "algo": "cryptonight", + "api": { + "port": 0, + "access-token": null, + "id": null, + "worker-id": null, + "ipv6": false, + "restricted": true + }, + "asm": true, + "autosave": true, + "av": 0, + "background": false, + "colors": true, + "cpu-affinity": null, + "cpu-priority": null, + "donate-level": 5, + "huge-pages": true, + "hw-aes": null, + "log-file": null, + "max-cpu-usage": 100, + "pools": [ + { + "url": "donate.v2.xmrig.com:3333", + "user": "YOUR_WALLET_ADDRESS", + "pass": "x", + "rig-id": null, + "nicehash": false, + "keepalive": false, + "variant": -1, + "tls": false, + "tls-fingerprint": null + } + ], + "print-time": 60, + "retries": 5, + "retry-pause": 5, + "safe": false, + "threads": null, + "user-agent": null, + "watch": false +} +)==="; +#endif + + +} /* namespace xmrig */ + +#endif /* XMRIG_CONFIGLOADER_DEFAULT_H */ From 4ebfc135e00265d4d905a71af3dd802d773e8b57 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 3 Mar 2019 17:33:27 +0700 Subject: [PATCH 18/55] Build whole CryptonightR_gen.cpp only if ASM used. --- CMakeLists.txt | 1 - cmake/asm.cmake | 2 +- src/crypto/CryptonightR_gen.cpp | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6ccc84bc..14dcc931a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,7 +156,6 @@ set(SOURCES_CRYPTO src/crypto/c_blake256.c src/crypto/c_jh.c src/crypto/c_skein.c - src/crypto/CryptonightR_gen.cpp ) if (WIN32) diff --git a/cmake/asm.cmake b/cmake/asm.cmake index dc6424ff2..1007f9277 100644 --- a/cmake/asm.cmake +++ b/cmake/asm.cmake @@ -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) + set(XMRIG_ASM_SOURCES src/crypto/Asm.h src/crypto/Asm.cpp src/crypto/CryptonightR_gen.cpp) set_property(TARGET ${XMRIG_ASM_LIBRARY} PROPERTY LINKER_LANGUAGE C) else() set(XMRIG_ASM_SOURCES "") diff --git a/src/crypto/CryptonightR_gen.cpp b/src/crypto/CryptonightR_gen.cpp index 6e53ef190..3fba49cd9 100644 --- a/src/crypto/CryptonightR_gen.cpp +++ b/src/crypto/CryptonightR_gen.cpp @@ -31,7 +31,6 @@ typedef void(*void_func)(); #include "crypto/asm/CryptonightR_template.h" #include "Mem.h" -#if !defined XMRIG_ARM && !defined XMRIG_NO_ASM static inline void add_code(uint8_t* &p, void (*p1)(), void (*p2)()) { @@ -186,5 +185,3 @@ void v4_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* m Mem::flushInstructionCache(machine_code, p - p0); } - -#endif From f2574c2a418ac93922feb791a74c3cbfd68798de Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 4 Mar 2019 00:42:17 +0700 Subject: [PATCH 19/55] Use machine friendly test data for cn/r and cn/wow algorithms. --- src/crypto/CryptoNight_constants.h | 4 +- src/crypto/CryptoNight_test.h | 73 ++++++++++++++++-------- src/interfaces/IWorker.h | 11 ++-- src/workers/MultiWorker.cpp | 91 ++++++++++++------------------ src/workers/MultiWorker.h | 2 +- 5 files changed, 95 insertions(+), 86 deletions(-) diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 4ea1adb3b..6afedc905 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -202,8 +202,8 @@ template<> inline constexpr Variant cn_base_variant() { return VA template inline constexpr bool cn_is_cryptonight_r() { return false; } -template<> inline constexpr bool cn_is_cryptonight_r() { return true; } -template<> inline constexpr bool cn_is_cryptonight_r() { return true; } +template<> inline constexpr bool cn_is_cryptonight_r() { return true; } +template<> inline constexpr bool cn_is_cryptonight_r() { return true; } } /* namespace xmrig */ diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index 237fe31bf..7480fae54 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -58,27 +58,58 @@ const static uint8_t test_input[380] = { 0xCF, 0x50, 0x29, 0x6A, 0x07, 0x0B, 0x93, 0x8F, 0x8F, 0xA8, 0x10, 0x04 }; -const static char* test_input_WOW = R"===(9d47bf4c41b7e8e727e681715acb47fa1677cdba9ca7bcb05ad8cc8abd5daa66 5468697320697320612074657374205468697320697320612074657374205468697320697320612074657374 1806260 -0d4a495cb844a3ca8ba4edb8e6bcf829ef1c06d9cdea2b62ca46c2a21b8b0a79 4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e67 1806261 -a1d6d848b5c5915fccd2f64cf216c6b1a02cf7c77bc80d8d4e51b419e88ff0dd 656c69742c2073656420646f20656975736d6f642074656d706f7220696e6369646964756e74207574206c61626f7265 1806262 -af3a8544a0221a148c2ac90484b19861e3afca33fe17021efb8ad6496b567915 657420646f6c6f7265206d61676e6120616c697175612e20557420656e696d206164206d696e696d2076656e69616d2c 1806263 -313399e0963ae8a99dab8af66d343e097dae0c0feb08dbc43ccdafef5515f413 71756973206e6f737472756420657865726369746174696f6e20756c6c616d636f206c61626f726973206e697369 1806264 -6021c6ef90bff9ae94a7506d623d3a7a86c1756d655f50dd558f716d64622a34 757420616c697175697020657820656120636f6d6d6f646f20636f6e7365717561742e20447569732061757465 1806265 -2b13000535f3db5f9b9b84a65c4351f386cd2cdedebb8c3ad2eab086e6a3fee5 697275726520646f6c6f7220696e20726570726568656e646572697420696e20766f6c7570746174652076656c6974 1806266 -fc0e1dad8e895749dc90eb690bc1ba059a1cd772afaaf65a106bf9e5e6b80503 657373652063696c6c756d20646f6c6f726520657520667567696174206e756c6c612070617269617475722e 1806267 -b60b0afe144deff7d903ed2d5545e77ebe66a3c51fee7016eeb8fee9eb630c0f 4578636570746575722073696e74206f6363616563617420637570696461746174206e6f6e2070726f6964656e742c 1806268 -64774b27e7d5fec862fc4c0c13ac6bf09123b6f05bb0e4b75c97f379a2b3a679 73756e7420696e2063756c706120717569206f666669636961206465736572756e74206d6f6c6c697420616e696d20696420657374206c61626f72756d2e 1806269)==="; -const static char* test_input_R = R"===(f759588ad57e758467295443a9bd71490abff8e9dad1b95b6bf2f5d0d78387bc 5468697320697320612074657374205468697320697320612074657374205468697320697320612074657374 1806260 -5bb833deca2bdd7252a9ccd7b4ce0b6a4854515794b56c207262f7a5b9bdb566 4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e67 1806261 -1ee6728da60fbd8d7d55b2b1ade487a3cf52a2c3ac6f520db12c27d8921f6cab 656c69742c2073656420646f20656975736d6f642074656d706f7220696e6369646964756e74207574206c61626f7265 1806262 -6969fe2ddfb758438d48049f302fc2108a4fcc93e37669170e6db4b0b9b4c4cb 657420646f6c6f7265206d61676e6120616c697175612e20557420656e696d206164206d696e696d2076656e69616d2c 1806263 -7f3048b4e90d0cbe7a57c0394f37338a01fae3adfdc0e5126d863a895eb04e02 71756973206e6f737472756420657865726369746174696f6e20756c6c616d636f206c61626f726973206e697369 1806264 -1d290443a4b542af04a82f6b2494a6ee7f20f2754c58e0849032483a56e8e2ef 757420616c697175697020657820656120636f6d6d6f646f20636f6e7365717561742e20447569732061757465 1806265 -c43cc6567436a86afbd6aa9eaa7c276e9806830334b614b2bee23cc76634f6fd 697275726520646f6c6f7220696e20726570726568656e646572697420696e20766f6c7570746174652076656c6974 1806266 -87be2479c0c4e8edfdfaa5603e93f4265b3f8224c1c5946feb424819d18990a4 657373652063696c6c756d20646f6c6f726520657520667567696174206e756c6c612070617269617475722e 1806267 -dd9d6a6d8e47465cceac0877ef889b93e7eba979557e3935d7f86dce11b070f3 4578636570746575722073696e74206f6363616563617420637570696461746174206e6f6e2070726f6964656e742c 1806268 -75c6f2ae49a20521de97285b431e717125847fb8935ed84a61e7f8d36a2c3d8e 73756e7420696e2063756c706120717569206f666669636961206465736572756e74206d6f6c6c697420616e696d20696420657374206c61626f72756d2e 1806269)==="; +struct cn_r_test_input_data +{ + uint64_t height; + size_t size; + uint8_t data[64]; +}; + + +const static cn_r_test_input_data cn_r_test_input[] = { + { 1806260, 44, { 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74 } }, + { 1806261, 50, { 0x4c, 0x6f, 0x72, 0x65, 0x6d, 0x20, 0x69, 0x70, 0x73, 0x75, 0x6d, 0x20, 0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x73, 0x69, 0x74, 0x20, 0x61, 0x6d, 0x65, 0x74, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x63, 0x74, 0x65, 0x74, 0x75, 0x72, 0x20, 0x61, 0x64, 0x69, 0x70, 0x69, 0x73, 0x63, 0x69, 0x6e, 0x67 } }, + { 1806262, 48, { 0x65, 0x6c, 0x69, 0x74, 0x2c, 0x20, 0x73, 0x65, 0x64, 0x20, 0x64, 0x6f, 0x20, 0x65, 0x69, 0x75, 0x73, 0x6d, 0x6f, 0x64, 0x20, 0x74, 0x65, 0x6d, 0x70, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x63, 0x69, 0x64, 0x69, 0x64, 0x75, 0x6e, 0x74, 0x20, 0x75, 0x74, 0x20, 0x6c, 0x61, 0x62, 0x6f, 0x72, 0x65 } }, + { 1806263, 48, { 0x65, 0x74, 0x20, 0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x65, 0x20, 0x6d, 0x61, 0x67, 0x6e, 0x61, 0x20, 0x61, 0x6c, 0x69, 0x71, 0x75, 0x61, 0x2e, 0x20, 0x55, 0x74, 0x20, 0x65, 0x6e, 0x69, 0x6d, 0x20, 0x61, 0x64, 0x20, 0x6d, 0x69, 0x6e, 0x69, 0x6d, 0x20, 0x76, 0x65, 0x6e, 0x69, 0x61, 0x6d, 0x2c } }, + { 1806264, 46, { 0x71, 0x75, 0x69, 0x73, 0x20, 0x6e, 0x6f, 0x73, 0x74, 0x72, 0x75, 0x64, 0x20, 0x65, 0x78, 0x65, 0x72, 0x63, 0x69, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x75, 0x6c, 0x6c, 0x61, 0x6d, 0x63, 0x6f, 0x20, 0x6c, 0x61, 0x62, 0x6f, 0x72, 0x69, 0x73, 0x20, 0x6e, 0x69, 0x73, 0x69 } }, + { 1806265, 45, { 0x75, 0x74, 0x20, 0x61, 0x6c, 0x69, 0x71, 0x75, 0x69, 0x70, 0x20, 0x65, 0x78, 0x20, 0x65, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x64, 0x6f, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x71, 0x75, 0x61, 0x74, 0x2e, 0x20, 0x44, 0x75, 0x69, 0x73, 0x20, 0x61, 0x75, 0x74, 0x65 } }, + { 1806266, 47, { 0x69, 0x72, 0x75, 0x72, 0x65, 0x20, 0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x69, 0x6e, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x68, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x69, 0x74, 0x20, 0x69, 0x6e, 0x20, 0x76, 0x6f, 0x6c, 0x75, 0x70, 0x74, 0x61, 0x74, 0x65, 0x20, 0x76, 0x65, 0x6c, 0x69, 0x74 } }, + { 1806267, 44, { 0x65, 0x73, 0x73, 0x65, 0x20, 0x63, 0x69, 0x6c, 0x6c, 0x75, 0x6d, 0x20, 0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x65, 0x20, 0x65, 0x75, 0x20, 0x66, 0x75, 0x67, 0x69, 0x61, 0x74, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x20, 0x70, 0x61, 0x72, 0x69, 0x61, 0x74, 0x75, 0x72, 0x2e } }, + { 1806268, 47, { 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x65, 0x75, 0x72, 0x20, 0x73, 0x69, 0x6e, 0x74, 0x20, 0x6f, 0x63, 0x63, 0x61, 0x65, 0x63, 0x61, 0x74, 0x20, 0x63, 0x75, 0x70, 0x69, 0x64, 0x61, 0x74, 0x61, 0x74, 0x20, 0x6e, 0x6f, 0x6e, 0x20, 0x70, 0x72, 0x6f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2c } }, + { 1806269, 62, { 0x73, 0x75, 0x6e, 0x74, 0x20, 0x69, 0x6e, 0x20, 0x63, 0x75, 0x6c, 0x70, 0x61, 0x20, 0x71, 0x75, 0x69, 0x20, 0x6f, 0x66, 0x66, 0x69, 0x63, 0x69, 0x61, 0x20, 0x64, 0x65, 0x73, 0x65, 0x72, 0x75, 0x6e, 0x74, 0x20, 0x6d, 0x6f, 0x6c, 0x6c, 0x69, 0x74, 0x20, 0x61, 0x6e, 0x69, 0x6d, 0x20, 0x69, 0x64, 0x20, 0x65, 0x73, 0x74, 0x20, 0x6c, 0x61, 0x62, 0x6f, 0x72, 0x75, 0x6d, 0x2e } }, +}; + + +// "cn/wow" +const static uint8_t test_output_wow[] = { + 0x9d, 0x47, 0xbf, 0x4c, 0x41, 0xb7, 0xe8, 0xe7, 0x27, 0xe6, 0x81, 0x71, 0x5a, 0xcb, 0x47, 0xfa, 0x16, 0x77, 0xcd, 0xba, 0x9c, 0xa7, 0xbc, 0xb0, 0x5a, 0xd8, 0xcc, 0x8a, 0xbd, 0x5d, 0xaa, 0x66, + 0x0d, 0x4a, 0x49, 0x5c, 0xb8, 0x44, 0xa3, 0xca, 0x8b, 0xa4, 0xed, 0xb8, 0xe6, 0xbc, 0xf8, 0x29, 0xef, 0x1c, 0x06, 0xd9, 0xcd, 0xea, 0x2b, 0x62, 0xca, 0x46, 0xc2, 0xa2, 0x1b, 0x8b, 0x0a, 0x79, + 0xa1, 0xd6, 0xd8, 0x48, 0xb5, 0xc5, 0x91, 0x5f, 0xcc, 0xd2, 0xf6, 0x4c, 0xf2, 0x16, 0xc6, 0xb1, 0xa0, 0x2c, 0xf7, 0xc7, 0x7b, 0xc8, 0x0d, 0x8d, 0x4e, 0x51, 0xb4, 0x19, 0xe8, 0x8f, 0xf0, 0xdd, + 0xaf, 0x3a, 0x85, 0x44, 0xa0, 0x22, 0x1a, 0x14, 0x8c, 0x2a, 0xc9, 0x04, 0x84, 0xb1, 0x98, 0x61, 0xe3, 0xaf, 0xca, 0x33, 0xfe, 0x17, 0x02, 0x1e, 0xfb, 0x8a, 0xd6, 0x49, 0x6b, 0x56, 0x79, 0x15, + 0x31, 0x33, 0x99, 0xe0, 0x96, 0x3a, 0xe8, 0xa9, 0x9d, 0xab, 0x8a, 0xf6, 0x6d, 0x34, 0x3e, 0x09, 0x7d, 0xae, 0x0c, 0x0f, 0xeb, 0x08, 0xdb, 0xc4, 0x3c, 0xcd, 0xaf, 0xef, 0x55, 0x15, 0xf4, 0x13, + 0x60, 0x21, 0xc6, 0xef, 0x90, 0xbf, 0xf9, 0xae, 0x94, 0xa7, 0x50, 0x6d, 0x62, 0x3d, 0x3a, 0x7a, 0x86, 0xc1, 0x75, 0x6d, 0x65, 0x5f, 0x50, 0xdd, 0x55, 0x8f, 0x71, 0x6d, 0x64, 0x62, 0x2a, 0x34, + 0x2b, 0x13, 0x00, 0x05, 0x35, 0xf3, 0xdb, 0x5f, 0x9b, 0x9b, 0x84, 0xa6, 0x5c, 0x43, 0x51, 0xf3, 0x86, 0xcd, 0x2c, 0xde, 0xde, 0xbb, 0x8c, 0x3a, 0xd2, 0xea, 0xb0, 0x86, 0xe6, 0xa3, 0xfe, 0xe5, + 0xfc, 0x0e, 0x1d, 0xad, 0x8e, 0x89, 0x57, 0x49, 0xdc, 0x90, 0xeb, 0x69, 0x0b, 0xc1, 0xba, 0x05, 0x9a, 0x1c, 0xd7, 0x72, 0xaf, 0xaa, 0xf6, 0x5a, 0x10, 0x6b, 0xf9, 0xe5, 0xe6, 0xb8, 0x05, 0x03, + 0xb6, 0x0b, 0x0a, 0xfe, 0x14, 0x4d, 0xef, 0xf7, 0xd9, 0x03, 0xed, 0x2d, 0x55, 0x45, 0xe7, 0x7e, 0xbe, 0x66, 0xa3, 0xc5, 0x1f, 0xee, 0x70, 0x16, 0xee, 0xb8, 0xfe, 0xe9, 0xeb, 0x63, 0x0c, 0x0f, + 0x64, 0x77, 0x4b, 0x27, 0xe7, 0xd5, 0xfe, 0xc8, 0x62, 0xfc, 0x4c, 0x0c, 0x13, 0xac, 0x6b, 0xf0, 0x91, 0x23, 0xb6, 0xf0, 0x5b, 0xb0, 0xe4, 0xb7, 0x5c, 0x97, 0xf3, 0x79, 0xa2, 0xb3, 0xa6, 0x79, +}; + + +// "cn/r" +const static uint8_t test_output_r[] = { + 0xf7, 0x59, 0x58, 0x8a, 0xd5, 0x7e, 0x75, 0x84, 0x67, 0x29, 0x54, 0x43, 0xa9, 0xbd, 0x71, 0x49, 0x0a, 0xbf, 0xf8, 0xe9, 0xda, 0xd1, 0xb9, 0x5b, 0x6b, 0xf2, 0xf5, 0xd0, 0xd7, 0x83, 0x87, 0xbc, + 0x5b, 0xb8, 0x33, 0xde, 0xca, 0x2b, 0xdd, 0x72, 0x52, 0xa9, 0xcc, 0xd7, 0xb4, 0xce, 0x0b, 0x6a, 0x48, 0x54, 0x51, 0x57, 0x94, 0xb5, 0x6c, 0x20, 0x72, 0x62, 0xf7, 0xa5, 0xb9, 0xbd, 0xb5, 0x66, + 0x1e, 0xe6, 0x72, 0x8d, 0xa6, 0x0f, 0xbd, 0x8d, 0x7d, 0x55, 0xb2, 0xb1, 0xad, 0xe4, 0x87, 0xa3, 0xcf, 0x52, 0xa2, 0xc3, 0xac, 0x6f, 0x52, 0x0d, 0xb1, 0x2c, 0x27, 0xd8, 0x92, 0x1f, 0x6c, 0xab, + 0x69, 0x69, 0xfe, 0x2d, 0xdf, 0xb7, 0x58, 0x43, 0x8d, 0x48, 0x04, 0x9f, 0x30, 0x2f, 0xc2, 0x10, 0x8a, 0x4f, 0xcc, 0x93, 0xe3, 0x76, 0x69, 0x17, 0x0e, 0x6d, 0xb4, 0xb0, 0xb9, 0xb4, 0xc4, 0xcb, + 0x7f, 0x30, 0x48, 0xb4, 0xe9, 0x0d, 0x0c, 0xbe, 0x7a, 0x57, 0xc0, 0x39, 0x4f, 0x37, 0x33, 0x8a, 0x01, 0xfa, 0xe3, 0xad, 0xfd, 0xc0, 0xe5, 0x12, 0x6d, 0x86, 0x3a, 0x89, 0x5e, 0xb0, 0x4e, 0x02, + 0x1d, 0x29, 0x04, 0x43, 0xa4, 0xb5, 0x42, 0xaf, 0x04, 0xa8, 0x2f, 0x6b, 0x24, 0x94, 0xa6, 0xee, 0x7f, 0x20, 0xf2, 0x75, 0x4c, 0x58, 0xe0, 0x84, 0x90, 0x32, 0x48, 0x3a, 0x56, 0xe8, 0xe2, 0xef, + 0xc4, 0x3c, 0xc6, 0x56, 0x74, 0x36, 0xa8, 0x6a, 0xfb, 0xd6, 0xaa, 0x9e, 0xaa, 0x7c, 0x27, 0x6e, 0x98, 0x06, 0x83, 0x03, 0x34, 0xb6, 0x14, 0xb2, 0xbe, 0xe2, 0x3c, 0xc7, 0x66, 0x34, 0xf6, 0xfd, + 0x87, 0xbe, 0x24, 0x79, 0xc0, 0xc4, 0xe8, 0xed, 0xfd, 0xfa, 0xa5, 0x60, 0x3e, 0x93, 0xf4, 0x26, 0x5b, 0x3f, 0x82, 0x24, 0xc1, 0xc5, 0x94, 0x6f, 0xeb, 0x42, 0x48, 0x19, 0xd1, 0x89, 0x90, 0xa4, + 0xdd, 0x9d, 0x6a, 0x6d, 0x8e, 0x47, 0x46, 0x5c, 0xce, 0xac, 0x08, 0x77, 0xef, 0x88, 0x9b, 0x93, 0xe7, 0xeb, 0xa9, 0x79, 0x55, 0x7e, 0x39, 0x35, 0xd7, 0xf8, 0x6d, 0xce, 0x11, 0xb0, 0x70, 0xf3, + 0x75, 0xc6, 0xf2, 0xae, 0x49, 0xa2, 0x05, 0x21, 0xde, 0x97, 0x28, 0x5b, 0x43, 0x1e, 0x71, 0x71, 0x25, 0x84, 0x7f, 0xb8, 0x93, 0x5e, 0xd8, 0x4a, 0x61, 0xe7, 0xf8, 0xd3, 0x6a, 0x2c, 0x3d, 0x8e, +}; + // "cn/0" const static uint8_t test_output_v0[160] = { @@ -295,8 +326,6 @@ const static uint8_t test_output_pico_trtl[160] = { }; #endif -unsigned char hf_hex2bin(char c, bool &err); -char hf_bin2hex(unsigned char c); #ifndef XMRIG_NO_CN_GPU // "cn/gpu" diff --git a/src/interfaces/IWorker.h b/src/interfaces/IWorker.h index 90394c2cc..83e9306ec 100644 --- a/src/interfaces/IWorker.h +++ b/src/interfaces/IWorker.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __IWORKER_H__ -#define __IWORKER_H__ +#ifndef XMRIG_IWORKER_H +#define XMRIG_IWORKER_H #include @@ -31,7 +32,7 @@ class IWorker { public: - virtual ~IWorker() {} + virtual ~IWorker() = default; virtual bool selfTest() = 0; virtual size_t id() const = 0; @@ -41,4 +42,4 @@ public: }; -#endif // __IWORKER_H__ +#endif // XMRIG_IWORKER_H diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 340b6620f..1d1c75193 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -25,7 +25,6 @@ #include -#include #include "crypto/CryptoNight_test.h" @@ -56,23 +55,16 @@ bool MultiWorker::selfTest() using namespace xmrig; if (m_thread->algorithm() == CRYPTONIGHT) { - if (!verify2(VARIANT_WOW, test_input_WOW)) { - LOG_WARN("CryptonightR (Wownero) self-test failed"); - return false; - } - if (!verify2(VARIANT_4, test_input_R)) { - LOG_WARN("CryptonightR self-test failed"); - return false; - } - - const bool rc = verify(VARIANT_0, test_output_v0) && - verify(VARIANT_1, test_output_v1) && - verify(VARIANT_2, test_output_v2) && - verify(VARIANT_XTL, test_output_xtl) && - verify(VARIANT_MSR, test_output_msr) && - verify(VARIANT_XAO, test_output_xao) && - verify(VARIANT_RTO, test_output_rto) && - verify(VARIANT_HALF, test_output_half); + const bool rc = verify(VARIANT_0, test_output_v0) && + verify(VARIANT_1, test_output_v1) && + verify(VARIANT_2, test_output_v2) && + verify(VARIANT_XTL, test_output_xtl) && + verify(VARIANT_MSR, test_output_msr) && + verify(VARIANT_XAO, test_output_xao) && + verify(VARIANT_RTO, test_output_rto) && + verify(VARIANT_HALF, test_output_half) && + verify2(VARIANT_WOW, test_output_wow) && + verify2(VARIANT_4, test_output_r); # ifndef XMRIG_NO_CN_GPU if (!rc || N > 1) { @@ -179,61 +171,48 @@ bool MultiWorker::verify(xmrig::Variant variant, const uint8_t *referenceValu template -bool MultiWorker::verify2(xmrig::Variant variant, const char *test_data) +bool MultiWorker::verify2(xmrig::Variant variant, const uint8_t *referenceValue) { xmrig::CpuThread::cn_hash_fun func = m_thread->fn(variant); if (!func) { return false; } - std::stringstream s(test_data); - std::string expected_hex; - std::string input_hex; - uint64_t height; - while (!s.eof()) - { - uint8_t referenceValue[N * 32]; - uint8_t input[N * 256]; - - s >> expected_hex; - s >> input_hex; - s >> height; - - if ((expected_hex.length() != 64) || (input_hex.length() > 512)) - { - return false; + for (size_t i = 0; i < (sizeof(cn_r_test_input) / sizeof(cn_r_test_input[0])); ++i) { + const size_t size = cn_r_test_input[i].size; + for (size_t k = 0; k < N; ++k) { + memcpy(m_state.blob + (k * size), cn_r_test_input[i].data, size); } - bool err = false; + func(m_state.blob, size, m_hash, m_ctx, cn_r_test_input[i].height); - for (int i = 0; i < 32; ++i) - { - referenceValue[i] = (hf_hex2bin(expected_hex[i * 2], err) << 4) + hf_hex2bin(expected_hex[i * 2 + 1], err); + for (size_t k = 0; k < N; ++k) { + if (memcmp(m_hash + k * 32, referenceValue + i * 32, sizeof m_hash / N) != 0) { + return false; + } } + } - const size_t input_len = input_hex.length() / 2; - for (size_t i = 0; i < input_len; ++i) - { - input[i] = (hf_hex2bin(input_hex[i * 2], err) << 4) + hf_hex2bin(input_hex[i * 2 + 1], err); - } + return true; +} - if (err) - { - return false; - } - for (size_t i = 1; i < N; ++i) - { - memcpy(input + i * input_len, input, input_len); - memcpy(referenceValue + i * 32, referenceValue, 32); - } +template<> +bool MultiWorker<1>::verify2(xmrig::Variant variant, const uint8_t *referenceValue) +{ + xmrig::CpuThread::cn_hash_fun func = m_thread->fn(variant); + if (!func) { + return false; + } - func(input, input_len, m_hash, m_ctx, height); - if (memcmp(m_hash, referenceValue, sizeof m_hash) != 0) - { + for (size_t i = 0; i < (sizeof(cn_r_test_input) / sizeof(cn_r_test_input[0])); ++i) { + func(cn_r_test_input[i].data, cn_r_test_input[i].size, m_hash, m_ctx, cn_r_test_input[i].height); + + if (memcmp(m_hash, referenceValue + i * 32, sizeof m_hash) != 0) { return false; } } + return true; } diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index 8560b510a..b7e4c8cae 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -50,7 +50,7 @@ protected: private: bool resume(const xmrig::Job &job); bool verify(xmrig::Variant variant, const uint8_t *referenceValue); - bool verify2(xmrig::Variant variant, const char *test_data); + bool verify2(xmrig::Variant variant, const uint8_t *referenceValue); void consumeJob(); void save(const xmrig::Job &job); From 18a9803e5e3e2128a2d30569f2c9111b4dba74a7 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 4 Mar 2019 14:40:22 +0700 Subject: [PATCH 20/55] Removed unnecessary ASM files duplicates for MSYS2. --- cmake/asm.cmake | 2 +- .../win64/CryptonightR_soft_aes_template.inc | 279 --- src/crypto/asm/win64/CryptonightR_template.S | 1595 ----------------- .../asm/win64/CryptonightR_template.inc | 529 ------ .../CryptonightWOW_soft_aes_template.inc | 266 --- .../asm/win64/CryptonightWOW_template.inc | 486 ----- 6 files changed, 1 insertion(+), 3156 deletions(-) delete mode 100644 src/crypto/asm/win64/CryptonightR_soft_aes_template.inc delete mode 100644 src/crypto/asm/win64/CryptonightR_template.S delete mode 100644 src/crypto/asm/win64/CryptonightR_template.inc delete mode 100644 src/crypto/asm/win64/CryptonightWOW_soft_aes_template.inc delete mode 100644 src/crypto/asm/win64/CryptonightWOW_template.inc diff --git a/cmake/asm.cmake b/cmake/asm.cmake index 1007f9277..389f67231 100644 --- a/cmake/asm.cmake +++ b/cmake/asm.cmake @@ -23,7 +23,7 @@ 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/win64/CryptonightR_template.S" + "src/crypto/asm/CryptonightR_template.S" ) else() set(XMRIG_ASM_FILES diff --git a/src/crypto/asm/win64/CryptonightR_soft_aes_template.inc b/src/crypto/asm/win64/CryptonightR_soft_aes_template.inc deleted file mode 100644 index c4a0559bd..000000000 --- a/src/crypto/asm/win64/CryptonightR_soft_aes_template.inc +++ /dev/null @@ -1,279 +0,0 @@ -PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_part1) -PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_mainloop) -PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_part2) -PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_part3) -PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_end) - -ALIGN(64) -FN_PREFIX(CryptonightR_soft_aes_template_part1): - mov QWORD PTR [rsp+8], rcx - push rbx - push rbp - push rsi - push rdi - push r12 - push r13 - push r14 - push r15 - sub rsp, 232 - - mov eax, [rcx+96] - mov ebx, [rcx+100] - mov esi, [rcx+104] - mov edx, [rcx+108] - mov [rsp+144], eax - mov [rsp+148], ebx - mov [rsp+152], esi - mov [rsp+156], edx - - mov rax, QWORD PTR [rcx+48] - mov r10, rcx - xor rax, QWORD PTR [rcx+16] - mov r8, QWORD PTR [rcx+32] - xor r8, QWORD PTR [rcx] - mov r9, QWORD PTR [rcx+40] - xor r9, QWORD PTR [rcx+8] - movd xmm4, rax - mov rdx, QWORD PTR [rcx+56] - xor rdx, QWORD PTR [rcx+24] - mov r11, QWORD PTR [rcx+224] - mov rcx, QWORD PTR [rcx+88] - xor rcx, QWORD PTR [r10+72] - mov rax, QWORD PTR [r10+80] - movd xmm0, rdx - xor rax, QWORD PTR [r10+64] - - movaps XMMWORD PTR [rsp+16], xmm6 - movaps XMMWORD PTR [rsp+32], xmm7 - movaps XMMWORD PTR [rsp+48], xmm8 - movaps XMMWORD PTR [rsp+64], xmm9 - movaps XMMWORD PTR [rsp+80], xmm10 - movaps XMMWORD PTR [rsp+96], xmm11 - movaps XMMWORD PTR [rsp+112], xmm12 - movaps XMMWORD PTR [rsp+128], xmm13 - - movd xmm5, rax - - mov rax, r8 - punpcklqdq xmm4, xmm0 - and eax, 2097136 - movd xmm10, QWORD PTR [r10+96] - movd xmm0, rcx - mov rcx, QWORD PTR [r10+104] - xorps xmm9, xmm9 - mov QWORD PTR [rsp+328], rax - movd xmm12, r11 - mov QWORD PTR [rsp+320], r9 - punpcklqdq xmm5, xmm0 - movd xmm13, rcx - mov r12d, 524288 - - ALIGN(64) -FN_PREFIX(CryptonightR_soft_aes_template_mainloop): - movd xmm11, r12d - mov r12, QWORD PTR [r10+272] - lea r13, QWORD PTR [rax+r11] - mov esi, DWORD PTR [r13] - movd xmm0, r9 - mov r10d, DWORD PTR [r13+4] - movd xmm7, r8 - mov ebp, DWORD PTR [r13+12] - mov r14d, DWORD PTR [r13+8] - mov rdx, QWORD PTR [rsp+328] - movzx ecx, sil - shr esi, 8 - punpcklqdq xmm7, xmm0 - mov r15d, DWORD PTR [r12+rcx*4] - movzx ecx, r10b - shr r10d, 8 - mov edi, DWORD PTR [r12+rcx*4] - movzx ecx, r14b - shr r14d, 8 - mov ebx, DWORD PTR [r12+rcx*4] - movzx ecx, bpl - shr ebp, 8 - mov r9d, DWORD PTR [r12+rcx*4] - movzx ecx, r10b - shr r10d, 8 - xor r15d, DWORD PTR [r12+rcx*4+1024] - movzx ecx, r14b - shr r14d, 8 - mov eax, r14d - shr eax, 8 - xor edi, DWORD PTR [r12+rcx*4+1024] - add eax, 256 - movzx ecx, bpl - shr ebp, 8 - xor ebx, DWORD PTR [r12+rcx*4+1024] - movzx ecx, sil - shr esi, 8 - xor r9d, DWORD PTR [r12+rcx*4+1024] - add r12, 2048 - movzx ecx, r10b - shr r10d, 8 - add r10d, 256 - mov r11d, DWORD PTR [r12+rax*4] - xor r11d, DWORD PTR [r12+rcx*4] - xor r11d, r9d - movzx ecx, sil - mov r10d, DWORD PTR [r12+r10*4] - shr esi, 8 - add esi, 256 - xor r10d, DWORD PTR [r12+rcx*4] - movzx ecx, bpl - xor r10d, ebx - shr ebp, 8 - movd xmm1, r11d - add ebp, 256 - movd r11, xmm12 - mov r9d, DWORD PTR [r12+rcx*4] - xor r9d, DWORD PTR [r12+rsi*4] - mov eax, DWORD PTR [r12+rbp*4] - xor r9d, edi - movzx ecx, r14b - movd xmm0, r10d - movd xmm2, r9d - xor eax, DWORD PTR [r12+rcx*4] - mov rcx, rdx - xor eax, r15d - punpckldq xmm2, xmm1 - xor rcx, 16 - movd xmm6, eax - mov rax, rdx - punpckldq xmm6, xmm0 - xor rax, 32 - punpckldq xmm6, xmm2 - xor rdx, 48 - movdqu xmm2, XMMWORD PTR [rcx+r11] - pxor xmm6, xmm2 - pxor xmm6, xmm7 - paddq xmm2, xmm4 - movdqu xmm1, XMMWORD PTR [rax+r11] - movdqu xmm0, XMMWORD PTR [rdx+r11] - pxor xmm6, xmm1 - pxor xmm6, xmm0 - paddq xmm0, xmm5 - movdqu XMMWORD PTR [rcx+r11], xmm0 - movdqu XMMWORD PTR [rax+r11], xmm2 - movd rcx, xmm13 - paddq xmm1, xmm7 - movdqu XMMWORD PTR [rdx+r11], xmm1 - movd rdi, xmm6 - mov r10, rdi - and r10d, 2097136 - movdqa xmm0, xmm6 - pxor xmm0, xmm4 - movdqu XMMWORD PTR [r13], xmm0 - - mov ebx, [rsp+144] - mov ebp, [rsp+152] - add ebx, [rsp+148] - add ebp, [rsp+156] - shl rbp, 32 - or rbx, rbp - - xor rbx, QWORD PTR [r10+r11] - lea r14, QWORD PTR [r10+r11] - mov rbp, QWORD PTR [r14+8] - - mov [rsp+160], rbx - mov [rsp+168], rdi - mov [rsp+176], rbp - mov [rsp+184], r10 - mov r10, rsp - - mov ebx, [rsp+144] - mov esi, [rsp+148] - mov edi, [rsp+152] - mov ebp, [rsp+156] - - movd esp, xmm7 - movaps xmm0, xmm7 - psrldq xmm0, 8 - movd r15d, xmm0 - movd eax, xmm4 - movd edx, xmm5 - movaps xmm0, xmm5 - psrldq xmm0, 8 - movd r9d, xmm0 - -FN_PREFIX(CryptonightR_soft_aes_template_part2): - mov rsp, r10 - mov [rsp+144], ebx - mov [rsp+148], esi - mov [rsp+152], edi - mov [rsp+156], ebp - - mov edi, edi - shl rbp, 32 - or rbp, rdi - xor r8, rbp - - mov ebx, ebx - shl rsi, 32 - or rsi, rbx - xor QWORD PTR [rsp+320], rsi - - mov rbx, [rsp+160] - mov rdi, [rsp+168] - mov rbp, [rsp+176] - mov r10, [rsp+184] - - mov r9, r10 - xor r9, 16 - mov rcx, r10 - xor rcx, 32 - xor r10, 48 - mov rax, rbx - mul rdi - movdqu xmm2, XMMWORD PTR [r9+r11] - movdqu xmm1, XMMWORD PTR [rcx+r11] - pxor xmm6, xmm2 - pxor xmm6, xmm1 - paddq xmm1, xmm7 - add r8, rdx - movdqu xmm0, XMMWORD PTR [r10+r11] - pxor xmm6, xmm0 - paddq xmm0, xmm5 - paddq xmm2, xmm4 - movdqu XMMWORD PTR [r9+r11], xmm0 - movdqa xmm5, xmm4 - mov r9, QWORD PTR [rsp+320] - movdqa xmm4, xmm6 - add r9, rax - movdqu XMMWORD PTR [rcx+r11], xmm2 - movdqu XMMWORD PTR [r10+r11], xmm1 - mov r10, QWORD PTR [rsp+304] - movd r12d, xmm11 - mov QWORD PTR [r14], r8 - xor r8, rbx - mov rax, r8 - mov QWORD PTR [r14+8], r9 - and eax, 2097136 - xor r9, rbp - mov QWORD PTR [rsp+320], r9 - mov QWORD PTR [rsp+328], rax - sub r12d, 1 - jne FN_PREFIX(CryptonightR_soft_aes_template_mainloop) - -FN_PREFIX(CryptonightR_soft_aes_template_part3): - movaps xmm6, XMMWORD PTR [rsp+16] - movaps xmm7, XMMWORD PTR [rsp+32] - movaps xmm8, XMMWORD PTR [rsp+48] - movaps xmm9, XMMWORD PTR [rsp+64] - movaps xmm10, XMMWORD PTR [rsp+80] - movaps xmm11, XMMWORD PTR [rsp+96] - movaps xmm12, XMMWORD PTR [rsp+112] - movaps xmm13, XMMWORD PTR [rsp+128] - - add rsp, 232 - pop r15 - pop r14 - pop r13 - pop r12 - pop rdi - pop rsi - pop rbp - pop rbx - ret -FN_PREFIX(CryptonightR_soft_aes_template_end): diff --git a/src/crypto/asm/win64/CryptonightR_template.S b/src/crypto/asm/win64/CryptonightR_template.S deleted file mode 100644 index d2974d160..000000000 --- a/src/crypto/asm/win64/CryptonightR_template.S +++ /dev/null @@ -1,1595 +0,0 @@ -#ifdef __APPLE__ -# define ALIGN(x) .align 6 -#else -# define ALIGN(x) .align 64 -#endif -.intel_syntax noprefix -#ifdef __APPLE__ -# define FN_PREFIX(fn) _ ## fn -.text -#else -# define FN_PREFIX(fn) fn -.section .text -#endif - -#define PUBLIC .global - -PUBLIC FN_PREFIX(CryptonightR_instruction0) -PUBLIC FN_PREFIX(CryptonightR_instruction1) -PUBLIC FN_PREFIX(CryptonightR_instruction2) -PUBLIC FN_PREFIX(CryptonightR_instruction3) -PUBLIC FN_PREFIX(CryptonightR_instruction4) -PUBLIC FN_PREFIX(CryptonightR_instruction5) -PUBLIC FN_PREFIX(CryptonightR_instruction6) -PUBLIC FN_PREFIX(CryptonightR_instruction7) -PUBLIC FN_PREFIX(CryptonightR_instruction8) -PUBLIC FN_PREFIX(CryptonightR_instruction9) -PUBLIC FN_PREFIX(CryptonightR_instruction10) -PUBLIC FN_PREFIX(CryptonightR_instruction11) -PUBLIC FN_PREFIX(CryptonightR_instruction12) -PUBLIC FN_PREFIX(CryptonightR_instruction13) -PUBLIC FN_PREFIX(CryptonightR_instruction14) -PUBLIC FN_PREFIX(CryptonightR_instruction15) -PUBLIC FN_PREFIX(CryptonightR_instruction16) -PUBLIC FN_PREFIX(CryptonightR_instruction17) -PUBLIC FN_PREFIX(CryptonightR_instruction18) -PUBLIC FN_PREFIX(CryptonightR_instruction19) -PUBLIC FN_PREFIX(CryptonightR_instruction20) -PUBLIC FN_PREFIX(CryptonightR_instruction21) -PUBLIC FN_PREFIX(CryptonightR_instruction22) -PUBLIC FN_PREFIX(CryptonightR_instruction23) -PUBLIC FN_PREFIX(CryptonightR_instruction24) -PUBLIC FN_PREFIX(CryptonightR_instruction25) -PUBLIC FN_PREFIX(CryptonightR_instruction26) -PUBLIC FN_PREFIX(CryptonightR_instruction27) -PUBLIC FN_PREFIX(CryptonightR_instruction28) -PUBLIC FN_PREFIX(CryptonightR_instruction29) -PUBLIC FN_PREFIX(CryptonightR_instruction30) -PUBLIC FN_PREFIX(CryptonightR_instruction31) -PUBLIC FN_PREFIX(CryptonightR_instruction32) -PUBLIC FN_PREFIX(CryptonightR_instruction33) -PUBLIC FN_PREFIX(CryptonightR_instruction34) -PUBLIC FN_PREFIX(CryptonightR_instruction35) -PUBLIC FN_PREFIX(CryptonightR_instruction36) -PUBLIC FN_PREFIX(CryptonightR_instruction37) -PUBLIC FN_PREFIX(CryptonightR_instruction38) -PUBLIC FN_PREFIX(CryptonightR_instruction39) -PUBLIC FN_PREFIX(CryptonightR_instruction40) -PUBLIC FN_PREFIX(CryptonightR_instruction41) -PUBLIC FN_PREFIX(CryptonightR_instruction42) -PUBLIC FN_PREFIX(CryptonightR_instruction43) -PUBLIC FN_PREFIX(CryptonightR_instruction44) -PUBLIC FN_PREFIX(CryptonightR_instruction45) -PUBLIC FN_PREFIX(CryptonightR_instruction46) -PUBLIC FN_PREFIX(CryptonightR_instruction47) -PUBLIC FN_PREFIX(CryptonightR_instruction48) -PUBLIC FN_PREFIX(CryptonightR_instruction49) -PUBLIC FN_PREFIX(CryptonightR_instruction50) -PUBLIC FN_PREFIX(CryptonightR_instruction51) -PUBLIC FN_PREFIX(CryptonightR_instruction52) -PUBLIC FN_PREFIX(CryptonightR_instruction53) -PUBLIC FN_PREFIX(CryptonightR_instruction54) -PUBLIC FN_PREFIX(CryptonightR_instruction55) -PUBLIC FN_PREFIX(CryptonightR_instruction56) -PUBLIC FN_PREFIX(CryptonightR_instruction57) -PUBLIC FN_PREFIX(CryptonightR_instruction58) -PUBLIC FN_PREFIX(CryptonightR_instruction59) -PUBLIC FN_PREFIX(CryptonightR_instruction60) -PUBLIC FN_PREFIX(CryptonightR_instruction61) -PUBLIC FN_PREFIX(CryptonightR_instruction62) -PUBLIC FN_PREFIX(CryptonightR_instruction63) -PUBLIC FN_PREFIX(CryptonightR_instruction64) -PUBLIC FN_PREFIX(CryptonightR_instruction65) -PUBLIC FN_PREFIX(CryptonightR_instruction66) -PUBLIC FN_PREFIX(CryptonightR_instruction67) -PUBLIC FN_PREFIX(CryptonightR_instruction68) -PUBLIC FN_PREFIX(CryptonightR_instruction69) -PUBLIC FN_PREFIX(CryptonightR_instruction70) -PUBLIC FN_PREFIX(CryptonightR_instruction71) -PUBLIC FN_PREFIX(CryptonightR_instruction72) -PUBLIC FN_PREFIX(CryptonightR_instruction73) -PUBLIC FN_PREFIX(CryptonightR_instruction74) -PUBLIC FN_PREFIX(CryptonightR_instruction75) -PUBLIC FN_PREFIX(CryptonightR_instruction76) -PUBLIC FN_PREFIX(CryptonightR_instruction77) -PUBLIC FN_PREFIX(CryptonightR_instruction78) -PUBLIC FN_PREFIX(CryptonightR_instruction79) -PUBLIC FN_PREFIX(CryptonightR_instruction80) -PUBLIC FN_PREFIX(CryptonightR_instruction81) -PUBLIC FN_PREFIX(CryptonightR_instruction82) -PUBLIC FN_PREFIX(CryptonightR_instruction83) -PUBLIC FN_PREFIX(CryptonightR_instruction84) -PUBLIC FN_PREFIX(CryptonightR_instruction85) -PUBLIC FN_PREFIX(CryptonightR_instruction86) -PUBLIC FN_PREFIX(CryptonightR_instruction87) -PUBLIC FN_PREFIX(CryptonightR_instruction88) -PUBLIC FN_PREFIX(CryptonightR_instruction89) -PUBLIC FN_PREFIX(CryptonightR_instruction90) -PUBLIC FN_PREFIX(CryptonightR_instruction91) -PUBLIC FN_PREFIX(CryptonightR_instruction92) -PUBLIC FN_PREFIX(CryptonightR_instruction93) -PUBLIC FN_PREFIX(CryptonightR_instruction94) -PUBLIC FN_PREFIX(CryptonightR_instruction95) -PUBLIC FN_PREFIX(CryptonightR_instruction96) -PUBLIC FN_PREFIX(CryptonightR_instruction97) -PUBLIC FN_PREFIX(CryptonightR_instruction98) -PUBLIC FN_PREFIX(CryptonightR_instruction99) -PUBLIC FN_PREFIX(CryptonightR_instruction100) -PUBLIC FN_PREFIX(CryptonightR_instruction101) -PUBLIC FN_PREFIX(CryptonightR_instruction102) -PUBLIC FN_PREFIX(CryptonightR_instruction103) -PUBLIC FN_PREFIX(CryptonightR_instruction104) -PUBLIC FN_PREFIX(CryptonightR_instruction105) -PUBLIC FN_PREFIX(CryptonightR_instruction106) -PUBLIC FN_PREFIX(CryptonightR_instruction107) -PUBLIC FN_PREFIX(CryptonightR_instruction108) -PUBLIC FN_PREFIX(CryptonightR_instruction109) -PUBLIC FN_PREFIX(CryptonightR_instruction110) -PUBLIC FN_PREFIX(CryptonightR_instruction111) -PUBLIC FN_PREFIX(CryptonightR_instruction112) -PUBLIC FN_PREFIX(CryptonightR_instruction113) -PUBLIC FN_PREFIX(CryptonightR_instruction114) -PUBLIC FN_PREFIX(CryptonightR_instruction115) -PUBLIC FN_PREFIX(CryptonightR_instruction116) -PUBLIC FN_PREFIX(CryptonightR_instruction117) -PUBLIC FN_PREFIX(CryptonightR_instruction118) -PUBLIC FN_PREFIX(CryptonightR_instruction119) -PUBLIC FN_PREFIX(CryptonightR_instruction120) -PUBLIC FN_PREFIX(CryptonightR_instruction121) -PUBLIC FN_PREFIX(CryptonightR_instruction122) -PUBLIC FN_PREFIX(CryptonightR_instruction123) -PUBLIC FN_PREFIX(CryptonightR_instruction124) -PUBLIC FN_PREFIX(CryptonightR_instruction125) -PUBLIC FN_PREFIX(CryptonightR_instruction126) -PUBLIC FN_PREFIX(CryptonightR_instruction127) -PUBLIC FN_PREFIX(CryptonightR_instruction128) -PUBLIC FN_PREFIX(CryptonightR_instruction129) -PUBLIC FN_PREFIX(CryptonightR_instruction130) -PUBLIC FN_PREFIX(CryptonightR_instruction131) -PUBLIC FN_PREFIX(CryptonightR_instruction132) -PUBLIC FN_PREFIX(CryptonightR_instruction133) -PUBLIC FN_PREFIX(CryptonightR_instruction134) -PUBLIC FN_PREFIX(CryptonightR_instruction135) -PUBLIC FN_PREFIX(CryptonightR_instruction136) -PUBLIC FN_PREFIX(CryptonightR_instruction137) -PUBLIC FN_PREFIX(CryptonightR_instruction138) -PUBLIC FN_PREFIX(CryptonightR_instruction139) -PUBLIC FN_PREFIX(CryptonightR_instruction140) -PUBLIC FN_PREFIX(CryptonightR_instruction141) -PUBLIC FN_PREFIX(CryptonightR_instruction142) -PUBLIC FN_PREFIX(CryptonightR_instruction143) -PUBLIC FN_PREFIX(CryptonightR_instruction144) -PUBLIC FN_PREFIX(CryptonightR_instruction145) -PUBLIC FN_PREFIX(CryptonightR_instruction146) -PUBLIC FN_PREFIX(CryptonightR_instruction147) -PUBLIC FN_PREFIX(CryptonightR_instruction148) -PUBLIC FN_PREFIX(CryptonightR_instruction149) -PUBLIC FN_PREFIX(CryptonightR_instruction150) -PUBLIC FN_PREFIX(CryptonightR_instruction151) -PUBLIC FN_PREFIX(CryptonightR_instruction152) -PUBLIC FN_PREFIX(CryptonightR_instruction153) -PUBLIC FN_PREFIX(CryptonightR_instruction154) -PUBLIC FN_PREFIX(CryptonightR_instruction155) -PUBLIC FN_PREFIX(CryptonightR_instruction156) -PUBLIC FN_PREFIX(CryptonightR_instruction157) -PUBLIC FN_PREFIX(CryptonightR_instruction158) -PUBLIC FN_PREFIX(CryptonightR_instruction159) -PUBLIC FN_PREFIX(CryptonightR_instruction160) -PUBLIC FN_PREFIX(CryptonightR_instruction161) -PUBLIC FN_PREFIX(CryptonightR_instruction162) -PUBLIC FN_PREFIX(CryptonightR_instruction163) -PUBLIC FN_PREFIX(CryptonightR_instruction164) -PUBLIC FN_PREFIX(CryptonightR_instruction165) -PUBLIC FN_PREFIX(CryptonightR_instruction166) -PUBLIC FN_PREFIX(CryptonightR_instruction167) -PUBLIC FN_PREFIX(CryptonightR_instruction168) -PUBLIC FN_PREFIX(CryptonightR_instruction169) -PUBLIC FN_PREFIX(CryptonightR_instruction170) -PUBLIC FN_PREFIX(CryptonightR_instruction171) -PUBLIC FN_PREFIX(CryptonightR_instruction172) -PUBLIC FN_PREFIX(CryptonightR_instruction173) -PUBLIC FN_PREFIX(CryptonightR_instruction174) -PUBLIC FN_PREFIX(CryptonightR_instruction175) -PUBLIC FN_PREFIX(CryptonightR_instruction176) -PUBLIC FN_PREFIX(CryptonightR_instruction177) -PUBLIC FN_PREFIX(CryptonightR_instruction178) -PUBLIC FN_PREFIX(CryptonightR_instruction179) -PUBLIC FN_PREFIX(CryptonightR_instruction180) -PUBLIC FN_PREFIX(CryptonightR_instruction181) -PUBLIC FN_PREFIX(CryptonightR_instruction182) -PUBLIC FN_PREFIX(CryptonightR_instruction183) -PUBLIC FN_PREFIX(CryptonightR_instruction184) -PUBLIC FN_PREFIX(CryptonightR_instruction185) -PUBLIC FN_PREFIX(CryptonightR_instruction186) -PUBLIC FN_PREFIX(CryptonightR_instruction187) -PUBLIC FN_PREFIX(CryptonightR_instruction188) -PUBLIC FN_PREFIX(CryptonightR_instruction189) -PUBLIC FN_PREFIX(CryptonightR_instruction190) -PUBLIC FN_PREFIX(CryptonightR_instruction191) -PUBLIC FN_PREFIX(CryptonightR_instruction192) -PUBLIC FN_PREFIX(CryptonightR_instruction193) -PUBLIC FN_PREFIX(CryptonightR_instruction194) -PUBLIC FN_PREFIX(CryptonightR_instruction195) -PUBLIC FN_PREFIX(CryptonightR_instruction196) -PUBLIC FN_PREFIX(CryptonightR_instruction197) -PUBLIC FN_PREFIX(CryptonightR_instruction198) -PUBLIC FN_PREFIX(CryptonightR_instruction199) -PUBLIC FN_PREFIX(CryptonightR_instruction200) -PUBLIC FN_PREFIX(CryptonightR_instruction201) -PUBLIC FN_PREFIX(CryptonightR_instruction202) -PUBLIC FN_PREFIX(CryptonightR_instruction203) -PUBLIC FN_PREFIX(CryptonightR_instruction204) -PUBLIC FN_PREFIX(CryptonightR_instruction205) -PUBLIC FN_PREFIX(CryptonightR_instruction206) -PUBLIC FN_PREFIX(CryptonightR_instruction207) -PUBLIC FN_PREFIX(CryptonightR_instruction208) -PUBLIC FN_PREFIX(CryptonightR_instruction209) -PUBLIC FN_PREFIX(CryptonightR_instruction210) -PUBLIC FN_PREFIX(CryptonightR_instruction211) -PUBLIC FN_PREFIX(CryptonightR_instruction212) -PUBLIC FN_PREFIX(CryptonightR_instruction213) -PUBLIC FN_PREFIX(CryptonightR_instruction214) -PUBLIC FN_PREFIX(CryptonightR_instruction215) -PUBLIC FN_PREFIX(CryptonightR_instruction216) -PUBLIC FN_PREFIX(CryptonightR_instruction217) -PUBLIC FN_PREFIX(CryptonightR_instruction218) -PUBLIC FN_PREFIX(CryptonightR_instruction219) -PUBLIC FN_PREFIX(CryptonightR_instruction220) -PUBLIC FN_PREFIX(CryptonightR_instruction221) -PUBLIC FN_PREFIX(CryptonightR_instruction222) -PUBLIC FN_PREFIX(CryptonightR_instruction223) -PUBLIC FN_PREFIX(CryptonightR_instruction224) -PUBLIC FN_PREFIX(CryptonightR_instruction225) -PUBLIC FN_PREFIX(CryptonightR_instruction226) -PUBLIC FN_PREFIX(CryptonightR_instruction227) -PUBLIC FN_PREFIX(CryptonightR_instruction228) -PUBLIC FN_PREFIX(CryptonightR_instruction229) -PUBLIC FN_PREFIX(CryptonightR_instruction230) -PUBLIC FN_PREFIX(CryptonightR_instruction231) -PUBLIC FN_PREFIX(CryptonightR_instruction232) -PUBLIC FN_PREFIX(CryptonightR_instruction233) -PUBLIC FN_PREFIX(CryptonightR_instruction234) -PUBLIC FN_PREFIX(CryptonightR_instruction235) -PUBLIC FN_PREFIX(CryptonightR_instruction236) -PUBLIC FN_PREFIX(CryptonightR_instruction237) -PUBLIC FN_PREFIX(CryptonightR_instruction238) -PUBLIC FN_PREFIX(CryptonightR_instruction239) -PUBLIC FN_PREFIX(CryptonightR_instruction240) -PUBLIC FN_PREFIX(CryptonightR_instruction241) -PUBLIC FN_PREFIX(CryptonightR_instruction242) -PUBLIC FN_PREFIX(CryptonightR_instruction243) -PUBLIC FN_PREFIX(CryptonightR_instruction244) -PUBLIC FN_PREFIX(CryptonightR_instruction245) -PUBLIC FN_PREFIX(CryptonightR_instruction246) -PUBLIC FN_PREFIX(CryptonightR_instruction247) -PUBLIC FN_PREFIX(CryptonightR_instruction248) -PUBLIC FN_PREFIX(CryptonightR_instruction249) -PUBLIC FN_PREFIX(CryptonightR_instruction250) -PUBLIC FN_PREFIX(CryptonightR_instruction251) -PUBLIC FN_PREFIX(CryptonightR_instruction252) -PUBLIC FN_PREFIX(CryptonightR_instruction253) -PUBLIC FN_PREFIX(CryptonightR_instruction254) -PUBLIC FN_PREFIX(CryptonightR_instruction255) -PUBLIC FN_PREFIX(CryptonightR_instruction256) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov0) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov1) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov2) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov3) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov4) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov5) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov6) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov7) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov8) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov9) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov10) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov11) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov12) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov13) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov14) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov15) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov16) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov17) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov18) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov19) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov20) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov21) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov22) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov23) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov24) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov25) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov26) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov27) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov28) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov29) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov30) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov31) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov32) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov33) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov34) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov35) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov36) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov37) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov38) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov39) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov40) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov41) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov42) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov43) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov44) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov45) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov46) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov47) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov48) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov49) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov50) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov51) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov52) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov53) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov54) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov55) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov56) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov57) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov58) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov59) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov60) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov61) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov62) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov63) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov64) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov65) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov66) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov67) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov68) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov69) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov70) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov71) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov72) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov73) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov74) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov75) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov76) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov77) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov78) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov79) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov80) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov81) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov82) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov83) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov84) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov85) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov86) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov87) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov88) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov89) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov90) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov91) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov92) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov93) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov94) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov95) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov96) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov97) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov98) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov99) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov100) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov101) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov102) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov103) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov104) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov105) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov106) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov107) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov108) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov109) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov110) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov111) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov112) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov113) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov114) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov115) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov116) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov117) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov118) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov119) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov120) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov121) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov122) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov123) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov124) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov125) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov126) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov127) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov128) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov129) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov130) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov131) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov132) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov133) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov134) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov135) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov136) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov137) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov138) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov139) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov140) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov141) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov142) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov143) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov144) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov145) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov146) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov147) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov148) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov149) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov150) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov151) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov152) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov153) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov154) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov155) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov156) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov157) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov158) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov159) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov160) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov161) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov162) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov163) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov164) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov165) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov166) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov167) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov168) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov169) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov170) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov171) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov172) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov173) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov174) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov175) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov176) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov177) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov178) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov179) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov180) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov181) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov182) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov183) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov184) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov185) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov186) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov187) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov188) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov189) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov190) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov191) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov192) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov193) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov194) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov195) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov196) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov197) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov198) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov199) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov200) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov201) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov202) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov203) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov204) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov205) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov206) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov207) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov208) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov209) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov210) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov211) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov212) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov213) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov214) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov215) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov216) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov217) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov218) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov219) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov220) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov221) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov222) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov223) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov224) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov225) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov226) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov227) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov228) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov229) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov230) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov231) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov232) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov233) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov234) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov235) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov236) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov237) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov238) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov239) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov240) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov241) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov242) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov243) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov244) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov245) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov246) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov247) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov248) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov249) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov250) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov251) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov252) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov253) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov254) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov255) -PUBLIC FN_PREFIX(CryptonightR_instruction_mov256) - -#include "CryptonightWOW_template.inc" -#include "CryptonightR_template.inc" -#include "CryptonightWOW_soft_aes_template.inc" -#include "CryptonightR_soft_aes_template.inc" - -FN_PREFIX(CryptonightR_instruction0): - imul rbx, rbx -FN_PREFIX(CryptonightR_instruction1): - imul rbx, rbx -FN_PREFIX(CryptonightR_instruction2): - imul rbx, rbx -FN_PREFIX(CryptonightR_instruction3): - add rbx, r9 - add rbx, 2147483647 -FN_PREFIX(CryptonightR_instruction4): - sub rbx, r9 -FN_PREFIX(CryptonightR_instruction5): - ror ebx, cl -FN_PREFIX(CryptonightR_instruction6): - rol ebx, cl -FN_PREFIX(CryptonightR_instruction7): - xor rbx, r9 -FN_PREFIX(CryptonightR_instruction8): - imul rsi, rbx -FN_PREFIX(CryptonightR_instruction9): - imul rsi, rbx -FN_PREFIX(CryptonightR_instruction10): - imul rsi, rbx -FN_PREFIX(CryptonightR_instruction11): - add rsi, rbx - add rsi, 2147483647 -FN_PREFIX(CryptonightR_instruction12): - sub rsi, rbx -FN_PREFIX(CryptonightR_instruction13): - ror esi, cl -FN_PREFIX(CryptonightR_instruction14): - rol esi, cl -FN_PREFIX(CryptonightR_instruction15): - xor rsi, rbx -FN_PREFIX(CryptonightR_instruction16): - imul rdi, rbx -FN_PREFIX(CryptonightR_instruction17): - imul rdi, rbx -FN_PREFIX(CryptonightR_instruction18): - imul rdi, rbx -FN_PREFIX(CryptonightR_instruction19): - add rdi, rbx - add rdi, 2147483647 -FN_PREFIX(CryptonightR_instruction20): - sub rdi, rbx -FN_PREFIX(CryptonightR_instruction21): - ror edi, cl -FN_PREFIX(CryptonightR_instruction22): - rol edi, cl -FN_PREFIX(CryptonightR_instruction23): - xor rdi, rbx -FN_PREFIX(CryptonightR_instruction24): - imul rbp, rbx -FN_PREFIX(CryptonightR_instruction25): - imul rbp, rbx -FN_PREFIX(CryptonightR_instruction26): - imul rbp, rbx -FN_PREFIX(CryptonightR_instruction27): - add rbp, rbx - add rbp, 2147483647 -FN_PREFIX(CryptonightR_instruction28): - sub rbp, rbx -FN_PREFIX(CryptonightR_instruction29): - ror ebp, cl -FN_PREFIX(CryptonightR_instruction30): - rol ebp, cl -FN_PREFIX(CryptonightR_instruction31): - xor rbp, rbx -FN_PREFIX(CryptonightR_instruction32): - imul rbx, rsi -FN_PREFIX(CryptonightR_instruction33): - imul rbx, rsi -FN_PREFIX(CryptonightR_instruction34): - imul rbx, rsi -FN_PREFIX(CryptonightR_instruction35): - add rbx, rsi - add rbx, 2147483647 -FN_PREFIX(CryptonightR_instruction36): - sub rbx, rsi -FN_PREFIX(CryptonightR_instruction37): - ror ebx, cl -FN_PREFIX(CryptonightR_instruction38): - rol ebx, cl -FN_PREFIX(CryptonightR_instruction39): - xor rbx, rsi -FN_PREFIX(CryptonightR_instruction40): - imul rsi, rsi -FN_PREFIX(CryptonightR_instruction41): - imul rsi, rsi -FN_PREFIX(CryptonightR_instruction42): - imul rsi, rsi -FN_PREFIX(CryptonightR_instruction43): - add rsi, r9 - add rsi, 2147483647 -FN_PREFIX(CryptonightR_instruction44): - sub rsi, r9 -FN_PREFIX(CryptonightR_instruction45): - ror esi, cl -FN_PREFIX(CryptonightR_instruction46): - rol esi, cl -FN_PREFIX(CryptonightR_instruction47): - xor rsi, r9 -FN_PREFIX(CryptonightR_instruction48): - imul rdi, rsi -FN_PREFIX(CryptonightR_instruction49): - imul rdi, rsi -FN_PREFIX(CryptonightR_instruction50): - imul rdi, rsi -FN_PREFIX(CryptonightR_instruction51): - add rdi, rsi - add rdi, 2147483647 -FN_PREFIX(CryptonightR_instruction52): - sub rdi, rsi -FN_PREFIX(CryptonightR_instruction53): - ror edi, cl -FN_PREFIX(CryptonightR_instruction54): - rol edi, cl -FN_PREFIX(CryptonightR_instruction55): - xor rdi, rsi -FN_PREFIX(CryptonightR_instruction56): - imul rbp, rsi -FN_PREFIX(CryptonightR_instruction57): - imul rbp, rsi -FN_PREFIX(CryptonightR_instruction58): - imul rbp, rsi -FN_PREFIX(CryptonightR_instruction59): - add rbp, rsi - add rbp, 2147483647 -FN_PREFIX(CryptonightR_instruction60): - sub rbp, rsi -FN_PREFIX(CryptonightR_instruction61): - ror ebp, cl -FN_PREFIX(CryptonightR_instruction62): - rol ebp, cl -FN_PREFIX(CryptonightR_instruction63): - xor rbp, rsi -FN_PREFIX(CryptonightR_instruction64): - imul rbx, rdi -FN_PREFIX(CryptonightR_instruction65): - imul rbx, rdi -FN_PREFIX(CryptonightR_instruction66): - imul rbx, rdi -FN_PREFIX(CryptonightR_instruction67): - add rbx, rdi - add rbx, 2147483647 -FN_PREFIX(CryptonightR_instruction68): - sub rbx, rdi -FN_PREFIX(CryptonightR_instruction69): - ror ebx, cl -FN_PREFIX(CryptonightR_instruction70): - rol ebx, cl -FN_PREFIX(CryptonightR_instruction71): - xor rbx, rdi -FN_PREFIX(CryptonightR_instruction72): - imul rsi, rdi -FN_PREFIX(CryptonightR_instruction73): - imul rsi, rdi -FN_PREFIX(CryptonightR_instruction74): - imul rsi, rdi -FN_PREFIX(CryptonightR_instruction75): - add rsi, rdi - add rsi, 2147483647 -FN_PREFIX(CryptonightR_instruction76): - sub rsi, rdi -FN_PREFIX(CryptonightR_instruction77): - ror esi, cl -FN_PREFIX(CryptonightR_instruction78): - rol esi, cl -FN_PREFIX(CryptonightR_instruction79): - xor rsi, rdi -FN_PREFIX(CryptonightR_instruction80): - imul rdi, rdi -FN_PREFIX(CryptonightR_instruction81): - imul rdi, rdi -FN_PREFIX(CryptonightR_instruction82): - imul rdi, rdi -FN_PREFIX(CryptonightR_instruction83): - add rdi, r9 - add rdi, 2147483647 -FN_PREFIX(CryptonightR_instruction84): - sub rdi, r9 -FN_PREFIX(CryptonightR_instruction85): - ror edi, cl -FN_PREFIX(CryptonightR_instruction86): - rol edi, cl -FN_PREFIX(CryptonightR_instruction87): - xor rdi, r9 -FN_PREFIX(CryptonightR_instruction88): - imul rbp, rdi -FN_PREFIX(CryptonightR_instruction89): - imul rbp, rdi -FN_PREFIX(CryptonightR_instruction90): - imul rbp, rdi -FN_PREFIX(CryptonightR_instruction91): - add rbp, rdi - add rbp, 2147483647 -FN_PREFIX(CryptonightR_instruction92): - sub rbp, rdi -FN_PREFIX(CryptonightR_instruction93): - ror ebp, cl -FN_PREFIX(CryptonightR_instruction94): - rol ebp, cl -FN_PREFIX(CryptonightR_instruction95): - xor rbp, rdi -FN_PREFIX(CryptonightR_instruction96): - imul rbx, rbp -FN_PREFIX(CryptonightR_instruction97): - imul rbx, rbp -FN_PREFIX(CryptonightR_instruction98): - imul rbx, rbp -FN_PREFIX(CryptonightR_instruction99): - add rbx, rbp - add rbx, 2147483647 -FN_PREFIX(CryptonightR_instruction100): - sub rbx, rbp -FN_PREFIX(CryptonightR_instruction101): - ror ebx, cl -FN_PREFIX(CryptonightR_instruction102): - rol ebx, cl -FN_PREFIX(CryptonightR_instruction103): - xor rbx, rbp -FN_PREFIX(CryptonightR_instruction104): - imul rsi, rbp -FN_PREFIX(CryptonightR_instruction105): - imul rsi, rbp -FN_PREFIX(CryptonightR_instruction106): - imul rsi, rbp -FN_PREFIX(CryptonightR_instruction107): - add rsi, rbp - add rsi, 2147483647 -FN_PREFIX(CryptonightR_instruction108): - sub rsi, rbp -FN_PREFIX(CryptonightR_instruction109): - ror esi, cl -FN_PREFIX(CryptonightR_instruction110): - rol esi, cl -FN_PREFIX(CryptonightR_instruction111): - xor rsi, rbp -FN_PREFIX(CryptonightR_instruction112): - imul rdi, rbp -FN_PREFIX(CryptonightR_instruction113): - imul rdi, rbp -FN_PREFIX(CryptonightR_instruction114): - imul rdi, rbp -FN_PREFIX(CryptonightR_instruction115): - add rdi, rbp - add rdi, 2147483647 -FN_PREFIX(CryptonightR_instruction116): - sub rdi, rbp -FN_PREFIX(CryptonightR_instruction117): - ror edi, cl -FN_PREFIX(CryptonightR_instruction118): - rol edi, cl -FN_PREFIX(CryptonightR_instruction119): - xor rdi, rbp -FN_PREFIX(CryptonightR_instruction120): - imul rbp, rbp -FN_PREFIX(CryptonightR_instruction121): - imul rbp, rbp -FN_PREFIX(CryptonightR_instruction122): - imul rbp, rbp -FN_PREFIX(CryptonightR_instruction123): - add rbp, r9 - add rbp, 2147483647 -FN_PREFIX(CryptonightR_instruction124): - sub rbp, r9 -FN_PREFIX(CryptonightR_instruction125): - ror ebp, cl -FN_PREFIX(CryptonightR_instruction126): - rol ebp, cl -FN_PREFIX(CryptonightR_instruction127): - xor rbp, r9 -FN_PREFIX(CryptonightR_instruction128): - imul rbx, rsp -FN_PREFIX(CryptonightR_instruction129): - imul rbx, rsp -FN_PREFIX(CryptonightR_instruction130): - imul rbx, rsp -FN_PREFIX(CryptonightR_instruction131): - add rbx, rsp - add rbx, 2147483647 -FN_PREFIX(CryptonightR_instruction132): - sub rbx, rsp -FN_PREFIX(CryptonightR_instruction133): - ror ebx, cl -FN_PREFIX(CryptonightR_instruction134): - rol ebx, cl -FN_PREFIX(CryptonightR_instruction135): - xor rbx, rsp -FN_PREFIX(CryptonightR_instruction136): - imul rsi, rsp -FN_PREFIX(CryptonightR_instruction137): - imul rsi, rsp -FN_PREFIX(CryptonightR_instruction138): - imul rsi, rsp -FN_PREFIX(CryptonightR_instruction139): - add rsi, rsp - add rsi, 2147483647 -FN_PREFIX(CryptonightR_instruction140): - sub rsi, rsp -FN_PREFIX(CryptonightR_instruction141): - ror esi, cl -FN_PREFIX(CryptonightR_instruction142): - rol esi, cl -FN_PREFIX(CryptonightR_instruction143): - xor rsi, rsp -FN_PREFIX(CryptonightR_instruction144): - imul rdi, rsp -FN_PREFIX(CryptonightR_instruction145): - imul rdi, rsp -FN_PREFIX(CryptonightR_instruction146): - imul rdi, rsp -FN_PREFIX(CryptonightR_instruction147): - add rdi, rsp - add rdi, 2147483647 -FN_PREFIX(CryptonightR_instruction148): - sub rdi, rsp -FN_PREFIX(CryptonightR_instruction149): - ror edi, cl -FN_PREFIX(CryptonightR_instruction150): - rol edi, cl -FN_PREFIX(CryptonightR_instruction151): - xor rdi, rsp -FN_PREFIX(CryptonightR_instruction152): - imul rbp, rsp -FN_PREFIX(CryptonightR_instruction153): - imul rbp, rsp -FN_PREFIX(CryptonightR_instruction154): - imul rbp, rsp -FN_PREFIX(CryptonightR_instruction155): - add rbp, rsp - add rbp, 2147483647 -FN_PREFIX(CryptonightR_instruction156): - sub rbp, rsp -FN_PREFIX(CryptonightR_instruction157): - ror ebp, cl -FN_PREFIX(CryptonightR_instruction158): - rol ebp, cl -FN_PREFIX(CryptonightR_instruction159): - xor rbp, rsp -FN_PREFIX(CryptonightR_instruction160): - imul rbx, r15 -FN_PREFIX(CryptonightR_instruction161): - imul rbx, r15 -FN_PREFIX(CryptonightR_instruction162): - imul rbx, r15 -FN_PREFIX(CryptonightR_instruction163): - add rbx, r15 - add rbx, 2147483647 -FN_PREFIX(CryptonightR_instruction164): - sub rbx, r15 -FN_PREFIX(CryptonightR_instruction165): - ror ebx, cl -FN_PREFIX(CryptonightR_instruction166): - rol ebx, cl -FN_PREFIX(CryptonightR_instruction167): - xor rbx, r15 -FN_PREFIX(CryptonightR_instruction168): - imul rsi, r15 -FN_PREFIX(CryptonightR_instruction169): - imul rsi, r15 -FN_PREFIX(CryptonightR_instruction170): - imul rsi, r15 -FN_PREFIX(CryptonightR_instruction171): - add rsi, r15 - add rsi, 2147483647 -FN_PREFIX(CryptonightR_instruction172): - sub rsi, r15 -FN_PREFIX(CryptonightR_instruction173): - ror esi, cl -FN_PREFIX(CryptonightR_instruction174): - rol esi, cl -FN_PREFIX(CryptonightR_instruction175): - xor rsi, r15 -FN_PREFIX(CryptonightR_instruction176): - imul rdi, r15 -FN_PREFIX(CryptonightR_instruction177): - imul rdi, r15 -FN_PREFIX(CryptonightR_instruction178): - imul rdi, r15 -FN_PREFIX(CryptonightR_instruction179): - add rdi, r15 - add rdi, 2147483647 -FN_PREFIX(CryptonightR_instruction180): - sub rdi, r15 -FN_PREFIX(CryptonightR_instruction181): - ror edi, cl -FN_PREFIX(CryptonightR_instruction182): - rol edi, cl -FN_PREFIX(CryptonightR_instruction183): - xor rdi, r15 -FN_PREFIX(CryptonightR_instruction184): - imul rbp, r15 -FN_PREFIX(CryptonightR_instruction185): - imul rbp, r15 -FN_PREFIX(CryptonightR_instruction186): - imul rbp, r15 -FN_PREFIX(CryptonightR_instruction187): - add rbp, r15 - add rbp, 2147483647 -FN_PREFIX(CryptonightR_instruction188): - sub rbp, r15 -FN_PREFIX(CryptonightR_instruction189): - ror ebp, cl -FN_PREFIX(CryptonightR_instruction190): - rol ebp, cl -FN_PREFIX(CryptonightR_instruction191): - xor rbp, r15 -FN_PREFIX(CryptonightR_instruction192): - imul rbx, rax -FN_PREFIX(CryptonightR_instruction193): - imul rbx, rax -FN_PREFIX(CryptonightR_instruction194): - imul rbx, rax -FN_PREFIX(CryptonightR_instruction195): - add rbx, rax - add rbx, 2147483647 -FN_PREFIX(CryptonightR_instruction196): - sub rbx, rax -FN_PREFIX(CryptonightR_instruction197): - ror ebx, cl -FN_PREFIX(CryptonightR_instruction198): - rol ebx, cl -FN_PREFIX(CryptonightR_instruction199): - xor rbx, rax -FN_PREFIX(CryptonightR_instruction200): - imul rsi, rax -FN_PREFIX(CryptonightR_instruction201): - imul rsi, rax -FN_PREFIX(CryptonightR_instruction202): - imul rsi, rax -FN_PREFIX(CryptonightR_instruction203): - add rsi, rax - add rsi, 2147483647 -FN_PREFIX(CryptonightR_instruction204): - sub rsi, rax -FN_PREFIX(CryptonightR_instruction205): - ror esi, cl -FN_PREFIX(CryptonightR_instruction206): - rol esi, cl -FN_PREFIX(CryptonightR_instruction207): - xor rsi, rax -FN_PREFIX(CryptonightR_instruction208): - imul rdi, rax -FN_PREFIX(CryptonightR_instruction209): - imul rdi, rax -FN_PREFIX(CryptonightR_instruction210): - imul rdi, rax -FN_PREFIX(CryptonightR_instruction211): - add rdi, rax - add rdi, 2147483647 -FN_PREFIX(CryptonightR_instruction212): - sub rdi, rax -FN_PREFIX(CryptonightR_instruction213): - ror edi, cl -FN_PREFIX(CryptonightR_instruction214): - rol edi, cl -FN_PREFIX(CryptonightR_instruction215): - xor rdi, rax -FN_PREFIX(CryptonightR_instruction216): - imul rbp, rax -FN_PREFIX(CryptonightR_instruction217): - imul rbp, rax -FN_PREFIX(CryptonightR_instruction218): - imul rbp, rax -FN_PREFIX(CryptonightR_instruction219): - add rbp, rax - add rbp, 2147483647 -FN_PREFIX(CryptonightR_instruction220): - sub rbp, rax -FN_PREFIX(CryptonightR_instruction221): - ror ebp, cl -FN_PREFIX(CryptonightR_instruction222): - rol ebp, cl -FN_PREFIX(CryptonightR_instruction223): - xor rbp, rax -FN_PREFIX(CryptonightR_instruction224): - imul rbx, rdx -FN_PREFIX(CryptonightR_instruction225): - imul rbx, rdx -FN_PREFIX(CryptonightR_instruction226): - imul rbx, rdx -FN_PREFIX(CryptonightR_instruction227): - add rbx, rdx - add rbx, 2147483647 -FN_PREFIX(CryptonightR_instruction228): - sub rbx, rdx -FN_PREFIX(CryptonightR_instruction229): - ror ebx, cl -FN_PREFIX(CryptonightR_instruction230): - rol ebx, cl -FN_PREFIX(CryptonightR_instruction231): - xor rbx, rdx -FN_PREFIX(CryptonightR_instruction232): - imul rsi, rdx -FN_PREFIX(CryptonightR_instruction233): - imul rsi, rdx -FN_PREFIX(CryptonightR_instruction234): - imul rsi, rdx -FN_PREFIX(CryptonightR_instruction235): - add rsi, rdx - add rsi, 2147483647 -FN_PREFIX(CryptonightR_instruction236): - sub rsi, rdx -FN_PREFIX(CryptonightR_instruction237): - ror esi, cl -FN_PREFIX(CryptonightR_instruction238): - rol esi, cl -FN_PREFIX(CryptonightR_instruction239): - xor rsi, rdx -FN_PREFIX(CryptonightR_instruction240): - imul rdi, rdx -FN_PREFIX(CryptonightR_instruction241): - imul rdi, rdx -FN_PREFIX(CryptonightR_instruction242): - imul rdi, rdx -FN_PREFIX(CryptonightR_instruction243): - add rdi, rdx - add rdi, 2147483647 -FN_PREFIX(CryptonightR_instruction244): - sub rdi, rdx -FN_PREFIX(CryptonightR_instruction245): - ror edi, cl -FN_PREFIX(CryptonightR_instruction246): - rol edi, cl -FN_PREFIX(CryptonightR_instruction247): - xor rdi, rdx -FN_PREFIX(CryptonightR_instruction248): - imul rbp, rdx -FN_PREFIX(CryptonightR_instruction249): - imul rbp, rdx -FN_PREFIX(CryptonightR_instruction250): - imul rbp, rdx -FN_PREFIX(CryptonightR_instruction251): - add rbp, rdx - add rbp, 2147483647 -FN_PREFIX(CryptonightR_instruction252): - sub rbp, rdx -FN_PREFIX(CryptonightR_instruction253): - ror ebp, cl -FN_PREFIX(CryptonightR_instruction254): - rol ebp, cl -FN_PREFIX(CryptonightR_instruction255): - xor rbp, rdx -FN_PREFIX(CryptonightR_instruction256): - imul rbx, rbx -FN_PREFIX(CryptonightR_instruction_mov0): - -FN_PREFIX(CryptonightR_instruction_mov1): - -FN_PREFIX(CryptonightR_instruction_mov2): - -FN_PREFIX(CryptonightR_instruction_mov3): - -FN_PREFIX(CryptonightR_instruction_mov4): - -FN_PREFIX(CryptonightR_instruction_mov5): - mov rcx, rbx -FN_PREFIX(CryptonightR_instruction_mov6): - mov rcx, rbx -FN_PREFIX(CryptonightR_instruction_mov7): - -FN_PREFIX(CryptonightR_instruction_mov8): - -FN_PREFIX(CryptonightR_instruction_mov9): - -FN_PREFIX(CryptonightR_instruction_mov10): - -FN_PREFIX(CryptonightR_instruction_mov11): - -FN_PREFIX(CryptonightR_instruction_mov12): - -FN_PREFIX(CryptonightR_instruction_mov13): - mov rcx, rbx -FN_PREFIX(CryptonightR_instruction_mov14): - mov rcx, rbx -FN_PREFIX(CryptonightR_instruction_mov15): - -FN_PREFIX(CryptonightR_instruction_mov16): - -FN_PREFIX(CryptonightR_instruction_mov17): - -FN_PREFIX(CryptonightR_instruction_mov18): - -FN_PREFIX(CryptonightR_instruction_mov19): - -FN_PREFIX(CryptonightR_instruction_mov20): - -FN_PREFIX(CryptonightR_instruction_mov21): - mov rcx, rbx -FN_PREFIX(CryptonightR_instruction_mov22): - mov rcx, rbx -FN_PREFIX(CryptonightR_instruction_mov23): - -FN_PREFIX(CryptonightR_instruction_mov24): - -FN_PREFIX(CryptonightR_instruction_mov25): - -FN_PREFIX(CryptonightR_instruction_mov26): - -FN_PREFIX(CryptonightR_instruction_mov27): - -FN_PREFIX(CryptonightR_instruction_mov28): - -FN_PREFIX(CryptonightR_instruction_mov29): - mov rcx, rbx -FN_PREFIX(CryptonightR_instruction_mov30): - mov rcx, rbx -FN_PREFIX(CryptonightR_instruction_mov31): - -FN_PREFIX(CryptonightR_instruction_mov32): - -FN_PREFIX(CryptonightR_instruction_mov33): - -FN_PREFIX(CryptonightR_instruction_mov34): - -FN_PREFIX(CryptonightR_instruction_mov35): - -FN_PREFIX(CryptonightR_instruction_mov36): - -FN_PREFIX(CryptonightR_instruction_mov37): - mov rcx, rsi -FN_PREFIX(CryptonightR_instruction_mov38): - mov rcx, rsi -FN_PREFIX(CryptonightR_instruction_mov39): - -FN_PREFIX(CryptonightR_instruction_mov40): - -FN_PREFIX(CryptonightR_instruction_mov41): - -FN_PREFIX(CryptonightR_instruction_mov42): - -FN_PREFIX(CryptonightR_instruction_mov43): - -FN_PREFIX(CryptonightR_instruction_mov44): - -FN_PREFIX(CryptonightR_instruction_mov45): - mov rcx, rsi -FN_PREFIX(CryptonightR_instruction_mov46): - mov rcx, rsi -FN_PREFIX(CryptonightR_instruction_mov47): - -FN_PREFIX(CryptonightR_instruction_mov48): - -FN_PREFIX(CryptonightR_instruction_mov49): - -FN_PREFIX(CryptonightR_instruction_mov50): - -FN_PREFIX(CryptonightR_instruction_mov51): - -FN_PREFIX(CryptonightR_instruction_mov52): - -FN_PREFIX(CryptonightR_instruction_mov53): - mov rcx, rsi -FN_PREFIX(CryptonightR_instruction_mov54): - mov rcx, rsi -FN_PREFIX(CryptonightR_instruction_mov55): - -FN_PREFIX(CryptonightR_instruction_mov56): - -FN_PREFIX(CryptonightR_instruction_mov57): - -FN_PREFIX(CryptonightR_instruction_mov58): - -FN_PREFIX(CryptonightR_instruction_mov59): - -FN_PREFIX(CryptonightR_instruction_mov60): - -FN_PREFIX(CryptonightR_instruction_mov61): - mov rcx, rsi -FN_PREFIX(CryptonightR_instruction_mov62): - mov rcx, rsi -FN_PREFIX(CryptonightR_instruction_mov63): - -FN_PREFIX(CryptonightR_instruction_mov64): - -FN_PREFIX(CryptonightR_instruction_mov65): - -FN_PREFIX(CryptonightR_instruction_mov66): - -FN_PREFIX(CryptonightR_instruction_mov67): - -FN_PREFIX(CryptonightR_instruction_mov68): - -FN_PREFIX(CryptonightR_instruction_mov69): - mov rcx, rdi -FN_PREFIX(CryptonightR_instruction_mov70): - mov rcx, rdi -FN_PREFIX(CryptonightR_instruction_mov71): - -FN_PREFIX(CryptonightR_instruction_mov72): - -FN_PREFIX(CryptonightR_instruction_mov73): - -FN_PREFIX(CryptonightR_instruction_mov74): - -FN_PREFIX(CryptonightR_instruction_mov75): - -FN_PREFIX(CryptonightR_instruction_mov76): - -FN_PREFIX(CryptonightR_instruction_mov77): - mov rcx, rdi -FN_PREFIX(CryptonightR_instruction_mov78): - mov rcx, rdi -FN_PREFIX(CryptonightR_instruction_mov79): - -FN_PREFIX(CryptonightR_instruction_mov80): - -FN_PREFIX(CryptonightR_instruction_mov81): - -FN_PREFIX(CryptonightR_instruction_mov82): - -FN_PREFIX(CryptonightR_instruction_mov83): - -FN_PREFIX(CryptonightR_instruction_mov84): - -FN_PREFIX(CryptonightR_instruction_mov85): - mov rcx, rdi -FN_PREFIX(CryptonightR_instruction_mov86): - mov rcx, rdi -FN_PREFIX(CryptonightR_instruction_mov87): - -FN_PREFIX(CryptonightR_instruction_mov88): - -FN_PREFIX(CryptonightR_instruction_mov89): - -FN_PREFIX(CryptonightR_instruction_mov90): - -FN_PREFIX(CryptonightR_instruction_mov91): - -FN_PREFIX(CryptonightR_instruction_mov92): - -FN_PREFIX(CryptonightR_instruction_mov93): - mov rcx, rdi -FN_PREFIX(CryptonightR_instruction_mov94): - mov rcx, rdi -FN_PREFIX(CryptonightR_instruction_mov95): - -FN_PREFIX(CryptonightR_instruction_mov96): - -FN_PREFIX(CryptonightR_instruction_mov97): - -FN_PREFIX(CryptonightR_instruction_mov98): - -FN_PREFIX(CryptonightR_instruction_mov99): - -FN_PREFIX(CryptonightR_instruction_mov100): - -FN_PREFIX(CryptonightR_instruction_mov101): - mov rcx, rbp -FN_PREFIX(CryptonightR_instruction_mov102): - mov rcx, rbp -FN_PREFIX(CryptonightR_instruction_mov103): - -FN_PREFIX(CryptonightR_instruction_mov104): - -FN_PREFIX(CryptonightR_instruction_mov105): - -FN_PREFIX(CryptonightR_instruction_mov106): - -FN_PREFIX(CryptonightR_instruction_mov107): - -FN_PREFIX(CryptonightR_instruction_mov108): - -FN_PREFIX(CryptonightR_instruction_mov109): - mov rcx, rbp -FN_PREFIX(CryptonightR_instruction_mov110): - mov rcx, rbp -FN_PREFIX(CryptonightR_instruction_mov111): - -FN_PREFIX(CryptonightR_instruction_mov112): - -FN_PREFIX(CryptonightR_instruction_mov113): - -FN_PREFIX(CryptonightR_instruction_mov114): - -FN_PREFIX(CryptonightR_instruction_mov115): - -FN_PREFIX(CryptonightR_instruction_mov116): - -FN_PREFIX(CryptonightR_instruction_mov117): - mov rcx, rbp -FN_PREFIX(CryptonightR_instruction_mov118): - mov rcx, rbp -FN_PREFIX(CryptonightR_instruction_mov119): - -FN_PREFIX(CryptonightR_instruction_mov120): - -FN_PREFIX(CryptonightR_instruction_mov121): - -FN_PREFIX(CryptonightR_instruction_mov122): - -FN_PREFIX(CryptonightR_instruction_mov123): - -FN_PREFIX(CryptonightR_instruction_mov124): - -FN_PREFIX(CryptonightR_instruction_mov125): - mov rcx, rbp -FN_PREFIX(CryptonightR_instruction_mov126): - mov rcx, rbp -FN_PREFIX(CryptonightR_instruction_mov127): - -FN_PREFIX(CryptonightR_instruction_mov128): - -FN_PREFIX(CryptonightR_instruction_mov129): - -FN_PREFIX(CryptonightR_instruction_mov130): - -FN_PREFIX(CryptonightR_instruction_mov131): - -FN_PREFIX(CryptonightR_instruction_mov132): - -FN_PREFIX(CryptonightR_instruction_mov133): - mov rcx, rsp -FN_PREFIX(CryptonightR_instruction_mov134): - mov rcx, rsp -FN_PREFIX(CryptonightR_instruction_mov135): - -FN_PREFIX(CryptonightR_instruction_mov136): - -FN_PREFIX(CryptonightR_instruction_mov137): - -FN_PREFIX(CryptonightR_instruction_mov138): - -FN_PREFIX(CryptonightR_instruction_mov139): - -FN_PREFIX(CryptonightR_instruction_mov140): - -FN_PREFIX(CryptonightR_instruction_mov141): - mov rcx, rsp -FN_PREFIX(CryptonightR_instruction_mov142): - mov rcx, rsp -FN_PREFIX(CryptonightR_instruction_mov143): - -FN_PREFIX(CryptonightR_instruction_mov144): - -FN_PREFIX(CryptonightR_instruction_mov145): - -FN_PREFIX(CryptonightR_instruction_mov146): - -FN_PREFIX(CryptonightR_instruction_mov147): - -FN_PREFIX(CryptonightR_instruction_mov148): - -FN_PREFIX(CryptonightR_instruction_mov149): - mov rcx, rsp -FN_PREFIX(CryptonightR_instruction_mov150): - mov rcx, rsp -FN_PREFIX(CryptonightR_instruction_mov151): - -FN_PREFIX(CryptonightR_instruction_mov152): - -FN_PREFIX(CryptonightR_instruction_mov153): - -FN_PREFIX(CryptonightR_instruction_mov154): - -FN_PREFIX(CryptonightR_instruction_mov155): - -FN_PREFIX(CryptonightR_instruction_mov156): - -FN_PREFIX(CryptonightR_instruction_mov157): - mov rcx, rsp -FN_PREFIX(CryptonightR_instruction_mov158): - mov rcx, rsp -FN_PREFIX(CryptonightR_instruction_mov159): - -FN_PREFIX(CryptonightR_instruction_mov160): - -FN_PREFIX(CryptonightR_instruction_mov161): - -FN_PREFIX(CryptonightR_instruction_mov162): - -FN_PREFIX(CryptonightR_instruction_mov163): - -FN_PREFIX(CryptonightR_instruction_mov164): - -FN_PREFIX(CryptonightR_instruction_mov165): - mov rcx, r15 -FN_PREFIX(CryptonightR_instruction_mov166): - mov rcx, r15 -FN_PREFIX(CryptonightR_instruction_mov167): - -FN_PREFIX(CryptonightR_instruction_mov168): - -FN_PREFIX(CryptonightR_instruction_mov169): - -FN_PREFIX(CryptonightR_instruction_mov170): - -FN_PREFIX(CryptonightR_instruction_mov171): - -FN_PREFIX(CryptonightR_instruction_mov172): - -FN_PREFIX(CryptonightR_instruction_mov173): - mov rcx, r15 -FN_PREFIX(CryptonightR_instruction_mov174): - mov rcx, r15 -FN_PREFIX(CryptonightR_instruction_mov175): - -FN_PREFIX(CryptonightR_instruction_mov176): - -FN_PREFIX(CryptonightR_instruction_mov177): - -FN_PREFIX(CryptonightR_instruction_mov178): - -FN_PREFIX(CryptonightR_instruction_mov179): - -FN_PREFIX(CryptonightR_instruction_mov180): - -FN_PREFIX(CryptonightR_instruction_mov181): - mov rcx, r15 -FN_PREFIX(CryptonightR_instruction_mov182): - mov rcx, r15 -FN_PREFIX(CryptonightR_instruction_mov183): - -FN_PREFIX(CryptonightR_instruction_mov184): - -FN_PREFIX(CryptonightR_instruction_mov185): - -FN_PREFIX(CryptonightR_instruction_mov186): - -FN_PREFIX(CryptonightR_instruction_mov187): - -FN_PREFIX(CryptonightR_instruction_mov188): - -FN_PREFIX(CryptonightR_instruction_mov189): - mov rcx, r15 -FN_PREFIX(CryptonightR_instruction_mov190): - mov rcx, r15 -FN_PREFIX(CryptonightR_instruction_mov191): - -FN_PREFIX(CryptonightR_instruction_mov192): - -FN_PREFIX(CryptonightR_instruction_mov193): - -FN_PREFIX(CryptonightR_instruction_mov194): - -FN_PREFIX(CryptonightR_instruction_mov195): - -FN_PREFIX(CryptonightR_instruction_mov196): - -FN_PREFIX(CryptonightR_instruction_mov197): - mov rcx, rax -FN_PREFIX(CryptonightR_instruction_mov198): - mov rcx, rax -FN_PREFIX(CryptonightR_instruction_mov199): - -FN_PREFIX(CryptonightR_instruction_mov200): - -FN_PREFIX(CryptonightR_instruction_mov201): - -FN_PREFIX(CryptonightR_instruction_mov202): - -FN_PREFIX(CryptonightR_instruction_mov203): - -FN_PREFIX(CryptonightR_instruction_mov204): - -FN_PREFIX(CryptonightR_instruction_mov205): - mov rcx, rax -FN_PREFIX(CryptonightR_instruction_mov206): - mov rcx, rax -FN_PREFIX(CryptonightR_instruction_mov207): - -FN_PREFIX(CryptonightR_instruction_mov208): - -FN_PREFIX(CryptonightR_instruction_mov209): - -FN_PREFIX(CryptonightR_instruction_mov210): - -FN_PREFIX(CryptonightR_instruction_mov211): - -FN_PREFIX(CryptonightR_instruction_mov212): - -FN_PREFIX(CryptonightR_instruction_mov213): - mov rcx, rax -FN_PREFIX(CryptonightR_instruction_mov214): - mov rcx, rax -FN_PREFIX(CryptonightR_instruction_mov215): - -FN_PREFIX(CryptonightR_instruction_mov216): - -FN_PREFIX(CryptonightR_instruction_mov217): - -FN_PREFIX(CryptonightR_instruction_mov218): - -FN_PREFIX(CryptonightR_instruction_mov219): - -FN_PREFIX(CryptonightR_instruction_mov220): - -FN_PREFIX(CryptonightR_instruction_mov221): - mov rcx, rax -FN_PREFIX(CryptonightR_instruction_mov222): - mov rcx, rax -FN_PREFIX(CryptonightR_instruction_mov223): - -FN_PREFIX(CryptonightR_instruction_mov224): - -FN_PREFIX(CryptonightR_instruction_mov225): - -FN_PREFIX(CryptonightR_instruction_mov226): - -FN_PREFIX(CryptonightR_instruction_mov227): - -FN_PREFIX(CryptonightR_instruction_mov228): - -FN_PREFIX(CryptonightR_instruction_mov229): - mov rcx, rdx -FN_PREFIX(CryptonightR_instruction_mov230): - mov rcx, rdx -FN_PREFIX(CryptonightR_instruction_mov231): - -FN_PREFIX(CryptonightR_instruction_mov232): - -FN_PREFIX(CryptonightR_instruction_mov233): - -FN_PREFIX(CryptonightR_instruction_mov234): - -FN_PREFIX(CryptonightR_instruction_mov235): - -FN_PREFIX(CryptonightR_instruction_mov236): - -FN_PREFIX(CryptonightR_instruction_mov237): - mov rcx, rdx -FN_PREFIX(CryptonightR_instruction_mov238): - mov rcx, rdx -FN_PREFIX(CryptonightR_instruction_mov239): - -FN_PREFIX(CryptonightR_instruction_mov240): - -FN_PREFIX(CryptonightR_instruction_mov241): - -FN_PREFIX(CryptonightR_instruction_mov242): - -FN_PREFIX(CryptonightR_instruction_mov243): - -FN_PREFIX(CryptonightR_instruction_mov244): - -FN_PREFIX(CryptonightR_instruction_mov245): - mov rcx, rdx -FN_PREFIX(CryptonightR_instruction_mov246): - mov rcx, rdx -FN_PREFIX(CryptonightR_instruction_mov247): - -FN_PREFIX(CryptonightR_instruction_mov248): - -FN_PREFIX(CryptonightR_instruction_mov249): - -FN_PREFIX(CryptonightR_instruction_mov250): - -FN_PREFIX(CryptonightR_instruction_mov251): - -FN_PREFIX(CryptonightR_instruction_mov252): - -FN_PREFIX(CryptonightR_instruction_mov253): - mov rcx, rdx -FN_PREFIX(CryptonightR_instruction_mov254): - mov rcx, rdx -FN_PREFIX(CryptonightR_instruction_mov255): - -FN_PREFIX(CryptonightR_instruction_mov256): diff --git a/src/crypto/asm/win64/CryptonightR_template.inc b/src/crypto/asm/win64/CryptonightR_template.inc deleted file mode 100644 index 1dae434a2..000000000 --- a/src/crypto/asm/win64/CryptonightR_template.inc +++ /dev/null @@ -1,529 +0,0 @@ -PUBLIC FN_PREFIX(CryptonightR_template_part1) -PUBLIC FN_PREFIX(CryptonightR_template_mainloop) -PUBLIC FN_PREFIX(CryptonightR_template_part2) -PUBLIC FN_PREFIX(CryptonightR_template_part3) -PUBLIC FN_PREFIX(CryptonightR_template_end) -PUBLIC FN_PREFIX(CryptonightR_template_double_part1) -PUBLIC FN_PREFIX(CryptonightR_template_double_mainloop) -PUBLIC FN_PREFIX(CryptonightR_template_double_part2) -PUBLIC FN_PREFIX(CryptonightR_template_double_part3) -PUBLIC FN_PREFIX(CryptonightR_template_double_part4) -PUBLIC FN_PREFIX(CryptonightR_template_double_end) - -ALIGN(64) -FN_PREFIX(CryptonightR_template_part1): - mov QWORD PTR [rsp+16], rbx - mov QWORD PTR [rsp+24], rbp - mov QWORD PTR [rsp+32], rsi - push r10 - push r11 - push r12 - push r13 - push r14 - push r15 - push rdi - sub rsp, 64 - mov r12, rcx - mov r8, QWORD PTR [r12+32] - mov rdx, r12 - xor r8, QWORD PTR [r12] - mov r15, QWORD PTR [r12+40] - mov r9, r8 - xor r15, QWORD PTR [r12+8] - mov r11, QWORD PTR [r12+224] - mov r12, QWORD PTR [r12+56] - xor r12, QWORD PTR [rdx+24] - mov rax, QWORD PTR [rdx+48] - xor rax, QWORD PTR [rdx+16] - movaps XMMWORD PTR [rsp+48], xmm6 - movd xmm0, r12 - movaps XMMWORD PTR [rsp+32], xmm7 - movaps XMMWORD PTR [rsp+16], xmm8 - movaps XMMWORD PTR [rsp], xmm9 - mov r12, QWORD PTR [rdx+88] - xor r12, QWORD PTR [rdx+72] - movd xmm6, rax - mov rax, QWORD PTR [rdx+80] - xor rax, QWORD PTR [rdx+64] - punpcklqdq xmm6, xmm0 - and r9d, 2097136 - movd xmm0, r12 - movd xmm7, rax - punpcklqdq xmm7, xmm0 - mov r10d, r9d - movd xmm9, rsp - mov rsp, r8 - mov r8d, 524288 - - mov ebx, [rdx+96] - mov esi, [rdx+100] - mov edi, [rdx+104] - mov ebp, [rdx+108] - - ALIGN(64) -FN_PREFIX(CryptonightR_template_mainloop): - movdqa xmm5, XMMWORD PTR [r9+r11] - movd xmm0, r15 - movd xmm4, rsp - punpcklqdq xmm4, xmm0 - lea rdx, QWORD PTR [r9+r11] - - aesenc xmm5, xmm4 - - mov r12d, r9d - mov eax, r9d - xor r9d, 48 - xor r12d, 16 - xor eax, 32 - movdqu xmm0, XMMWORD PTR [r9+r11] - movaps xmm3, xmm0 - movdqu xmm2, XMMWORD PTR [r12+r11] - movdqu xmm1, XMMWORD PTR [rax+r11] - pxor xmm0, xmm2 - pxor xmm5, xmm1 - pxor xmm5, xmm0 - paddq xmm3, xmm7 - paddq xmm2, xmm6 - paddq xmm1, xmm4 - movdqu XMMWORD PTR [r12+r11], xmm3 - movdqu XMMWORD PTR [rax+r11], xmm2 - movdqu XMMWORD PTR [r9+r11], xmm1 - - movd r12, xmm5 - movd r10d, xmm5 - and r10d, 2097136 - - movdqa xmm0, xmm5 - pxor xmm0, xmm6 - movdqu XMMWORD PTR [rdx], xmm0 - - lea r13d, [ebx+esi] - lea edx, [edi+ebp] - shl rdx, 32 - or r13, rdx - - xor r13, QWORD PTR [r10+r11] - mov r14, QWORD PTR [r10+r11+8] - - movd eax, xmm6 - movd edx, xmm7 - pextrd r9d, xmm7, 2 - -FN_PREFIX(CryptonightR_template_part2): - mov eax, edi - mov edx, ebp - shl rdx, 32 - or rax, rdx - xor rsp, rax - - mov eax, ebx - mov edx, esi - shl rdx, 32 - or rax, rdx - xor r15, rax - - mov rax, r13 - mul r12 - - mov r9d, r10d - mov r12d, r10d - xor r9d, 16 - xor r12d, 32 - xor r10d, 48 - movdqa xmm1, XMMWORD PTR [r12+r11] - movaps xmm3, xmm1 - movdqa xmm2, XMMWORD PTR [r9+r11] - movdqa xmm0, XMMWORD PTR [r10+r11] - pxor xmm1, xmm2 - pxor xmm5, xmm0 - pxor xmm5, xmm1 - paddq xmm3, xmm4 - paddq xmm2, xmm6 - paddq xmm0, xmm7 - movdqu XMMWORD PTR [r9+r11], xmm0 - movdqu XMMWORD PTR [r12+r11], xmm2 - movdqu XMMWORD PTR [r10+r11], xmm3 - - movdqa xmm7, xmm6 - add r15, rax - add rsp, rdx - xor r10, 48 - mov QWORD PTR [r10+r11], rsp - xor rsp, r13 - mov r9d, esp - mov QWORD PTR [r10+r11+8], r15 - and r9d, 2097136 - xor r15, r14 - movdqa xmm6, xmm5 - dec r8d - jnz FN_PREFIX(CryptonightR_template_mainloop) - -FN_PREFIX(CryptonightR_template_part3): - movd rsp, xmm9 - - mov rbx, QWORD PTR [rsp+136] - mov rbp, QWORD PTR [rsp+144] - mov rsi, QWORD PTR [rsp+152] - movaps xmm6, XMMWORD PTR [rsp+48] - movaps xmm7, XMMWORD PTR [rsp+32] - movaps xmm8, XMMWORD PTR [rsp+16] - movaps xmm9, XMMWORD PTR [rsp] - add rsp, 64 - pop rdi - pop r15 - pop r14 - pop r13 - pop r12 - pop r11 - pop r10 - ret 0 -FN_PREFIX(CryptonightR_template_end): - -ALIGN(64) -FN_PREFIX(CryptonightR_template_double_part1): - mov QWORD PTR [rsp+24], rbx - push rbp - push rsi - push rdi - push r12 - push r13 - push r14 - push r15 - sub rsp, 320 - mov r14, QWORD PTR [rcx+32] - mov r8, rcx - xor r14, QWORD PTR [rcx] - mov r12, QWORD PTR [rcx+40] - mov ebx, r14d - mov rsi, QWORD PTR [rcx+224] - and ebx, 2097136 - xor r12, QWORD PTR [rcx+8] - mov rcx, QWORD PTR [rcx+56] - xor rcx, QWORD PTR [r8+24] - mov rax, QWORD PTR [r8+48] - xor rax, QWORD PTR [r8+16] - mov r15, QWORD PTR [rdx+32] - xor r15, QWORD PTR [rdx] - movd xmm0, rcx - mov rcx, QWORD PTR [r8+88] - xor rcx, QWORD PTR [r8+72] - mov r13, QWORD PTR [rdx+40] - mov rdi, QWORD PTR [rdx+224] - xor r13, QWORD PTR [rdx+8] - movaps XMMWORD PTR [rsp+160], xmm6 - movaps XMMWORD PTR [rsp+176], xmm7 - movaps XMMWORD PTR [rsp+192], xmm8 - movaps XMMWORD PTR [rsp+208], xmm9 - movaps XMMWORD PTR [rsp+224], xmm10 - movaps XMMWORD PTR [rsp+240], xmm11 - movaps XMMWORD PTR [rsp+256], xmm12 - movaps XMMWORD PTR [rsp+272], xmm13 - movaps XMMWORD PTR [rsp+288], xmm14 - movaps XMMWORD PTR [rsp+304], xmm15 - movd xmm7, rax - mov rax, QWORD PTR [r8+80] - xor rax, QWORD PTR [r8+64] - - movaps xmm1, XMMWORD PTR [rdx+96] - movaps xmm2, XMMWORD PTR [r8+96] - movaps XMMWORD PTR [rsp], xmm1 - movaps XMMWORD PTR [rsp+16], xmm2 - - mov r8d, r15d - punpcklqdq xmm7, xmm0 - movd xmm0, rcx - mov rcx, QWORD PTR [rdx+56] - xor rcx, QWORD PTR [rdx+24] - movd xmm9, rax - mov QWORD PTR [rsp+128], rsi - mov rax, QWORD PTR [rdx+48] - xor rax, QWORD PTR [rdx+16] - punpcklqdq xmm9, xmm0 - movd xmm0, rcx - mov rcx, QWORD PTR [rdx+88] - xor rcx, QWORD PTR [rdx+72] - movd xmm8, rax - mov QWORD PTR [rsp+136], rdi - mov rax, QWORD PTR [rdx+80] - xor rax, QWORD PTR [rdx+64] - punpcklqdq xmm8, xmm0 - and r8d, 2097136 - movd xmm0, rcx - mov r11d, 524288 - movd xmm10, rax - punpcklqdq xmm10, xmm0 - - movd xmm14, QWORD PTR [rsp+128] - movd xmm15, QWORD PTR [rsp+136] - - ALIGN(64) -FN_PREFIX(CryptonightR_template_double_mainloop): - movdqu xmm6, XMMWORD PTR [rbx+rsi] - movd xmm0, r12 - mov ecx, ebx - movd xmm3, r14 - punpcklqdq xmm3, xmm0 - xor ebx, 16 - aesenc xmm6, xmm3 - movd xmm4, r15 - movdqu xmm0, XMMWORD PTR [rbx+rsi] - pxor xmm6, xmm0 - xor ebx, 48 - paddq xmm0, xmm7 - movdqu xmm1, XMMWORD PTR [rbx+rsi] - pxor xmm6, xmm1 - movdqu XMMWORD PTR [rbx+rsi], xmm0 - paddq xmm1, xmm3 - xor ebx, 16 - mov eax, ebx - xor rax, 32 - movdqu xmm0, XMMWORD PTR [rbx+rsi] - pxor xmm6, xmm0 - movd rdx, xmm6 - movdqu XMMWORD PTR [rbx+rsi], xmm1 - paddq xmm0, xmm9 - movdqu XMMWORD PTR [rax+rsi], xmm0 - movdqa xmm0, xmm6 - pxor xmm0, xmm7 - movdqu XMMWORD PTR [rcx+rsi], xmm0 - mov esi, edx - movdqu xmm5, XMMWORD PTR [r8+rdi] - and esi, 2097136 - mov ecx, r8d - movd xmm0, r13 - punpcklqdq xmm4, xmm0 - xor r8d, 16 - aesenc xmm5, xmm4 - movdqu xmm0, XMMWORD PTR [r8+rdi] - pxor xmm5, xmm0 - xor r8d, 48 - paddq xmm0, xmm8 - movdqu xmm1, XMMWORD PTR [r8+rdi] - pxor xmm5, xmm1 - movdqu XMMWORD PTR [r8+rdi], xmm0 - paddq xmm1, xmm4 - xor r8d, 16 - mov eax, r8d - xor rax, 32 - movdqu xmm0, XMMWORD PTR [r8+rdi] - pxor xmm5, xmm0 - movdqu XMMWORD PTR [r8+rdi], xmm1 - paddq xmm0, xmm10 - movdqu XMMWORD PTR [rax+rdi], xmm0 - movdqa xmm0, xmm5 - pxor xmm0, xmm8 - movdqu XMMWORD PTR [rcx+rdi], xmm0 - movd rdi, xmm5 - movd rcx, xmm14 - mov ebp, edi - mov r8, QWORD PTR [rcx+rsi] - mov r10, QWORD PTR [rcx+rsi+8] - lea r9, QWORD PTR [rcx+rsi] - xor esi, 16 - - movd xmm0, rsp - movd xmm1, rsi - movd xmm2, rdi - movd xmm11, rbp - movd xmm12, r15 - movd xmm13, rdx - mov [rsp+104], rcx - mov [rsp+112], r9 - - mov ebx, DWORD PTR [rsp+16] - mov esi, DWORD PTR [rsp+20] - mov edi, DWORD PTR [rsp+24] - mov ebp, DWORD PTR [rsp+28] - - lea eax, [ebx+esi] - lea edx, [edi+ebp] - shl rdx, 32 - or rax, rdx - xor r8, rax - - movd esp, xmm3 - pextrd r15d, xmm3, 2 - movd eax, xmm7 - movd edx, xmm9 - pextrd r9d, xmm9, 2 - -FN_PREFIX(CryptonightR_template_double_part2): - - mov eax, edi - mov edx, ebp - shl rdx, 32 - or rax, rdx - xor r14, rax - - mov eax, ebx - mov edx, esi - shl rdx, 32 - or rax, rdx - xor r12, rax - - movd rsp, xmm0 - mov DWORD PTR [rsp+16], ebx - mov DWORD PTR [rsp+20], esi - mov DWORD PTR [rsp+24], edi - mov DWORD PTR [rsp+28], ebp - - movd rsi, xmm1 - movd rdi, xmm2 - movd rbp, xmm11 - movd r15, xmm12 - movd rdx, xmm13 - mov rcx, [rsp+104] - mov r9, [rsp+112] - - mov rbx, r8 - mov rax, r8 - mul rdx - and ebp, 2097136 - mov r8, rax - movdqu xmm1, XMMWORD PTR [rcx+rsi] - pxor xmm6, xmm1 - xor esi, 48 - paddq xmm1, xmm7 - movdqu xmm2, XMMWORD PTR [rsi+rcx] - pxor xmm6, xmm2 - paddq xmm2, xmm3 - movdqu XMMWORD PTR [rsi+rcx], xmm1 - xor esi, 16 - mov eax, esi - mov rsi, rcx - movdqu xmm0, XMMWORD PTR [rax+rcx] - pxor xmm6, xmm0 - movdqu XMMWORD PTR [rax+rcx], xmm2 - paddq xmm0, xmm9 - add r12, r8 - xor rax, 32 - add r14, rdx - movdqa xmm9, xmm7 - movdqa xmm7, xmm6 - movdqu XMMWORD PTR [rax+rcx], xmm0 - mov QWORD PTR [r9+8], r12 - xor r12, r10 - mov QWORD PTR [r9], r14 - movd rcx, xmm15 - xor r14, rbx - mov r10d, ebp - mov ebx, r14d - xor ebp, 16 - and ebx, 2097136 - mov r8, QWORD PTR [r10+rcx] - mov r9, QWORD PTR [r10+rcx+8] - - movd xmm0, rsp - movd xmm1, rbx - movd xmm2, rsi - movd xmm11, rdi - movd xmm12, rbp - movd xmm13, r15 - mov [rsp+104], rcx - mov [rsp+112], r9 - - mov ebx, DWORD PTR [rsp] - mov esi, DWORD PTR [rsp+4] - mov edi, DWORD PTR [rsp+8] - mov ebp, DWORD PTR [rsp+12] - - lea eax, [ebx+esi] - lea edx, [edi+ebp] - shl rdx, 32 - or rax, rdx - - xor r8, rax - movd xmm3, r8 - - movd esp, xmm4 - pextrd r15d, xmm4, 2 - movd eax, xmm8 - movd edx, xmm10 - pextrd r9d, xmm10, 2 - -FN_PREFIX(CryptonightR_template_double_part3): - - movd r15, xmm13 - - mov eax, edi - mov edx, ebp - shl rdx, 32 - or rax, rdx - xor r15, rax - - mov eax, ebx - mov edx, esi - shl rdx, 32 - or rax, rdx - xor r13, rax - - movd rsp, xmm0 - mov DWORD PTR [rsp], ebx - mov DWORD PTR [rsp+4], esi - mov DWORD PTR [rsp+8], edi - mov DWORD PTR [rsp+12], ebp - - movd rbx, xmm1 - movd rsi, xmm2 - movd rdi, xmm11 - movd rbp, xmm12 - mov rcx, [rsp+104] - mov r9, [rsp+112] - - mov rax, r8 - mul rdi - mov rdi, rcx - mov r8, rax - movdqu xmm1, XMMWORD PTR [rbp+rcx] - pxor xmm5, xmm1 - xor ebp, 48 - paddq xmm1, xmm8 - add r13, r8 - movdqu xmm2, XMMWORD PTR [rbp+rcx] - pxor xmm5, xmm2 - add r15, rdx - movdqu XMMWORD PTR [rbp+rcx], xmm1 - paddq xmm2, xmm4 - xor ebp, 16 - mov eax, ebp - xor rax, 32 - movdqu xmm0, XMMWORD PTR [rbp+rcx] - pxor xmm5, xmm0 - movdqu XMMWORD PTR [rbp+rcx], xmm2 - paddq xmm0, xmm10 - movdqu XMMWORD PTR [rax+rcx], xmm0 - movd rax, xmm3 - movdqa xmm10, xmm8 - mov QWORD PTR [r10+rcx], r15 - movdqa xmm8, xmm5 - xor r15, rax - mov QWORD PTR [r10+rcx+8], r13 - mov r8d, r15d - xor r13, r9 - and r8d, 2097136 - dec r11d - jnz FN_PREFIX(CryptonightR_template_double_mainloop) - -FN_PREFIX(CryptonightR_template_double_part4): - - mov rbx, QWORD PTR [rsp+400] - movaps xmm6, XMMWORD PTR [rsp+160] - movaps xmm7, XMMWORD PTR [rsp+176] - movaps xmm8, XMMWORD PTR [rsp+192] - movaps xmm9, XMMWORD PTR [rsp+208] - movaps xmm10, XMMWORD PTR [rsp+224] - movaps xmm11, XMMWORD PTR [rsp+240] - movaps xmm12, XMMWORD PTR [rsp+256] - movaps xmm13, XMMWORD PTR [rsp+272] - movaps xmm14, XMMWORD PTR [rsp+288] - movaps xmm15, XMMWORD PTR [rsp+304] - add rsp, 320 - pop r15 - pop r14 - pop r13 - pop r12 - pop rdi - pop rsi - pop rbp - ret 0 -FN_PREFIX(CryptonightR_template_double_end): diff --git a/src/crypto/asm/win64/CryptonightWOW_soft_aes_template.inc b/src/crypto/asm/win64/CryptonightWOW_soft_aes_template.inc deleted file mode 100644 index cc273781c..000000000 --- a/src/crypto/asm/win64/CryptonightWOW_soft_aes_template.inc +++ /dev/null @@ -1,266 +0,0 @@ -PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_part1) -PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_mainloop) -PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_part2) -PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_part3) -PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_end) - -ALIGN(64) -FN_PREFIX(CryptonightWOW_soft_aes_template_part1): - mov QWORD PTR [rsp+8], rcx - push rbx - push rbp - push rsi - push rdi - push r12 - push r13 - push r14 - push r15 - sub rsp, 232 - - mov eax, [rcx+96] - mov ebx, [rcx+100] - mov esi, [rcx+104] - mov edx, [rcx+108] - mov [rsp+144], eax - mov [rsp+148], ebx - mov [rsp+152], esi - mov [rsp+156], edx - - mov rax, QWORD PTR [rcx+48] - mov r10, rcx - xor rax, QWORD PTR [rcx+16] - mov r8, QWORD PTR [rcx+32] - xor r8, QWORD PTR [rcx] - mov r9, QWORD PTR [rcx+40] - xor r9, QWORD PTR [rcx+8] - movd xmm4, rax - mov rdx, QWORD PTR [rcx+56] - xor rdx, QWORD PTR [rcx+24] - mov r11, QWORD PTR [rcx+224] - mov rcx, QWORD PTR [rcx+88] - xor rcx, QWORD PTR [r10+72] - mov rax, QWORD PTR [r10+80] - movd xmm0, rdx - xor rax, QWORD PTR [r10+64] - - movaps XMMWORD PTR [rsp+16], xmm6 - movaps XMMWORD PTR [rsp+32], xmm7 - movaps XMMWORD PTR [rsp+48], xmm8 - movaps XMMWORD PTR [rsp+64], xmm9 - movaps XMMWORD PTR [rsp+80], xmm10 - movaps XMMWORD PTR [rsp+96], xmm11 - movaps XMMWORD PTR [rsp+112], xmm12 - movaps XMMWORD PTR [rsp+128], xmm13 - - movd xmm5, rax - - mov rax, r8 - punpcklqdq xmm4, xmm0 - and eax, 2097136 - movd xmm10, QWORD PTR [r10+96] - movd xmm0, rcx - mov rcx, QWORD PTR [r10+104] - xorps xmm9, xmm9 - mov QWORD PTR [rsp+328], rax - movd xmm12, r11 - mov QWORD PTR [rsp+320], r9 - punpcklqdq xmm5, xmm0 - movd xmm13, rcx - mov r12d, 524288 - - ALIGN(64) -FN_PREFIX(CryptonightWOW_soft_aes_template_mainloop): - movd xmm11, r12d - mov r12, QWORD PTR [r10+272] - lea r13, QWORD PTR [rax+r11] - mov esi, DWORD PTR [r13] - movd xmm0, r9 - mov r10d, DWORD PTR [r13+4] - movd xmm7, r8 - mov ebp, DWORD PTR [r13+12] - mov r14d, DWORD PTR [r13+8] - mov rdx, QWORD PTR [rsp+328] - movzx ecx, sil - shr esi, 8 - punpcklqdq xmm7, xmm0 - mov r15d, DWORD PTR [r12+rcx*4] - movzx ecx, r10b - shr r10d, 8 - mov edi, DWORD PTR [r12+rcx*4] - movzx ecx, r14b - shr r14d, 8 - mov ebx, DWORD PTR [r12+rcx*4] - movzx ecx, bpl - shr ebp, 8 - mov r9d, DWORD PTR [r12+rcx*4] - movzx ecx, r10b - shr r10d, 8 - xor r15d, DWORD PTR [r12+rcx*4+1024] - movzx ecx, r14b - shr r14d, 8 - mov eax, r14d - shr eax, 8 - xor edi, DWORD PTR [r12+rcx*4+1024] - add eax, 256 - movzx ecx, bpl - shr ebp, 8 - xor ebx, DWORD PTR [r12+rcx*4+1024] - movzx ecx, sil - shr esi, 8 - xor r9d, DWORD PTR [r12+rcx*4+1024] - add r12, 2048 - movzx ecx, r10b - shr r10d, 8 - add r10d, 256 - mov r11d, DWORD PTR [r12+rax*4] - xor r11d, DWORD PTR [r12+rcx*4] - xor r11d, r9d - movzx ecx, sil - mov r10d, DWORD PTR [r12+r10*4] - shr esi, 8 - add esi, 256 - xor r10d, DWORD PTR [r12+rcx*4] - movzx ecx, bpl - xor r10d, ebx - shr ebp, 8 - movd xmm1, r11d - add ebp, 256 - movd r11, xmm12 - mov r9d, DWORD PTR [r12+rcx*4] - xor r9d, DWORD PTR [r12+rsi*4] - mov eax, DWORD PTR [r12+rbp*4] - xor r9d, edi - movzx ecx, r14b - movd xmm0, r10d - movd xmm2, r9d - xor eax, DWORD PTR [r12+rcx*4] - mov rcx, rdx - xor eax, r15d - punpckldq xmm2, xmm1 - xor rcx, 16 - movd xmm6, eax - mov rax, rdx - punpckldq xmm6, xmm0 - xor rax, 32 - punpckldq xmm6, xmm2 - xor rdx, 48 - movdqu xmm2, XMMWORD PTR [rcx+r11] - pxor xmm6, xmm7 - paddq xmm2, xmm4 - movdqu xmm1, XMMWORD PTR [rax+r11] - movdqu xmm0, XMMWORD PTR [rdx+r11] - paddq xmm0, xmm5 - movdqu XMMWORD PTR [rcx+r11], xmm0 - movdqu XMMWORD PTR [rax+r11], xmm2 - movd rcx, xmm13 - paddq xmm1, xmm7 - movdqu XMMWORD PTR [rdx+r11], xmm1 - movd rdi, xmm6 - mov r10, rdi - and r10d, 2097136 - movdqa xmm0, xmm6 - pxor xmm0, xmm4 - movdqu XMMWORD PTR [r13], xmm0 - - mov ebx, [rsp+144] - mov ebp, [rsp+152] - add ebx, [rsp+148] - add ebp, [rsp+156] - shl rbp, 32 - or rbx, rbp - - xor rbx, QWORD PTR [r10+r11] - lea r14, QWORD PTR [r10+r11] - mov rbp, QWORD PTR [r14+8] - - mov [rsp+160], rbx - mov [rsp+168], rdi - mov [rsp+176], rbp - mov [rsp+184], r10 - mov r10, rsp - - mov ebx, [rsp+144] - mov esi, [rsp+148] - mov edi, [rsp+152] - mov ebp, [rsp+156] - - movd esp, xmm7 - movaps xmm0, xmm7 - psrldq xmm0, 8 - movd r15d, xmm0 - movd eax, xmm4 - movd edx, xmm5 - -FN_PREFIX(CryptonightWOW_soft_aes_template_part2): - mov rsp, r10 - mov [rsp+144], ebx - mov [rsp+148], esi - mov [rsp+152], edi - mov [rsp+156], ebp - - mov rbx, [rsp+160] - mov rdi, [rsp+168] - mov rbp, [rsp+176] - mov r10, [rsp+184] - - mov r9, r10 - xor r9, 16 - mov rcx, r10 - xor rcx, 32 - xor r10, 48 - mov rax, rbx - mul rdi - movdqu xmm2, XMMWORD PTR [r9+r11] - movdqu xmm1, XMMWORD PTR [rcx+r11] - paddq xmm1, xmm7 - movd xmm0, rax - movd xmm3, rdx - xor rax, QWORD PTR [r11+rcx+8] - xor rdx, QWORD PTR [rcx+r11] - punpcklqdq xmm3, xmm0 - add r8, rdx - movdqu xmm0, XMMWORD PTR [r10+r11] - pxor xmm2, xmm3 - paddq xmm0, xmm5 - paddq xmm2, xmm4 - movdqu XMMWORD PTR [r9+r11], xmm0 - movdqa xmm5, xmm4 - mov r9, QWORD PTR [rsp+320] - movdqa xmm4, xmm6 - add r9, rax - movdqu XMMWORD PTR [rcx+r11], xmm2 - movdqu XMMWORD PTR [r10+r11], xmm1 - mov r10, QWORD PTR [rsp+304] - movd r12d, xmm11 - mov QWORD PTR [r14], r8 - xor r8, rbx - mov rax, r8 - mov QWORD PTR [r14+8], r9 - and eax, 2097136 - xor r9, rbp - mov QWORD PTR [rsp+320], r9 - mov QWORD PTR [rsp+328], rax - sub r12d, 1 - jne FN_PREFIX(CryptonightWOW_soft_aes_template_mainloop) - -FN_PREFIX(CryptonightWOW_soft_aes_template_part3): - movaps xmm6, XMMWORD PTR [rsp+16] - movaps xmm7, XMMWORD PTR [rsp+32] - movaps xmm8, XMMWORD PTR [rsp+48] - movaps xmm9, XMMWORD PTR [rsp+64] - movaps xmm10, XMMWORD PTR [rsp+80] - movaps xmm11, XMMWORD PTR [rsp+96] - movaps xmm12, XMMWORD PTR [rsp+112] - movaps xmm13, XMMWORD PTR [rsp+128] - - add rsp, 232 - pop r15 - pop r14 - pop r13 - pop r12 - pop rdi - pop rsi - pop rbp - pop rbx - ret -FN_PREFIX(CryptonightWOW_soft_aes_template_end): diff --git a/src/crypto/asm/win64/CryptonightWOW_template.inc b/src/crypto/asm/win64/CryptonightWOW_template.inc deleted file mode 100644 index 47fbc94f8..000000000 --- a/src/crypto/asm/win64/CryptonightWOW_template.inc +++ /dev/null @@ -1,486 +0,0 @@ -PUBLIC FN_PREFIX(CryptonightWOW_template_part1) -PUBLIC FN_PREFIX(CryptonightWOW_template_mainloop) -PUBLIC FN_PREFIX(CryptonightWOW_template_part2) -PUBLIC FN_PREFIX(CryptonightWOW_template_part3) -PUBLIC FN_PREFIX(CryptonightWOW_template_end) -PUBLIC FN_PREFIX(CryptonightWOW_template_double_part1) -PUBLIC FN_PREFIX(CryptonightWOW_template_double_mainloop) -PUBLIC FN_PREFIX(CryptonightWOW_template_double_part2) -PUBLIC FN_PREFIX(CryptonightWOW_template_double_part3) -PUBLIC FN_PREFIX(CryptonightWOW_template_double_part4) -PUBLIC FN_PREFIX(CryptonightWOW_template_double_end) - -ALIGN(64) -FN_PREFIX(CryptonightWOW_template_part1): - mov QWORD PTR [rsp+16], rbx - mov QWORD PTR [rsp+24], rbp - mov QWORD PTR [rsp+32], rsi - push r10 - push r11 - push r12 - push r13 - push r14 - push r15 - push rdi - sub rsp, 64 - mov r12, rcx - mov r8, QWORD PTR [r12+32] - mov rdx, r12 - xor r8, QWORD PTR [r12] - mov r15, QWORD PTR [r12+40] - mov r9, r8 - xor r15, QWORD PTR [r12+8] - mov r11, QWORD PTR [r12+224] - mov r12, QWORD PTR [r12+56] - xor r12, QWORD PTR [rdx+24] - mov rax, QWORD PTR [rdx+48] - xor rax, QWORD PTR [rdx+16] - movaps XMMWORD PTR [rsp+48], xmm6 - movd xmm0, r12 - movaps XMMWORD PTR [rsp+32], xmm7 - movaps XMMWORD PTR [rsp+16], xmm8 - movaps XMMWORD PTR [rsp], xmm9 - mov r12, QWORD PTR [rdx+88] - xor r12, QWORD PTR [rdx+72] - movd xmm6, rax - mov rax, QWORD PTR [rdx+80] - xor rax, QWORD PTR [rdx+64] - punpcklqdq xmm6, xmm0 - and r9d, 2097136 - movd xmm0, r12 - movd xmm7, rax - punpcklqdq xmm7, xmm0 - mov r10d, r9d - movd xmm9, rsp - mov rsp, r8 - mov r8d, 524288 - - mov ebx, [rdx+96] - mov esi, [rdx+100] - mov edi, [rdx+104] - mov ebp, [rdx+108] - - ALIGN(64) -FN_PREFIX(CryptonightWOW_template_mainloop): - movdqa xmm5, XMMWORD PTR [r9+r11] - movd xmm0, r15 - movd xmm4, rsp - punpcklqdq xmm4, xmm0 - lea rdx, QWORD PTR [r9+r11] - - aesenc xmm5, xmm4 - movd r10d, xmm5 - and r10d, 2097136 - - mov r12d, r9d - mov eax, r9d - xor r9d, 48 - xor r12d, 16 - xor eax, 32 - movdqu xmm0, XMMWORD PTR [r9+r11] - movdqu xmm2, XMMWORD PTR [r12+r11] - movdqu xmm1, XMMWORD PTR [rax+r11] - paddq xmm0, xmm7 - paddq xmm2, xmm6 - paddq xmm1, xmm4 - movdqu XMMWORD PTR [r12+r11], xmm0 - movd r12, xmm5 - movdqu XMMWORD PTR [rax+r11], xmm2 - movdqu XMMWORD PTR [r9+r11], xmm1 - - movdqa xmm0, xmm5 - pxor xmm0, xmm6 - movdqu XMMWORD PTR [rdx], xmm0 - - lea r13d, [ebx+esi] - lea edx, [edi+ebp] - shl rdx, 32 - or r13, rdx - - xor r13, QWORD PTR [r10+r11] - mov r14, QWORD PTR [r10+r11+8] - - movd eax, xmm6 - movd edx, xmm7 - pextrd r9d, xmm7, 2 - -FN_PREFIX(CryptonightWOW_template_part2): - mov rax, r13 - mul r12 - movd xmm0, rax - movd xmm3, rdx - punpcklqdq xmm3, xmm0 - - mov r9d, r10d - mov r12d, r10d - xor r9d, 16 - xor r12d, 32 - xor r10d, 48 - movdqa xmm1, XMMWORD PTR [r12+r11] - xor rdx, QWORD PTR [r12+r11] - xor rax, QWORD PTR [r11+r12+8] - movdqa xmm2, XMMWORD PTR [r9+r11] - pxor xmm3, xmm2 - paddq xmm7, XMMWORD PTR [r10+r11] - paddq xmm1, xmm4 - paddq xmm3, xmm6 - movdqu XMMWORD PTR [r9+r11], xmm7 - movdqu XMMWORD PTR [r12+r11], xmm3 - movdqu XMMWORD PTR [r10+r11], xmm1 - - movdqa xmm7, xmm6 - add r15, rax - add rsp, rdx - xor r10, 48 - mov QWORD PTR [r10+r11], rsp - xor rsp, r13 - mov r9d, esp - mov QWORD PTR [r10+r11+8], r15 - and r9d, 2097136 - xor r15, r14 - movdqa xmm6, xmm5 - dec r8d - jnz FN_PREFIX(CryptonightWOW_template_mainloop) - -FN_PREFIX(CryptonightWOW_template_part3): - movd rsp, xmm9 - - mov rbx, QWORD PTR [rsp+136] - mov rbp, QWORD PTR [rsp+144] - mov rsi, QWORD PTR [rsp+152] - movaps xmm6, XMMWORD PTR [rsp+48] - movaps xmm7, XMMWORD PTR [rsp+32] - movaps xmm8, XMMWORD PTR [rsp+16] - movaps xmm9, XMMWORD PTR [rsp] - add rsp, 64 - pop rdi - pop r15 - pop r14 - pop r13 - pop r12 - pop r11 - pop r10 - ret 0 -FN_PREFIX(CryptonightWOW_template_end): - -ALIGN(64) -FN_PREFIX(CryptonightWOW_template_double_part1): - mov QWORD PTR [rsp+24], rbx - push rbp - push rsi - push rdi - push r12 - push r13 - push r14 - push r15 - sub rsp, 320 - mov r14, QWORD PTR [rcx+32] - mov r8, rcx - xor r14, QWORD PTR [rcx] - mov r12, QWORD PTR [rcx+40] - mov ebx, r14d - mov rsi, QWORD PTR [rcx+224] - and ebx, 2097136 - xor r12, QWORD PTR [rcx+8] - mov rcx, QWORD PTR [rcx+56] - xor rcx, QWORD PTR [r8+24] - mov rax, QWORD PTR [r8+48] - xor rax, QWORD PTR [r8+16] - mov r15, QWORD PTR [rdx+32] - xor r15, QWORD PTR [rdx] - movd xmm0, rcx - mov rcx, QWORD PTR [r8+88] - xor rcx, QWORD PTR [r8+72] - mov r13, QWORD PTR [rdx+40] - mov rdi, QWORD PTR [rdx+224] - xor r13, QWORD PTR [rdx+8] - movaps XMMWORD PTR [rsp+160], xmm6 - movaps XMMWORD PTR [rsp+176], xmm7 - movaps XMMWORD PTR [rsp+192], xmm8 - movaps XMMWORD PTR [rsp+208], xmm9 - movaps XMMWORD PTR [rsp+224], xmm10 - movaps XMMWORD PTR [rsp+240], xmm11 - movaps XMMWORD PTR [rsp+256], xmm12 - movaps XMMWORD PTR [rsp+272], xmm13 - movaps XMMWORD PTR [rsp+288], xmm14 - movaps XMMWORD PTR [rsp+304], xmm15 - movd xmm7, rax - mov rax, QWORD PTR [r8+80] - xor rax, QWORD PTR [r8+64] - - movaps xmm1, XMMWORD PTR [rdx+96] - movaps xmm2, XMMWORD PTR [r8+96] - movaps XMMWORD PTR [rsp], xmm1 - movaps XMMWORD PTR [rsp+16], xmm2 - - mov r8d, r15d - punpcklqdq xmm7, xmm0 - movd xmm0, rcx - mov rcx, QWORD PTR [rdx+56] - xor rcx, QWORD PTR [rdx+24] - movd xmm9, rax - mov QWORD PTR [rsp+128], rsi - mov rax, QWORD PTR [rdx+48] - xor rax, QWORD PTR [rdx+16] - punpcklqdq xmm9, xmm0 - movd xmm0, rcx - mov rcx, QWORD PTR [rdx+88] - xor rcx, QWORD PTR [rdx+72] - movd xmm8, rax - mov QWORD PTR [rsp+136], rdi - mov rax, QWORD PTR [rdx+80] - xor rax, QWORD PTR [rdx+64] - punpcklqdq xmm8, xmm0 - and r8d, 2097136 - movd xmm0, rcx - mov r11d, 524288 - movd xmm10, rax - punpcklqdq xmm10, xmm0 - - movd xmm14, QWORD PTR [rsp+128] - movd xmm15, QWORD PTR [rsp+136] - - ALIGN(64) -FN_PREFIX(CryptonightWOW_template_double_mainloop): - movdqu xmm6, XMMWORD PTR [rbx+rsi] - movd xmm0, r12 - mov ecx, ebx - movd xmm3, r14 - punpcklqdq xmm3, xmm0 - xor ebx, 16 - aesenc xmm6, xmm3 - movd rdx, xmm6 - movd xmm4, r15 - movdqu xmm0, XMMWORD PTR [rbx+rsi] - xor ebx, 48 - paddq xmm0, xmm7 - movdqu xmm1, XMMWORD PTR [rbx+rsi] - movdqu XMMWORD PTR [rbx+rsi], xmm0 - paddq xmm1, xmm3 - xor ebx, 16 - mov eax, ebx - xor rax, 32 - movdqu xmm0, XMMWORD PTR [rbx+rsi] - movdqu XMMWORD PTR [rbx+rsi], xmm1 - paddq xmm0, xmm9 - movdqu XMMWORD PTR [rax+rsi], xmm0 - movdqa xmm0, xmm6 - pxor xmm0, xmm7 - movdqu XMMWORD PTR [rcx+rsi], xmm0 - mov esi, edx - movdqu xmm5, XMMWORD PTR [r8+rdi] - and esi, 2097136 - mov ecx, r8d - movd xmm0, r13 - punpcklqdq xmm4, xmm0 - xor r8d, 16 - aesenc xmm5, xmm4 - movdqu xmm0, XMMWORD PTR [r8+rdi] - xor r8d, 48 - paddq xmm0, xmm8 - movdqu xmm1, XMMWORD PTR [r8+rdi] - movdqu XMMWORD PTR [r8+rdi], xmm0 - paddq xmm1, xmm4 - xor r8d, 16 - mov eax, r8d - xor rax, 32 - movdqu xmm0, XMMWORD PTR [r8+rdi] - movdqu XMMWORD PTR [r8+rdi], xmm1 - paddq xmm0, xmm10 - movdqu XMMWORD PTR [rax+rdi], xmm0 - movdqa xmm0, xmm5 - pxor xmm0, xmm8 - movdqu XMMWORD PTR [rcx+rdi], xmm0 - movd rdi, xmm5 - movd rcx, xmm14 - mov ebp, edi - mov r8, QWORD PTR [rcx+rsi] - mov r10, QWORD PTR [rcx+rsi+8] - lea r9, QWORD PTR [rcx+rsi] - xor esi, 16 - - movd xmm0, rsp - movd xmm1, rsi - movd xmm2, rdi - movd xmm11, rbp - movd xmm12, r15 - movd xmm13, rdx - mov [rsp+104], rcx - mov [rsp+112], r9 - - mov ebx, DWORD PTR [rsp+16] - mov esi, DWORD PTR [rsp+20] - mov edi, DWORD PTR [rsp+24] - mov ebp, DWORD PTR [rsp+28] - - lea eax, [ebx+esi] - lea edx, [edi+ebp] - shl rdx, 32 - or rax, rdx - xor r8, rax - - movd esp, xmm3 - pextrd r15d, xmm3, 2 - movd eax, xmm7 - movd edx, xmm9 - pextrd r9d, xmm9, 2 - -FN_PREFIX(CryptonightWOW_template_double_part2): - - movd rsp, xmm0 - mov DWORD PTR [rsp+16], ebx - mov DWORD PTR [rsp+20], esi - mov DWORD PTR [rsp+24], edi - mov DWORD PTR [rsp+28], ebp - - movd rsi, xmm1 - movd rdi, xmm2 - movd rbp, xmm11 - movd r15, xmm12 - movd rdx, xmm13 - mov rcx, [rsp+104] - mov r9, [rsp+112] - - mov rbx, r8 - mov rax, r8 - mul rdx - and ebp, 2097136 - mov r8, rax - movd xmm1, rdx - movd xmm0, r8 - punpcklqdq xmm1, xmm0 - pxor xmm1, XMMWORD PTR [rcx+rsi] - xor esi, 48 - paddq xmm1, xmm7 - movdqu xmm2, XMMWORD PTR [rsi+rcx] - xor rdx, QWORD PTR [rsi+rcx] - paddq xmm2, xmm3 - xor r8, QWORD PTR [rsi+rcx+8] - movdqu XMMWORD PTR [rsi+rcx], xmm1 - xor esi, 16 - mov eax, esi - mov rsi, rcx - movdqu xmm0, XMMWORD PTR [rax+rcx] - movdqu XMMWORD PTR [rax+rcx], xmm2 - paddq xmm0, xmm9 - add r12, r8 - xor rax, 32 - add r14, rdx - movdqa xmm9, xmm7 - movdqa xmm7, xmm6 - movdqu XMMWORD PTR [rax+rcx], xmm0 - mov QWORD PTR [r9+8], r12 - xor r12, r10 - mov QWORD PTR [r9], r14 - movd rcx, xmm15 - xor r14, rbx - mov r10d, ebp - mov ebx, r14d - xor ebp, 16 - and ebx, 2097136 - mov r8, QWORD PTR [r10+rcx] - mov r9, QWORD PTR [r10+rcx+8] - - movd xmm0, rsp - movd xmm1, rbx - movd xmm2, rsi - movd xmm11, rdi - movd xmm12, rbp - movd xmm13, r15 - mov [rsp+104], rcx - mov [rsp+112], r9 - - mov ebx, DWORD PTR [rsp] - mov esi, DWORD PTR [rsp+4] - mov edi, DWORD PTR [rsp+8] - mov ebp, DWORD PTR [rsp+12] - - lea eax, [ebx+esi] - lea edx, [edi+ebp] - shl rdx, 32 - or rax, rdx - - xor r8, rax - movd xmm3, r8 - - movd esp, xmm4 - pextrd r15d, xmm4, 2 - movd eax, xmm8 - movd edx, xmm10 - pextrd r9d, xmm10, 2 - -FN_PREFIX(CryptonightWOW_template_double_part3): - - movd rsp, xmm0 - mov DWORD PTR [rsp], ebx - mov DWORD PTR [rsp+4], esi - mov DWORD PTR [rsp+8], edi - mov DWORD PTR [rsp+12], ebp - - movd rbx, xmm1 - movd rsi, xmm2 - movd rdi, xmm11 - movd rbp, xmm12 - movd r15, xmm13 - mov rcx, [rsp+104] - mov r9, [rsp+112] - - mov rax, r8 - mul rdi - movd xmm1, rdx - movd xmm0, rax - punpcklqdq xmm1, xmm0 - mov rdi, rcx - mov r8, rax - pxor xmm1, XMMWORD PTR [rbp+rcx] - xor ebp, 48 - paddq xmm1, xmm8 - xor r8, QWORD PTR [rbp+rcx+8] - xor rdx, QWORD PTR [rbp+rcx] - add r13, r8 - movdqu xmm2, XMMWORD PTR [rbp+rcx] - add r15, rdx - movdqu XMMWORD PTR [rbp+rcx], xmm1 - paddq xmm2, xmm4 - xor ebp, 16 - mov eax, ebp - xor rax, 32 - movdqu xmm0, XMMWORD PTR [rbp+rcx] - movdqu XMMWORD PTR [rbp+rcx], xmm2 - paddq xmm0, xmm10 - movdqu XMMWORD PTR [rax+rcx], xmm0 - movd rax, xmm3 - movdqa xmm10, xmm8 - mov QWORD PTR [r10+rcx], r15 - movdqa xmm8, xmm5 - xor r15, rax - mov QWORD PTR [r10+rcx+8], r13 - mov r8d, r15d - xor r13, r9 - and r8d, 2097136 - dec r11d - jnz FN_PREFIX(CryptonightWOW_template_double_mainloop) - -FN_PREFIX(CryptonightWOW_template_double_part4): - - mov rbx, QWORD PTR [rsp+400] - movaps xmm6, XMMWORD PTR [rsp+160] - movaps xmm7, XMMWORD PTR [rsp+176] - movaps xmm8, XMMWORD PTR [rsp+192] - movaps xmm9, XMMWORD PTR [rsp+208] - movaps xmm10, XMMWORD PTR [rsp+224] - movaps xmm11, XMMWORD PTR [rsp+240] - movaps xmm12, XMMWORD PTR [rsp+256] - movaps xmm13, XMMWORD PTR [rsp+272] - movaps xmm14, XMMWORD PTR [rsp+288] - movaps xmm15, XMMWORD PTR [rsp+304] - add rsp, 320 - pop r15 - pop r14 - pop r13 - pop r12 - pop rdi - pop rsi - pop rbp - ret 0 -FN_PREFIX(CryptonightWOW_template_double_end): From 9f2d82197082be92c986320690612056e8c8111e Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 4 Mar 2019 17:39:49 +0100 Subject: [PATCH 21/55] Optimized cn/r asm code Average over 100 block heights: Coffee Lake +0.1% Ryzen +0.4% Sandy Bridge +1.5% --- src/crypto/asm/CryptonightR_template.inc | 36 ++++++++++--------- src/crypto/asm/CryptonightR_template_win.inc | 36 ++++++++++--------- .../asm/win64/CryptonightR_template.inc | 36 ++++++++++--------- .../asm/win64/CryptonightR_template_win.inc | 36 ++++++++++--------- 4 files changed, 76 insertions(+), 68 deletions(-) diff --git a/src/crypto/asm/CryptonightR_template.inc b/src/crypto/asm/CryptonightR_template.inc index b54486a57..8ecab7247 100644 --- a/src/crypto/asm/CryptonightR_template.inc +++ b/src/crypto/asm/CryptonightR_template.inc @@ -70,29 +70,30 @@ FN_PREFIX(CryptonightR_template_mainloop): aesenc xmm5, xmm4 - mov r12d, r9d + mov r13d, r9d mov eax, r9d xor r9d, 48 - xor r12d, 16 + xor r13d, 16 xor eax, 32 movdqu xmm0, XMMWORD PTR [r9+r11] movaps xmm3, xmm0 - movdqu xmm2, XMMWORD PTR [r12+r11] + movdqu xmm2, XMMWORD PTR [r13+r11] movdqu xmm1, XMMWORD PTR [rax+r11] pxor xmm0, xmm2 pxor xmm5, xmm1 pxor xmm5, xmm0 - paddq xmm3, xmm7 - paddq xmm2, xmm6 - paddq xmm1, xmm4 - movdqu XMMWORD PTR [r12+r11], xmm3 - movdqu XMMWORD PTR [rax+r11], xmm2 - movdqu XMMWORD PTR [r9+r11], xmm1 movq r12, xmm5 movd r10d, xmm5 and r10d, 2097136 + paddq xmm3, xmm7 + paddq xmm2, xmm6 + paddq xmm1, xmm4 + movdqu XMMWORD PTR [r13+r11], xmm3 + movdqu XMMWORD PTR [rax+r11], xmm2 + movdqu XMMWORD PTR [r9+r11], xmm1 + movdqa xmm0, xmm5 pxor xmm0, xmm6 movdqu XMMWORD PTR [rdx], xmm0 @@ -102,14 +103,16 @@ FN_PREFIX(CryptonightR_template_mainloop): shl rdx, 32 or r13, rdx - xor r13, QWORD PTR [r10+r11] - mov r14, QWORD PTR [r10+r11+8] - movd eax, xmm6 movd edx, xmm7 pextrd r9d, xmm7, 2 + xor r13, QWORD PTR [r10+r11] + mov r14, QWORD PTR [r10+r11+8] + FN_PREFIX(CryptonightR_template_part2): + lea rcx, [r10+r11] + mov eax, edi mov edx, ebp shl rdx, 32 @@ -124,6 +127,8 @@ FN_PREFIX(CryptonightR_template_part2): mov rax, r13 mul r12 + add r15, rax + add rsp, rdx mov r9d, r10d mov r12d, r10d @@ -145,13 +150,10 @@ FN_PREFIX(CryptonightR_template_part2): movdqu XMMWORD PTR [r10+r11], xmm3 movdqa xmm7, xmm6 - add r15, rax - add rsp, rdx - xor r10, 48 - mov QWORD PTR [r10+r11], rsp + mov QWORD PTR [rcx], rsp xor rsp, r13 mov r9d, esp - mov QWORD PTR [r10+r11+8], r15 + mov QWORD PTR [rcx+8], r15 and r9d, 2097136 xor r15, r14 movdqa xmm6, xmm5 diff --git a/src/crypto/asm/CryptonightR_template_win.inc b/src/crypto/asm/CryptonightR_template_win.inc index 150bb0e35..a170f2d2b 100644 --- a/src/crypto/asm/CryptonightR_template_win.inc +++ b/src/crypto/asm/CryptonightR_template_win.inc @@ -70,29 +70,30 @@ CryptonightR_template_mainloop: aesenc xmm5, xmm4 - mov r12d, r9d + mov r13d, r9d mov eax, r9d xor r9d, 48 - xor r12d, 16 + xor r13d, 16 xor eax, 32 movdqu xmm0, XMMWORD PTR [r9+r11] movaps xmm3, xmm0 - movdqu xmm2, XMMWORD PTR [r12+r11] + movdqu xmm2, XMMWORD PTR [r13+r11] movdqu xmm1, XMMWORD PTR [rax+r11] pxor xmm0, xmm2 pxor xmm5, xmm1 pxor xmm5, xmm0 - paddq xmm3, xmm7 - paddq xmm2, xmm6 - paddq xmm1, xmm4 - movdqu XMMWORD PTR [r12+r11], xmm3 - movdqu XMMWORD PTR [rax+r11], xmm2 - movdqu XMMWORD PTR [r9+r11], xmm1 movq r12, xmm5 movd r10d, xmm5 and r10d, 2097136 + paddq xmm3, xmm7 + paddq xmm2, xmm6 + paddq xmm1, xmm4 + movdqu XMMWORD PTR [r13+r11], xmm3 + movdqu XMMWORD PTR [rax+r11], xmm2 + movdqu XMMWORD PTR [r9+r11], xmm1 + movdqa xmm0, xmm5 pxor xmm0, xmm6 movdqu XMMWORD PTR [rdx], xmm0 @@ -102,14 +103,16 @@ CryptonightR_template_mainloop: shl rdx, 32 or r13, rdx - xor r13, QWORD PTR [r10+r11] - mov r14, QWORD PTR [r10+r11+8] - movd eax, xmm6 movd edx, xmm7 pextrd r9d, xmm7, 2 + xor r13, QWORD PTR [r10+r11] + mov r14, QWORD PTR [r10+r11+8] + CryptonightR_template_part2: + lea rcx, [r10+r11] + mov eax, edi mov edx, ebp shl rdx, 32 @@ -124,6 +127,8 @@ CryptonightR_template_part2: mov rax, r13 mul r12 + add r15, rax + add rsp, rdx mov r9d, r10d mov r12d, r10d @@ -145,13 +150,10 @@ CryptonightR_template_part2: movdqu XMMWORD PTR [r10+r11], xmm3 movdqa xmm7, xmm6 - add r15, rax - add rsp, rdx - xor r10, 48 - mov QWORD PTR [r10+r11], rsp + mov QWORD PTR [rcx], rsp xor rsp, r13 mov r9d, esp - mov QWORD PTR [r10+r11+8], r15 + mov QWORD PTR [rcx+8], r15 and r9d, 2097136 xor r15, r14 movdqa xmm6, xmm5 diff --git a/src/crypto/asm/win64/CryptonightR_template.inc b/src/crypto/asm/win64/CryptonightR_template.inc index 1dae434a2..97ba5347b 100644 --- a/src/crypto/asm/win64/CryptonightR_template.inc +++ b/src/crypto/asm/win64/CryptonightR_template.inc @@ -70,29 +70,30 @@ FN_PREFIX(CryptonightR_template_mainloop): aesenc xmm5, xmm4 - mov r12d, r9d + mov r13d, r9d mov eax, r9d xor r9d, 48 - xor r12d, 16 + xor r13d, 16 xor eax, 32 movdqu xmm0, XMMWORD PTR [r9+r11] movaps xmm3, xmm0 - movdqu xmm2, XMMWORD PTR [r12+r11] + movdqu xmm2, XMMWORD PTR [r13+r11] movdqu xmm1, XMMWORD PTR [rax+r11] pxor xmm0, xmm2 pxor xmm5, xmm1 pxor xmm5, xmm0 - paddq xmm3, xmm7 - paddq xmm2, xmm6 - paddq xmm1, xmm4 - movdqu XMMWORD PTR [r12+r11], xmm3 - movdqu XMMWORD PTR [rax+r11], xmm2 - movdqu XMMWORD PTR [r9+r11], xmm1 movd r12, xmm5 movd r10d, xmm5 and r10d, 2097136 + paddq xmm3, xmm7 + paddq xmm2, xmm6 + paddq xmm1, xmm4 + movdqu XMMWORD PTR [r13+r11], xmm3 + movdqu XMMWORD PTR [rax+r11], xmm2 + movdqu XMMWORD PTR [r9+r11], xmm1 + movdqa xmm0, xmm5 pxor xmm0, xmm6 movdqu XMMWORD PTR [rdx], xmm0 @@ -102,14 +103,16 @@ FN_PREFIX(CryptonightR_template_mainloop): shl rdx, 32 or r13, rdx - xor r13, QWORD PTR [r10+r11] - mov r14, QWORD PTR [r10+r11+8] - movd eax, xmm6 movd edx, xmm7 pextrd r9d, xmm7, 2 + xor r13, QWORD PTR [r10+r11] + mov r14, QWORD PTR [r10+r11+8] + FN_PREFIX(CryptonightR_template_part2): + lea rcx, [r10+r11] + mov eax, edi mov edx, ebp shl rdx, 32 @@ -124,6 +127,8 @@ FN_PREFIX(CryptonightR_template_part2): mov rax, r13 mul r12 + add r15, rax + add rsp, rdx mov r9d, r10d mov r12d, r10d @@ -145,13 +150,10 @@ FN_PREFIX(CryptonightR_template_part2): movdqu XMMWORD PTR [r10+r11], xmm3 movdqa xmm7, xmm6 - add r15, rax - add rsp, rdx - xor r10, 48 - mov QWORD PTR [r10+r11], rsp + mov QWORD PTR [rcx], rsp xor rsp, r13 mov r9d, esp - mov QWORD PTR [r10+r11+8], r15 + mov QWORD PTR [rcx+8], r15 and r9d, 2097136 xor r15, r14 movdqa xmm6, xmm5 diff --git a/src/crypto/asm/win64/CryptonightR_template_win.inc b/src/crypto/asm/win64/CryptonightR_template_win.inc index 2f2d71a25..60ee3441b 100644 --- a/src/crypto/asm/win64/CryptonightR_template_win.inc +++ b/src/crypto/asm/win64/CryptonightR_template_win.inc @@ -70,29 +70,30 @@ CryptonightR_template_mainloop: aesenc xmm5, xmm4 - mov r12d, r9d + mov r13d, r9d mov eax, r9d xor r9d, 48 - xor r12d, 16 + xor r13d, 16 xor eax, 32 movdqu xmm0, XMMWORD PTR [r9+r11] movaps xmm3, xmm0 - movdqu xmm2, XMMWORD PTR [r12+r11] + movdqu xmm2, XMMWORD PTR [r13+r11] movdqu xmm1, XMMWORD PTR [rax+r11] pxor xmm0, xmm2 pxor xmm5, xmm1 pxor xmm5, xmm0 - paddq xmm3, xmm7 - paddq xmm2, xmm6 - paddq xmm1, xmm4 - movdqu XMMWORD PTR [r12+r11], xmm3 - movdqu XMMWORD PTR [rax+r11], xmm2 - movdqu XMMWORD PTR [r9+r11], xmm1 movd r12, xmm5 movd r10d, xmm5 and r10d, 2097136 + paddq xmm3, xmm7 + paddq xmm2, xmm6 + paddq xmm1, xmm4 + movdqu XMMWORD PTR [r13+r11], xmm3 + movdqu XMMWORD PTR [rax+r11], xmm2 + movdqu XMMWORD PTR [r9+r11], xmm1 + movdqa xmm0, xmm5 pxor xmm0, xmm6 movdqu XMMWORD PTR [rdx], xmm0 @@ -102,14 +103,16 @@ CryptonightR_template_mainloop: shl rdx, 32 or r13, rdx - xor r13, QWORD PTR [r10+r11] - mov r14, QWORD PTR [r10+r11+8] - movd eax, xmm6 movd edx, xmm7 pextrd r9d, xmm7, 2 + xor r13, QWORD PTR [r10+r11] + mov r14, QWORD PTR [r10+r11+8] + CryptonightR_template_part2: + lea rcx, [r10+r11] + mov eax, edi mov edx, ebp shl rdx, 32 @@ -124,6 +127,8 @@ CryptonightR_template_part2: mov rax, r13 mul r12 + add r15, rax + add rsp, rdx mov r9d, r10d mov r12d, r10d @@ -145,13 +150,10 @@ CryptonightR_template_part2: movdqu XMMWORD PTR [r10+r11], xmm3 movdqa xmm7, xmm6 - add r15, rax - add rsp, rdx - xor r10, 48 - mov QWORD PTR [r10+r11], rsp + mov QWORD PTR [rcx], rsp xor rsp, r13 mov r9d, esp - mov QWORD PTR [r10+r11+8], r15 + mov QWORD PTR [rcx+8], r15 and r9d, 2097136 xor r15, r14 movdqa xmm6, xmm5 From 154806ac74e01ef91e65ecbf3dddf39553d425f4 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 4 Mar 2019 19:57:33 +0100 Subject: [PATCH 22/55] CryptoNight v8 ReverseWaltz (+asm code and all test vectors) Co-Authored-By: Vitalius Parubochyi --- src/base/net/Pool.cpp | 1 + src/common/crypto/Algorithm.cpp | 2 + src/common/xmrig.h | 1 + src/crypto/CryptoNight_arm.h | 14 +- src/crypto/CryptoNight_constants.h | 6 + src/crypto/CryptoNight_monero.h | 34 +- src/crypto/CryptoNight_test.h | 12 + src/crypto/CryptoNight_x86.h | 26 +- .../asm/cn2/cnv2_rwz_double_main_loop.inc | 410 ++++++++++++++++++ src/crypto/asm/cn2/cnv2_rwz_main_loop.inc | 186 ++++++++ src/crypto/asm/cn_main_loop.S | 20 + src/crypto/asm/cn_main_loop.asm | 16 + .../win64/cn2/cnv2_rwz_double_main_loop.inc | 410 ++++++++++++++++++ .../asm/win64/cn2/cnv2_rwz_main_loop.inc | 186 ++++++++ src/crypto/asm/win64/cn_main_loop.S | 20 + src/crypto/asm/win64/cn_main_loop.asm | 16 + src/workers/CpuThread.cpp | 19 + src/workers/MultiWorker.cpp | 3 +- 18 files changed, 1353 insertions(+), 29 deletions(-) create mode 100644 src/crypto/asm/cn2/cnv2_rwz_double_main_loop.inc create mode 100644 src/crypto/asm/cn2/cnv2_rwz_main_loop.inc create mode 100644 src/crypto/asm/win64/cn2/cnv2_rwz_double_main_loop.inc create mode 100644 src/crypto/asm/win64/cn2/cnv2_rwz_main_loop.inc diff --git a/src/base/net/Pool.cpp b/src/base/net/Pool.cpp index 8a4d0a0a3..a1fd4331b 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -484,6 +484,7 @@ void xmrig::Pool::rebuild() m_algorithms.push_back(m_algorithm); # ifndef XMRIG_PROXY_PROJECT + addVariant(VARIANT_RWZ); addVariant(VARIANT_4); addVariant(VARIANT_WOW); addVariant(VARIANT_2); diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index 7d03acfc1..ae7ba7c7d 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -66,6 +66,7 @@ static AlgoData const algorithms[] = { { "cryptonight/xtlv9", "cn/xtlv9", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF }, { "cryptonight/wow", "cn/wow", xmrig::CRYPTONIGHT, xmrig::VARIANT_WOW }, { "cryptonight/r", "cn/r", xmrig::CRYPTONIGHT, xmrig::VARIANT_4 }, + { "cryptonight/rwz", "cn/rwz", xmrig::CRYPTONIGHT, xmrig::VARIANT_RWZ }, # ifndef XMRIG_NO_AEON { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, @@ -133,6 +134,7 @@ static const char *variants[] = { "gpu", "wow", "r", + "rwz" }; diff --git a/src/common/xmrig.h b/src/common/xmrig.h index c6a5f5688..575251b78 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -76,6 +76,7 @@ enum Variant { VARIANT_GPU = 11, // CryptoNight-GPU (Ryo) VARIANT_WOW = 12, // CryptoNightR (Wownero) VARIANT_4 = 13, // CryptoNightR (Monero's variant 4) + VARIANT_RWZ = 14, // CryptoNight variant 2 with 3/4 iterations and reversed shuffle operation (Graft) VARIANT_MAX }; diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index e7232eb1f..d762929c2 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -436,7 +436,7 @@ static inline void cryptonight_monero_tweak(const uint8_t* l, uint64_t idx, __m1 uint64_t* mem_out = (uint64_t*)&l[idx]; if (BASE == xmrig::VARIANT_2) { - VARIANT2_SHUFFLE(l, idx, ax0, bx0, bx1, cx); + VARIANT2_SHUFFLE(l, idx, ax0, bx0, bx1, cx, (VARIANT == xmrig::VARIANT_RWZ ? 1 : 0)); _mm_store_si128((__m128i *)mem_out, _mm_xor_si128(bx0, cx)); } else { __m128i tmp = _mm_xor_si128(bx0, cx); @@ -530,9 +530,9 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si if (BASE == xmrig::VARIANT_2) { if (VARIANT == xmrig::VARIANT_4) { - VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx0, bx1, cx); + VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx0, bx1, cx, 0); } else { - VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx0, bx1, hi, lo); + VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx0, bx1, hi, lo, (VARIANT == xmrig::VARIANT_RWZ ? 1 : 0)); } } @@ -709,9 +709,9 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si if (BASE == xmrig::VARIANT_2) { if (VARIANT == xmrig::VARIANT_4) { - VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx00, bx01, cx0); + VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx00, bx01, cx0, 0); } else { - VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx00, bx01, hi, lo); + VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx00, bx01, hi, lo, (VARIANT == xmrig::VARIANT_RWZ ? 1 : 0)); } } @@ -767,9 +767,9 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si if (BASE == xmrig::VARIANT_2) { if (VARIANT == xmrig::VARIANT_4) { - VARIANT2_SHUFFLE(l1, idx1 & MASK, ax1, bx10, bx11, cx1); + VARIANT2_SHUFFLE(l1, idx1 & MASK, ax1, bx10, bx11, cx1, 0); } else { - VARIANT2_SHUFFLE2(l1, idx1 & MASK, ax1, bx10, bx11, hi, lo); + VARIANT2_SHUFFLE2(l1, idx1 & MASK, ax1, bx10, bx11, hi, lo, (VARIANT == xmrig::VARIANT_RWZ ? 1 : 0)); } } diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 6afedc905..a6623ebaf 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -42,6 +42,7 @@ constexpr const uint32_t CRYPTONIGHT_MASK = 0x1FFFF0; constexpr const uint32_t CRYPTONIGHT_ITER = 0x80000; constexpr const uint32_t CRYPTONIGHT_HALF_ITER = 0x40000; constexpr const uint32_t CRYPTONIGHT_XAO_ITER = 0x100000; +constexpr const uint32_t CRYPTONIGHT_WALTZ_ITER = 0x60000; constexpr const uint32_t CRYPTONIGHT_GPU_ITER = 0xC000; constexpr const uint32_t CRYPTONIGHT_GPU_MASK = 0x1FFFC0; @@ -134,6 +135,7 @@ template<> inline constexpr uint32_t cn_select_iter() template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_XAO_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_GPU_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_WALTZ_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } @@ -158,6 +160,9 @@ inline uint32_t cn_select_iter(Algo algorithm, Variant variant) case VARIANT_TRTL: return CRYPTONIGHT_TRTL_ITER; + case VARIANT_RWZ: + return CRYPTONIGHT_WALTZ_ITER; + default: break; } @@ -199,6 +204,7 @@ template<> inline constexpr Variant cn_base_variant() { return VA template<> inline constexpr Variant cn_base_variant() { return VARIANT_GPU; } template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } template inline constexpr bool cn_is_cryptonight_r() { return false; } diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index 4cfff0f86..4e84ac5d0 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -83,11 +83,11 @@ sqrt_result_xmm_##part = int_sqrt_v2(cx_0 + division_result); \ } while (0) -# define VARIANT2_SHUFFLE(base_ptr, offset, _a, _b, _b1, _c) \ +# define VARIANT2_SHUFFLE(base_ptr, offset, _a, _b, _b1, _c, reverse) \ do { \ - const __m128i chunk1 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10))); \ + const __m128i chunk1 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ (reverse ? 0x30 : 0x10)))); \ const __m128i chunk2 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20))); \ - const __m128i chunk3 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x30))); \ + const __m128i chunk3 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ (reverse ? 0x10 : 0x30)))); \ _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10)), _mm_add_epi64(chunk3, _b1)); \ _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20)), _mm_add_epi64(chunk1, _b)); \ _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x30)), _mm_add_epi64(chunk2, _a)); \ @@ -96,15 +96,20 @@ } \ } while (0) -# define VARIANT2_SHUFFLE2(base_ptr, offset, _a, _b, _b1, hi, lo) \ +# define VARIANT2_SHUFFLE2(base_ptr, offset, _a, _b, _b1, hi, lo, reverse) \ do { \ const __m128i chunk1 = _mm_xor_si128(_mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10))), _mm_set_epi64x(lo, hi)); \ const __m128i chunk2 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20))); \ hi ^= ((uint64_t*)((base_ptr) + ((offset) ^ 0x20)))[0]; \ lo ^= ((uint64_t*)((base_ptr) + ((offset) ^ 0x20)))[1]; \ const __m128i chunk3 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x30))); \ - _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10)), _mm_add_epi64(chunk3, _b1)); \ - _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20)), _mm_add_epi64(chunk1, _b)); \ + if (reverse) { \ + _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10)), _mm_add_epi64(chunk1, _b1)); \ + _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20)), _mm_add_epi64(chunk3, _b)); \ + } else { \ + _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10)), _mm_add_epi64(chunk3, _b1)); \ + _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20)), _mm_add_epi64(chunk1, _b)); \ + } \ _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x30)), _mm_add_epi64(chunk2, _a)); \ } while (0) @@ -128,11 +133,11 @@ sqrt_result_##part += ((r2 + b > sqrt_input) ? -1 : 0) + ((r2 + (1ULL << 32) < sqrt_input - s) ? 1 : 0); \ } while (0) -# define VARIANT2_SHUFFLE(base_ptr, offset, _a, _b, _b1, _c) \ +# define VARIANT2_SHUFFLE(base_ptr, offset, _a, _b, _b1, _c, reverse) \ do { \ - const uint64x2_t chunk1 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x10))); \ + const uint64x2_t chunk1 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ (reverse ? 0x30 : 0x10)))); \ const uint64x2_t chunk2 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20))); \ - const uint64x2_t chunk3 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x30))); \ + const uint64x2_t chunk3 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ (reverse ? 0x10 : 0x30)))); \ vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x10)), vaddq_u64(chunk3, vreinterpretq_u64_u8(_b1))); \ vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20)), vaddq_u64(chunk1, vreinterpretq_u64_u8(_b))); \ vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x30)), vaddq_u64(chunk2, vreinterpretq_u64_u8(_a))); \ @@ -141,15 +146,20 @@ } \ } while (0) -# define VARIANT2_SHUFFLE2(base_ptr, offset, _a, _b, _b1, hi, lo) \ +# define VARIANT2_SHUFFLE2(base_ptr, offset, _a, _b, _b1, hi, lo, reverse) \ do { \ const uint64x2_t chunk1 = veorq_u64(vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x10))), vcombine_u64(vcreate_u64(hi), vcreate_u64(lo))); \ const uint64x2_t chunk2 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20))); \ hi ^= ((uint64_t*)((base_ptr) + ((offset) ^ 0x20)))[0]; \ lo ^= ((uint64_t*)((base_ptr) + ((offset) ^ 0x20)))[1]; \ const uint64x2_t chunk3 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x30))); \ - vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x10)), vaddq_u64(chunk3, vreinterpretq_u64_u8(_b1))); \ - vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20)), vaddq_u64(chunk1, vreinterpretq_u64_u8(_b))); \ + if (reverse) { \ + vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x10)), vaddq_u64(chunk1, vreinterpretq_u64_u8(_b1))); \ + vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20)), vaddq_u64(chunk3, vreinterpretq_u64_u8(_b))); \ + } else { \ + vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x10)), vaddq_u64(chunk3, vreinterpretq_u64_u8(_b1))); \ + vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20)), vaddq_u64(chunk1, vreinterpretq_u64_u8(_b))); \ + } \ vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x30)), vaddq_u64(chunk2, vreinterpretq_u64_u8(_a))); \ } while (0) #endif diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index 7480fae54..4f10b2216 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -230,6 +230,18 @@ const static uint8_t test_output_rto[160] = { 0xE7, 0x81, 0x4E, 0x2A, 0xBD, 0x62, 0xC1, 0x1B, 0x7C, 0xB9, 0x33, 0x7B, 0xEE, 0x95, 0x80, 0xB3 }; +const static uint8_t test_output_rwz[160] = { + 0x5f, 0x56, 0xc6, 0xb0, 0x99, 0x6b, 0xa2, 0x3e, 0x0b, 0xba, 0x07, 0x29, 0xc9, 0x90, 0x74, 0x85, + 0x5a, 0x10, 0xe3, 0x08, 0x7f, 0xdb, 0xfe, 0x94, 0x75, 0x33, 0x54, 0x73, 0x76, 0xf0, 0x75, 0xb8, + 0x8b, 0x70, 0x43, 0x9a, 0xfc, 0xf5, 0xeb, 0x15, 0xbb, 0xf9, 0xad, 0x9d, 0x2a, 0xbd, 0x72, 0x52, + 0x49, 0x54, 0x0b, 0x91, 0xea, 0x61, 0x7f, 0x98, 0x7d, 0x39, 0x17, 0xb7, 0xd7, 0x65, 0xff, 0x75, + 0x13, 0x21, 0x1d, 0xce, 0x61, 0x5a, 0xdc, 0x5f, 0x8c, 0xcb, 0x1f, 0x6f, 0xbb, 0x92, 0x88, 0xc3, + 0xe3, 0xe2, 0xfc, 0x4f, 0x62, 0xfb, 0xf0, 0x48, 0x02, 0x01, 0xd3, 0xbe, 0x77, 0x6a, 0x40, 0xca, + 0x9a, 0xe9, 0xba, 0x0c, 0xc0, 0x2b, 0x11, 0xf6, 0x9b, 0xee, 0x24, 0x3a, 0xd8, 0x86, 0x18, 0xd0, + 0xe8, 0xeb, 0xcb, 0x38, 0x2c, 0xf5, 0x99, 0x83, 0x14, 0x7b, 0x0c, 0x20, 0xbe, 0x50, 0xf4, 0x87, + 0x83, 0x41, 0x75, 0xd8, 0xd1, 0xdd, 0x4b, 0x73, 0xb3, 0x92, 0x8f, 0xe6, 0x1c, 0x72, 0x70, 0xf5, + 0x7c, 0xf6, 0x23, 0x3a, 0xb4, 0x5f, 0xdf, 0xde, 0xa6, 0x5a, 0x58, 0xec, 0x13, 0x5a, 0x23, 0x2f, +}; #ifndef XMRIG_NO_AEON // "cn-lite/0" diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index e53a4dbeb..5c4de441f 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -531,7 +531,7 @@ template static inline void cryptonight_monero_tweak(uint64_t* mem_out, const uint8_t* l, uint64_t idx, __m128i ax0, __m128i bx0, __m128i bx1, __m128i& cx) { if (BASE == xmrig::VARIANT_2) { - VARIANT2_SHUFFLE(l, idx, ax0, bx0, bx1, cx); + VARIANT2_SHUFFLE(l, idx, ax0, bx0, bx1, cx, (VARIANT == xmrig::VARIANT_RWZ ? 1 : 0)); _mm_store_si128((__m128i *)mem_out, _mm_xor_si128(bx0, cx)); } else { __m128i tmp = _mm_xor_si128(bx0, cx); @@ -653,9 +653,9 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si if (BASE == xmrig::VARIANT_2) { if (VARIANT == xmrig::VARIANT_4) { - VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx0, bx1, cx); + VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx0, bx1, cx, 0); } else { - VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx0, bx1, hi, lo); + VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx0, bx1, hi, lo, (VARIANT == xmrig::VARIANT_RWZ ? 1 : 0)); } } @@ -754,6 +754,8 @@ extern "C" void cnv2_mainloop_ivybridge_asm(cryptonight_ctx *ctx); extern "C" void cnv2_mainloop_ryzen_asm(cryptonight_ctx *ctx); extern "C" void cnv2_mainloop_bulldozer_asm(cryptonight_ctx *ctx); extern "C" void cnv2_double_mainloop_sandybridge_asm(cryptonight_ctx* ctx0, cryptonight_ctx* ctx1); +extern "C" void cnv2_rwz_mainloop_asm(cryptonight_ctx *ctx); +extern "C" void cnv2_rwz_double_mainloop_asm(cryptonight_ctx* ctx0, cryptonight_ctx* ctx1); extern xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ivybridge_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ryzen_asm; @@ -843,6 +845,9 @@ inline void cryptonight_single_hash_asm(const uint8_t *__restrict__ input, size_ cn_trtl_mainloop_bulldozer_asm(ctx[0]); } } + else if (VARIANT == xmrig::VARIANT_RWZ) { + cnv2_rwz_mainloop_asm(ctx[0]); + } else if (xmrig::cn_is_cryptonight_r()) { ctx[0]->generated_code(ctx[0]); } @@ -881,6 +886,9 @@ inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_ else if (VARIANT == xmrig::VARIANT_TRTL) { cn_trtl_double_mainloop_sandybridge_asm(ctx[0], ctx[1]); } + else if (VARIANT == xmrig::VARIANT_RWZ) { + cnv2_rwz_double_mainloop_asm(ctx[0], ctx[1]); + } else if (xmrig::cn_is_cryptonight_r()) { ctx[0]->generated_code_double(ctx[0], ctx[1]); } @@ -995,9 +1003,9 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si if (BASE == xmrig::VARIANT_2) { if (VARIANT == xmrig::VARIANT_4) { - VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx00, bx01, cx0); + VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx00, bx01, cx0, 0); } else { - VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx00, bx01, hi, lo); + VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx00, bx01, hi, lo, (VARIANT == xmrig::VARIANT_RWZ ? 1 : 0)); } } @@ -1051,9 +1059,9 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si if (BASE == xmrig::VARIANT_2) { if (VARIANT == xmrig::VARIANT_4) { - VARIANT2_SHUFFLE(l1, idx1 & MASK, ax1, bx10, bx11, cx1); + VARIANT2_SHUFFLE(l1, idx1 & MASK, ax1, bx10, bx11, cx1, 0); } else { - VARIANT2_SHUFFLE2(l1, idx1 & MASK, ax1, bx10, bx11, hi, lo); + VARIANT2_SHUFFLE2(l1, idx1 & MASK, ax1, bx10, bx11, hi, lo, (VARIANT == xmrig::VARIANT_RWZ ? 1 : 0)); } } @@ -1155,9 +1163,9 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si lo = __umul128(idx, cl##part, &hi); \ if (BASE == xmrig::VARIANT_2) { \ if (VARIANT == xmrig::VARIANT_4) { \ - VARIANT2_SHUFFLE(l, idx & MASK, a, b0, b1, c); \ + VARIANT2_SHUFFLE(l, idx & MASK, a, b0, b1, c, 0); \ } else { \ - VARIANT2_SHUFFLE2(l, idx & MASK, a, b0, b1, hi, lo); \ + VARIANT2_SHUFFLE2(l, idx & MASK, a, b0, b1, hi, lo, (VARIANT == xmrig::VARIANT_RWZ ? 1 : 0)); \ } \ } \ if (VARIANT == xmrig::VARIANT_4) { \ diff --git a/src/crypto/asm/cn2/cnv2_rwz_double_main_loop.inc b/src/crypto/asm/cn2/cnv2_rwz_double_main_loop.inc new file mode 100644 index 000000000..d2d871732 --- /dev/null +++ b/src/crypto/asm/cn2/cnv2_rwz_double_main_loop.inc @@ -0,0 +1,410 @@ + mov rax, rsp + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 184 + + stmxcsr DWORD PTR [rsp+272] + mov DWORD PTR [rsp+276], 24448 + ldmxcsr DWORD PTR [rsp+276] + + mov r13, QWORD PTR [rcx+224] + mov r9, rdx + mov r10, QWORD PTR [rcx+32] + mov r8, rcx + xor r10, QWORD PTR [rcx] + mov r14d, 393216 + mov r11, QWORD PTR [rcx+40] + xor r11, QWORD PTR [rcx+8] + mov rsi, QWORD PTR [rdx+224] + mov rdx, QWORD PTR [rcx+56] + xor rdx, QWORD PTR [rcx+24] + mov rdi, QWORD PTR [r9+32] + xor rdi, QWORD PTR [r9] + mov rbp, QWORD PTR [r9+40] + xor rbp, QWORD PTR [r9+8] + movq xmm0, rdx + movaps XMMWORD PTR [rax-88], xmm6 + movaps XMMWORD PTR [rax-104], xmm7 + movaps XMMWORD PTR [rax-120], xmm8 + movaps XMMWORD PTR [rsp+112], xmm9 + movaps XMMWORD PTR [rsp+96], xmm10 + movaps XMMWORD PTR [rsp+80], xmm11 + movaps XMMWORD PTR [rsp+64], xmm12 + movaps XMMWORD PTR [rsp+48], xmm13 + movaps XMMWORD PTR [rsp+32], xmm14 + movaps XMMWORD PTR [rsp+16], xmm15 + mov rdx, r10 + movq xmm4, QWORD PTR [r8+96] + and edx, 2097136 + mov rax, QWORD PTR [rcx+48] + xorps xmm13, xmm13 + xor rax, QWORD PTR [rcx+16] + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r8+72] + movq xmm5, QWORD PTR [r8+104] + movq xmm7, rax + + mov eax, 1 + shl rax, 52 + movq xmm14, rax + punpcklqdq xmm14, xmm14 + + mov eax, 1023 + shl rax, 52 + movq xmm12, rax + punpcklqdq xmm12, xmm12 + + mov rax, QWORD PTR [r8+80] + xor rax, QWORD PTR [r8+64] + punpcklqdq xmm7, xmm0 + movq xmm0, rcx + mov rcx, QWORD PTR [r9+56] + xor rcx, QWORD PTR [r9+24] + movq xmm3, rax + mov rax, QWORD PTR [r9+48] + xor rax, QWORD PTR [r9+16] + punpcklqdq xmm3, xmm0 + movq xmm0, rcx + mov QWORD PTR [rsp], r13 + mov rcx, QWORD PTR [r9+88] + xor rcx, QWORD PTR [r9+72] + movq xmm6, rax + mov rax, QWORD PTR [r9+80] + xor rax, QWORD PTR [r9+64] + punpcklqdq xmm6, xmm0 + movq xmm0, rcx + mov QWORD PTR [rsp+256], r10 + mov rcx, rdi + mov QWORD PTR [rsp+264], r11 + movq xmm8, rax + and ecx, 2097136 + punpcklqdq xmm8, xmm0 + movq xmm0, QWORD PTR [r9+96] + punpcklqdq xmm4, xmm0 + movq xmm0, QWORD PTR [r9+104] + lea r8, QWORD PTR [rcx+rsi] + movdqu xmm11, XMMWORD PTR [r8] + punpcklqdq xmm5, xmm0 + lea r9, QWORD PTR [rdx+r13] + movdqu xmm15, XMMWORD PTR [r9] + + ALIGN(64) +rwz_main_loop_double: + movdqu xmm9, xmm15 + mov eax, edx + mov ebx, edx + xor eax, 16 + xor ebx, 32 + xor edx, 48 + + movq xmm0, r11 + movq xmm2, r10 + punpcklqdq xmm2, xmm0 + aesenc xmm9, xmm2 + + movdqu xmm0, XMMWORD PTR [rdx+r13] + movdqu xmm1, XMMWORD PTR [rbx+r13] + paddq xmm0, xmm7 + paddq xmm1, xmm2 + movdqu XMMWORD PTR [rbx+r13], xmm0 + movdqu xmm0, XMMWORD PTR [rax+r13] + movdqu XMMWORD PTR [rdx+r13], xmm1 + paddq xmm0, xmm3 + movdqu XMMWORD PTR [rax+r13], xmm0 + + movq r11, xmm9 + mov edx, r11d + and edx, 2097136 + movdqa xmm0, xmm9 + pxor xmm0, xmm7 + movdqu XMMWORD PTR [r9], xmm0 + + lea rbx, QWORD PTR [rdx+r13] + mov r10, QWORD PTR [rdx+r13] + + movdqu xmm10, xmm11 + movq xmm0, rbp + movq xmm11, rdi + punpcklqdq xmm11, xmm0 + aesenc xmm10, xmm11 + + mov eax, ecx + mov r12d, ecx + xor eax, 16 + xor r12d, 32 + xor ecx, 48 + + movdqu xmm0, XMMWORD PTR [rcx+rsi] + paddq xmm0, xmm6 + movdqu xmm1, XMMWORD PTR [r12+rsi] + movdqu XMMWORD PTR [r12+rsi], xmm0 + paddq xmm1, xmm11 + movdqu xmm0, XMMWORD PTR [rax+rsi] + movdqu XMMWORD PTR [rcx+rsi], xmm1 + paddq xmm0, xmm8 + movdqu XMMWORD PTR [rax+rsi], xmm0 + + movq rcx, xmm10 + and ecx, 2097136 + + movdqa xmm0, xmm10 + pxor xmm0, xmm6 + movdqu XMMWORD PTR [r8], xmm0 + mov r12, QWORD PTR [rcx+rsi] + + mov r9, QWORD PTR [rbx+8] + + xor edx, 16 + mov r8d, edx + mov r15d, edx + + movq rdx, xmm5 + shl rdx, 32 + movq rax, xmm4 + xor rdx, rax + xor r10, rdx + mov rax, r10 + mul r11 + mov r11d, r8d + xor r11d, 48 + movq xmm0, rdx + xor rdx, [r11+r13] + movq xmm1, rax + xor rax, [r11+r13+8] + punpcklqdq xmm0, xmm1 + + pxor xmm0, XMMWORD PTR [r8+r13] + movdqu xmm1, XMMWORD PTR [r11+r13] + paddq xmm0, xmm3 + paddq xmm1, xmm2 + movdqu XMMWORD PTR [r8+r13], xmm0 + xor r8d, 32 + movdqu xmm0, XMMWORD PTR [r8+r13] + movdqu XMMWORD PTR [r8+r13], xmm1 + paddq xmm0, xmm7 + movdqu XMMWORD PTR [r11+r13], xmm0 + + mov r11, QWORD PTR [rsp+256] + add r11, rdx + mov rdx, QWORD PTR [rsp+264] + add rdx, rax + mov QWORD PTR [rbx], r11 + xor r11, r10 + mov QWORD PTR [rbx+8], rdx + xor rdx, r9 + mov QWORD PTR [rsp+256], r11 + and r11d, 2097136 + mov QWORD PTR [rsp+264], rdx + mov QWORD PTR [rsp+8], r11 + lea r15, QWORD PTR [r11+r13] + movdqu xmm15, XMMWORD PTR [r11+r13] + lea r13, QWORD PTR [rsi+rcx] + movdqa xmm0, xmm5 + psrldq xmm0, 8 + movaps xmm2, xmm13 + movq r10, xmm0 + psllq xmm5, 1 + shl r10, 32 + movdqa xmm0, xmm9 + psrldq xmm0, 8 + movdqa xmm1, xmm10 + movq r11, xmm0 + psrldq xmm1, 8 + movq r8, xmm1 + psrldq xmm4, 8 + movaps xmm0, xmm13 + movq rax, xmm4 + xor r10, rax + movaps xmm1, xmm13 + xor r10, r12 + lea rax, QWORD PTR [r11+1] + shr rax, 1 + movdqa xmm3, xmm9 + punpcklqdq xmm3, xmm10 + paddq xmm5, xmm3 + movq rdx, xmm5 + psrldq xmm5, 8 + cvtsi2sd xmm2, rax + or edx, -2147483647 + lea rax, QWORD PTR [r8+1] + shr rax, 1 + movq r9, xmm5 + cvtsi2sd xmm0, rax + or r9d, -2147483647 + cvtsi2sd xmm1, rdx + unpcklpd xmm2, xmm0 + movaps xmm0, xmm13 + cvtsi2sd xmm0, r9 + unpcklpd xmm1, xmm0 + divpd xmm2, xmm1 + paddq xmm2, xmm14 + cvttsd2si rax, xmm2 + psrldq xmm2, 8 + mov rbx, rax + imul rax, rdx + sub r11, rax + js rwz_div_fix_1 +rwz_div_fix_1_ret: + + cvttsd2si rdx, xmm2 + mov rax, rdx + imul rax, r9 + movd xmm2, r11d + movd xmm4, ebx + sub r8, rax + js rwz_div_fix_2 +rwz_div_fix_2_ret: + + movd xmm1, r8d + movd xmm0, edx + punpckldq xmm2, xmm1 + punpckldq xmm4, xmm0 + punpckldq xmm4, xmm2 + paddq xmm3, xmm4 + movdqa xmm0, xmm3 + psrlq xmm0, 12 + paddq xmm0, xmm12 + sqrtpd xmm1, xmm0 + movq r9, xmm1 + movdqa xmm5, xmm1 + psrlq xmm5, 19 + test r9, 524287 + je rwz_sqrt_fix_1 +rwz_sqrt_fix_1_ret: + + movq r9, xmm10 + psrldq xmm1, 8 + movq r8, xmm1 + test r8, 524287 + je rwz_sqrt_fix_2 +rwz_sqrt_fix_2_ret: + + mov r12d, ecx + mov r8d, ecx + xor r12d, 16 + xor r8d, 32 + xor ecx, 48 + mov rax, r10 + mul r9 + movq xmm0, rax + movq xmm3, rdx + punpcklqdq xmm3, xmm0 + + movdqu xmm0, XMMWORD PTR [r12+rsi] + pxor xmm0, xmm3 + movdqu xmm1, XMMWORD PTR [r8+rsi] + xor rdx, [r8+rsi] + xor rax, [r8+rsi+8] + movdqu xmm3, XMMWORD PTR [rcx+rsi] + paddq xmm3, xmm6 + paddq xmm1, xmm11 + paddq xmm0, xmm8 + movdqu XMMWORD PTR [r8+rsi], xmm3 + movdqu XMMWORD PTR [rcx+rsi], xmm1 + movdqu XMMWORD PTR [r12+rsi], xmm0 + + add rdi, rdx + mov QWORD PTR [r13], rdi + xor rdi, r10 + mov ecx, edi + and ecx, 2097136 + lea r8, QWORD PTR [rcx+rsi] + + mov rdx, QWORD PTR [r13+8] + add rbp, rax + mov QWORD PTR [r13+8], rbp + movdqu xmm11, XMMWORD PTR [rcx+rsi] + xor rbp, rdx + mov r13, QWORD PTR [rsp] + movdqa xmm3, xmm7 + mov rdx, QWORD PTR [rsp+8] + movdqa xmm8, xmm6 + mov r10, QWORD PTR [rsp+256] + movdqa xmm7, xmm9 + mov r11, QWORD PTR [rsp+264] + movdqa xmm6, xmm10 + mov r9, r15 + dec r14d + jne rwz_main_loop_double + + ldmxcsr DWORD PTR [rsp+272] + movaps xmm13, XMMWORD PTR [rsp+48] + lea r11, QWORD PTR [rsp+184] + movaps xmm6, XMMWORD PTR [r11-24] + movaps xmm7, XMMWORD PTR [r11-40] + movaps xmm8, XMMWORD PTR [r11-56] + movaps xmm9, XMMWORD PTR [r11-72] + movaps xmm10, XMMWORD PTR [r11-88] + movaps xmm11, XMMWORD PTR [r11-104] + movaps xmm12, XMMWORD PTR [r11-120] + movaps xmm14, XMMWORD PTR [rsp+32] + movaps xmm15, XMMWORD PTR [rsp+16] + mov rsp, r11 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + pop rbx + jmp rwz_cnv2_double_mainloop_asm_endp + +rwz_div_fix_1: + dec rbx + add r11, rdx + jmp rwz_div_fix_1_ret + +rwz_div_fix_2: + dec rdx + add r8, r9 + jmp rwz_div_fix_2_ret + +rwz_sqrt_fix_1: + movq r8, xmm3 + movdqa xmm0, xmm5 + psrldq xmm0, 8 + dec r9 + mov r11d, -1022 + shl r11, 32 + mov rax, r9 + shr r9, 19 + shr rax, 20 + mov rdx, r9 + sub rdx, rax + lea rdx, [rdx+r11+1] + add rax, r11 + imul rdx, rax + sub rdx, r8 + adc r9, 0 + movq xmm5, r9 + punpcklqdq xmm5, xmm0 + jmp rwz_sqrt_fix_1_ret + +rwz_sqrt_fix_2: + psrldq xmm3, 8 + movq r11, xmm3 + dec r8 + mov ebx, -1022 + shl rbx, 32 + mov rax, r8 + shr r8, 19 + shr rax, 20 + mov rdx, r8 + sub rdx, rax + lea rdx, [rdx+rbx+1] + add rax, rbx + imul rdx, rax + sub rdx, r11 + adc r8, 0 + movq xmm0, r8 + punpcklqdq xmm5, xmm0 + jmp rwz_sqrt_fix_2_ret + +rwz_cnv2_double_mainloop_asm_endp: diff --git a/src/crypto/asm/cn2/cnv2_rwz_main_loop.inc b/src/crypto/asm/cn2/cnv2_rwz_main_loop.inc new file mode 100644 index 000000000..021f787e3 --- /dev/null +++ b/src/crypto/asm/cn2/cnv2_rwz_main_loop.inc @@ -0,0 +1,186 @@ + mov QWORD PTR [rsp+24], rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 80 + + stmxcsr DWORD PTR [rsp] + mov DWORD PTR [rsp+4], 24448 + ldmxcsr DWORD PTR [rsp+4] + + mov rax, QWORD PTR [rcx+48] + mov r9, rcx + xor rax, QWORD PTR [rcx+16] + mov esi, 393216 + mov r8, QWORD PTR [rcx+32] + mov r13d, -2147483647 + xor r8, QWORD PTR [rcx] + mov r11, QWORD PTR [rcx+40] + mov r10, r8 + mov rdx, QWORD PTR [rcx+56] + movq xmm4, rax + xor rdx, QWORD PTR [rcx+24] + xor r11, QWORD PTR [rcx+8] + mov rbx, QWORD PTR [rcx+224] + mov rax, QWORD PTR [r9+80] + xor rax, QWORD PTR [r9+64] + movq xmm0, rdx + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r9+72] + movq xmm3, QWORD PTR [r9+104] + movaps XMMWORD PTR [rsp+64], xmm6 + movaps XMMWORD PTR [rsp+48], xmm7 + movaps XMMWORD PTR [rsp+32], xmm8 + and r10d, 2097136 + movq xmm5, rax + + xor eax, eax + mov QWORD PTR [rsp+16], rax + + mov ax, 1023 + shl rax, 52 + movq xmm8, rax + mov r15, QWORD PTR [r9+96] + punpcklqdq xmm4, xmm0 + movq xmm0, rcx + punpcklqdq xmm5, xmm0 + movdqu xmm6, XMMWORD PTR [r10+rbx] + + ALIGN(64) +rwz_main_loop: + lea rdx, QWORD PTR [r10+rbx] + mov ecx, r10d + mov eax, r10d + mov rdi, r15 + xor ecx, 16 + xor eax, 32 + xor r10d, 48 + movq xmm0, r11 + movq xmm7, r8 + punpcklqdq xmm7, xmm0 + aesenc xmm6, xmm7 + movq rbp, xmm6 + mov r9, rbp + and r9d, 2097136 + movdqu xmm0, XMMWORD PTR [rcx+rbx] + movdqu xmm1, XMMWORD PTR [rax+rbx] + movdqu xmm2, XMMWORD PTR [r10+rbx] + paddq xmm0, xmm5 + paddq xmm1, xmm7 + paddq xmm2, xmm4 + movdqu XMMWORD PTR [rcx+rbx], xmm0 + movdqu XMMWORD PTR [rax+rbx], xmm2 + movdqu XMMWORD PTR [r10+rbx], xmm1 + mov r10, r9 + xor r10d, 32 + movq rcx, xmm3 + mov rax, rcx + shl rax, 32 + xor rdi, rax + movdqa xmm0, xmm6 + pxor xmm0, xmm4 + movdqu XMMWORD PTR [rdx], xmm0 + xor rdi, QWORD PTR [r9+rbx] + lea r14, QWORD PTR [r9+rbx] + mov r12, QWORD PTR [r14+8] + xor edx, edx + lea r9d, DWORD PTR [ecx+ecx] + add r9d, ebp + movdqa xmm0, xmm6 + psrldq xmm0, 8 + or r9d, r13d + movq rax, xmm0 + div r9 + xorps xmm3, xmm3 + mov eax, eax + shl rdx, 32 + add rdx, rax + lea r9, QWORD PTR [rdx+rbp] + mov r15, rdx + mov rax, r9 + shr rax, 12 + movq xmm0, rax + paddq xmm0, xmm8 + sqrtsd xmm3, xmm0 + psubq xmm3, XMMWORD PTR [rsp+16] + movq rdx, xmm3 + test edx, 524287 + je rwz_sqrt_fixup + psrlq xmm3, 19 +rwz_sqrt_fixup_ret: + + mov ecx, r10d + mov rax, rdi + mul rbp + movq xmm2, rdx + xor rdx, [rcx+rbx] + add r8, rdx + mov QWORD PTR [r14], r8 + xor r8, rdi + mov edi, r8d + and edi, 2097136 + movq xmm0, rax + xor rax, [rcx+rbx+8] + add r11, rax + mov QWORD PTR [r14+8], r11 + punpcklqdq xmm2, xmm0 + + mov r9d, r10d + xor r9d, 48 + xor r10d, 16 + pxor xmm2, XMMWORD PTR [r9+rbx] + movdqu xmm0, XMMWORD PTR [r10+rbx] + paddq xmm0, xmm4 + movdqu xmm1, XMMWORD PTR [rcx+rbx] + paddq xmm2, xmm5 + paddq xmm1, xmm7 + movdqa xmm5, xmm4 + movdqu XMMWORD PTR [r9+rbx], xmm2 + movdqa xmm4, xmm6 + movdqu XMMWORD PTR [rcx+rbx], xmm0 + movdqu XMMWORD PTR [r10+rbx], xmm1 + movdqu xmm6, [rdi+rbx] + mov r10d, edi + xor r11, r12 + dec rsi + jne rwz_main_loop + + ldmxcsr DWORD PTR [rsp] + mov rbx, QWORD PTR [rsp+160] + movaps xmm6, XMMWORD PTR [rsp+64] + movaps xmm7, XMMWORD PTR [rsp+48] + movaps xmm8, XMMWORD PTR [rsp+32] + add rsp, 80 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + jmp cnv2_rwz_main_loop_endp + +rwz_sqrt_fixup: + dec rdx + mov r13d, -1022 + shl r13, 32 + mov rax, rdx + shr rdx, 19 + shr rax, 20 + mov rcx, rdx + sub rcx, rax + add rax, r13 + not r13 + sub rcx, r13 + mov r13d, -2147483647 + imul rcx, rax + sub rcx, r9 + adc rdx, 0 + movq xmm3, rdx + jmp rwz_sqrt_fixup_ret + +cnv2_rwz_main_loop_endp: diff --git a/src/crypto/asm/cn_main_loop.S b/src/crypto/asm/cn_main_loop.S index a792337f0..c2c08739a 100644 --- a/src/crypto/asm/cn_main_loop.S +++ b/src/crypto/asm/cn_main_loop.S @@ -15,6 +15,8 @@ .global FN_PREFIX(cnv2_mainloop_ryzen_asm) .global FN_PREFIX(cnv2_mainloop_bulldozer_asm) .global FN_PREFIX(cnv2_double_mainloop_sandybridge_asm) +.global FN_PREFIX(cnv2_rwz_mainloop_asm) +.global FN_PREFIX(cnv2_rwz_double_mainloop_asm) ALIGN(64) FN_PREFIX(cnv2_mainloop_ivybridge_asm): @@ -52,3 +54,21 @@ FN_PREFIX(cnv2_double_mainloop_sandybridge_asm): add rsp, 48 ret 0 mov eax, 3735929054 + +ALIGN(64) +FN_PREFIX(cnv2_rwz_mainloop_asm): + sub rsp, 48 + mov rcx, rdi + #include "cn2/cnv2_rwz_main_loop.inc" + add rsp, 48 + ret 0 + mov eax, 3735929054 + +ALIGN(64) +FN_PREFIX(cnv2_rwz_double_mainloop_asm): + sub rsp, 48 + mov rcx, rdi + #include "cn2/cnv2_rwz_double_main_loop.inc" + add rsp, 48 + ret 0 + mov eax, 3735929054 diff --git a/src/crypto/asm/cn_main_loop.asm b/src/crypto/asm/cn_main_loop.asm index f1384be80..f0766a7c7 100644 --- a/src/crypto/asm/cn_main_loop.asm +++ b/src/crypto/asm/cn_main_loop.asm @@ -3,6 +3,8 @@ PUBLIC cnv2_mainloop_ivybridge_asm PUBLIC cnv2_mainloop_ryzen_asm PUBLIC cnv2_mainloop_bulldozer_asm PUBLIC cnv2_double_mainloop_sandybridge_asm +PUBLIC cnv2_rwz_mainloop_asm +PUBLIC cnv2_rwz_double_mainloop_asm ALIGN(64) cnv2_mainloop_ivybridge_asm PROC @@ -32,5 +34,19 @@ cnv2_double_mainloop_sandybridge_asm PROC mov eax, 3735929054 cnv2_double_mainloop_sandybridge_asm ENDP +ALIGN(64) +cnv2_rwz_mainloop_asm PROC + INCLUDE cn2/cnv2_rwz_main_loop.inc + ret 0 + mov eax, 3735929054 +cnv2_rwz_mainloop_asm ENDP + +ALIGN(64) +cnv2_rwz_double_mainloop_asm PROC + INCLUDE cn2/cnv2_rwz_double_main_loop.inc + ret 0 + mov eax, 3735929054 +cnv2_rwz_double_mainloop_asm ENDP + _TEXT_CNV2_MAINLOOP ENDS END diff --git a/src/crypto/asm/win64/cn2/cnv2_rwz_double_main_loop.inc b/src/crypto/asm/win64/cn2/cnv2_rwz_double_main_loop.inc new file mode 100644 index 000000000..69ca8793c --- /dev/null +++ b/src/crypto/asm/win64/cn2/cnv2_rwz_double_main_loop.inc @@ -0,0 +1,410 @@ + mov rax, rsp + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 184 + + stmxcsr DWORD PTR [rsp+272] + mov DWORD PTR [rsp+276], 24448 + ldmxcsr DWORD PTR [rsp+276] + + mov r13, QWORD PTR [rcx+224] + mov r9, rdx + mov r10, QWORD PTR [rcx+32] + mov r8, rcx + xor r10, QWORD PTR [rcx] + mov r14d, 393216 + mov r11, QWORD PTR [rcx+40] + xor r11, QWORD PTR [rcx+8] + mov rsi, QWORD PTR [rdx+224] + mov rdx, QWORD PTR [rcx+56] + xor rdx, QWORD PTR [rcx+24] + mov rdi, QWORD PTR [r9+32] + xor rdi, QWORD PTR [r9] + mov rbp, QWORD PTR [r9+40] + xor rbp, QWORD PTR [r9+8] + movd xmm0, rdx + movaps XMMWORD PTR [rax-88], xmm6 + movaps XMMWORD PTR [rax-104], xmm7 + movaps XMMWORD PTR [rax-120], xmm8 + movaps XMMWORD PTR [rsp+112], xmm9 + movaps XMMWORD PTR [rsp+96], xmm10 + movaps XMMWORD PTR [rsp+80], xmm11 + movaps XMMWORD PTR [rsp+64], xmm12 + movaps XMMWORD PTR [rsp+48], xmm13 + movaps XMMWORD PTR [rsp+32], xmm14 + movaps XMMWORD PTR [rsp+16], xmm15 + mov rdx, r10 + movd xmm4, QWORD PTR [r8+96] + and edx, 2097136 + mov rax, QWORD PTR [rcx+48] + xorps xmm13, xmm13 + xor rax, QWORD PTR [rcx+16] + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r8+72] + movd xmm5, QWORD PTR [r8+104] + movd xmm7, rax + + mov eax, 1 + shl rax, 52 + movd xmm14, rax + punpcklqdq xmm14, xmm14 + + mov eax, 1023 + shl rax, 52 + movd xmm12, rax + punpcklqdq xmm12, xmm12 + + mov rax, QWORD PTR [r8+80] + xor rax, QWORD PTR [r8+64] + punpcklqdq xmm7, xmm0 + movd xmm0, rcx + mov rcx, QWORD PTR [r9+56] + xor rcx, QWORD PTR [r9+24] + movd xmm3, rax + mov rax, QWORD PTR [r9+48] + xor rax, QWORD PTR [r9+16] + punpcklqdq xmm3, xmm0 + movd xmm0, rcx + mov QWORD PTR [rsp], r13 + mov rcx, QWORD PTR [r9+88] + xor rcx, QWORD PTR [r9+72] + movd xmm6, rax + mov rax, QWORD PTR [r9+80] + xor rax, QWORD PTR [r9+64] + punpcklqdq xmm6, xmm0 + movd xmm0, rcx + mov QWORD PTR [rsp+256], r10 + mov rcx, rdi + mov QWORD PTR [rsp+264], r11 + movd xmm8, rax + and ecx, 2097136 + punpcklqdq xmm8, xmm0 + movd xmm0, QWORD PTR [r9+96] + punpcklqdq xmm4, xmm0 + movd xmm0, QWORD PTR [r9+104] + lea r8, QWORD PTR [rcx+rsi] + movdqu xmm11, XMMWORD PTR [r8] + punpcklqdq xmm5, xmm0 + lea r9, QWORD PTR [rdx+r13] + movdqu xmm15, XMMWORD PTR [r9] + + ALIGN(64) +rwz_main_loop_double: + movdqu xmm9, xmm15 + mov eax, edx + mov ebx, edx + xor eax, 16 + xor ebx, 32 + xor edx, 48 + + movd xmm0, r11 + movd xmm2, r10 + punpcklqdq xmm2, xmm0 + aesenc xmm9, xmm2 + + movdqu xmm0, XMMWORD PTR [rdx+r13] + movdqu xmm1, XMMWORD PTR [rbx+r13] + paddq xmm0, xmm7 + paddq xmm1, xmm2 + movdqu XMMWORD PTR [rbx+r13], xmm0 + movdqu xmm0, XMMWORD PTR [rax+r13] + movdqu XMMWORD PTR [rdx+r13], xmm1 + paddq xmm0, xmm3 + movdqu XMMWORD PTR [rax+r13], xmm0 + + movd r11, xmm9 + mov edx, r11d + and edx, 2097136 + movdqa xmm0, xmm9 + pxor xmm0, xmm7 + movdqu XMMWORD PTR [r9], xmm0 + + lea rbx, QWORD PTR [rdx+r13] + mov r10, QWORD PTR [rdx+r13] + + movdqu xmm10, xmm11 + movd xmm0, rbp + movd xmm11, rdi + punpcklqdq xmm11, xmm0 + aesenc xmm10, xmm11 + + mov eax, ecx + mov r12d, ecx + xor eax, 16 + xor r12d, 32 + xor ecx, 48 + + movdqu xmm0, XMMWORD PTR [rcx+rsi] + paddq xmm0, xmm6 + movdqu xmm1, XMMWORD PTR [r12+rsi] + movdqu XMMWORD PTR [r12+rsi], xmm0 + paddq xmm1, xmm11 + movdqu xmm0, XMMWORD PTR [rax+rsi] + movdqu XMMWORD PTR [rcx+rsi], xmm1 + paddq xmm0, xmm8 + movdqu XMMWORD PTR [rax+rsi], xmm0 + + movd rcx, xmm10 + and ecx, 2097136 + + movdqa xmm0, xmm10 + pxor xmm0, xmm6 + movdqu XMMWORD PTR [r8], xmm0 + mov r12, QWORD PTR [rcx+rsi] + + mov r9, QWORD PTR [rbx+8] + + xor edx, 16 + mov r8d, edx + mov r15d, edx + + movd rdx, xmm5 + shl rdx, 32 + movd rax, xmm4 + xor rdx, rax + xor r10, rdx + mov rax, r10 + mul r11 + mov r11d, r8d + xor r11d, 48 + movd xmm0, rdx + xor rdx, [r11+r13] + movd xmm1, rax + xor rax, [r11+r13+8] + punpcklqdq xmm0, xmm1 + + pxor xmm0, XMMWORD PTR [r8+r13] + movdqu xmm1, XMMWORD PTR [r11+r13] + paddq xmm0, xmm3 + paddq xmm1, xmm2 + movdqu XMMWORD PTR [r8+r13], xmm0 + xor r8d, 32 + movdqu xmm0, XMMWORD PTR [r8+r13] + movdqu XMMWORD PTR [r8+r13], xmm1 + paddq xmm0, xmm7 + movdqu XMMWORD PTR [r11+r13], xmm0 + + mov r11, QWORD PTR [rsp+256] + add r11, rdx + mov rdx, QWORD PTR [rsp+264] + add rdx, rax + mov QWORD PTR [rbx], r11 + xor r11, r10 + mov QWORD PTR [rbx+8], rdx + xor rdx, r9 + mov QWORD PTR [rsp+256], r11 + and r11d, 2097136 + mov QWORD PTR [rsp+264], rdx + mov QWORD PTR [rsp+8], r11 + lea r15, QWORD PTR [r11+r13] + movdqu xmm15, XMMWORD PTR [r11+r13] + lea r13, QWORD PTR [rsi+rcx] + movdqa xmm0, xmm5 + psrldq xmm0, 8 + movaps xmm2, xmm13 + movd r10, xmm0 + psllq xmm5, 1 + shl r10, 32 + movdqa xmm0, xmm9 + psrldq xmm0, 8 + movdqa xmm1, xmm10 + movd r11, xmm0 + psrldq xmm1, 8 + movd r8, xmm1 + psrldq xmm4, 8 + movaps xmm0, xmm13 + movd rax, xmm4 + xor r10, rax + movaps xmm1, xmm13 + xor r10, r12 + lea rax, QWORD PTR [r11+1] + shr rax, 1 + movdqa xmm3, xmm9 + punpcklqdq xmm3, xmm10 + paddq xmm5, xmm3 + movd rdx, xmm5 + psrldq xmm5, 8 + cvtsi2sd xmm2, rax + or edx, -2147483647 + lea rax, QWORD PTR [r8+1] + shr rax, 1 + movd r9, xmm5 + cvtsi2sd xmm0, rax + or r9d, -2147483647 + cvtsi2sd xmm1, rdx + unpcklpd xmm2, xmm0 + movaps xmm0, xmm13 + cvtsi2sd xmm0, r9 + unpcklpd xmm1, xmm0 + divpd xmm2, xmm1 + paddq xmm2, xmm14 + cvttsd2si rax, xmm2 + psrldq xmm2, 8 + mov rbx, rax + imul rax, rdx + sub r11, rax + js rwz_div_fix_1 +rwz_div_fix_1_ret: + + cvttsd2si rdx, xmm2 + mov rax, rdx + imul rax, r9 + movd xmm2, r11d + movd xmm4, ebx + sub r8, rax + js rwz_div_fix_2 +rwz_div_fix_2_ret: + + movd xmm1, r8d + movd xmm0, edx + punpckldq xmm2, xmm1 + punpckldq xmm4, xmm0 + punpckldq xmm4, xmm2 + paddq xmm3, xmm4 + movdqa xmm0, xmm3 + psrlq xmm0, 12 + paddq xmm0, xmm12 + sqrtpd xmm1, xmm0 + movd r9, xmm1 + movdqa xmm5, xmm1 + psrlq xmm5, 19 + test r9, 524287 + je rwz_sqrt_fix_1 +rwz_sqrt_fix_1_ret: + + movd r9, xmm10 + psrldq xmm1, 8 + movd r8, xmm1 + test r8, 524287 + je rwz_sqrt_fix_2 +rwz_sqrt_fix_2_ret: + + mov r12d, ecx + mov r8d, ecx + xor r12d, 16 + xor r8d, 32 + xor ecx, 48 + mov rax, r10 + mul r9 + movd xmm0, rax + movd xmm3, rdx + punpcklqdq xmm3, xmm0 + + movdqu xmm0, XMMWORD PTR [r12+rsi] + pxor xmm0, xmm3 + movdqu xmm1, XMMWORD PTR [r8+rsi] + xor rdx, [r8+rsi] + xor rax, [r8+rsi+8] + movdqu xmm3, XMMWORD PTR [rcx+rsi] + paddq xmm3, xmm6 + paddq xmm1, xmm11 + paddq xmm0, xmm8 + movdqu XMMWORD PTR [r8+rsi], xmm3 + movdqu XMMWORD PTR [rcx+rsi], xmm1 + movdqu XMMWORD PTR [r12+rsi], xmm0 + + add rdi, rdx + mov QWORD PTR [r13], rdi + xor rdi, r10 + mov ecx, edi + and ecx, 2097136 + lea r8, QWORD PTR [rcx+rsi] + + mov rdx, QWORD PTR [r13+8] + add rbp, rax + mov QWORD PTR [r13+8], rbp + movdqu xmm11, XMMWORD PTR [rcx+rsi] + xor rbp, rdx + mov r13, QWORD PTR [rsp] + movdqa xmm3, xmm7 + mov rdx, QWORD PTR [rsp+8] + movdqa xmm8, xmm6 + mov r10, QWORD PTR [rsp+256] + movdqa xmm7, xmm9 + mov r11, QWORD PTR [rsp+264] + movdqa xmm6, xmm10 + mov r9, r15 + dec r14d + jne rwz_main_loop_double + + ldmxcsr DWORD PTR [rsp+272] + movaps xmm13, XMMWORD PTR [rsp+48] + lea r11, QWORD PTR [rsp+184] + movaps xmm6, XMMWORD PTR [r11-24] + movaps xmm7, XMMWORD PTR [r11-40] + movaps xmm8, XMMWORD PTR [r11-56] + movaps xmm9, XMMWORD PTR [r11-72] + movaps xmm10, XMMWORD PTR [r11-88] + movaps xmm11, XMMWORD PTR [r11-104] + movaps xmm12, XMMWORD PTR [r11-120] + movaps xmm14, XMMWORD PTR [rsp+32] + movaps xmm15, XMMWORD PTR [rsp+16] + mov rsp, r11 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + pop rbx + jmp rwz_cnv2_double_mainloop_asm_endp + +rwz_div_fix_1: + dec rbx + add r11, rdx + jmp rwz_div_fix_1_ret + +rwz_div_fix_2: + dec rdx + add r8, r9 + jmp rwz_div_fix_2_ret + +rwz_sqrt_fix_1: + movd r8, xmm3 + movdqa xmm0, xmm5 + psrldq xmm0, 8 + dec r9 + mov r11d, -1022 + shl r11, 32 + mov rax, r9 + shr r9, 19 + shr rax, 20 + mov rdx, r9 + sub rdx, rax + lea rdx, [rdx+r11+1] + add rax, r11 + imul rdx, rax + sub rdx, r8 + adc r9, 0 + movd xmm5, r9 + punpcklqdq xmm5, xmm0 + jmp rwz_sqrt_fix_1_ret + +rwz_sqrt_fix_2: + psrldq xmm3, 8 + movd r11, xmm3 + dec r8 + mov ebx, -1022 + shl rbx, 32 + mov rax, r8 + shr r8, 19 + shr rax, 20 + mov rdx, r8 + sub rdx, rax + lea rdx, [rdx+rbx+1] + add rax, rbx + imul rdx, rax + sub rdx, r11 + adc r8, 0 + movd xmm0, r8 + punpcklqdq xmm5, xmm0 + jmp rwz_sqrt_fix_2_ret + +rwz_cnv2_double_mainloop_asm_endp: diff --git a/src/crypto/asm/win64/cn2/cnv2_rwz_main_loop.inc b/src/crypto/asm/win64/cn2/cnv2_rwz_main_loop.inc new file mode 100644 index 000000000..993177305 --- /dev/null +++ b/src/crypto/asm/win64/cn2/cnv2_rwz_main_loop.inc @@ -0,0 +1,186 @@ + mov QWORD PTR [rsp+24], rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 80 + + stmxcsr DWORD PTR [rsp] + mov DWORD PTR [rsp+4], 24448 + ldmxcsr DWORD PTR [rsp+4] + + mov rax, QWORD PTR [rcx+48] + mov r9, rcx + xor rax, QWORD PTR [rcx+16] + mov esi, 393216 + mov r8, QWORD PTR [rcx+32] + mov r13d, -2147483647 + xor r8, QWORD PTR [rcx] + mov r11, QWORD PTR [rcx+40] + mov r10, r8 + mov rdx, QWORD PTR [rcx+56] + movd xmm4, rax + xor rdx, QWORD PTR [rcx+24] + xor r11, QWORD PTR [rcx+8] + mov rbx, QWORD PTR [rcx+224] + mov rax, QWORD PTR [r9+80] + xor rax, QWORD PTR [r9+64] + movd xmm0, rdx + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r9+72] + movd xmm3, QWORD PTR [r9+104] + movaps XMMWORD PTR [rsp+64], xmm6 + movaps XMMWORD PTR [rsp+48], xmm7 + movaps XMMWORD PTR [rsp+32], xmm8 + and r10d, 2097136 + movd xmm5, rax + + xor eax, eax + mov QWORD PTR [rsp+16], rax + + mov ax, 1023 + shl rax, 52 + movd xmm8, rax + mov r15, QWORD PTR [r9+96] + punpcklqdq xmm4, xmm0 + movd xmm0, rcx + punpcklqdq xmm5, xmm0 + movdqu xmm6, XMMWORD PTR [r10+rbx] + + ALIGN(64) +rwz_main_loop: + lea rdx, QWORD PTR [r10+rbx] + mov ecx, r10d + mov eax, r10d + mov rdi, r15 + xor ecx, 16 + xor eax, 32 + xor r10d, 48 + movd xmm0, r11 + movd xmm7, r8 + punpcklqdq xmm7, xmm0 + aesenc xmm6, xmm7 + movd rbp, xmm6 + mov r9, rbp + and r9d, 2097136 + movdqu xmm0, XMMWORD PTR [rcx+rbx] + movdqu xmm1, XMMWORD PTR [rax+rbx] + movdqu xmm2, XMMWORD PTR [r10+rbx] + paddq xmm0, xmm5 + paddq xmm1, xmm7 + paddq xmm2, xmm4 + movdqu XMMWORD PTR [rcx+rbx], xmm0 + movdqu XMMWORD PTR [rax+rbx], xmm2 + movdqu XMMWORD PTR [r10+rbx], xmm1 + mov r10, r9 + xor r10d, 32 + movd rcx, xmm3 + mov rax, rcx + shl rax, 32 + xor rdi, rax + movdqa xmm0, xmm6 + pxor xmm0, xmm4 + movdqu XMMWORD PTR [rdx], xmm0 + xor rdi, QWORD PTR [r9+rbx] + lea r14, QWORD PTR [r9+rbx] + mov r12, QWORD PTR [r14+8] + xor edx, edx + lea r9d, DWORD PTR [ecx+ecx] + add r9d, ebp + movdqa xmm0, xmm6 + psrldq xmm0, 8 + or r9d, r13d + movd rax, xmm0 + div r9 + xorps xmm3, xmm3 + mov eax, eax + shl rdx, 32 + add rdx, rax + lea r9, QWORD PTR [rdx+rbp] + mov r15, rdx + mov rax, r9 + shr rax, 12 + movd xmm0, rax + paddq xmm0, xmm8 + sqrtsd xmm3, xmm0 + psubq xmm3, XMMWORD PTR [rsp+16] + movd rdx, xmm3 + test edx, 524287 + je rwz_sqrt_fixup + psrlq xmm3, 19 +rwz_sqrt_fixup_ret: + + mov ecx, r10d + mov rax, rdi + mul rbp + movd xmm2, rdx + xor rdx, [rcx+rbx] + add r8, rdx + mov QWORD PTR [r14], r8 + xor r8, rdi + mov edi, r8d + and edi, 2097136 + movd xmm0, rax + xor rax, [rcx+rbx+8] + add r11, rax + mov QWORD PTR [r14+8], r11 + punpcklqdq xmm2, xmm0 + + mov r9d, r10d + xor r9d, 48 + xor r10d, 16 + pxor xmm2, XMMWORD PTR [r9+rbx] + movdqu xmm0, XMMWORD PTR [r10+rbx] + paddq xmm0, xmm4 + movdqu xmm1, XMMWORD PTR [rcx+rbx] + paddq xmm2, xmm5 + paddq xmm1, xmm7 + movdqa xmm5, xmm4 + movdqu XMMWORD PTR [r9+rbx], xmm2 + movdqa xmm4, xmm6 + movdqu XMMWORD PTR [rcx+rbx], xmm0 + movdqu XMMWORD PTR [r10+rbx], xmm1 + movdqu xmm6, [rdi+rbx] + mov r10d, edi + xor r11, r12 + dec rsi + jne rwz_main_loop + + ldmxcsr DWORD PTR [rsp] + mov rbx, QWORD PTR [rsp+160] + movaps xmm6, XMMWORD PTR [rsp+64] + movaps xmm7, XMMWORD PTR [rsp+48] + movaps xmm8, XMMWORD PTR [rsp+32] + add rsp, 80 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + jmp cnv2_rwz_main_loop_endp + +rwz_sqrt_fixup: + dec rdx + mov r13d, -1022 + shl r13, 32 + mov rax, rdx + shr rdx, 19 + shr rax, 20 + mov rcx, rdx + sub rcx, rax + add rax, r13 + not r13 + sub rcx, r13 + mov r13d, -2147483647 + imul rcx, rax + sub rcx, r9 + adc rdx, 0 + movd xmm3, rdx + jmp rwz_sqrt_fixup_ret + +cnv2_rwz_main_loop_endp: diff --git a/src/crypto/asm/win64/cn_main_loop.S b/src/crypto/asm/win64/cn_main_loop.S index 1200c4dfe..3c4dc020b 100644 --- a/src/crypto/asm/win64/cn_main_loop.S +++ b/src/crypto/asm/win64/cn_main_loop.S @@ -5,6 +5,8 @@ .global cnv2_mainloop_ryzen_asm .global cnv2_mainloop_bulldozer_asm .global cnv2_double_mainloop_sandybridge_asm +.global FN_PREFIX(cnv2_rwz_mainloop_asm) +.global FN_PREFIX(cnv2_rwz_double_mainloop_asm) ALIGN(64) cnv2_mainloop_ivybridge_asm: @@ -29,3 +31,21 @@ cnv2_double_mainloop_sandybridge_asm: #include "../cn2/cnv2_double_main_loop_sandybridge.inc" ret 0 mov eax, 3735929054 + +ALIGN(64) +FN_PREFIX(cnv2_rwz_mainloop_asm): + sub rsp, 48 + mov rcx, rdi + #include "cn2/cnv2_rwz_main_loop.inc" + add rsp, 48 + ret 0 + mov eax, 3735929054 + +ALIGN(64) +FN_PREFIX(cnv2_rwz_double_mainloop_asm): + sub rsp, 48 + mov rcx, rdi + #include "cn2/cnv2_rwz_double_main_loop.inc" + add rsp, 48 + ret 0 + mov eax, 3735929054 diff --git a/src/crypto/asm/win64/cn_main_loop.asm b/src/crypto/asm/win64/cn_main_loop.asm index 846b860c8..57246cf5c 100644 --- a/src/crypto/asm/win64/cn_main_loop.asm +++ b/src/crypto/asm/win64/cn_main_loop.asm @@ -3,6 +3,8 @@ PUBLIC cnv2_mainloop_ivybridge_asm PUBLIC cnv2_mainloop_ryzen_asm PUBLIC cnv2_mainloop_bulldozer_asm PUBLIC cnv2_double_mainloop_sandybridge_asm +PUBLIC cnv2_rwz_mainloop_asm +PUBLIC cnv2_rwz_double_mainloop_asm ALIGN 64 cnv2_mainloop_ivybridge_asm PROC @@ -32,5 +34,19 @@ cnv2_double_mainloop_sandybridge_asm PROC mov eax, 3735929054 cnv2_double_mainloop_sandybridge_asm ENDP +ALIGN(64) +cnv2_rwz_mainloop_asm PROC + INCLUDE cn2/cnv2_rwz_main_loop.inc + ret 0 + mov eax, 3735929054 +cnv2_rwz_mainloop_asm ENDP + +ALIGN(64) +cnv2_rwz_double_mainloop_asm PROC + INCLUDE cn2/cnv2_rwz_double_main_loop.inc + ret 0 + mov eax, 3735929054 +cnv2_rwz_double_mainloop_asm ENDP + _TEXT_CNV2_MAINLOOP ENDS END diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 6065bc3aa..dfa6518cc 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -180,6 +180,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a add_asm_func(asm_func_map); # endif + add_asm_func(asm_func_map); + asm_func_map_initialized = true; } @@ -323,6 +325,17 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + # ifndef XMRIG_NO_AEON cryptonight_single_hash, cryptonight_double_hash, @@ -358,6 +371,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a 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 # 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 @@ -373,6 +387,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a 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 # endif # ifndef XMRIG_NO_SUMO @@ -422,6 +437,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a 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 # 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 @@ -437,6 +453,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a 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 # endif # ifndef XMRIG_NO_CN_PICO @@ -465,6 +482,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a 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 # 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 @@ -480,6 +498,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a 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 # endif }; diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 1d1c75193..1bc52bf42 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -64,7 +64,8 @@ bool MultiWorker::selfTest() verify(VARIANT_RTO, test_output_rto) && verify(VARIANT_HALF, test_output_half) && verify2(VARIANT_WOW, test_output_wow) && - verify2(VARIANT_4, test_output_r); + verify2(VARIANT_4, test_output_r) && + verify(VARIANT_RWZ, test_output_rwz); # ifndef XMRIG_NO_CN_GPU if (!rc || N > 1) { From 21d9ad6dbc7243d422b99af809213f9deb6111b9 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 Mar 2019 02:11:34 +0700 Subject: [PATCH 23/55] Fix MSYS2 build. --- src/crypto/asm/win64/cn_main_loop.S | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/crypto/asm/win64/cn_main_loop.S b/src/crypto/asm/win64/cn_main_loop.S index 3c4dc020b..63c3a8ba6 100644 --- a/src/crypto/asm/win64/cn_main_loop.S +++ b/src/crypto/asm/win64/cn_main_loop.S @@ -5,8 +5,8 @@ .global cnv2_mainloop_ryzen_asm .global cnv2_mainloop_bulldozer_asm .global cnv2_double_mainloop_sandybridge_asm -.global FN_PREFIX(cnv2_rwz_mainloop_asm) -.global FN_PREFIX(cnv2_rwz_double_mainloop_asm) +.global cnv2_rwz_mainloop_asm +.global cnv2_rwz_double_mainloop_asm ALIGN(64) cnv2_mainloop_ivybridge_asm: @@ -33,19 +33,13 @@ cnv2_double_mainloop_sandybridge_asm: mov eax, 3735929054 ALIGN(64) -FN_PREFIX(cnv2_rwz_mainloop_asm): - sub rsp, 48 - mov rcx, rdi +cnv2_rwz_mainloop_asm: #include "cn2/cnv2_rwz_main_loop.inc" - add rsp, 48 ret 0 mov eax, 3735929054 ALIGN(64) -FN_PREFIX(cnv2_rwz_double_mainloop_asm): - sub rsp, 48 - mov rcx, rdi +cnv2_rwz_double_mainloop_asm: #include "cn2/cnv2_rwz_double_main_loop.inc" - add rsp, 48 ret 0 mov eax, 3735929054 From 8800219cf4f34ad164a44bfe2c33dd01947203b6 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 Mar 2019 13:10:22 +0700 Subject: [PATCH 24/55] Include ConfigLoader_default.h only if embedded enabled. --- src/common/config/ConfigLoader.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index 7124d121a..26742e5f2 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -47,13 +47,17 @@ #include "common/interfaces/IConfig.h" #include "common/Platform.h" #include "core/ConfigCreator.h" -#include "core/ConfigLoader_default.h" #include "core/ConfigLoader_platform.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" #include "rapidjson/fwd.h" +#ifdef XMRIG_FEATURE_EMBEDDED_CONFIG +# include "core/ConfigLoader_default.h" +#endif + + xmrig::ConfigWatcher *xmrig::ConfigLoader::m_watcher = nullptr; xmrig::IConfigCreator *xmrig::ConfigLoader::m_creator = nullptr; xmrig::IConfigListener *xmrig::ConfigLoader::m_listener = nullptr; From 6052da3c4399514c95245b2d342f04baa20958db Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 Mar 2019 15:03:43 +0700 Subject: [PATCH 25/55] #951 Fix AVX detection. --- src/common/cpu/BasicCpuInfo.cpp | 15 ++++++++++++++- src/core/cpu/AdvancedCpuInfo.cpp | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/common/cpu/BasicCpuInfo.cpp b/src/common/cpu/BasicCpuInfo.cpp index e9018c98a..d7778bdde 100644 --- a/src/common/cpu/BasicCpuInfo.cpp +++ b/src/common/cpu/BasicCpuInfo.cpp @@ -36,6 +36,10 @@ # define bit_AES (1 << 25) #endif +#ifndef bit_OSXSAVE +# define bit_OSXSAVE (1 << 27) +#endif + #ifndef bit_AVX2 # define bit_AVX2 (1 << 5) #endif @@ -107,10 +111,19 @@ static inline bool has_avx2() } +static inline bool has_ossave() +{ + int32_t cpu_info[4] = { 0 }; + cpuid(PROCESSOR_INFO, cpu_info); + + return (cpu_info[ECX_Reg] & bit_OSXSAVE) != 0; +} + + xmrig::BasicCpuInfo::BasicCpuInfo() : m_assembly(ASM_NONE), m_aes(has_aes_ni()), - m_avx2(has_avx2()), + m_avx2(has_avx2() && has_ossave()), m_brand(), m_threads(std::thread::hardware_concurrency()) { diff --git a/src/core/cpu/AdvancedCpuInfo.cpp b/src/core/cpu/AdvancedCpuInfo.cpp index c41378e53..df6a385ee 100644 --- a/src/core/cpu/AdvancedCpuInfo.cpp +++ b/src/core/cpu/AdvancedCpuInfo.cpp @@ -85,7 +85,7 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : } } - m_avx2 = data.flags[CPU_FEATURE_AVX2]; + m_avx2 = data.flags[CPU_FEATURE_AVX2] && data.flags[CPU_FEATURE_OSXSAVE]; } From 0bbeafde65023faf48f01c3a7e22ff37fe20e67b Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 Mar 2019 18:29:13 +0700 Subject: [PATCH 26/55] Added "cn/zls" (Zelerius) and "cn/double" (X-CASH) algorithms. --- src/common/crypto/Algorithm.cpp | 32 +++++---- src/common/xmrig.h | 34 ++++----- src/crypto/CryptoNight_constants.h | 40 ++++++----- src/crypto/CryptoNight_test.h | 31 ++++++++- src/crypto/CryptoNight_x86.h | 38 +++++++++++ src/workers/CpuThread.cpp | 106 +++++++++++++++++++++++------ src/workers/MultiWorker.cpp | 24 ++++--- 7 files changed, 227 insertions(+), 78 deletions(-) diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index ae7ba7c7d..f14d034de 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -54,19 +54,21 @@ struct AlgoData static AlgoData const algorithms[] = { - { "cryptonight", "cn", xmrig::CRYPTONIGHT, xmrig::VARIANT_AUTO }, - { "cryptonight/0", "cn/0", xmrig::CRYPTONIGHT, xmrig::VARIANT_0 }, - { "cryptonight/1", "cn/1", xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, - { "cryptonight/xtl", "cn/xtl", xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL }, - { "cryptonight/msr", "cn/msr", xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR }, - { "cryptonight/xao", "cn/xao", xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO }, - { "cryptonight/rto", "cn/rto", xmrig::CRYPTONIGHT, xmrig::VARIANT_RTO }, - { "cryptonight/2", "cn/2", xmrig::CRYPTONIGHT, xmrig::VARIANT_2 }, - { "cryptonight/half", "cn/half", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF }, - { "cryptonight/xtlv9", "cn/xtlv9", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF }, - { "cryptonight/wow", "cn/wow", xmrig::CRYPTONIGHT, xmrig::VARIANT_WOW }, - { "cryptonight/r", "cn/r", xmrig::CRYPTONIGHT, xmrig::VARIANT_4 }, - { "cryptonight/rwz", "cn/rwz", xmrig::CRYPTONIGHT, xmrig::VARIANT_RWZ }, + { "cryptonight", "cn", xmrig::CRYPTONIGHT, xmrig::VARIANT_AUTO }, + { "cryptonight/0", "cn/0", xmrig::CRYPTONIGHT, xmrig::VARIANT_0 }, + { "cryptonight/1", "cn/1", xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, + { "cryptonight/xtl", "cn/xtl", xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL }, + { "cryptonight/msr", "cn/msr", xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR }, + { "cryptonight/xao", "cn/xao", xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO }, + { "cryptonight/rto", "cn/rto", xmrig::CRYPTONIGHT, xmrig::VARIANT_RTO }, + { "cryptonight/2", "cn/2", xmrig::CRYPTONIGHT, xmrig::VARIANT_2 }, + { "cryptonight/half", "cn/half", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF }, + { "cryptonight/xtlv9", "cn/xtlv9", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF }, + { "cryptonight/wow", "cn/wow", xmrig::CRYPTONIGHT, xmrig::VARIANT_WOW }, + { "cryptonight/r", "cn/r", xmrig::CRYPTONIGHT, xmrig::VARIANT_4 }, + { "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 }, # ifndef XMRIG_NO_AEON { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, @@ -134,7 +136,9 @@ static const char *variants[] = { "gpu", "wow", "r", - "rwz" + "rwz", + "zls", + "double" }; diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 575251b78..e8ca8857e 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -61,22 +61,24 @@ enum AlgoVariant { enum Variant { - VARIANT_AUTO = -1, // Autodetect - VARIANT_0 = 0, // Original CryptoNight or CryptoNight-Heavy - VARIANT_1 = 1, // CryptoNight variant 1 also known as Monero7 and CryptoNightV7 - VARIANT_TUBE = 2, // Modified CryptoNight-Heavy (TUBE only) - VARIANT_XTL = 3, // Modified CryptoNight variant 1 (Stellite only) - VARIANT_MSR = 4, // Modified CryptoNight variant 1 (Masari only) - VARIANT_XHV = 5, // Modified CryptoNight-Heavy (Haven Protocol only) - VARIANT_XAO = 6, // Modified CryptoNight variant 0 (Alloy only) - VARIANT_RTO = 7, // Modified CryptoNight variant 1 (Arto only) - VARIANT_2 = 8, // CryptoNight variant 2 - VARIANT_HALF = 9, // CryptoNight variant 2 with half iterations (Masari/Stellite) - VARIANT_TRTL = 10, // CryptoNight Turtle (TRTL) - VARIANT_GPU = 11, // CryptoNight-GPU (Ryo) - VARIANT_WOW = 12, // CryptoNightR (Wownero) - VARIANT_4 = 13, // CryptoNightR (Monero's variant 4) - VARIANT_RWZ = 14, // CryptoNight variant 2 with 3/4 iterations and reversed shuffle operation (Graft) + VARIANT_AUTO = -1, // Autodetect + VARIANT_0 = 0, // Original CryptoNight or CryptoNight-Heavy + VARIANT_1 = 1, // CryptoNight variant 1 also known as Monero7 and CryptoNightV7 + VARIANT_TUBE = 2, // Modified CryptoNight-Heavy (TUBE only) + VARIANT_XTL = 3, // Modified CryptoNight variant 1 (Stellite only) + VARIANT_MSR = 4, // Modified CryptoNight variant 1 (Masari only) + VARIANT_XHV = 5, // Modified CryptoNight-Heavy (Haven Protocol only) + VARIANT_XAO = 6, // Modified CryptoNight variant 0 (Alloy only) + VARIANT_RTO = 7, // Modified CryptoNight variant 1 (Arto only) + VARIANT_2 = 8, // CryptoNight variant 2 + VARIANT_HALF = 9, // CryptoNight variant 2 with half iterations (Masari/Stellite) + VARIANT_TRTL = 10, // CryptoNight Turtle (TRTL) + VARIANT_GPU = 11, // CryptoNight-GPU (Ryo) + VARIANT_WOW = 12, // CryptoNightR (Wownero) + VARIANT_4 = 13, // CryptoNightR (Monero's variant 4) + 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_MAX }; diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index a6623ebaf..58a3915fc 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -42,7 +42,9 @@ constexpr const uint32_t CRYPTONIGHT_MASK = 0x1FFFF0; constexpr const uint32_t CRYPTONIGHT_ITER = 0x80000; constexpr const uint32_t CRYPTONIGHT_HALF_ITER = 0x40000; constexpr const uint32_t CRYPTONIGHT_XAO_ITER = 0x100000; +constexpr const uint32_t CRYPTONIGHT_DOUBLE_ITER = 0x100000; constexpr const uint32_t CRYPTONIGHT_WALTZ_ITER = 0x60000; +constexpr const uint32_t CRYPTONIGHT_ZLS_ITER = 0x60000; constexpr const uint32_t CRYPTONIGHT_GPU_ITER = 0xC000; constexpr const uint32_t CRYPTONIGHT_GPU_MASK = 0x1FFFC0; @@ -136,6 +138,8 @@ template<> inline constexpr uint32_t cn_select_iter() template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_GPU_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_WALTZ_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ZLS_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_DOUBLE_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } @@ -155,12 +159,14 @@ inline uint32_t cn_select_iter(Algo algorithm, Variant variant) return CRYPTONIGHT_GPU_ITER; case VARIANT_RTO: + case VARIANT_DOUBLE: return CRYPTONIGHT_XAO_ITER; case VARIANT_TRTL: return CRYPTONIGHT_TRTL_ITER; case VARIANT_RWZ: + case VARIANT_ZLS: return CRYPTONIGHT_WALTZ_ITER; default: @@ -189,22 +195,24 @@ inline uint32_t cn_select_iter(Algo algorithm, Variant variant) } -template inline constexpr Variant cn_base_variant() { return VARIANT_0; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_0; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_0; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_0; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_GPU; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } -template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +template inline constexpr Variant cn_base_variant() { return VARIANT_0; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_0; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_0; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_0; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_GPU; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } template inline constexpr bool cn_is_cryptonight_r() { return false; } diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index 4f10b2216..6fa9dd286 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -230,6 +230,7 @@ const static uint8_t test_output_rto[160] = { 0xE7, 0x81, 0x4E, 0x2A, 0xBD, 0x62, 0xC1, 0x1B, 0x7C, 0xB9, 0x33, 0x7B, 0xEE, 0x95, 0x80, 0xB3 }; +// "cn/rwz" const static uint8_t test_output_rwz[160] = { 0x5f, 0x56, 0xc6, 0xb0, 0x99, 0x6b, 0xa2, 0x3e, 0x0b, 0xba, 0x07, 0x29, 0xc9, 0x90, 0x74, 0x85, 0x5a, 0x10, 0xe3, 0x08, 0x7f, 0xdb, 0xfe, 0x94, 0x75, 0x33, 0x54, 0x73, 0x76, 0xf0, 0x75, 0xb8, @@ -240,7 +241,35 @@ const static uint8_t test_output_rwz[160] = { 0x9a, 0xe9, 0xba, 0x0c, 0xc0, 0x2b, 0x11, 0xf6, 0x9b, 0xee, 0x24, 0x3a, 0xd8, 0x86, 0x18, 0xd0, 0xe8, 0xeb, 0xcb, 0x38, 0x2c, 0xf5, 0x99, 0x83, 0x14, 0x7b, 0x0c, 0x20, 0xbe, 0x50, 0xf4, 0x87, 0x83, 0x41, 0x75, 0xd8, 0xd1, 0xdd, 0x4b, 0x73, 0xb3, 0x92, 0x8f, 0xe6, 0x1c, 0x72, 0x70, 0xf5, - 0x7c, 0xf6, 0x23, 0x3a, 0xb4, 0x5f, 0xdf, 0xde, 0xa6, 0x5a, 0x58, 0xec, 0x13, 0x5a, 0x23, 0x2f, + 0x7c, 0xf6, 0x23, 0x3a, 0xb4, 0x5f, 0xdf, 0xde, 0xa6, 0x5a, 0x58, 0xec, 0x13, 0x5a, 0x23, 0x2f +}; + +// "cn/zls" +const static uint8_t test_output_zls[160] = { + 0x51, 0x6E, 0x33, 0xC6, 0xE4, 0x46, 0xAB, 0xBC, 0xCD, 0xAD, 0x18, 0xC0, 0x4C, 0xD9, 0xA2, 0x5E, + 0x64, 0x10, 0x28, 0x53, 0xB2, 0x0A, 0x42, 0xDF, 0xDE, 0xAA, 0x8B, 0x59, 0x9E, 0xCF, 0x40, 0xE2, + 0x0D, 0x62, 0x5B, 0x42, 0x18, 0xE2, 0x76, 0xAD, 0xD0, 0x74, 0x90, 0x60, 0x8D, 0xC4, 0xC7, 0x80, + 0x17, 0xB5, 0x1B, 0x25, 0x31, 0x39, 0x87, 0xD2, 0x2D, 0x6A, 0x9D, 0x1C, 0x74, 0xF4, 0x43, 0x22, + 0x4B, 0x97, 0x1F, 0x6A, 0xD0, 0xBE, 0x00, 0x74, 0xEC, 0xC5, 0xD8, 0x3B, 0xE6, 0xF4, 0x03, 0x8A, + 0x7B, 0xBA, 0x80, 0xCC, 0x9F, 0x00, 0xCB, 0xC2, 0x14, 0x8F, 0xF3, 0xD8, 0x92, 0x73, 0xBF, 0x17, + 0x3D, 0x9B, 0x22, 0xA3, 0x61, 0x94, 0x41, 0x9E, 0xF9, 0x68, 0x1D, 0x42, 0x48, 0x3B, 0x39, 0x45, + 0xE2, 0xE6, 0x16, 0x84, 0xFC, 0x21, 0xE6, 0xDA, 0x38, 0x7F, 0x17, 0xAB, 0xD3, 0xF2, 0xCE, 0x1A, + 0x2F, 0x35, 0xD5, 0x74, 0xFA, 0x45, 0x3B, 0x06, 0xD1, 0x4E, 0x84, 0x3A, 0x5D, 0xE3, 0x0E, 0xA5, + 0x00, 0x08, 0x64, 0xF0, 0xA6, 0xC8, 0x94, 0x45, 0x08, 0xED, 0x03, 0x95, 0x52, 0xE9, 0xBC, 0x5F +}; + +// "cn/double" +const static uint8_t test_output_double[160] = { + 0xAE, 0xFB, 0xB3, 0xF0, 0xCC, 0x88, 0x04, 0x6D, 0x11, 0x9F, 0x6C, 0x54, 0xB9, 0x6D, 0x90, 0xC9, + 0xE8, 0x84, 0xEA, 0x3B, 0x59, 0x83, 0xA6, 0x0D, 0x50, 0xA4, 0x2D, 0x7D, 0x3E, 0xBE, 0x48, 0x21, + 0x49, 0xCE, 0x8E, 0xF3, 0xBC, 0x8A, 0x36, 0xBF, 0x86, 0x37, 0x89, 0x55, 0x09, 0xBA, 0x22, 0xF8, + 0xEB, 0x3A, 0xE1, 0xDC, 0x91, 0xF7, 0x62, 0x4B, 0x9F, 0x48, 0xE6, 0x92, 0xBD, 0xE4, 0x5D, 0xC1, + 0xF1, 0x3C, 0x63, 0x1D, 0xEB, 0x0B, 0x04, 0xA3, 0x30, 0xD5, 0x11, 0x15, 0x4C, 0xCE, 0xEF, 0x4F, + 0xDF, 0x69, 0xE3, 0x9E, 0xD2, 0x68, 0xFC, 0x1B, 0x6F, 0xE8, 0x08, 0x9C, 0xBB, 0xA5, 0x2B, 0x60, + 0x52, 0x0F, 0xE5, 0xD2, 0xF3, 0x8A, 0xB3, 0xE1, 0x76, 0x7F, 0x44, 0x25, 0x76, 0xEC, 0xFF, 0xA2, + 0x0C, 0x64, 0xD0, 0x0E, 0x32, 0x33, 0x28, 0x20, 0x73, 0xE0, 0x31, 0x66, 0x4E, 0x54, 0x83, 0x49, + 0x51, 0x55, 0x4D, 0x2E, 0x22, 0xB7, 0x51, 0x09, 0x73, 0x61, 0x7E, 0x6A, 0x57, 0x0B, 0x28, 0x3C, + 0x5E, 0x2E, 0xC1, 0x80, 0x89, 0x39, 0xB3, 0x54, 0x39, 0x52, 0x0E, 0x69, 0x3D, 0xF6, 0xC5, 0x4A }; #ifndef XMRIG_NO_AEON diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 5c4de441f..8b9ea7836 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -767,6 +767,16 @@ extern xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_ryzen_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_bulldozer_asm; extern xmrig::CpuThread::cn_mainloop_double_fun cn_trtl_double_mainloop_sandybridge_asm; +extern xmrig::CpuThread::cn_mainloop_fun cn_zls_mainloop_ivybridge_asm; +extern xmrig::CpuThread::cn_mainloop_fun cn_zls_mainloop_ryzen_asm; +extern xmrig::CpuThread::cn_mainloop_fun cn_zls_mainloop_bulldozer_asm; +extern xmrig::CpuThread::cn_mainloop_double_fun cn_zls_double_mainloop_sandybridge_asm; + +extern xmrig::CpuThread::cn_mainloop_fun cn_double_mainloop_ivybridge_asm; +extern xmrig::CpuThread::cn_mainloop_fun cn_double_mainloop_ryzen_asm; +extern xmrig::CpuThread::cn_mainloop_fun cn_double_mainloop_bulldozer_asm; +extern xmrig::CpuThread::cn_mainloop_double_fun cn_double_double_mainloop_sandybridge_asm; + void wow_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); void v4_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); void wow_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); @@ -848,6 +858,28 @@ inline void cryptonight_single_hash_asm(const uint8_t *__restrict__ input, size_ else if (VARIANT == xmrig::VARIANT_RWZ) { cnv2_rwz_mainloop_asm(ctx[0]); } + else if (VARIANT == xmrig::VARIANT_ZLS) { + if (ASM == xmrig::ASM_INTEL) { + cn_zls_mainloop_ivybridge_asm(ctx[0]); + } + else if (ASM == xmrig::ASM_RYZEN) { + cn_zls_mainloop_ryzen_asm(ctx[0]); + } + else { + cn_zls_mainloop_bulldozer_asm(ctx[0]); + } + } + else if (VARIANT == xmrig::VARIANT_DOUBLE) { + if (ASM == xmrig::ASM_INTEL) { + cn_double_mainloop_ivybridge_asm(ctx[0]); + } + else if (ASM == xmrig::ASM_RYZEN) { + cn_double_mainloop_ryzen_asm(ctx[0]); + } + else { + cn_double_mainloop_bulldozer_asm(ctx[0]); + } + } else if (xmrig::cn_is_cryptonight_r()) { ctx[0]->generated_code(ctx[0]); } @@ -889,6 +921,12 @@ inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_ else if (VARIANT == xmrig::VARIANT_RWZ) { cnv2_rwz_double_mainloop_asm(ctx[0], ctx[1]); } + else if (VARIANT == xmrig::VARIANT_ZLS) { + cn_zls_double_mainloop_sandybridge_asm(ctx[0], ctx[1]); + } + else if (VARIANT == xmrig::VARIANT_DOUBLE) { + cn_double_double_mainloop_sandybridge_asm(ctx[0], ctx[1]); + } else if (xmrig::cn_is_cryptonight_r()) { ctx[0]->generated_code_double(ctx[0], ctx[1]); } diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index dfa6518cc..c98b730ad 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -96,15 +96,25 @@ extern "C" void cnv2_mainloop_bulldozer_asm(cryptonight_ctx *ctx); extern "C" void cnv2_double_mainloop_sandybridge_asm(cryptonight_ctx *ctx0, cryptonight_ctx *ctx1); -xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ivybridge_asm = nullptr; -xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ryzen_asm = nullptr; -xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_bulldozer_asm = nullptr; -xmrig::CpuThread::cn_mainloop_double_fun cn_half_double_mainloop_sandybridge_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ivybridge_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ryzen_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_bulldozer_asm = nullptr; +xmrig::CpuThread::cn_mainloop_double_fun cn_half_double_mainloop_sandybridge_asm = nullptr; -xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_ivybridge_asm = nullptr; -xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_ryzen_asm = nullptr; -xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_bulldozer_asm = nullptr; -xmrig::CpuThread::cn_mainloop_double_fun cn_trtl_double_mainloop_sandybridge_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_ivybridge_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_ryzen_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_bulldozer_asm = nullptr; +xmrig::CpuThread::cn_mainloop_double_fun cn_trtl_double_mainloop_sandybridge_asm = nullptr; + +xmrig::CpuThread::cn_mainloop_fun cn_zls_mainloop_ivybridge_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_zls_mainloop_ryzen_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_zls_mainloop_bulldozer_asm = nullptr; +xmrig::CpuThread::cn_mainloop_double_fun cn_zls_double_mainloop_sandybridge_asm = nullptr; + +xmrig::CpuThread::cn_mainloop_fun cn_double_mainloop_ivybridge_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_double_mainloop_ryzen_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_double_mainloop_bulldozer_asm = nullptr; +xmrig::CpuThread::cn_mainloop_double_fun cn_double_double_mainloop_sandybridge_asm = nullptr; void xmrig::CpuThread::patchAsmVariants() @@ -122,15 +132,35 @@ void xmrig::CpuThread::patchAsmVariants() cn_trtl_mainloop_bulldozer_asm = reinterpret_cast (base + 0x6000); cn_trtl_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0x7000); - patchCode(cn_half_mainloop_ivybridge_asm, cnv2_mainloop_ivybridge_asm, xmrig::CRYPTONIGHT_HALF_ITER, xmrig::CRYPTONIGHT_MASK); - patchCode(cn_half_mainloop_ryzen_asm, cnv2_mainloop_ryzen_asm, xmrig::CRYPTONIGHT_HALF_ITER, xmrig::CRYPTONIGHT_MASK); - patchCode(cn_half_mainloop_bulldozer_asm, cnv2_mainloop_bulldozer_asm, xmrig::CRYPTONIGHT_HALF_ITER, xmrig::CRYPTONIGHT_MASK); - patchCode(cn_half_double_mainloop_sandybridge_asm, cnv2_double_mainloop_sandybridge_asm, xmrig::CRYPTONIGHT_HALF_ITER, xmrig::CRYPTONIGHT_MASK); + 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); - patchCode(cn_trtl_mainloop_ivybridge_asm, cnv2_mainloop_ivybridge_asm, xmrig::CRYPTONIGHT_TRTL_ITER, xmrig::CRYPTONIGHT_PICO_MASK); - patchCode(cn_trtl_mainloop_ryzen_asm, cnv2_mainloop_ryzen_asm, xmrig::CRYPTONIGHT_TRTL_ITER, xmrig::CRYPTONIGHT_PICO_MASK); - patchCode(cn_trtl_mainloop_bulldozer_asm, cnv2_mainloop_bulldozer_asm, xmrig::CRYPTONIGHT_TRTL_ITER, xmrig::CRYPTONIGHT_PICO_MASK); - patchCode(cn_trtl_double_mainloop_sandybridge_asm, cnv2_double_mainloop_sandybridge_asm, xmrig::CRYPTONIGHT_TRTL_ITER, xmrig::CRYPTONIGHT_PICO_MASK); + 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); + + patchCode(cn_half_mainloop_ivybridge_asm, cnv2_mainloop_ivybridge_asm, xmrig::CRYPTONIGHT_HALF_ITER, xmrig::CRYPTONIGHT_MASK); + patchCode(cn_half_mainloop_ryzen_asm, cnv2_mainloop_ryzen_asm, xmrig::CRYPTONIGHT_HALF_ITER, xmrig::CRYPTONIGHT_MASK); + patchCode(cn_half_mainloop_bulldozer_asm, cnv2_mainloop_bulldozer_asm, xmrig::CRYPTONIGHT_HALF_ITER, xmrig::CRYPTONIGHT_MASK); + patchCode(cn_half_double_mainloop_sandybridge_asm, cnv2_double_mainloop_sandybridge_asm, xmrig::CRYPTONIGHT_HALF_ITER, xmrig::CRYPTONIGHT_MASK); + + patchCode(cn_trtl_mainloop_ivybridge_asm, cnv2_mainloop_ivybridge_asm, xmrig::CRYPTONIGHT_TRTL_ITER, xmrig::CRYPTONIGHT_PICO_MASK); + patchCode(cn_trtl_mainloop_ryzen_asm, cnv2_mainloop_ryzen_asm, xmrig::CRYPTONIGHT_TRTL_ITER, xmrig::CRYPTONIGHT_PICO_MASK); + patchCode(cn_trtl_mainloop_bulldozer_asm, cnv2_mainloop_bulldozer_asm, xmrig::CRYPTONIGHT_TRTL_ITER, xmrig::CRYPTONIGHT_PICO_MASK); + patchCode(cn_trtl_double_mainloop_sandybridge_asm, cnv2_double_mainloop_sandybridge_asm, xmrig::CRYPTONIGHT_TRTL_ITER, xmrig::CRYPTONIGHT_PICO_MASK); + + patchCode(cn_zls_mainloop_ivybridge_asm, cnv2_mainloop_ivybridge_asm, xmrig::CRYPTONIGHT_ZLS_ITER, xmrig::CRYPTONIGHT_MASK); + patchCode(cn_zls_mainloop_ryzen_asm, cnv2_mainloop_ryzen_asm, xmrig::CRYPTONIGHT_ZLS_ITER, xmrig::CRYPTONIGHT_MASK); + patchCode(cn_zls_mainloop_bulldozer_asm, cnv2_mainloop_bulldozer_asm, xmrig::CRYPTONIGHT_ZLS_ITER, xmrig::CRYPTONIGHT_MASK); + patchCode(cn_zls_double_mainloop_sandybridge_asm, cnv2_double_mainloop_sandybridge_asm, xmrig::CRYPTONIGHT_ZLS_ITER, xmrig::CRYPTONIGHT_MASK); + + patchCode(cn_double_mainloop_ivybridge_asm, cnv2_mainloop_ivybridge_asm, xmrig::CRYPTONIGHT_DOUBLE_ITER, xmrig::CRYPTONIGHT_MASK); + patchCode(cn_double_mainloop_ryzen_asm, cnv2_mainloop_ryzen_asm, xmrig::CRYPTONIGHT_DOUBLE_ITER, xmrig::CRYPTONIGHT_MASK); + 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); @@ -148,12 +178,12 @@ bool xmrig::CpuThread::isSoftAES(AlgoVariant av) template static inline void add_asm_func(xmrig::CpuThread::cn_hash_fun(&asm_func_map)[xmrig::ALGO_MAX][xmrig::AV_MAX][xmrig::VARIANT_MAX][xmrig::ASM_MAX]) { - asm_func_map[algo][xmrig::AV_SINGLE][variant][xmrig::ASM_INTEL] = cryptonight_single_hash_asm; - asm_func_map[algo][xmrig::AV_SINGLE][variant][xmrig::ASM_RYZEN] = cryptonight_single_hash_asm; + asm_func_map[algo][xmrig::AV_SINGLE][variant][xmrig::ASM_INTEL] = cryptonight_single_hash_asm; + asm_func_map[algo][xmrig::AV_SINGLE][variant][xmrig::ASM_RYZEN] = cryptonight_single_hash_asm; asm_func_map[algo][xmrig::AV_SINGLE][variant][xmrig::ASM_BULLDOZER] = cryptonight_single_hash_asm; - asm_func_map[algo][xmrig::AV_DOUBLE][variant][xmrig::ASM_INTEL] = cryptonight_double_hash_asm; - asm_func_map[algo][xmrig::AV_DOUBLE][variant][xmrig::ASM_RYZEN] = cryptonight_double_hash_asm; + asm_func_map[algo][xmrig::AV_DOUBLE][variant][xmrig::ASM_INTEL] = cryptonight_double_hash_asm; + asm_func_map[algo][xmrig::AV_DOUBLE][variant][xmrig::ASM_RYZEN] = cryptonight_double_hash_asm; asm_func_map[algo][xmrig::AV_DOUBLE][variant][xmrig::ASM_BULLDOZER] = cryptonight_double_hash_asm; } #endif @@ -181,6 +211,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a # endif add_asm_func(asm_func_map); + add_asm_func(asm_func_map); + add_asm_func(asm_func_map); asm_func_map_initialized = true; } @@ -336,6 +368,28 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + # ifndef XMRIG_NO_AEON cryptonight_single_hash, cryptonight_double_hash, @@ -372,6 +426,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a 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 # 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 @@ -388,6 +444,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a 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 # endif # ifndef XMRIG_NO_SUMO @@ -438,6 +496,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a 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 # 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 @@ -454,6 +514,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a 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 # endif # ifndef XMRIG_NO_CN_PICO @@ -483,6 +545,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a 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 # 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 @@ -499,6 +563,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a 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 # endif }; diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 1bc52bf42..02eec378e 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -55,17 +55,19 @@ bool MultiWorker::selfTest() using namespace xmrig; if (m_thread->algorithm() == CRYPTONIGHT) { - const bool rc = verify(VARIANT_0, test_output_v0) && - verify(VARIANT_1, test_output_v1) && - verify(VARIANT_2, test_output_v2) && - verify(VARIANT_XTL, test_output_xtl) && - verify(VARIANT_MSR, test_output_msr) && - verify(VARIANT_XAO, test_output_xao) && - verify(VARIANT_RTO, test_output_rto) && - verify(VARIANT_HALF, test_output_half) && - verify2(VARIANT_WOW, test_output_wow) && - verify2(VARIANT_4, test_output_r) && - verify(VARIANT_RWZ, test_output_rwz); + const bool rc = verify(VARIANT_0, test_output_v0) && + verify(VARIANT_1, test_output_v1) && + verify(VARIANT_2, test_output_v2) && + verify(VARIANT_XTL, test_output_xtl) && + verify(VARIANT_MSR, test_output_msr) && + verify(VARIANT_XAO, test_output_xao) && + verify(VARIANT_RTO, test_output_rto) && + verify(VARIANT_HALF, test_output_half) && + verify2(VARIANT_WOW, test_output_wow) && + verify2(VARIANT_4, test_output_r) && + verify(VARIANT_RWZ, test_output_rwz) && + verify(VARIANT_ZLS, test_output_zls) && + verify(VARIANT_DOUBLE, test_output_double); # ifndef XMRIG_NO_CN_GPU if (!rc || N > 1) { From 6a77a27e7fa99dad79ce154fd5a0b947cd057ea8 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 Mar 2019 23:44:16 +0700 Subject: [PATCH 27/55] Fix algorithm negotiation (recently added algorithms was missing). --- src/base/net/Pool.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/base/net/Pool.cpp b/src/base/net/Pool.cpp index a1fd4331b..9d4f2bde6 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -484,7 +484,6 @@ void xmrig::Pool::rebuild() m_algorithms.push_back(m_algorithm); # ifndef XMRIG_PROXY_PROJECT - addVariant(VARIANT_RWZ); addVariant(VARIANT_4); addVariant(VARIANT_WOW); addVariant(VARIANT_2); @@ -498,6 +497,9 @@ void xmrig::Pool::rebuild() addVariant(VARIANT_XAO); addVariant(VARIANT_RTO); addVariant(VARIANT_GPU); + addVariant(VARIANT_RWZ); + addVariant(VARIANT_ZLS); + addVariant(VARIANT_DOUBLE); addVariant(VARIANT_AUTO); # endif } From fb3129c67deed8b367bf1daf64c6179b5825d5e5 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 5 Mar 2019 18:05:19 +0100 Subject: [PATCH 28/55] Algo switch at Graft fork --- src/common/net/Job.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index 546865356..8dcc11783 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -137,6 +137,9 @@ bool xmrig::Job::setBlob(const char *blob) else if (m_algorithm.variant() == VARIANT_WOW && m_blob[0] < 11) { m_algorithm.setVariant(VARIANT_2); } + else if (m_algorithm.variant() == VARIANT_RWZ && m_blob[0] < 12) { + m_algorithm.setVariant(VARIANT_2); + } } # ifdef XMRIG_PROXY_PROJECT From 31e40943d08f0a818b1607eeac2406633fe09a2a Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 6 Mar 2019 13:05:13 +0700 Subject: [PATCH 29/55] Add algo-switch for ZLS. --- src/common/net/Job.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index 8dcc11783..851507adc 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -140,6 +140,9 @@ bool xmrig::Job::setBlob(const char *blob) else if (m_algorithm.variant() == VARIANT_RWZ && m_blob[0] < 12) { m_algorithm.setVariant(VARIANT_2); } + else if (m_algorithm.variant() == VARIANT_ZLS && m_blob[0] < 8) { + m_algorithm.setVariant(VARIANT_2); + } } # ifdef XMRIG_PROXY_PROJECT From c8b1f176e7c723d55d43cd95da4adcfd404269df Mon Sep 17 00:00:00 2001 From: xmrig Date: Wed, 6 Mar 2019 17:58:24 +0700 Subject: [PATCH 30/55] Update CHANGELOG.md --- CHANGELOG.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb7f2378a..0e13e55a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ +# v2.14.0 +- **[#969](https://github.com/xmrig/xmrig/pull/969) Added new algorithm `cryptonight/rwz`, short alias `cn/rwz` (also known as CryptoNight ReverseWaltz), for upcoming [Graft](https://www.graft.network/) fork.** +- **[#931](https://github.com/xmrig/xmrig/issues/931) Added new algorithm `cryptonight/zls`, short alias `cn/zls` for [Zelerius Network](https://zelerius.org) fork.** +- **[#940](https://github.com/xmrig/xmrig/issues/940) Added new algorithm `cryptonight/double`, short alias `cn/double` (also known as CryptoNight HeavyX), for [X-CASH](https://x-cash.org/).** +- [#951](https://github.com/xmrig/xmrig/issues/951#issuecomment-469581529) Fixed crash if AVX was disabled on OS level. +- [#952](https://github.com/xmrig/xmrig/issues/952) Fixed compile error on some Linux. +- [#957](https://github.com/xmrig/xmrig/issues/957#issuecomment-468890667) Added support for embedded config. +- [#958](https://github.com/xmrig/xmrig/pull/958) Fixed incorrect user agent on ARM platforms. +- [#968](https://github.com/xmrig/xmrig/pull/968) Optimized `cn/r` algorithm performance. + # v2.13.1 -[#946](https://github.com/xmrig/xmrig/pull/946) Optimized software AES implementations for CPUs without hardware AES support. `cn/r`, `cn/wow` up to 2.6 times faster, 4-9% improvements for other algorithms. +- [#946](https://github.com/xmrig/xmrig/pull/946) Optimized software AES implementations for CPUs without hardware AES support. `cn/r`, `cn/wow` up to 2.6 times faster, 4-9% improvements for other algorithms. # v2.13.0 - **[#938](https://github.com/xmrig/xmrig/issues/938) Added support for new algorithm `cryptonight/r`, short alias `cn/r` (also known as CryptoNightR or CryptoNight variant 4), for upcoming [Monero](https://www.getmonero.org/) fork on March 9, thanks [@SChernykh](https://github.com/SChernykh).** From 5cd48f483e513aa2b437d6420218b7ecb4277249 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 6 Mar 2019 19:12:15 +0700 Subject: [PATCH 31/55] v2.14.0 --- src/version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/version.h b/src/version.h index 6c8418088..e383a1a6e 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.13.2-dev" +#define APP_VERSION "2.14.0" #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 13 -#define APP_VER_PATCH 2 +#define APP_VER_MINOR 14 +#define APP_VER_PATCH 0 #ifdef _MSC_VER # if (_MSC_VER >= 1910) From 80a7aa24974015bbc801480c63f4c8cdaebe9464 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 7 Mar 2019 14:52:40 +0700 Subject: [PATCH 32/55] #975 Fixed crash on Linux if used double thread. --- src/crypto/asm/cn_main_loop.S | 1 + 1 file changed, 1 insertion(+) diff --git a/src/crypto/asm/cn_main_loop.S b/src/crypto/asm/cn_main_loop.S index c2c08739a..347f0e088 100644 --- a/src/crypto/asm/cn_main_loop.S +++ b/src/crypto/asm/cn_main_loop.S @@ -68,6 +68,7 @@ ALIGN(64) FN_PREFIX(cnv2_rwz_double_mainloop_asm): sub rsp, 48 mov rcx, rdi + mov rdx, rsi #include "cn2/cnv2_rwz_double_main_loop.inc" add rsp, 48 ret 0 From 1042f23dd5fde343dfdbebdc19d4f094b7d59657 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 7 Mar 2019 15:02:55 +0700 Subject: [PATCH 33/55] v2.14.1 --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index e383a1a6e..ff00eca3d 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.14.0" +#define APP_VERSION "2.14.1" #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 14 -#define APP_VER_PATCH 0 +#define APP_VER_PATCH 1 #ifdef _MSC_VER # if (_MSC_VER >= 1910) From 08ef94486b1f5e24b25e4609621929a7efd72732 Mon Sep 17 00:00:00 2001 From: xmrig Date: Thu, 7 Mar 2019 15:16:42 +0700 Subject: [PATCH 34/55] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e13e55a1..79c8bb4a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# v2.14.1 +* [#975](https://github.com/xmrig/xmrig/issues/975) Fixed crash on Linux if double thread mode used. + # v2.14.0 - **[#969](https://github.com/xmrig/xmrig/pull/969) Added new algorithm `cryptonight/rwz`, short alias `cn/rwz` (also known as CryptoNight ReverseWaltz), for upcoming [Graft](https://www.graft.network/) fork.** - **[#931](https://github.com/xmrig/xmrig/issues/931) Added new algorithm `cryptonight/zls`, short alias `cn/zls` for [Zelerius Network](https://zelerius.org) fork.** From 5d9ebb0b917550d09e6f0f26bf5b1f02060f3427 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 7 Mar 2019 17:51:54 +0700 Subject: [PATCH 35/55] v2.14.2-dev --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index ff00eca3d..4e8fee459 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.14.1" +#define APP_VERSION "2.14.2-dev" #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 14 -#define APP_VER_PATCH 1 +#define APP_VER_PATCH 2 #ifdef _MSC_VER # if (_MSC_VER >= 1910) From 1bb8f77b527b02271c0645ced7063522322d628c Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 13 Mar 2019 22:00:44 +0100 Subject: [PATCH 36/55] Unified ASM functions signature --- src/Mem.cpp | 2 +- src/crypto/CryptoNight.h | 5 +- src/crypto/CryptoNight_x86.h | 70 +++++++++---------- .../asm/CryptonightR_soft_aes_template.inc | 2 + .../CryptonightR_soft_aes_template_win.inc | 2 + src/crypto/asm/CryptonightR_template.inc | 5 ++ src/crypto/asm/CryptonightR_template_win.inc | 5 ++ .../asm/CryptonightWOW_soft_aes_template.inc | 2 + .../CryptonightWOW_soft_aes_template_win.inc | 2 + src/crypto/asm/CryptonightWOW_template.inc | 5 ++ .../asm/CryptonightWOW_template_win.inc | 5 ++ .../cn2/cnv2_double_main_loop_sandybridge.inc | 3 + .../asm/cn2/cnv2_main_loop_bulldozer.inc | 2 + .../asm/cn2/cnv2_main_loop_ivybridge.inc | 2 + src/crypto/asm/cn2/cnv2_main_loop_ryzen.inc | 2 + .../asm/cn2/cnv2_rwz_double_main_loop.inc | 3 + src/crypto/asm/cn2/cnv2_rwz_main_loop.inc | 2 + src/crypto/asm/cn_main_loop.S | 2 - .../CryptonightR_soft_aes_template_win.inc | 2 + .../asm/win64/CryptonightR_template_win.inc | 5 ++ .../CryptonightWOW_soft_aes_template_win.inc | 2 + .../asm/win64/CryptonightWOW_template_win.inc | 5 ++ .../cn2/cnv2_double_main_loop_sandybridge.inc | 3 + .../win64/cn2/cnv2_main_loop_bulldozer.inc | 2 + .../win64/cn2/cnv2_main_loop_ivybridge.inc | 2 + .../asm/win64/cn2/cnv2_main_loop_ryzen.inc | 2 + .../win64/cn2/cnv2_rwz_double_main_loop.inc | 3 + .../asm/win64/cn2/cnv2_rwz_main_loop.inc | 2 + src/workers/CpuThread.cpp | 24 +++---- src/workers/CpuThread.h | 3 +- 30 files changed, 121 insertions(+), 55 deletions(-) diff --git a/src/Mem.cpp b/src/Mem.cpp index 4fa794d65..01a2157b3 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -53,7 +53,7 @@ MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count) uint8_t* p = reinterpret_cast(allocateExecutableMemory(0x4000)); c->generated_code = reinterpret_cast(p); - c->generated_code_double = reinterpret_cast(p + 0x2000); + c->generated_code_double = reinterpret_cast(p + 0x2000); c->generated_code_data.variant = xmrig::VARIANT_MAX; c->generated_code_data.height = (uint64_t)(-1); diff --git a/src/crypto/CryptoNight.h b/src/crypto/CryptoNight.h index 91a4c7b71..b1ec2371d 100644 --- a/src/crypto/CryptoNight.h +++ b/src/crypto/CryptoNight.h @@ -36,8 +36,7 @@ #endif struct cryptonight_ctx; -typedef void(*cn_mainloop_fun_ms_abi)(cryptonight_ctx*) ABI_ATTRIBUTE; -typedef void(*cn_mainloop_double_fun_ms_abi)(cryptonight_ctx*, cryptonight_ctx*) ABI_ATTRIBUTE; +typedef void(*cn_mainloop_fun_ms_abi)(cryptonight_ctx**) ABI_ATTRIBUTE; struct cryptonight_r_data { int variant; @@ -54,7 +53,7 @@ struct cryptonight_ctx { const uint32_t* saes_table; cn_mainloop_fun_ms_abi generated_code; - cn_mainloop_double_fun_ms_abi generated_code_double; + 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 8b9ea7836..202b662a2 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -590,7 +590,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si } ctx[0]->saes_table = (const uint32_t*)saes_table; - ctx[0]->generated_code(ctx[0]); + ctx[0]->generated_code(ctx); } else { #endif @@ -750,32 +750,32 @@ inline void cryptonight_single_hash_gpu(const uint8_t *__restrict__ input, size_ #ifndef XMRIG_NO_ASM -extern "C" void cnv2_mainloop_ivybridge_asm(cryptonight_ctx *ctx); -extern "C" void cnv2_mainloop_ryzen_asm(cryptonight_ctx *ctx); -extern "C" void cnv2_mainloop_bulldozer_asm(cryptonight_ctx *ctx); -extern "C" void cnv2_double_mainloop_sandybridge_asm(cryptonight_ctx* ctx0, cryptonight_ctx* ctx1); -extern "C" void cnv2_rwz_mainloop_asm(cryptonight_ctx *ctx); -extern "C" void cnv2_rwz_double_mainloop_asm(cryptonight_ctx* ctx0, cryptonight_ctx* ctx1); +extern "C" void cnv2_mainloop_ivybridge_asm(cryptonight_ctx **ctx); +extern "C" void cnv2_mainloop_ryzen_asm(cryptonight_ctx **ctx); +extern "C" void cnv2_mainloop_bulldozer_asm(cryptonight_ctx **ctx); +extern "C" void cnv2_double_mainloop_sandybridge_asm(cryptonight_ctx **ctx); +extern "C" void cnv2_rwz_mainloop_asm(cryptonight_ctx **ctx); +extern "C" void cnv2_rwz_double_mainloop_asm(cryptonight_ctx **ctx); extern xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ivybridge_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ryzen_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_bulldozer_asm; -extern xmrig::CpuThread::cn_mainloop_double_fun cn_half_double_mainloop_sandybridge_asm; +extern xmrig::CpuThread::cn_mainloop_fun cn_half_double_mainloop_sandybridge_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_ivybridge_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_ryzen_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_bulldozer_asm; -extern xmrig::CpuThread::cn_mainloop_double_fun cn_trtl_double_mainloop_sandybridge_asm; +extern xmrig::CpuThread::cn_mainloop_fun cn_trtl_double_mainloop_sandybridge_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_zls_mainloop_ivybridge_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_zls_mainloop_ryzen_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_zls_mainloop_bulldozer_asm; -extern xmrig::CpuThread::cn_mainloop_double_fun cn_zls_double_mainloop_sandybridge_asm; +extern xmrig::CpuThread::cn_mainloop_fun cn_zls_double_mainloop_sandybridge_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_double_mainloop_ivybridge_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_double_mainloop_ryzen_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_double_mainloop_bulldozer_asm; -extern xmrig::CpuThread::cn_mainloop_double_fun cn_double_double_mainloop_sandybridge_asm; +extern xmrig::CpuThread::cn_mainloop_fun cn_double_double_mainloop_sandybridge_asm; void wow_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); void v4_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); @@ -824,64 +824,64 @@ inline void cryptonight_single_hash_asm(const uint8_t *__restrict__ input, size_ if (VARIANT == xmrig::VARIANT_2) { if (ASM == xmrig::ASM_INTEL) { - cnv2_mainloop_ivybridge_asm(ctx[0]); + cnv2_mainloop_ivybridge_asm(ctx); } else if (ASM == xmrig::ASM_RYZEN) { - cnv2_mainloop_ryzen_asm(ctx[0]); + cnv2_mainloop_ryzen_asm(ctx); } else { - cnv2_mainloop_bulldozer_asm(ctx[0]); + cnv2_mainloop_bulldozer_asm(ctx); } } else if (VARIANT == xmrig::VARIANT_HALF) { if (ASM == xmrig::ASM_INTEL) { - cn_half_mainloop_ivybridge_asm(ctx[0]); + cn_half_mainloop_ivybridge_asm(ctx); } else if (ASM == xmrig::ASM_RYZEN) { - cn_half_mainloop_ryzen_asm(ctx[0]); + cn_half_mainloop_ryzen_asm(ctx); } else { - cn_half_mainloop_bulldozer_asm(ctx[0]); + cn_half_mainloop_bulldozer_asm(ctx); } } else if (VARIANT == xmrig::VARIANT_TRTL) { if (ASM == xmrig::ASM_INTEL) { - cn_trtl_mainloop_ivybridge_asm(ctx[0]); + cn_trtl_mainloop_ivybridge_asm(ctx); } else if (ASM == xmrig::ASM_RYZEN) { - cn_trtl_mainloop_ryzen_asm(ctx[0]); + cn_trtl_mainloop_ryzen_asm(ctx); } else { - cn_trtl_mainloop_bulldozer_asm(ctx[0]); + cn_trtl_mainloop_bulldozer_asm(ctx); } } else if (VARIANT == xmrig::VARIANT_RWZ) { - cnv2_rwz_mainloop_asm(ctx[0]); + cnv2_rwz_mainloop_asm(ctx); } else if (VARIANT == xmrig::VARIANT_ZLS) { if (ASM == xmrig::ASM_INTEL) { - cn_zls_mainloop_ivybridge_asm(ctx[0]); + cn_zls_mainloop_ivybridge_asm(ctx); } else if (ASM == xmrig::ASM_RYZEN) { - cn_zls_mainloop_ryzen_asm(ctx[0]); + cn_zls_mainloop_ryzen_asm(ctx); } else { - cn_zls_mainloop_bulldozer_asm(ctx[0]); + cn_zls_mainloop_bulldozer_asm(ctx); } } else if (VARIANT == xmrig::VARIANT_DOUBLE) { if (ASM == xmrig::ASM_INTEL) { - cn_double_mainloop_ivybridge_asm(ctx[0]); + cn_double_mainloop_ivybridge_asm(ctx); } else if (ASM == xmrig::ASM_RYZEN) { - cn_double_mainloop_ryzen_asm(ctx[0]); + cn_double_mainloop_ryzen_asm(ctx); } else { - cn_double_mainloop_bulldozer_asm(ctx[0]); + cn_double_mainloop_bulldozer_asm(ctx); } } else if (xmrig::cn_is_cryptonight_r()) { - ctx[0]->generated_code(ctx[0]); + ctx[0]->generated_code(ctx); } cn_implode_scratchpad(reinterpret_cast<__m128i*>(ctx[0]->memory), reinterpret_cast<__m128i*>(ctx[0]->state)); @@ -910,25 +910,25 @@ inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_ cn_explode_scratchpad(reinterpret_cast<__m128i*>(ctx[1]->state), reinterpret_cast<__m128i*>(ctx[1]->memory)); if (VARIANT == xmrig::VARIANT_2) { - cnv2_double_mainloop_sandybridge_asm(ctx[0], ctx[1]); + cnv2_double_mainloop_sandybridge_asm(ctx); } else if (VARIANT == xmrig::VARIANT_HALF) { - cn_half_double_mainloop_sandybridge_asm(ctx[0], ctx[1]); + cn_half_double_mainloop_sandybridge_asm(ctx); } else if (VARIANT == xmrig::VARIANT_TRTL) { - cn_trtl_double_mainloop_sandybridge_asm(ctx[0], ctx[1]); + cn_trtl_double_mainloop_sandybridge_asm(ctx); } else if (VARIANT == xmrig::VARIANT_RWZ) { - cnv2_rwz_double_mainloop_asm(ctx[0], ctx[1]); + cnv2_rwz_double_mainloop_asm(ctx); } else if (VARIANT == xmrig::VARIANT_ZLS) { - cn_zls_double_mainloop_sandybridge_asm(ctx[0], ctx[1]); + cn_zls_double_mainloop_sandybridge_asm(ctx); } else if (VARIANT == xmrig::VARIANT_DOUBLE) { - cn_double_double_mainloop_sandybridge_asm(ctx[0], ctx[1]); + cn_double_double_mainloop_sandybridge_asm(ctx); } else if (xmrig::cn_is_cryptonight_r()) { - ctx[0]->generated_code_double(ctx[0], ctx[1]); + ctx[0]->generated_code_double(ctx); } cn_implode_scratchpad(reinterpret_cast<__m128i*>(ctx[0]->memory), reinterpret_cast<__m128i*>(ctx[0]->state)); diff --git a/src/crypto/asm/CryptonightR_soft_aes_template.inc b/src/crypto/asm/CryptonightR_soft_aes_template.inc index 40c7874d2..e9e1bb4f6 100644 --- a/src/crypto/asm/CryptonightR_soft_aes_template.inc +++ b/src/crypto/asm/CryptonightR_soft_aes_template.inc @@ -6,6 +6,8 @@ PUBLIC FN_PREFIX(CryptonightR_soft_aes_template_end) ALIGN(64) FN_PREFIX(CryptonightR_soft_aes_template_part1): + mov rcx, [rcx] + mov QWORD PTR [rsp+8], rcx push rbx push rbp diff --git a/src/crypto/asm/CryptonightR_soft_aes_template_win.inc b/src/crypto/asm/CryptonightR_soft_aes_template_win.inc index d771f69cf..589192cab 100644 --- a/src/crypto/asm/CryptonightR_soft_aes_template_win.inc +++ b/src/crypto/asm/CryptonightR_soft_aes_template_win.inc @@ -6,6 +6,8 @@ PUBLIC CryptonightR_soft_aes_template_end ALIGN(64) CryptonightR_soft_aes_template_part1: + mov rcx, [rcx] + mov QWORD PTR [rsp+8], rcx push rbx push rbp diff --git a/src/crypto/asm/CryptonightR_template.inc b/src/crypto/asm/CryptonightR_template.inc index 8ecab7247..61b6b9855 100644 --- a/src/crypto/asm/CryptonightR_template.inc +++ b/src/crypto/asm/CryptonightR_template.inc @@ -12,6 +12,8 @@ PUBLIC FN_PREFIX(CryptonightR_template_double_end) ALIGN(64) FN_PREFIX(CryptonightR_template_part1): + mov rcx, [rcx] + mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp mov QWORD PTR [rsp+32], rsi @@ -183,6 +185,9 @@ FN_PREFIX(CryptonightR_template_end): ALIGN(64) FN_PREFIX(CryptonightR_template_double_part1): + mov rdx, [rcx+8] + mov rcx, [rcx] + mov QWORD PTR [rsp+24], rbx push rbp push rsi diff --git a/src/crypto/asm/CryptonightR_template_win.inc b/src/crypto/asm/CryptonightR_template_win.inc index a170f2d2b..1bb89eb15 100644 --- a/src/crypto/asm/CryptonightR_template_win.inc +++ b/src/crypto/asm/CryptonightR_template_win.inc @@ -12,6 +12,8 @@ PUBLIC CryptonightR_template_double_end ALIGN(64) CryptonightR_template_part1: + mov rcx, [rcx] + mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp mov QWORD PTR [rsp+32], rsi @@ -183,6 +185,9 @@ CryptonightR_template_end: ALIGN(64) CryptonightR_template_double_part1: + mov rdx, [rcx+8] + mov rcx, [rcx] + mov QWORD PTR [rsp+24], rbx push rbp push rsi diff --git a/src/crypto/asm/CryptonightWOW_soft_aes_template.inc b/src/crypto/asm/CryptonightWOW_soft_aes_template.inc index feea3949c..53b7016a0 100644 --- a/src/crypto/asm/CryptonightWOW_soft_aes_template.inc +++ b/src/crypto/asm/CryptonightWOW_soft_aes_template.inc @@ -6,6 +6,8 @@ PUBLIC FN_PREFIX(CryptonightWOW_soft_aes_template_end) ALIGN(64) FN_PREFIX(CryptonightWOW_soft_aes_template_part1): + mov rcx, [rcx] + mov QWORD PTR [rsp+8], rcx push rbx push rbp diff --git a/src/crypto/asm/CryptonightWOW_soft_aes_template_win.inc b/src/crypto/asm/CryptonightWOW_soft_aes_template_win.inc index 6ebad99f6..b3202b781 100644 --- a/src/crypto/asm/CryptonightWOW_soft_aes_template_win.inc +++ b/src/crypto/asm/CryptonightWOW_soft_aes_template_win.inc @@ -6,6 +6,8 @@ PUBLIC CryptonightWOW_soft_aes_template_end ALIGN(64) CryptonightWOW_soft_aes_template_part1: + mov rcx, [rcx] + mov QWORD PTR [rsp+8], rcx push rbx push rbp diff --git a/src/crypto/asm/CryptonightWOW_template.inc b/src/crypto/asm/CryptonightWOW_template.inc index 7183a659f..82d455f6d 100644 --- a/src/crypto/asm/CryptonightWOW_template.inc +++ b/src/crypto/asm/CryptonightWOW_template.inc @@ -12,6 +12,8 @@ PUBLIC FN_PREFIX(CryptonightWOW_template_double_end) ALIGN(64) FN_PREFIX(CryptonightWOW_template_part1): + mov rcx, [rcx] + mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp mov QWORD PTR [rsp+32], rsi @@ -165,6 +167,9 @@ FN_PREFIX(CryptonightWOW_template_end): ALIGN(64) FN_PREFIX(CryptonightWOW_template_double_part1): + mov rdx, [rcx+8] + mov rcx, [rcx] + mov QWORD PTR [rsp+24], rbx push rbp push rsi diff --git a/src/crypto/asm/CryptonightWOW_template_win.inc b/src/crypto/asm/CryptonightWOW_template_win.inc index c5652e278..644c01f13 100644 --- a/src/crypto/asm/CryptonightWOW_template_win.inc +++ b/src/crypto/asm/CryptonightWOW_template_win.inc @@ -12,6 +12,8 @@ PUBLIC CryptonightWOW_template_double_end ALIGN(64) CryptonightWOW_template_part1: + mov rcx, [rcx] + mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp mov QWORD PTR [rsp+32], rsi @@ -165,6 +167,9 @@ CryptonightWOW_template_end: ALIGN(64) CryptonightWOW_template_double_part1: + mov rdx, [rcx+8] + mov rcx, [rcx] + mov QWORD PTR [rsp+24], rbx push rbp push rsi diff --git a/src/crypto/asm/cn2/cnv2_double_main_loop_sandybridge.inc b/src/crypto/asm/cn2/cnv2_double_main_loop_sandybridge.inc index aa5101a83..1710cac70 100644 --- a/src/crypto/asm/cn2/cnv2_double_main_loop_sandybridge.inc +++ b/src/crypto/asm/cn2/cnv2_double_main_loop_sandybridge.inc @@ -1,3 +1,6 @@ + mov rdx, [rcx+8] + mov rcx, [rcx] + mov rax, rsp push rbx push rbp diff --git a/src/crypto/asm/cn2/cnv2_main_loop_bulldozer.inc b/src/crypto/asm/cn2/cnv2_main_loop_bulldozer.inc index c764501db..b881b6698 100644 --- a/src/crypto/asm/cn2/cnv2_main_loop_bulldozer.inc +++ b/src/crypto/asm/cn2/cnv2_main_loop_bulldozer.inc @@ -1,3 +1,5 @@ + mov rcx, [rcx] + mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp mov QWORD PTR [rsp+32], rsi diff --git a/src/crypto/asm/cn2/cnv2_main_loop_ivybridge.inc b/src/crypto/asm/cn2/cnv2_main_loop_ivybridge.inc index 06f1d28be..863673de1 100644 --- a/src/crypto/asm/cn2/cnv2_main_loop_ivybridge.inc +++ b/src/crypto/asm/cn2/cnv2_main_loop_ivybridge.inc @@ -1,3 +1,5 @@ + mov rcx, [rcx] + mov QWORD PTR [rsp+24], rbx push rbp push rsi diff --git a/src/crypto/asm/cn2/cnv2_main_loop_ryzen.inc b/src/crypto/asm/cn2/cnv2_main_loop_ryzen.inc index 5dbf5917f..8ccc5e179 100644 --- a/src/crypto/asm/cn2/cnv2_main_loop_ryzen.inc +++ b/src/crypto/asm/cn2/cnv2_main_loop_ryzen.inc @@ -1,3 +1,5 @@ + mov rcx, [rcx] + mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp mov QWORD PTR [rsp+32], rsi diff --git a/src/crypto/asm/cn2/cnv2_rwz_double_main_loop.inc b/src/crypto/asm/cn2/cnv2_rwz_double_main_loop.inc index d2d871732..d9bfc9c18 100644 --- a/src/crypto/asm/cn2/cnv2_rwz_double_main_loop.inc +++ b/src/crypto/asm/cn2/cnv2_rwz_double_main_loop.inc @@ -1,3 +1,6 @@ + mov rdx, [rcx+8] + mov rcx, [rcx] + mov rax, rsp push rbx push rbp diff --git a/src/crypto/asm/cn2/cnv2_rwz_main_loop.inc b/src/crypto/asm/cn2/cnv2_rwz_main_loop.inc index 021f787e3..b59c02d63 100644 --- a/src/crypto/asm/cn2/cnv2_rwz_main_loop.inc +++ b/src/crypto/asm/cn2/cnv2_rwz_main_loop.inc @@ -1,3 +1,5 @@ + mov rcx, [rcx] + mov QWORD PTR [rsp+24], rbx push rbp push rsi diff --git a/src/crypto/asm/cn_main_loop.S b/src/crypto/asm/cn_main_loop.S index 347f0e088..7aed6c20b 100644 --- a/src/crypto/asm/cn_main_loop.S +++ b/src/crypto/asm/cn_main_loop.S @@ -49,7 +49,6 @@ ALIGN(64) FN_PREFIX(cnv2_double_mainloop_sandybridge_asm): sub rsp, 48 mov rcx, rdi - mov rdx, rsi #include "cn2/cnv2_double_main_loop_sandybridge.inc" add rsp, 48 ret 0 @@ -68,7 +67,6 @@ ALIGN(64) FN_PREFIX(cnv2_rwz_double_mainloop_asm): sub rsp, 48 mov rcx, rdi - mov rdx, rsi #include "cn2/cnv2_rwz_double_main_loop.inc" add rsp, 48 ret 0 diff --git a/src/crypto/asm/win64/CryptonightR_soft_aes_template_win.inc b/src/crypto/asm/win64/CryptonightR_soft_aes_template_win.inc index d6d393a96..6898a6041 100644 --- a/src/crypto/asm/win64/CryptonightR_soft_aes_template_win.inc +++ b/src/crypto/asm/win64/CryptonightR_soft_aes_template_win.inc @@ -6,6 +6,8 @@ PUBLIC CryptonightR_soft_aes_template_end ALIGN(64) CryptonightR_soft_aes_template_part1: + mov rcx, [rcx] + mov QWORD PTR [rsp+8], rcx push rbx push rbp diff --git a/src/crypto/asm/win64/CryptonightR_template_win.inc b/src/crypto/asm/win64/CryptonightR_template_win.inc index 60ee3441b..d24eedaa9 100644 --- a/src/crypto/asm/win64/CryptonightR_template_win.inc +++ b/src/crypto/asm/win64/CryptonightR_template_win.inc @@ -12,6 +12,8 @@ PUBLIC CryptonightR_template_double_end ALIGN(64) CryptonightR_template_part1: + mov rcx, [rcx] + mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp mov QWORD PTR [rsp+32], rsi @@ -183,6 +185,9 @@ CryptonightR_template_end: ALIGN(64) CryptonightR_template_double_part1: + mov rdx, [rcx+8] + mov rcx, [rcx] + mov QWORD PTR [rsp+24], rbx push rbp push rsi diff --git a/src/crypto/asm/win64/CryptonightWOW_soft_aes_template_win.inc b/src/crypto/asm/win64/CryptonightWOW_soft_aes_template_win.inc index 682090367..1c73f77c1 100644 --- a/src/crypto/asm/win64/CryptonightWOW_soft_aes_template_win.inc +++ b/src/crypto/asm/win64/CryptonightWOW_soft_aes_template_win.inc @@ -6,6 +6,8 @@ PUBLIC CryptonightWOW_soft_aes_template_end ALIGN(64) CryptonightWOW_soft_aes_template_part1: + mov rcx, [rcx] + mov QWORD PTR [rsp+8], rcx push rbx push rbp diff --git a/src/crypto/asm/win64/CryptonightWOW_template_win.inc b/src/crypto/asm/win64/CryptonightWOW_template_win.inc index 9db2cf397..55c8c8df3 100644 --- a/src/crypto/asm/win64/CryptonightWOW_template_win.inc +++ b/src/crypto/asm/win64/CryptonightWOW_template_win.inc @@ -12,6 +12,8 @@ PUBLIC CryptonightWOW_template_double_end ALIGN(64) CryptonightWOW_template_part1: + mov rcx, [rcx] + mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp mov QWORD PTR [rsp+32], rsi @@ -165,6 +167,9 @@ CryptonightWOW_template_end: ALIGN(64) CryptonightWOW_template_double_part1: + mov rdx, [rcx+8] + mov rcx, [rcx] + mov QWORD PTR [rsp+24], rbx push rbp push rsi diff --git a/src/crypto/asm/win64/cn2/cnv2_double_main_loop_sandybridge.inc b/src/crypto/asm/win64/cn2/cnv2_double_main_loop_sandybridge.inc index 05af93934..85077a201 100644 --- a/src/crypto/asm/win64/cn2/cnv2_double_main_loop_sandybridge.inc +++ b/src/crypto/asm/win64/cn2/cnv2_double_main_loop_sandybridge.inc @@ -1,3 +1,6 @@ + mov rdx, [rcx+8] + mov rcx, [rcx] + mov rax, rsp push rbx push rbp diff --git a/src/crypto/asm/win64/cn2/cnv2_main_loop_bulldozer.inc b/src/crypto/asm/win64/cn2/cnv2_main_loop_bulldozer.inc index 03a36f48d..f17017a07 100644 --- a/src/crypto/asm/win64/cn2/cnv2_main_loop_bulldozer.inc +++ b/src/crypto/asm/win64/cn2/cnv2_main_loop_bulldozer.inc @@ -1,3 +1,5 @@ + mov rcx, [rcx] + mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp mov QWORD PTR [rsp+32], rsi diff --git a/src/crypto/asm/win64/cn2/cnv2_main_loop_ivybridge.inc b/src/crypto/asm/win64/cn2/cnv2_main_loop_ivybridge.inc index 77e28f801..a12ac35c6 100644 --- a/src/crypto/asm/win64/cn2/cnv2_main_loop_ivybridge.inc +++ b/src/crypto/asm/win64/cn2/cnv2_main_loop_ivybridge.inc @@ -1,3 +1,5 @@ + mov rcx, [rcx] + mov QWORD PTR [rsp+24], rbx push rbp push rsi diff --git a/src/crypto/asm/win64/cn2/cnv2_main_loop_ryzen.inc b/src/crypto/asm/win64/cn2/cnv2_main_loop_ryzen.inc index 7e5c127f8..044235d84 100644 --- a/src/crypto/asm/win64/cn2/cnv2_main_loop_ryzen.inc +++ b/src/crypto/asm/win64/cn2/cnv2_main_loop_ryzen.inc @@ -1,3 +1,5 @@ + mov rcx, [rcx] + mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp mov QWORD PTR [rsp+32], rsi diff --git a/src/crypto/asm/win64/cn2/cnv2_rwz_double_main_loop.inc b/src/crypto/asm/win64/cn2/cnv2_rwz_double_main_loop.inc index 69ca8793c..97fb691b5 100644 --- a/src/crypto/asm/win64/cn2/cnv2_rwz_double_main_loop.inc +++ b/src/crypto/asm/win64/cn2/cnv2_rwz_double_main_loop.inc @@ -1,3 +1,6 @@ + mov rdx, [rcx+8] + mov rcx, [rcx] + mov rax, rsp push rbx push rbp diff --git a/src/crypto/asm/win64/cn2/cnv2_rwz_main_loop.inc b/src/crypto/asm/win64/cn2/cnv2_rwz_main_loop.inc index 993177305..e2b7a5fcd 100644 --- a/src/crypto/asm/win64/cn2/cnv2_rwz_main_loop.inc +++ b/src/crypto/asm/win64/cn2/cnv2_rwz_main_loop.inc @@ -1,3 +1,5 @@ + mov rcx, [rcx] + mov QWORD PTR [rsp+24], rbx push rbp push rsi diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index c98b730ad..6548b4617 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -90,31 +90,31 @@ static void patchCode(T dst, U src, const uint32_t iterations, const uint32_t ma } -extern "C" void cnv2_mainloop_ivybridge_asm(cryptonight_ctx *ctx); -extern "C" void cnv2_mainloop_ryzen_asm(cryptonight_ctx *ctx); -extern "C" void cnv2_mainloop_bulldozer_asm(cryptonight_ctx *ctx); -extern "C" void cnv2_double_mainloop_sandybridge_asm(cryptonight_ctx *ctx0, cryptonight_ctx *ctx1); +extern "C" void cnv2_mainloop_ivybridge_asm(cryptonight_ctx **ctx); +extern "C" void cnv2_mainloop_ryzen_asm(cryptonight_ctx **ctx); +extern "C" void cnv2_mainloop_bulldozer_asm(cryptonight_ctx **ctx); +extern "C" void cnv2_double_mainloop_sandybridge_asm(cryptonight_ctx **ctx); xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ivybridge_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ryzen_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_bulldozer_asm = nullptr; -xmrig::CpuThread::cn_mainloop_double_fun cn_half_double_mainloop_sandybridge_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_half_double_mainloop_sandybridge_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_ivybridge_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_ryzen_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_bulldozer_asm = nullptr; -xmrig::CpuThread::cn_mainloop_double_fun cn_trtl_double_mainloop_sandybridge_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_trtl_double_mainloop_sandybridge_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_zls_mainloop_ivybridge_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_zls_mainloop_ryzen_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_zls_mainloop_bulldozer_asm = nullptr; -xmrig::CpuThread::cn_mainloop_double_fun cn_zls_double_mainloop_sandybridge_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_zls_double_mainloop_sandybridge_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_double_mainloop_ivybridge_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_double_mainloop_ryzen_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_double_mainloop_bulldozer_asm = nullptr; -xmrig::CpuThread::cn_mainloop_double_fun cn_double_double_mainloop_sandybridge_asm = nullptr; +xmrig::CpuThread::cn_mainloop_fun cn_double_double_mainloop_sandybridge_asm = nullptr; void xmrig::CpuThread::patchAsmVariants() @@ -125,22 +125,22 @@ void xmrig::CpuThread::patchAsmVariants() 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_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0x3000); 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_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0x7000); 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); + cn_zls_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0xB000); 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_double_double_mainloop_sandybridge_asm = reinterpret_cast (base + 0xF000); patchCode(cn_half_mainloop_ivybridge_asm, cnv2_mainloop_ivybridge_asm, xmrig::CRYPTONIGHT_HALF_ITER, xmrig::CRYPTONIGHT_MASK); patchCode(cn_half_mainloop_ryzen_asm, cnv2_mainloop_ryzen_asm, xmrig::CRYPTONIGHT_HALF_ITER, xmrig::CRYPTONIGHT_MASK); diff --git a/src/workers/CpuThread.h b/src/workers/CpuThread.h index 54e98cde5..05d4a0661 100644 --- a/src/workers/CpuThread.h +++ b/src/workers/CpuThread.h @@ -61,8 +61,7 @@ public: CpuThread(size_t index, Algo algorithm, AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch, Assembly assembly); typedef void (*cn_hash_fun)(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx **ctx, uint64_t height); - typedef void (*cn_mainloop_fun)(cryptonight_ctx *ctx); - typedef void (*cn_mainloop_double_fun)(cryptonight_ctx *ctx1, cryptonight_ctx *ctx2); + typedef void (*cn_mainloop_fun)(cryptonight_ctx **ctx); # ifndef XMRIG_NO_ASM static void patchAsmVariants(); From d57b41c67303b39e390a2a4d657d51dc22a8b9cc Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 14 Mar 2019 18:42:27 +0700 Subject: [PATCH 37/55] Sync changes. --- CMakeLists.txt | 1 + src/base/net/Pool.cpp | 2 +- src/base/tools/Chrono.h | 60 +++++++++++++++++++ src/common/interfaces/IClientListener.h | 6 +- src/common/interfaces/IConfig.h | 2 + src/common/net/Client.cpp | 8 ++- src/common/net/Job.h | 8 ++- .../net/strategies/FailoverStrategy.cpp | 2 +- src/common/net/strategies/FailoverStrategy.h | 4 +- .../net/strategies/SinglePoolStrategy.cpp | 2 +- .../net/strategies/SinglePoolStrategy.h | 4 +- src/crypto/CryptoNight_constants.h | 26 ++++++++ 12 files changed, 113 insertions(+), 12 deletions(-) create mode 100644 src/base/tools/Chrono.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 14dcc931a..94bf61b63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ set(HEADERS src/base/net/Pool.h src/base/net/Pools.h src/base/tools/Arguments.h + src/base/tools/Chrono.h src/base/tools/Handle.h src/base/tools/String.h src/common/config/CommonConfig.h diff --git a/src/base/net/Pool.cpp b/src/base/net/Pool.cpp index 9d4f2bde6..de02be92c 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -165,7 +165,7 @@ bool xmrig::Pool::isCompatible(const Algorithm &algorithm) const # ifdef XMRIG_PROXY_PROJECT if (m_algorithm.algo() == xmrig::CRYPTONIGHT && algorithm.algo() == xmrig::CRYPTONIGHT) { - return m_algorithm.variant() == xmrig::VARIANT_XTL || m_algorithm.variant() == xmrig::VARIANT_MSR; + return m_algorithm.variant() == xmrig::VARIANT_RWZ || m_algorithm.variant() == xmrig::VARIANT_ZLS; } # endif diff --git a/src/base/tools/Chrono.h b/src/base/tools/Chrono.h new file mode 100644 index 000000000..d3c146028 --- /dev/null +++ b/src/base/tools/Chrono.h @@ -0,0 +1,60 @@ +/* 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-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 . + */ + +#ifndef XMRIG_CHRONO_H +#define XMRIG_CHRONO_H + + +#include + + +namespace xmrig { + + +class Chrono +{ +public: + static inline uint64_t steadyMSecs() + { + using namespace std::chrono; + if (high_resolution_clock::is_steady) { + return static_cast(time_point_cast(high_resolution_clock::now()).time_since_epoch().count()); + } + + return static_cast(time_point_cast(steady_clock::now()).time_since_epoch().count()); + } + + + static inline uint64_t currentMSecsSinceEpoch() + { + using namespace std::chrono; + + return static_cast(time_point_cast(system_clock::now()).time_since_epoch().count()); + } +}; + + +} /* namespace xmrig */ + +#endif /* XMRIG_CHRONO_H */ diff --git a/src/common/interfaces/IClientListener.h b/src/common/interfaces/IClientListener.h index 70a3d1d0f..753847eef 100644 --- a/src/common/interfaces/IClientListener.h +++ b/src/common/interfaces/IClientListener.h @@ -29,6 +29,9 @@ #include +#include "rapidjson/fwd.h" + + namespace xmrig { @@ -43,7 +46,8 @@ public: virtual ~IClientListener() = default; virtual void onClose(Client *client, int failures) = 0; - virtual void onJobReceived(Client *client, const Job &job) = 0; + virtual void onJobReceived(Client *client, const Job &job, const rapidjson::Value ¶ms) = 0; + virtual void onLogin(Client *client, rapidjson::Document &doc, rapidjson::Value ¶ms) = 0; virtual void onLoginSuccess(Client *client) = 0; virtual void onResultAccepted(Client *client, const SubmitResult &result, const char *error) = 0; }; diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 7e6931a89..41a2f01c5 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -117,6 +117,8 @@ public: TlsCiphersKey = 1112, TlsCipherSuitesKey = 1113, TlsProtocolsKey = 1114, + AlgoExtKey = 1115, + ProxyPasswordKey = 1116, // xmrig nvidia CudaMaxThreadsKey = 1200, diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index 7cd09d46b..c08109275 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -252,7 +252,7 @@ int64_t xmrig::Client::submit(const JobResult &result) params.AddMember("nonce", StringRef(nonce), allocator); params.AddMember("result", StringRef(data), allocator); - if (m_extensions & AlgoExt) { + if ((m_extensions & AlgoExt) && result.algorithm.isValid()) { params.AddMember("algo", StringRef(result.algorithm.shortName()), allocator); } @@ -643,6 +643,8 @@ void xmrig::Client::login() params.AddMember("algo", algo, allocator); } + m_listener->onLogin(this, doc, params); + doc.AddMember("params", params, allocator); send(doc); @@ -750,7 +752,7 @@ void xmrig::Client::parseNotification(const char *method, const rapidjson::Value if (strcmp(method, "job") == 0) { int code = -1; if (parseJob(params, &code)) { - m_listener->onJobReceived(this, m_job); + m_listener->onJobReceived(this, m_job, params); } return; @@ -799,7 +801,7 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co m_failures = 0; m_listener->onLoginSuccess(this); - m_listener->onJobReceived(this, m_job); + m_listener->onJobReceived(this, m_job, result["job"]); return; } diff --git a/src/common/net/Job.h b/src/common/net/Job.h index 49ddc7da3..a6e1ec257 100644 --- a/src/common/net/Job.h +++ b/src/common/net/Job.h @@ -58,18 +58,19 @@ public: inline bool isNicehash() const { return m_nicehash; } inline bool isValid() const { return m_size > 0 && m_diff > 0; } inline bool setId(const char *id) { return m_id.setId(id); } - inline const uint32_t *nonce() const { return reinterpret_cast(m_blob + 39); } - inline const uint8_t *blob() const { return m_blob; } inline const Algorithm &algorithm() const { return m_algorithm; } inline const Id &clientId() const { return m_clientId; } inline const Id &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 int poolId() const { return m_poolId; } inline int threadId() const { return m_threadId; } inline size_t size() const { return m_size; } inline uint32_t *nonce() { return reinterpret_cast(m_blob + 39); } inline uint32_t diff() const { return static_cast(m_diff); } - inline uint64_t target() const { return m_target; } inline uint64_t height() const { return m_height; } + inline uint64_t target() const { return m_target; } + inline uint8_t fixedByte() const { return *(m_blob + 42); } inline void reset() { m_size = 0; m_diff = 0; } inline void setClientId(const Id &id) { m_clientId = id; } inline void setPoolId(int poolId) { m_poolId = poolId; } @@ -79,6 +80,7 @@ public: # 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; } # endif diff --git a/src/common/net/strategies/FailoverStrategy.cpp b/src/common/net/strategies/FailoverStrategy.cpp index c833f6e6e..1ec7449f9 100644 --- a/src/common/net/strategies/FailoverStrategy.cpp +++ b/src/common/net/strategies/FailoverStrategy.cpp @@ -150,7 +150,7 @@ void xmrig::FailoverStrategy::onClose(Client *client, int failures) } -void xmrig::FailoverStrategy::onJobReceived(Client *client, const Job &job) +void xmrig::FailoverStrategy::onJobReceived(Client *client, const Job &job, const rapidjson::Value &) { if (m_active == client->id()) { m_listener->onJob(this, client, job); diff --git a/src/common/net/strategies/FailoverStrategy.h b/src/common/net/strategies/FailoverStrategy.h index d2231a30b..a02b590e4 100644 --- a/src/common/net/strategies/FailoverStrategy.h +++ b/src/common/net/strategies/FailoverStrategy.h @@ -61,8 +61,10 @@ public: void tick(uint64_t now) override; protected: + inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {} + void onClose(Client *client, int failures) override; - void onJobReceived(Client *client, const Job &job) override; + void onJobReceived(Client *client, const Job &job, const rapidjson::Value ¶ms) override; void onLoginSuccess(Client *client) override; void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; diff --git a/src/common/net/strategies/SinglePoolStrategy.cpp b/src/common/net/strategies/SinglePoolStrategy.cpp index d17a43da1..ca5d45f73 100644 --- a/src/common/net/strategies/SinglePoolStrategy.cpp +++ b/src/common/net/strategies/SinglePoolStrategy.cpp @@ -98,7 +98,7 @@ void xmrig::SinglePoolStrategy::onClose(Client *, int) } -void xmrig::SinglePoolStrategy::onJobReceived(Client *client, const Job &job) +void xmrig::SinglePoolStrategy::onJobReceived(Client *client, const Job &job, const rapidjson::Value &) { m_listener->onJob(this, client, job); } diff --git a/src/common/net/strategies/SinglePoolStrategy.h b/src/common/net/strategies/SinglePoolStrategy.h index eeb6903e8..7d864263e 100644 --- a/src/common/net/strategies/SinglePoolStrategy.h +++ b/src/common/net/strategies/SinglePoolStrategy.h @@ -55,8 +55,10 @@ public: void tick(uint64_t now) override; protected: + inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {} + void onClose(Client *client, int failures) override; - void onJobReceived(Client *client, const Job &job) override; + void onJobReceived(Client *client, const Job &job, const rapidjson::Value ¶ms) override; void onLoginSuccess(Client *client) override; void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 58a3915fc..1bc06a3bb 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -215,6 +215,32 @@ template<> inline constexpr Variant cn_base_variant() { return V template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +inline Variant cn_base_variant(Variant variant) +{ + switch (variant) { + case VARIANT_0: + case VARIANT_XHV: + case VARIANT_XAO: + return VARIANT_0; + + case VARIANT_1: + case VARIANT_TUBE: + case VARIANT_XTL: + case VARIANT_MSR: + case VARIANT_RTO: + return VARIANT_1; + + case VARIANT_GPU: + return VARIANT_GPU; + + default: + break; + } + + return VARIANT_2; +} + + template inline constexpr bool cn_is_cryptonight_r() { return false; } template<> inline constexpr bool cn_is_cryptonight_r() { return true; } template<> inline constexpr bool cn_is_cryptonight_r() { return true; } From be5d609856f1db604f8b3203b10d7c7c9f630a32 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Mar 2019 01:06:10 +0700 Subject: [PATCH 38/55] Client refactoring. --- src/api/NetworkState.cpp | 18 ++++++----- src/api/NetworkState.h | 2 +- src/base/kernel/Process.cpp | 3 ++ src/common/net/Client.cpp | 59 +++++++++++++++++++++---------------- src/common/net/Client.h | 34 ++++++++++++++------- src/net/Network.cpp | 3 +- 6 files changed, 72 insertions(+), 47 deletions(-) diff --git a/src/api/NetworkState.cpp b/src/api/NetworkState.cpp index 0d60cbd2e..6ccc0d0fa 100644 --- a/src/api/NetworkState.cpp +++ b/src/api/NetworkState.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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 @@ -29,6 +30,7 @@ #include "api/NetworkState.h" +#include "base/tools/Chrono.h" #include "common/net/SubmitResult.h" @@ -44,12 +46,6 @@ xmrig::NetworkState::NetworkState() : } -int xmrig::NetworkState::connectionTime() const -{ - return m_active ? (int)((uv_now(uv_default_loop()) - m_connectionTime) / 1000) : 0; -} - - uint32_t xmrig::NetworkState::avgTime() const { if (m_latency.empty()) { @@ -74,6 +70,12 @@ uint32_t xmrig::NetworkState::latency() const } +uint64_t xmrig::NetworkState::connectionTime() const +{ + return m_active ? ((Chrono::steadyMSecs() - m_connectionTime) / 1000) : 0; +} + + void xmrig::NetworkState::add(const SubmitResult &result, const char *error) { if (error) { @@ -99,7 +101,7 @@ void xmrig::NetworkState::setPool(const char *host, int port, const char *ip) snprintf(pool, sizeof(pool) - 1, "%s:%d", host, port); m_active = true; - m_connectionTime = uv_now(uv_default_loop()); + m_connectionTime = Chrono::steadyMSecs(); } diff --git a/src/api/NetworkState.h b/src/api/NetworkState.h index c45761fb2..2f88d9b30 100644 --- a/src/api/NetworkState.h +++ b/src/api/NetworkState.h @@ -41,9 +41,9 @@ class NetworkState public: NetworkState(); - int connectionTime() const; uint32_t avgTime() const; uint32_t latency() const; + uint64_t connectionTime() const; void add(const SubmitResult &result, const char *error); void setPool(const char *host, int port, const char *ip); void stop(); diff --git a/src/base/kernel/Process.cpp b/src/base/kernel/Process.cpp index 0bc40e2da..7feec4810 100644 --- a/src/base/kernel/Process.cpp +++ b/src/base/kernel/Process.cpp @@ -28,6 +28,7 @@ #include "base/kernel/Process.h" +#include "version.h" static size_t location(xmrig::Process::Location location, char *buf, size_t max) @@ -51,6 +52,8 @@ xmrig::Process::Process(int argc, char **argv) : m_arguments(argc, argv) { srand(static_cast(static_cast(time(nullptr)) ^ reinterpret_cast(this))); + + uv_set_process_title(APP_DESC " " APP_VERSION); } diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index c08109275..59ad69b0b 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -37,6 +37,7 @@ #endif +#include "base/tools/Chrono.h" #include "common/interfaces/IClientListener.h" #include "common/log/Log.h" #include "common/net/Client.h" @@ -72,12 +73,11 @@ static const char *states[] = { xmrig::Client::Client(int id, const char *agent, IClientListener *listener) : + m_enabled(true), m_ipv6(false), - m_nicehash(false), m_quiet(false), m_agent(agent), m_listener(listener), - m_extensions(0), m_id(id), m_retries(5), m_retryPause(5000), @@ -252,7 +252,7 @@ int64_t xmrig::Client::submit(const JobResult &result) params.AddMember("nonce", StringRef(nonce), allocator); params.AddMember("result", StringRef(data), allocator); - if ((m_extensions & AlgoExt) && result.algorithm.isValid()) { + if (has() && result.algorithm.isValid()) { params.AddMember("algo", StringRef(result.algorithm.shortName()), allocator); } @@ -327,7 +327,7 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code) return false; } - Job job(m_id, m_nicehash, m_pool.algorithm(), m_rpcId); + Job job(m_id, has(), m_pool.algorithm(), m_rpcId); if (!job.setId(params["job_id"].GetString())) { *code = 3; @@ -402,11 +402,7 @@ bool xmrig::Client::parseLogin(const rapidjson::Value &result, int *code) return false; } - m_nicehash = m_pool.isNicehash(); - - if (result.HasMember("extensions")) { - parseExtensions(result["extensions"]); - } + parseExtensions(result); const bool rc = parseJob(result["job"], code); m_jobs = 0; @@ -547,7 +543,7 @@ int64_t xmrig::Client::send(size_t size) } } - m_expire = uv_now(uv_default_loop()) + kResponseTimeout; + m_expire = Chrono::steadyMSecs() + kResponseTimeout; return m_sequence++; } @@ -597,7 +593,7 @@ void xmrig::Client::handshake() { # ifndef XMRIG_NO_TLS if (isTLS()) { - m_expire = uv_now(uv_default_loop()) + kResponseTimeout; + m_expire = Chrono::steadyMSecs() + kResponseTimeout; m_tls->handshake(); } @@ -709,28 +705,37 @@ void xmrig::Client::parse(char *line, size_t len) } -void xmrig::Client::parseExtensions(const rapidjson::Value &value) +void xmrig::Client::parseExtensions(const rapidjson::Value &result) { - m_extensions = 0; + m_extensions.reset(); - if (!value.IsArray()) { + if (!result.HasMember("extensions")) { return; } - for (const rapidjson::Value &ext : value.GetArray()) { + const rapidjson::Value &extensions = result["extensions"]; + if (!extensions.IsArray()) { + return; + } + + for (const rapidjson::Value &ext : extensions.GetArray()) { if (!ext.IsString()) { continue; } - if (strcmp(ext.GetString(), "algo") == 0) { - m_extensions |= AlgoExt; - continue; - } + const char *name = ext.GetString(); - if (strcmp(ext.GetString(), "nicehash") == 0) { - m_extensions |= NicehashExt; - m_nicehash = true; - continue; + if (strcmp(name, "algo") == 0) { + setExtension(EXT_ALGO, true); + } + else if (strcmp(name, "nicehash") == 0) { + setExtension(EXT_NICEHASH, true); + } + else if (strcmp(name, "connect") == 0) { + setExtension(EXT_CONNECT, true); + } + else if (strcmp(name, "keepalive") == 0) { + setExtension(EXT_KEEPALIVE, true); } } } @@ -868,7 +873,7 @@ void xmrig::Client::reconnect() m_failures++; m_listener->onClose(this, (int) m_failures); - m_expire = uv_now(uv_default_loop()) + m_retryPause; + m_expire = Chrono::steadyMSecs() + m_retryPause; } @@ -888,8 +893,10 @@ void xmrig::Client::startTimeout() { m_expire = 0; - if (m_pool.keepAlive()) { - m_keepAlive = uv_now(uv_default_loop()) + (m_pool.keepAlive() * 1000); + if (has()) { + const uint64_t ms = static_cast(m_pool.keepAlive() > 0 ? m_pool.keepAlive() : Pool::kKeepAliveTimeout) * 1000; + + m_keepAlive = Chrono::steadyMSecs() + ms; } } diff --git a/src/common/net/Client.h b/src/common/net/Client.h index 9314739a2..c46395199 100644 --- a/src/common/net/Client.h +++ b/src/common/net/Client.h @@ -26,6 +26,7 @@ #define XMRIG_CLIENT_H +#include #include #include #include @@ -61,6 +62,14 @@ public: ClosingState }; + enum Extension { + EXT_ALGO, + EXT_NICEHASH, + EXT_CONNECT, + EXT_KEEPALIVE, + EXT_MAX + }; + constexpr static int kResponseTimeout = 20 * 1000; # ifndef XMRIG_NO_TLS @@ -82,6 +91,7 @@ public: void setPool(const Pool &pool); void tick(uint64_t now); + inline bool isEnabled() const { return m_enabled; } inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; } inline const char *host() const { return m_pool.host(); } inline const char *ip() const { return m_ip; } @@ -90,19 +100,16 @@ public: inline SocketState state() const { return m_state; } inline uint16_t port() const { return m_pool.port(); } inline void setAlgo(const Algorithm &algo) { m_pool.setAlgo(algo); } + inline void setEnabled(bool enabled) { m_enabled = enabled; } inline void setQuiet(bool quiet) { m_quiet = quiet; } inline void setRetries(int retries) { m_retries = retries; } inline void setRetryPause(int ms) { m_retryPause = ms; } + template inline bool has() const noexcept { return m_extensions.test(ext); } + private: class Tls; - - enum Extensions { - NicehashExt = 1, - AlgoExt = 2 - }; - bool close(); bool isCriticalError(const char *message); bool isTLS() const; @@ -119,7 +126,7 @@ private: void login(); void onClose(); void parse(char *line, size_t len); - void parseExtensions(const rapidjson::Value &value); + void parseExtensions(const rapidjson::Value &result); void parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error); void parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error); void ping(); @@ -128,7 +135,8 @@ private: void setState(SocketState state); void startTimeout(); - inline bool isQuiet() const { return m_quiet || m_failures >= m_retries; } + inline bool isQuiet() const { return m_quiet || m_failures >= m_retries; } + inline void setExtension(Extension ext, bool enable) noexcept { m_extensions.set(ext, enable); } static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf); static void onClose(uv_handle_t *handle); @@ -139,15 +147,15 @@ private: static inline Client *getClient(void *data) { return m_storage.get(data); } addrinfo m_hints; + bool m_enabled; bool m_ipv6; - bool m_nicehash; bool m_quiet; char m_buf[kInputBufferSize]; char m_ip[46]; char m_sendBuf[2048]; const char *m_agent; IClientListener *m_listener; - int m_extensions; + Id m_rpcId; int m_id; int m_retries; int m_retryPause; @@ -156,6 +164,7 @@ private: Pool m_pool; size_t m_recvBufPos; SocketState m_state; + std::bitset m_extensions; std::map m_results; Tls *m_tls; uint64_t m_expire; @@ -166,13 +175,16 @@ private: uv_getaddrinfo_t m_resolver; uv_stream_t *m_stream; uv_tcp_t *m_socket; - Id m_rpcId; static int64_t m_sequence; static Storage m_storage; }; +template<> inline bool Client::has() const noexcept { return m_extensions.test(EXT_NICEHASH) || m_pool.isNicehash(); } +template<> inline bool Client::has() const noexcept { return m_extensions.test(EXT_KEEPALIVE) || m_pool.keepAlive() > 0; } + + } /* namespace xmrig */ diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 34714c8ad..6822ad32b 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -32,6 +32,7 @@ #include "api/Api.h" +#include "base/tools/Chrono.h" #include "common/log/Log.h" #include "common/net/Client.h" #include "common/net/SubmitResult.h" @@ -204,7 +205,7 @@ void xmrig::Network::setJob(Client *client, const Job &job, bool donate) void xmrig::Network::tick() { - const uint64_t now = uv_now(uv_default_loop()); + const uint64_t now = Chrono::steadyMSecs(); m_strategy->tick(now); From ba01f2a9c4cf0acd8cc4c868d616d2782bb8d126 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Mar 2019 01:50:35 +0700 Subject: [PATCH 39/55] Rename files. --- CMakeLists.txt | 42 +++++++++---------- cmake/OpenSSL.cmake | 2 +- src/Summary.cpp | 2 +- src/api/ApiRouter.cpp | 2 +- src/api/NetworkState.cpp | 2 +- .../kernel}/interfaces/IClientListener.h | 0 .../kernel}/interfaces/IStrategy.h | 0 .../kernel}/interfaces/IStrategyListener.h | 0 .../net => base/net/stratum}/Client.cpp | 6 +-- src/{common/net => base/net/stratum}/Client.h | 10 ++--- src/{common/net => base/net/stratum}/Id.h | 0 src/{common/net => base/net/stratum}/Job.cpp | 2 +- src/{common/net => base/net/stratum}/Job.h | 2 +- src/base/net/{ => stratum}/Pool.cpp | 2 +- src/base/net/{ => stratum}/Pool.h | 0 src/base/net/{ => stratum}/Pools.cpp | 6 +-- src/base/net/{ => stratum}/Pools.h | 2 +- .../net => base/net/stratum}/SubmitResult.cpp | 2 +- .../net => base/net/stratum}/SubmitResult.h | 0 src/{common/net => base/net/stratum}/Tls.cpp | 4 +- src/{common/net => base/net/stratum}/Tls.h | 2 +- .../stratum}/strategies/FailoverStrategy.cpp | 6 +-- .../stratum}/strategies/FailoverStrategy.h | 6 +-- .../strategies/SinglePoolStrategy.cpp | 6 +-- .../stratum}/strategies/SinglePoolStrategy.h | 4 +- src/{common/net => base/net/tools}/Storage.h | 34 ++++++++------- src/common/config/CommonConfig.h | 2 +- src/net/JobResult.h | 2 +- src/net/Network.cpp | 4 +- src/net/Network.h | 2 +- src/net/strategies/DonateStrategy.cpp | 9 ++-- src/net/strategies/DonateStrategy.h | 8 ++-- src/workers/MultiWorker.h | 2 +- src/workers/Workers.h | 2 +- 34 files changed, 88 insertions(+), 87 deletions(-) rename src/{common => base/kernel}/interfaces/IClientListener.h (100%) rename src/{common => base/kernel}/interfaces/IStrategy.h (100%) rename src/{common => base/kernel}/interfaces/IStrategyListener.h (100%) rename src/{common/net => base/net/stratum}/Client.cpp (99%) rename src/{common/net => base/net/stratum}/Client.h (97%) rename src/{common/net => base/net/stratum}/Id.h (100%) rename src/{common/net => base/net/stratum}/Job.cpp (99%) rename src/{common/net => base/net/stratum}/Job.h (99%) rename src/base/net/{ => stratum}/Pool.cpp (99%) rename src/base/net/{ => stratum}/Pool.h (100%) rename src/base/net/{ => stratum}/Pools.cpp (97%) rename src/base/net/{ => stratum}/Pools.h (98%) rename src/{common/net => base/net/stratum}/SubmitResult.cpp (97%) rename src/{common/net => base/net/stratum}/SubmitResult.h (100%) rename src/{common/net => base/net/stratum}/Tls.cpp (98%) rename src/{common/net => base/net/stratum}/Tls.h (98%) rename src/{common/net => base/net/stratum}/strategies/FailoverStrategy.cpp (96%) rename src/{common/net => base/net/stratum}/strategies/FailoverStrategy.h (95%) rename src/{common/net => base/net/stratum}/strategies/SinglePoolStrategy.cpp (95%) rename src/{common/net => base/net/stratum}/strategies/SinglePoolStrategy.h (96%) rename src/{common/net => base/net/tools}/Storage.h (70%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 94bf61b63..188f595ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,14 +23,24 @@ set(HEADERS src/App.h src/base/io/Json.h src/base/io/Watcher.h + src/base/kernel/Entry.h + src/base/kernel/interfaces/IClientListener.h src/base/kernel/interfaces/IConfigListener.h src/base/kernel/interfaces/ISignalListener.h + src/base/kernel/interfaces/IStrategy.h + src/base/kernel/interfaces/IStrategyListener.h src/base/kernel/interfaces/IWatcherListener.h - src/base/kernel/Entry.h src/base/kernel/Process.h src/base/kernel/Signals.h - src/base/net/Pool.h - src/base/net/Pools.h + src/base/net/stratum/Client.h + src/base/net/stratum/Id.h + src/base/net/stratum/Job.h + src/base/net/stratum/Pool.h + src/base/net/stratum/Pools.h + src/base/net/stratum/strategies/FailoverStrategy.h + src/base/net/stratum/strategies/SinglePoolStrategy.h + src/base/net/stratum/SubmitResult.h + src/base/net/tools/Storage.h src/base/tools/Arguments.h src/base/tools/Chrono.h src/base/tools/Handle.h @@ -42,32 +52,22 @@ set(HEADERS src/common/cpu/Cpu.h src/common/crypto/Algorithm.h src/common/crypto/keccak.h - src/common/interfaces/IClientListener.h src/common/interfaces/IConfig.h src/common/interfaces/IConfigCreator.h src/common/interfaces/IConsoleListener.h src/common/interfaces/IControllerListener.h src/common/interfaces/ICpuInfo.h src/common/interfaces/ILogBackend.h - src/common/interfaces/IStrategy.h - src/common/interfaces/IStrategyListener.h src/common/log/BasicLog.h src/common/log/ConsoleLog.h src/common/log/FileLog.h src/common/log/Log.h - src/common/net/Client.h - src/common/net/Id.h - src/common/net/Job.h - src/common/net/Storage.h - src/common/net/strategies/FailoverStrategy.h - src/common/net/strategies/SinglePoolStrategy.h - src/common/net/SubmitResult.h src/common/Platform.h src/common/utils/c_str.h src/common/utils/mm_malloc.h src/common/xmrig.h - src/core/ConfigLoader_platform.h src/core/ConfigLoader_default.h + src/core/ConfigLoader_platform.h src/core/Controller.h src/interfaces/IJobResultListener.h src/interfaces/IThread.h @@ -116,8 +116,13 @@ set(SOURCES src/base/kernel/Entry.cpp src/base/kernel/Process.cpp src/base/kernel/Signals.cpp - src/base/net/Pool.cpp - src/base/net/Pools.cpp + src/base/net/stratum/Client.cpp + src/base/net/stratum/Job.cpp + src/base/net/stratum/Pool.cpp + src/base/net/stratum/Pools.cpp + src/base/net/stratum/strategies/FailoverStrategy.cpp + src/base/net/stratum/strategies/SinglePoolStrategy.cpp + src/base/net/stratum/SubmitResult.cpp src/base/tools/Arguments.cpp src/base/tools/Handle.cpp src/base/tools/String.cpp @@ -131,11 +136,6 @@ set(SOURCES src/common/log/ConsoleLog.cpp src/common/log/FileLog.cpp src/common/log/Log.cpp - src/common/net/Client.cpp - src/common/net/Job.cpp - src/common/net/strategies/FailoverStrategy.cpp - src/common/net/strategies/SinglePoolStrategy.cpp - src/common/net/SubmitResult.cpp src/common/Platform.cpp src/core/Config.cpp src/core/Controller.cpp diff --git a/cmake/OpenSSL.cmake b/cmake/OpenSSL.cmake index 79731d6f7..5761f99f4 100644 --- a/cmake/OpenSSL.cmake +++ b/cmake/OpenSSL.cmake @@ -11,7 +11,7 @@ if (WITH_TLS) find_package(OpenSSL) if (OPENSSL_FOUND) - set(TLS_SOURCES src/common/net/Tls.h src/common/net/Tls.cpp) + set(TLS_SOURCES src/base/net/stratum/Tls.h src/base/net/stratum/Tls.cpp) include_directories(${OPENSSL_INCLUDE_DIR}) else() message(FATAL_ERROR "OpenSSL NOT found: use `-DWITH_TLS=OFF` to build without TLS support") diff --git a/src/Summary.cpp b/src/Summary.cpp index 60a9278f9..7a52d1b13 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -28,7 +28,7 @@ #include -#include "base/net/Pool.h" +#include "base/net/stratum/Pool.h" #include "common/cpu/Cpu.h" #include "common/log/Log.h" #include "core/Config.h" diff --git a/src/api/ApiRouter.cpp b/src/api/ApiRouter.cpp index bdedac4d3..ff99c0475 100644 --- a/src/api/ApiRouter.cpp +++ b/src/api/ApiRouter.cpp @@ -34,11 +34,11 @@ #include "api/ApiRouter.h" +#include "base/net/stratum/Job.h" #include "common/api/HttpReply.h" #include "common/api/HttpRequest.h" #include "common/cpu/Cpu.h" #include "common/crypto/keccak.h" -#include "common/net/Job.h" #include "common/Platform.h" #include "core/Config.h" #include "core/Controller.h" diff --git a/src/api/NetworkState.cpp b/src/api/NetworkState.cpp index 6ccc0d0fa..8a541eaa5 100644 --- a/src/api/NetworkState.cpp +++ b/src/api/NetworkState.cpp @@ -30,8 +30,8 @@ #include "api/NetworkState.h" +#include "base/net/stratum/SubmitResult.h" #include "base/tools/Chrono.h" -#include "common/net/SubmitResult.h" xmrig::NetworkState::NetworkState() : diff --git a/src/common/interfaces/IClientListener.h b/src/base/kernel/interfaces/IClientListener.h similarity index 100% rename from src/common/interfaces/IClientListener.h rename to src/base/kernel/interfaces/IClientListener.h diff --git a/src/common/interfaces/IStrategy.h b/src/base/kernel/interfaces/IStrategy.h similarity index 100% rename from src/common/interfaces/IStrategy.h rename to src/base/kernel/interfaces/IStrategy.h diff --git a/src/common/interfaces/IStrategyListener.h b/src/base/kernel/interfaces/IStrategyListener.h similarity index 100% rename from src/common/interfaces/IStrategyListener.h rename to src/base/kernel/interfaces/IStrategyListener.h diff --git a/src/common/net/Client.cpp b/src/base/net/stratum/Client.cpp similarity index 99% rename from src/common/net/Client.cpp rename to src/base/net/stratum/Client.cpp index 59ad69b0b..1dfbc7fd5 100644 --- a/src/common/net/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -33,14 +33,14 @@ #ifndef XMRIG_NO_TLS # include # include -# include "common/net/Tls.h" +# include "base/net/stratum/Tls.h" #endif +#include "base/kernel/interfaces/IClientListener.h" +#include "base/net/stratum/Client.h" #include "base/tools/Chrono.h" -#include "common/interfaces/IClientListener.h" #include "common/log/Log.h" -#include "common/net/Client.h" #include "net/JobResult.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" diff --git a/src/common/net/Client.h b/src/base/net/stratum/Client.h similarity index 97% rename from src/common/net/Client.h rename to src/base/net/stratum/Client.h index c46395199..977a3681f 100644 --- a/src/common/net/Client.h +++ b/src/base/net/stratum/Client.h @@ -32,12 +32,12 @@ #include -#include "base/net/Pool.h" +#include "base/net/stratum/Id.h" +#include "base/net/stratum/Job.h" +#include "base/net/stratum/Pool.h" +#include "base/net/stratum/SubmitResult.h" +#include "base/net/tools/Storage.h" #include "common/crypto/Algorithm.h" -#include "common/net/Id.h" -#include "common/net/Job.h" -#include "common/net/Storage.h" -#include "common/net/SubmitResult.h" #include "rapidjson/fwd.h" diff --git a/src/common/net/Id.h b/src/base/net/stratum/Id.h similarity index 100% rename from src/common/net/Id.h rename to src/base/net/stratum/Id.h diff --git a/src/common/net/Job.cpp b/src/base/net/stratum/Job.cpp similarity index 99% rename from src/common/net/Job.cpp rename to src/base/net/stratum/Job.cpp index 851507adc..3fb691ced 100644 --- a/src/common/net/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -28,7 +28,7 @@ #include -#include "common/net/Job.h" +#include "base/net/stratum/Job.h" unsigned char hf_hex2bin(char c, bool &err) diff --git a/src/common/net/Job.h b/src/base/net/stratum/Job.h similarity index 99% rename from src/common/net/Job.h rename to src/base/net/stratum/Job.h index a6e1ec257..426a64ded 100644 --- a/src/common/net/Job.h +++ b/src/base/net/stratum/Job.h @@ -32,7 +32,7 @@ #include "common/crypto/Algorithm.h" -#include "common/net/Id.h" +#include "base/net/stratum/Id.h" namespace xmrig { diff --git a/src/base/net/Pool.cpp b/src/base/net/stratum/Pool.cpp similarity index 99% rename from src/base/net/Pool.cpp rename to src/base/net/stratum/Pool.cpp index de02be92c..f371b4c07 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/stratum/Pool.cpp @@ -30,7 +30,7 @@ #include "base/io/Json.h" -#include "base/net/Pool.h" +#include "base/net/stratum/Pool.h" #include "rapidjson/document.h" diff --git a/src/base/net/Pool.h b/src/base/net/stratum/Pool.h similarity index 100% rename from src/base/net/Pool.h rename to src/base/net/stratum/Pool.h diff --git a/src/base/net/Pools.cpp b/src/base/net/stratum/Pools.cpp similarity index 97% rename from src/base/net/Pools.cpp rename to src/base/net/stratum/Pools.cpp index e3b86acac..ba55e94b1 100644 --- a/src/base/net/Pools.cpp +++ b/src/base/net/stratum/Pools.cpp @@ -23,10 +23,10 @@ */ -#include "base/net/Pools.h" +#include "base/net/stratum/Pools.h" +#include "base/net/stratum/strategies/FailoverStrategy.h" +#include "base/net/stratum/strategies/SinglePoolStrategy.h" #include "common/log/Log.h" -#include "common/net/strategies/FailoverStrategy.h" -#include "common/net/strategies/SinglePoolStrategy.h" #include "rapidjson/document.h" diff --git a/src/base/net/Pools.h b/src/base/net/stratum/Pools.h similarity index 98% rename from src/base/net/Pools.h rename to src/base/net/stratum/Pools.h index a6038a044..0f856c695 100644 --- a/src/base/net/Pools.h +++ b/src/base/net/stratum/Pools.h @@ -29,7 +29,7 @@ #include -#include "base/net/Pool.h" +#include "base/net/stratum/Pool.h" namespace xmrig { diff --git a/src/common/net/SubmitResult.cpp b/src/base/net/stratum/SubmitResult.cpp similarity index 97% rename from src/common/net/SubmitResult.cpp rename to src/base/net/stratum/SubmitResult.cpp index d14bbb408..ad8a48af0 100644 --- a/src/common/net/SubmitResult.cpp +++ b/src/base/net/stratum/SubmitResult.cpp @@ -26,7 +26,7 @@ #include -#include "common/net/SubmitResult.h" +#include "base/net/stratum/SubmitResult.h" xmrig::SubmitResult::SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId) : diff --git a/src/common/net/SubmitResult.h b/src/base/net/stratum/SubmitResult.h similarity index 100% rename from src/common/net/SubmitResult.h rename to src/base/net/stratum/SubmitResult.h diff --git a/src/common/net/Tls.cpp b/src/base/net/stratum/Tls.cpp similarity index 98% rename from src/common/net/Tls.cpp rename to src/base/net/stratum/Tls.cpp index a9b3fa7de..04aeae92c 100644 --- a/src/common/net/Tls.cpp +++ b/src/base/net/stratum/Tls.cpp @@ -27,8 +27,8 @@ #include -#include "common/net/Client.h" -#include "common/net/Tls.h" +#include "base/net/stratum/Client.h" +#include "base/net/stratum/Tls.h" #include "common/log/Log.h" diff --git a/src/common/net/Tls.h b/src/base/net/stratum/Tls.h similarity index 98% rename from src/common/net/Tls.h rename to src/base/net/stratum/Tls.h index cce78eeb4..e070be526 100644 --- a/src/common/net/Tls.h +++ b/src/base/net/stratum/Tls.h @@ -29,7 +29,7 @@ #include -#include "common/net/Client.h" +#include "base/net/stratum/Client.h" namespace xmrig { diff --git a/src/common/net/strategies/FailoverStrategy.cpp b/src/base/net/stratum/strategies/FailoverStrategy.cpp similarity index 96% rename from src/common/net/strategies/FailoverStrategy.cpp rename to src/base/net/stratum/strategies/FailoverStrategy.cpp index 1ec7449f9..d2e4a6da3 100644 --- a/src/common/net/strategies/FailoverStrategy.cpp +++ b/src/base/net/stratum/strategies/FailoverStrategy.cpp @@ -23,9 +23,9 @@ */ -#include "common/interfaces/IStrategyListener.h" -#include "common/net/Client.h" -#include "common/net/strategies/FailoverStrategy.h" +#include "base/kernel/interfaces/IStrategyListener.h" +#include "base/net/stratum/Client.h" +#include "base/net/stratum/strategies/FailoverStrategy.h" #include "common/Platform.h" diff --git a/src/common/net/strategies/FailoverStrategy.h b/src/base/net/stratum/strategies/FailoverStrategy.h similarity index 95% rename from src/common/net/strategies/FailoverStrategy.h rename to src/base/net/stratum/strategies/FailoverStrategy.h index a02b590e4..3517de9d1 100644 --- a/src/common/net/strategies/FailoverStrategy.h +++ b/src/base/net/stratum/strategies/FailoverStrategy.h @@ -29,9 +29,9 @@ #include -#include "base/net/Pool.h" -#include "common/interfaces/IClientListener.h" -#include "common/interfaces/IStrategy.h" +#include "base/kernel/interfaces/IClientListener.h" +#include "base/kernel/interfaces/IStrategy.h" +#include "base/net/stratum/Pool.h" namespace xmrig { diff --git a/src/common/net/strategies/SinglePoolStrategy.cpp b/src/base/net/stratum/strategies/SinglePoolStrategy.cpp similarity index 95% rename from src/common/net/strategies/SinglePoolStrategy.cpp rename to src/base/net/stratum/strategies/SinglePoolStrategy.cpp index ca5d45f73..b81594e14 100644 --- a/src/common/net/strategies/SinglePoolStrategy.cpp +++ b/src/base/net/stratum/strategies/SinglePoolStrategy.cpp @@ -23,9 +23,9 @@ */ -#include "common/interfaces/IStrategyListener.h" -#include "common/net/Client.h" -#include "common/net/strategies/SinglePoolStrategy.h" +#include "base/kernel/interfaces/IStrategyListener.h" +#include "base/net/stratum/Client.h" +#include "base/net/stratum/strategies/SinglePoolStrategy.h" #include "common/Platform.h" diff --git a/src/common/net/strategies/SinglePoolStrategy.h b/src/base/net/stratum/strategies/SinglePoolStrategy.h similarity index 96% rename from src/common/net/strategies/SinglePoolStrategy.h rename to src/base/net/stratum/strategies/SinglePoolStrategy.h index 7d864263e..5b3016c13 100644 --- a/src/common/net/strategies/SinglePoolStrategy.h +++ b/src/base/net/stratum/strategies/SinglePoolStrategy.h @@ -26,8 +26,8 @@ #define XMRIG_SINGLEPOOLSTRATEGY_H -#include "common/interfaces/IClientListener.h" -#include "common/interfaces/IStrategy.h" +#include "base/kernel/interfaces/IClientListener.h" +#include "base/kernel/interfaces/IStrategy.h" namespace xmrig { diff --git a/src/common/net/Storage.h b/src/base/net/tools/Storage.h similarity index 70% rename from src/common/net/Storage.h rename to src/base/net/tools/Storage.h index f36ce5946..aff624816 100644 --- a/src/common/net/Storage.h +++ b/src/base/net/tools/Storage.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __STORAGE_H__ -#define __STORAGE_H__ +#ifndef XMRIG_STORAGE_H +#define XMRIG_STORAGE_H #include @@ -53,11 +54,10 @@ public: inline static void *ptr(uintptr_t id) { return reinterpret_cast(id); } - inline TYPE *get(void *id) const { return get(reinterpret_cast(id)); } + inline TYPE *get(const void *id) const { return get(reinterpret_cast(id)); } inline TYPE *get(uintptr_t id) const { assert(m_data.count(id) > 0); - if (m_data.count(id) == 0) { return nullptr; } @@ -66,20 +66,22 @@ public: } - inline void remove(void *id) { remove(reinterpret_cast(id)); } - inline void remove(uintptr_t id) + inline void remove(const void *id) { delete release(reinterpret_cast(id)); } + inline void remove(uintptr_t id) { delete release(id); } + + + inline TYPE *release(const void *id) { release(reinterpret_cast(id)); } + inline TYPE *release(uintptr_t id) { TYPE *obj = get(id); - if (obj == nullptr) { - return; + if (obj != nullptr) { + auto it = m_data.find(id); + if (it != m_data.end()) { + m_data.erase(it); + } } - auto it = m_data.find(id); - if (it != m_data.end()) { - m_data.erase(it); - } - - delete obj; + return obj; } @@ -92,4 +94,4 @@ private: } /* namespace xmrig */ -#endif /* __STORAGE_H__ */ +#endif /* XMRIG_STORAGE_H */ diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 103e69d24..729c24510 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -26,7 +26,7 @@ #define XMRIG_COMMONCONFIG_H -#include "base/net/Pools.h" +#include "base/net/stratum/Pools.h" #include "base/tools/String.h" #include "common/interfaces/IConfig.h" #include "common/xmrig.h" diff --git a/src/net/JobResult.h b/src/net/JobResult.h index 5ab4d2942..2e5b08688 100644 --- a/src/net/JobResult.h +++ b/src/net/JobResult.h @@ -31,7 +31,7 @@ #include -#include "common/net/Job.h" +#include "base/net/stratum/Job.h" namespace xmrig { diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 6822ad32b..b8f4f05e7 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -32,10 +32,10 @@ #include "api/Api.h" +#include "base/net/stratum/Client.h" +#include "base/net/stratum/SubmitResult.h" #include "base/tools/Chrono.h" #include "common/log/Log.h" -#include "common/net/Client.h" -#include "common/net/SubmitResult.h" #include "core/Config.h" #include "core/Controller.h" #include "net/Network.h" diff --git a/src/net/Network.h b/src/net/Network.h index 5a5cbc3ef..8796045a2 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -31,8 +31,8 @@ #include "api/NetworkState.h" +#include "base/kernel/interfaces/IStrategyListener.h" #include "common/interfaces/IControllerListener.h" -#include "common/interfaces/IStrategyListener.h" #include "interfaces/IJobResultListener.h" diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 9593dc9a8..f056d498c 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -23,12 +23,11 @@ */ +#include "base/net/stratum/Client.h" +#include "base/net/stratum/Job.h" +#include "base/net/stratum/strategies/FailoverStrategy.h" +#include "base/net/stratum/strategies/SinglePoolStrategy.h" #include "common/crypto/keccak.h" -#include "common/interfaces/IStrategyListener.h" -#include "common/net/Client.h" -#include "common/net/Job.h" -#include "common/net/strategies/FailoverStrategy.h" -#include "common/net/strategies/SinglePoolStrategy.h" #include "common/Platform.h" #include "common/xmrig.h" #include "net/strategies/DonateStrategy.h" diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 76702ef32..8c350097e 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -30,10 +30,10 @@ #include -#include "base/net/Pool.h" -#include "common/interfaces/IClientListener.h" -#include "common/interfaces/IStrategy.h" -#include "common/interfaces/IStrategyListener.h" +#include "base/kernel/interfaces/IClientListener.h" +#include "base/kernel/interfaces/IStrategy.h" +#include "base/kernel/interfaces/IStrategyListener.h" +#include "base/net/stratum/Pool.h" namespace xmrig { diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index b7e4c8cae..525eee18c 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -27,7 +27,7 @@ #define XMRIG_MULTIWORKER_H -#include "common/net/Job.h" +#include "base/net/stratum/Job.h" #include "Mem.h" #include "net/JobResult.h" #include "workers/Worker.h" diff --git a/src/workers/Workers.h b/src/workers/Workers.h index a9b8e6958..0760c98f3 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -31,7 +31,7 @@ #include #include -#include "common/net/Job.h" +#include "base/net/stratum/Job.h" #include "net/JobResult.h" #include "rapidjson/fwd.h" From 8c362411efddd796aa74746605c40777a1eaa2f0 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Mar 2019 02:03:01 +0700 Subject: [PATCH 40/55] Removed class Id. --- CMakeLists.txt | 1 - src/base/net/stratum/Client.cpp | 5 +- src/base/net/stratum/Client.h | 3 +- src/base/net/stratum/Id.h | 98 --------------------------------- src/base/net/stratum/Job.cpp | 14 ++--- src/base/net/stratum/Job.h | 20 +++---- src/net/JobResult.h | 9 +-- 7 files changed, 26 insertions(+), 124 deletions(-) delete mode 100644 src/base/net/stratum/Id.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 188f595ce..f83045890 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,6 @@ set(HEADERS src/base/kernel/Process.h src/base/kernel/Signals.h src/base/net/stratum/Client.h - src/base/net/stratum/Id.h src/base/net/stratum/Job.h src/base/net/stratum/Pool.h src/base/net/stratum/Pools.h diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 1dfbc7fd5..cffbe5432 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -397,7 +397,8 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code) bool xmrig::Client::parseLogin(const rapidjson::Value &result, int *code) { - if (!m_rpcId.setId(result["id"].GetString())) { + m_rpcId = result["id"].GetString(); + if (m_rpcId.isNull()) { *code = 1; return false; } @@ -498,7 +499,7 @@ int64_t xmrig::Client::send(const rapidjson::Document &doc) { using namespace rapidjson; - StringBuffer buffer(0, 512); + StringBuffer buffer(nullptr, 512); Writer writer(buffer); doc.Accept(writer); diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index 977a3681f..ed433ff95 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -32,7 +32,6 @@ #include -#include "base/net/stratum/Id.h" #include "base/net/stratum/Job.h" #include "base/net/stratum/Pool.h" #include "base/net/stratum/SubmitResult.h" @@ -155,7 +154,6 @@ private: char m_sendBuf[2048]; const char *m_agent; IClientListener *m_listener; - Id m_rpcId; int m_id; int m_retries; int m_retryPause; @@ -166,6 +164,7 @@ private: SocketState m_state; std::bitset m_extensions; std::map m_results; + String m_rpcId; Tls *m_tls; uint64_t m_expire; uint64_t m_jobs; diff --git a/src/base/net/stratum/Id.h b/src/base/net/stratum/Id.h deleted file mode 100644 index 999e7837a..000000000 --- a/src/base/net/stratum/Id.h +++ /dev/null @@ -1,98 +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-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_ID_H -#define XMRIG_ID_H - - -#include - - -namespace xmrig { - - -class Id -{ -public: - inline Id() : - m_data() - { - } - - - inline Id(const char *id, size_t sizeFix = 0) - { - setId(id, sizeFix); - } - - - inline bool operator==(const Id &other) const - { - return memcmp(m_data, other.m_data, sizeof(m_data)) == 0; - } - - - inline bool operator!=(const Id &other) const - { - return memcmp(m_data, other.m_data, sizeof(m_data)) != 0; - } - - - Id &operator=(const Id &other) - { - memcpy(m_data, other.m_data, sizeof(m_data)); - - return *this; - } - - - inline bool setId(const char *id, size_t sizeFix = 0) - { - memset(m_data, 0, sizeof(m_data)); - if (!id) { - return false; - } - - const size_t size = strlen(id); - if (size >= sizeof(m_data)) { - return false; - } - - memcpy(m_data, id, size - sizeFix); - return true; - } - - - inline const char *data() const { return m_data; } - inline bool isValid() const { return *m_data != '\0'; } - - -private: - char m_data[64]; -}; - - -} /* namespace xmrig */ - - -#endif /* XMRIG_ID_H */ diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index 3fb691ced..c9902f49d 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -65,25 +65,25 @@ xmrig::Job::Job() : m_threadId(-1), m_size(0), m_diff(0), + m_height(0), m_target(0), - m_blob(), - m_height(0) + m_blob() { } -xmrig::Job::Job(int poolId, bool nicehash, const Algorithm &algorithm, const Id &clientId) : +xmrig::Job::Job(int poolId, bool nicehash, const Algorithm &algorithm, const String &clientId) : + m_algorithm(algorithm), m_autoVariant(algorithm.variant() == VARIANT_AUTO), m_nicehash(nicehash), m_poolId(poolId), m_threadId(-1), m_size(0), + m_clientId(clientId), m_diff(0), - m_target(0), - m_blob(), m_height(0), - m_algorithm(algorithm), - m_clientId(clientId) + m_target(0), + m_blob() { } diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index 426a64ded..878274e8c 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -31,8 +31,8 @@ #include +#include "base/tools/String.h" #include "common/crypto/Algorithm.h" -#include "base/net/stratum/Id.h" namespace xmrig { @@ -46,7 +46,7 @@ public: static constexpr const size_t kMaxBlobSize = 128; Job(); - Job(int poolId, bool nicehash, const Algorithm &algorithm, const Id &clientId); + Job(int poolId, bool nicehash, const Algorithm &algorithm, const String &clientId); ~Job(); bool isEqual(const Job &other) const; @@ -57,10 +57,10 @@ public: inline bool isNicehash() const { return m_nicehash; } inline bool isValid() const { return m_size > 0 && m_diff > 0; } - inline bool setId(const char *id) { return m_id.setId(id); } + inline bool setId(const char *id) { return m_id = id; } inline const Algorithm &algorithm() const { return m_algorithm; } - inline const Id &clientId() const { return m_clientId; } - inline const Id &id() const { return m_id; } + inline const String &clientId() const { return m_clientId; } + 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 int poolId() const { return m_poolId; } @@ -72,7 +72,7 @@ public: inline uint64_t target() const { return m_target; } inline uint8_t fixedByte() const { return *(m_blob + 42); } inline void reset() { m_size = 0; m_diff = 0; } - inline void setClientId(const Id &id) { m_clientId = id; } + inline void setClientId(const String &id) { m_clientId = id; } inline void setPoolId(int poolId) { m_poolId = poolId; } inline void setThreadId(int threadId) { m_threadId = threadId; } inline void setVariant(const char *variant) { m_algorithm.parseVariant(variant); } @@ -99,18 +99,18 @@ public: private: Variant variant() const; + Algorithm m_algorithm; bool m_autoVariant; bool m_nicehash; int m_poolId; int m_threadId; size_t m_size; + String m_clientId; + String m_id; uint64_t m_diff; + uint64_t m_height; uint64_t m_target; uint8_t m_blob[kMaxBlobSize]; - uint64_t m_height; - xmrig::Algorithm m_algorithm; - xmrig::Id m_clientId; - xmrig::Id m_id; # ifdef XMRIG_PROXY_PROJECT char m_rawBlob[kMaxBlobSize * 2 + 8]; diff --git a/src/net/JobResult.h b/src/net/JobResult.h index 2e5b08688..9d2300b57 100644 --- a/src/net/JobResult.h +++ b/src/net/JobResult.h @@ -31,6 +31,7 @@ #include +#include "base/tools/String.h" #include "base/net/stratum/Job.h" @@ -41,11 +42,11 @@ class JobResult { public: inline JobResult() : poolId(0), diff(0), nonce(0) {} - inline JobResult(int poolId, const Id &jobId, const Id &clientId, uint32_t nonce, const uint8_t *result, uint32_t diff, const Algorithm &algorithm) : + inline JobResult(int poolId, const String &jobId, const String &clientId, uint32_t nonce, const uint8_t *result, uint32_t diff, const Algorithm &algorithm) : algorithm(algorithm), + poolId(poolId), clientId(clientId), jobId(jobId), - poolId(poolId), diff(diff), nonce(nonce) { @@ -71,9 +72,9 @@ public: Algorithm algorithm; - Id clientId; - Id jobId; int poolId; + String clientId; + String jobId; uint32_t diff; uint32_t nonce; uint8_t result[32]; From 9808fbe3963dc1af389d2b632e4bec215aeae85a Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Mar 2019 02:25:38 +0700 Subject: [PATCH 41/55] Added class Buffer. --- CMakeLists.txt | 2 + src/api/ApiRouter.cpp | 4 +- src/base/net/stratum/Client.cpp | 5 +- src/base/net/stratum/Job.cpp | 68 +-------- src/base/net/stratum/Job.h | 6 - src/base/net/stratum/Tls.cpp | 3 +- src/base/tools/Buffer.cpp | 201 ++++++++++++++++++++++++++ src/base/tools/Buffer.h | 88 +++++++++++ src/net/strategies/DonateStrategy.cpp | 3 +- 9 files changed, 304 insertions(+), 76 deletions(-) create mode 100644 src/base/tools/Buffer.cpp create mode 100644 src/base/tools/Buffer.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f83045890..81ad18f6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ set(HEADERS src/base/net/stratum/SubmitResult.h src/base/net/tools/Storage.h src/base/tools/Arguments.h + src/base/tools/Buffer.h src/base/tools/Chrono.h src/base/tools/Handle.h src/base/tools/String.h @@ -123,6 +124,7 @@ set(SOURCES src/base/net/stratum/strategies/SinglePoolStrategy.cpp src/base/net/stratum/SubmitResult.cpp src/base/tools/Arguments.cpp + src/base/tools/Buffer.cpp src/base/tools/Handle.cpp src/base/tools/String.cpp src/common/config/CommonConfig.cpp diff --git a/src/api/ApiRouter.cpp b/src/api/ApiRouter.cpp index ff99c0475..5f3b1f634 100644 --- a/src/api/ApiRouter.cpp +++ b/src/api/ApiRouter.cpp @@ -34,7 +34,7 @@ #include "api/ApiRouter.h" -#include "base/net/stratum/Job.h" +#include "base/tools/Buffer.h" #include "common/api/HttpReply.h" #include "common/api/HttpRequest.h" #include "common/cpu/Cpu.h" @@ -174,7 +174,7 @@ void ApiRouter::genId(const char *id) memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, strlen(APP_KIND)); xmrig::keccak(input, inSize, hash); - xmrig::Job::toHex(hash, 8, m_id); + xmrig::Buffer::toHex(hash, 8, m_id); delete [] input; break; diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index cffbe5432..5b330311b 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -39,6 +39,7 @@ #include "base/kernel/interfaces/IClientListener.h" #include "base/net/stratum/Client.h" +#include "base/tools/Buffer.h" #include "base/tools/Chrono.h" #include "common/log/Log.h" #include "net/JobResult.h" @@ -232,10 +233,10 @@ int64_t xmrig::Client::submit(const JobResult &result) char *nonce = m_sendBuf; char *data = m_sendBuf + 16; - Job::toHex(reinterpret_cast(&result.nonce), 4, nonce); + Buffer::toHex(reinterpret_cast(&result.nonce), 4, nonce); nonce[8] = '\0'; - Job::toHex(result.result, 32, data); + Buffer::toHex(result.result, 32, data); data[64] = '\0'; # endif diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index c9902f49d..f8239459c 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -29,33 +29,7 @@ #include "base/net/stratum/Job.h" - - -unsigned char hf_hex2bin(char c, bool &err) -{ - if (c >= '0' && c <= '9') { - return c - '0'; - } - else if (c >= 'a' && c <= 'f') { - return c - 'a' + 0xA; - } - else if (c >= 'A' && c <= 'F') { - return c - 'A' + 0xA; - } - - err = true; - return 0; -} - - -char hf_bin2hex(unsigned char c) -{ - if (c <= 0x9) { - return '0' + c; - } - - return 'a' - 0xA + c; -} +#include "base/tools/Buffer.h" xmrig::Job::Job() : @@ -115,7 +89,7 @@ bool xmrig::Job::setBlob(const char *blob) return false; } - if (!fromHex(blob, (int) m_size * 2, m_blob)) { + if (!Buffer::fromHex(blob, m_size * 2, m_blob)) { return false; } @@ -167,7 +141,7 @@ bool xmrig::Job::setTarget(const char *target) char str[8]; memcpy(str, target, len); - if (!fromHex(str, 8, reinterpret_cast(&tmp)) || tmp == 0) { + if (!Buffer::fromHex(str, 8, reinterpret_cast(&tmp)) || tmp == 0) { return false; } @@ -178,7 +152,7 @@ bool xmrig::Job::setTarget(const char *target) char str[16]; memcpy(str, target, len); - if (!fromHex(str, 16, reinterpret_cast(&m_target)) || m_target == 0) { + if (!Buffer::fromHex(str, 16, reinterpret_cast(&m_target)) || m_target == 0) { return false; } } @@ -212,40 +186,6 @@ void xmrig::Job::setHeight(uint64_t height) } -bool xmrig::Job::fromHex(const char* in, unsigned int len, unsigned char* out) -{ - bool error = false; - for (unsigned int i = 0; i < len; i += 2) { - out[i / 2] = (hf_hex2bin(in[i], error) << 4) | hf_hex2bin(in[i + 1], error); - - if (error) { - return false; - } - } - return true; -} - - -void xmrig::Job::toHex(const unsigned char* in, unsigned int len, char* out) -{ - for (unsigned int i = 0; i < len; i++) { - out[i * 2] = hf_bin2hex((in[i] & 0xF0) >> 4); - out[i * 2 + 1] = hf_bin2hex(in[i] & 0x0F); - } -} - - -#ifdef APP_DEBUG -char *xmrig::Job::toHex(const unsigned char* in, unsigned int len) -{ - char *out = new char[len * 2 + 1](); - toHex(in, len, out); - - return out; -} -#endif - - 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 878274e8c..8fc3d7097 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -84,14 +84,8 @@ public: inline const char *rawTarget() const { return m_rawTarget; } # endif - static bool fromHex(const char* in, unsigned int len, unsigned char* out); static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast(blob + 39); } static inline uint64_t toDiff(uint64_t target) { return 0xFFFFFFFFFFFFFFFFULL / target; } - static void toHex(const unsigned char* in, unsigned int len, char* out); - -# ifdef APP_DEBUG - static char *toHex(const unsigned char* in, unsigned int len); -# endif inline bool operator==(const Job &other) const { return isEqual(other); } inline bool operator!=(const Job &other) const { return !isEqual(other); } diff --git a/src/base/net/stratum/Tls.cpp b/src/base/net/stratum/Tls.cpp index 04aeae92c..e8948f34f 100644 --- a/src/base/net/stratum/Tls.cpp +++ b/src/base/net/stratum/Tls.cpp @@ -29,6 +29,7 @@ #include "base/net/stratum/Client.h" #include "base/net/stratum/Tls.h" +#include "base/tools/Buffer.h" #include "common/log/Log.h" @@ -183,7 +184,7 @@ bool xmrig::Client::Tls::verifyFingerprint(X509 *cert) return false; } - Job::toHex(md, 32, m_fingerprint); + Buffer::toHex(md, 32, m_fingerprint); const char *fingerprint = m_client->m_pool.fingerprint(); return fingerprint == nullptr || strncasecmp(m_fingerprint, fingerprint, 64) == 0; diff --git a/src/base/tools/Buffer.cpp b/src/base/tools/Buffer.cpp new file mode 100644 index 000000000..05a68cb4c --- /dev/null +++ b/src/base/tools/Buffer.cpp @@ -0,0 +1,201 @@ +/* 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-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 "base/tools/Buffer.h" + + +static inline uint8_t hf_hex2bin(uint8_t c, bool &err) +{ + if (c >= '0' && c <= '9') { + return c - '0'; + } + else if (c >= 'a' && c <= 'f') { + return c - 'a' + 0xA; + } + else if (c >= 'A' && c <= 'F') { + return c - 'A' + 0xA; + } + + err = true; + return 0; +} + + +static inline uint8_t hf_bin2hex(uint8_t c) +{ + if (c <= 0x9) { + return '0' + c; + } + + return 'a' - 0xA + c; +} + + +xmrig::Buffer::Buffer() : + m_data(nullptr), + m_size(0) +{ +} + + +xmrig::Buffer::Buffer(Buffer &&other) : + m_data(other.m_data), + m_size(other.m_size) +{ + other.m_data = nullptr; + other.m_size = 0; +} + + +xmrig::Buffer::Buffer(const Buffer &other) +{ + copy(other.data(), other.size()); +} + + +xmrig::Buffer::Buffer(const char *data, size_t size) +{ + copy(data, size); +} + + +xmrig::Buffer::Buffer(size_t size) : + m_size(size) +{ + m_data = new char[size](); +} + + +xmrig::Buffer::~Buffer() +{ + delete [] m_data; +} + + +void xmrig::Buffer::from(const char *data, size_t size) +{ + if (m_size > 0) { + if (m_size == size) { + memcpy(m_data, data, m_size); + + return; + } + + delete [] m_data; + } + + copy(data, size); +} + + +xmrig::Buffer xmrig::Buffer::allocUnsafe(size_t size) +{ + Buffer buf; + buf.m_size = size; + buf.m_data = new char[size]; + + return buf; +} + + +bool xmrig::Buffer::fromHex(const uint8_t *in, size_t size, uint8_t *out) +{ + bool error = false; + for (size_t i = 0; i < size; i += 2) { + out[i / 2] = static_cast((hf_hex2bin(in[i], error) << 4) | hf_hex2bin(in[i + 1], error)); + + if (error) { + return false; + } + } + + return true; +} + + +xmrig::Buffer xmrig::Buffer::fromHex(const char *data, size_t size) +{ + if (data == nullptr || size % 2 != 0) { + return Buffer(); + } + + Buffer buf(size / 2); + fromHex(data, size, buf.data()); + + return buf; +} + + +void xmrig::Buffer::toHex(const uint8_t *in, size_t size, uint8_t *out) +{ + for (size_t i = 0; i < size; i++) { + out[i * 2] = hf_bin2hex((in[i] & 0xF0) >> 4); + out[i * 2 + 1] = hf_bin2hex(in[i] & 0x0F); + } +} + + +xmrig::String xmrig::Buffer::toHex(const uint8_t *in, size_t size) +{ + return Buffer(reinterpret_cast(in), size).toHex(); +} + + +xmrig::String xmrig::Buffer::toHex() const +{ + if (m_size == 0) { + return String(); + } + + char *buf = new char[m_size * 2 + 1]; + buf[m_size * 2] = '\0'; + + toHex(m_data, m_size, buf); + + return String(buf); +} + + +void xmrig::Buffer::copy(const char *data, size_t size) +{ + m_data = new char[size]; + m_size = size; + + memcpy(m_data, data, m_size); +} + + +void xmrig::Buffer::move(Buffer &&other) +{ + if (m_size > 0) { + delete [] m_data; + } + + m_data = other.m_data; + m_size = other.m_size; + + other.m_data = nullptr; + other.m_size = 0; +} diff --git a/src/base/tools/Buffer.h b/src/base/tools/Buffer.h new file mode 100644 index 000000000..6b720357b --- /dev/null +++ b/src/base/tools/Buffer.h @@ -0,0 +1,88 @@ +/* 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-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 . + */ + +#ifndef XMRIG_BUFFER_H +#define XMRIG_BUFFER_H + + +#include "base/tools/String.h" + + +namespace xmrig { + + +class Buffer +{ +public: + Buffer(); + Buffer(Buffer &&other); + Buffer(const Buffer &other); + Buffer(const char *data, size_t size); + Buffer(size_t size); + ~Buffer(); + + + inline char *data() { return m_data; } + inline const char *data() const { return m_data; } + inline size_t size() const { return m_size; } + inline void from(const Buffer &other) { from(other.data(), other.size()); } + + + void from(const char *data, size_t size); + + + inline Buffer &operator=(const Buffer &other) { from(other); return *this; } + inline Buffer &operator=(Buffer &&other) { move(std::move(other)); return *this; } + + + static Buffer allocUnsafe(size_t size); + static inline Buffer alloc(size_t size) { return Buffer(size); } + + + inline static bool fromHex(const char *in, size_t size, char *out) { return fromHex(reinterpret_cast(in), size, reinterpret_cast(out)); } + inline static bool fromHex(const char *in, size_t size, uint8_t *out) { return fromHex(reinterpret_cast(in), size, out); } + inline static Buffer fromHex(const char *data) { return fromHex(data, strlen(data)); } + inline static Buffer fromHex(const String &str) { return fromHex(str.data(), str.size()); } + inline static void toHex(const char *in, size_t size, char *out) { return toHex(reinterpret_cast(in), size, reinterpret_cast(out)); } + inline static void toHex(const uint8_t *in, size_t size, char *out) { return toHex(in, size, reinterpret_cast(out)); } + + static bool fromHex(const uint8_t *in, size_t size, uint8_t *out); + static Buffer fromHex(const char *data, size_t size); + static String toHex(const uint8_t *in, size_t size); + static void toHex(const uint8_t *in, size_t size, uint8_t *out); + String toHex() const; + +private: + void copy(const char *data, size_t size); + void move(Buffer &&other); + + char *m_data; + size_t m_size; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_BUFFER_H */ diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index f056d498c..ba544c4b6 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -27,6 +27,7 @@ #include "base/net/stratum/Job.h" #include "base/net/stratum/strategies/FailoverStrategy.h" #include "base/net/stratum/strategies/SinglePoolStrategy.h" +#include "base/tools/Buffer.h" #include "common/crypto/keccak.h" #include "common/Platform.h" #include "common/xmrig.h" @@ -51,7 +52,7 @@ xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IS char userId[65] = { 0 }; keccak(reinterpret_cast(user), strlen(user), hash); - Job::toHex(hash, 32, userId); + Buffer::toHex(hash, 32, userId); # ifndef XMRIG_NO_TLS m_pools.push_back(Pool("donate.ssl.xmrig.com", 443, userId, nullptr, false, true, true)); From f5077cadbd48d5009b270e9d12ad44d68d5cbe91 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Mar 2019 03:44:02 +0700 Subject: [PATCH 42/55] Added class RecvBuf. --- CMakeLists.txt | 2 + src/base/kernel/interfaces/ILineListener.h | 50 ++++++++++ src/base/net/stratum/Client.cpp | 107 ++++++++------------- src/base/net/stratum/Client.h | 15 +-- src/base/net/stratum/Tls.cpp | 3 +- src/base/net/tools/RecvBuf.h | 99 +++++++++++++++++++ 6 files changed, 203 insertions(+), 73 deletions(-) create mode 100644 src/base/kernel/interfaces/ILineListener.h create mode 100644 src/base/net/tools/RecvBuf.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 81ad18f6e..42bb51f89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ set(HEADERS src/base/kernel/Entry.h src/base/kernel/interfaces/IClientListener.h src/base/kernel/interfaces/IConfigListener.h + src/base/kernel/interfaces/ILineListener.h src/base/kernel/interfaces/ISignalListener.h src/base/kernel/interfaces/IStrategy.h src/base/kernel/interfaces/IStrategyListener.h @@ -39,6 +40,7 @@ set(HEADERS src/base/net/stratum/strategies/FailoverStrategy.h src/base/net/stratum/strategies/SinglePoolStrategy.h src/base/net/stratum/SubmitResult.h + src/base/net/tools/RecvBuf.h src/base/net/tools/Storage.h src/base/tools/Arguments.h src/base/tools/Buffer.h diff --git a/src/base/kernel/interfaces/ILineListener.h b/src/base/kernel/interfaces/ILineListener.h new file mode 100644 index 000000000..1a6d49142 --- /dev/null +++ b/src/base/kernel/interfaces/ILineListener.h @@ -0,0 +1,50 @@ +/* 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-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 . + */ + +#ifndef XMRIG_ILINELISTENER_H +#define XMRIG_ILINELISTENER_H + + +#include + + +namespace xmrig { + + +class String; + + +class ILineListener +{ +public: + virtual ~ILineListener() = default; + + virtual void onLine(char *line, size_t size) = 0; +}; + + +} /* namespace xmrig */ + + +#endif // XMRIG_ILINELISTENER_H diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 5b330311b..313f4ec39 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -83,7 +83,6 @@ xmrig::Client::Client(int id, const char *agent, IClientListener *listener) : m_retries(5), m_retryPause(5000), m_failures(0), - m_recvBufPos(0), m_state(UnconnectedState), m_tls(nullptr), m_expire(0), @@ -103,9 +102,6 @@ xmrig::Client::Client(int id, const char *agent, IClientListener *listener) : m_hints.ai_family = AF_UNSPEC; m_hints.ai_socktype = SOCK_STREAM; m_hints.ai_protocol = IPPROTO_TCP; - - m_recvBuf.base = m_buf; - m_recvBuf.len = sizeof(m_buf); } @@ -477,8 +473,8 @@ int xmrig::Client::resolve(const char *host) { setState(HostLookupState); - m_expire = 0; - m_recvBufPos = 0; + m_expire = 0; + m_recvBuf.reset(); if (m_failures == -1) { m_failures = 0; @@ -672,8 +668,6 @@ void xmrig::Client::parse(char *line, size_t len) { startTimeout(); - line[len - 1] = '\0'; - LOG_DEBUG("[%s] received (%d bytes): \"%s\"", m_pool.url(), len, line); if (len < 32 || line[0] != '{') { @@ -827,32 +821,42 @@ void xmrig::Client::ping() } -void xmrig::Client::read() +void xmrig::Client::read(ssize_t nread) { - char* end; - char* start = m_recvBuf.base; - size_t remaining = m_recvBufPos; + const size_t size = static_cast(nread); - while ((end = static_cast(memchr(start, '\n', remaining))) != nullptr) { - end++; - size_t len = end - start; - parse(start, len); - - remaining -= len; - start = end; + if (nread > 0 && size > m_recvBuf.available()) { + nread = UV_ENOBUFS; } - if (remaining == 0) { - m_recvBufPos = 0; + if (nread < 0) { + if (!isQuiet()) { + LOG_ERR("[%s] read error: \"%s\"", m_pool.url(), uv_strerror(static_cast(nread))); + } + + close(); return; } - if (start == m_recvBuf.base) { - return; + assert(client->m_listener != nullptr); + if (!m_listener) { + return reconnect(); } - memcpy(m_recvBuf.base, start, remaining); - m_recvBufPos = remaining; + m_recvBuf.nread(size); + +# ifndef XMRIG_NO_TLS + if (isTLS()) { + LOG_DEBUG("[%s] TLS received (%d bytes)", m_pool.url(), static_cast(nread)); + + m_tls->read(m_recvBuf.base(), m_recvBuf.pos()); + m_recvBuf.reset(); + } + else +# endif + { + m_recvBuf.getline(this); + } } @@ -873,7 +877,7 @@ void xmrig::Client::reconnect() setState(ConnectingState); m_failures++; - m_listener->onClose(this, (int) m_failures); + m_listener->onClose(this, static_cast(m_failures)); m_expire = Chrono::steadyMSecs() + m_retryPause; } @@ -903,15 +907,20 @@ void xmrig::Client::startTimeout() } -void xmrig::Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) +void xmrig::Client::onAllocBuffer(uv_handle_t *handle, size_t, uv_buf_t *buf) { auto client = getClient(handle->data); if (!client) { return; } - buf->base = &client->m_recvBuf.base[client->m_recvBufPos]; - buf->len = client->m_recvBuf.len - client->m_recvBufPos; + buf->base = client->m_recvBuf.current(); + +# ifdef _WIN32 + buf->len = static_cast(client->m_recvBuf.available()); +# else + buf->len = client->m_recvBuf.available(); +# endif } @@ -955,45 +964,11 @@ void xmrig::Client::onConnect(uv_connect_t *req, int status) } -void xmrig::Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) +void xmrig::Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *) { auto client = getClient(stream->data); - if (!client) { - return; - } - - if (nread < 0) { - if (!client->isQuiet()) { - LOG_ERR("[%s] read error: \"%s\"", client->m_pool.url(), uv_strerror((int) nread)); - } - - client->close(); - return; - } - - if ((size_t) nread > (sizeof(m_buf) - 8 - client->m_recvBufPos)) { - client->close(); - return; - } - - assert(client->m_listener != nullptr); - if (!client->m_listener) { - return client->reconnect(); - } - - client->m_recvBufPos += nread; - -# ifndef XMRIG_NO_TLS - if (client->isTLS()) { - LOG_DEBUG("[%s] TLS received (%d bytes)", client->m_pool.url(), static_cast(nread)); - - client->m_tls->read(client->m_recvBuf.base, client->m_recvBufPos); - client->m_recvBufPos = 0; - } - else -# endif - { - client->read(); + if (client) { + client->read(nread); } } diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index ed433ff95..07c82a8f8 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -32,9 +32,11 @@ #include +#include "base/kernel/interfaces/ILineListener.h" #include "base/net/stratum/Job.h" #include "base/net/stratum/Pool.h" #include "base/net/stratum/SubmitResult.h" +#include "base/net/tools/RecvBuf.h" #include "base/net/tools/Storage.h" #include "common/crypto/Algorithm.h" #include "rapidjson/fwd.h" @@ -50,7 +52,7 @@ class IClientListener; class JobResult; -class Client +class Client : public ILineListener { public: enum SocketState { @@ -78,7 +80,7 @@ public: # endif Client(int id, const char *agent, IClientListener *listener); - ~Client(); + ~Client() override; bool disconnect(); const char *tlsFingerprint() const; @@ -106,6 +108,9 @@ public: template inline bool has() const noexcept { return m_extensions.test(ext); } +protected: + inline void onLine(char *line, size_t size) override { parse(line, size); } + private: class Tls; @@ -129,7 +134,7 @@ private: void parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error); void parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error); void ping(); - void read(); + void read(ssize_t nread); void reconnect(); void setState(SocketState state); void startTimeout(); @@ -149,7 +154,6 @@ private: bool m_enabled; bool m_ipv6; bool m_quiet; - char m_buf[kInputBufferSize]; char m_ip[46]; char m_sendBuf[2048]; const char *m_agent; @@ -160,7 +164,7 @@ private: int64_t m_failures; Job m_job; Pool m_pool; - size_t m_recvBufPos; + RecvBuf m_recvBuf; SocketState m_state; std::bitset m_extensions; std::map m_results; @@ -170,7 +174,6 @@ private: uint64_t m_jobs; uint64_t m_keepAlive; uintptr_t m_key; - uv_buf_t m_recvBuf; uv_getaddrinfo_t m_resolver; uv_stream_t *m_stream; uv_tcp_t *m_socket; diff --git a/src/base/net/stratum/Tls.cpp b/src/base/net/stratum/Tls.cpp index e8948f34f..e96d9946e 100644 --- a/src/base/net/stratum/Tls.cpp +++ b/src/base/net/stratum/Tls.cpp @@ -135,7 +135,8 @@ void xmrig::Client::Tls::read(const char *data, size_t size) int bytes_read = 0; while ((bytes_read = SSL_read(m_ssl, m_buf, sizeof(m_buf))) > 0) { - m_client->parse(m_buf, bytes_read); + m_buf[bytes_read - 1] = '\0'; + m_client->parse(m_buf, static_cast(bytes_read)); } } diff --git a/src/base/net/tools/RecvBuf.h b/src/base/net/tools/RecvBuf.h new file mode 100644 index 000000000..5122c9804 --- /dev/null +++ b/src/base/net/tools/RecvBuf.h @@ -0,0 +1,99 @@ +/* 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-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 . + */ + +#ifndef XMRIG_RECVBUF_H +#define XMRIG_RECVBUF_H + + +#include + + +#include "base/kernel/interfaces/ILineListener.h" + + +namespace xmrig { + + +template +class RecvBuf +{ +public: + inline RecvBuf() : + m_buf(), + m_pos(0) + { + } + + inline char *base() { return m_buf; } + inline char *current() { return m_buf + m_pos; } + inline const char *base() const { return m_buf; } + inline const char *current() const { return m_buf + m_pos; } + inline size_t available() const { return N - m_pos; } + inline size_t pos() const { return m_pos; } + inline void nread(size_t size) { m_pos += size; } + inline void reset() { m_pos = 0; } + + constexpr inline size_t size() const { return N; } + + inline void getline(ILineListener *listener) + { + char *end; + char *start = m_buf; + size_t remaining = m_pos; + + while ((end = static_cast(memchr(start, '\n', remaining))) != nullptr) { + *end = '\0'; + + end++; + const size_t len = static_cast(end - start); + + listener->onLine(start, len - 1); + + remaining -= len; + start = end; + } + + if (remaining == 0) { + m_pos = 0; + return; + } + + if (start == m_buf) { + return; + } + + memcpy(m_buf, start, remaining); + m_pos = remaining; + } + +private: + char m_buf[N]; + size_t m_pos; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_RECVBUF_H */ From 3094741c64f3d08e5c4425123cdfb4035612d2f8 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Mar 2019 12:54:00 +0700 Subject: [PATCH 43/55] Remove file SubmitResult.cpp. --- CMakeLists.txt | 1 - src/base/net/stratum/SubmitResult.cpp | 46 --------------------------- src/base/net/stratum/SubmitResult.h | 25 ++++++++++++--- 3 files changed, 20 insertions(+), 52 deletions(-) delete mode 100644 src/base/net/stratum/SubmitResult.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 42bb51f89..00dd85772 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,7 +124,6 @@ set(SOURCES src/base/net/stratum/Pools.cpp src/base/net/stratum/strategies/FailoverStrategy.cpp src/base/net/stratum/strategies/SinglePoolStrategy.cpp - src/base/net/stratum/SubmitResult.cpp src/base/tools/Arguments.cpp src/base/tools/Buffer.cpp src/base/tools/Handle.cpp diff --git a/src/base/net/stratum/SubmitResult.cpp b/src/base/net/stratum/SubmitResult.cpp deleted file mode 100644 index ad8a48af0..000000000 --- a/src/base/net/stratum/SubmitResult.cpp +++ /dev/null @@ -1,46 +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 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 - - -#include "base/net/stratum/SubmitResult.h" - - -xmrig::SubmitResult::SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId) : - reqId(reqId), - seq(seq), - diff(diff), - actualDiff(actualDiff), - elapsed(0) -{ - start = uv_hrtime(); -} - - -void xmrig::SubmitResult::done() -{ - elapsed = (uv_hrtime() - start) / 1000000; -} diff --git a/src/base/net/stratum/SubmitResult.h b/src/base/net/stratum/SubmitResult.h index db97ac38a..583d426fe 100644 --- a/src/base/net/stratum/SubmitResult.h +++ b/src/base/net/stratum/SubmitResult.h @@ -26,7 +26,7 @@ #define XMRIG_SUBMITRESULT_H -#include +#include "base/tools/Chrono.h" namespace xmrig { @@ -35,10 +35,25 @@ namespace xmrig { class SubmitResult { public: - inline SubmitResult() : reqId(0), seq(0), diff(0), actualDiff(0), elapsed(0), start(0) {} - SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId = 0); + inline SubmitResult() : + reqId(0), + seq(0), + diff(0), + actualDiff(0), + elapsed(0), + m_start(0) + {} - void done(); + inline SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId = 0) : + reqId(reqId), + seq(seq), + diff(diff), + actualDiff(actualDiff), + elapsed(0), + m_start(Chrono::steadyMSecs()) + {} + + inline void done() { elapsed = Chrono::steadyMSecs() - m_start; } int64_t reqId; int64_t seq; @@ -47,7 +62,7 @@ public: uint64_t elapsed; private: - uint64_t start; + uint64_t m_start; }; From af3655c27e53d0b4c703584ee1c1b22a2f43553a Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Mar 2019 18:14:25 +0700 Subject: [PATCH 44/55] Add classes Dns, DnsRecord, IDnsListener. --- CMakeLists.txt | 5 + src/base/kernel/interfaces/IDnsListener.h | 47 +++++++ src/base/net/dns/Dns.cpp | 158 +++++++++++++++++++++ src/base/net/dns/Dns.h | 80 +++++++++++ src/base/net/dns/DnsRecord.cpp | 66 +++++++++ src/base/net/dns/DnsRecord.h | 66 +++++++++ src/base/net/stratum/Client.cpp | 162 ++++++++-------------- src/base/net/stratum/Client.h | 17 +-- src/base/net/stratum/Pool.cpp | 23 +-- src/base/net/stratum/Pool.h | 21 +-- 10 files changed, 514 insertions(+), 131 deletions(-) create mode 100644 src/base/kernel/interfaces/IDnsListener.h create mode 100644 src/base/net/dns/Dns.cpp create mode 100644 src/base/net/dns/Dns.h create mode 100644 src/base/net/dns/DnsRecord.cpp create mode 100644 src/base/net/dns/DnsRecord.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 00dd85772..f0d2e64f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ set(HEADERS src/base/kernel/Entry.h src/base/kernel/interfaces/IClientListener.h src/base/kernel/interfaces/IConfigListener.h + src/base/kernel/interfaces/IDnsListener.h src/base/kernel/interfaces/ILineListener.h src/base/kernel/interfaces/ISignalListener.h src/base/kernel/interfaces/IStrategy.h @@ -33,6 +34,8 @@ set(HEADERS src/base/kernel/interfaces/IWatcherListener.h src/base/kernel/Process.h src/base/kernel/Signals.h + src/base/net/dns/Dns.h + src/base/net/dns/DnsRecord.h src/base/net/stratum/Client.h src/base/net/stratum/Job.h src/base/net/stratum/Pool.h @@ -118,6 +121,8 @@ set(SOURCES src/base/kernel/Entry.cpp src/base/kernel/Process.cpp src/base/kernel/Signals.cpp + src/base/net/dns/Dns.cpp + src/base/net/dns/DnsRecord.cpp src/base/net/stratum/Client.cpp src/base/net/stratum/Job.cpp src/base/net/stratum/Pool.cpp diff --git a/src/base/kernel/interfaces/IDnsListener.h b/src/base/kernel/interfaces/IDnsListener.h new file mode 100644 index 000000000..3683ea51d --- /dev/null +++ b/src/base/kernel/interfaces/IDnsListener.h @@ -0,0 +1,47 @@ +/* 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-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 . + */ + +#ifndef XMRIG_IDNSLISTENER_H +#define XMRIG_IDNSLISTENER_H + + +namespace xmrig { + + +class Dns; + + +class IDnsListener +{ +public: + virtual ~IDnsListener() = default; + + virtual void onResolved(const Dns &dns, int status) = 0; +}; + + +} /* namespace xmrig */ + + +#endif // XMRIG_IDNSLISTENER_H diff --git a/src/base/net/dns/Dns.cpp b/src/base/net/dns/Dns.cpp new file mode 100644 index 000000000..1e285fb4b --- /dev/null +++ b/src/base/net/dns/Dns.cpp @@ -0,0 +1,158 @@ +/* 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-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 "base/kernel/interfaces/IDnsListener.h" +#include "base/net/dns/Dns.h" +#include "base/tools/Handle.h" + + +namespace xmrig { + Storage Dns::m_storage; + static const DnsRecord defaultRecord; +} + + +xmrig::Dns::Dns(IDnsListener *listener) : + m_hints(), + m_listener(listener), + m_status(0) +{ + m_key = m_storage.add(this); + + m_resolver = new uv_getaddrinfo_t; + m_resolver->data = m_storage.ptr(m_key); + + m_hints.ai_family = AF_UNSPEC; + m_hints.ai_socktype = SOCK_STREAM; + m_hints.ai_protocol = IPPROTO_TCP; +} + + +xmrig::Dns::~Dns() +{ + Handle::close(m_resolver); + + m_storage.release(m_key); +} + + +bool xmrig::Dns::resolve(const String &host) +{ + if (m_host != host) { + m_host = host; + + clear(); + } + + m_status = uv_getaddrinfo(uv_default_loop(), m_resolver, Dns::onResolved, m_host.data(), nullptr, &m_hints); + + return m_status == 0; +} + + +const char *xmrig::Dns::error() const +{ + return uv_strerror(m_status); +} + + +const xmrig::DnsRecord &xmrig::Dns::get(DnsRecord::Type prefered) const +{ + if (count() == 0) { + return defaultRecord; + } + + const size_t ipv4 = m_ipv4.size(); + const size_t ipv6 = m_ipv6.size(); + + if (ipv6 && (prefered == DnsRecord::AAAA || !ipv4)) { + return m_ipv6[ipv6 == 1 ? 0 : static_cast(rand()) % ipv6]; + } + + if (ipv4) { + return m_ipv4[ipv4 == 1 ? 0 : static_cast(rand()) % ipv4]; + } + + return defaultRecord; +} + + +size_t xmrig::Dns::count(DnsRecord::Type type) const +{ + if (type == DnsRecord::A) { + return m_ipv4.size(); + } + + if (type == DnsRecord::AAAA) { + return m_ipv6.size(); + } + + return m_ipv4.size() + m_ipv6.size(); +} + + +void xmrig::Dns::clear() +{ + m_ipv4.clear(); + m_ipv6.clear(); +} + + +void xmrig::Dns::onResolved(int status, addrinfo *res) +{ + m_status = status; + + if (m_status < 0) { + return m_listener->onResolved(*this, status); + } + + clear(); + + addrinfo *ptr = res; + while (ptr != nullptr) { + if (ptr->ai_family == AF_INET) { + m_ipv4.push_back(ptr); + } + + if (ptr->ai_family == AF_INET6) { + m_ipv6.push_back(ptr); + } + + ptr = ptr->ai_next; + } + + m_listener->onResolved(*this, status); +} + + +void xmrig::Dns::onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res) +{ + Dns *dns = m_storage.get(req->data); + if (dns) { + dns->onResolved(status, res); + } + + uv_freeaddrinfo(res); +} diff --git a/src/base/net/dns/Dns.h b/src/base/net/dns/Dns.h new file mode 100644 index 000000000..73c47cdd9 --- /dev/null +++ b/src/base/net/dns/Dns.h @@ -0,0 +1,80 @@ +/* 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-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 . + */ + +#ifndef XMRIG_DNS_H +#define XMRIG_DNS_H + + +#include +#include + + +#include "base/net/dns/DnsRecord.h" +#include "base/net/tools/Storage.h" +#include "base/tools/String.h" + + +namespace xmrig { + + +class IDnsListener; + + +class Dns +{ +public: + Dns(IDnsListener *listener); + ~Dns(); + + inline bool isEmpty() const { return m_ipv4.empty() && m_ipv6.empty(); } + inline int status() const { return m_status; } + + bool resolve(const String &host); + const char *error() const; + const DnsRecord &get(DnsRecord::Type prefered = DnsRecord::A) const; + size_t count(DnsRecord::Type type = DnsRecord::Unknown) const; + +private: + void clear(); + void onResolved(int status, addrinfo *res); + + static void onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res); + + addrinfo m_hints; + IDnsListener *m_listener; + int m_status; + std::vector m_ipv4; + std::vector m_ipv6; + String m_host; + uintptr_t m_key; + uv_getaddrinfo_t *m_resolver; + + static Storage m_storage; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_DNS_H */ diff --git a/src/base/net/dns/DnsRecord.cpp b/src/base/net/dns/DnsRecord.cpp new file mode 100644 index 000000000..7a85799b2 --- /dev/null +++ b/src/base/net/dns/DnsRecord.cpp @@ -0,0 +1,66 @@ +/* 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-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 + + +#include "base/net/dns/DnsRecord.h" + + +xmrig::DnsRecord::DnsRecord(const addrinfo *addr) : + m_type(addr->ai_family == AF_INET6 ? AAAA : A) +{ + char *buf = nullptr; + + if (m_type == AAAA) { + buf = new char[45](); + uv_ip6_name(reinterpret_cast(addr->ai_addr), buf, 45); + } + else { + buf = new char[16](); + uv_ip4_name(reinterpret_cast(addr->ai_addr), buf, 16); + } + + m_ip = buf; +} + + +sockaddr *xmrig::DnsRecord::addr(uint16_t port) const +{ + if (m_type == A) { + sockaddr_in *addr = new sockaddr_in(); + uv_ip4_addr(m_ip.data(), port, addr); + + return reinterpret_cast(addr); + } + else if (m_type == AAAA) { + sockaddr_in6 *addr = new sockaddr_in6(); + uv_ip6_addr(m_ip.data(), port, addr); + + return reinterpret_cast(addr); + } + + return nullptr; +} diff --git a/src/base/net/dns/DnsRecord.h b/src/base/net/dns/DnsRecord.h new file mode 100644 index 000000000..71d1e9c84 --- /dev/null +++ b/src/base/net/dns/DnsRecord.h @@ -0,0 +1,66 @@ +/* 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-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 . + */ + +#ifndef XMRIG_DNSRECORD_H +#define XMRIG_DNSRECORD_H + + +struct addrinfo; +struct sockaddr; + + +#include "base/tools/String.h" + + +namespace xmrig { + + +class DnsRecord +{ +public: + enum Type { + Unknown, + A, + AAAA + }; + + inline DnsRecord() : m_type(Unknown) {} + DnsRecord(const addrinfo *addr); + + sockaddr *addr(uint16_t port = 0) const; + + inline bool isValid() const { return m_type != Unknown; } + inline const String &ip() const { return m_ip; } + inline Type type() const { return m_type; } + +private: + Type m_type; + String m_ip; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_DNSRECORD_H */ diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 313f4ec39..c892b9998 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -38,6 +38,7 @@ #include "base/kernel/interfaces/IClientListener.h" +#include "base/net/dns/Dns.h" #include "base/net/stratum/Client.h" #include "base/tools/Buffer.h" #include "base/tools/Chrono.h" @@ -93,20 +94,13 @@ xmrig::Client::Client(int id, const char *agent, IClientListener *listener) : m_socket(nullptr) { m_key = m_storage.add(this); - - memset(m_ip, 0, sizeof(m_ip)); - memset(&m_hints, 0, sizeof(m_hints)); - - m_resolver.data = m_storage.ptr(m_key); - - m_hints.ai_family = AF_UNSPEC; - m_hints.ai_socktype = SOCK_STREAM; - m_hints.ai_protocol = IPPROTO_TCP; + m_dns = new Dns(this); } xmrig::Client::~Client() { + delete m_dns; delete m_socket; } @@ -164,7 +158,7 @@ void xmrig::Client::tick(uint64_t now) { if (m_state == ConnectedState) { if (m_expire && now > m_expire) { - LOG_DEBUG_ERR("[%s] timeout", m_pool.url()); + LOG_DEBUG_ERR("[%s] timeout", url()); close(); } else if (m_keepAlive && now > m_keepAlive) { @@ -265,6 +259,36 @@ int64_t xmrig::Client::submit(const JobResult &result) } +void xmrig::Client::onResolved(const Dns &dns, int status) +{ + assert(client->m_listener != nullptr); + if (!m_listener) { + return reconnect(); + } + + if (status < 0 && dns.isEmpty()) { + if (!isQuiet()) { + LOG_ERR("[%s] DNS error: \"%s\"", url(), uv_strerror(status)); + } + + return reconnect(); + } + + if (dns.isEmpty()) { + if (!isQuiet()) { + LOG_ERR("[%s] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", url()); + } + + return reconnect(); + } + + const DnsRecord &record = dns.get(); + m_ip = record.ip(); + + connect(record.addr(m_pool.port())); +} + + bool xmrig::Client::close() { if (m_state == ClosingState) { @@ -384,7 +408,7 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code) } if (!isQuiet()) { - LOG_WARN("[%s] duplicate job received, reconnect", m_pool.url()); + LOG_WARN("[%s] duplicate job received, reconnect", url()); } close(); @@ -419,7 +443,7 @@ bool xmrig::Client::send(BIO *bio) return true; } - LOG_DEBUG("[%s] TLS send (%d bytes)", m_pool.url(), static_cast(buf.len)); + LOG_DEBUG("[%s] TLS send (%d bytes)", url(), static_cast(buf.len)); bool result = false; if (state() == ConnectedState && uv_is_writable(m_stream)) { @@ -430,7 +454,7 @@ bool xmrig::Client::send(BIO *bio) } } else { - LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", m_pool.url(), m_state); + LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", url(), m_state); } (void) BIO_reset(bio); @@ -469,7 +493,7 @@ bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm) const } -int xmrig::Client::resolve(const char *host) +int xmrig::Client::resolve(const String &host) { setState(HostLookupState); @@ -480,11 +504,11 @@ int xmrig::Client::resolve(const char *host) m_failures = 0; } - const int r = uv_getaddrinfo(uv_default_loop(), &m_resolver, Client::onResolved, host, nullptr, &m_hints); - if (r) { + if (!m_dns->resolve(host)) { if (!isQuiet()) { - LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host, m_pool.port(), uv_strerror(r)); + LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host.data(), m_pool.port(), uv_strerror(m_dns->status())); } + return 1; } @@ -502,7 +526,7 @@ int64_t xmrig::Client::send(const rapidjson::Document &doc) const size_t size = buffer.GetSize(); if (size > (sizeof(m_sendBuf) - 2)) { - LOG_ERR("[%s] send failed: \"send buffer overflow: %zu > %zu\"", m_pool.url(), size, (sizeof(m_sendBuf) - 2)); + LOG_ERR("[%s] send failed: \"send buffer overflow: %zu > %zu\"", url(), size, (sizeof(m_sendBuf) - 2)); close(); return -1; } @@ -517,7 +541,7 @@ int64_t xmrig::Client::send(const rapidjson::Document &doc) int64_t xmrig::Client::send(size_t size) { - LOG_DEBUG("[%s] send (%d bytes): \"%s\"", m_pool.url(), size, m_sendBuf); + LOG_DEBUG("[%s] send (%d bytes): \"%s\"", url(), size, m_sendBuf); # ifndef XMRIG_NO_TLS if (isTLS()) { @@ -529,7 +553,7 @@ int64_t xmrig::Client::send(size_t size) # endif { if (state() != ConnectedState || !uv_is_writable(m_stream)) { - LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", m_pool.url(), m_state); + LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", url(), m_state); return -1; } @@ -546,24 +570,6 @@ int64_t xmrig::Client::send(size_t size) } -void xmrig::Client::connect(const std::vector &ipv4, const std::vector &ipv6) -{ - addrinfo *addr = nullptr; - m_ipv6 = ipv4.empty() && !ipv6.empty(); - - if (m_ipv6) { - addr = ipv6[ipv6.size() == 1 ? 0 : rand() % ipv6.size()]; - uv_ip6_name(reinterpret_cast(addr->ai_addr), m_ip, 45); - } - else { - addr = ipv4[ipv4.size() == 1 ? 0 : rand() % ipv4.size()]; - uv_ip4_name(reinterpret_cast(addr->ai_addr), m_ip, 16); - } - - connect(addr->ai_addr); -} - - void xmrig::Client::connect(sockaddr *addr) { setState(ConnectingState); @@ -616,12 +622,12 @@ void xmrig::Client::login() doc.AddMember("method", "login", allocator); Value params(kObjectType); - params.AddMember("login", StringRef(m_pool.user()), allocator); - params.AddMember("pass", StringRef(m_pool.password()), allocator); + params.AddMember("login", m_pool.user().toJSON(), allocator); + params.AddMember("pass", m_pool.password().toJSON(), allocator); params.AddMember("agent", StringRef(m_agent), allocator); - if (m_pool.rigId()) { - params.AddMember("rigid", StringRef(m_pool.rigId()), allocator); + if (!m_pool.rigId().isNull()) { + params.AddMember("rigid", m_pool.rigId().toJSON(), allocator); } # ifdef XMRIG_PROXY_PROJECT @@ -668,11 +674,11 @@ void xmrig::Client::parse(char *line, size_t len) { startTimeout(); - LOG_DEBUG("[%s] received (%d bytes): \"%s\"", m_pool.url(), len, line); + LOG_DEBUG("[%s] received (%d bytes): \"%s\"", url(), len, line); if (len < 32 || line[0] != '{') { if (!isQuiet()) { - LOG_ERR("[%s] JSON decode failed", m_pool.url()); + LOG_ERR("[%s] JSON decode failed", url()); } return; @@ -681,7 +687,7 @@ void xmrig::Client::parse(char *line, size_t len) rapidjson::Document doc; if (doc.ParseInsitu(line).HasParseError()) { if (!isQuiet()) { - LOG_ERR("[%s] JSON decode failed: \"%s\"", m_pool.url(), rapidjson::GetParseError_En(doc.GetParseError())); + LOG_ERR("[%s] JSON decode failed: \"%s\"", url(), rapidjson::GetParseError_En(doc.GetParseError())); } return; @@ -741,7 +747,7 @@ void xmrig::Client::parseNotification(const char *method, const rapidjson::Value { if (error.IsObject()) { if (!isQuiet()) { - LOG_ERR("[%s] error: \"%s\", code: %d", m_pool.url(), error["message"].GetString(), error["code"].GetInt()); + LOG_ERR("[%s] error: \"%s\", code: %d", url(), error["message"].GetString(), error["code"].GetInt()); } return; } @@ -759,7 +765,7 @@ void xmrig::Client::parseNotification(const char *method, const rapidjson::Value return; } - LOG_WARN("[%s] unsupported method: \"%s\"", m_pool.url(), method); + LOG_WARN("[%s] unsupported method: \"%s\"", url(), method); } @@ -775,7 +781,7 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co m_results.erase(it); } else if (!isQuiet()) { - LOG_ERR("[%s] error: \"%s\", code: %d", m_pool.url(), message, error["code"].GetInt()); + LOG_ERR("[%s] error: \"%s\", code: %d", url(), message, error["code"].GetInt()); } if (isCriticalError(message)) { @@ -793,7 +799,7 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co int code = -1; if (!parseLogin(result, &code)) { if (!isQuiet()) { - LOG_ERR("[%s] login error code: %d", m_pool.url(), code); + LOG_ERR("[%s] login error code: %d", url(), code); } close(); @@ -831,7 +837,7 @@ void xmrig::Client::read(ssize_t nread) if (nread < 0) { if (!isQuiet()) { - LOG_ERR("[%s] read error: \"%s\"", m_pool.url(), uv_strerror(static_cast(nread))); + LOG_ERR("[%s] read error: \"%s\"", url(), uv_strerror(static_cast(nread))); } close(); @@ -847,7 +853,7 @@ void xmrig::Client::read(ssize_t nread) # ifndef XMRIG_NO_TLS if (isTLS()) { - LOG_DEBUG("[%s] TLS received (%d bytes)", m_pool.url(), static_cast(nread)); + LOG_DEBUG("[%s] TLS received (%d bytes)", url(), static_cast(nread)); m_tls->read(m_recvBuf.base(), m_recvBuf.pos()); m_recvBuf.reset(); @@ -885,7 +891,7 @@ void xmrig::Client::reconnect() void xmrig::Client::setState(SocketState state) { - LOG_DEBUG("[%s] state: \"%s\"", m_pool.url(), states[state]); + LOG_DEBUG("[%s] state: \"%s\"", url(), states[state]); if (m_state == state) { return; @@ -945,7 +951,7 @@ void xmrig::Client::onConnect(uv_connect_t *req, int status) if (status < 0) { if (!client->isQuiet()) { - LOG_ERR("[%s] connect error: \"%s\"", client->m_pool.url(), uv_strerror(status)); + LOG_ERR("[%s] connect error: \"%s\"", client->url(), uv_strerror(status)); } delete req; @@ -971,53 +977,3 @@ void xmrig::Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *) client->read(nread); } } - - -void xmrig::Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res) -{ - auto client = getClient(req->data); - if (!client) { - return; - } - - assert(client->m_listener != nullptr); - if (!client->m_listener) { - return client->reconnect(); - } - - if (status < 0) { - if (!client->isQuiet()) { - LOG_ERR("[%s] DNS error: \"%s\"", client->m_pool.url(), uv_strerror(status)); - } - - return client->reconnect(); - } - - addrinfo *ptr = res; - std::vector ipv4; - std::vector ipv6; - - while (ptr != nullptr) { - if (ptr->ai_family == AF_INET) { - ipv4.push_back(ptr); - } - - if (ptr->ai_family == AF_INET6) { - ipv6.push_back(ptr); - } - - ptr = ptr->ai_next; - } - - if (ipv4.empty() && ipv6.empty()) { - if (!client->isQuiet()) { - LOG_ERR("[%s] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_pool.url()); - } - - uv_freeaddrinfo(res); - return client->reconnect(); - } - - client->connect(ipv4, ipv6); - uv_freeaddrinfo(res); -} diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index 07c82a8f8..ce2b0276f 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -32,6 +32,7 @@ #include +#include "base/kernel/interfaces/IDnsListener.h" #include "base/kernel/interfaces/ILineListener.h" #include "base/net/stratum/Job.h" #include "base/net/stratum/Pool.h" @@ -39,7 +40,7 @@ #include "base/net/tools/RecvBuf.h" #include "base/net/tools/Storage.h" #include "common/crypto/Algorithm.h" -#include "rapidjson/fwd.h" + typedef struct bio_st BIO; @@ -52,7 +53,7 @@ class IClientListener; class JobResult; -class Client : public ILineListener +class Client : public IDnsListener, public ILineListener { public: enum SocketState { @@ -111,6 +112,8 @@ public: protected: inline void onLine(char *line, size_t size) override { parse(line, size); } + void onResolved(const Dns &dns, int status) override; + private: class Tls; @@ -121,10 +124,9 @@ private: bool parseLogin(const rapidjson::Value &result, int *code); bool send(BIO *bio); bool verifyAlgorithm(const Algorithm &algorithm) const; - int resolve(const char *host); + int resolve(const String &host); int64_t send(const rapidjson::Document &doc); int64_t send(size_t size); - void connect(const std::vector &ipv4, const std::vector &ipv6); void connect(sockaddr *addr); void handshake(); void login(); @@ -140,23 +142,22 @@ private: void startTimeout(); inline bool isQuiet() const { return m_quiet || m_failures >= m_retries; } + inline const char *url() const { return m_pool.url(); } inline void setExtension(Extension ext, bool enable) noexcept { m_extensions.set(ext, enable); } static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf); static void onClose(uv_handle_t *handle); static void onConnect(uv_connect_t *req, int status); static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf); - static void onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res); static inline Client *getClient(void *data) { return m_storage.get(data); } - addrinfo m_hints; bool m_enabled; bool m_ipv6; bool m_quiet; - char m_ip[46]; char m_sendBuf[2048]; const char *m_agent; + Dns *m_dns; IClientListener *m_listener; int m_id; int m_retries; @@ -168,13 +169,13 @@ private: SocketState m_state; std::bitset m_extensions; std::map m_results; + String m_ip; String m_rpcId; Tls *m_tls; uint64_t m_expire; uint64_t m_jobs; uint64_t m_keepAlive; uintptr_t m_key; - uv_getaddrinfo_t m_resolver; uv_stream_t *m_stream; uv_tcp_t *m_socket; diff --git a/src/base/net/stratum/Pool.cpp b/src/base/net/stratum/Pool.cpp index f371b4c07..c5f16f4f9 100644 --- a/src/base/net/stratum/Pool.cpp +++ b/src/base/net/stratum/Pool.cpp @@ -47,16 +47,19 @@ namespace xmrig { -static const char *kEnabled = "enabled"; -static const char *kFingerprint = "tls-fingerprint"; -static const char *kKeepalive = "keepalive"; -static const char *kNicehash = "nicehash"; -static const char *kPass = "pass"; -static const char *kRigId = "rig-id"; -static const char *kTls = "tls"; -static const char *kUrl = "url"; -static const char *kUser = "user"; -static const char *kVariant = "variant"; +static const char *kEnabled = "enabled"; +static const char *kFingerprint = "tls-fingerprint"; +static const char *kKeepalive = "keepalive"; +static const char *kNicehash = "nicehash"; +static const char *kPass = "pass"; +static const char *kRigId = "rig-id"; +static const char *kTls = "tls"; +static const char *kUrl = "url"; +static const char *kUser = "user"; +static const char *kVariant = "variant"; + +const String Pool::kDefaultPassword = "x"; +const String Pool::kDefaultUser = "x"; } diff --git a/src/base/net/stratum/Pool.h b/src/base/net/stratum/Pool.h index a16cc15b9..f681f0c4a 100644 --- a/src/base/net/stratum/Pool.h +++ b/src/base/net/stratum/Pool.h @@ -40,8 +40,9 @@ namespace xmrig { class Pool { public: - constexpr static const char *kDefaultPassword = "x"; - constexpr static const char *kDefaultUser = "x"; + static const String kDefaultPassword; + static const String kDefaultUser; + constexpr static uint16_t kDefaultPort = 3333; constexpr static int kKeepAliveTimeout = 60; @@ -57,28 +58,28 @@ public: bool tls = false ); + inline Algorithm &algorithm() { return m_algorithm; } inline bool isNicehash() const { return m_nicehash; } inline bool isTLS() const { return m_tls; } inline bool isValid() const { return !m_host.isNull() && m_port > 0; } - inline const char *fingerprint() const { return m_fingerprint.data(); } - inline const char *host() const { return m_host.data(); } - inline const char *password() const { return !m_password.isNull() ? m_password.data() : kDefaultPassword; } - inline const char *rigId() const { return m_rigId.data(); } - inline const char *url() const { return m_url.data(); } - inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; } inline const Algorithm &algorithm() const { return m_algorithm; } inline const Algorithms &algorithms() const { return m_algorithms; } + inline const String &fingerprint() const { return m_fingerprint; } + inline const String &host() const { return m_host; } + inline const String &password() const { return !m_password.isNull() ? m_password : kDefaultPassword; } + inline const String &rigId() const { return m_rigId; } + inline const String &url() const { return m_url; } + inline const String &user() const { return !m_user.isNull() ? m_user : kDefaultUser; } inline int keepAlive() const { return m_keepAlive; } inline uint16_t port() const { return m_port; } inline void setFingerprint(const char *fingerprint) { m_fingerprint = fingerprint; } - inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; } inline void setKeepAlive(bool enable) { setKeepAlive(enable ? kKeepAliveTimeout : 0); } + inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } inline void setPassword(const char *password) { m_password = password; } inline void setRigId(const char *rigId) { m_rigId = rigId; } inline void setTLS(bool tls) { m_tls = tls; } inline void setUser(const char *user) { m_user = user; } - inline Algorithm &algorithm() { return m_algorithm; } inline bool operator!=(const Pool &other) const { return !isEqual(other); } inline bool operator==(const Pool &other) const { return isEqual(other); } From 1e62943010a6dd10effe5342f2bf21cbff4a3edc Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Mar 2019 18:54:45 +0700 Subject: [PATCH 45/55] Fix memory leak. --- src/base/net/stratum/Client.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index c892b9998..0693afb74 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -590,6 +590,8 @@ void xmrig::Client::connect(sockaddr *addr) # endif uv_tcp_connect(req, m_socket, reinterpret_cast(addr), Client::onConnect); + + delete addr; } From ba68fb6c538b3a86592023a823f2010f5637cad7 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 16 Mar 2019 00:44:15 +0700 Subject: [PATCH 46/55] Added real graceful exit. --- CMakeLists.txt | 5 +- src/App.cpp | 12 ++- src/App.h | 2 +- src/Summary.cpp | 16 ++-- src/base/kernel/Signals.cpp | 19 ++++- src/base/kernel/Signals.h | 2 + src/base/net/dns/Dns.cpp | 4 +- src/base/tools/Handle.cpp | 79 -------------------- src/base/tools/Handle.h | 68 ++++++++++++++--- src/common/Console.cpp | 35 ++++++--- src/common/Console.h | 21 ++++-- src/common/api/Httpd.cpp | 26 +++++-- src/common/api/Httpd.h | 12 +-- src/common/interfaces/IConsoleListener.h | 19 +++-- src/common/interfaces/ILogBackend.h | 17 +++-- src/common/log/BasicLog.cpp | 11 +-- src/common/log/BasicLog.h | 14 ++-- src/common/log/ConsoleLog.cpp | 41 +++++----- src/common/log/ConsoleLog.h | 22 +++--- src/common/log/FileLog.cpp | 22 +++--- src/common/log/FileLog.h | 18 +++-- src/common/log/Log.cpp | 18 +++-- src/common/log/Log.h | 20 +++-- src/common/log/SysLog.cpp | 9 ++- src/common/log/SysLog.h | 16 +++- src/core/Controller.cpp | 15 +++- src/core/Controller.h | 1 + src/net/Network.cpp | 28 ++++--- src/net/Network.h | 3 +- src/net/strategies/DonateStrategy.cpp | 13 ++-- src/net/strategies/DonateStrategy.h | 2 +- src/workers/Hashrate.cpp | 15 ++-- src/workers/Hashrate.h | 11 +-- src/workers/MultiWorker.cpp | 2 +- src/workers/MultiWorker.h | 2 +- src/workers/{Handle.cpp => ThreadHandle.cpp} | 11 +-- src/workers/{Handle.h => ThreadHandle.h} | 13 ++-- src/workers/Worker.cpp | 4 +- src/workers/Worker.h | 4 +- src/workers/Workers.cpp | 34 +++++---- src/workers/Workers.h | 8 +- 41 files changed, 391 insertions(+), 303 deletions(-) delete mode 100644 src/base/tools/Handle.cpp rename src/workers/{Handle.cpp => ThreadHandle.cpp} (79%) rename src/workers/{Handle.h => ThreadHandle.h} (85%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0d2e64f8..1f87a85df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,7 @@ set(HEADERS src/Summary.h src/version.h src/workers/CpuThread.h - src/workers/Handle.h + src/workers/ThreadHandle.h src/workers/Hashrate.h src/workers/MultiWorker.h src/workers/Worker.h @@ -131,7 +131,6 @@ set(SOURCES src/base/net/stratum/strategies/SinglePoolStrategy.cpp src/base/tools/Arguments.cpp src/base/tools/Buffer.cpp - src/base/tools/Handle.cpp src/base/tools/String.cpp src/common/config/CommonConfig.cpp src/common/config/ConfigLoader.cpp @@ -151,7 +150,7 @@ set(SOURCES src/net/strategies/DonateStrategy.cpp src/Summary.cpp src/workers/CpuThread.cpp - src/workers/Handle.cpp + src/workers/ThreadHandle.cpp src/workers/Hashrate.cpp src/workers/MultiWorker.cpp src/workers/Worker.cpp diff --git a/src/App.cpp b/src/App.cpp index e75766acf..62dd38144 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -187,8 +187,14 @@ void xmrig::App::onSignal(int signum) void xmrig::App::close() { - m_controller->network()->stop(); - Workers::stop(); +# ifndef XMRIG_NO_HTTPD + m_httpd->stop(); +# endif - uv_stop(uv_default_loop()); + m_signals->stop(); + m_console->stop(); + m_controller->stop(); + + Workers::stop(); + Log::release(); } diff --git a/src/App.h b/src/App.h index fc9449673..02cc61a22 100644 --- a/src/App.h +++ b/src/App.h @@ -31,13 +31,13 @@ #include "common/interfaces/IConsoleListener.h" -class Console; class Httpd; namespace xmrig { +class Console; class Controller; class Network; class Process; diff --git a/src/Summary.cpp b/src/Summary.cpp index 7a52d1b13..616380197 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -59,11 +59,11 @@ inline static const char *asmName(xmrig::Assembly assembly, bool colors) static void print_memory(xmrig::Config *config) { # ifdef _WIN32 if (config->isColors()) { - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", + xmrig::Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "\x1B[1;32mavailable" : "\x1B[01;31munavailable"); } else { - Log::i()->text(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable"); + xmrig::Log::i()->text(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable"); } # endif } @@ -108,7 +108,7 @@ static void print_threads(xmrig::Config *config) snprintf(buf, sizeof buf, ", affinity=0x%" PRIX64, config->affinity()); } - Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, av=%d, %sdonate=%d%%") WHITE_BOLD("%s") + xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, av=%d, %sdonate=%d%%") WHITE_BOLD("%s") : " * %-13s%d, %s, av=%d, %sdonate=%d%%%s", "THREADS", config->threadsCount(), @@ -119,7 +119,7 @@ static void print_threads(xmrig::Config *config) buf); } else { - Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, %sdonate=%d%%") + xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, %sdonate=%d%%") : " * %-13s%d, %s, %sdonate=%d%%", "THREADS", config->threadsCount(), @@ -132,11 +132,11 @@ static void print_threads(xmrig::Config *config) if (config->assembly() == xmrig::ASM_AUTO) { const xmrig::Assembly assembly = xmrig::Cpu::info()->assembly(); - Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13sauto:%s") + xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13sauto:%s") : " * %-13sauto:%s", "ASSEMBLY", asmName(assembly, config->isColors())); } else { - Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s") : " * %-13s%s", "ASSEMBLY", asmName(config->assembly(), config->isColors())); + xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s") : " * %-13s%s", "ASSEMBLY", asmName(config->assembly(), config->isColors())); } # endif } @@ -145,12 +145,12 @@ static void print_threads(xmrig::Config *config) static void print_commands(xmrig::Config *config) { if (config->isColors()) { - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ") + xmrig::Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ") MAGENTA_BOLD("p") WHITE_BOLD("ause, ") MAGENTA_BOLD("r") WHITE_BOLD("esume")); } else { - Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume"); + xmrig::Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume"); } } diff --git a/src/base/kernel/Signals.cpp b/src/base/kernel/Signals.cpp index a37c49c6f..87825b832 100644 --- a/src/base/kernel/Signals.cpp +++ b/src/base/kernel/Signals.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018 SChernykh - * Copyright 2016-2018 XMRig , + * 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 @@ -44,20 +44,31 @@ xmrig::Signals::Signals(ISignalListener *listener) m_signals[i] = signal; uv_signal_init(uv_default_loop(), signal); - uv_signal_start(signal, xmrig::Signals::onSignal, signums[i]); + uv_signal_start(signal, Signals::onSignal, signums[i]); } } xmrig::Signals::~Signals() { + stop(); +} + + +void xmrig::Signals::stop() +{ + if (!m_signals[0]) { + return; + } + for (size_t i = 0; i < kSignalsCount; ++i) { Handle::close(m_signals[i]); + m_signals[i] = nullptr; } } void xmrig::Signals::onSignal(uv_signal_t *handle, int signum) { - static_cast(handle->data)->m_listener->onSignal(signum); + static_cast(handle->data)->m_listener->onSignal(signum); } diff --git a/src/base/kernel/Signals.h b/src/base/kernel/Signals.h index 8ef4a4bb4..9b4a870a4 100644 --- a/src/base/kernel/Signals.h +++ b/src/base/kernel/Signals.h @@ -46,6 +46,8 @@ public: Signals(ISignalListener *listener); ~Signals(); + void stop(); + private: void close(int signum); diff --git a/src/base/net/dns/Dns.cpp b/src/base/net/dns/Dns.cpp index 1e285fb4b..f24021245 100644 --- a/src/base/net/dns/Dns.cpp +++ b/src/base/net/dns/Dns.cpp @@ -52,9 +52,9 @@ xmrig::Dns::Dns(IDnsListener *listener) : xmrig::Dns::~Dns() { - Handle::close(m_resolver); - m_storage.release(m_key); + + Handle::close(m_resolver); } diff --git a/src/base/tools/Handle.cpp b/src/base/tools/Handle.cpp deleted file mode 100644 index d486ab39f..000000000 --- a/src/base/tools/Handle.cpp +++ /dev/null @@ -1,79 +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 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 - - -#include "base/tools/Handle.h" - - -void xmrig::Handle::close(uv_fs_event_t *handle) -{ - if (handle) { - uv_fs_event_stop(handle); - close(reinterpret_cast(handle)); - } -} - - -void xmrig::Handle::close(uv_getaddrinfo_t *handle) -{ - if (handle) { - uv_cancel(reinterpret_cast(handle)); - close(reinterpret_cast(handle)); - } -} - - -void xmrig::Handle::close(uv_handle_t *handle) -{ - uv_close(handle, [](uv_handle_t *handle) { delete handle; }); -} - - -void xmrig::Handle::close(uv_signal_t *handle) -{ - if (handle) { - uv_signal_stop(handle); - close(reinterpret_cast(handle)); - } -} - - -void xmrig::Handle::close(uv_tcp_t *handle) -{ - if (handle) { - close(reinterpret_cast(handle)); - } -} - - -void xmrig::Handle::close(uv_timer_s *handle) -{ - if (handle) { - uv_timer_stop(handle); - close(reinterpret_cast(handle)); - } -} diff --git a/src/base/tools/Handle.h b/src/base/tools/Handle.h index 547c92026..980d4500a 100644 --- a/src/base/tools/Handle.h +++ b/src/base/tools/Handle.h @@ -26,12 +26,7 @@ #define XMRIG_HANDLE_H -typedef struct uv_fs_event_s uv_fs_event_t; -typedef struct uv_getaddrinfo_s uv_getaddrinfo_t; -typedef struct uv_handle_s uv_handle_t; -typedef struct uv_signal_s uv_signal_t; -typedef struct uv_tcp_s uv_tcp_t; -typedef struct uv_timer_s uv_timer_t; +#include namespace xmrig { @@ -40,15 +35,64 @@ namespace xmrig { class Handle { public: - static void close(uv_fs_event_t *handle); - static void close(uv_getaddrinfo_t *handle); - static void close(uv_handle_t *handle); - static void close(uv_signal_t *handle); - static void close(uv_tcp_t *handle); - static void close(uv_timer_t *handle); + template + static inline void close(T handle) + { + if (handle) { + deleteLater(handle); + } + } + + + template + static inline void deleteLater(T handle) + { + uv_close(reinterpret_cast(handle), [](uv_handle_t *handle) { delete handle; }); + } }; +template<> +inline void Handle::close(uv_timer_t *handle) +{ + if (handle) { + uv_timer_stop(handle); + deleteLater(handle); + } +} + + +template<> +inline void Handle::close(uv_signal_t *handle) +{ + if (handle) { + uv_signal_stop(handle); + deleteLater(handle); + } +} + + +template<> +inline void Handle::close(uv_getaddrinfo_t *handle) +{ + if (handle) { + uv_cancel(reinterpret_cast(handle)); + + delete handle; + } +} + + +template<> +inline void Handle::close(uv_fs_event_t *handle) +{ + if (handle) { + uv_fs_event_stop(handle); + deleteLater(handle); + } +} + + } /* namespace xmrig */ diff --git a/src/common/Console.cpp b/src/common/Console.cpp index 350fb1390..8e5d7285d 100644 --- a/src/common/Console.cpp +++ b/src/common/Console.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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 @@ -22,26 +23,42 @@ */ +#include "base/tools/Handle.h" #include "common/Console.h" #include "interfaces/IConsoleListener.h" -Console::Console(IConsoleListener *listener) +xmrig::Console::Console(IConsoleListener *listener) : m_listener(listener) { - m_tty.data = this; - uv_tty_init(uv_default_loop(), &m_tty, 0, 1); + m_tty = new uv_tty_t; - if (!uv_is_readable(reinterpret_cast(&m_tty))) { + m_tty->data = this; + uv_tty_init(uv_default_loop(), m_tty, 0, 1); + + if (!uv_is_readable(reinterpret_cast(m_tty))) { return; } - uv_tty_set_mode(&m_tty, UV_TTY_MODE_RAW); - uv_read_start(reinterpret_cast(&m_tty), Console::onAllocBuffer, Console::onRead); + uv_tty_set_mode(m_tty, UV_TTY_MODE_RAW); + uv_read_start(reinterpret_cast(m_tty), Console::onAllocBuffer, Console::onRead); } -void Console::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) +xmrig::Console::~Console() +{ + stop(); +} + + +void xmrig::Console::stop() +{ + Handle::close(m_tty); + m_tty = nullptr; +} + + +void xmrig::Console::onAllocBuffer(uv_handle_t *handle, size_t, uv_buf_t *buf) { auto console = static_cast(handle->data); buf->len = 1; @@ -49,7 +66,7 @@ void Console::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t } -void Console::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) +void xmrig::Console::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { if (nread < 0) { return uv_close(reinterpret_cast(stream), nullptr); diff --git a/src/common/Console.h b/src/common/Console.h index 7f2e3cc90..c0a36ec4f 100644 --- a/src/common/Console.h +++ b/src/common/Console.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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,13 +22,17 @@ * along with this program. If not, see . */ -#ifndef __CONSOLE_H__ -#define __CONSOLE_H__ +#ifndef XMRIG_CONSOLE_H +#define XMRIG_CONSOLE_H #include + +namespace xmrig { + + class IConsoleListener; @@ -35,6 +40,9 @@ class Console { public: Console(IConsoleListener *listener); + ~Console(); + + void stop(); private: static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf); @@ -42,8 +50,11 @@ private: char m_buf[1]; IConsoleListener *m_listener; - uv_tty_t m_tty; + uv_tty_t *m_tty; }; -#endif /* __CONSOLE_H__ */ +} /* namespace xmrig */ + + +#endif /* XMRIG_CONSOLE_H */ diff --git a/src/common/api/Httpd.cpp b/src/common/api/Httpd.cpp index eb6a4ba61..cca2b056f 100644 --- a/src/common/api/Httpd.cpp +++ b/src/common/api/Httpd.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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 @@ -27,6 +28,7 @@ #include "api/Api.h" +#include "base/tools/Handle.h" #include "common/api/Httpd.h" #include "common/api/HttpReply.h" #include "common/api/HttpRequest.h" @@ -41,14 +43,15 @@ Httpd::Httpd(int port, const char *accessToken, bool IPv6, bool restricted) : m_port(port), m_daemon(nullptr) { - uv_timer_init(uv_default_loop(), &m_timer); - m_timer.data = this; + m_timer = new uv_timer_t; + uv_timer_init(uv_default_loop(), m_timer); + m_timer->data = this; } Httpd::~Httpd() { - uv_timer_stop(&m_timer); + stop(); if (m_daemon) { MHD_stop_daemon(m_daemon); @@ -82,15 +85,22 @@ bool Httpd::start() } # if MHD_VERSION >= 0x00093900 - uv_timer_start(&m_timer, Httpd::onTimer, kIdleInterval, kIdleInterval); + uv_timer_start(m_timer, Httpd::onTimer, kIdleInterval, kIdleInterval); # else - uv_timer_start(&m_timer, Httpd::onTimer, kActiveInterval, kActiveInterval); + uv_timer_start(m_timer, Httpd::onTimer, kActiveInterval, kActiveInterval); # endif return true; } +void Httpd::stop() +{ + xmrig::Handle::close(m_timer); + m_timer = nullptr; +} + + int Httpd::process(xmrig::HttpRequest &req) { xmrig::HttpReply reply; @@ -115,11 +125,11 @@ void Httpd::run() # if MHD_VERSION >= 0x00093900 const MHD_DaemonInfo *info = MHD_get_daemon_info(m_daemon, MHD_DAEMON_INFO_CURRENT_CONNECTIONS); if (m_idle && info->num_connections) { - uv_timer_set_repeat(&m_timer, kActiveInterval); + uv_timer_set_repeat(m_timer, kActiveInterval); m_idle = false; } else if (!m_idle && !info->num_connections) { - uv_timer_set_repeat(&m_timer, kIdleInterval); + uv_timer_set_repeat(m_timer, kIdleInterval); m_idle = true; } # endif diff --git a/src/common/api/Httpd.h b/src/common/api/Httpd.h index adec1d716..82ca15416 100644 --- a/src/common/api/Httpd.h +++ b/src/common/api/Httpd.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __HTTPD_H__ -#define __HTTPD_H__ +#ifndef XMRIG_HTTPD_H +#define XMRIG_HTTPD_H #include @@ -47,6 +48,7 @@ public: Httpd(int port, const char *accessToken, bool IPv6, bool restricted); ~Httpd(); bool start(); + void stop(); private: constexpr static const int kIdleInterval = 200; @@ -64,7 +66,7 @@ private: const char *m_accessToken; const int m_port; MHD_Daemon *m_daemon; - uv_timer_t m_timer; + uv_timer_t *m_timer; }; -#endif /* __HTTPD_H__ */ +#endif /* XMRIG_HTTPD_H */ diff --git a/src/common/interfaces/IConsoleListener.h b/src/common/interfaces/IConsoleListener.h index 723f87dff..88972f058 100644 --- a/src/common/interfaces/IConsoleListener.h +++ b/src/common/interfaces/IConsoleListener.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,17 +22,23 @@ * along with this program. If not, see . */ -#ifndef __ICONSOLELISTENER_H__ -#define __ICONSOLELISTENER_H__ +#ifndef XMRIG_ICONSOLELISTENER_H +#define XMRIG_ICONSOLELISTENER_H + + +namespace xmrig { class IConsoleListener { public: - virtual ~IConsoleListener() {} + virtual ~IConsoleListener() = default; virtual void onConsoleCommand(char command) = 0; }; -#endif // __ICONSOLELISTENER_H__ +} /* namespace xmrig */ + + +#endif // XMRIG_ICONSOLELISTENER_H diff --git a/src/common/interfaces/ILogBackend.h b/src/common/interfaces/ILogBackend.h index 85a04e935..2299fc671 100644 --- a/src/common/interfaces/ILogBackend.h +++ b/src/common/interfaces/ILogBackend.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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,14 +22,17 @@ * along with this program. If not, see . */ -#ifndef __ILOGBACKEND_H__ -#define __ILOGBACKEND_H__ +#ifndef XMRIG_ILOGBACKEND_H +#define XMRIG_ILOGBACKEND_H #include #include +namespace xmrig { + + class ILogBackend { public: @@ -46,11 +50,14 @@ public: constexpr static const size_t kBufferSize = 512; # endif - virtual ~ILogBackend() {} + virtual ~ILogBackend() = default; virtual void message(Level level, const char* fmt, va_list args) = 0; virtual void text(const char* fmt, va_list args) = 0; }; -#endif // __ILOGBACKEND_H__ +} /* namespace xmrig */ + + +#endif // XMRIG_ILOGBACKEND_H diff --git a/src/common/log/BasicLog.cpp b/src/common/log/BasicLog.cpp index cb4defcde..b048dd6e0 100644 --- a/src/common/log/BasicLog.cpp +++ b/src/common/log/BasicLog.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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 @@ -38,12 +39,12 @@ #include "common/log/Log.h" -BasicLog::BasicLog() +xmrig::BasicLog::BasicLog() { } -void BasicLog::message(Level level, const char* fmt, va_list args) +void xmrig::BasicLog::message(Level level, const char* fmt, va_list args) { time_t now = time(nullptr); tm stime; @@ -70,7 +71,7 @@ void BasicLog::message(Level level, const char* fmt, va_list args) } -void BasicLog::text(const char* fmt, va_list args) +void xmrig::BasicLog::text(const char* fmt, va_list args) { snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(false)); @@ -78,7 +79,7 @@ void BasicLog::text(const char* fmt, va_list args) } -void BasicLog::print(va_list args) +void xmrig::BasicLog::print(va_list args) { if (vsnprintf(m_buf, sizeof(m_buf) - 1, m_fmt, args) <= 0) { return; diff --git a/src/common/log/BasicLog.h b/src/common/log/BasicLog.h index 523538e95..bddbe07cb 100644 --- a/src/common/log/BasicLog.h +++ b/src/common/log/BasicLog.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __BASICLOG_H__ -#define __BASICLOG_H__ +#ifndef XMRIG_BASICLOG_H +#define XMRIG_BASICLOG_H #include @@ -32,8 +33,6 @@ namespace xmrig { - class Controller; -} class BasicLog : public ILogBackend @@ -52,4 +51,7 @@ private: char m_fmt[256]; }; -#endif /* __BASICLOG_H__ */ + +} /* namespace xmrig */ + +#endif /* XMRIG_BASICLOG_H */ diff --git a/src/common/log/ConsoleLog.cpp b/src/common/log/ConsoleLog.cpp index b10812a6d..e0ac01eaa 100644 --- a/src/common/log/ConsoleLog.cpp +++ b/src/common/log/ConsoleLog.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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 @@ -34,24 +35,24 @@ #endif +#include "base/tools/Handle.h" #include "common/log/ConsoleLog.h" #include "common/log/Log.h" -#include "core/Config.h" -#include "core/Controller.h" -ConsoleLog::ConsoleLog(xmrig::Controller *controller) : - m_stream(nullptr), - m_controller(controller) +xmrig::ConsoleLog::ConsoleLog() : + m_stream(nullptr) { - if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) { + m_tty = new uv_tty_t; + + if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) { Log::colors = false; return; } - uv_tty_set_mode(&m_tty, UV_TTY_MODE_NORMAL); + uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL); m_uvBuf.base = m_buf; - m_stream = reinterpret_cast(&m_tty); + m_stream = reinterpret_cast(m_tty); # ifdef WIN32 HANDLE handle = GetStdHandle(STD_INPUT_HANDLE); @@ -66,7 +67,13 @@ ConsoleLog::ConsoleLog(xmrig::Controller *controller) : } -void ConsoleLog::message(Level level, const char* fmt, va_list args) +xmrig::ConsoleLog::~ConsoleLog() +{ + Handle::close(m_tty); +} + + +void xmrig::ConsoleLog::message(Level level, const char* fmt, va_list args) { time_t now = time(nullptr); tm stime; @@ -77,8 +84,6 @@ void ConsoleLog::message(Level level, const char* fmt, va_list args) localtime_r(&now, &stime); # endif - const bool isColors = m_controller->config()->isColors(); - snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s", stime.tm_year + 1900, stime.tm_mon + 1, @@ -86,24 +91,24 @@ void ConsoleLog::message(Level level, const char* fmt, va_list args) stime.tm_hour, stime.tm_min, stime.tm_sec, - Log::colorByLevel(level, isColors), + Log::colorByLevel(level, Log::colors), fmt, - Log::endl(isColors) + Log::endl(Log::colors) ); print(args); } -void ConsoleLog::text(const char* fmt, va_list args) +void xmrig::ConsoleLog::text(const char* fmt, va_list args) { - snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(m_controller->config()->isColors())); + snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(Log::colors)); print(args); } -bool ConsoleLog::isWritable() const +bool xmrig::ConsoleLog::isWritable() const { if (!m_stream || uv_is_writable(m_stream) != 1) { return false; @@ -114,7 +119,7 @@ bool ConsoleLog::isWritable() const } -void ConsoleLog::print(va_list args) +void xmrig::ConsoleLog::print(va_list args) { m_uvBuf.len = vsnprintf(m_buf, sizeof(m_buf) - 1, m_fmt, args); if (m_uvBuf.len <= 0) { diff --git a/src/common/log/ConsoleLog.h b/src/common/log/ConsoleLog.h index bac09a535..73a701e66 100644 --- a/src/common/log/ConsoleLog.h +++ b/src/common/log/ConsoleLog.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __CONSOLELOG_H__ -#define __CONSOLELOG_H__ +#ifndef XMRIG_CONSOLELOG_H +#define XMRIG_CONSOLELOG_H #include @@ -32,15 +33,15 @@ namespace xmrig { - class Controller; -} class ConsoleLog : public ILogBackend { public: - ConsoleLog(xmrig::Controller *controller); + ConsoleLog(); + ~ConsoleLog() override; +protected: void message(Level level, const char *fmt, va_list args) override; void text(const char *fmt, va_list args) override; @@ -52,8 +53,11 @@ private: char m_fmt[256]; uv_buf_t m_uvBuf; uv_stream_t *m_stream; - uv_tty_t m_tty; - xmrig::Controller *m_controller; + uv_tty_t *m_tty; }; -#endif /* __CONSOLELOG_H__ */ + +} /* namespace xmrig */ + + +#endif /* XMRIG_CONSOLELOG_H */ diff --git a/src/common/log/FileLog.cpp b/src/common/log/FileLog.cpp index 9134c7c75..71eeb18ca 100644 --- a/src/common/log/FileLog.cpp +++ b/src/common/log/FileLog.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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 @@ -31,12 +32,9 @@ #include "common/log/FileLog.h" #include "common/log/Log.h" -#include "core/Config.h" -#include "core/Controller.h" -FileLog::FileLog(xmrig::Controller *controller, const char *fileName) : - m_controller(controller) +xmrig::FileLog::FileLog(const char *fileName) { uv_fs_t req; m_file = uv_fs_open(uv_default_loop(), &req, fileName, O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr); @@ -44,7 +42,7 @@ FileLog::FileLog(xmrig::Controller *controller, const char *fileName) : } -void FileLog::message(Level level, const char* fmt, va_list args) +void xmrig::FileLog::message(Level level, const char* fmt, va_list args) { if (m_file < 0) { return; @@ -59,8 +57,6 @@ void FileLog::message(Level level, const char* fmt, va_list args) localtime_r(&now, &stime); # endif - const bool isColors = m_controller->config()->isColors(); - snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s", stime.tm_year + 1900, stime.tm_mon + 1, @@ -68,9 +64,9 @@ void FileLog::message(Level level, const char* fmt, va_list args) stime.tm_hour, stime.tm_min, stime.tm_sec, - Log::colorByLevel(level, isColors), + Log::colorByLevel(level, Log::colors), fmt, - Log::endl(isColors) + Log::endl(Log::colors) ); char *buf = new char[kBufferSize]; @@ -80,13 +76,13 @@ void FileLog::message(Level level, const char* fmt, va_list args) } -void FileLog::text(const char* fmt, va_list args) +void xmrig::FileLog::text(const char* fmt, va_list args) { message(INFO, fmt, args); } -void FileLog::onWrite(uv_fs_t *req) +void xmrig::FileLog::onWrite(uv_fs_t *req) { delete [] static_cast(req->data); @@ -95,7 +91,7 @@ void FileLog::onWrite(uv_fs_t *req) } -void FileLog::write(char *data, size_t size) +void xmrig::FileLog::write(char *data, size_t size) { uv_buf_t buf = uv_buf_init(data, (unsigned int) size); uv_fs_t *req = new uv_fs_t; diff --git a/src/common/log/FileLog.h b/src/common/log/FileLog.h index 8a58d4e40..da80acb23 100644 --- a/src/common/log/FileLog.h +++ b/src/common/log/FileLog.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __FILELOG_H__ -#define __FILELOG_H__ +#ifndef XMRIG_FILELOG_H +#define XMRIG_FILELOG_H #include @@ -32,14 +33,12 @@ namespace xmrig { - class Controller; -} class FileLog : public ILogBackend { public: - FileLog(xmrig::Controller *controller, const char *fileName); + FileLog(const char *fileName); void message(Level level, const char* fmt, va_list args) override; void text(const char* fmt, va_list args) override; @@ -51,7 +50,10 @@ private: char m_fmt[256]; int m_file; - xmrig::Controller *m_controller; }; -#endif /* __FILELOG_H__ */ + +} /* namespace xmrig */ + + +#endif /* XMRIG_FILELOG_H */ diff --git a/src/common/log/Log.cpp b/src/common/log/Log.cpp index 07e4f2998..4ef1e14aa 100644 --- a/src/common/log/Log.cpp +++ b/src/common/log/Log.cpp @@ -35,6 +35,8 @@ #include "common/log/Log.h" +namespace xmrig { + Log *Log::m_self = nullptr; bool Log::colors = true; @@ -51,8 +53,10 @@ static const char *color[5] = { # endif }; +} /* namespace xmrig */ -void Log::message(ILogBackend::Level level, const char* fmt, ...) + +void xmrig::Log::message(ILogBackend::Level level, const char* fmt, ...) { uv_mutex_lock(&m_mutex); @@ -72,7 +76,7 @@ void Log::message(ILogBackend::Level level, const char* fmt, ...) } -void Log::text(const char* fmt, ...) +void xmrig::Log::text(const char* fmt, ...) { uv_mutex_lock(&m_mutex); @@ -92,7 +96,7 @@ void Log::text(const char* fmt, ...) } -const char *Log::colorByLevel(ILogBackend::Level level, bool isColors) +const char *xmrig::Log::colorByLevel(ILogBackend::Level level, bool isColors) { if (!isColors) { return ""; @@ -102,7 +106,7 @@ const char *Log::colorByLevel(ILogBackend::Level level, bool isColors) } -const char *Log::endl(bool isColors) +const char *xmrig::Log::endl(bool isColors) { # ifdef _WIN32 return isColors ? "\x1B[0m\r\n" : "\r\n"; @@ -112,7 +116,7 @@ const char *Log::endl(bool isColors) } -void Log::defaultInit() +void xmrig::Log::defaultInit() { m_self = new Log(); @@ -120,8 +124,10 @@ void Log::defaultInit() } -Log::~Log() +xmrig::Log::~Log() { + m_self = nullptr; + for (auto backend : m_backends) { delete backend; } diff --git a/src/common/log/Log.h b/src/common/log/Log.h index c32edddd4..9a0ba2a94 100644 --- a/src/common/log/Log.h +++ b/src/common/log/Log.h @@ -34,6 +34,9 @@ #include "common/interfaces/ILogBackend.h" +namespace xmrig { + + class Log { public: @@ -68,6 +71,9 @@ private: }; +} /* namespace xmrig */ + + #define RED_BOLD(x) "\x1B[1;31m" x "\x1B[0m" #define RED(x) "\x1B[0;31m" x "\x1B[0m" #define GREEN_BOLD(x) "\x1B[1;32m" x "\x1B[0m" @@ -83,20 +89,20 @@ private: #define GRAY(x) "\x1B[1;30m" x "\x1B[0m" -#define LOG_ERR(x, ...) Log::i()->message(ILogBackend::ERR, x, ##__VA_ARGS__) -#define LOG_WARN(x, ...) Log::i()->message(ILogBackend::WARNING, x, ##__VA_ARGS__) -#define LOG_NOTICE(x, ...) Log::i()->message(ILogBackend::NOTICE, x, ##__VA_ARGS__) -#define LOG_INFO(x, ...) Log::i()->message(ILogBackend::INFO, x, ##__VA_ARGS__) +#define LOG_ERR(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::ERR, x, ##__VA_ARGS__) +#define LOG_WARN(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::WARNING, x, ##__VA_ARGS__) +#define LOG_NOTICE(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::NOTICE, x, ##__VA_ARGS__) +#define LOG_INFO(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::INFO, x, ##__VA_ARGS__) #ifdef APP_DEBUG -# define LOG_DEBUG(x, ...) Log::i()->message(ILogBackend::DEBUG, x, ##__VA_ARGS__) +# define LOG_DEBUG(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::DEBUG, x, ##__VA_ARGS__) #else # define LOG_DEBUG(x, ...) #endif #if defined(APP_DEBUG) || defined(APP_DEVEL) -# define LOG_DEBUG_ERR(x, ...) Log::i()->message(ILogBackend::ERR, x, ##__VA_ARGS__) -# define LOG_DEBUG_WARN(x, ...) Log::i()->message(ILogBackend::WARNING, x, ##__VA_ARGS__) +# define LOG_DEBUG_ERR(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::ERR, x, ##__VA_ARGS__) +# define LOG_DEBUG_WARN(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::WARNING, x, ##__VA_ARGS__) #else # define LOG_DEBUG_ERR(x, ...) # define LOG_DEBUG_WARN(x, ...) diff --git a/src/common/log/SysLog.cpp b/src/common/log/SysLog.cpp index bcb963943..1a8ffbd2f 100644 --- a/src/common/log/SysLog.cpp +++ b/src/common/log/SysLog.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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 @@ -29,19 +30,19 @@ #include "version.h" -SysLog::SysLog() +xmrig::SysLog::SysLog() { openlog(APP_ID, LOG_PID, LOG_USER); } -void SysLog::message(Level level, const char *fmt, va_list args) +void xmrig::SysLog::message(Level level, const char *fmt, va_list args) { vsyslog(static_cast(level), fmt, args); } -void SysLog::text(const char *fmt, va_list args) +void xmrig::SysLog::text(const char *fmt, va_list args) { vsyslog(LOG_INFO, fmt, args); } diff --git a/src/common/log/SysLog.h b/src/common/log/SysLog.h index 5cfeefcdb..3e64cf8b6 100644 --- a/src/common/log/SysLog.h +++ b/src/common/log/SysLog.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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,13 +22,16 @@ * along with this program. If not, see . */ -#ifndef __SYSLOG_H__ -#define __SYSLOG_H__ +#ifndef XMRIG_SYSLOG_H +#define XMRIG_SYSLOG_H #include "common/interfaces/ILogBackend.h" +namespace xmrig { + + class SysLog : public ILogBackend { public: @@ -37,4 +41,8 @@ public: void text(const char *fmt, va_list args) override; }; -#endif /* __SYSLOG_BACKEND_H__ */ + +} /* namespace xmrig */ + + +#endif /* XMRIG_SYSLOG_H */ diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index 7639bfaae..cfd132ddc 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -75,8 +75,6 @@ xmrig::Controller::Controller(Process *process) xmrig::Controller::~Controller() { - ConfigLoader::release(); - delete d_ptr; } @@ -109,11 +107,11 @@ int xmrig::Controller::init() Platform::setProcessPriority(d_ptr->config->priority()); if (!config()->isBackground()) { - Log::add(new ConsoleLog(this)); + Log::add(new ConsoleLog()); } if (config()->logFile()) { - Log::add(new FileLog(this, config()->logFile())); + Log::add(new FileLog(config()->logFile())); } # ifdef HAVE_SYSLOG_H @@ -166,3 +164,12 @@ void xmrig::Controller::onNewConfig(IConfig *config) delete previousConfig; } + + +void xmrig::Controller::stop() +{ + ConfigLoader::release(); + + delete d_ptr->network; + d_ptr->network = nullptr; +} diff --git a/src/core/Controller.h b/src/core/Controller.h index 8d2f26745..7c74b53c5 100644 --- a/src/core/Controller.h +++ b/src/core/Controller.h @@ -54,6 +54,7 @@ public: Network *network() const; void addListener(IControllerListener *listener); void save(); + void stop(); protected: void onNewConfig(IConfig *config) override; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index b8f4f05e7..efadb365d 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -35,6 +35,7 @@ #include "base/net/stratum/Client.h" #include "base/net/stratum/SubmitResult.h" #include "base/tools/Chrono.h" +#include "base/tools/Handle.h" #include "common/log/Log.h" #include "core/Config.h" #include "core/Controller.h" @@ -44,7 +45,8 @@ xmrig::Network::Network(Controller *controller) : - m_donate(nullptr) + m_donate(nullptr), + m_timer(nullptr) { Workers::setListener(this); controller->addListener(this); @@ -56,15 +58,21 @@ xmrig::Network::Network(Controller *controller) : m_donate = new DonateStrategy(controller->config()->donateLevel(), pools.data().front().user(), controller->config()->algorithm().algo(), this); } - m_timer.data = this; - uv_timer_init(uv_default_loop(), &m_timer); - - uv_timer_start(&m_timer, Network::onTick, kTickInterval, kTickInterval); + m_timer = new uv_timer_t; + m_timer->data = this; + uv_timer_init(uv_default_loop(), m_timer); + uv_timer_start(m_timer, Network::onTick, kTickInterval, kTickInterval); } xmrig::Network::~Network() { + Handle::close(m_timer); + + if (m_donate) { + delete m_donate; + } + delete m_strategy; } @@ -75,16 +83,6 @@ void xmrig::Network::connect() } -void xmrig::Network::stop() -{ - if (m_donate) { - m_donate->stop(); - } - - m_strategy->stop(); -} - - void xmrig::Network::onActive(IStrategy *strategy, Client *client) { if (m_donate && m_donate == strategy) { diff --git a/src/net/Network.h b/src/net/Network.h index 8796045a2..e83e60e22 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -50,7 +50,6 @@ public: ~Network() override; void connect(); - void stop(); protected: void onActive(IStrategy *strategy, Client *client) override; @@ -72,7 +71,7 @@ private: IStrategy *m_donate; IStrategy *m_strategy; NetworkState m_state; - uv_timer_t m_timer; + uv_timer_t *m_timer; }; diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index ba544c4b6..7d08fb338 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -28,6 +28,7 @@ #include "base/net/stratum/strategies/FailoverStrategy.h" #include "base/net/stratum/strategies/SinglePoolStrategy.h" #include "base/tools/Buffer.h" +#include "base/tools/Handle.h" #include "common/crypto/keccak.h" #include "common/Platform.h" #include "common/xmrig.h" @@ -71,8 +72,9 @@ xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IS m_strategy = new SinglePoolStrategy(m_pools.front(), 1, 2, this, true); } - m_timer.data = this; - uv_timer_init(uv_default_loop(), &m_timer); + m_timer = new uv_timer_t; + m_timer->data = this; + uv_timer_init(uv_default_loop(), m_timer); idle(m_idleTime * randomf(0.5, 1.5)); } @@ -80,6 +82,7 @@ xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IS xmrig::DonateStrategy::~DonateStrategy() { + Handle::close(m_timer); delete m_strategy; } @@ -104,7 +107,7 @@ void xmrig::DonateStrategy::setAlgo(const xmrig::Algorithm &algo) void xmrig::DonateStrategy::stop() { - uv_timer_stop(&m_timer); + uv_timer_stop(m_timer); m_strategy->stop(); } @@ -125,7 +128,7 @@ void xmrig::DonateStrategy::tick(uint64_t now) void xmrig::DonateStrategy::onActive(IStrategy *strategy, Client *client) { if (!isActive()) { - uv_timer_start(&m_timer, DonateStrategy::onTimer, m_donateTime, 0); + uv_timer_start(m_timer, DonateStrategy::onTimer, m_donateTime, 0); } m_active = true; @@ -154,7 +157,7 @@ void xmrig::DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client void xmrig::DonateStrategy::idle(uint64_t timeout) { - uv_timer_start(&m_timer, DonateStrategy::onTimer, timeout, 0); + uv_timer_start(m_timer, DonateStrategy::onTimer, timeout, 0); } diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 8c350097e..ab898332b 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -79,7 +79,7 @@ private: std::vector m_pools; uint64_t m_now; uint64_t m_stop; - uv_timer_t m_timer; + uv_timer_t *m_timer; }; diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 2a7503180..591b719ae 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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 @@ -29,6 +30,7 @@ #include +#include "base/tools/Handle.h" #include "common/log/Log.h" #include "core/Config.h" #include "core/Controller.h" @@ -49,6 +51,7 @@ inline static const char *format(double h, char *buf, size_t size) Hashrate::Hashrate(size_t threads, xmrig::Controller *controller) : m_highest(0.0), m_threads(threads), + m_timer(nullptr), m_controller(controller) { m_counts = new uint64_t*[threads]; @@ -64,10 +67,11 @@ Hashrate::Hashrate(size_t threads, xmrig::Controller *controller) : const int printTime = controller->config()->printTime(); if (printTime > 0) { - uv_timer_init(uv_default_loop(), &m_timer); - m_timer.data = this; + m_timer = new uv_timer_t; + uv_timer_init(uv_default_loop(), m_timer); + m_timer->data = this; - uv_timer_start(&m_timer, Hashrate::onReport, (printTime + 4) * 1000, printTime * 1000); + uv_timer_start(m_timer, Hashrate::onReport, (printTime + 4) * 1000, printTime * 1000); } } @@ -171,7 +175,8 @@ void Hashrate::print() const void Hashrate::stop() { - uv_timer_stop(&m_timer); + xmrig::Handle::close(m_timer); + m_timer = nullptr; } diff --git a/src/workers/Hashrate.h b/src/workers/Hashrate.h index e766f1170..673c6a51d 100644 --- a/src/workers/Hashrate.h +++ b/src/workers/Hashrate.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __HASHRATE_H__ -#define __HASHRATE_H__ +#ifndef XMRIG_HASHRATE_H +#define XMRIG_HASHRATE_H #include @@ -67,9 +68,9 @@ private: uint32_t* m_top; uint64_t** m_counts; uint64_t** m_timestamps; - uv_timer_t m_timer; + uv_timer_t *m_timer; xmrig::Controller *m_controller; }; -#endif /* __HASHRATE_H__ */ +#endif /* XMRIG_HASHRATE_H */ diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 02eec378e..b3c4882b6 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -35,7 +35,7 @@ template -MultiWorker::MultiWorker(Handle *handle) +MultiWorker::MultiWorker(ThreadHandle *handle) : Worker(handle) { m_memory = Mem::create(m_ctx, m_thread->algorithm(), N); diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index 525eee18c..99d37e442 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -40,7 +40,7 @@ template class MultiWorker : public Worker { public: - MultiWorker(Handle *handle); + MultiWorker(ThreadHandle *handle); ~MultiWorker(); protected: diff --git a/src/workers/Handle.cpp b/src/workers/ThreadHandle.cpp similarity index 79% rename from src/workers/Handle.cpp rename to src/workers/ThreadHandle.cpp index d42ea3689..43ff950c4 100644 --- a/src/workers/Handle.cpp +++ b/src/workers/ThreadHandle.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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 @@ -22,10 +23,10 @@ */ -#include "workers/Handle.h" +#include "workers/ThreadHandle.h" -Handle::Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays) : +ThreadHandle::ThreadHandle(xmrig::IThread *config, uint32_t offset, size_t totalWays) : m_worker(nullptr), m_totalWays(totalWays), m_offset(offset), @@ -34,13 +35,13 @@ Handle::Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays) : } -void Handle::join() +void ThreadHandle::join() { uv_thread_join(&m_thread); } -void Handle::start(void (*callback) (void *)) +void ThreadHandle::start(void (*callback) (void *)) { uv_thread_create(&m_thread, callback, this); } diff --git a/src/workers/Handle.h b/src/workers/ThreadHandle.h similarity index 85% rename from src/workers/Handle.h rename to src/workers/ThreadHandle.h index 4bb899f9f..f3e09ce50 100644 --- a/src/workers/Handle.h +++ b/src/workers/ThreadHandle.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __HANDLE_H__ -#define __HANDLE_H__ +#ifndef XMRIG_THREADHANDLE_H +#define XMRIG_THREADHANDLE_H #include @@ -36,10 +37,10 @@ class IWorker; -class Handle +class ThreadHandle { public: - Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays); + ThreadHandle(xmrig::IThread *config, uint32_t offset, size_t totalWays); void join(); void start(void (*callback) (void *)); @@ -59,4 +60,4 @@ private: }; -#endif /* __HANDLE_H__ */ +#endif /* XMRIG_THREADHANDLE_H */ diff --git a/src/workers/Worker.cpp b/src/workers/Worker.cpp index c569908c6..234e7bfda 100644 --- a/src/workers/Worker.cpp +++ b/src/workers/Worker.cpp @@ -27,11 +27,11 @@ #include "common/cpu/Cpu.h" #include "common/Platform.h" #include "workers/CpuThread.h" -#include "workers/Handle.h" +#include "workers/ThreadHandle.h" #include "workers/Worker.h" -Worker::Worker(Handle *handle) : +Worker::Worker(ThreadHandle *handle) : m_id(handle->threadId()), m_totalWays(handle->totalWays()), m_offset(handle->offset()), diff --git a/src/workers/Worker.h b/src/workers/Worker.h index 73e250330..4710bcc54 100644 --- a/src/workers/Worker.h +++ b/src/workers/Worker.h @@ -33,7 +33,7 @@ #include "Mem.h" -class Handle; +class ThreadHandle; namespace xmrig { @@ -44,7 +44,7 @@ namespace xmrig { class Worker : public IWorker { public: - Worker(Handle *handle); + Worker(ThreadHandle *handle); inline const MemInfo &memory() const { return m_memory; } inline size_t id() const override { return m_id; } diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index f718a52c5..5426762e9 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -28,6 +28,7 @@ #include "api/Api.h" +#include "base/tools/Handle.h" #include "common/log/Log.h" #include "core/Config.h" #include "core/Controller.h" @@ -36,9 +37,9 @@ #include "interfaces/IThread.h" #include "Mem.h" #include "rapidjson/document.h" -#include "workers/Handle.h" #include "workers/Hashrate.h" #include "workers/MultiWorker.h" +#include "workers/ThreadHandle.h" #include "workers/Workers.h" @@ -51,12 +52,12 @@ Workers::LaunchStatus Workers::m_status; std::atomic Workers::m_paused; std::atomic Workers::m_sequence; std::list Workers::m_queue; -std::vector Workers::m_workers; +std::vector Workers::m_workers; uint64_t Workers::m_ticks = 0; -uv_async_t Workers::m_async; +uv_async_t *Workers::m_async = nullptr; uv_mutex_t Workers::m_mutex; uv_rwlock_t Workers::m_rwlock; -uv_timer_t Workers::m_timer; +uv_timer_t *Workers::m_timer = nullptr; xmrig::Controller *Workers::m_controller = nullptr; @@ -103,11 +104,11 @@ void Workers::printHashrate(bool detail) char num2[8] = { 0 }; char num3[8] = { 0 }; - Log::i()->text("%s| THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |", isColors ? "\x1B[1;37m" : ""); + xmrig::Log::i()->text("%s| THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |", isColors ? "\x1B[1;37m" : ""); size_t i = 0; for (const xmrig::IThread *thread : m_controller->config()->threads()) { - Log::i()->text("| %6zu | %8" PRId64 " | %7s | %7s | %7s |", + xmrig::Log::i()->text("| %6zu | %8" PRId64 " | %7s | %7s | %7s |", thread->index(), thread->affinity(), Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::ShortInterval), num1, sizeof num1), @@ -192,14 +193,17 @@ void Workers::start(xmrig::Controller *controller) m_sequence = 1; m_paused = 1; - uv_async_init(uv_default_loop(), &m_async, Workers::onResult); - uv_timer_init(uv_default_loop(), &m_timer); - uv_timer_start(&m_timer, Workers::onTick, 500, 500); + m_async = new uv_async_t; + uv_async_init(uv_default_loop(), m_async, Workers::onResult); + + m_timer = new uv_timer_t; + uv_timer_init(uv_default_loop(), m_timer); + uv_timer_start(m_timer, Workers::onTick, 500, 500); uint32_t offset = 0; for (xmrig::IThread *thread : threads) { - Handle *handle = new Handle(thread, offset, m_status.ways); + ThreadHandle *handle = new ThreadHandle(thread, offset, m_status.ways); offset += thread->multiway(); m_workers.push_back(handle); @@ -212,10 +216,10 @@ void Workers::start(xmrig::Controller *controller) void Workers::stop() { - uv_timer_stop(&m_timer); + xmrig::Handle::close(m_timer); + xmrig::Handle::close(m_async); m_hashrate->stop(); - uv_close(reinterpret_cast(&m_async), nullptr); m_paused = 0; m_sequence = 0; @@ -231,7 +235,7 @@ void Workers::submit(const xmrig::JobResult &result) m_queue.push_back(result); uv_mutex_unlock(&m_mutex); - uv_async_send(&m_async); + uv_async_send(m_async); } @@ -257,7 +261,7 @@ void Workers::threadsSummary(rapidjson::Document &doc) void Workers::onReady(void *arg) { - auto handle = static_cast(arg); + auto handle = static_cast(arg); IWorker *worker = nullptr; @@ -319,7 +323,7 @@ void Workers::onResult(uv_async_t *handle) void Workers::onTick(uv_timer_t *handle) { - for (Handle *handle : m_workers) { + for (ThreadHandle *handle : m_workers) { if (!handle->worker()) { return; } diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 0760c98f3..23b0a27cd 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -36,9 +36,9 @@ #include "rapidjson/fwd.h" -class Handle; class Hashrate; class IWorker; +class ThreadHandle; namespace xmrig { @@ -109,12 +109,12 @@ private: static std::atomic m_paused; static std::atomic m_sequence; static std::list m_queue; - static std::vector m_workers; + static std::vector m_workers; static uint64_t m_ticks; - static uv_async_t m_async; + static uv_async_t *m_async; static uv_mutex_t m_mutex; static uv_rwlock_t m_rwlock; - static uv_timer_t m_timer; + static uv_timer_t *m_timer; static xmrig::Controller *m_controller; }; From 0d86e53a32fb62e6fa177b2bc67094d0fa92b26b Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 16 Mar 2019 02:07:26 +0700 Subject: [PATCH 47/55] Move files. --- CMakeLists.txt | 58 ++---------------- cmake/OpenSSL.cmake | 4 ++ src/App.cpp | 2 +- src/App.h | 2 +- src/base/base.cmake | 60 +++++++++++++++++++ src/{common => base/io}/Console.cpp | 4 +- src/{common => base/io}/Console.h | 0 .../kernel}/interfaces/IConsoleListener.h | 0 src/common/utils/c_str.h | 39 ------------ src/common/utils/timestamp.h | 55 ----------------- 10 files changed, 74 insertions(+), 150 deletions(-) create mode 100644 src/base/base.cmake rename src/{common => base/io}/Console.cpp (96%) rename src/{common => base/io}/Console.h (100%) rename src/{common => base/kernel}/interfaces/IConsoleListener.h (100%) delete mode 100644 src/common/utils/c_str.h delete mode 100644 src/common/utils/timestamp.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f87a85df..c8e68648a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,50 +16,21 @@ option(WITH_EMBEDDED_CONFIG "Enable internal embedded JSON config" OFF) include (CheckIncludeFile) include (cmake/cpu.cmake) +include (src/base/base.cmake) set(HEADERS + "${HEADERS_BASE}" src/api/NetworkState.h src/App.h - src/base/io/Json.h - src/base/io/Watcher.h - src/base/kernel/Entry.h - src/base/kernel/interfaces/IClientListener.h - src/base/kernel/interfaces/IConfigListener.h - src/base/kernel/interfaces/IDnsListener.h - src/base/kernel/interfaces/ILineListener.h - src/base/kernel/interfaces/ISignalListener.h - src/base/kernel/interfaces/IStrategy.h - src/base/kernel/interfaces/IStrategyListener.h - src/base/kernel/interfaces/IWatcherListener.h - src/base/kernel/Process.h - src/base/kernel/Signals.h - src/base/net/dns/Dns.h - src/base/net/dns/DnsRecord.h - src/base/net/stratum/Client.h - src/base/net/stratum/Job.h - src/base/net/stratum/Pool.h - src/base/net/stratum/Pools.h - src/base/net/stratum/strategies/FailoverStrategy.h - src/base/net/stratum/strategies/SinglePoolStrategy.h - src/base/net/stratum/SubmitResult.h - src/base/net/tools/RecvBuf.h - src/base/net/tools/Storage.h - src/base/tools/Arguments.h - src/base/tools/Buffer.h - src/base/tools/Chrono.h - src/base/tools/Handle.h - src/base/tools/String.h src/common/config/CommonConfig.h src/common/config/ConfigLoader.h src/common/config/ConfigWatcher.h - src/common/Console.h src/common/cpu/Cpu.h src/common/crypto/Algorithm.h src/common/crypto/keccak.h src/common/interfaces/IConfig.h src/common/interfaces/IConfigCreator.h - src/common/interfaces/IConsoleListener.h src/common/interfaces/IControllerListener.h src/common/interfaces/ICpuInfo.h src/common/interfaces/ILogBackend.h @@ -68,7 +39,6 @@ set(HEADERS src/common/log/FileLog.h src/common/log/Log.h src/common/Platform.h - src/common/utils/c_str.h src/common/utils/mm_malloc.h src/common/xmrig.h src/core/ConfigLoader_default.h @@ -114,28 +84,12 @@ else() endif() set(SOURCES + "${SOURCES_BASE}" src/api/NetworkState.cpp src/App.cpp - src/base/io/Json.cpp - src/base/io/Watcher.cpp - src/base/kernel/Entry.cpp - src/base/kernel/Process.cpp - src/base/kernel/Signals.cpp - src/base/net/dns/Dns.cpp - src/base/net/dns/DnsRecord.cpp - src/base/net/stratum/Client.cpp - src/base/net/stratum/Job.cpp - src/base/net/stratum/Pool.cpp - src/base/net/stratum/Pools.cpp - src/base/net/stratum/strategies/FailoverStrategy.cpp - src/base/net/stratum/strategies/SinglePoolStrategy.cpp - src/base/tools/Arguments.cpp - src/base/tools/Buffer.cpp - src/base/tools/String.cpp src/common/config/CommonConfig.cpp src/common/config/ConfigLoader.cpp src/common/config/ConfigWatcher.cpp - src/common/Console.cpp src/common/crypto/Algorithm.cpp src/common/crypto/keccak.cpp src/common/log/BasicLog.cpp @@ -167,9 +121,9 @@ set(SOURCES_CRYPTO if (WIN32) set(SOURCES_OS + "${SOURCES_OS}" res/app.rc src/App_win.cpp - src/base/io/Json_win.cpp src/common/Platform_win.cpp src/Mem_win.cpp ) @@ -178,15 +132,15 @@ if (WIN32) set(EXTRA_LIBS ws2_32 psapi iphlpapi userenv) elseif (APPLE) set(SOURCES_OS + "${SOURCES_OS}" src/App_unix.cpp - src/base/io/Json_unix.cpp src/common/Platform_mac.cpp src/Mem_unix.cpp ) else() set(SOURCES_OS + "${SOURCES_OS}" src/App_unix.cpp - src/base/io/Json_unix.cpp src/common/Platform_unix.cpp src/Mem_unix.cpp ) diff --git a/cmake/OpenSSL.cmake b/cmake/OpenSSL.cmake index 5761f99f4..219d50b9d 100644 --- a/cmake/OpenSSL.cmake +++ b/cmake/OpenSSL.cmake @@ -16,9 +16,13 @@ if (WITH_TLS) else() message(FATAL_ERROR "OpenSSL NOT found: use `-DWITH_TLS=OFF` to build without TLS support") endif() + + add_definitions(/DXMRIG_FEATURE_TLS) + remove_definitions(/DXMRIG_NO_TLS) else() set(TLS_SOURCES "") set(OPENSSL_LIBRARIES "") + remove_definitions(/DXMRIG_FEATURE_TLS) add_definitions(/DXMRIG_NO_TLS) set(CMAKE_PROJECT_NAME "${CMAKE_PROJECT_NAME}-notls") diff --git a/src/App.cpp b/src/App.cpp index 62dd38144..500a521d6 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -30,8 +30,8 @@ #include "api/Api.h" #include "App.h" +#include "base/io/Console.h" #include "base/kernel/Signals.h" -#include "common/Console.h" #include "common/cpu/Cpu.h" #include "common/log/Log.h" #include "common/Platform.h" diff --git a/src/App.h b/src/App.h index 02cc61a22..21e57725f 100644 --- a/src/App.h +++ b/src/App.h @@ -27,8 +27,8 @@ #define XMRIG_APP_H +#include "base/kernel/interfaces/IConsoleListener.h" #include "base/kernel/interfaces/ISignalListener.h" -#include "common/interfaces/IConsoleListener.h" class Httpd; diff --git a/src/base/base.cmake b/src/base/base.cmake new file mode 100644 index 000000000..79181f05f --- /dev/null +++ b/src/base/base.cmake @@ -0,0 +1,60 @@ +set(HEADERS_BASE + src/base/io/Console.h + src/base/io/Json.h + src/base/io/Watcher.h + src/base/kernel/Entry.h + src/base/kernel/interfaces/IClientListener.h + src/base/kernel/interfaces/IConfigListener.h + src/base/kernel/interfaces/IConsoleListener.h + src/base/kernel/interfaces/IDnsListener.h + src/base/kernel/interfaces/ILineListener.h + src/base/kernel/interfaces/ISignalListener.h + src/base/kernel/interfaces/IStrategy.h + src/base/kernel/interfaces/IStrategyListener.h + src/base/kernel/interfaces/IWatcherListener.h + src/base/kernel/Process.h + src/base/kernel/Signals.h + src/base/net/dns/Dns.h + src/base/net/dns/DnsRecord.h + src/base/net/stratum/Client.h + src/base/net/stratum/Job.h + src/base/net/stratum/Pool.h + src/base/net/stratum/Pools.h + src/base/net/stratum/strategies/FailoverStrategy.h + src/base/net/stratum/strategies/SinglePoolStrategy.h + src/base/net/stratum/SubmitResult.h + src/base/net/tools/RecvBuf.h + src/base/net/tools/Storage.h + src/base/tools/Arguments.h + src/base/tools/Buffer.h + src/base/tools/Chrono.h + src/base/tools/Handle.h + src/base/tools/String.h + ) + +set(SOURCES_BASE + src/base/io/Console.cpp + src/base/io/Json.cpp + src/base/io/Watcher.cpp + src/base/kernel/Entry.cpp + src/base/kernel/Process.cpp + src/base/kernel/Signals.cpp + src/base/net/dns/Dns.cpp + src/base/net/dns/DnsRecord.cpp + src/base/net/stratum/Client.cpp + src/base/net/stratum/Job.cpp + src/base/net/stratum/Pool.cpp + src/base/net/stratum/Pools.cpp + src/base/net/stratum/strategies/FailoverStrategy.cpp + src/base/net/stratum/strategies/SinglePoolStrategy.cpp + src/base/tools/Arguments.cpp + src/base/tools/Buffer.cpp + src/base/tools/String.cpp + ) + + +if (WIN32) + set(SOURCES_OS src/base/io/Json_win.cpp) +else() + set(SOURCES_OS src/base/io/Json_unix.cpp) +endif() diff --git a/src/common/Console.cpp b/src/base/io/Console.cpp similarity index 96% rename from src/common/Console.cpp rename to src/base/io/Console.cpp index 8e5d7285d..cb23c4b08 100644 --- a/src/common/Console.cpp +++ b/src/base/io/Console.cpp @@ -23,9 +23,9 @@ */ +#include "base/io/Console.h" +#include "base/kernel/interfaces/IConsoleListener.h" #include "base/tools/Handle.h" -#include "common/Console.h" -#include "interfaces/IConsoleListener.h" xmrig::Console::Console(IConsoleListener *listener) diff --git a/src/common/Console.h b/src/base/io/Console.h similarity index 100% rename from src/common/Console.h rename to src/base/io/Console.h diff --git a/src/common/interfaces/IConsoleListener.h b/src/base/kernel/interfaces/IConsoleListener.h similarity index 100% rename from src/common/interfaces/IConsoleListener.h rename to src/base/kernel/interfaces/IConsoleListener.h diff --git a/src/common/utils/c_str.h b/src/common/utils/c_str.h deleted file mode 100644 index fe0164b9e..000000000 --- a/src/common/utils/c_str.h +++ /dev/null @@ -1,39 +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 XMRIG_C_STR_H -#define XMRIG_C_STR_H - - -#include "base/tools/String.h" - - -namespace xmrig { - - -typedef String c_str; - - -} /* namespace xmrig */ - -#endif /* XMRIG_C_STR_H */ diff --git a/src/common/utils/timestamp.h b/src/common/utils/timestamp.h deleted file mode 100644 index 7fc4ab503..000000000 --- a/src/common/utils/timestamp.h +++ /dev/null @@ -1,55 +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 XMRIG_TIMESTAMP_H -#define XMRIG_TIMESTAMP_H - - -#include - - -namespace xmrig { - - -static inline int64_t steadyTimestamp() -{ - using namespace std::chrono; - if (high_resolution_clock::is_steady) { - return time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); - } - - return time_point_cast(steady_clock::now()).time_since_epoch().count(); -} - - -static inline int64_t currentMSecsSinceEpoch() -{ - using namespace std::chrono; - - return time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); -} - - -} /* namespace xmrig */ - -#endif /* XMRIG_TIMESTAMP_H */ From 1b9fbf11324a0188d631f975de11bceab1b7d83d Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 16 Mar 2019 13:10:04 +0700 Subject: [PATCH 48/55] Fix compile issues. --- src/base/net/stratum/Client.cpp | 4 ++-- src/base/net/stratum/Pools.cpp | 4 ++-- src/base/net/stratum/Tls.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 0693afb74..ab4b934d3 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -261,7 +261,7 @@ int64_t xmrig::Client::submit(const JobResult &result) void xmrig::Client::onResolved(const Dns &dns, int status) { - assert(client->m_listener != nullptr); + assert(m_listener != nullptr); if (!m_listener) { return reconnect(); } @@ -846,7 +846,7 @@ void xmrig::Client::read(ssize_t nread) return; } - assert(client->m_listener != nullptr); + assert(m_listener != nullptr); if (!m_listener) { return reconnect(); } diff --git a/src/base/net/stratum/Pools.cpp b/src/base/net/stratum/Pools.cpp index ba55e94b1..7a738cf02 100644 --- a/src/base/net/stratum/Pools.cpp +++ b/src/base/net/stratum/Pools.cpp @@ -164,7 +164,7 @@ void xmrig::Pools::print() const Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m variant " WHITE_BOLD("%s"), i, color, - pool.url(), + pool.url().data(), pool.algorithm().variantName() ); } @@ -172,7 +172,7 @@ void xmrig::Pools::print() const Log::i()->text(" * POOL #%-7zu%s%s variant=%s %s", i, pool.isEnabled() ? "" : "-", - pool.url(), + pool.url().data(), pool.algorithm().variantName(), pool.isTLS() ? "TLS" : "" ); diff --git a/src/base/net/stratum/Tls.cpp b/src/base/net/stratum/Tls.cpp index e96d9946e..d92d7e547 100644 --- a/src/base/net/stratum/Tls.cpp +++ b/src/base/net/stratum/Tls.cpp @@ -150,13 +150,13 @@ bool xmrig::Client::Tls::send() bool xmrig::Client::Tls::verify(X509 *cert) { if (cert == nullptr) { - LOG_ERR("[%s] Failed to get server certificate", m_client->m_pool.url()); + LOG_ERR("[%s] Failed to get server certificate", m_client->url()); return false; } if (!verifyFingerprint(cert)) { - LOG_ERR("[%s] Failed to verify server certificate fingerprint", m_client->m_pool.url()); + LOG_ERR("[%s] Failed to verify server certificate fingerprint", m_client->url()); const char *fingerprint = m_client->m_pool.fingerprint(); if (strlen(m_fingerprint) == 64 && fingerprint != nullptr) { From c94c0210f74f48a5a634d4df35de11a7ddf61384 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 16 Mar 2019 13:32:00 +0700 Subject: [PATCH 49/55] Fix copy. --- src/base/tools/String.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/base/tools/String.cpp b/src/base/tools/String.cpp index 7ed61d01f..9884f0aca 100644 --- a/src/base/tools/String.cpp +++ b/src/base/tools/String.cpp @@ -178,14 +178,10 @@ void xmrig::String::copy(const char *str) void xmrig::String::copy(const String &other) { - if (m_size > 0) { - if (m_size == other.m_size) { - memcpy(m_data, other.m_data, m_size + 1); + if (m_size > 0 && m_size == other.m_size) { + memcpy(m_data, other.m_data, m_size + 1); - return; - } - - delete [] m_data; + return; } delete [] m_data; From bbf0d11a513bd66dbc99fc66231c058de0780571 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 17 Mar 2019 16:03:45 +0700 Subject: [PATCH 50/55] Sync changes. --- src/base/kernel/Process.cpp | 3 --- src/base/tools/Handle.h | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/base/kernel/Process.cpp b/src/base/kernel/Process.cpp index 7feec4810..0bc40e2da 100644 --- a/src/base/kernel/Process.cpp +++ b/src/base/kernel/Process.cpp @@ -28,7 +28,6 @@ #include "base/kernel/Process.h" -#include "version.h" static size_t location(xmrig::Process::Location location, char *buf, size_t max) @@ -52,8 +51,6 @@ xmrig::Process::Process(int argc, char **argv) : m_arguments(argc, argv) { srand(static_cast(static_cast(time(nullptr)) ^ reinterpret_cast(this))); - - uv_set_process_title(APP_DESC " " APP_VERSION); } diff --git a/src/base/tools/Handle.h b/src/base/tools/Handle.h index 980d4500a..288c32de9 100644 --- a/src/base/tools/Handle.h +++ b/src/base/tools/Handle.h @@ -47,6 +47,10 @@ public: template static inline void deleteLater(T handle) { + if (uv_is_closing(reinterpret_cast(handle))) { + return; + } + uv_close(reinterpret_cast(handle), [](uv_handle_t *handle) { delete handle; }); } }; From 9a6a5a94b5d2da0710d0d27ead53fabc8a59c861 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 18 Mar 2019 02:36:17 +0700 Subject: [PATCH 51/55] Add class Timer. --- src/App.h | 4 +- src/base/base.cmake | 3 + src/base/io/Watcher.cpp | 22 ++--- src/base/io/Watcher.h | 14 ++-- src/base/kernel/interfaces/ITimerListener.h | 47 +++++++++++ src/base/tools/String.cpp | 1 + src/base/tools/String.h | 3 +- src/base/tools/Timer.cpp | 91 +++++++++++++++++++++ src/base/tools/Timer.h | 66 +++++++++++++++ src/common/api/Httpd.cpp | 37 ++++----- src/common/api/Httpd.h | 31 ++++--- src/net/Network.cpp | 15 +--- src/net/Network.h | 10 +-- 13 files changed, 271 insertions(+), 73 deletions(-) create mode 100644 src/base/kernel/interfaces/ITimerListener.h create mode 100644 src/base/tools/Timer.cpp create mode 100644 src/base/tools/Timer.h diff --git a/src/App.h b/src/App.h index 21e57725f..86f281e89 100644 --- a/src/App.h +++ b/src/App.h @@ -31,14 +31,12 @@ #include "base/kernel/interfaces/ISignalListener.h" -class Httpd; - - namespace xmrig { class Console; class Controller; +class Httpd; class Network; class Process; class Signals; diff --git a/src/base/base.cmake b/src/base/base.cmake index 79181f05f..08d868053 100644 --- a/src/base/base.cmake +++ b/src/base/base.cmake @@ -11,6 +11,7 @@ set(HEADERS_BASE src/base/kernel/interfaces/ISignalListener.h src/base/kernel/interfaces/IStrategy.h src/base/kernel/interfaces/IStrategyListener.h + src/base/kernel/interfaces/ITimerListener.h src/base/kernel/interfaces/IWatcherListener.h src/base/kernel/Process.h src/base/kernel/Signals.h @@ -30,6 +31,7 @@ set(HEADERS_BASE src/base/tools/Chrono.h src/base/tools/Handle.h src/base/tools/String.h + src/base/tools/Timer.h ) set(SOURCES_BASE @@ -50,6 +52,7 @@ set(SOURCES_BASE src/base/tools/Arguments.cpp src/base/tools/Buffer.cpp src/base/tools/String.cpp + src/base/tools/Timer.cpp ) diff --git a/src/base/io/Watcher.cpp b/src/base/io/Watcher.cpp index b8ea4c3b9..f5ce9647a 100644 --- a/src/base/io/Watcher.cpp +++ b/src/base/io/Watcher.cpp @@ -29,37 +29,31 @@ #include "base/kernel/interfaces/IWatcherListener.h" #include "base/io/Watcher.h" #include "base/tools/Handle.h" +#include "base/tools/Timer.h" xmrig::Watcher::Watcher(const String &path, IWatcherListener *listener) : m_listener(listener), m_path(path) { + m_timer = new Timer(this); + m_fsEvent = new uv_fs_event_t; + m_fsEvent->data = this; uv_fs_event_init(uv_default_loop(), m_fsEvent); - m_timer = new uv_timer_t; - uv_timer_init(uv_default_loop(), m_timer); - - m_fsEvent->data = m_timer->data = this; - start(); } xmrig::Watcher::~Watcher() { - Handle::close(m_timer); + delete m_timer; + Handle::close(m_fsEvent); } -void xmrig::Watcher::onTimer(uv_timer_t *handle) -{ - static_cast(handle->data)->reload(); -} - - void xmrig::Watcher::onFsEvent(uv_fs_event_t *handle, const char *filename, int, int) { if (!filename) { @@ -72,8 +66,8 @@ void xmrig::Watcher::onFsEvent(uv_fs_event_t *handle, const char *filename, int, void xmrig::Watcher::queueUpdate() { - uv_timer_stop(m_timer); - uv_timer_start(m_timer, xmrig::Watcher::onTimer, kDelay, 0); + m_timer->stop(); + m_timer->start(kDelay, 0); } diff --git a/src/base/io/Watcher.h b/src/base/io/Watcher.h index 4fec4c687..6438cb7a2 100644 --- a/src/base/io/Watcher.h +++ b/src/base/io/Watcher.h @@ -26,30 +26,33 @@ #define XMRIG_WATCHER_H +#include "base/kernel/interfaces/ITimerListener.h" #include "base/tools/String.h" typedef struct uv_fs_event_s uv_fs_event_t; -typedef struct uv_timer_s uv_timer_t; namespace xmrig { class IWatcherListener; +class Timer; -class Watcher +class Watcher : public ITimerListener { public: Watcher(const String &path, IWatcherListener *listener); - ~Watcher(); + ~Watcher() override; + +protected: + inline void onTimer(const Timer *) override { reload(); } private: constexpr static int kDelay = 500; static void onFsEvent(uv_fs_event_t *handle, const char *filename, int events, int status); - static void onTimer(uv_timer_t *handle); void queueUpdate(); void reload(); @@ -57,11 +60,12 @@ private: IWatcherListener *m_listener; String m_path; + Timer *m_timer; uv_fs_event_t *m_fsEvent; - uv_timer_t *m_timer; }; } /* namespace xmrig */ + #endif /* XMRIG_WATCHER_H */ diff --git a/src/base/kernel/interfaces/ITimerListener.h b/src/base/kernel/interfaces/ITimerListener.h new file mode 100644 index 000000000..1b6337d63 --- /dev/null +++ b/src/base/kernel/interfaces/ITimerListener.h @@ -0,0 +1,47 @@ +/* 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-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 . + */ + +#ifndef XMRIG_ITIMERLISTENER_H +#define XMRIG_ITIMERLISTENER_H + + +namespace xmrig { + + +class Timer; + + +class ITimerListener +{ +public: + virtual ~ITimerListener() = default; + + virtual void onTimer(const Timer *timer) = 0; +}; + + +} /* namespace xmrig */ + + +#endif // XMRIG_ITIMERLISTENER_H diff --git a/src/base/tools/String.cpp b/src/base/tools/String.cpp index 9884f0aca..c908fe9a9 100644 --- a/src/base/tools/String.cpp +++ b/src/base/tools/String.cpp @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * 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 diff --git a/src/base/tools/String.h b/src/base/tools/String.h index 0c191dfde..a640469a1 100644 --- a/src/base/tools/String.h +++ b/src/base/tools/String.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * 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 diff --git a/src/base/tools/Timer.cpp b/src/base/tools/Timer.cpp new file mode 100644 index 000000000..d06df1636 --- /dev/null +++ b/src/base/tools/Timer.cpp @@ -0,0 +1,91 @@ +/* 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-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 "base/kernel/interfaces/ITimerListener.h" +#include "base/tools/Handle.h" +#include "base/tools/Timer.h" + + +xmrig::Timer::Timer(ITimerListener *listener) : + m_listener(listener), + m_timer(nullptr) +{ + init(); +} + + +xmrig::Timer::Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat) : + m_listener(listener), + m_timer(nullptr) +{ + init(); + start(timeout, repeat); +} + + +xmrig::Timer::~Timer() +{ + Handle::close(m_timer); +} + + +uint64_t xmrig::Timer::repeat() const +{ + return uv_timer_get_repeat(m_timer); +} + + +void xmrig::Timer::setRepeat(uint64_t repeat) +{ + uv_timer_set_repeat(m_timer, repeat); +} + + +void xmrig::Timer::start(uint64_t timeout, uint64_t repeat) +{ + uv_timer_start(m_timer, onTimer, timeout, repeat); +} + + +void xmrig::Timer::stop() +{ + uv_timer_stop(m_timer); +} + + +void xmrig::Timer::init() +{ + m_timer = new uv_timer_t; + m_timer->data = this; + uv_timer_init(uv_default_loop(), m_timer); +} + + +void xmrig::Timer::onTimer(uv_timer_t *handle) +{ + const Timer *timer = static_cast(handle->data); + + timer->m_listener->onTimer(timer); +} diff --git a/src/base/tools/Timer.h b/src/base/tools/Timer.h new file mode 100644 index 000000000..e0e210f52 --- /dev/null +++ b/src/base/tools/Timer.h @@ -0,0 +1,66 @@ +/* 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-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 . + */ + +#ifndef XMRIG_TIMER_H +#define XMRIG_TIMER_H + + +#include + + +typedef struct uv_timer_s uv_timer_t; + + +namespace xmrig { + + +class ITimerListener; + + +class Timer +{ +public: + Timer(ITimerListener *listener); + Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat); + ~Timer(); + + uint64_t repeat() const; + void setRepeat(uint64_t repeat); + void start(uint64_t timeout, uint64_t repeat); + void stop(); + +private: + void init(); + + static void onTimer(uv_timer_t *handle); + + ITimerListener *m_listener; + uv_timer_t *m_timer; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_TIMER_H */ diff --git a/src/common/api/Httpd.cpp b/src/common/api/Httpd.cpp index cca2b056f..7b5e8578d 100644 --- a/src/common/api/Httpd.cpp +++ b/src/common/api/Httpd.cpp @@ -29,13 +29,14 @@ #include "api/Api.h" #include "base/tools/Handle.h" +#include "base/tools/Timer.h" #include "common/api/Httpd.h" #include "common/api/HttpReply.h" #include "common/api/HttpRequest.h" #include "common/log/Log.h" -Httpd::Httpd(int port, const char *accessToken, bool IPv6, bool restricted) : +xmrig::Httpd::Httpd(int port, const char *accessToken, bool IPv6, bool restricted) : m_idle(true), m_IPv6(IPv6), m_restricted(restricted), @@ -43,13 +44,11 @@ Httpd::Httpd(int port, const char *accessToken, bool IPv6, bool restricted) : m_port(port), m_daemon(nullptr) { - m_timer = new uv_timer_t; - uv_timer_init(uv_default_loop(), m_timer); - m_timer->data = this; + m_timer = new Timer(this); } -Httpd::~Httpd() +xmrig::Httpd::~Httpd() { stop(); @@ -61,7 +60,7 @@ Httpd::~Httpd() } -bool Httpd::start() +bool xmrig::Httpd::start() { if (!m_port) { return false; @@ -85,23 +84,23 @@ bool Httpd::start() } # if MHD_VERSION >= 0x00093900 - uv_timer_start(m_timer, Httpd::onTimer, kIdleInterval, kIdleInterval); + m_timer->start(kIdleInterval, kIdleInterval); # else - uv_timer_start(m_timer, Httpd::onTimer, kActiveInterval, kActiveInterval); + m_timer->start(kActiveInterval, kActiveInterval); # endif return true; } -void Httpd::stop() +void xmrig::Httpd::stop() { - xmrig::Handle::close(m_timer); + delete m_timer; m_timer = nullptr; } -int Httpd::process(xmrig::HttpRequest &req) +int xmrig::Httpd::process(HttpRequest &req) { xmrig::HttpReply reply; if (!req.process(m_accessToken, m_restricted, reply)) { @@ -118,27 +117,27 @@ int Httpd::process(xmrig::HttpRequest &req) } -void Httpd::run() +void xmrig::Httpd::run() { MHD_run(m_daemon); # if MHD_VERSION >= 0x00093900 const MHD_DaemonInfo *info = MHD_get_daemon_info(m_daemon, MHD_DAEMON_INFO_CURRENT_CONNECTIONS); if (m_idle && info->num_connections) { - uv_timer_set_repeat(m_timer, kActiveInterval); + m_timer->setRepeat(kActiveInterval); m_idle = false; } else if (!m_idle && !info->num_connections) { - uv_timer_set_repeat(m_timer, kIdleInterval); + m_timer->setRepeat(kIdleInterval); m_idle = true; } # endif } -int Httpd::handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *uploadData, size_t *uploadSize, void **con_cls) +int xmrig::Httpd::handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *, const char *uploadData, size_t *uploadSize, void **con_cls) { - xmrig::HttpRequest req(connection, url, method, uploadData, uploadSize, con_cls); + HttpRequest req(connection, url, method, uploadData, uploadSize, con_cls); if (req.method() == xmrig::HttpRequest::Options) { return req.end(MHD_HTTP_OK, nullptr); @@ -150,9 +149,3 @@ int Httpd::handler(void *cls, struct MHD_Connection *connection, const char *url return static_cast(cls)->process(req); } - - -void Httpd::onTimer(uv_timer_t *handle) -{ - static_cast(handle->data)->run(); -} diff --git a/src/common/api/Httpd.h b/src/common/api/Httpd.h index 82ca15416..f0b6ce872 100644 --- a/src/common/api/Httpd.h +++ b/src/common/api/Httpd.h @@ -26,7 +26,10 @@ #define XMRIG_HTTPD_H -#include +#include + + +#include "base/kernel/interfaces/ITimerListener.h" struct MHD_Connection; @@ -34,31 +37,33 @@ struct MHD_Daemon; struct MHD_Response; -class UploadCtx; - - namespace xmrig { - class HttpRequest; -} -class Httpd +class HttpRequest; +class Timer; + + +class Httpd : public ITimerListener { public: Httpd(int port, const char *accessToken, bool IPv6, bool restricted); - ~Httpd(); + ~Httpd() override; + bool start(); void stop(); +protected: + void onTimer(const Timer *) override { run(); } + private: constexpr static const int kIdleInterval = 200; constexpr static const int kActiveInterval = 25; - int process(xmrig::HttpRequest &req); + int process(HttpRequest &req); void run(); static int handler(void *cls, MHD_Connection *connection, const char *url, const char *method, const char *version, const char *uploadData, size_t *uploadSize, void **con_cls); - static void onTimer(uv_timer_t *handle); bool m_idle; bool m_IPv6; @@ -66,7 +71,11 @@ private: const char *m_accessToken; const int m_port; MHD_Daemon *m_daemon; - uv_timer_t *m_timer; + Timer *m_timer; }; + +} /* namespace xmrig */ + + #endif /* XMRIG_HTTPD_H */ diff --git a/src/net/Network.cpp b/src/net/Network.cpp index efadb365d..61f6080b6 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -35,7 +35,7 @@ #include "base/net/stratum/Client.h" #include "base/net/stratum/SubmitResult.h" #include "base/tools/Chrono.h" -#include "base/tools/Handle.h" +#include "base/tools/Timer.h" #include "common/log/Log.h" #include "core/Config.h" #include "core/Controller.h" @@ -58,16 +58,13 @@ xmrig::Network::Network(Controller *controller) : m_donate = new DonateStrategy(controller->config()->donateLevel(), pools.data().front().user(), controller->config()->algorithm().algo(), this); } - m_timer = new uv_timer_t; - m_timer->data = this; - uv_timer_init(uv_default_loop(), m_timer); - uv_timer_start(m_timer, Network::onTick, kTickInterval, kTickInterval); + m_timer = new Timer(this, kTickInterval, kTickInterval); } xmrig::Network::~Network() { - Handle::close(m_timer); + delete m_timer; if (m_donate) { delete m_donate; @@ -215,9 +212,3 @@ void xmrig::Network::tick() Api::tick(m_state); # endif } - - -void xmrig::Network::onTick(uv_timer_t *handle) -{ - static_cast(handle->data)->tick(); -} diff --git a/src/net/Network.h b/src/net/Network.h index e83e60e22..8afc54924 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -27,11 +27,11 @@ #include -#include #include "api/NetworkState.h" #include "base/kernel/interfaces/IStrategyListener.h" +#include "base/kernel/interfaces/ITimerListener.h" #include "common/interfaces/IControllerListener.h" #include "interfaces/IJobResultListener.h" @@ -43,7 +43,7 @@ class Controller; class IStrategy; -class Network : public IJobResultListener, public IStrategyListener, public IControllerListener +class Network : public IJobResultListener, public IStrategyListener, public IControllerListener, public ITimerListener { public: Network(Controller *controller); @@ -52,6 +52,8 @@ public: void connect(); protected: + inline void onTimer(const Timer *) override { tick(); } + void onActive(IStrategy *strategy, Client *client) override; void onConfigChanged(Config *config, Config *previousConfig) override; void onJob(IStrategy *strategy, Client *client, const Job &job) override; @@ -66,12 +68,10 @@ private: void setJob(Client *client, const Job &job, bool donate); void tick(); - static void onTick(uv_timer_t *handle); - IStrategy *m_donate; IStrategy *m_strategy; NetworkState m_state; - uv_timer_t *m_timer; + Timer *m_timer; }; From 55686c7d57a7a7213f89b3aca8ae34ba769a9c21 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 18 Mar 2019 13:40:56 +0700 Subject: [PATCH 52/55] Use new Timer inside DonateStrategy. --- src/base/kernel/Process.cpp | 3 +- src/net/strategies/DonateStrategy.cpp | 55 +++++++++++++-------------- src/net/strategies/DonateStrategy.h | 6 ++- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/base/kernel/Process.cpp b/src/base/kernel/Process.cpp index 0bc40e2da..9193d378e 100644 --- a/src/base/kernel/Process.cpp +++ b/src/base/kernel/Process.cpp @@ -28,6 +28,7 @@ #include "base/kernel/Process.h" +#include "base/tools/Chrono.h" static size_t location(xmrig::Process::Location location, char *buf, size_t max) @@ -50,7 +51,7 @@ static size_t location(xmrig::Process::Location location, char *buf, size_t max) xmrig::Process::Process(int argc, char **argv) : m_arguments(argc, argv) { - srand(static_cast(static_cast(time(nullptr)) ^ reinterpret_cast(this))); + srand(static_cast(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast(this))); } diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 7d08fb338..11fca39b8 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -28,22 +28,25 @@ #include "base/net/stratum/strategies/FailoverStrategy.h" #include "base/net/stratum/strategies/SinglePoolStrategy.h" #include "base/tools/Buffer.h" -#include "base/tools/Handle.h" +#include "base/tools/Timer.h" #include "common/crypto/keccak.h" #include "common/Platform.h" #include "common/xmrig.h" #include "net/strategies/DonateStrategy.h" -static inline float randomf(float min, float max) { - return (max - min) * ((((float) rand()) / (float) RAND_MAX)) + min; -} +namespace xmrig { + +static inline double randomf(double min, double max) { return (max - min) * (((static_cast(rand())) / static_cast(RAND_MAX))) + min; } +static inline uint64_t random(uint64_t base, double min, double max) { return static_cast(base * randomf(min, max)); } + +} /* namespace xmrig */ xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IStrategyListener *listener) : m_active(false), - m_donateTime(level * 60 * 1000), - m_idleTime((100 - level) * 60 * 1000), + m_donateTime(static_cast(level) * 60 * 1000), + m_idleTime((100 - static_cast(level)) * 60 * 1000), m_strategy(nullptr), m_listener(listener), m_now(0), @@ -55,7 +58,7 @@ xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IS keccak(reinterpret_cast(user), strlen(user), hash); Buffer::toHex(hash, 32, userId); -# ifndef XMRIG_NO_TLS +# ifdef XMRIG_FEATURE_TLS m_pools.push_back(Pool("donate.ssl.xmrig.com", 443, userId, nullptr, false, true, true)); # endif @@ -72,17 +75,15 @@ xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IS m_strategy = new SinglePoolStrategy(m_pools.front(), 1, 2, this, true); } - m_timer = new uv_timer_t; - m_timer->data = this; - uv_timer_init(uv_default_loop(), m_timer); + m_timer = new Timer(this); - idle(m_idleTime * randomf(0.5, 1.5)); + idle(random(m_idleTime, 0.5, 1.5)); } xmrig::DonateStrategy::~DonateStrategy() { - Handle::close(m_timer); + delete m_timer; delete m_strategy; } @@ -107,7 +108,7 @@ void xmrig::DonateStrategy::setAlgo(const xmrig::Algorithm &algo) void xmrig::DonateStrategy::stop() { - uv_timer_stop(m_timer); + m_timer->stop(); m_strategy->stop(); } @@ -128,7 +129,7 @@ void xmrig::DonateStrategy::tick(uint64_t now) void xmrig::DonateStrategy::onActive(IStrategy *strategy, Client *client) { if (!isActive()) { - uv_timer_start(m_timer, DonateStrategy::onTimer, m_donateTime, 0); + m_timer->start(m_donateTime, 0); } m_active = true; @@ -155,9 +156,19 @@ void xmrig::DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client } +void xmrig::DonateStrategy::onTimer(const Timer *) +{ + if (!isActive()) { + return connect(); + } + + suspend(); +} + + void xmrig::DonateStrategy::idle(uint64_t timeout) { - uv_timer_start(m_timer, DonateStrategy::onTimer, timeout, 0); + m_timer->start(timeout, 0); } @@ -172,17 +183,5 @@ void xmrig::DonateStrategy::suspend() m_active = false; m_listener->onPause(this); - idle(m_idleTime); -} - - -void xmrig::DonateStrategy::onTimer(uv_timer_t *handle) -{ - auto strategy = static_cast(handle->data); - - if (!strategy->isActive()) { - return strategy->connect(); - } - - strategy->suspend(); + idle(random(m_idleTime, 0.8, 1.2)); } diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index ab898332b..b5ea13c88 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -33,6 +33,7 @@ #include "base/kernel/interfaces/IClientListener.h" #include "base/kernel/interfaces/IStrategy.h" #include "base/kernel/interfaces/IStrategyListener.h" +#include "base/kernel/interfaces/ITimerListener.h" #include "base/net/stratum/Pool.h" @@ -43,7 +44,7 @@ class Client; class IStrategyListener; -class DonateStrategy : public IStrategy, public IStrategyListener +class DonateStrategy : public IStrategy, public IStrategyListener, public ITimerListener { public: DonateStrategy(int level, const char *user, Algo algo, IStrategyListener *listener); @@ -64,6 +65,7 @@ protected: void onJob(IStrategy *strategy, Client *client, const Job &job) override; void onPause(IStrategy *strategy) override; void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override; + void onTimer(const Timer *timer) override; private: void idle(uint64_t timeout); @@ -79,7 +81,7 @@ private: std::vector m_pools; uint64_t m_now; uint64_t m_stop; - uv_timer_t *m_timer; + Timer *m_timer; }; From 0907d1eb0c69521b05b389ac17c376b932ae7bd8 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 19 Mar 2019 00:16:30 +0700 Subject: [PATCH 53/55] Added "donate-over-proxy" option. --- src/Summary.cpp | 8 +- src/api/ApiRouter.cpp | 2 +- src/base/net/stratum/Client.cpp | 5 + src/base/net/stratum/Client.h | 1 + src/base/net/stratum/Pools.cpp | 24 ++++- src/base/net/stratum/Pools.h | 12 +++ src/common/config/CommonConfig.cpp | 10 +- src/common/config/CommonConfig.h | 2 - src/common/interfaces/IConfig.h | 1 + src/config.json | 1 + src/core/Config.cpp | 23 ++--- src/core/ConfigLoader_platform.h | 134 +++++++++++++------------- src/net/Network.cpp | 4 +- src/net/strategies/DonateStrategy.cpp | 117 ++++++++++++++-------- src/net/strategies/DonateStrategy.h | 26 +++-- 15 files changed, 229 insertions(+), 141 deletions(-) diff --git a/src/Summary.cpp b/src/Summary.cpp index 616380197..78d624df4 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -114,8 +114,8 @@ static void print_threads(xmrig::Config *config) config->threadsCount(), config->algorithm().name(), config->algoVariant(), - config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "", - config->donateLevel(), + config->isColors() && config->pools().donateLevel() == 0 ? "\x1B[1;31m" : "", + config->pools().donateLevel(), buf); } else { @@ -124,8 +124,8 @@ static void print_threads(xmrig::Config *config) "THREADS", config->threadsCount(), config->algorithm().name(), - config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "", - config->donateLevel()); + config->isColors() && config->pools().donateLevel() == 0 ? "\x1B[1;31m" : "", + config->pools().donateLevel()); } # ifndef XMRIG_NO_ASM diff --git a/src/api/ApiRouter.cpp b/src/api/ApiRouter.cpp index 5f3b1f634..69ab153c9 100644 --- a/src/api/ApiRouter.cpp +++ b/src/api/ApiRouter.cpp @@ -254,7 +254,7 @@ void ApiRouter::getMiner(rapidjson::Document &doc) const doc.AddMember("cpu", cpu, allocator); doc.AddMember("algo", rapidjson::StringRef(m_controller->config()->algorithm().name()), allocator); doc.AddMember("hugepages", Workers::hugePages() > 0, allocator); - doc.AddMember("donate_level", m_controller->config()->donateLevel(), allocator); + doc.AddMember("donate_level", m_controller->config()->pools().donateLevel(), allocator); } diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index ab4b934d3..d88acfc7a 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -741,6 +741,11 @@ void xmrig::Client::parseExtensions(const rapidjson::Value &result) else if (strcmp(name, "keepalive") == 0) { setExtension(EXT_KEEPALIVE, true); } +# ifdef XMRIG_FEATURE_TLS + else if (strcmp(name, "tls") == 0) { + setExtension(EXT_TLS, true); + } +# endif } } diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index ce2b0276f..e41d01ad2 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -68,6 +68,7 @@ public: EXT_ALGO, EXT_NICEHASH, EXT_CONNECT, + EXT_TLS, EXT_KEEPALIVE, EXT_MAX }; diff --git a/src/base/net/stratum/Pools.cpp b/src/base/net/stratum/Pools.cpp index 7a738cf02..fc132dd5f 100644 --- a/src/base/net/stratum/Pools.cpp +++ b/src/base/net/stratum/Pools.cpp @@ -27,12 +27,15 @@ #include "base/net/stratum/strategies/FailoverStrategy.h" #include "base/net/stratum/strategies/SinglePoolStrategy.h" #include "common/log/Log.h" +#include "donate.h" #include "rapidjson/document.h" xmrig::Pools::Pools() : + m_donateLevel(kDefaultDonateLevel), m_retries(5), - m_retryPause(5) + m_retryPause(5), + m_proxyDonate(PROXY_DONATE_AUTO) { # ifdef XMRIG_PROXY_PROJECT m_retries = 2; @@ -191,6 +194,25 @@ void xmrig::Pools::print() const } +void xmrig::Pools::setDonateLevel(int level) +{ + if (level >= kMinimumDonateLevel && level <= 99) { + m_donateLevel = level; + } +} + + +void xmrig::Pools::setProxyDonate(int value) +{ + switch (value) { + case PROXY_DONATE_NONE: + case PROXY_DONATE_AUTO: + case PROXY_DONATE_ALWAYS: + m_proxyDonate = static_cast(value); + } +} + + void xmrig::Pools::setRetries(int retries) { if (retries > 0 && retries <= 1000) { diff --git a/src/base/net/stratum/Pools.h b/src/base/net/stratum/Pools.h index 0f856c695..f563f243f 100644 --- a/src/base/net/stratum/Pools.h +++ b/src/base/net/stratum/Pools.h @@ -42,12 +42,20 @@ class IStrategyListener; class Pools { public: + enum ProxyDonate { + PROXY_DONATE_NONE, + PROXY_DONATE_AUTO, + PROXY_DONATE_ALWAYS + }; + Pools(); inline bool setUserpass(const char *userpass) { return current().setUserpass(userpass); } inline const std::vector &data() const { return m_data; } + inline int donateLevel() const { return m_donateLevel; } inline int retries() const { return m_retries; } inline int retryPause() const { return m_retryPause; } + inline ProxyDonate proxyDonate() const { return m_proxyDonate; } inline void setFingerprint(const char *fingerprint) { current().setFingerprint(fingerprint); } inline void setKeepAlive(bool enable) { current().setKeepAlive(enable); } inline void setKeepAlive(int keepAlive) { current().setKeepAlive(keepAlive); } @@ -70,14 +78,18 @@ public: void adjust(const Algorithm &algorithm); void load(const rapidjson::Value &pools); void print() const; + void setDonateLevel(int level); + void setProxyDonate(int value); void setRetries(int retries); void setRetryPause(int retryPause); private: Pool ¤t(); + int m_donateLevel; int m_retries; int m_retryPause; + ProxyDonate m_proxyDonate; std::vector m_data; }; diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 36d156a31..94bbd59f7 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -57,7 +57,6 @@ #include "base/io/Json.h" #include "common/config/CommonConfig.h" #include "common/log/Log.h" -#include "donate.h" #include "rapidjson/document.h" #include "rapidjson/filewritestream.h" #include "rapidjson/prettywriter.h" @@ -75,7 +74,6 @@ xmrig::CommonConfig::CommonConfig() : m_syslog(false), m_watch(true), m_apiPort(0), - m_donateLevel(kDefaultDonateLevel), m_printTime(60), m_state(NoneState) { @@ -397,9 +395,11 @@ bool xmrig::CommonConfig::parseInt(int key, int arg) break; case DonateLevelKey: /* --donate-level */ - if (arg >= kMinimumDonateLevel && arg <= 99) { - m_donateLevel = arg; - } + m_pools.setDonateLevel(arg); + break; + + case ProxyDonateKey: /* --donate-over-proxy */ + m_pools.setProxyDonate(arg); break; case ApiPort: /* --api-port */ diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 729c24510..e11069daf 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -53,7 +53,6 @@ public: inline const char *userAgent() const { return m_userAgent.data(); } inline const Pools &pools() const { return m_pools; } inline int apiPort() const { return m_apiPort; } - inline int donateLevel() const { return m_donateLevel; } inline int printTime() const { return m_printTime; } inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } @@ -91,7 +90,6 @@ protected: bool m_syslog; bool m_watch; int m_apiPort; - int m_donateLevel; int m_printTime; Pools m_pools; State m_state; diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 41a2f01c5..e898c24cc 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -69,6 +69,7 @@ public: TlsKey = 1013, FingerprintKey = 1014, AutoSaveKey = 1016, + ProxyDonateKey = 1017, // xmrig common CPUPriorityKey = 1021, diff --git a/src/config.json b/src/config.json index 5018db514..08b912a0b 100644 --- a/src/config.json +++ b/src/config.json @@ -16,6 +16,7 @@ "cpu-affinity": null, "cpu-priority": null, "donate-level": 5, + "donate-over-proxy": 1, "huge-pages": true, "hw-aes": null, "log-file": null, diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 82a961178..d566af263 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -97,17 +97,18 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("cpu-affinity", kNullType, allocator); } - doc.AddMember("cpu-priority", priority() != -1 ? Value(priority()) : Value(kNullType), allocator); - doc.AddMember("donate-level", donateLevel(), allocator); - doc.AddMember("huge-pages", isHugePages(), allocator); - doc.AddMember("hw-aes", m_aesMode == AES_AUTO ? Value(kNullType) : Value(m_aesMode == AES_HW), allocator); - doc.AddMember("log-file", logFile() ? Value(StringRef(logFile())).Move() : Value(kNullType).Move(), allocator); - doc.AddMember("max-cpu-usage", m_maxCpuUsage, allocator); - doc.AddMember("pools", m_pools.toJSON(doc), allocator); - doc.AddMember("print-time", printTime(), allocator); - doc.AddMember("retries", m_pools.retries(), allocator); - doc.AddMember("retry-pause", m_pools.retryPause(), allocator); - doc.AddMember("safe", m_safe, allocator); + doc.AddMember("cpu-priority", priority() != -1 ? Value(priority()) : Value(kNullType), allocator); + doc.AddMember("donate-level", m_pools.donateLevel(), allocator); + doc.AddMember("donate-over-proxy", m_pools.proxyDonate(), allocator); + doc.AddMember("huge-pages", isHugePages(), allocator); + doc.AddMember("hw-aes", m_aesMode == AES_AUTO ? Value(kNullType) : Value(m_aesMode == AES_HW), allocator); + doc.AddMember("log-file", m_logFile.toJSON(), allocator); + doc.AddMember("max-cpu-usage", m_maxCpuUsage, allocator); + doc.AddMember("pools", m_pools.toJSON(doc), allocator); + doc.AddMember("print-time", printTime(), allocator); + doc.AddMember("retries", m_pools.retries(), allocator); + doc.AddMember("retry-pause", m_pools.retryPause(), allocator); + doc.AddMember("safe", m_safe, allocator); if (threadsMode() != Simple) { Value threads(kArrayType); diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index 0b71c3fda..a13983cd5 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -44,81 +44,83 @@ static char const short_options[] = "a:c:kBp:Px:r:R:s:t:T:o:u:O:v:l:S"; static struct option const options[] = { - { "algo", 1, nullptr, xmrig::IConfig::AlgorithmKey }, - { "api-access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey }, - { "api-port", 1, nullptr, xmrig::IConfig::ApiPort }, - { "api-worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey }, - { "api-id", 1, nullptr, xmrig::IConfig::ApiIdKey }, - { "api-ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key }, - { "api-no-restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey }, - { "av", 1, nullptr, xmrig::IConfig::AVKey }, - { "background", 0, nullptr, xmrig::IConfig::BackgroundKey }, - { "config", 1, nullptr, xmrig::IConfig::ConfigKey }, - { "cpu-affinity", 1, nullptr, xmrig::IConfig::CPUAffinityKey }, - { "cpu-priority", 1, nullptr, xmrig::IConfig::CPUPriorityKey }, - { "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey }, - { "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey }, - { "keepalive", 0, nullptr, xmrig::IConfig::KeepAliveKey }, - { "log-file", 1, nullptr, xmrig::IConfig::LogFileKey }, - { "max-cpu-usage", 1, nullptr, xmrig::IConfig::MaxCPUUsageKey }, - { "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey }, - { "no-color", 0, nullptr, xmrig::IConfig::ColorKey }, - { "no-watch", 0, nullptr, xmrig::IConfig::WatchKey }, - { "no-huge-pages", 0, nullptr, xmrig::IConfig::HugePagesKey }, - { "variant", 1, nullptr, xmrig::IConfig::VariantKey }, - { "pass", 1, nullptr, xmrig::IConfig::PasswordKey }, - { "print-time", 1, nullptr, xmrig::IConfig::PrintTimeKey }, - { "retries", 1, nullptr, xmrig::IConfig::RetriesKey }, - { "retry-pause", 1, nullptr, xmrig::IConfig::RetryPauseKey }, - { "safe", 0, nullptr, xmrig::IConfig::SafeKey }, - { "syslog", 0, nullptr, xmrig::IConfig::SyslogKey }, - { "threads", 1, nullptr, xmrig::IConfig::ThreadsKey }, - { "url", 1, nullptr, xmrig::IConfig::UrlKey }, - { "user", 1, nullptr, xmrig::IConfig::UserKey }, - { "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey }, - { "userpass", 1, nullptr, xmrig::IConfig::UserpassKey }, - { "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey }, - { "tls", 0, nullptr, xmrig::IConfig::TlsKey }, - { "tls-fingerprint", 1, nullptr, xmrig::IConfig::FingerprintKey }, - { "asm", 1, nullptr, xmrig::IConfig::AssemblyKey }, + { "algo", 1, nullptr, IConfig::AlgorithmKey }, + { "api-access-token", 1, nullptr, IConfig::ApiAccessTokenKey }, + { "api-port", 1, nullptr, IConfig::ApiPort }, + { "api-worker-id", 1, nullptr, IConfig::ApiWorkerIdKey }, + { "api-id", 1, nullptr, IConfig::ApiIdKey }, + { "api-ipv6", 0, nullptr, IConfig::ApiIPv6Key }, + { "api-no-restricted", 0, nullptr, IConfig::ApiRestrictedKey }, + { "av", 1, nullptr, IConfig::AVKey }, + { "background", 0, nullptr, IConfig::BackgroundKey }, + { "config", 1, nullptr, IConfig::ConfigKey }, + { "cpu-affinity", 1, nullptr, IConfig::CPUAffinityKey }, + { "cpu-priority", 1, nullptr, IConfig::CPUPriorityKey }, + { "donate-level", 1, nullptr, IConfig::DonateLevelKey }, + { "donate-over-proxy", 1, nullptr, IConfig::ProxyDonateKey }, + { "dry-run", 0, nullptr, IConfig::DryRunKey }, + { "keepalive", 0, nullptr, IConfig::KeepAliveKey }, + { "log-file", 1, nullptr, IConfig::LogFileKey }, + { "max-cpu-usage", 1, nullptr, IConfig::MaxCPUUsageKey }, + { "nicehash", 0, nullptr, IConfig::NicehashKey }, + { "no-color", 0, nullptr, IConfig::ColorKey }, + { "no-watch", 0, nullptr, IConfig::WatchKey }, + { "no-huge-pages", 0, nullptr, IConfig::HugePagesKey }, + { "variant", 1, nullptr, IConfig::VariantKey }, + { "pass", 1, nullptr, IConfig::PasswordKey }, + { "print-time", 1, nullptr, IConfig::PrintTimeKey }, + { "retries", 1, nullptr, IConfig::RetriesKey }, + { "retry-pause", 1, nullptr, IConfig::RetryPauseKey }, + { "safe", 0, nullptr, IConfig::SafeKey }, + { "syslog", 0, nullptr, IConfig::SyslogKey }, + { "threads", 1, nullptr, IConfig::ThreadsKey }, + { "url", 1, nullptr, IConfig::UrlKey }, + { "user", 1, nullptr, IConfig::UserKey }, + { "user-agent", 1, nullptr, IConfig::UserAgentKey }, + { "userpass", 1, nullptr, IConfig::UserpassKey }, + { "rig-id", 1, nullptr, IConfig::RigIdKey }, + { "tls", 0, nullptr, IConfig::TlsKey }, + { "tls-fingerprint", 1, nullptr, IConfig::FingerprintKey }, + { "asm", 1, nullptr, IConfig::AssemblyKey }, { nullptr, 0, nullptr, 0 } }; static struct option const config_options[] = { - { "algo", 1, nullptr, xmrig::IConfig::AlgorithmKey }, - { "av", 1, nullptr, xmrig::IConfig::AVKey }, - { "background", 0, nullptr, xmrig::IConfig::BackgroundKey }, - { "colors", 0, nullptr, xmrig::IConfig::ColorKey }, - { "cpu-affinity", 1, nullptr, xmrig::IConfig::CPUAffinityKey }, - { "cpu-priority", 1, nullptr, xmrig::IConfig::CPUPriorityKey }, - { "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey }, - { "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey }, - { "huge-pages", 0, nullptr, xmrig::IConfig::HugePagesKey }, - { "log-file", 1, nullptr, xmrig::IConfig::LogFileKey }, - { "max-cpu-usage", 1, nullptr, xmrig::IConfig::MaxCPUUsageKey }, - { "print-time", 1, nullptr, xmrig::IConfig::PrintTimeKey }, - { "retries", 1, nullptr, xmrig::IConfig::RetriesKey }, - { "retry-pause", 1, nullptr, xmrig::IConfig::RetryPauseKey }, - { "safe", 0, nullptr, xmrig::IConfig::SafeKey }, - { "syslog", 0, nullptr, xmrig::IConfig::SyslogKey }, - { "threads", 1, nullptr, xmrig::IConfig::ThreadsKey }, - { "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey }, - { "watch", 0, nullptr, xmrig::IConfig::WatchKey }, - { "hw-aes", 0, nullptr, xmrig::IConfig::HardwareAESKey }, - { "asm", 1, nullptr, xmrig::IConfig::AssemblyKey }, - { "autosave", 0, nullptr, xmrig::IConfig::AutoSaveKey }, - { nullptr, 0, nullptr, 0 } + { "algo", 1, nullptr, IConfig::AlgorithmKey }, + { "av", 1, nullptr, IConfig::AVKey }, + { "background", 0, nullptr, IConfig::BackgroundKey }, + { "colors", 0, nullptr, IConfig::ColorKey }, + { "cpu-affinity", 1, nullptr, IConfig::CPUAffinityKey }, + { "cpu-priority", 1, nullptr, IConfig::CPUPriorityKey }, + { "donate-level", 1, nullptr, IConfig::DonateLevelKey }, + { "donate-over-proxy", 1, nullptr, IConfig::ProxyDonateKey }, + { "dry-run", 0, nullptr, IConfig::DryRunKey }, + { "huge-pages", 0, nullptr, IConfig::HugePagesKey }, + { "log-file", 1, nullptr, IConfig::LogFileKey }, + { "max-cpu-usage", 1, nullptr, IConfig::MaxCPUUsageKey }, + { "print-time", 1, nullptr, IConfig::PrintTimeKey }, + { "retries", 1, nullptr, IConfig::RetriesKey }, + { "retry-pause", 1, nullptr, IConfig::RetryPauseKey }, + { "safe", 0, nullptr, IConfig::SafeKey }, + { "syslog", 0, nullptr, IConfig::SyslogKey }, + { "threads", 1, nullptr, IConfig::ThreadsKey }, + { "user-agent", 1, nullptr, IConfig::UserAgentKey }, + { "watch", 0, nullptr, IConfig::WatchKey }, + { "hw-aes", 0, nullptr, IConfig::HardwareAESKey }, + { "asm", 1, nullptr, IConfig::AssemblyKey }, + { "autosave", 0, nullptr, IConfig::AutoSaveKey }, + { nullptr, 0, nullptr, 0 } }; static struct option const api_options[] = { - { "port", 1, nullptr, xmrig::IConfig::ApiPort }, - { "access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey }, - { "worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey }, - { "ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key }, - { "restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey }, - { "id", 1, nullptr, xmrig::IConfig::ApiIdKey }, + { "port", 1, nullptr, IConfig::ApiPort }, + { "access-token", 1, nullptr, IConfig::ApiAccessTokenKey }, + { "worker-id", 1, nullptr, IConfig::ApiWorkerIdKey }, + { "ipv6", 0, nullptr, IConfig::ApiIPv6Key }, + { "restricted", 0, nullptr, IConfig::ApiRestrictedKey }, + { "id", 1, nullptr, IConfig::ApiIdKey }, { nullptr, 0, nullptr, 0 } }; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 61f6080b6..f50e3f0ab 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -54,8 +54,8 @@ xmrig::Network::Network(Controller *controller) : const Pools &pools = controller->config()->pools(); m_strategy = pools.createStrategy(this); - if (controller->config()->donateLevel() > 0) { - m_donate = new DonateStrategy(controller->config()->donateLevel(), pools.data().front().user(), controller->config()->algorithm().algo(), this); + if (pools.donateLevel() > 0) { + m_donate = new DonateStrategy(controller, this); } m_timer = new Timer(this, kTickInterval, kTickInterval); diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 11fca39b8..37a9c7c9b 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -23,6 +23,9 @@ */ +#include + + #include "base/net/stratum/Client.h" #include "base/net/stratum/Job.h" #include "base/net/stratum/strategies/FailoverStrategy.h" @@ -32,40 +35,50 @@ #include "common/crypto/keccak.h" #include "common/Platform.h" #include "common/xmrig.h" +#include "core/Config.h" +#include "core/Controller.h" +#include "net/Network.h" #include "net/strategies/DonateStrategy.h" namespace xmrig { -static inline double randomf(double min, double max) { return (max - min) * (((static_cast(rand())) / static_cast(RAND_MAX))) + min; } +static inline double randomf(double min, double max) { return (max - min) * (((static_cast(rand())) / static_cast(RAND_MAX))) + min; } static inline uint64_t random(uint64_t base, double min, double max) { return static_cast(base * randomf(min, max)); } +static const char *kDonateHost = "donate.v2.xmrig.com"; +#ifdef XMRIG_FEATURE_TLS +static const char *kDonateHostTls = "donate.ssl.xmrig.com"; +#endif + } /* namespace xmrig */ -xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IStrategyListener *listener) : - m_active(false), - m_donateTime(static_cast(level) * 60 * 1000), - m_idleTime((100 - static_cast(level)) * 60 * 1000), +xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener *listener) : + m_proxy(nullptr), + m_donateTime(static_cast(controller->config()->pools().donateLevel()) * 60 * 1000), + m_idleTime((100 - static_cast(controller->config()->pools().donateLevel())) * 60 * 1000), + m_controller(controller), m_strategy(nullptr), m_listener(listener), + m_state(STATE_NEW), m_now(0), m_stop(0) { uint8_t hash[200]; char userId[65] = { 0 }; - keccak(reinterpret_cast(user), strlen(user), hash); + const String &user = controller->config()->pools().data().front().user(); + keccak(reinterpret_cast(user.data()), user.size(), hash); Buffer::toHex(hash, 32, userId); # ifdef XMRIG_FEATURE_TLS - m_pools.push_back(Pool("donate.ssl.xmrig.com", 443, userId, nullptr, false, true, true)); + m_pools.push_back(Pool(kDonateHostTls, 443, userId, nullptr, false, true, true)); # endif - - m_pools.push_back(Pool("donate.v2.xmrig.com", 3333, userId, nullptr, false, true)); + m_pools.push_back(Pool(kDonateHost, 3333, userId, nullptr, false, true)); for (Pool &pool : m_pools) { - pool.adjust(Algorithm(algo, VARIANT_AUTO)); + pool.adjust(Algorithm(controller->config()->algorithm().algo(), VARIANT_AUTO)); } if (m_pools.size() > 1) { @@ -77,7 +90,7 @@ xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IS m_timer = new Timer(this); - idle(random(m_idleTime, 0.5, 1.5)); + setState(STATE_IDLE); } @@ -119,20 +132,19 @@ void xmrig::DonateStrategy::tick(uint64_t now) m_strategy->tick(now); - if (m_stop && now > m_stop) { - m_strategy->stop(); - m_stop = 0; + if (state() == STATE_WAIT && now > m_stop) { + setState(STATE_IDLE); } } void xmrig::DonateStrategy::onActive(IStrategy *strategy, Client *client) { - if (!isActive()) { - m_timer->start(m_donateTime, 0); + if (isActive()) { + return; } - m_active = true; + setState(STATE_ACTIVE); m_listener->onActive(this, client); } @@ -158,30 +170,53 @@ void xmrig::DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client void xmrig::DonateStrategy::onTimer(const Timer *) { - if (!isActive()) { - return connect(); + setState(isActive() ? STATE_WAIT : STATE_CONNECT); +} + + +void xmrig::DonateStrategy::idle(double min, double max) +{ + m_timer->start(random(m_idleTime, min, max), 0); +} + + +void xmrig::DonateStrategy::setState(State state) +{ + constexpr const uint64_t waitTime = 3000; + + assert(m_state != state && state != STATE_NEW); + if (m_state == state) { + return; } - suspend(); -} - - -void xmrig::DonateStrategy::idle(uint64_t timeout) -{ - m_timer->start(timeout, 0); -} - - -void xmrig::DonateStrategy::suspend() -{ -# if defined(XMRIG_AMD_PROJECT) || defined(XMRIG_NVIDIA_PROJECT) - m_stop = m_now + 5000; -# else - m_stop = m_now + 500; -# endif - - m_active = false; - m_listener->onPause(this); - - idle(random(m_idleTime, 0.8, 1.2)); + const State prev = m_state; + m_state = state; + + switch (state) { + case STATE_NEW: + break; + + case STATE_IDLE: + if (prev == STATE_NEW) { + idle(0.5, 1.5); + } + else { + m_strategy->stop(); + idle(0.8, 1.2); + } + break; + + case STATE_CONNECT: + connect(); + break; + + case STATE_ACTIVE: + m_timer->start(m_donateTime, 0); + break; + + case STATE_WAIT: + m_stop = m_now + waitTime; + m_listener->onPause(this); + break; + } } diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index b5ea13c88..a06f901f5 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -26,7 +26,6 @@ #define XMRIG_DONATESTRATEGY_H -#include #include @@ -41,17 +40,18 @@ namespace xmrig { class Client; +class Controller; class IStrategyListener; class DonateStrategy : public IStrategy, public IStrategyListener, public ITimerListener { public: - DonateStrategy(int level, const char *user, Algo algo, IStrategyListener *listener); + DonateStrategy(Controller *controller, IStrategyListener *listener); ~DonateStrategy() override; public: - inline bool isActive() const override { return m_active; } + inline bool isActive() const override { return state() == STATE_ACTIVE; } inline void resume() override {} int64_t submit(const JobResult &result) override; @@ -68,20 +68,30 @@ protected: void onTimer(const Timer *timer) override; private: - void idle(uint64_t timeout); - void suspend(); + enum State { + STATE_NEW, + STATE_IDLE, + STATE_CONNECT, + STATE_ACTIVE, + STATE_WAIT + }; - static void onTimer(uv_timer_t *handle); + inline State state() const { return m_state; } - bool m_active; + void idle(double min, double max); + void setState(State state); + + Client *m_proxy; const uint64_t m_donateTime; const uint64_t m_idleTime; + Controller *m_controller; IStrategy *m_strategy; IStrategyListener *m_listener; + State m_state; std::vector m_pools; + Timer *m_timer; uint64_t m_now; uint64_t m_stop; - Timer *m_timer; }; From 4c95136e6ab8435098b33ac67e83ac25a0f12226 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 19 Mar 2019 21:31:54 +0700 Subject: [PATCH 54/55] Implemented donate over proxy. --- src/base/kernel/interfaces/IStrategy.h | 6 +- src/base/net/stratum/Client.cpp | 20 +-- src/base/net/stratum/Client.h | 3 +- .../stratum/strategies/FailoverStrategy.cpp | 14 +- .../net/stratum/strategies/FailoverStrategy.h | 11 +- .../stratum/strategies/SinglePoolStrategy.h | 7 +- src/net/Network.h | 2 + src/net/strategies/DonateStrategy.cpp | 125 +++++++++++++++--- src/net/strategies/DonateStrategy.h | 28 ++-- 9 files changed, 161 insertions(+), 55 deletions(-) diff --git a/src/base/kernel/interfaces/IStrategy.h b/src/base/kernel/interfaces/IStrategy.h index 1e9c19bc4..31798b9c2 100644 --- a/src/base/kernel/interfaces/IStrategy.h +++ b/src/base/kernel/interfaces/IStrategy.h @@ -29,13 +29,12 @@ #include -class JobResult; - - namespace xmrig { class Algorithm; +class Client; +class JobResult; class IStrategy @@ -44,6 +43,7 @@ public: virtual ~IStrategy() = default; virtual bool isActive() const = 0; + virtual Client *client() const = 0; virtual int64_t submit(const JobResult &result) = 0; virtual void connect() = 0; virtual void resume() = 0; diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index d88acfc7a..db6f26636 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -182,6 +182,16 @@ bool xmrig::Client::disconnect() } +bool xmrig::Client::isTLS() const +{ +# ifndef XMRIG_NO_TLS + return m_pool.isTLS() && m_tls; +# else + return false; +# endif +} + + const char *xmrig::Client::tlsFingerprint() const { # ifndef XMRIG_NO_TLS @@ -331,16 +341,6 @@ bool xmrig::Client::isCriticalError(const char *message) } -bool xmrig::Client::isTLS() const -{ -# ifndef XMRIG_NO_TLS - return m_pool.isTLS() && m_tls; -# else - return false; -# endif -} - - bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code) { if (!params.IsObject()) { diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index e41d01ad2..c0ea8a93a 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -85,6 +85,7 @@ public: ~Client() override; bool disconnect(); + bool isTLS() const; const char *tlsFingerprint() const; const char *tlsVersion() const; int64_t submit(const JobResult &result); @@ -99,6 +100,7 @@ public: inline const char *host() const { return m_pool.host(); } inline const char *ip() const { return m_ip; } inline const Job &job() const { return m_job; } + inline const Pool &pool() const { return m_pool; } inline int id() const { return m_id; } inline SocketState state() const { return m_state; } inline uint16_t port() const { return m_pool.port(); } @@ -120,7 +122,6 @@ private: bool close(); bool isCriticalError(const char *message); - bool isTLS() const; bool parseJob(const rapidjson::Value ¶ms, int *code); bool parseLogin(const rapidjson::Value &result, int *code); bool send(BIO *bio); diff --git a/src/base/net/stratum/strategies/FailoverStrategy.cpp b/src/base/net/stratum/strategies/FailoverStrategy.cpp index d2e4a6da3..7a59e2a6e 100644 --- a/src/base/net/stratum/strategies/FailoverStrategy.cpp +++ b/src/base/net/stratum/strategies/FailoverStrategy.cpp @@ -34,8 +34,8 @@ xmrig::FailoverStrategy::FailoverStrategy(const std::vector &pools, int re m_retries(retries), m_retryPause(retryPause), m_active(-1), - m_index(0), - m_listener(listener) + m_listener(listener), + m_index(0) { for (const Pool &pool : pools) { add(pool); @@ -48,8 +48,8 @@ xmrig::FailoverStrategy::FailoverStrategy(int retryPause, int retries, IStrategy m_retries(retries), m_retryPause(retryPause), m_active(-1), - m_index(0), - m_listener(listener) + m_listener(listener), + m_index(0) { } @@ -86,7 +86,7 @@ int64_t xmrig::FailoverStrategy::submit(const JobResult &result) void xmrig::FailoverStrategy::connect() { - m_pools[static_cast(m_index)]->connect(); + m_pools[m_index]->connect(); } @@ -144,8 +144,8 @@ void xmrig::FailoverStrategy::onClose(Client *client, int failures) return; } - if (m_index == client->id() && (m_pools.size() - static_cast(m_index)) > 1) { - m_pools[static_cast(++m_index)]->connect(); + if (m_index == static_cast(client->id()) && (m_pools.size() - m_index) > 1) { + m_pools[++m_index]->connect(); } } diff --git a/src/base/net/stratum/strategies/FailoverStrategy.h b/src/base/net/stratum/strategies/FailoverStrategy.h index 3517de9d1..fcebc52f6 100644 --- a/src/base/net/stratum/strategies/FailoverStrategy.h +++ b/src/base/net/stratum/strategies/FailoverStrategy.h @@ -50,8 +50,10 @@ public: void add(const Pool &pool); -public: - inline bool isActive() const override { return m_active >= 0; } +protected: + inline bool isActive() const override { return m_active >= 0; } + inline Client *client() const override { return active(); } + inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {} int64_t submit(const JobResult &result) override; void connect() override; @@ -60,9 +62,6 @@ public: void stop() override; void tick(uint64_t now) override; -protected: - inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {} - void onClose(Client *client, int failures) override; void onJobReceived(Client *client, const Job &job, const rapidjson::Value ¶ms) override; void onLoginSuccess(Client *client) override; @@ -75,8 +74,8 @@ private: const int m_retries; const int m_retryPause; int m_active; - int m_index; IStrategyListener *m_listener; + size_t m_index; std::vector m_pools; }; diff --git a/src/base/net/stratum/strategies/SinglePoolStrategy.h b/src/base/net/stratum/strategies/SinglePoolStrategy.h index 5b3016c13..8d9f9fd14 100644 --- a/src/base/net/stratum/strategies/SinglePoolStrategy.h +++ b/src/base/net/stratum/strategies/SinglePoolStrategy.h @@ -44,8 +44,10 @@ public: SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); ~SinglePoolStrategy() override; -public: +protected: inline bool isActive() const override { return m_active; } + inline Client *client() const override { return m_client; } + inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {} int64_t submit(const JobResult &result) override; void connect() override; @@ -54,9 +56,6 @@ public: void stop() override; void tick(uint64_t now) override; -protected: - inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {} - void onClose(Client *client, int failures) override; void onJobReceived(Client *client, const Job &job, const rapidjson::Value ¶ms) override; void onLoginSuccess(Client *client) override; diff --git a/src/net/Network.h b/src/net/Network.h index 8afc54924..ac74384e6 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -49,6 +49,8 @@ public: Network(Controller *controller); ~Network() override; + inline IStrategy *strategy() const { return m_strategy; } + void connect(); protected: diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 37a9c7c9b..adfb9a998 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -39,6 +39,7 @@ #include "core/Controller.h" #include "net/Network.h" #include "net/strategies/DonateStrategy.h" +#include "rapidjson/document.h" namespace xmrig { @@ -55,6 +56,8 @@ static const char *kDonateHostTls = "donate.ssl.xmrig.com"; xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener *listener) : + m_tls(false), + m_userId(), m_proxy(nullptr), m_donateTime(static_cast(controller->config()->pools().donateLevel()) * 60 * 1000), m_idleTime((100 - static_cast(controller->config()->pools().donateLevel())) * 60 * 1000), @@ -63,19 +66,18 @@ xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener m_listener(listener), m_state(STATE_NEW), m_now(0), - m_stop(0) + m_timestamp(0) { uint8_t hash[200]; - char userId[65] = { 0 }; const String &user = controller->config()->pools().data().front().user(); keccak(reinterpret_cast(user.data()), user.size(), hash); - Buffer::toHex(hash, 32, userId); + Buffer::toHex(hash, 32, m_userId); # ifdef XMRIG_FEATURE_TLS - m_pools.push_back(Pool(kDonateHostTls, 443, userId, nullptr, false, true, true)); + m_pools.push_back(Pool(kDonateHostTls, 443, m_userId, nullptr, 0, true, true)); # endif - m_pools.push_back(Pool(kDonateHost, 3333, userId, nullptr, false, true)); + m_pools.push_back(Pool(kDonateHost, 3333, m_userId, nullptr, 0, true)); for (Pool &pool : m_pools) { pool.adjust(Algorithm(controller->config()->algorithm().algo(), VARIANT_AUTO)); @@ -98,18 +100,31 @@ xmrig::DonateStrategy::~DonateStrategy() { delete m_timer; delete m_strategy; + + if (m_proxy) { + m_proxy->deleteLater(); + } } int64_t xmrig::DonateStrategy::submit(const JobResult &result) { - return m_strategy->submit(result); + return m_proxy ? m_proxy->submit(result) : m_strategy->submit(result); } void xmrig::DonateStrategy::connect() { - m_strategy->connect(); + m_proxy = createProxy(); + if (m_proxy) { + m_proxy->connect(); + } + else if (m_controller->config()->pools().proxyDonate() == Pools::PROXY_DONATE_ALWAYS) { + setState(STATE_IDLE); + } + else { + m_strategy->connect(); + } } @@ -132,13 +147,17 @@ void xmrig::DonateStrategy::tick(uint64_t now) m_strategy->tick(now); - if (state() == STATE_WAIT && now > m_stop) { + if (m_proxy) { + m_proxy->tick(now); + } + + if (state() == STATE_WAIT && now > m_timestamp) { setState(STATE_IDLE); } } -void xmrig::DonateStrategy::onActive(IStrategy *strategy, Client *client) +void xmrig::DonateStrategy::onActive(IStrategy *, Client *client) { if (isActive()) { return; @@ -149,22 +168,49 @@ void xmrig::DonateStrategy::onActive(IStrategy *strategy, Client *client) } -void xmrig::DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job) +void xmrig::DonateStrategy::onPause(IStrategy *) { - if (isActive()) { - m_listener->onJob(this, client, job); +} + + +void xmrig::DonateStrategy::onClose(Client *, int failures) +{ + if (failures == 2 && m_controller->config()->pools().proxyDonate() == Pools::PROXY_DONATE_AUTO) { + m_proxy->deleteLater(); + m_proxy = nullptr; + + m_strategy->connect(); } } -void xmrig::DonateStrategy::onPause(IStrategy *strategy) +void xmrig::DonateStrategy::onLogin(Client *, rapidjson::Document &doc, rapidjson::Value ¶ms) { + auto &allocator = doc.GetAllocator(); + +# ifdef XMRIG_FEATURE_TLS + if (m_tls) { + char buf[40] = { 0 }; + snprintf(buf, sizeof(buf), "stratum+ssl://%s", m_pools[0].url().data()); + params.AddMember("url", rapidjson::Value(buf, allocator), allocator); + } + else { + params.AddMember("url", m_pools[1].url().toJSON(), allocator); + } +# else + params.AddMember("url", m_pools[0].url().toJSON(), allocator); +# endif } -void xmrig::DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) +void xmrig::DonateStrategy::onLoginSuccess(Client *client) { - m_listener->onResultAccepted(this, client, result, error); + if (isActive()) { + return; + } + + setState(STATE_ACTIVE); + m_listener->onActive(this, client); } @@ -174,12 +220,51 @@ void xmrig::DonateStrategy::onTimer(const Timer *) } +xmrig::Client *xmrig::DonateStrategy::createProxy() +{ + if (m_controller->config()->pools().proxyDonate() == Pools::PROXY_DONATE_NONE) { + return nullptr; + } + + IStrategy *strategy = m_controller->network()->strategy(); + if (!strategy->isActive() || !strategy->client()->has()) { + return nullptr; + } + + const Client *client = strategy->client(); + m_tls = client->has(); + + Pool pool(client->ip(), client->port(), m_userId, client->pool().password(), 0, true, client->isTLS()); + pool.setAlgo(client->pool().algorithm()); + + Client *proxy = new Client(-1, Platform::userAgent(), this); + proxy->setPool(pool); + proxy->setQuiet(true); + + return proxy; +} + + void xmrig::DonateStrategy::idle(double min, double max) { m_timer->start(random(m_idleTime, min, max), 0); } +void xmrig::DonateStrategy::setJob(Client *client, const Job &job) +{ + if (isActive()) { + m_listener->onJob(this, client, job); + } +} + + +void xmrig::DonateStrategy::setResult(Client *client, const SubmitResult &result, const char *error) +{ + m_listener->onResultAccepted(this, client, result, error); +} + + void xmrig::DonateStrategy::setState(State state) { constexpr const uint64_t waitTime = 3000; @@ -200,8 +285,16 @@ void xmrig::DonateStrategy::setState(State state) if (prev == STATE_NEW) { idle(0.5, 1.5); } + else if (prev == STATE_CONNECT) { + m_timer->start(20000, 0); + } else { m_strategy->stop(); + if (m_proxy) { + m_proxy->deleteLater(); + m_proxy = nullptr; + } + idle(0.8, 1.2); } break; @@ -215,7 +308,7 @@ void xmrig::DonateStrategy::setState(State state) break; case STATE_WAIT: - m_stop = m_now + waitTime; + m_timestamp = m_now + waitTime; m_listener->onPause(this); break; } diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index a06f901f5..827596f37 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -44,15 +44,20 @@ class Controller; class IStrategyListener; -class DonateStrategy : public IStrategy, public IStrategyListener, public ITimerListener +class DonateStrategy : public IStrategy, public IStrategyListener, public ITimerListener, public IClientListener { public: DonateStrategy(Controller *controller, IStrategyListener *listener); ~DonateStrategy() override; -public: - inline bool isActive() const override { return state() == STATE_ACTIVE; } - inline void resume() override {} +protected: + inline bool isActive() const override { return state() == STATE_ACTIVE; } + inline Client *client() const override { return m_proxy ? m_proxy : m_strategy->client(); } + inline void onJob(IStrategy *, Client *client, const Job &job) override { setJob(client, job); } + inline void onJobReceived(Client *client, const Job &job, const rapidjson::Value &) override { setJob(client, job); } + inline void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override { setResult(client, result, error); } + inline void onResultAccepted(IStrategy *, Client *client, const SubmitResult &result, const char *error) override { setResult(client, result, error); } + inline void resume() override {} int64_t submit(const JobResult &result) override; void connect() override; @@ -60,11 +65,13 @@ public: void stop() override; void tick(uint64_t now) override; -protected: void onActive(IStrategy *strategy, Client *client) override; - void onJob(IStrategy *strategy, Client *client, const Job &job) override; void onPause(IStrategy *strategy) override; - void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override; + + void onClose(Client *client, int failures) override; + void onLogin(Client *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override; + void onLoginSuccess(Client *client) override; + void onTimer(const Timer *timer) override; private: @@ -78,9 +85,14 @@ private: inline State state() const { return m_state; } + Client *createProxy(); void idle(double min, double max); + void setJob(Client *client, const Job &job); + void setResult(Client *client, const SubmitResult &result, const char *error); void setState(State state); + bool m_tls; + char m_userId[65]; Client *m_proxy; const uint64_t m_donateTime; const uint64_t m_idleTime; @@ -91,7 +103,7 @@ private: std::vector m_pools; Timer *m_timer; uint64_t m_now; - uint64_t m_stop; + uint64_t m_timestamp; }; From 8d61a47040ea3cffccf839c91340d7a606e98b07 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 19 Mar 2019 22:13:43 +0700 Subject: [PATCH 55/55] Fix uv_tty_reset_mode on Linux. --- src/App.cpp | 2 -- src/base/io/Console.cpp | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 500a521d6..db91bab5a 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -68,8 +68,6 @@ xmrig::App::App(Process *process) : xmrig::App::~App() { - uv_tty_reset_mode(); - delete m_signals; delete m_console; delete m_controller; diff --git a/src/base/io/Console.cpp b/src/base/io/Console.cpp index cb23c4b08..0e5cd2696 100644 --- a/src/base/io/Console.cpp +++ b/src/base/io/Console.cpp @@ -53,6 +53,8 @@ xmrig::Console::~Console() void xmrig::Console::stop() { + uv_tty_reset_mode(); + Handle::close(m_tty); m_tty = nullptr; }