33#include <string.h>
44#include <stdint.h>
55
6- #include "sha3/sph_shabal.h"
76#include "crypto/mshabal.h"
87
9- static __thread uint32_t _ALIGN (128 ) M [65536 ][8 ];
10-
11- void axiomhash (void * output , const void * input )
12- {
13- sph_shabal256_context ctx ;
14- const int N = 65536 ;
15-
16- sph_shabal256_init (& ctx );
17- sph_shabal256 (& ctx , input , 80 );
18- sph_shabal256_close (& ctx , M [0 ]);
19-
20- for (int i = 1 ; i < N ; i ++ ) {
21- //sph_shabal256_init(&ctx);
22- sph_shabal256 (& ctx , M [i - 1 ], 32 );
23- sph_shabal256_close (& ctx , M [i ]);
24- }
25-
26- for (int b = 0 ; b < N ; b ++ )
27- {
28- const int p = b > 0 ? b - 1 : 0xFFFF ;
29- const int q = M [p ][0 ] % 0xFFFF ;
30- const int j = (b + q ) % N ;
31-
32- //sph_shabal256_init(&ctx);
33- #if 0
34- sph_shabal256 (& ctx , M [p ], 32 );
35- sph_shabal256 (& ctx , M [j ], 32 );
36- #else
37- uint8_t _ALIGN (128 ) hash [64 ];
38- memcpy (hash , M [p ], 32 );
39- memcpy (& hash [32 ], M [j ], 32 );
40- sph_shabal256 (& ctx , hash , 64 );
8+ #ifdef __AVX2__
9+ #define __8WAY__
4110#endif
42- sph_shabal256_close (& ctx , M [b ]);
43- }
44- memcpy (output , M [N - 1 ], 32 );
45- }
4611
4712typedef uint32_t hash_t [8 ];
4813
@@ -117,7 +82,7 @@ void axiomhash4way(mshabal_context* ctx_org, void* memspace, const void *input1,
11782 memcpy (result4 , hash4 [0xffff ], 32 );
11883}
11984
120- #ifdef __AVX__
85+ #ifdef __8WAY__
12186void axiomhash8way (mshabal8_context * ctx_org , void * memspace ,
12287 const void * input1 , void * result1 ,
12388 const void * input2 , void * result2 ,
@@ -229,87 +194,42 @@ void axiomhash8way(mshabal8_context* ctx_org, void* memspace,
229194
230195
231196int scanhash_axiom (int thr_id , uint32_t * pdata , const uint32_t * ptarget ,
232- uint32_t max_nonce , uint64_t * hashes_done )
197+ uint32_t max_nonce , uint64_t * hashes_done , uint32_t * nonces , int * nonces_len )
233198{
234- #ifndef __AVX__
235- uint32_t _ALIGN (128 ) hash64_1 [8 ], hash64_2 [8 ], hash64_3 [8 ], hash64_4 [8 ];
236- uint32_t _ALIGN (128 ) endiandata_1 [20 ], endiandata_2 [20 ], endiandata_3 [20 ], endiandata_4 [20 ];
237- mshabal_context ctx_org ;
238- void * memspace ;
239-
240- const uint32_t Htarg = ptarget [7 ];
241- const uint32_t first_nonce = pdata [19 ];
242-
243- uint32_t n = first_nonce ;
244-
245- // to avoid small chance of generating duplicate shares
246- max_nonce = (max_nonce / 4 ) * 4 ;
247-
248- for (int i = 0 ; i < 19 ; i ++ ) {
249- be32enc (& endiandata_1 [i ], pdata [i ]);
250- }
251-
252- memcpy (endiandata_2 , endiandata_1 , sizeof (endiandata_1 ));
253- memcpy (endiandata_3 , endiandata_1 , sizeof (endiandata_1 ));
254- memcpy (endiandata_4 , endiandata_1 , sizeof (endiandata_1 ));
255-
256- mshabal_init (& ctx_org , 256 );
257- memspace = malloc (65536 * 32 * 4 );
199+ #ifdef __8WAY__
200+ #define HASHES 8
201+ #else
202+ #define HASHES 4
203+ #endif
258204
259- do {
260- be32enc (& endiandata_1 [19 ], n );
261- be32enc (& endiandata_2 [19 ], n + 1 );
262- be32enc (& endiandata_3 [19 ], n + 2 );
263- be32enc (& endiandata_4 [19 ], n + 3 );
264- //axiomhash(hash64_1, endiandata_1);
265- axiomhash4way (& ctx_org , memspace , endiandata_1 , hash64_1 , endiandata_2 , hash64_2 , endiandata_3 , hash64_3 , endiandata_4 , hash64_4 );
266- if (hash64_1 [7 ] < Htarg && fulltest (hash64_1 , ptarget )) {
267- * hashes_done = n - first_nonce + 4 ;
268- pdata [19 ] = n ;
269- free (memspace );
270- return true;
271- }
272- if (hash64_2 [7 ] < Htarg && fulltest (hash64_2 , ptarget )) {
273- * hashes_done = n - first_nonce + 4 ;
274- pdata [19 ] = n + 1 ;
275- free (memspace );
276- return true;
277- }
278- if (hash64_3 [7 ] < Htarg && fulltest (hash64_3 , ptarget )) {
279- * hashes_done = n - first_nonce + 4 ;
280- pdata [19 ] = n + 2 ;
281- free (memspace );
282- return true;
283- }
284- if (hash64_4 [7 ] < Htarg && fulltest (hash64_4 , ptarget )) {
285- * hashes_done = n - first_nonce + 4 ;
286- pdata [19 ] = n + 3 ;
287- free (memspace );
288- return true;
289- }
290-
291- n += 4 ;
292- //n++;
205+ uint32_t _ALIGN (128 ) hash64_1 [8 ], hash64_2 [8 ], hash64_3 [8 ], hash64_4 [8 ]
206+ #ifdef __8WAY__
207+ , hash64_5 [8 ], hash64_6 [8 ], hash64_7 [8 ], hash64_8 [8 ]
208+ #endif
209+ ;
293210
294- } while (n < max_nonce && !work_restart [thr_id ].restart );
211+ uint32_t _ALIGN (128 ) endiandata_1 [20 ], endiandata_2 [20 ], endiandata_3 [20 ], endiandata_4 [20 ]
212+ #ifdef __8WAY__
213+ , endiandata_5 [20 ], endiandata_6 [20 ], endiandata_7 [20 ], endiandata_8 [20 ]
214+ #endif
215+ ;
295216
296- * hashes_done = n - first_nonce ;
297- pdata [19 ] = n ;
298- free (memspace );
299- return 0 ;
217+ #ifdef __8WAY__
218+ mshabal8_context ctx_org ;
300219#else
301- uint32_t _ALIGN (128 ) hash64_1 [8 ], hash64_2 [8 ], hash64_3 [8 ], hash64_4 [8 ], hash64_5 [8 ], hash64_6 [8 ], hash64_7 [8 ], hash64_8 [8 ];
302- uint32_t _ALIGN (128 ) endiandata_1 [20 ], endiandata_2 [20 ], endiandata_3 [20 ], endiandata_4 [20 ], endiandata_5 [20 ], endiandata_6 [20 ], endiandata_7 [20 ], endiandata_8 [20 ];
303- mshabal8_context ctx_org8 ;
220+ mshabal_context ctx_org ;
221+ #endif
304222 void * memspace ;
305223
306224 const uint32_t Htarg = ptarget [7 ];
307225 const uint32_t first_nonce = pdata [19 ];
308226
309227 uint32_t n = first_nonce ;
310228
229+ * nonces_len = 0 ;
230+
311231 // to avoid small chance of generating duplicate shares
312- max_nonce = (max_nonce / 8 ) * 8 ;
232+ max_nonce = (max_nonce / HASHES ) * HASHES ;
313233
314234 for (int i = 0 ; i < 19 ; i ++ ) {
315235 be32enc (& endiandata_1 [i ], pdata [i ]);
@@ -318,84 +238,81 @@ int scanhash_axiom(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
318238 memcpy (endiandata_2 , endiandata_1 , sizeof (endiandata_1 ));
319239 memcpy (endiandata_3 , endiandata_1 , sizeof (endiandata_1 ));
320240 memcpy (endiandata_4 , endiandata_1 , sizeof (endiandata_1 ));
241+ #ifdef __8WAY__
321242 memcpy (endiandata_5 , endiandata_1 , sizeof (endiandata_1 ));
322243 memcpy (endiandata_6 , endiandata_1 , sizeof (endiandata_1 ));
323244 memcpy (endiandata_7 , endiandata_1 , sizeof (endiandata_1 ));
324245 memcpy (endiandata_8 , endiandata_1 , sizeof (endiandata_1 ));
246+ #endif
325247
326- mshabal8_init (& ctx_org8 , 256 );
327- memspace = malloc (65536 * 32 * 8 );
248+ #ifdef __8WAY__
249+ mshabal8_init (& ctx_org , 256 );
250+ #else
251+ mshabal_init (& ctx_org , 256 );
252+ #endif
253+ memspace = malloc (65536 * 32 * HASHES );
328254
329255 do {
330256 be32enc (& endiandata_1 [19 ], n );
331257 be32enc (& endiandata_2 [19 ], n + 1 );
332258 be32enc (& endiandata_3 [19 ], n + 2 );
333259 be32enc (& endiandata_4 [19 ], n + 3 );
260+ #ifdef __8WAY__
334261 be32enc (& endiandata_5 [19 ], n + 4 );
335262 be32enc (& endiandata_6 [19 ], n + 5 );
336263 be32enc (& endiandata_7 [19 ], n + 6 );
337264 be32enc (& endiandata_8 [19 ], n + 7 );
265+ #endif
338266
339- axiomhash8way (& ctx_org8 , memspace , endiandata_1 , hash64_1 , endiandata_2 , hash64_2 , endiandata_3 , hash64_3 , endiandata_4 , hash64_4 ,
267+ #ifdef __8WAY__
268+ axiomhash8way (& ctx_org , memspace , endiandata_1 , hash64_1 , endiandata_2 , hash64_2 , endiandata_3 , hash64_3 , endiandata_4 , hash64_4 ,
340269 endiandata_5 , hash64_5 , endiandata_6 , hash64_6 , endiandata_7 , hash64_7 , endiandata_8 , hash64_8 );
270+ #else
271+ axiomhash4way (& ctx_org , memspace , endiandata_1 , hash64_1 , endiandata_2 , hash64_2 , endiandata_3 , hash64_3 , endiandata_4 , hash64_4 );
272+ #endif
341273
342274 if (hash64_1 [7 ] < Htarg && fulltest (hash64_1 , ptarget )) {
343- * hashes_done = n - first_nonce + 8 ;
344- pdata [19 ] = n ;
345- free (memspace );
346- return true;
275+ nonces [(* nonces_len )++ ] = n ;
347276 }
348277 if (hash64_2 [7 ] < Htarg && fulltest (hash64_2 , ptarget )) {
349- * hashes_done = n - first_nonce + 8 ;
350- pdata [19 ] = n + 1 ;
351- free (memspace );
352- return true;
278+ nonces [(* nonces_len )++ ] = n + 1 ;
353279 }
354280 if (hash64_3 [7 ] < Htarg && fulltest (hash64_3 , ptarget )) {
355- * hashes_done = n - first_nonce + 8 ;
356- pdata [19 ] = n + 2 ;
357- free (memspace );
358- return true;
281+ nonces [(* nonces_len )++ ] = n + 2 ;
359282 }
360283 if (hash64_4 [7 ] < Htarg && fulltest (hash64_4 , ptarget )) {
361- * hashes_done = n - first_nonce + 8 ;
362- pdata [19 ] = n + 3 ;
363- free (memspace );
364- return true;
284+ nonces [(* nonces_len )++ ] = n + 3 ;
365285 }
366286
287+ #ifdef __8WAY__
367288 if (hash64_5 [7 ] < Htarg && fulltest (hash64_5 , ptarget )) {
368- * hashes_done = n - first_nonce + 8 ;
369- pdata [19 ] = n + 4 ;
370- free (memspace );
371- return true;
289+ nonces [(* nonces_len )++ ] = n + 4 ;
372290 }
373291 if (hash64_6 [7 ] < Htarg && fulltest (hash64_6 , ptarget )) {
374- * hashes_done = n - first_nonce + 8 ;
375- pdata [19 ] = n + 5 ;
376- free (memspace );
377- return true;
292+ nonces [(* nonces_len )++ ] = n + 5 ;
378293 }
379294 if (hash64_7 [7 ] < Htarg && fulltest (hash64_7 , ptarget )) {
380- * hashes_done = n - first_nonce + 8 ;
381- pdata [19 ] = n + 6 ;
382- free (memspace );
383- return true;
295+ nonces [(* nonces_len )++ ] = n + 6 ;
384296 }
385297 if (hash64_8 [7 ] < Htarg && fulltest (hash64_8 , ptarget )) {
386- * hashes_done = n - first_nonce + 8 ;
387- pdata [19 ] = n + 7 ;
298+ nonces [(* nonces_len )++ ] = n + 7 ;
299+ }
300+ #endif
301+
302+ n += HASHES ;
303+
304+ if ((* nonces_len ) > 0 )
305+ {
306+ * hashes_done = n - first_nonce ;
307+ pdata [19 ] = n ;
388308 free (memspace );
389309 return true;
390310 }
391311
392- n += 8 ;
393-
394312 } while (n < max_nonce && !work_restart [thr_id ].restart );
395313
396314 * hashes_done = n - first_nonce ;
397315 pdata [19 ] = n ;
398316 free (memspace );
399317 return 0 ;
400- #endif
401318}
0 commit comments