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

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
nicehashdev committed Aug 5, 2015
1 parent 1453b1d commit 966e6b1
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 175 deletions.
201 changes: 59 additions & 142 deletions algo/axiom.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,11 @@
#include <string.h>
#include <stdint.h>

#include "sha3/sph_shabal.h"
#include "crypto/mshabal.h"

static __thread uint32_t _ALIGN(128) M[65536][8];

void axiomhash(void *output, const void *input)
{
sph_shabal256_context ctx;
const int N = 65536;

sph_shabal256_init(&ctx);
sph_shabal256(&ctx, input, 80);
sph_shabal256_close(&ctx, M[0]);

for(int i = 1; i < N; i++) {
//sph_shabal256_init(&ctx);
sph_shabal256(&ctx, M[i-1], 32);
sph_shabal256_close(&ctx, M[i]);
}

for(int b = 0; b < N; b++)
{
const int p = b > 0 ? b - 1 : 0xFFFF;
const int q = M[p][0] % 0xFFFF;
const int j = (b + q) % N;

//sph_shabal256_init(&ctx);
#if 0
sph_shabal256(&ctx, M[p], 32);
sph_shabal256(&ctx, M[j], 32);
#else
uint8_t _ALIGN(128) hash[64];
memcpy(hash, M[p], 32);
memcpy(&hash[32], M[j], 32);
sph_shabal256(&ctx, hash, 64);
#ifdef __AVX2__
#define __8WAY__
#endif
sph_shabal256_close(&ctx, M[b]);
}
memcpy(output, M[N-1], 32);
}

typedef uint32_t hash_t[8];

Expand Down Expand Up @@ -117,7 +82,7 @@ void axiomhash4way(mshabal_context* ctx_org, void* memspace, const void *input1,
memcpy(result4, hash4[0xffff], 32);
}

