diff --git a/src/Mem.cpp b/src/Mem.cpp index 714e35a1d..2c78e10dc 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -24,6 +24,9 @@ */ +#include + + #include "crypto/common/portable/mm_malloc.h" #include "crypto/common/VirtualMemory.h" #include "crypto/CryptoNight_constants.h" @@ -52,13 +55,9 @@ MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count) cryptonight_ctx *c = static_cast(_mm_malloc(sizeof(cryptonight_ctx), 4096)); c->memory = info.memory + (i * cn_select_memory(algorithm)); - uint8_t* p = reinterpret_cast(xmrig::VirtualMemory::allocateExecutableMemory(0x4000)); - c->generated_code = reinterpret_cast(p); - c->generated_code_double = reinterpret_cast(p + 0x2000); - + c->generated_code = reinterpret_cast(xmrig::VirtualMemory::allocateExecutableMemory(0x4000)); c->generated_code_data.variant = xmrig::VARIANT_MAX; - c->generated_code_data.height = (uint64_t)(-1); - c->generated_code_double_data = c->generated_code_data; + c->generated_code_data.height = std::numeric_limits::max(); ctx[i] = c; } diff --git a/src/crypto/CryptoNight.h b/src/crypto/CryptoNight.h index b1ec2371d..f50966ed2 100644 --- a/src/crypto/CryptoNight.h +++ b/src/crypto/CryptoNight.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett + * Copyright 2018-2019 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -30,14 +31,16 @@ #include #if defined _MSC_VER || defined XMRIG_ARM -#define ABI_ATTRIBUTE +# define ABI_ATTRIBUTE #else -#define ABI_ATTRIBUTE __attribute__((ms_abi)) +# define ABI_ATTRIBUTE __attribute__((ms_abi)) #endif + struct cryptonight_ctx; typedef void(*cn_mainloop_fun_ms_abi)(cryptonight_ctx**) ABI_ATTRIBUTE; + struct cryptonight_r_data { int variant; uint64_t height; @@ -45,17 +48,16 @@ struct cryptonight_r_data { bool match(const int v, const uint64_t h) const { return (v == variant) && (h == height); } }; + struct cryptonight_ctx { alignas(16) uint8_t state[224]; alignas(16) uint8_t *memory; uint8_t unused[40]; - const uint32_t* saes_table; + const uint32_t *saes_table; cn_mainloop_fun_ms_abi generated_code; - cn_mainloop_fun_ms_abi generated_code_double; cryptonight_r_data generated_code_data; - cryptonight_r_data generated_code_double_data; }; diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 202b662a2..390f203b1 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -895,12 +895,12 @@ inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_ { constexpr size_t MEM = xmrig::cn_select_memory(); - if (xmrig::cn_is_cryptonight_r() && !ctx[0]->generated_code_double_data.match(VARIANT, height)) { + if (xmrig::cn_is_cryptonight_r() && !ctx[0]->generated_code_data.match(VARIANT, height)) { V4_Instruction code[256]; const int code_size = v4_random_math_init(code, height); - cn_r_compile_code_double(code, code_size, reinterpret_cast(ctx[0]->generated_code_double), ASM); - ctx[0]->generated_code_double_data.variant = VARIANT; - ctx[0]->generated_code_double_data.height = height; + cn_r_compile_code_double(code, code_size, reinterpret_cast(ctx[0]->generated_code), ASM); + ctx[0]->generated_code_data.variant = VARIANT; + ctx[0]->generated_code_data.height = height; } xmrig::keccak(input, size, ctx[0]->state); @@ -928,7 +928,7 @@ inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_ cn_double_double_mainloop_sandybridge_asm(ctx); } else if (xmrig::cn_is_cryptonight_r()) { - ctx[0]->generated_code_double(ctx); + ctx[0]->generated_code(ctx); } cn_implode_scratchpad(reinterpret_cast<__m128i*>(ctx[0]->memory), reinterpret_cast<__m128i*>(ctx[0]->state));