From b641bfdf8b21ac4ec7ffe0ab2ce43ed746d2e186 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 6 Oct 2015 23:08:47 +0200 Subject: [PATCH] diff: rename functions like cpuminer-multi more proper, intuitive... --- Algo256/blake256.cu | 13 ++++++------- bignum.cpp | 8 +++++++- ccminer.cpp | 8 ++++---- miner.h | 6 +++++- util.cpp | 13 +++++++++---- x15/whirlpool.cu | 2 +- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Algo256/blake256.cu b/Algo256/blake256.cu index 5378848..fd20be1 100644 --- a/Algo256/blake256.cu +++ b/Algo256/blake256.cu @@ -436,6 +436,8 @@ extern "C" int scanhash_blake256(int thr_id, struct work* work, uint32_t max_non // GPU FULL HASH blake256_cpu_hash_80(thr_id, throughput, pdata[19], targetHigh, crcsum, blakerounds); #endif + *hashes_done = pdata[19] - first_nonce + throughput; + if (foundNonce != UINT32_MAX) { uint32_t vhashcpu[8]; @@ -447,27 +449,24 @@ extern "C" int scanhash_blake256(int thr_id, struct work* work, uint32_t max_non be32enc(&endiandata[19], foundNonce); blake256hash(vhashcpu, endiandata, blakerounds); - //applog(LOG_BLUE, "%08x %16llx", vhashcpu[6], targetHigh); if (vhashcpu[6] <= Htarg && fulltest(vhashcpu, ptarget)) { rc = 1; + work_set_target_ratio(work, vhashcpu); pdata[19] = foundNonce; - *hashes_done = pdata[19] - first_nonce + 1; #if NBN > 1 if (extra_results[0] != UINT32_MAX) { be32enc(&endiandata[19], extra_results[0]); blake256hash(vhashcpu, endiandata, blakerounds); - if (vhashcpu[6] <= Htarg /* && fulltest(vhashcpu, ptarget) */) { + if (vhashcpu[6] <= Htarg && fulltest(vhashcpu, ptarget)) { pdata[21] = extra_results[0]; applog(LOG_BLUE, "1:%x 2:%x", foundNonce, extra_results[0]); - *hashes_done = max(*hashes_done, extra_results[0] - first_nonce + 1); + work_set_target_ratio(work, vhashcpu); rc = 2; } extra_results[0] = UINT32_MAX; } #endif - //applog_hash((uint8_t*)ptarget); - //applog_compare_hash((uint8_t*)vhashcpu,(uint8_t*)ptarget); return rc; } else if (opt_debug) { @@ -504,4 +503,4 @@ extern "C" void free_blake256(int thr_id) init[thr_id] = false; cudaDeviceSynchronize(); -} \ No newline at end of file +} diff --git a/bignum.cpp b/bignum.cpp index f023798..3ed285c 100644 --- a/bignum.cpp +++ b/bignum.cpp @@ -77,4 +77,10 @@ extern "C" void bn_store_hash_target_ratio(uint32_t* hash, uint32_t* target, str work->shareratio = bn_hash_target_ratio(hash, target); work->sharediff = work->targetdiff * work->shareratio; } -} \ No newline at end of file +} + +extern "C" void work_set_target_ratio(struct work* work, uint32_t* hash) +{ + bn_store_hash_target_ratio(hash, work->target, work); +} + diff --git a/ccminer.cpp b/ccminer.cpp index 9736ed1..4d2f23a 100644 --- a/ccminer.cpp +++ b/ccminer.cpp @@ -1448,21 +1448,21 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work) case ALGO_NEOSCRYPT: case ALGO_SCRYPT: case ALGO_SCRYPT_JANE: - diff_to_target(work, sctx->job.diff / (65536.0 * opt_difficulty)); + work_set_target(work, sctx->job.diff / (65536.0 * opt_difficulty)); break; case ALGO_DMD_GR: case ALGO_FRESH: case ALGO_FUGUE256: case ALGO_GROESTL: case ALGO_LYRA2v2: - diff_to_target(work, sctx->job.diff / (256.0 * opt_difficulty)); + work_set_target(work, sctx->job.diff / (256.0 * opt_difficulty)); break; case ALGO_KECCAK: case ALGO_LYRA2: - diff_to_target(work, sctx->job.diff / (128.0 * opt_difficulty)); + work_set_target(work, sctx->job.diff / (128.0 * opt_difficulty)); break; default: - diff_to_target(work, sctx->job.diff / opt_difficulty); + work_set_target(work, sctx->job.diff / opt_difficulty); } return true; } diff --git a/miner.h b/miner.h index cd0f58f..267e173 100644 --- a/miner.h +++ b/miner.h @@ -523,7 +523,8 @@ extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len); extern int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y); extern bool fulltest(const uint32_t *hash, const uint32_t *target); -void diff_to_target(struct work* work, double diff); +void diff_to_target(uint32_t* target, double diff); +void work_set_target(struct work* work, double diff); double target_to_diff(uint32_t* target); extern void get_currentalgo(char* buf, int sz); extern uint32_t device_intensity(int thr_id, const char *func, uint32_t defcount); @@ -534,6 +535,9 @@ void bn_nbits_to_uchar(const uint32_t nBits, uchar *target); double bn_hash_target_ratio(uint32_t* hash, uint32_t* target); void bn_store_hash_target_ratio(uint32_t* hash, uint32_t* target, struct work* work); +void work_set_target_ratio(struct work* work, uint32_t* hash); + + struct stratum_job { char *job_id; unsigned char prevhash[32]; diff --git a/util.cpp b/util.cpp index cd26e65..f721f24 100644 --- a/util.cpp +++ b/util.cpp @@ -791,14 +791,11 @@ bool fulltest(const uint32_t *hash, const uint32_t *target) } // Only used by stratum pools -void diff_to_target(struct work* work, double diff) +void diff_to_target(uint32_t *target, double diff) { - uint32_t *target = work->target; uint64_t m; int k; - work->targetdiff = diff; - for (k = 6; k > 0 && diff > 1.0; k--) diff /= 4294967296.0; m = (uint64_t)(4294901760.0 / diff); @@ -811,6 +808,14 @@ void diff_to_target(struct work* work, double diff) } } +// Only used by stratum pools +void work_set_target(struct work* work, double diff) +{ + diff_to_target(work->target, diff); + work->targetdiff = diff; +} + + // Only used by longpoll pools double target_to_diff(uint32_t* target) { diff --git a/x15/whirlpool.cu b/x15/whirlpool.cu index cf4ded4..ac2eb1b 100644 --- a/x15/whirlpool.cu +++ b/x15/whirlpool.cu @@ -97,7 +97,7 @@ extern "C" int scanhash_whirl(int thr_id, struct work* work, uint32_t max_nonce, if (vhash[7] <= Htarg && fulltest(vhash, ptarget)) { int res = 1; *hashes_done = pdata[19] - first_nonce + throughput; - bn_store_hash_target_ratio(vhash, ptarget, work); + work_set_target_ratio(work, vhash); #if 0 uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1); if (secNonce != 0) {