#ifdef __AVX__
#ifdef __8WAY__
void axiomhash8way(mshabal8_context* ctx_org, void* memspace,
const void *input1, void *result1,
const void *input2, void *result2,
Expand Down Expand Up @@ -229,87 +194,42 @@ void axiomhash8way(mshabal8_context* ctx_org, void* memspace,


int scanhash_axiom(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
uint32_t max_nonce, uint64_t *hashes_done, uint32_t *nonces, int *nonces_len)
{
#ifndef __AVX__
uint32_t _ALIGN(128) hash64_1[8], hash64_2[8], hash64_3[8], hash64_4[8];
uint32_t _ALIGN(128) endiandata_1[20], endiandata_2[20], endiandata_3[20], endiandata_4[20];
mshabal_context ctx_org;
void* memspace;

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

uint32_t n = first_nonce;

// to avoid small chance of generating duplicate shares
max_nonce = (max_nonce / 4) * 4;

for (int i=0; i < 19; i++) {
be32enc(&endiandata_1[i], pdata[i]);
}

memcpy(endiandata_2, endiandata_1, sizeof(endiandata_1));
memcpy(endiandata_3, endiandata_1, sizeof(endiandata_1));
memcpy(endiandata_4, endiandata_1, sizeof(endiandata_1));

mshabal_init(&ctx_org, 256);
memspace = malloc(65536 * 32 * 4);
#ifdef __8WAY__
#define HASHES 8
#else
#define HASHES 4
#endif

do {
be32enc(&endiandata_1[19], n);
be32enc(&endiandata_2[19], n + 1);
be32enc(&endiandata_3[19], n + 2);
be32enc(&endiandata_4[19], n + 3);
//axiomhash(hash64_1, endiandata_1);
axiomhash4way(&ctx_org, memspace, endiandata_1, hash64_1, endiandata_2, hash64_2, endiandata_3, hash64_3, endiandata_4, hash64_4);
if (hash64_1[7] < Htarg && fulltest(hash64_1, ptarget)) {
*hashes_done = n - first_nonce + 4;
pdata[19] = n;
free(memspace);
return true;
}
if (hash64_2[7] < Htarg && fulltest(hash64_2, ptarget)) {
*hashes_done = n - first_nonce + 4;
pdata[19] = n + 1;
free(memspace);
return true;
}
if (hash64_3[7] < Htarg && fulltest(hash64_3, ptarget)) {
*hashes_done = n - first_nonce + 4;
pdata[19] = n + 2;
free(memspace);
return true;
}
if (hash64_4[7] < Htarg && fulltest(hash64_4, ptarget)) {
*hashes_done = n - first_nonce + 4;
pdata[19] = n + 3;
free(memspace);
return true;
}

n += 4;
//n++;
uint32_t _ALIGN(128) hash64_1[8], hash64_2[8], hash64_3[8], hash64_4[8]
#ifdef __8WAY__
, hash64_5[8], hash64_6[8], hash64_7[8], hash64_8[8]
#endif
;

} while (n < max_nonce && !work_restart[thr_id].restart);
uint32_t _ALIGN(128) endiandata_1[20], endiandata_2[20], endiandata_3[20], endiandata_4[20]
#ifdef __8WAY__
, endiandata_5[20], endiandata_6[20], endiandata_7[20], endiandata_8[20]
#endif
;

*hashes_done = n - first_nonce;
pdata[19] = n;
free(memspace);
return 0;
#ifdef __8WAY__
mshabal8_context ctx_org;
#else
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];
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];
mshabal8_context ctx_org8;
mshabal_context ctx_org;
#endif
void* memspace;

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

uint32_t n = first_nonce;

*nonces_len = 0;

// to avoid small chance of generating duplicate shares
max_nonce = (max_nonce / 8) * 8;
max_nonce = (max_nonce / HASHES) * HASHES;

for (int i = 0; i < 19; i++) {
be32enc(&endiandata_1[i], pdata[i]);
Expand All @@ -318,84 +238,81 @@ int scanhash_axiom(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
memcpy(endiandata_2, endiandata_1, sizeof(endiandata_1));
memcpy(endiandata_3, endiandata_1, sizeof(endiandata_1));
memcpy(endiandata_4, endiandata_1, sizeof(endiandata_1));
#ifdef __8WAY__
memcpy(endiandata_5, endiandata_1, sizeof(endiandata_1));
memcpy(endiandata_6, endiandata_1, sizeof(endiandata_1));
memcpy(endiandata_7, endiandata_1, sizeof(endiandata_1));
memcpy(endiandata_8, endiandata_1, sizeof(endiandata_1));
#endif

mshabal8_init(&ctx_org8, 256);
memspace = malloc(65536 * 32 * 8);
#ifdef __8WAY__
mshabal8_init(&ctx_org, 256);
#else
mshabal_init(&ctx_org, 256);
#endif
memspace = malloc(65536 * 32 * HASHES);

do {
be32enc(&endiandata_1[19], n);
be32enc(&endiandata_2[19], n + 1);
be32enc(&endiandata_3[19], n + 2);
be32enc(&endiandata_4[19], n + 3);
#ifdef __8WAY__
be32enc(&endiandata_5[19], n + 4);
be32enc(&endiandata_6[19], n + 5);
be32enc(&endiandata_7[19], n + 6);
be32enc(&endiandata_8[19], n + 7);
#endif

axiomhash8way(&ctx_org8, memspace, endiandata_1, hash64_1, endiandata_2, hash64_2, endiandata_3, hash64_3, endiandata_4, hash64_4,
#ifdef __8WAY__
axiomhash8way(&ctx_org, memspace, endiandata_1, hash64_1, endiandata_2, hash64_2, endiandata_3, hash64_3, endiandata_4, hash64_4,
endiandata_5, hash64_5, endiandata_6, hash64_6, endiandata_7, hash64_7, endiandata_8, hash64_8);
#else
axiomhash4way(&ctx_org, memspace, endiandata_1, hash64_1, endiandata_2, hash64_2, endiandata_3, hash64_3, endiandata_4, hash64_4);
#endif

if (hash64_1[7] < Htarg && fulltest(hash64_1, ptarget)) {
*hashes_done = n - first_nonce + 8;
pdata[19] = n;
free(memspace);
return true;
nonces[(*nonces_len)++] = n;
}
if (hash64_2[7] < Htarg && fulltest(hash64_2, ptarget)) {
*hashes_done = n - first_nonce + 8;
pdata[19] = n + 1;
free(memspace);
return true;
nonces[(*nonces_len)++] = n + 1;
}
if (hash64_3[7] < Htarg && fulltest(hash64_3, ptarget)) {
*hashes_done = n - first_nonce + 8;
pdata[19] = n + 2;
free(memspace);
return true;
nonces[(*nonces_len)++] = n + 2;
}
if (hash64_4[7] < Htarg && fulltest(hash64_4, ptarget)) {
*hashes_done = n - first_nonce + 8;
pdata[19] = n + 3;
free(memspace);
return true;
nonces[(*nonces_len)++] = n + 3;
}

#ifdef __8WAY__
if (hash64_5[7] < Htarg && fulltest(hash64_5, ptarget)) {
*hashes_done = n - first_nonce + 8;
pdata[19] = n + 4;
free(memspace);
return true;
nonces[(*nonces_len)++] = n + 4;
}
if (hash64_6[7] < Htarg && fulltest(hash64_6, ptarget)) {
*hashes_done = n - first_nonce + 8;
pdata[19] = n + 5;
free(memspace);
return true;
nonces[(*nonces_len)++] = n + 5;
}
if (hash64_7[7] < Htarg && fulltest(hash64_7, ptarget)) {
*hashes_done = n - first_nonce + 8;
pdata[19] = n + 6;
free(memspace);
return true;
nonces[(*nonces_len)++] = n + 6;
}
if (hash64_8[7] < Htarg && fulltest(hash64_8, ptarget)) {
*hashes_done = n - first_nonce + 8;
pdata[19] = n + 7;
nonces[(*nonces_len)++] = n + 7;
}
#endif

n += HASHES;

if ((*nonces_len) > 0)
{
*hashes_done = n - first_nonce;
pdata[19] = n;
free(memspace);
return true;
}

n += 8;

} while (n < max_nonce && !work_restart[thr_id].restart);

*hashes_done = n - first_nonce;
pdata[19] = n;
free(memspace);
return 0;
#endif
}
29 changes: 26 additions & 3 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,9 @@ static void *miner_thread(void *userdata)
int wkcmp_sz = nonce_oft;
int rc = 0;

uint32_t axiom_nonces[8];
int axiom_nonces_len;

if (opt_algo == ALGO_DROP || opt_algo == ALGO_ZR5) {
// Duplicates: ignore pok in data[0]
wkcmp_sz -= sizeof(uint32_t);
Expand Down Expand Up @@ -1920,7 +1923,7 @@ static void *miner_thread(void *userdata)
&hashes_done);
break;
case ALGO_AXIOM:
rc = scanhash_axiom(thr_id, work.data, work.target, max_nonce, &hashes_done);
rc = scanhash_axiom(thr_id, work.data, work.target, max_nonce, &hashes_done, axiom_nonces, &axiom_nonces_len);
break;
case ALGO_BLAKE:
rc = scanhash_blake(thr_id, work.data, work.target, max_nonce,
Expand Down Expand Up @@ -2068,8 +2071,28 @@ static void *miner_thread(void *userdata)

/* if nonce found, submit work */
if (rc && !opt_benchmark) {
if (!submit_work(mythr, &work))
break;
if (opt_algo == ALGO_AXIOM)
{
uint32_t oldnonce = work.data[19];

if (axiom_nonces_len > 1)
printf("Found multiple shares in single loop: %d\n", axiom_nonces_len);

/* axiom may find multiple nonces, submit all shares */
for (i = 0; i < axiom_nonces_len; i++)
{
work.data[19] = axiom_nonces[i];
if (!submit_work(mythr, &work))
break;
}

work.data[19] = oldnonce;
}
else
{
if (!submit_work(mythr, &work))
break;
}
// prevent stale work in solo

This comment has been minimized.

Copy link
@tpruvot

tpruvot Aug 5, 2015

This block should be placed after the "solo mining" test... else you submit multiples nonces on the wallet which cannot work... only one solution accepted per block ;) not a big deal, should not happen until the coin death

// we can't submit twice a block!
if (!have_stratum && !have_longpoll) {
Expand Down
4 changes: 2 additions & 2 deletions launcher/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Config
public string WorkerName;
public int Location;
public int Threads;
public bool UseAVX;
public int Extension;
#pragma warning restore 649

public static Config ConfigData;
Expand All @@ -27,7 +27,7 @@ static Config()
ConfigData.WorkerName = "worker1";
ConfigData.Location = 0;
ConfigData.Threads = Environment.ProcessorCount;
ConfigData.UseAVX = true;
ConfigData.Extension = 0;

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

1 comment on commit 966e6b1

@tpruvot
Copy link

@tpruvot tpruvot commented on 966e6b1 Aug 5, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.