Fixed unaligned memory accesses

This commit is contained in:
SChernykh 2022-01-26 15:26:23 +01:00
parent 41a3f97060
commit 644f4cc017
9 changed files with 74 additions and 14 deletions

View file

@ -30,6 +30,7 @@
#include "base/net/stratum/Job.h"
#include "base/tools/Alignment.h"
#include "crypto/common/Nonce.h"
@ -77,7 +78,7 @@ public:
}
else {
for (size_t i = 0; i < N; ++i) {
*nonce(i) += roundSize;
writeUnaligned(nonce(i), readUnaligned(nonce(i)) + roundSize);
}
}
@ -136,11 +137,11 @@ inline bool xmrig::WorkerJob<1>::nextRound(uint32_t rounds, uint32_t roundSize)
return false;
}
if (nonceSize() == sizeof(uint64_t)) {
m_jobs[index()].nonce()[1] = n[1];
writeUnaligned(m_jobs[index()].nonce() + 1, readUnaligned(n + 1));
}
}
else {
*n += roundSize;
writeUnaligned(n, readUnaligned(n) + roundSize);
}
return true;

View file

@ -23,6 +23,7 @@
#include "backend/cpu/Cpu.h"
#include "backend/cpu/CpuWorker.h"
#include "base/tools/Alignment.h"
#include "base/tools/Chrono.h"
#include "core/config/Config.h"
#include "core/Miner.h"
@ -271,7 +272,7 @@ void xmrig::CpuWorker<N>::start()
uint32_t current_job_nonces[N];
for (size_t i = 0; i < N; ++i) {
current_job_nonces[i] = *m_job.nonce(i);
current_job_nonces[i] = readUnaligned(m_job.nonce(i));
}
# ifdef XMRIG_FEATURE_BENCHMARK

View file

@ -22,6 +22,7 @@
#include "backend/cuda/runners/CudaCnRunner.h"
#include "backend/cuda/wrappers/CudaDevice.h"
#include "base/io/log/Log.h"
#include "base/tools/Alignment.h"
#include "base/tools/Chrono.h"
#include "core/Miner.h"
#include "crypto/common/Nonce.h"
@ -152,7 +153,7 @@ void xmrig::CudaWorker::start()
uint32_t foundNonce[16] = { 0 };
uint32_t foundCount = 0;
if (!m_runner->run(*m_job.nonce(), &foundCount, foundNonce)) {
if (!m_runner->run(readUnaligned(m_job.nonce()), &foundCount, foundNonce)) {
return;
}

View file

@ -23,6 +23,7 @@
#include "backend/opencl/runners/tools/OclSharedData.h"
#include "backend/opencl/runners/tools/OclSharedState.h"
#include "base/io/log/Log.h"
#include "base/tools/Alignment.h"
#include "base/tools/Chrono.h"
#include "core/Miner.h"
#include "crypto/common/Nonce.h"
@ -179,7 +180,7 @@ void xmrig::OclWorker::start()
const uint64_t t = Chrono::steadyMSecs();
try {
m_runner->run(*m_job.nonce(), results);
m_runner->run(readUnaligned(m_job.nonce()), results);
}
catch (std::exception &ex) {
printError(id(), ex.what());