mirror of
https://github.com/xmrig/xmrig.git
synced 2024-10-30 04:57:39 +00:00
fix nonce mask
This commit is contained in:
parent
b826985d05
commit
060c1af4c4
3 changed files with 11 additions and 9 deletions
|
@ -70,7 +70,7 @@ public:
|
||||||
|
|
||||||
if ((m_rounds[index()] % rounds) == 0) {
|
if ((m_rounds[index()] % rounds) == 0) {
|
||||||
for (size_t i = 0; i < N; ++i) {
|
for (size_t i = 0; i < N; ++i) {
|
||||||
if (!Nonce::next(index(), nonce(i), rounds * roundSize, currentJob().isNicehash(), nonceSize())) {
|
if (!Nonce::next(index(), nonce(i), rounds * roundSize, nonceMask())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,7 @@ public:
|
||||||
private:
|
private:
|
||||||
inline int32_t nonceOffset() const { return currentJob().nonceOffset(); }
|
inline int32_t nonceOffset() const { return currentJob().nonceOffset(); }
|
||||||
inline size_t nonceSize() const { return currentJob().nonceSize(); }
|
inline size_t nonceSize() const { return currentJob().nonceSize(); }
|
||||||
|
inline uint64_t nonceMask() const { return m_nonce_mask[index()]; }
|
||||||
|
|
||||||
inline void save(const Job &job, uint32_t reserveCount, Nonce::Backend backend)
|
inline void save(const Job &job, uint32_t reserveCount, Nonce::Backend backend)
|
||||||
{
|
{
|
||||||
|
@ -95,12 +96,13 @@ private:
|
||||||
const size_t size = job.size();
|
const size_t size = job.size();
|
||||||
m_jobs[index()] = job;
|
m_jobs[index()] = job;
|
||||||
m_rounds[index()] = 0;
|
m_rounds[index()] = 0;
|
||||||
|
m_nonce_mask[index()] = job.isNicehash() ? 0xFFFFFFULL : (nonceSize() == sizeof(uint64_t) ? (-1ull >> (job.extraNonce().size() * 4 + 1)): 0xFFFFFFFFULL);
|
||||||
|
|
||||||
m_jobs[index()].setBackend(backend);
|
m_jobs[index()].setBackend(backend);
|
||||||
|
|
||||||
for (size_t i = 0; i < N; ++i) {
|
for (size_t i = 0; i < N; ++i) {
|
||||||
memcpy(m_blobs[index()] + (i * size), job.blob(), size);
|
memcpy(m_blobs[index()] + (i * size), job.blob(), size);
|
||||||
Nonce::next(index(), nonce(i), reserveCount, job.isNicehash(), nonceSize());
|
Nonce::next(index(), nonce(i), reserveCount, nonceMask());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +110,7 @@ private:
|
||||||
alignas(16) uint8_t m_blobs[2][Job::kMaxBlobSize * N]{};
|
alignas(16) uint8_t m_blobs[2][Job::kMaxBlobSize * N]{};
|
||||||
Job m_jobs[2];
|
Job m_jobs[2];
|
||||||
uint32_t m_rounds[2] = { 0, 0 };
|
uint32_t m_rounds[2] = { 0, 0 };
|
||||||
|
uint64_t m_nonce_mask[2];
|
||||||
uint64_t m_sequence = 0;
|
uint64_t m_sequence = 0;
|
||||||
uint8_t m_index = 0;
|
uint8_t m_index = 0;
|
||||||
};
|
};
|
||||||
|
@ -128,7 +131,7 @@ inline bool xmrig::WorkerJob<1>::nextRound(uint32_t rounds, uint32_t roundSize)
|
||||||
uint32_t* n = nonce();
|
uint32_t* n = nonce();
|
||||||
|
|
||||||
if ((m_rounds[index()] % rounds) == 0) {
|
if ((m_rounds[index()] % rounds) == 0) {
|
||||||
if (!Nonce::next(index(), n, rounds * roundSize, currentJob().isNicehash(), nonceSize())) {
|
if (!Nonce::next(index(), n, rounds * roundSize, nonceMask())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (nonceSize() == sizeof(uint64_t)) {
|
if (nonceSize() == sizeof(uint64_t)) {
|
||||||
|
@ -149,11 +152,12 @@ inline void xmrig::WorkerJob<1>::save(const Job &job, uint32_t reserveCount, Non
|
||||||
m_index = job.index();
|
m_index = job.index();
|
||||||
m_jobs[index()] = job;
|
m_jobs[index()] = job;
|
||||||
m_rounds[index()] = 0;
|
m_rounds[index()] = 0;
|
||||||
|
m_nonce_mask[index()] = job.isNicehash() ? 0xFFFFFFULL : (nonceSize() == sizeof(uint64_t) ? (-1ull >> (job.extraNonce().size() * 4 + 1)): 0xFFFFFFFFULL);
|
||||||
|
|
||||||
m_jobs[index()].setBackend(backend);
|
m_jobs[index()].setBackend(backend);
|
||||||
|
|
||||||
memcpy(blob(), job.blob(), job.size());
|
memcpy(blob(), job.blob(), job.size());
|
||||||
Nonce::next(index(), nonce(), reserveCount, currentJob().isNicehash(), nonceSize());
|
Nonce::next(index(), nonce(), reserveCount, nonceMask());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,9 +50,8 @@ xmrig::Nonce::Nonce()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool xmrig::Nonce::next(uint8_t index, uint32_t *nonce, uint32_t reserveCount, bool nicehash, size_t nonceSize)
|
bool xmrig::Nonce::next(uint8_t index, uint32_t *nonce, uint32_t reserveCount, uint64_t mask)
|
||||||
{
|
{
|
||||||
const uint64_t mask = nicehash ? 0xFFFFFFULL : (nonceSize == sizeof(uint64_t) ? 0x7FFFFFFFFFFFFFFFULL : 0xFFFFFFFFULL);
|
|
||||||
if (reserveCount == 0 || mask < reserveCount - 1) {
|
if (reserveCount == 0 || mask < reserveCount - 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +72,7 @@ bool xmrig::Nonce::next(uint8_t index, uint32_t *nonce, uint32_t reserveCount, b
|
||||||
}
|
}
|
||||||
*nonce = (nonce[0] & ~mask) | counter;
|
*nonce = (nonce[0] & ~mask) | counter;
|
||||||
if (mask > 0xFFFFFFFFULL) {
|
if (mask > 0xFFFFFFFFULL) {
|
||||||
nonce[1] = (counter >> 32);
|
nonce[1] = (nonce[1] & (~mask >> 32)) | (counter >> 32);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
@ -54,7 +53,7 @@ public:
|
||||||
static inline void stop(Backend backend) { m_sequence[backend] = 0; }
|
static inline void stop(Backend backend) { m_sequence[backend] = 0; }
|
||||||
static inline void touch(Backend backend) { m_sequence[backend]++; }
|
static inline void touch(Backend backend) { m_sequence[backend]++; }
|
||||||
|
|
||||||
static bool next(uint8_t index, uint32_t *nonce, uint32_t reserveCount, bool nicehash, size_t nonceSize);
|
static bool next(uint8_t index, uint32_t *nonce, uint32_t reserveCount, uint64_t mask);
|
||||||
static void stop();
|
static void stop();
|
||||||
static void touch();
|
static void touch();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue