1 #include "cpuminer-config.h"
7 #include "sha3/sph_blake.h"
9 /* Move init out of loop, so init once externally, and then use one single memcpy with that bigger memory block */
11 sph_blake256_context blake1;
12 } blakehash_context_holder;
14 blakehash_context_holder base_contexts;
16 void init_blakehash_contexts()
18 sph_blake256_init(&base_contexts.blake1);
21 static void blakehash(void *state, const void *input)
23 blakehash_context_holder ctx;
28 //do one memcopy to get fresh contexts, its faster even with a larger block then issuing 9 memcopies
29 memcpy(&ctx, &base_contexts, sizeof(base_contexts));
31 sph_blake256 (&ctx.blake1, input, 80);
32 sph_blake256_close (&ctx.blake1, hashA); //0
33 memcpy(state, hashA, 32);
37 int scanhash_blake(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
38 uint32_t max_nonce, unsigned long *hashes_done)
40 uint32_t n = pdata[19] - 1;
41 const uint32_t first_nonce = pdata[19];
42 const uint32_t Htarg = ptarget[7];
43 uint32_t hash64[8] __attribute__((aligned(32)));
44 uint32_t endiandata[32];
46 //char testdata[] = {"\x70\x00\x00\x00\x5d\x38\x5b\xa1\x14\xd0\x79\x97\x0b\x29\xa9\x41\x8f\xd0\x54\x9e\x7d\x68\xa9\x5c\x7f\x16\x86\x21\xa3\x14\x20\x10\x00\x00\x00\x00\x57\x85\x86\xd1\x49\xfd\x07\xb2\x2f\x3a\x8a\x34\x7c\x51\x6d\xe7\x05\x2f\x03\x4d\x2b\x76\xff\x68\xe0\xd6\xec\xff\x9b\x77\xa4\x54\x89\xe3\xfd\x51\x17\x32\x01\x1d\xf0\x73\x10\x00"};
48 //we need bigendian data...
49 //lessons learned: do NOT endianchange directly in pdata, this will all proof-of-works be considered as stale from minerd....
53 be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]);
58 // applog(LOG_DEBUG, "Thr: %02d, firstN: %08x, maxN: %08x, ToDo: %d", thr_id, first_nonce, max_nonce, max_nonce-first_nonce);
61 /* I'm to lazy to put the loop in an inline function... so dirty copy'n'paste.... */
62 /* i know that i could set a variable, but i don't know how the compiler will optimize it, not that then the cpu needs to load the value *everytime* in a register */
66 be32enc(&endiandata[19], n);
67 blakehash(hash64, &endiandata);
68 if (((hash64[7]&0xFFFFFFFF)==0) &&
69 fulltest(hash64, ptarget)) {
70 *hashes_done = n - first_nonce + 1;
73 } while (n < max_nonce && !work_restart[thr_id].restart);
75 else if (ptarget[7]<=0xF)
79 be32enc(&endiandata[19], n);
80 blakehash(hash64, &endiandata);
81 if (((hash64[7]&0xFFFFFFF0)==0) &&
82 fulltest(hash64, ptarget)) {
83 *hashes_done = n - first_nonce + 1;
86 } while (n < max_nonce && !work_restart[thr_id].restart);
88 else if (ptarget[7]<=0xFF)
92 be32enc(&endiandata[19], n);
93 blakehash(hash64, &endiandata);
94 if (((hash64[7]&0xFFFFFF00)==0) &&
95 fulltest(hash64, ptarget)) {
96 *hashes_done = n - first_nonce + 1;
99 } while (n < max_nonce && !work_restart[thr_id].restart);
101 else if (ptarget[7]<=0xFFF)
105 be32enc(&endiandata[19], n);
106 blakehash(hash64, &endiandata);
107 if (((hash64[7]&0xFFFFF000)==0) &&
108 fulltest(hash64, ptarget)) {
109 *hashes_done = n - first_nonce + 1;
112 } while (n < max_nonce && !work_restart[thr_id].restart);
115 else if (ptarget[7]<=0xFFFF)
119 be32enc(&endiandata[19], n);
120 blakehash(hash64, &endiandata);
121 if (((hash64[7]&0xFFFF0000)==0) &&
122 fulltest(hash64, ptarget)) {
123 *hashes_done = n - first_nonce + 1;
126 } while (n < max_nonce && !work_restart[thr_id].restart);
133 be32enc(&endiandata[19], n);
134 blakehash(hash64, &endiandata);
135 if (fulltest(hash64, ptarget)) {
136 *hashes_done = n - first_nonce + 1;
139 } while (n < max_nonce && !work_restart[thr_id].restart);
143 *hashes_done = n - first_nonce + 1;