Pass max-nonce as arg to each sha256 algo. Should be an equivalent transformation, with no behavior changes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
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
diff --git a/miner.h b/miner.h
index eda9498..7639cd7 100644
--- a/miner.h
+++ b/miner.h
@@ -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;