Skip to content

Commit

Permalink
Add yespower algorithm
Browse files Browse the repository at this point in the history
Default algo is changed yespower 0.5 mode for "a few percent speedup" which is compatible with yescrypt.
  • Loading branch information
wo01 committed Jul 17, 2018
1 parent 932558f commit 6a70eec
Show file tree
Hide file tree
Showing 14 changed files with 2,888 additions and 48 deletions.
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ dist_man_MANS = minerd.1

minerd_SOURCES = elist.h miner.h compat.h \
cpu-miner.c util.c \
sha2.c scrypt.c \
yescrypt.c yescrypt.h
yescrypt.c yescrypt.h \
sha2.c sha256.c yespower.c yespower.h yespower-opt.c
if USE_ASM
if ARCH_x86
minerd_SOURCES += sha2-x86.S scrypt-x86.S
Expand Down
5 changes: 5 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
minerd-sse2.exe Core2, Nehalem
minerd-aes-sse42.exe Westmere, Sandy-Ivybridge
minerd-avx.exe Sandy-Ivybridge
minerd-avx2.exe Haswell, Sky-Kaby-Coffeelake
minerd-avx2-sha.exe Ryzen
57 changes: 11 additions & 46 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <sys/time.h>
#include <time.h>
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#else
#include <errno.h>
Expand Down Expand Up @@ -101,15 +102,13 @@ struct workio_cmd {
};

enum algos {
ALGO_SCRYPT, /* scrypt(1024,1,1) */
ALGO_SHA256D, /* SHA-256d */
ALGO_YESCRYPT,
ALGO_YESCRYPT,
ALGO_YESPOWER,
};

static const char *algo_names[] = {
[ALGO_SCRYPT] = "scrypt",
[ALGO_SHA256D] = "sha256d",
[ALGO_YESCRYPT] = "yescrypt",
[ALGO_YESPOWER] = "yespower",
};

bool opt_debug = false;
Expand All @@ -131,8 +130,7 @@ static int opt_fail_pause = 30;
int opt_timeout = 0;
static int opt_scantime = 5;
static const bool opt_time = true;
static enum algos opt_algo = ALGO_YESCRYPT;
static int opt_scrypt_n = 1024;
static enum algos opt_algo = ALGO_YESPOWER;
static int opt_n_threads;
static int num_processors;
static char *rpc_url;
Expand Down Expand Up @@ -173,10 +171,8 @@ static char const usage[] = "\
Usage: " PROGRAM_NAME " [OPTIONS]\n\
Options:\n\
-a, --algo=ALGO specify the algorithm to use\n\
scrypt scrypt(1024, 1, 1)\n\
scrypt:N scrypt(N, 1, 1)\n\
sha256d SHA-256d\n\
yescrypt yescrypt (default)\n\
yescrypt yescrypt\n\
yespower yespower 0.5 (default)\n\
-o, --url=URL URL of mining server\n\
-O, --userpass=U:P username:password pair for mining server\n\
-u, --user=USERNAME username for mining server\n\
Expand Down Expand Up @@ -1068,7 +1064,7 @@ static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
free(xnonce2str);
}

if (opt_algo == ALGO_SCRYPT || opt_algo == ALGO_YESCRYPT)
if (opt_algo == ALGO_YESCRYPT || opt_algo == ALGO_YESPOWER)
diff_to_target(work->target, sctx->job.diff / 65536.0);
else
diff_to_target(work->target, sctx->job.diff);
Expand All @@ -1083,7 +1079,6 @@ static void *miner_thread(void *userdata)
struct work work = {{0}};
uint32_t max_nonce;
uint32_t end_nonce = 0xffffffffU / opt_n_threads * (thr_id + 1) - 0x20;
unsigned char *scratchbuf = NULL;
char s[16];
int i;

Expand All @@ -1104,15 +1099,6 @@ static void *miner_thread(void *userdata)
affine_to_cpu(thr_id, thr_id % num_processors);
}

if (opt_algo == ALGO_SCRYPT) {
scratchbuf = scrypt_buffer_alloc(opt_scrypt_n);
if (!scratchbuf) {
applog(LOG_ERR, "scrypt buffer allocation failed");
pthread_mutex_lock(&applog_lock);
exit(1);
}
}

while (1) {
unsigned long hashes_done;
struct timeval tv_start, tv_end, diff;
Expand Down Expand Up @@ -1163,15 +1149,10 @@ static void *miner_thread(void *userdata)
max64 *= thr_hashrates[thr_id];
if (max64 <= 0) {
switch (opt_algo) {
case ALGO_SCRYPT:
max64 = opt_scrypt_n < 16 ? 0x3ffff : 0x3fffff / opt_scrypt_n;
break;
case ALGO_YESCRYPT:
case ALGO_YESPOWER:
max64 = 0x3fffff;
break;
case ALGO_SHA256D:
max64 = 0x1fffff;
break;
}
}
if (work.data[19] + max64 > end_nonce)
Expand All @@ -1184,21 +1165,14 @@ static void *miner_thread(void *userdata)

/* scan nonces for a proof-of-work hash */
switch (opt_algo) {
case ALGO_SCRYPT:
rc = scanhash_scrypt(thr_id, work.data, scratchbuf, work.target,
max_nonce, &hashes_done, opt_scrypt_n);
break;

case ALGO_YESCRYPT:
rc = scanhash_yescrypt(thr_id, work.data, work.target,
max_nonce, &hashes_done);
break;

case ALGO_SHA256D:
rc = scanhash_sha256d(thr_id, work.data, work.target,
case ALGO_YESPOWER:
rc = scanhash_yespower(thr_id, work.data, work.target,
max_nonce, &hashes_done);
break;

default:
/* should never happen */
goto out;
Expand Down Expand Up @@ -1521,15 +1495,6 @@ static void parse_arg(int key, char *arg, char *pname)
opt_algo = i;
break;
}
if (arg[v] == ':' && i == ALGO_SCRYPT) {
char *ep;
v = strtol(arg+v+1, &ep, 10);
if (*ep || v & (v-1) || v < 2)
continue;
opt_algo = i;
opt_scrypt_n = v;
break;
}
}
}
if (i == ARRAY_SIZE(algo_names)) {
Expand Down
1 change: 1 addition & 0 deletions insecure_memzero.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define insecure_memzero(buf, len) /* empty */
3 changes: 3 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ extern int scanhash_sha256d(int thr_id, uint32_t *pdata,
extern int scanhash_yescrypt(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);

extern int scanhash_yespower(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);

extern unsigned char *scrypt_buffer_alloc(int N);
extern int scanhash_scrypt(int thr_id, uint32_t *pdata,
unsigned char *scratchbuf, const uint32_t *ptarget,
Expand Down
Loading

0 comments on commit 6a70eec

Please sign in to comment.