diff options
author | Jeff Garzik <jeff@garzik.org> | 2011-01-29 00:56:24 -0500 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2011-01-29 00:56:24 -0500 |
commit | 0b677407076a55c6a758d1414fade617abd552e5 (patch) | |
tree | 193288f726bf0d89579deefe7d787088d2e8cf6f | |
parent | f570ffcf75764398c9682c310ad7420acd7593c2 (diff) |
Pass max-nonce as arg to each sha256 algo.
Should be an equivalent transformation, with no behavior changes.
-rw-r--r-- | cpu-miner.c | 13 | ||||
-rw-r--r-- | miner.h | 11 | ||||
-rw-r--r-- | sha256_4way.c | 7 | ||||
-rw-r--r-- | sha256_cryptopp.c | 8 | ||||
-rw-r--r-- | sha256_generic.c | 4 | ||||
-rw-r--r-- | sha256_via.c | 5 |
6 files changed, 27 insertions, 21 deletions
diff --git a/cpu-miner.c b/cpu-miner.c index dc611ad..8895d50 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -301,7 +301,8 @@ static void *miner_thread(void *thr_id_int) switch (opt_algo) { case ALGO_C: rc = scanhash_c(work.midstate, work.data + 64, - work.hash1, work.hash, &hashes_done); + work.hash1, work.hash, + 0xffffff, &hashes_done); break; #ifdef WANT_SSE2_4WAY @@ -309,7 +310,7 @@ static void *miner_thread(void *thr_id_int) unsigned int rc4 = ScanHash_4WaySSE2(work.midstate, work.data + 64, work.hash1, work.hash, - &hashes_done); + 0xffffff, &hashes_done); rc = (rc4 == -1) ? false : true; } break; @@ -317,18 +318,20 @@ static void *miner_thread(void *thr_id_int) #ifdef WANT_VIA_PADLOCK case ALGO_VIA: - rc = scanhash_via(work.data, &hashes_done); + rc = scanhash_via(work.data, 0xffffff, &hashes_done); break; #endif case ALGO_CRYPTOPP: rc = scanhash_cryptopp(work.midstate, work.data + 64, - work.hash1, work.hash, &hashes_done); + work.hash1, work.hash, + 0xffffff, &hashes_done); break; #ifdef WANT_CRYPTOPP_ASM32 case ALGO_CRYPTOPP_ASM32: rc = scanhash_asm32(work.midstate, work.data + 64, - work.hash1, work.hash, &hashes_done); + work.hash1, work.hash, + 0xffffff, &hashes_done); break; #endif @@ -37,19 +37,20 @@ extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len); extern unsigned int ScanHash_4WaySSE2(const unsigned char *pmidstate, unsigned char *pdata, unsigned char *phash1, unsigned char *phash, - unsigned long *nHashesDone); + uint32_t max_nonce, unsigned long *nHashesDone); -extern bool scanhash_via(unsigned char *data_inout, unsigned long *hashes_done); +extern bool scanhash_via(unsigned char *data_inout, + uint32_t max_nonce, unsigned long *hashes_done); extern bool scanhash_c(const unsigned char *midstate, unsigned char *data, unsigned char *hash1, unsigned char *hash, - unsigned long *hashes_done); + uint32_t max_nonce, unsigned long *hashes_done); extern bool scanhash_cryptopp(const unsigned char *midstate,unsigned char *data, unsigned char *hash1, unsigned char *hash, - unsigned long *hashes_done); + uint32_t max_nonce, unsigned long *hashes_done); extern bool scanhash_asm32(const unsigned char *midstate,unsigned char *data, unsigned char *hash1, unsigned char *hash, - unsigned long *hashes_done); + uint32_t max_nonce, unsigned long *hashes_done); extern int timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y); diff --git a/sha256_4way.c b/sha256_4way.c index e272ea4..bdc4c23 100644 --- a/sha256_4way.c +++ b/sha256_4way.c @@ -99,7 +99,8 @@ static const unsigned int pSHA256InitState[8] = unsigned int ScanHash_4WaySSE2(const unsigned char *pmidstate, unsigned char *pdata, - unsigned char *phash1, unsigned char *phash, unsigned long *nHashesDone) + unsigned char *phash1, unsigned char *phash, + uint32_t max_nonce, unsigned long *nHashesDone) { unsigned int *nNonce_p = (unsigned int*)(pdata + 12); unsigned int nonce = 0; @@ -128,9 +129,9 @@ unsigned int ScanHash_4WaySSE2(const unsigned char *pmidstate, unsigned char *pd } } - if ((nonce & 0xffffff) == 0) + if (nonce >= max_nonce) { - *nHashesDone = 0xffffff+1; + *nHashesDone = nonce; return -1; } } diff --git a/sha256_cryptopp.c b/sha256_cryptopp.c index c42eaf5..1535b6b 100644 --- a/sha256_cryptopp.c +++ b/sha256_cryptopp.c @@ -93,7 +93,7 @@ static void runhash(void *state, const void *input, const void *init) /* suspiciously similar to ScanHash* from bitcoin */ bool scanhash_cryptopp(const unsigned char *midstate, unsigned char *data, unsigned char *hash1, unsigned char *hash, - unsigned long *hashes_done) + uint32_t max_nonce, unsigned long *hashes_done) { uint32_t *hash32 = (uint32_t *) hash; uint32_t *nonce = (uint32_t *)(data + 12); @@ -122,7 +122,7 @@ bool scanhash_cryptopp(const unsigned char *midstate, unsigned char *data, return true; } - if ((n & 0xffffff) == 0) { + if (n >= max_nonce) { if (opt_debug) fprintf(stderr, "DBG: end of nonce range\n"); *hashes_done = stat_ctr; @@ -584,7 +584,7 @@ static void runhash32(void *state, const void *input, const void *init) /* suspiciously similar to ScanHash* from bitcoin */ bool scanhash_asm32(const unsigned char *midstate, unsigned char *data, unsigned char *hash1, unsigned char *hash, - unsigned long *hashes_done) + uint32_t max_nonce, unsigned long *hashes_done) { uint32_t *hash32 = (uint32_t *) hash; uint32_t *nonce = (uint32_t *)(data + 12); @@ -613,7 +613,7 @@ bool scanhash_asm32(const unsigned char *midstate, unsigned char *data, return true; } - if ((n & 0xffffff) == 0) { + if (n >= max_nonce) { if (opt_debug) fprintf(stderr, "DBG: end of nonce range\n"); *hashes_done = stat_ctr; diff --git a/sha256_generic.c b/sha256_generic.c index e778113..8817d92 100644 --- a/sha256_generic.c +++ b/sha256_generic.c @@ -239,7 +239,7 @@ const uint32_t sha256_init_state[8] = { /* suspiciously similar to ScanHash* from bitcoin */ bool scanhash_c(const unsigned char *midstate, unsigned char *data, unsigned char *hash1, unsigned char *hash, - unsigned long *hashes_done) + uint32_t max_nonce, unsigned long *hashes_done) { uint32_t *hash32 = (uint32_t *) hash; uint32_t *nonce = (uint32_t *)(data + 12); @@ -268,7 +268,7 @@ bool scanhash_c(const unsigned char *midstate, unsigned char *data, return true; } - if ((n & 0xffffff) == 0) { + if (n >= max_nonce) { if (opt_debug) fprintf(stderr, "DBG: end of nonce range\n"); *hashes_done = stat_ctr; diff --git a/sha256_via.c b/sha256_via.c index 6b85e2a..94576a4 100644 --- a/sha256_via.c +++ b/sha256_via.c @@ -17,7 +17,8 @@ static void via_sha256(void *hash, void *buf, unsigned len) :"memory"); } -bool scanhash_via(unsigned char *data_inout, unsigned long *hashes_done) +bool scanhash_via(unsigned char *data_inout, + uint32_t max_nonce, unsigned long *hashes_done) { unsigned char data[128] __attribute__((aligned(128))); unsigned char tmp_hash[32] __attribute__((aligned(128))); @@ -76,7 +77,7 @@ bool scanhash_via(unsigned char *data_inout, unsigned long *hashes_done) return true; } - if ((n & 0xffffff) == 0) { + if (n >= max_nonce) { if (opt_debug) fprintf(stderr, "DBG: end of nonce range\n"); *hashes_done = stat_ctr; |