diff options
author | Jeff Garzik <jeff@garzik.org> | 2010-11-25 01:27:19 -0500 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2010-11-25 01:27:19 -0500 |
commit | e4c4b3fe5f701aa4d154e4e651f1e3e34d35b001 (patch) | |
tree | ae1a234646538e42f6c856cf25680dc7bc6ba87c /cpu-miner.c | |
parent | 1032fec15b036b5f1be1b30f174deb21d377c22a (diff) |
scanhash micro-optimizations
* don't bother returning nonce, we only need success/fail boolean
* don't needlessly read nonce pointer data, for each loop
Diffstat (limited to 'cpu-miner.c')
-rw-r--r-- | cpu-miner.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/cpu-miner.c b/cpu-miner.c index a2c9569..7685fdb 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -334,16 +334,15 @@ static const uint32_t init_state[8] = { }; /* suspiciously similar to ScanHash* from bitcoin */ -static uint32_t scanhash(unsigned char *midstate, unsigned char *data, - unsigned char *hash1, unsigned char *hash) +static bool scanhash(unsigned char *midstate, unsigned char *data, + unsigned char *hash1, unsigned char *hash) { uint32_t *hash32 = (uint32_t *) hash; uint32_t *nonce = (uint32_t *)(data + 12); - uint32_t n; + uint32_t n = 0; unsigned long stat_ctr = 0; while (1) { - n = *nonce; n++; *nonce = n; @@ -359,7 +358,7 @@ static uint32_t scanhash(unsigned char *midstate, unsigned char *data, hexstr); free(hexstr); - return n; + return true; } stat_ctr++; @@ -373,7 +372,7 @@ static uint32_t scanhash(unsigned char *midstate, unsigned char *data, if (opt_debug) fprintf(stderr, "DBG: end of nonce range\n"); - return 0; + return false; } } } @@ -426,9 +425,8 @@ static void *miner_thread(void *dummy) "{\"method\": \"getwork\", \"params\": [], \"id\":0}\r\n"; while (1) { - json_t *val; struct work work __attribute__((aligned(128))); - uint32_t nonce; + json_t *val; bool rc; /* obtain new work from bitcoin */ @@ -448,11 +446,11 @@ static void *miner_thread(void *dummy) json_decref(val); /* scan nonces for a proof-of-work hash */ - nonce = scanhash(work.midstate, work.data + 64, - work.hash1, work.hash); + rc = scanhash(work.midstate, work.data + 64, + work.hash1, work.hash); /* if nonce found, submit work */ - if (nonce) + if (rc) submit_work(&work); } |