Browse Source

Refactor the CPU scanhash_* functions to use a common API. Fixes bugs.

- Before, some returned bool, and others returned int (which was then turned
  into a bool with a comparison); now, everything returns a bool
- Before, some set hashes_done to nonce - 1 when a share was found and others
  set it to nonce + 1 or 2. This caused some algorithms to scan/submit shares
  twice with the new cpu_scanhash function. Now, it has all been replaced with
  last_nonce, which is set to the final nonce checked by the scanhash_* func.
- VIA needs the full data, and cannot use midstate. All the others were
  expecting midstate and data+64 for their parameters. Now, we pass midstate
  and the full data pointer, and let the scanhash_* function choose which to
  use.
nfactor-troky
Luke Dashjr 13 years ago
parent
commit
b9d197dee8
  1. 144
      main.c
  2. 45
      miner.h
  3. 19
      sha256_4way.c
  4. 19
      sha256_altivec_4way.c
  5. 20
      sha256_cryptopp.c
  6. 10
      sha256_generic.c
  7. 23
      sha256_sse2_amd64.c
  8. 25
      sha256_sse2_i386.c
  9. 23
      sha256_sse4_amd64.c
  10. 12
      sha256_via.c

144
main.c

@ -146,7 +146,6 @@ const char *algo_names[] = {
#endif #endif
}; };
typedef void (*sha256_func)();
static const sha256_func sha256_funcs[] = { static const sha256_func sha256_funcs[] = {
[ALGO_C] = (sha256_func)scanhash_c, [ALGO_C] = (sha256_func)scanhash_c,
#ifdef WANT_SSE2_4WAY #ifdef WANT_SSE2_4WAY
@ -488,34 +487,20 @@ static double bench_algo_stage3(
struct timeval end; struct timeval end;
struct timeval start; struct timeval start;
uint32_t max_nonce = (1<<22); uint32_t max_nonce = (1<<22);
unsigned long hashes_done = 0; uint32_t last_nonce = 0;
gettimeofday(&start, 0); gettimeofday(&start, 0);
#if defined(WANT_VIA_PADLOCK)
// For some reason, the VIA padlock hasher has a different API ...
if (ALGO_VIA==algo) {
(void)scanhash_via(
0,
work.data,
work.target,
max_nonce,
&hashes_done,
work.blk.nonce
);
} else
#endif
{ {
sha256_func func = sha256_funcs[algo]; sha256_func func = sha256_funcs[algo];
(*func)( (*func)(
0, 0,
work.midstate, work.midstate,
work.data + 64, work.data,
work.hash1, work.hash1,
work.hash, work.hash,
work.target, work.target,
max_nonce, max_nonce,
&hashes_done, &last_nonce,
work.blk.nonce work.blk.nonce
); );
} }
@ -528,7 +513,7 @@ static double bench_algo_stage3(
double rate = -1.0; double rate = -1.0;
if (0<usec_elapsed) { if (0<usec_elapsed) {
rate = (1.0*hashes_done)/usec_elapsed; rate = (1.0*(last_nonce+1))/usec_elapsed;
} }
return rate; return rate;
} }
@ -5465,102 +5450,28 @@ static uint64_t cpu_scanhash(struct thr_info *thr, struct work *work, uint64_t m
{ {
const int thr_id = thr->id; const int thr_id = thr->id;
long unsigned int hashes_done = 0;
uint32_t first_nonce = work->blk.nonce; uint32_t first_nonce = work->blk.nonce;
bool rc = false; uint32_t last_nonce;
bool rc;
CPUSearch:
last_nonce = first_nonce;
rc = false;
/* scan nonces for a proof-of-work hash */ /* scan nonces for a proof-of-work hash */
switch (opt_algo) { {
case ALGO_C: sha256_func func = sha256_funcs[opt_algo];
rc = scanhash_c(thr_id, work->midstate, work->data + 64, rc = (*func)(
work->hash1, work->hash, work->target, thr_id,
max_nonce, &hashes_done, work->midstate,
work->blk.nonce); work->data,
break; work->hash1,
#ifdef WANT_X8632_SSE2 work->hash,
case ALGO_SSE2_32: { work->target,
unsigned int rc5 = max_nonce,
scanhash_sse2_32(thr_id, work->midstate, work->data + 64, &last_nonce,
work->hash1, work->hash, work->blk.nonce
work->target, );
max_nonce, &hashes_done,
work->blk.nonce);
rc = (rc5 == -1) ? false : true;
}
break;
#endif
#ifdef WANT_X8664_SSE2
case ALGO_SSE2_64: {
unsigned int rc5 =
scanhash_sse2_64(thr_id, work->midstate, work->data + 64,
work->hash1, work->hash,
work->target,
max_nonce, &hashes_done,
work->blk.nonce);
rc = (rc5 == -1) ? false : true;
}
break;
#endif
#ifdef WANT_X8664_SSE4
case ALGO_SSE4_64: {
unsigned int rc5 =
scanhash_sse4_64(thr_id, work->midstate, work->data + 64,
work->hash1, work->hash,
work->target,
max_nonce, &hashes_done,
work->blk.nonce);
rc = (rc5 == -1) ? false : true;
}
break;
#endif
#ifdef WANT_SSE2_4WAY
case ALGO_4WAY: {
unsigned int rc4 =
ScanHash_4WaySSE2(thr_id, work->midstate, work->data + 64,
work->hash1, work->hash,
work->target,
max_nonce, &hashes_done,
work->blk.nonce);
rc = (rc4 == -1) ? false : true;
}
break;
#endif
#ifdef WANT_ALTIVEC_4WAY
case ALGO_ALTIVEC_4WAY:
{
unsigned int rc4 = ScanHash_altivec_4way(thr_id, work->midstate, work->data + 64,
work->hash1, work->hash,
work->target,
max_nonce, &hashes_done,
work->blk.nonce);
rc = (rc4 == -1) ? false : true;
}
break;
#endif
#ifdef WANT_VIA_PADLOCK
case ALGO_VIA:
rc = scanhash_via(thr_id, work->data, work->target,
max_nonce, &hashes_done,
work->blk.nonce);
break;
#endif
case ALGO_CRYPTOPP:
rc = scanhash_cryptopp(thr_id, work->midstate, work->data + 64,
work->hash1, work->hash, work->target,
max_nonce, &hashes_done,
work->blk.nonce);
break;
#ifdef WANT_CRYPTOPP_ASM32
case ALGO_CRYPTOPP_ASM32:
rc = scanhash_asm32(thr_id, work->midstate, work->data + 64,
work->hash1, work->hash, work->target,
max_nonce, &hashes_done,
work->blk.nonce);
break;
#endif
default:
/* should never happen */
applog(LOG_ERR, "Unrecognized hash algorithm! This should be impossible!");
} }
/* if nonce found, submit work */ /* if nonce found, submit work */
@ -5570,10 +5481,15 @@ static uint64_t cpu_scanhash(struct thr_info *thr, struct work *work, uint64_t m
if (unlikely(!submit_work_sync(thr, work))) { if (unlikely(!submit_work_sync(thr, work))) {
applog(LOG_ERR, "Failed to submit_work_sync in miner_thread %d", thr_id); applog(LOG_ERR, "Failed to submit_work_sync in miner_thread %d", thr_id);
} }
work->blk.nonce = last_nonce + 1;
goto CPUSearch;
} }
else
if (unlikely(last_nonce == first_nonce))
return 0;
work->blk.nonce = hashes_done; work->blk.nonce = last_nonce + 1;
return (uint64_t)hashes_done - first_nonce; return last_nonce - first_nonce + 1;
} }
struct device_api cpu_api = { struct device_api cpu_api = {

45
miner.h

@ -381,57 +381,62 @@ extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
extern char *bin2hex(const unsigned char *p, size_t len); extern char *bin2hex(const unsigned char *p, size_t len);
extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len); extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
extern unsigned int ScanHash_4WaySSE2(int, const unsigned char *pmidstate, typedef bool (*sha256_func)(int thr_id, const unsigned char *pmidstate,
unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget,
uint32_t max_nonce, unsigned long *nHashesDone, uint32_t nonce);
extern unsigned int ScanHash_altivec_4way(int thr_id, const unsigned char *pmidstate,
unsigned char *pdata, unsigned char *pdata,
unsigned char *phash1, unsigned char *phash, unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget, const unsigned char *ptarget,
uint32_t max_nonce, unsigned long *nHashesDone, uint32_t nonce); uint32_t max_nonce,
uint32_t *last_nonce,
uint32_t nonce);
extern unsigned int scanhash_sse2_amd64(int, const unsigned char *pmidstate, extern bool ScanHash_4WaySSE2(int, const unsigned char *pmidstate,
unsigned char *pdata, unsigned char *phash1, unsigned char *phash, unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget, const unsigned char *ptarget,
uint32_t max_nonce, unsigned long *nHashesDone); uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
extern bool ScanHash_altivec_4way(int thr_id, const unsigned char *pmidstate,
unsigned char *pdata,
unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget,
uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
extern bool scanhash_via(int, unsigned char *data_inout, extern bool scanhash_via(int, const unsigned char *pmidstate,
unsigned char *pdata,
unsigned char *phash1, unsigned char *phash,
const unsigned char *target, const unsigned char *target,
uint32_t max_nonce, unsigned long *hashes_done, uint32_t n); uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
extern bool scanhash_c(int, const unsigned char *midstate, unsigned char *data, extern bool scanhash_c(int, const unsigned char *midstate, unsigned char *data,
unsigned char *hash1, unsigned char *hash, unsigned char *hash1, unsigned char *hash,
const unsigned char *target, const unsigned char *target,
uint32_t max_nonce, unsigned long *hashes_done, uint32_t n); uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
extern bool scanhash_cryptopp(int, const unsigned char *midstate,unsigned char *data, extern bool scanhash_cryptopp(int, const unsigned char *midstate,unsigned char *data,
unsigned char *hash1, unsigned char *hash, unsigned char *hash1, unsigned char *hash,
const unsigned char *target, const unsigned char *target,
uint32_t max_nonce, unsigned long *hashes_done, uint32_t n); uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
extern bool scanhash_asm32(int, const unsigned char *midstate,unsigned char *data, extern bool scanhash_asm32(int, const unsigned char *midstate,unsigned char *data,
unsigned char *hash1, unsigned char *hash, unsigned char *hash1, unsigned char *hash,
const unsigned char *target, const unsigned char *target,
uint32_t max_nonce, unsigned long *hashes_done, uint32_t nonce); uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
extern int scanhash_sse2_64(int, const unsigned char *pmidstate, unsigned char *pdata, extern bool scanhash_sse2_64(int, const unsigned char *pmidstate, unsigned char *pdata,
unsigned char *phash1, unsigned char *phash, unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget, const unsigned char *ptarget,
uint32_t max_nonce, unsigned long *nHashesDone, uint32_t max_nonce, uint32_t *last_nonce,
uint32_t nonce); uint32_t nonce);
extern int scanhash_sse4_64(int, const unsigned char *pmidstate, unsigned char *pdata, extern bool scanhash_sse4_64(int, const unsigned char *pmidstate, unsigned char *pdata,
unsigned char *phash1, unsigned char *phash, unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget, const unsigned char *ptarget,
uint32_t max_nonce, unsigned long *nHashesDone, uint32_t max_nonce, uint32_t *last_nonce,
uint32_t nonce); uint32_t nonce);
extern int scanhash_sse2_32(int, const unsigned char *pmidstate, unsigned char *pdata, extern bool scanhash_sse2_32(int, const unsigned char *pmidstate, unsigned char *pdata,
unsigned char *phash1, unsigned char *phash, unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget, const unsigned char *ptarget,
uint32_t max_nonce, unsigned long *nHashesDone, uint32_t max_nonce, uint32_t *last_nonce,
uint32_t nonce); uint32_t nonce);
extern int extern int

19
sha256_4way.c

@ -101,14 +101,16 @@ static const unsigned int pSHA256InitState[8] =
{0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
unsigned int ScanHash_4WaySSE2(int thr_id, const unsigned char *pmidstate, bool ScanHash_4WaySSE2(int thr_id, const unsigned char *pmidstate,
unsigned char *pdata, unsigned char *pdata,
unsigned char *phash1, unsigned char *phash, unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget, const unsigned char *ptarget,
uint32_t max_nonce, unsigned long *nHashesDone, uint32_t max_nonce, uint32_t *last_nonce,
uint32_t nonce) uint32_t nonce)
{ {
unsigned int *nNonce_p = (unsigned int*)(pdata + 12); unsigned int *nNonce_p = (unsigned int*)(pdata + 76);
pdata += 64;
work_restart[thr_id].restart = 0; work_restart[thr_id].restart = 0;
@ -132,17 +134,18 @@ unsigned int ScanHash_4WaySSE2(int thr_id, const unsigned char *pmidstate,
((unsigned int*)phash)[i] = thash[i][j]; ((unsigned int*)phash)[i] = thash[i][j];
if (fulltest(phash, ptarget)) { if (fulltest(phash, ptarget)) {
*nHashesDone = nonce; nonce += j;
*nNonce_p = nonce + j; *last_nonce = nonce;
return nonce + j; *nNonce_p = nonce;
return true;
} }
} }
} }
if ((nonce >= max_nonce) || work_restart[thr_id].restart) if ((nonce >= max_nonce) || work_restart[thr_id].restart)
{ {
*nHashesDone = nonce; *last_nonce = nonce;
return -1; return false;
} }
} }
} }

19
sha256_altivec_4way.c

@ -74,14 +74,16 @@ static const unsigned int pSHA256InitState[8] =
{0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
unsigned int ScanHash_altivec_4way(int thr_id, const unsigned char *pmidstate, bool ScanHash_altivec_4way(int thr_id, const unsigned char *pmidstate,
unsigned char *pdata, unsigned char *pdata,
unsigned char *phash1, unsigned char *phash, unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget, const unsigned char *ptarget,
uint32_t max_nonce, unsigned long *nHashesDone, uint32_t max_nonce, uint32_t *last_nonce,
uint32_t nonce) uint32_t nonce)
{ {
unsigned int *nNonce_p = (unsigned int*)(pdata + 12); unsigned int *nNonce_p = (unsigned int*)(pdata + 76);
pdata += 64;
work_restart[thr_id].restart = 0; work_restart[thr_id].restart = 0;
@ -104,17 +106,18 @@ unsigned int ScanHash_altivec_4way(int thr_id, const unsigned char *pmidstate,
((unsigned int*)phash)[i] = thash[i][j]; ((unsigned int*)phash)[i] = thash[i][j];
if (fulltest(phash, ptarget)) { if (fulltest(phash, ptarget)) {
*nHashesDone = nonce; nonce += j;
*nNonce_p = nonce + j; *last_nonce = nonce;
return nonce + j; *nNonce_p = nonce;
return true;
} }
} }
} }
if ((nonce >= max_nonce) || work_restart[thr_id].restart) if ((nonce >= max_nonce) || work_restart[thr_id].restart)
{ {
*nHashesDone = nonce; *last_nonce = nonce;
return -1; return false;
} }
nonce += NPAR; nonce += NPAR;

20
sha256_cryptopp.c

@ -97,11 +97,13 @@ bool scanhash_cryptopp(int thr_id, const unsigned char *midstate,
unsigned char *data, unsigned char *data,
unsigned char *hash1, unsigned char *hash, unsigned char *hash1, unsigned char *hash,
const unsigned char *target, const unsigned char *target,
uint32_t max_nonce, unsigned long *hashes_done, uint32_t max_nonce, uint32_t *last_nonce,
uint32_t n) uint32_t n)
{ {
uint32_t *hash32 = (uint32_t *) hash; uint32_t *hash32 = (uint32_t *) hash;
uint32_t *nonce = (uint32_t *)(data + 12); uint32_t *nonce = (uint32_t *)(data + 76);
data += 64;
work_restart[thr_id].restart = 0; work_restart[thr_id].restart = 0;
@ -113,12 +115,12 @@ bool scanhash_cryptopp(int thr_id, const unsigned char *midstate,
runhash(hash, hash1, sha256_init_state); runhash(hash, hash1, sha256_init_state);
if (unlikely((hash32[7] == 0) && fulltest(hash, target))) { if (unlikely((hash32[7] == 0) && fulltest(hash, target))) {
*hashes_done = n; *last_nonce = n;
return true; return true;
} }
if ((n >= max_nonce) || work_restart[thr_id].restart) { if ((n >= max_nonce) || work_restart[thr_id].restart) {
*hashes_done = n; *last_nonce = n;
return false; return false;
} }
} }
@ -579,11 +581,13 @@ bool scanhash_asm32(int thr_id, const unsigned char *midstate,
unsigned char *data, unsigned char *data,
unsigned char *hash1, unsigned char *hash, unsigned char *hash1, unsigned char *hash,
const unsigned char *target, const unsigned char *target,
uint32_t max_nonce, unsigned long *hashes_done, uint32_t max_nonce, uint32_t *last_nonce,
uint32_t n) uint32_t n)
{ {
uint32_t *hash32 = (uint32_t *) hash; uint32_t *hash32 = (uint32_t *) hash;
uint32_t *nonce = (uint32_t *)(data + 12); uint32_t *nonce = (uint32_t *)(data + 76);
data += 64;
work_restart[thr_id].restart = 0; work_restart[thr_id].restart = 0;
@ -595,12 +599,12 @@ bool scanhash_asm32(int thr_id, const unsigned char *midstate,
runhash32(hash, hash1, sha256_init_state); runhash32(hash, hash1, sha256_init_state);
if (unlikely((hash32[7] == 0) && fulltest(hash, target))) { if (unlikely((hash32[7] == 0) && fulltest(hash, target))) {
*hashes_done = n; *last_nonce = n;
return true; return true;
} }
if ((n >= max_nonce) || work_restart[thr_id].restart) { if ((n >= max_nonce) || work_restart[thr_id].restart) {
*hashes_done = n; *last_nonce = n;
return false; return false;
} }
} }

10
sha256_generic.c

@ -242,13 +242,15 @@ const uint32_t sha256_init_state[8] = {
bool scanhash_c(int thr_id, const unsigned char *midstate, unsigned char *data, bool scanhash_c(int thr_id, const unsigned char *midstate, unsigned char *data,
unsigned char *hash1, unsigned char *hash, unsigned char *hash1, unsigned char *hash,
const unsigned char *target, const unsigned char *target,
uint32_t max_nonce, unsigned long *hashes_done, uint32_t max_nonce, uint32_t *last_nonce,
uint32_t n) uint32_t n)
{ {
uint32_t *hash32 = (uint32_t *) hash; uint32_t *hash32 = (uint32_t *) hash;
uint32_t *nonce = (uint32_t *)(data + 12); uint32_t *nonce = (uint32_t *)(data + 76);
unsigned long stat_ctr = 0; unsigned long stat_ctr = 0;
data += 64;
work_restart[thr_id].restart = 0; work_restart[thr_id].restart = 0;
while (1) { while (1) {
@ -261,12 +263,12 @@ bool scanhash_c(int thr_id, const unsigned char *midstate, unsigned char *data,
stat_ctr++; stat_ctr++;
if (unlikely((hash32[7] == 0) && fulltest(hash, target))) { if (unlikely((hash32[7] == 0) && fulltest(hash, target))) {
*hashes_done = n; *last_nonce = n;
return true; return true;
} }
if ((n >= max_nonce) || work_restart[thr_id].restart) { if ((n >= max_nonce) || work_restart[thr_id].restart) {
*hashes_done = n; *last_nonce = n;
return false; return false;
} }
} }

23
sha256_sse2_amd64.c

@ -50,14 +50,14 @@ const uint32_t sha256_init[8]__attribute__((aligned(0x100))) =
__m128i g_4sha256_k[64]; __m128i g_4sha256_k[64];
__m128i sha256_consts_m128i[64]__attribute__((aligned(0x1000))); __m128i sha256_consts_m128i[64]__attribute__((aligned(0x1000)));
int scanhash_sse2_64(int thr_id, const unsigned char *pmidstate, bool scanhash_sse2_64(int thr_id, const unsigned char *pmidstate,
unsigned char *pdata, unsigned char *pdata,
unsigned char *phash1, unsigned char *phash, unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget, const unsigned char *ptarget,
uint32_t max_nonce, unsigned long *nHashesDone, uint32_t max_nonce, uint32_t *last_nonce,
uint32_t nonce) uint32_t nonce)
{ {
uint32_t *nNonce_p = (uint32_t *)(pdata + 12); uint32_t *nNonce_p = (uint32_t *)(pdata + 76);
uint32_t m_midstate[8], m_w[16], m_w1[16]; uint32_t m_midstate[8], m_w[16], m_w1[16];
__m128i m_4w[64] __attribute__ ((aligned (0x100))); __m128i m_4w[64] __attribute__ ((aligned (0x100)));
__m128i m_4hash[64] __attribute__ ((aligned (0x100))); __m128i m_4hash[64] __attribute__ ((aligned (0x100)));
@ -65,6 +65,8 @@ int scanhash_sse2_64(int thr_id, const unsigned char *pmidstate,
__m128i offset; __m128i offset;
int i; int i;
pdata += 64;
work_restart[thr_id].restart = 0; work_restart[thr_id].restart = 0;
/* For debugging */ /* For debugging */
@ -114,19 +116,20 @@ int scanhash_sse2_64(int thr_id, const unsigned char *pmidstate,
} }
if (fulltest(phash, ptarget)) { if (fulltest(phash, ptarget)) {
*nHashesDone = nonce; nonce += j;
*nNonce_p = nonce + j; *last_nonce = nonce + 1;
return nonce + j; *nNonce_p = nonce;
return true;
} }
} }
nonce += 4;
if (unlikely((nonce >= max_nonce) || work_restart[thr_id].restart)) if (unlikely((nonce >= max_nonce) || work_restart[thr_id].restart))
{ {
*nHashesDone = nonce; *last_nonce = nonce;
return -1; return false;
} }
nonce += 4;
} }
} }

25
sha256_sse2_i386.c

@ -50,14 +50,14 @@ const uint32_t sha256_32init[8]__attribute__((aligned(0x100))) =
__m128i g_4sha256_k[64]; __m128i g_4sha256_k[64];
__m128i sha256_consts_m128i[64]__attribute__((aligned(0x1000))); __m128i sha256_consts_m128i[64]__attribute__((aligned(0x1000)));
int scanhash_sse2_32(int thr_id, const unsigned char *pmidstate, bool scanhash_sse2_32(int thr_id, const unsigned char *pmidstate,
unsigned char *pdata, unsigned char *pdata,
unsigned char *phash1, unsigned char *phash, unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget, const unsigned char *ptarget,
uint32_t max_nonce, unsigned long *nHashesDone, uint32_t max_nonce, uint32_t *last_nonce,
uint32_t nonce) uint32_t nonce)
{ {
uint32_t *nNonce_p = (uint32_t *)(pdata + 12); uint32_t *nNonce_p = (uint32_t *)(pdata + 76);
uint32_t m_midstate[8], m_w[16], m_w1[16]; uint32_t m_midstate[8], m_w[16], m_w1[16];
__m128i m_4w[64] __attribute__ ((aligned (0x100))); __m128i m_4w[64] __attribute__ ((aligned (0x100)));
__m128i m_4hash[64] __attribute__ ((aligned (0x100))); __m128i m_4hash[64] __attribute__ ((aligned (0x100)));
@ -65,6 +65,8 @@ int scanhash_sse2_32(int thr_id, const unsigned char *pmidstate,
__m128i offset; __m128i offset;
int i; int i;
pdata += 64;
work_restart[thr_id].restart = 0; work_restart[thr_id].restart = 0;
/* For debugging */ /* For debugging */
@ -116,19 +118,20 @@ int scanhash_sse2_32(int thr_id, const unsigned char *pmidstate,
} }
if (fulltest(phash, ptarget)) { if (fulltest(phash, ptarget)) {
*nHashesDone = nonce; nonce += j;
*nNonce_p = nonce + j; *last_nonce = nonce;
return nonce + j; *nNonce_p = nonce;
return true;
} }
} }
if (unlikely((nonce >= max_nonce) || work_restart[thr_id].restart)) {
*last_nonce = nonce;
return false;
}
nonce += 4; nonce += 4;
if (unlikely((nonce >= max_nonce) || work_restart[thr_id].restart))
{
*nHashesDone = nonce;
return -1;
}
} }
} }

23
sha256_sse4_amd64.c

@ -49,19 +49,21 @@ static uint32_t g_sha256_hinit[8] =
__m128i g_4sha256_k[64]; __m128i g_4sha256_k[64];
int scanhash_sse4_64(int thr_id, const unsigned char *pmidstate, bool scanhash_sse4_64(int thr_id, const unsigned char *pmidstate,
unsigned char *pdata, unsigned char *pdata,
unsigned char *phash1, unsigned char *phash, unsigned char *phash1, unsigned char *phash,
const unsigned char *ptarget, const unsigned char *ptarget,
uint32_t max_nonce, unsigned long *nHashesDone, uint32_t max_nonce, uint32_t *last_nonce,
uint32_t nonce) uint32_t nonce)
{ {
uint32_t *nNonce_p = (uint32_t *)(pdata + 12); uint32_t *nNonce_p = (uint32_t *)(pdata + 76);
uint32_t m_midstate[8], m_w[16], m_w1[16]; uint32_t m_midstate[8], m_w[16], m_w1[16];
__m128i m_4w[64], m_4hash[64], m_4hash1[64]; __m128i m_4w[64], m_4hash[64], m_4hash1[64];
__m128i offset; __m128i offset;
int i; int i;
pdata += 64;
work_restart[thr_id].restart = 0; work_restart[thr_id].restart = 0;
/* For debugging */ /* For debugging */
@ -113,19 +115,20 @@ int scanhash_sse4_64(int thr_id, const unsigned char *pmidstate,
} }
if (fulltest(phash, ptarget)) { if (fulltest(phash, ptarget)) {
*nHashesDone = nonce; nonce += j;
*nNonce_p = nonce + j; *last_nonce = nonce;
return nonce + j; *nNonce_p = nonce;
return true;
} }
} }
nonce += 4;
if (unlikely((nonce >= max_nonce) || work_restart[thr_id].restart)) if (unlikely((nonce >= max_nonce) || work_restart[thr_id].restart))
{ {
*nHashesDone = nonce; *last_nonce = nonce;
return -1; return false;
} }
nonce += 4;
} }
} }

12
sha256_via.c

@ -19,9 +19,11 @@ static void via_sha256(void *hash, void *buf, unsigned len)
:"memory"); :"memory");
} }
bool scanhash_via(int thr_id, unsigned char *data_inout, bool scanhash_via(int thr_id, const unsigned char *pmidstate,
const unsigned char *target, unsigned char *data_inout,
uint32_t max_nonce, unsigned long *hashes_done, unsigned char *phash1, unsigned char *phash,
const unsigned char *target,
uint32_t max_nonce, uint32_t *last_nonce,
uint32_t n) uint32_t n)
{ {
unsigned char data[128] __attribute__((aligned(128))); unsigned char data[128] __attribute__((aligned(128)));
@ -70,12 +72,12 @@ bool scanhash_via(int thr_id, unsigned char *data_inout,
dout32[i] = swab32(data32[i]); dout32[i] = swab32(data32[i]);
} }
*hashes_done = n; *last_nonce = n;
return true; return true;
} }
if ((n >= max_nonce) || work_restart[thr_id].restart) { if ((n >= max_nonce) || work_restart[thr_id].restart) {
*hashes_done = n; *last_nonce = n;
return false; return false;
} }
} }

Loading…
Cancel
Save