xmrig v6.3.2 merge
This commit is contained in:
commit
651306a57a
25 changed files with 473 additions and 57 deletions
|
@ -51,6 +51,7 @@ static std::mutex mutex;
|
|||
|
||||
xmrig::VirtualMemory::VirtualMemory(size_t size, bool hugePages, bool oneGbPages, bool usePool, uint32_t node, size_t alignSize) :
|
||||
m_size(align(size)),
|
||||
m_capacity(m_size),
|
||||
m_node(node)
|
||||
{
|
||||
if (usePool) {
|
||||
|
@ -69,6 +70,7 @@ xmrig::VirtualMemory::VirtualMemory(size_t size, bool hugePages, bool oneGbPages
|
|||
}
|
||||
|
||||
if (oneGbPages && allocateOneGbPagesMemory()) {
|
||||
m_capacity = align(size, 1ULL << 30);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ public:
|
|||
inline bool isHugePages() const { return m_flags.test(FLAG_HUGEPAGES); }
|
||||
inline bool isOneGbPages() const { return m_flags.test(FLAG_1GB_PAGES); }
|
||||
inline size_t size() const { return m_size; }
|
||||
inline size_t capacity() const { return m_capacity; }
|
||||
inline uint8_t *raw() const { return m_scratchpad; }
|
||||
inline uint8_t *scratchpad() const { return m_scratchpad; }
|
||||
|
||||
|
@ -88,6 +89,7 @@ private:
|
|||
void freeLargePagesMemory();
|
||||
|
||||
const size_t m_size;
|
||||
size_t m_capacity;
|
||||
const uint32_t m_node;
|
||||
std::bitset<FLAG_MAX> m_flags;
|
||||
uint8_t *m_scratchpad = nullptr;
|
||||
|
|
|
@ -82,7 +82,17 @@ void *xmrig::VirtualMemory::allocateLargePagesMemory(size_t size)
|
|||
# elif defined(__FreeBSD__)
|
||||
void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0);
|
||||
# else
|
||||
void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0);
|
||||
|
||||
# if defined(MAP_HUGE_2MB)
|
||||
constexpr int flag_2mb = MAP_HUGE_2MB;
|
||||
# elif defined(MAP_HUGE_SHIFT)
|
||||
constexpr int flag_2mb = (21 << MAP_HUGE_SHIFT);
|
||||
# else
|
||||
constexpr int flag_2mb = 0;
|
||||
# endif
|
||||
|
||||
void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE | flag_2mb, 0, 0);
|
||||
|
||||
# endif
|
||||
|
||||
return mem == MAP_FAILED ? nullptr : mem;
|
||||
|
|
|
@ -108,7 +108,7 @@ namespace randomx {
|
|||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
if (src != dst) {
|
||||
ibc.isrc = &nreg->r[src];
|
||||
ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask);
|
||||
ibc.memMask = AddressMask[instr.getModMem()];
|
||||
}
|
||||
else {
|
||||
ibc.isrc = &zero;
|
||||
|
@ -142,7 +142,7 @@ namespace randomx {
|
|||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
if (src != dst) {
|
||||
ibc.isrc = &nreg->r[src];
|
||||
ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask);
|
||||
ibc.memMask = AddressMask[instr.getModMem()];
|
||||
}
|
||||
else {
|
||||
ibc.isrc = &zero;
|
||||
|
@ -176,7 +176,7 @@ namespace randomx {
|
|||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
if (src != dst) {
|
||||
ibc.isrc = &nreg->r[src];
|
||||
ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask);
|
||||
ibc.memMask = AddressMask[instr.getModMem()];
|
||||
}
|
||||
else {
|
||||
ibc.isrc = &zero;
|
||||
|
@ -204,7 +204,7 @@ namespace randomx {
|
|||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
if (src != dst) {
|
||||
ibc.isrc = &nreg->r[src];
|
||||
ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask);
|
||||
ibc.memMask = AddressMask[instr.getModMem()];
|
||||
}
|
||||
else {
|
||||
ibc.isrc = &zero;
|
||||
|
@ -232,7 +232,7 @@ namespace randomx {
|
|||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
if (src != dst) {
|
||||
ibc.isrc = &nreg->r[src];
|
||||
ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask);
|
||||
ibc.memMask = AddressMask[instr.getModMem()];
|
||||
}
|
||||
else {
|
||||
ibc.isrc = &zero;
|
||||
|
@ -290,7 +290,7 @@ namespace randomx {
|
|||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
if (src != dst) {
|
||||
ibc.isrc = &nreg->r[src];
|
||||
ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask);
|
||||
ibc.memMask = AddressMask[instr.getModMem()];
|
||||
}
|
||||
else {
|
||||
ibc.isrc = &zero;
|
||||
|
@ -373,7 +373,7 @@ namespace randomx {
|
|||
ibc.type = InstructionType::FADD_M;
|
||||
ibc.fdst = &nreg->f[dst];
|
||||
ibc.isrc = &nreg->r[src];
|
||||
ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask);
|
||||
ibc.memMask = AddressMask[instr.getModMem()];
|
||||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
return;
|
||||
}
|
||||
|
@ -393,7 +393,7 @@ namespace randomx {
|
|||
ibc.type = InstructionType::FSUB_M;
|
||||
ibc.fdst = &nreg->f[dst];
|
||||
ibc.isrc = &nreg->r[src];
|
||||
ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask);
|
||||
ibc.memMask = AddressMask[instr.getModMem()];
|
||||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
return;
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ namespace randomx {
|
|||
ibc.type = InstructionType::FDIV_M;
|
||||
ibc.fdst = &nreg->e[dst];
|
||||
ibc.isrc = &nreg->r[src];
|
||||
ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask);
|
||||
ibc.memMask = AddressMask[instr.getModMem()];
|
||||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
return;
|
||||
}
|
||||
|
@ -466,7 +466,7 @@ namespace randomx {
|
|||
ibc.isrc = &nreg->r[src];
|
||||
ibc.imm = signExtend2sCompl(instr.getImm32());
|
||||
if (instr.getModCond() < StoreL3Condition)
|
||||
ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask);
|
||||
ibc.memMask = AddressMask[instr.getModMem()];
|
||||
else
|
||||
ibc.memMask = ScratchpadL3Mask;
|
||||
return;
|
||||
|
|
|
@ -126,10 +126,7 @@ namespace randomx {
|
|||
double hi;
|
||||
};
|
||||
|
||||
#define ScratchpadL1Mask RandomX_CurrentConfig.ScratchpadL1Mask_Calculated
|
||||
#define ScratchpadL1Mask16 RandomX_CurrentConfig.ScratchpadL1Mask16_Calculated
|
||||
#define ScratchpadL2Mask RandomX_CurrentConfig.ScratchpadL2Mask_Calculated
|
||||
#define ScratchpadL2Mask16 RandomX_CurrentConfig.ScratchpadL2Mask16_Calculated
|
||||
#define AddressMask RandomX_CurrentConfig.AddressMask_Calculated
|
||||
#define ScratchpadL3Mask RandomX_CurrentConfig.ScratchpadL3Mask_Calculated
|
||||
#define ScratchpadL3Mask64 RandomX_CurrentConfig.ScratchpadL3Mask64_Calculated
|
||||
constexpr int RegistersCount = 8;
|
||||
|
|
|
@ -414,7 +414,7 @@ FORCE_INLINE void rx_store_vec_f128(double* mem_addr, rx_vec_f128 val) {
|
|||
}
|
||||
|
||||
FORCE_INLINE rx_vec_f128 rx_swap_vec_f128(rx_vec_f128 a) {
|
||||
float64x2_t temp;
|
||||
float64x2_t temp{};
|
||||
temp = vcopyq_laneq_f64(temp, 1, a, 1);
|
||||
a = vcopyq_laneq_f64(a, 1, a, 0);
|
||||
return vcopyq_laneq_f64(a, 0, temp, 1);
|
||||
|
@ -505,7 +505,7 @@ FORCE_INLINE void rx_store_vec_i128(rx_vec_i128* mem_addr, rx_vec_i128 val) {
|
|||
FORCE_INLINE rx_vec_f128 rx_cvt_packed_int_vec_f128(const void* addr) {
|
||||
double lo = unsigned32ToSigned2sCompl(load32((uint8_t*)addr + 0));
|
||||
double hi = unsigned32ToSigned2sCompl(load32((uint8_t*)addr + 4));
|
||||
rx_vec_f128 x;
|
||||
rx_vec_f128 x{};
|
||||
x = vsetq_lane_f64(lo, x, 0);
|
||||
x = vsetq_lane_f64(hi, x, 1);
|
||||
return x;
|
||||
|
|
|
@ -508,7 +508,7 @@ namespace randomx {
|
|||
*(uint32_t*)(code + codePos) = 0xe181;
|
||||
codePos += 2;
|
||||
}
|
||||
emit32(instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask, code, codePos);
|
||||
emit32(AddressMask[instr.getModMem()], code, codePos);
|
||||
}
|
||||
|
||||
template void JitCompilerX86::genAddressReg<false>(const Instruction& instr, const uint32_t src, uint8_t* code, uint32_t& codePos);
|
||||
|
@ -522,7 +522,7 @@ namespace randomx {
|
|||
emit32(instr.getImm32(), code, codePos);
|
||||
emitByte(0x25, code, codePos);
|
||||
if (instr.getModCond() < StoreL3Condition) {
|
||||
emit32(instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask, code, codePos);
|
||||
emit32(AddressMask[instr.getModMem()], code, codePos);
|
||||
}
|
||||
else {
|
||||
emit32(ScratchpadL3Mask, code, codePos);
|
||||
|
|
|
@ -193,18 +193,18 @@ RandomX_ConfigurationBase::RandomX_ConfigurationBase()
|
|||
fillAes4Rx4_Key[6] = rx_set_int_vec_i128(0xf63befa7, 0x2ba9660a, 0xf765a38b, 0xf273c9e7);
|
||||
fillAes4Rx4_Key[7] = rx_set_int_vec_i128(0xc0b0762d, 0x0c06d1fd, 0x915839de, 0x7a7cd609);
|
||||
|
||||
# if defined(_M_X64) || defined(__x86_64__)
|
||||
// Workaround for Visual Studio placing trampoline in debug builds.
|
||||
auto addr = [](void (*func)()) {
|
||||
const uint8_t* p = reinterpret_cast<const uint8_t*>(func);
|
||||
# if defined(_MSC_VER)
|
||||
# if defined(_MSC_VER)
|
||||
if (p[0] == 0xE9) {
|
||||
p += *(const int32_t*)(p + 1) + 5;
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
return p;
|
||||
};
|
||||
|
||||
#if defined(_M_X64) || defined(__x86_64__)
|
||||
{
|
||||
const uint8_t* a = addr(randomx_sshash_prefetch);
|
||||
const uint8_t* b = addr(randomx_sshash_end);
|
||||
|
@ -232,17 +232,21 @@ RandomX_ConfigurationBase::RandomX_ConfigurationBase()
|
|||
const uint8_t* b = addr(randomx_prefetch_scratchpad_end);
|
||||
memcpy(codePrefetchScratchpadTweaked, a, b - a);
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
static uint32_t Log2(size_t value) { return (value > 1) ? (Log2(value / 2) + 1) : 0; }
|
||||
|
||||
void RandomX_ConfigurationBase::Apply()
|
||||
{
|
||||
ScratchpadL1Mask_Calculated = (ScratchpadL1_Size / sizeof(uint64_t) - 1) * 8;
|
||||
ScratchpadL1Mask16_Calculated = (ScratchpadL1_Size / sizeof(uint64_t) / 2 - 1) * 16;
|
||||
ScratchpadL2Mask_Calculated = (ScratchpadL2_Size / sizeof(uint64_t) - 1) * 8;
|
||||
ScratchpadL2Mask16_Calculated = (ScratchpadL2_Size / sizeof(uint64_t) / 2 - 1) * 16;
|
||||
const uint32_t ScratchpadL1Mask_Calculated = (ScratchpadL1_Size / sizeof(uint64_t) - 1) * 8;
|
||||
const uint32_t ScratchpadL2Mask_Calculated = (ScratchpadL2_Size / sizeof(uint64_t) - 1) * 8;
|
||||
|
||||
AddressMask_Calculated[0] = ScratchpadL2Mask_Calculated;
|
||||
AddressMask_Calculated[1] = ScratchpadL1Mask_Calculated;
|
||||
AddressMask_Calculated[2] = ScratchpadL1Mask_Calculated;
|
||||
AddressMask_Calculated[3] = ScratchpadL1Mask_Calculated;
|
||||
|
||||
ScratchpadL3Mask_Calculated = (((ScratchpadL3_Size / sizeof(uint64_t)) - 1) * 8);
|
||||
ScratchpadL3Mask64_Calculated = ((ScratchpadL3_Size / sizeof(uint64_t)) / 8 - 1) * 64;
|
||||
|
||||
|
|
|
@ -130,10 +130,7 @@ struct RandomX_ConfigurationBase
|
|||
uint32_t CacheLineAlignMask_Calculated;
|
||||
uint32_t DatasetExtraItems_Calculated;
|
||||
|
||||
uint32_t ScratchpadL1Mask_Calculated;
|
||||
uint32_t ScratchpadL1Mask16_Calculated;
|
||||
uint32_t ScratchpadL2Mask_Calculated;
|
||||
uint32_t ScratchpadL2Mask16_Calculated;
|
||||
uint32_t AddressMask_Calculated[4];
|
||||
uint32_t ScratchpadL3Mask_Calculated;
|
||||
uint32_t ScratchpadL3Mask64_Calculated;
|
||||
|
||||
|
|
|
@ -193,6 +193,12 @@ void xmrig::RxDataset::allocate(bool hugePages, bool oneGbPages)
|
|||
}
|
||||
|
||||
m_memory = new VirtualMemory(maxSize(), hugePages, oneGbPages, false, m_node);
|
||||
|
||||
if (m_memory->isOneGbPages()) {
|
||||
m_scratchpadOffset = maxSize() + RANDOMX_CACHE_MAX_SIZE;
|
||||
m_scratchpadLimit = m_memory->capacity();
|
||||
}
|
||||
|
||||
m_dataset = randomx_create_dataset(m_memory->raw());
|
||||
|
||||
# ifdef XMRIG_OS_LINUX
|
||||
|
@ -201,3 +207,19 @@ void xmrig::RxDataset::allocate(bool hugePages, bool oneGbPages)
|
|||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
uint8_t* xmrig::RxDataset::tryAllocateScrathpad()
|
||||
{
|
||||
uint8_t* p = reinterpret_cast<uint8_t*>(raw());
|
||||
if (!p) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const size_t offset = m_scratchpadOffset.fetch_add(RANDOMX_SCRATCHPAD_L3_MAX_SIZE);
|
||||
if (offset + RANDOMX_SCRATCHPAD_L3_MAX_SIZE > m_scratchpadLimit) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return p + offset;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
#include "crypto/randomx/randomx.h"
|
||||
#include "crypto/rx/RxConfig.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
|
||||
struct randomx_dataset;
|
||||
|
||||
|
@ -69,6 +71,8 @@ public:
|
|||
void *raw() const;
|
||||
void setRaw(const void *raw);
|
||||
|
||||
uint8_t *tryAllocateScrathpad();
|
||||
|
||||
static inline constexpr size_t maxSize() { return RANDOMX_DATASET_MAX_SIZE; }
|
||||
|
||||
private:
|
||||
|
@ -79,6 +83,9 @@ private:
|
|||
randomx_dataset *m_dataset = nullptr;
|
||||
RxCache *m_cache = nullptr;
|
||||
VirtualMemory *m_memory = nullptr;
|
||||
|
||||
std::atomic<size_t> m_scratchpadOffset;
|
||||
size_t m_scratchpadLimit = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -176,10 +176,16 @@ public:
|
|||
|
||||
inline void initDatasets(uint32_t threads, int priority)
|
||||
{
|
||||
uint64_t ts = Chrono::steadyMSecs();
|
||||
auto id = m_nodeset.front();
|
||||
auto primary = dataset(id);
|
||||
uint64_t ts = Chrono::steadyMSecs();
|
||||
uint32_t id = 0;
|
||||
|
||||
for (const auto &kv : m_datasets) {
|
||||
if (kv.second->cache()) {
|
||||
id = kv.first;
|
||||
}
|
||||
}
|
||||
|
||||
auto primary = dataset(id);
|
||||
primary->init(m_seed.data(), threads, priority);
|
||||
|
||||
printDatasetReady(id, ts);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue