static int64_t cpu_scanhash(struct thr_info *thr, struct work *work, int64_t max_nonce) { const int thr_id = thr->id; const uint first_nonce = work->blk.nonce; uint final_nonce, rc; while(!thr->work_restart) { final_nonce = work->blk.nonce; #if (USE_NEOSCRYPT) if(opt_neoscrypt) { rc = scanhash_neoscrypt(thr, (uint *) work->data, (uint *) work->target, (uint *) work->hash, work->blk.nonce, max_nonce, &final_nonce); } else #endif #if (USE_SCRYPT) if(opt_scrypt) { rc = scanhash_altscrypt(thr, (uint *) work->data, (uint *) work->target, (uint *) work->hash, work->blk.nonce, max_nonce, &final_nonce); } else #endif { uchar hash1[64]; memcpy(&hash1[0], &hash1_init[0], sizeof(hash1)); sha256_func func = sha256_funcs[opt_algo]; rc = (*func) (thr, work->midstate, work->data, hash1, work->hash, work->target, max_nonce, &final_nonce, work->blk.nonce); } if(rc) { applog(LOG_DEBUG, "CPU thread %d found nonce 0x%X", dev_from_id(thr_id), final_nonce); submit_work_async(work, NULL); /* Set a new start nonce and keep hashing */ work->blk.nonce = final_nonce + 1; } else break; } if(final_nonce != first_nonce) { work->blk.nonce = final_nonce + 1; return(final_nonce - first_nonce + 1); } return(0); }
static int64_t cpu_scanhash(struct thr_info *thr, struct work *work, int64_t max_nonce) { const int thr_id = thr->id; unsigned char hash1[64]; uint32_t first_nonce = work->blk.nonce; uint32_t last_nonce; bool rc; hex2bin(hash1, "00000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000010000", 64); CPUSearch: last_nonce = first_nonce; rc = false; /* scan nonces for a proof-of-work hash */ { sha256_func func = sha256_funcs[opt_algo]; rc = (*func)( thr, work->midstate, work->data, hash1, work->hash, work->target, max_nonce, &last_nonce, work->blk.nonce ); } /* if nonce found, submit work */ if (unlikely(rc)) { applog(LOG_DEBUG, "CPU %d found something?", dev_from_id(thr_id)); submit_work_async(work, NULL); work->blk.nonce = last_nonce + 1; goto CPUSearch; } else if (unlikely(last_nonce == first_nonce)) return 0; work->blk.nonce = last_nonce + 1; return last_nonce - first_nonce + 1; }