Skip to content

Commit

Permalink
Merge pull request #2623 from psychocrypt/rx-topic-optimizeRXHashRound
Browse files Browse the repository at this point in the history
[RX] optimize hash calculation up to 5%
  • Loading branch information
fireice-uk authored Dec 10, 2019
2 parents b7586c5 + 606d89e commit af08f28
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions xmrstak/backend/cpu/minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,6 @@ void minethd::multiway_work_main()
continue;
}

constexpr uint32_t nonce_chunk = 4096;
int64_t nonce_ctr = 0;

assert(sizeof(job_result::sJobID) == sizeof(pool_job::sJobID));

if(oWork.bNiceHash)
Expand All @@ -608,6 +605,13 @@ void minethd::multiway_work_main()
if(on_new_job != nullptr)
on_new_job(oWork, ctx);

uint64_t tempHash[N][8];
uint32_t current_nonces[N];
// always use a multiple of N
constexpr uint32_t nonce_chunk = 4096 * N;
int64_t nonce_ctr = 0;
bool first = true;

constexpr uint64_t update_stat_each = 128;
// only check each 128 hash if the job has changed
while((iCount % update_stat_each) != 0 || globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo)
Expand All @@ -622,20 +626,41 @@ void minethd::multiway_work_main()
break;
}

if(first)
{
first = false;
for(size_t i = 0u; i < N; ++i)
{
*piNonce[i] = iNonce;
current_nonces[i] = iNonce;
++iNonce;
randomx_calculate_hash_first(ctx[i]->m_rx_vm, tempHash[i], bWorkBlob + oWork.iWorkSize * i, oWork.iWorkSize);
}
};

// prepare nonce for next round
for(size_t i = 0; i < N; i++)
*piNonce[i] = iNonce++;
{
*piNonce[i] = iNonce;
++iNonce;
}

ctx[0]->hash_fn(bWorkBlob, oWork.iWorkSize, bHashOut, ctx, miner_algo);
for(size_t i = 0u; i < N; ++i)
randomx_calculate_hash_next(ctx[i]->m_rx_vm, tempHash[i], bWorkBlob + oWork.iWorkSize * i, oWork.iWorkSize, (char*)bHashOut + 32 * i);

for(size_t i = 0; i < N; i++)
for(size_t i = 0u; i < N; i++)
{
if(*piHashVal[i] < oWork.iTarget)
{
executor::inst()->push_event(
ex_event(job_result(oWork.sJobID, iNonce - N + i, bHashOut + 32 * i, iThreadNo, miner_algo),
ex_event(job_result(oWork.sJobID, current_nonces[i], bHashOut + 32 * i, iThreadNo, miner_algo),
oWork.iPoolId));
}
}

for(size_t i = 0; i < N; i++)
current_nonces[i] = iNonce - N + i;

if((iCount++ % update_stat_each) == 0) //Store stats every 8*N hashes
{
updateStats((iCount - iLastCount) * N, oWork.iPoolId);
Expand Down

0 comments on commit af08f28

Please sign in to comment.