Skip to content

Commit

Permalink
Pass max-nonce as arg to each sha256 algo.
Browse files Browse the repository at this point in the history
Should be an equivalent transformation, with no behavior changes.
  • Loading branch information
Jeff Garzik authored and Jeff Garzik committed Jan 29, 2011
1 parent f570ffc commit 0b67740
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
13 changes: 8 additions & 5 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,34 +301,37 @@ 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
case ALGO_4WAY: {
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;
#endif

#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

Expand Down
11 changes: 6 additions & 5 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions sha256_4way.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
8 changes: 4 additions & 4 deletions sha256_cryptopp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions sha256_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions sha256_via.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0b67740

Please sign in to comment.