Skip to content

Commit

Permalink
diff: prepare all algos for diff report (part 2)
Browse files Browse the repository at this point in the history
we need to pass the work structure to store the solved diff

Signed-off-by: Tanguy Pruvot <[email protected]>
  • Loading branch information
tpruvot committed Dec 28, 2015
1 parent 6f91327 commit f7c584d
Show file tree
Hide file tree
Showing 40 changed files with 527 additions and 625 deletions.
12 changes: 7 additions & 5 deletions algo/axiom.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ void axiomhash(void *output, const void *input)
memcpy(output, M[N-1], 32);
}

int scanhash_axiom(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
int scanhash_axiom(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t _ALIGN(128) hash64[8];
uint32_t _ALIGN(128) hash32[8];
uint32_t _ALIGN(128) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;

const uint32_t Htarg = ptarget[7];
const uint32_t first_nonce = pdata[19];
Expand All @@ -60,8 +61,9 @@ int scanhash_axiom(int thr_id, uint32_t *pdata, const uint32_t *ptarget,

do {
be32enc(&endiandata[19], n);
axiomhash(hash64, endiandata);
if (hash64[7] < Htarg && fulltest(hash64, ptarget)) {
axiomhash(hash32, endiandata);
if (hash32[7] < Htarg && fulltest(hash32, ptarget)) {
work_set_target_ratio(work, hash32);
*hashes_done = n - first_nonce + 1;
pdata[19] = n;
return true;
Expand Down
10 changes: 5 additions & 5 deletions algo/bastion.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ void bastionhash(void *output, const void *input)
memcpy(output, hash, 32);
}

int scanhash_bastion(int thr_id, struct work *work, uint64_t max_nonce, uint64_t *hashes_done)
int scanhash_bastion(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t _ALIGN(64) hash64[8];
uint32_t _ALIGN(64) hash32[8];
uint32_t _ALIGN(64) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
Expand All @@ -119,9 +119,9 @@ int scanhash_bastion(int thr_id, struct work *work, uint64_t max_nonce, uint64_t

do {
be32enc(&endiandata[19], n);
bastionhash(hash64, endiandata);
if (hash64[7] < Htarg && fulltest(hash64, ptarget)) {
work_set_target_ratio(work, hash64);
bastionhash(hash32, endiandata);
if (hash32[7] < Htarg && fulltest(hash32, ptarget)) {
work_set_target_ratio(work, hash32);
*hashes_done = n - first_nonce + 1;
pdata[19] = n;
return true;
Expand Down
25 changes: 14 additions & 11 deletions algo/blake.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ void blakehash(void *state, const void *input)
memcpy(state, hash, 32);
}

int scanhash_blake(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
int scanhash_blake(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t _ALIGN(128) hash32[8];
uint32_t _ALIGN(128) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;

const uint32_t first_nonce = pdata[19];
uint32_t HTarget = ptarget[7];

uint32_t _ALIGN(32) hash64[8];
uint32_t _ALIGN(32) endiandata[20];

uint32_t n = first_nonce;

ctx_midstate_done = false;
Expand All @@ -65,19 +66,21 @@ int scanhash_blake(int thr_id, uint32_t *pdata, const uint32_t *ptarget,

do {
be32enc(&endiandata[19], n);
blakehash(hash64, endiandata);
blakehash(hash32, endiandata);
#ifndef DEBUG_ALGO
if (hash64[7] <= HTarget && fulltest(hash64, ptarget)) {
if (hash32[7] <= HTarget && fulltest(hash32, ptarget)) {
work_set_target_ratio(work, hash32);
*hashes_done = n - first_nonce + 1;
return true;
return 1;
}
#else
if (!(n % 0x1000) && !thr_id) printf(".");
if (hash64[7] == 0) {
if (hash32[7] == 0) {
printf("[%d]",thr_id);
if (fulltest(hash64, ptarget)) {
if (fulltest(hash32, ptarget)) {
work_set_target_ratio(work, hash32);
*hashes_done = n - first_nonce + 1;
return true;
return 1;
}
}
#endif
Expand Down
16 changes: 9 additions & 7 deletions algo/blake2.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ inline void blake2s_hash(void *output, const void *input)
memcpy(output, hash, 32);
}

int scanhash_blake2s(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
int scanhash_blake2s(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t _ALIGN(64) hash64[8];
uint32_t _ALIGN(64) endiandata[20];
uint32_t _ALIGN(128) hash32[8];
uint32_t _ALIGN(128) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;

const uint32_t Htarg = ptarget[7];
const uint32_t first_nonce = pdata[19];
Expand All @@ -34,11 +35,12 @@ int scanhash_blake2s(int thr_id, uint32_t *pdata, const uint32_t *ptarget,

do {
be32enc(&endiandata[19], n);
blake2s_hash(hash64, endiandata);
if (hash64[7] < Htarg && fulltest(hash64, ptarget)) {
blake2s_hash(hash32, endiandata);
if (hash32[7] < Htarg && fulltest(hash32, ptarget)) {
work_set_target_ratio(work, hash32);
*hashes_done = n - first_nonce + 1;
pdata[19] = n;
return true;
return 1;
}
n++;

Expand Down
26 changes: 14 additions & 12 deletions algo/blakecoin.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ void blakecoinhash(void *state, const void *input)
memcpy(state, hash, 32);
}

int scanhash_blakecoin(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
int scanhash_blakecoin(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t _ALIGN(128) hash32[8];
uint32_t _ALIGN(128) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;

const uint32_t first_nonce = pdata[19];
uint32_t HTarget = ptarget[7];

uint32_t _ALIGN(32) hash64[8];
uint32_t _ALIGN(32) endiandata[20];

uint32_t n = first_nonce;

ctx_midstate_done = false;
Expand All @@ -70,19 +70,21 @@ int scanhash_blakecoin(int thr_id, uint32_t *pdata, const uint32_t *ptarget,

do {
be32enc(&endiandata[19], n);
blakecoinhash(hash64, endiandata);
blakecoinhash(hash32, endiandata);
#ifndef DEBUG_ALGO
if (hash64[7] <= HTarget && fulltest(hash64, ptarget)) {
if (hash32[7] <= HTarget && fulltest(hash32, ptarget)) {
work_set_target_ratio(work, hash32);
*hashes_done = n - first_nonce + 1;
return true;
return 1;
}
#else
if (!(n % 0x1000) && !thr_id) printf(".");
if (hash64[7] == 0) {
if (hash32[7] == 0) {
printf("[%d]",thr_id);
if (fulltest(hash64, ptarget)) {
if (fulltest(hash32, ptarget)) {
work_set_target_ratio(work, hash32);
*hashes_done = n - first_nonce + 1;
return true;
return 1;
}
}
#endif
Expand Down
16 changes: 9 additions & 7 deletions algo/bmw256.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ void bmwhash(void *output, const void *input)
memcpy(output, hash, 32);
}

int scanhash_bmw(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
int scanhash_bmw(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t _ALIGN(64) hash64[8];
uint32_t _ALIGN(64) endiandata[20];
uint32_t _ALIGN(128) hash32[8];
uint32_t _ALIGN(128) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;

const uint32_t Htarg = ptarget[7];
const uint32_t first_nonce = pdata[19];
Expand All @@ -34,11 +35,12 @@ int scanhash_bmw(int thr_id, uint32_t *pdata, const uint32_t *ptarget,

do {
be32enc(&endiandata[19], n);
bmwhash(hash64, endiandata);
if (hash64[7] < Htarg && fulltest(hash64, ptarget)) {
bmwhash(hash32, endiandata);
if (hash32[7] < Htarg && fulltest(hash32, ptarget)) {
work_set_target_ratio(work, hash32);
*hashes_done = n - first_nonce + 1;
pdata[19] = n;
return true;
return 1;
}
n++;

Expand Down
19 changes: 11 additions & 8 deletions algo/c11.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,30 @@ void c11hash(void *output, const void *input)
memcpy(output, hash, 32);
}

int scanhash_c11(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
int scanhash_c11(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t _ALIGN(128) hash32[8];
uint32_t _ALIGN(128) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;

const uint32_t Htarg = ptarget[7];
const uint32_t first_nonce = pdata[19];
uint32_t _ALIGN(64) endiandata[20];
uint32_t nonce = first_nonce;
volatile uint8_t *restart = &(work_restart[thr_id].restart);

if (opt_benchmark)
((uint32_t*)ptarget)[7] = 0x0cff;
ptarget[7] = 0x0cff;

for (int k=0; k < 19; k++)
be32enc(&endiandata[k], pdata[k]);

const uint32_t Htarg = ptarget[7];
do {
uint32_t hash[8];
be32enc(&endiandata[19], nonce);
c11hash(hash, endiandata);
c11hash(hash32, endiandata);

if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
if (hash32[7] <= Htarg && fulltest(hash32, ptarget)) {
work_set_target_ratio(work, hash32);
pdata[19] = nonce;
*hashes_done = pdata[19] - first_nonce;
return 1;
Expand Down
15 changes: 9 additions & 6 deletions algo/cryptolight.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,15 @@ static void cryptolight_hash_ctx_aes_ni(void* output, const void* input, int len
oaes_free((OAES_CTX **) &ctx->aes_ctx);
}

int scanhash_cryptolight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
int scanhash_cryptolight(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t _ALIGN(128) hash[HASH_SIZE / 4];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;

uint32_t *nonceptr = (uint32_t*) (((char*)pdata) + 39);
uint32_t n = *nonceptr - 1;
const uint32_t first_nonce = n + 1;
//const uint32_t Htarg = ptarget[7];
uint32_t _ALIGN(32) hash[HASH_SIZE / 4];

struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx));

Expand All @@ -326,19 +327,21 @@ int scanhash_cryptolight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
*nonceptr = ++n;
cryptolight_hash_ctx_aes_ni(hash, pdata, 76, ctx);
if (unlikely(hash[7] < ptarget[7])) {
work_set_target_ratio(work, hash);
*hashes_done = n - first_nonce + 1;
free(ctx);
return true;
return 1;
}
} while (likely((n <= max_nonce && !work_restart[thr_id].restart)));
} else {
do {
*nonceptr = ++n;
cryptolight_hash_ctx(hash, pdata, 76, ctx);
if (unlikely(hash[7] < ptarget[7])) {
work_set_target_ratio(work, hash);
*hashes_done = n - first_nonce + 1;
free(ctx);
return true;
return 1;
}
} while (likely((n <= max_nonce && !work_restart[thr_id].restart)));
}
Expand Down
15 changes: 9 additions & 6 deletions algo/cryptonight.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,15 @@ static void cryptonight_hash_ctx_aes_ni(void* output, const void* input, int len
oaes_free((OAES_CTX **) &ctx->aes_ctx);
}

int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
int scanhash_cryptonight(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t _ALIGN(128) hash[HASH_SIZE / 4];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;

uint32_t *nonceptr = (uint32_t*) (((char*)pdata) + 39);
uint32_t n = *nonceptr - 1;
const uint32_t first_nonce = n + 1;
//const uint32_t Htarg = ptarget[7];
uint32_t _ALIGN(32) hash[HASH_SIZE / 4];

struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx));

Expand All @@ -328,19 +329,21 @@ int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
*nonceptr = ++n;
cryptonight_hash_ctx_aes_ni(hash, pdata, 76, ctx);
if (unlikely(hash[7] < ptarget[7])) {
work_set_target_ratio(work, hash);
*hashes_done = n - first_nonce + 1;
free(ctx);
return true;
return 1;
}
} while (likely((n <= max_nonce && !work_restart[thr_id].restart)));
} else {
do {
*nonceptr = ++n;
cryptonight_hash_ctx(hash, pdata, 76, ctx);
if (unlikely(hash[7] < ptarget[7])) {
work_set_target_ratio(work, hash);
*hashes_done = n - first_nonce + 1;
free(ctx);
return true;
return 1;
}
} while (likely((n <= max_nonce && !work_restart[thr_id].restart)));
}
Expand Down
5 changes: 2 additions & 3 deletions algo/drop.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static void droplp_hash_pok(void *output, uint32_t *pdata, const uint32_t versio

int scanhash_drop(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t _ALIGN(64) hash[16];
uint32_t _ALIGN(128) hash[16];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
const uint32_t version = pdata[0] & (~POK_DATA_MASK);
Expand All @@ -193,11 +193,10 @@ int scanhash_drop(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *h
droplp_hash_pok(hash, tmpdata, version);

if (hash[7] <= htarg && fulltest(hash, ptarget)) {
work_set_target_ratio(work, hash);
pdata[0] = tmpdata[0];
pdata[19] = nonce;
*hashes_done = pdata[19] - first_nonce + 1;
if (opt_debug)
applog(LOG_INFO, "found nonce %x", nonce);
return 1;
}
nonce++;
Expand Down
Loading

0 comments on commit f7c584d

Please sign in to comment.