Skip to content
This repository was archived by the owner on Jan 9, 2021. It is now read-only.

Commit 966e6b1

Browse files
author
nicehashdev
committed
Improvements
- Better Axiom speed measure (more exact) - Axiom submit multiple shares if multiple nonces found - Axiom code cleanup - Axiom 8way speedup only for AVX2 (8way does not work on AVX) - Updated launcher to 1.0.1.0 with new cpuminer bins
1 parent 1453b1d commit 966e6b1

File tree

8 files changed

+126
-175
lines changed

8 files changed

+126
-175
lines changed

algo/axiom.c

Lines changed: 59 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,11 @@
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

4712
typedef 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__
12186
void 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

231196
int 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
}

cpu-miner.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,9 @@ static void *miner_thread(void *userdata)
17141714
int wkcmp_sz = nonce_oft;
17151715
int rc = 0;
17161716

1717+
uint32_t axiom_nonces[8];
1718+
int axiom_nonces_len;
1719+
17171720
if (opt_algo == ALGO_DROP || opt_algo == ALGO_ZR5) {
17181721
// Duplicates: ignore pok in data[0]
17191722
wkcmp_sz -= sizeof(uint32_t);
@@ -1920,7 +1923,7 @@ static void *miner_thread(void *userdata)
19201923
&hashes_done);
19211924
break;
19221925
case ALGO_AXIOM:
1923-
rc = scanhash_axiom(thr_id, work.data, work.target, max_nonce, &hashes_done);
1926+
rc = scanhash_axiom(thr_id, work.data, work.target, max_nonce, &hashes_done, axiom_nonces, &axiom_nonces_len);
19241927
break;
19251928
case ALGO_BLAKE:
19261929
rc = scanhash_blake(thr_id, work.data, work.target, max_nonce,
@@ -2068,8 +2071,28 @@ static void *miner_thread(void *userdata)
20682071

20692072
/* if nonce found, submit work */
20702073
if (rc && !opt_benchmark) {
2071-
if (!submit_work(mythr, &work))
2072-
break;
2074+
if (opt_algo == ALGO_AXIOM)
2075+
{
2076+
uint32_t oldnonce = work.data[19];
2077+
2078+
if (axiom_nonces_len > 1)
2079+
printf("Found multiple shares in single loop: %d\n", axiom_nonces_len);
2080+
2081+
/* axiom may find multiple nonces, submit all shares */
2082+
for (i = 0; i < axiom_nonces_len; i++)
2083+
{
2084+
work.data[19] = axiom_nonces[i];
2085+
if (!submit_work(mythr, &work))
2086+
break;
2087+
}
2088+
2089+
work.data[19] = oldnonce;
2090+
}
2091+
else
2092+
{
2093+
if (!submit_work(mythr, &work))
2094+
break;
2095+
}
20732096
// prevent stale work in solo
20742097
// we can't submit twice a block!
20752098
if (!have_stratum && !have_longpoll) {

launcher/Config.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Config
1414
public string WorkerName;
1515
public int Location;
1616
public int Threads;
17-
public bool UseAVX;
17+
public int Extension;
1818
#pragma warning restore 649
1919

2020
public static Config ConfigData;
@@ -27,7 +27,7 @@ static Config()
2727
ConfigData.WorkerName = "worker1";
2828
ConfigData.Location = 0;
2929
ConfigData.Threads = Environment.ProcessorCount;
30-
ConfigData.UseAVX = true;
30+
ConfigData.Extension = 0;
3131

3232
try { ConfigData = JsonConvert.DeserializeObject<Config>(File.ReadAllText("config.json")); }
3333
catch { }

0 commit comments

Comments
 (0)