Skip to content

Commit

Permalink
Default to NeoScrypt
Browse files Browse the repository at this point in the history
SHA-256d and Scrypt not compiled in by default, though still supported.
  • Loading branch information
ghostlander committed Oct 1, 2017
1 parent 160777a commit f33fbc1
Show file tree
Hide file tree
Showing 20 changed files with 412 additions and 269 deletions.
13 changes: 8 additions & 5 deletions api.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2458,7 +2458,7 @@ static bool splitgpuvalue(struct io_data *io_data, char *param, int *gpu, char *


static void gpuintensity(struct io_data *io_data, __maybe_unused SOCKETTYPE c, static void gpuintensity(struct io_data *io_data, __maybe_unused SOCKETTYPE c,
char *param, bool isjson, __maybe_unused char group) { char *param, bool isjson, __maybe_unused char group) {
int id, intensity, min_intensity, max_intensity; int id, intensity, min_intensity = -127, max_intensity = 127;
char *value, intensitystr[7]; char *value, intensitystr[7];


if(!splitgpuvalue(io_data, param, &id, &value, isjson)) if(!splitgpuvalue(io_data, param, &id, &value, isjson))
Expand All @@ -2470,22 +2470,25 @@ static void gpuintensity(struct io_data *io_data, __maybe_unused SOCKETTYPE c,
} else { } else {
intensity = atoi(value); intensity = atoi(value);


#if (USE_NEOSCRYPT) #ifdef USE_NEOSCRYPT
if(opt_neoscrypt) { if(opt_neoscrypt) {
min_intensity = MIN_NEOSCRYPT_INTENSITY; min_intensity = MIN_NEOSCRYPT_INTENSITY;
max_intensity = MAX_NEOSCRYPT_INTENSITY; max_intensity = MAX_NEOSCRYPT_INTENSITY;
} else } else
#endif #endif
#if (USE_SCRYPT) #ifdef USE_SCRYPT
if(opt_scrypt) { if(opt_scrypt) {
min_intensity = MIN_SCRYPT_INTENSITY; min_intensity = MIN_SCRYPT_INTENSITY;
max_intensity = MAX_SCRYPT_INTENSITY; max_intensity = MAX_SCRYPT_INTENSITY;
} else } else
#endif #endif
{ #ifdef USE_SHA256D
if(opt_sha256d) {
min_intensity = MIN_SHA256D_INTENSITY; min_intensity = MIN_SHA256D_INTENSITY;
max_intensity = MAX_SHA256D_INTENSITY; max_intensity = MAX_SHA256D_INTENSITY;
} } else
#endif
{ }


if((intensity < min_intensity) || (intensity > max_intensity)) { if((intensity < min_intensity) || (intensity > max_intensity)) {
message(io_data, MSG_INVINT, 0, value, isjson); message(io_data, MSG_INVINT, 0, value, isjson);
Expand Down
23 changes: 20 additions & 3 deletions configure.ac
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -145,23 +145,33 @@ neoscrypt="yes"


AC_ARG_ENABLE([neoscrypt], AC_ARG_ENABLE([neoscrypt],
[AC_HELP_STRING([--disable-neoscrypt],[Build without support for NeoScrypt (default enabled)])], [AC_HELP_STRING([--disable-neoscrypt],[Build without support for NeoScrypt (default enabled)])],
[scrypt=$enableval] [neoscrypt=$enableval]
) )
if test "x$neoscrypt" = xyes; then if test "x$neoscrypt" = xyes; then
AC_DEFINE([USE_NEOSCRYPT], [1], [Defined to 1 if NeoScrypt support is wanted]) AC_DEFINE([USE_NEOSCRYPT], [1], [Defined to 1 if NeoScrypt support is wanted])
fi fi




scrypt="yes" scrypt="no"


AC_ARG_ENABLE([scrypt], AC_ARG_ENABLE([scrypt],
[AC_HELP_STRING([--disable-scrypt],[Build without support for Scrypt (default enabled)])], [AC_HELP_STRING([--disable-scrypt],[Build without support for Scrypt (default disabled)])],
[scrypt=$enableval] [scrypt=$enableval]
) )
if test "x$scrypt" = xyes; then if test "x$scrypt" = xyes; then
AC_DEFINE([USE_SCRYPT], [1], [Defined to 1 if Scrypt support is wanted]) AC_DEFINE([USE_SCRYPT], [1], [Defined to 1 if Scrypt support is wanted])
fi fi


sha256d="no"

AC_ARG_ENABLE([sha256d],
[AC_HELP_STRING([--disable-sha256d],[Build without support for SHA-256d (default disabled)])],
[sha256d=$enableval]
)
if test "x$sha256d" = xyes; then
AC_DEFINE([USE_SHA256D], [1], [Defined to 1 if SHA-256d support is wanted])
fi



cpumining="no" cpumining="no"


Expand Down Expand Up @@ -423,6 +433,7 @@ AM_CONDITIONAL([NEED_DYNCLOCK], [test x$icarus$modminer$x6500$ztex != xnonono])
AM_CONDITIONAL([NEED_FPGAUTILS], [test x$icarus$bitforce$modminer$x6500$ztex != xnonononono]) AM_CONDITIONAL([NEED_FPGAUTILS], [test x$icarus$bitforce$modminer$x6500$ztex != xnonononono])
AM_CONDITIONAL([HAS_NEOSCRYPT], [test x$neoscrypt = xyes]) AM_CONDITIONAL([HAS_NEOSCRYPT], [test x$neoscrypt = xyes])
AM_CONDITIONAL([HAS_SCRYPT], [test x$scrypt = xyes]) AM_CONDITIONAL([HAS_SCRYPT], [test x$scrypt = xyes])
AM_CONDITIONAL([HAS_SHA256D], [test x$sha256d = xyes])
AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes]) AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes])
AM_CONDITIONAL([HAVE_CYGWIN], [test x$have_cygwin = xtrue]) AM_CONDITIONAL([HAVE_CYGWIN], [test x$have_cygwin = xtrue])
AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue]) AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
Expand Down Expand Up @@ -688,6 +699,12 @@ else
echo " Scrypt...............: Disabled" echo " Scrypt...............: Disabled"
fi fi


if test "x$sha256d" != xno; then
echo " SHA-256d.............: Enabled"
else
echo " SHA-256d.............: Disabled"
fi

echo echo


if test "x$opencl" = xyes; then if test "x$opencl" = xyes; then
Expand Down
123 changes: 67 additions & 56 deletions driver-cpu.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ extern char *set_int_range(const char *arg, int *i, int min, int max);
extern int dev_from_id(int thr_id); extern int dev_from_id(int thr_id);




#ifdef USE_SHA256D
/* chipset-optimized hash functions */ /* chipset-optimized hash functions */
extern bool ScanHash_4WaySSE2(struct thr_info*, const unsigned char *pmidstate, extern bool ScanHash_4WaySSE2(struct thr_info*, const unsigned char *pmidstate,
unsigned char *pdata, unsigned char *phash1, unsigned char *phash, unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
Expand Down Expand Up @@ -133,11 +134,14 @@ extern bool scanhash_sse2_32(struct thr_info*, const unsigned char *pmidstate, u
const unsigned char *ptarget, const unsigned char *ptarget,
uint32_t max_nonce, uint32_t *last_nonce, uint32_t max_nonce, uint32_t *last_nonce,
uint32_t nonce); uint32_t nonce);
#endif /* USE_SHA256D */



#ifdef WANT_CPUMINE #ifdef WANT_CPUMINE
static size_t max_name_len = 0; static size_t max_name_len = 0;
static char *name_spaces_pad = NULL; static char *name_spaces_pad = NULL;
const char *algo_names[] = { const char *algo_names[] = {
#ifdef USE_SHA256D
[ALGO_C] = "c", [ALGO_C] = "c",
#ifdef WANT_SSE2_4WAY #ifdef WANT_SSE2_4WAY
[ALGO_4WAY] = "4way", [ALGO_4WAY] = "4way",
Expand All @@ -161,14 +165,17 @@ const char *algo_names[] = {
#ifdef WANT_ALTIVEC_4WAY #ifdef WANT_ALTIVEC_4WAY
[ALGO_ALTIVEC_4WAY] = "altivec_4way", [ALGO_ALTIVEC_4WAY] = "altivec_4way",
#endif #endif
#if (USE_NEOSCRYPT) #endif /* USE_SHA256D */
#ifdef USE_NEOSCRYPT
[ALGO_NEOSCRYPT] = "neoscrypt", [ALGO_NEOSCRYPT] = "neoscrypt",
#endif #endif
#if (USE_SCRYPT) #ifdef USE_SCRYPT
[ALGO_SCRYPT] = "scrypt", [ALGO_SCRYPT] = "scrypt",
#endif #endif
[ALGO_VOID] = "void",
}; };


#ifdef USE_SHA256D
static const sha256_func sha256_funcs[] = { static const sha256_func sha256_funcs[] = {
[ALGO_C] = (sha256_func)scanhash_c, [ALGO_C] = (sha256_func)scanhash_c,
#ifdef WANT_SSE2_4WAY #ifdef WANT_SSE2_4WAY
Expand All @@ -194,18 +201,23 @@ static const sha256_func sha256_funcs[] = {
[ALGO_SSE4_64] = (sha256_func)scanhash_sse4_64, [ALGO_SSE4_64] = (sha256_func)scanhash_sse4_64,
#endif #endif
}; };
#endif /* USE_SHA256D */
#endif #endif






#ifdef WANT_CPUMINE #ifdef WANT_CPUMINE
#ifdef USE_SHA256D
#if defined(WANT_X8664_SSE2) && defined(__SSE2__) #if defined(WANT_X8664_SSE2) && defined(__SSE2__)
enum sha256_algos opt_algo = ALGO_SSE2_64; enum algo_types opt_algo = ALGO_SSE2_64;
#elif defined(WANT_X8632_SSE2) && defined(__SSE2__) #elif defined(WANT_X8632_SSE2) && defined(__SSE2__)
enum sha256_algos opt_algo = ALGO_SSE2_32; enum algo_types opt_algo = ALGO_SSE2_32;
#else #else
enum sha256_algos opt_algo = ALGO_C; enum algo_types opt_algo = ALGO_C;
#endif #endif
#else
enum algo_types opt_algo = ALGO_VOID;
#endif /* USE_SHA256D */
bool opt_usecpu = false; bool opt_usecpu = false;
static bool forced_n_threads; static bool forced_n_threads;
#endif #endif
Expand All @@ -221,11 +233,9 @@ static const uint32_t hash1_init[] = {




#ifdef WANT_CPUMINE #ifdef WANT_CPUMINE
#ifdef USE_SHA256D
// Algo benchmark, crash-prone, system independent stage // Algo benchmark, crash-prone, system independent stage
double bench_algo_stage3( double bench_algo_stage3(enum algo_types algo) {
enum sha256_algos algo
)
{
// Use a random work block pulled from a pool // Use a random work block pulled from a pool
static uint8_t bench_block[] = { CGMINER_BENCHMARK_BLOCK }; static uint8_t bench_block[] = { CGMINER_BENCHMARK_BLOCK };
struct work work __attribute__((aligned(128))); struct work work __attribute__((aligned(128)));
Expand Down Expand Up @@ -299,10 +309,7 @@ double bench_algo_stage3(
#endif // defined(unix) #endif // defined(unix)


// Algo benchmark, crash-safe, system-dependent stage // Algo benchmark, crash-safe, system-dependent stage
static double bench_algo_stage2( static double bench_algo_stage2(enum algo_types algo) {
enum sha256_algos algo
)
{
// Here, the gig is to safely run a piece of code that potentially // Here, the gig is to safely run a piece of code that potentially
// crashes. Unfortunately, the Right Way (tm) to do this is rather // crashes. Unfortunately, the Right Way (tm) to do this is rather
// heavily platform dependent :( // heavily platform dependent :(
Expand Down Expand Up @@ -561,12 +568,8 @@ static double bench_algo_stage2(
return rate; return rate;
} }


static void bench_algo( static void bench_algo(double *best_rate, enum algo_types *best_algo,
double *best_rate, enum algo_types algo) {
enum sha256_algos *best_algo,
enum sha256_algos algo
)
{
size_t n = max_name_len - strlen(algo_names[algo]); size_t n = max_name_len - strlen(algo_names[algo]);
memset(name_spaces_pad, ' ', n); memset(name_spaces_pad, ' ', n);
name_spaces_pad[n] = 0; name_spaces_pad[n] = 0;
Expand Down Expand Up @@ -601,30 +604,10 @@ static void bench_algo(
} }
} }


// Figure out the longest algorithm name
void init_max_name_len()
{
size_t i;
size_t nb_names = sizeof(algo_names)/sizeof(algo_names[0]);
for (i=0; i<nb_names; ++i) {
const char *p = algo_names[i];
size_t name_len = p ? strlen(p) : 0;
if (max_name_len<name_len)
max_name_len = name_len;
}

name_spaces_pad = (char*) malloc(max_name_len+16);
if (0==name_spaces_pad) {
perror("malloc failed");
exit(1);
}
}

// Pick the fastest CPU hasher // Pick the fastest CPU hasher
static enum sha256_algos pick_fastest_algo() static enum algo_types pick_fastest_algo() {
{
double best_rate = -1.0; double best_rate = -1.0;
enum sha256_algos best_algo = 0; enum algo_types best_algo = 0;
applog(LOG_ERR, "benchmarking all sha256 algorithms ..."); applog(LOG_ERR, "benchmarking all sha256 algorithms ...");


bench_algo(&best_rate, &best_algo, ALGO_C); bench_algo(&best_rate, &best_algo, ALGO_C);
Expand Down Expand Up @@ -671,15 +654,35 @@ static enum sha256_algos pick_fastest_algo()
); );
return best_algo; return best_algo;
} }
#endif /* USE_SHA256D */


/* FIXME: Use asprintf for better errors. */ // Figure out the longest algorithm name
char *set_algo(const char *arg, enum sha256_algos *algo) void init_max_name_len()
{ {
enum sha256_algos i; size_t i;
size_t nb_names = sizeof(algo_names)/sizeof(algo_names[0]);
for (i=0; i<nb_names; ++i) {
const char *p = algo_names[i];
size_t name_len = p ? strlen(p) : 0;
if (max_name_len<name_len)
max_name_len = name_len;
}


if(opt_neoscrypt || opt_scrypt) name_spaces_pad = (char*) malloc(max_name_len+16);
if (0==name_spaces_pad) {
perror("malloc failed");
exit(1);
}
}

/* FIXME: Use asprintf for better errors. */
char *set_algo(const char *arg, enum algo_types *algo) {
enum algo_types i;

if(!opt_sha256d)
return("default"); return("default");


#ifdef USE_SHA256D
if (!strcmp(arg, "auto")) { if (!strcmp(arg, "auto")) {
*algo = pick_fastest_algo(); *algo = pick_fastest_algo();
return NULL; return NULL;
Expand All @@ -691,22 +694,25 @@ char *set_algo(const char *arg, enum sha256_algos *algo)
return NULL; return NULL;
} }
} }
return "Unknown algorithm"; #endif /* USE_SHA256D */

return("void");
} }


void *set_algo_quick(enum sha256_algos *algo) { void *set_algo_quick(enum algo_types *algo) {


if(opt_neoscrypt) { if(opt_neoscrypt) {
*algo = ALGO_NEOSCRYPT; *algo = ALGO_NEOSCRYPT;
} else if(opt_scrypt) { } else if(opt_scrypt) {
*algo = ALGO_SCRYPT; *algo = ALGO_SCRYPT;
} else {
*algo = ALGO_VOID;
} }


} }


void show_algo(char buf[OPT_SHOW_LEN], const enum sha256_algos *algo) void show_algo(char buf[OPT_SHOW_LEN], const enum algo_types *algo) {
{ strncpy(buf, algo_names[*algo], OPT_SHOW_LEN);
strncpy(buf, algo_names[*algo], OPT_SHOW_LEN);
} }
#endif #endif


Expand Down Expand Up @@ -807,7 +813,7 @@ static bool cpu_thread_init(struct thr_info *thr)
return true; return true;
} }


#if (USE_NEOSCRYPT) #ifdef USE_NEOSCRYPT
/* NeoScrypt(128, 2, 1) with Salsa20/20 and ChaCha20/20 */ /* NeoScrypt(128, 2, 1) with Salsa20/20 and ChaCha20/20 */
static int scanhash_neoscrypt(struct thr_info *thr, uint *pdata, const uint *ptarget, static int scanhash_neoscrypt(struct thr_info *thr, uint *pdata, const uint *ptarget,
uint *phash, uint start_nonce, uint max_nonce, uint *final_nonce) { uint *phash, uint start_nonce, uint max_nonce, uint *final_nonce) {
Expand Down Expand Up @@ -842,7 +848,7 @@ static int scanhash_neoscrypt(struct thr_info *thr, uint *pdata, const uint *pta
} }
#endif #endif


#if (USE_SCRYPT) #ifdef USE_SCRYPT
/* Scrypt(1024, 1, 1) with Salsa20/8 through NeoScrypt */ /* Scrypt(1024, 1, 1) with Salsa20/8 through NeoScrypt */
static int scanhash_altscrypt(struct thr_info *thr, uint *pdata, const uint *ptarget, static int scanhash_altscrypt(struct thr_info *thr, uint *pdata, const uint *ptarget,
uint *phash, uint start_nonce, uint max_nonce, uint *final_nonce) { uint *phash, uint start_nonce, uint max_nonce, uint *final_nonce) {
Expand Down Expand Up @@ -887,30 +893,35 @@ static int scanhash_altscrypt(struct thr_info *thr, uint *pdata, const uint *pta
static int64_t cpu_scanhash(struct thr_info *thr, struct work *work, int64_t max_nonce) { static int64_t cpu_scanhash(struct thr_info *thr, struct work *work, int64_t max_nonce) {
const int thr_id = thr->id; const int thr_id = thr->id;
const uint first_nonce = work->blk.nonce; const uint first_nonce = work->blk.nonce;
uint final_nonce, rc; uint final_nonce, rc = 0;


while(!thr->work_restart) { while(!thr->work_restart) {


final_nonce = work->blk.nonce; final_nonce = work->blk.nonce;


#if (USE_NEOSCRYPT) #ifdef USE_NEOSCRYPT
if(opt_neoscrypt) { if(opt_neoscrypt) {
rc = scanhash_neoscrypt(thr, (uint *) work->data, (uint *) work->target, rc = scanhash_neoscrypt(thr, (uint *) work->data, (uint *) work->target,
(uint *) work->hash, work->blk.nonce, max_nonce, &final_nonce); (uint *) work->hash, work->blk.nonce, max_nonce, &final_nonce);
} else } else
#endif #endif
#if (USE_SCRYPT) #ifdef USE_SCRYPT
if(opt_scrypt) { if(opt_scrypt) {
rc = scanhash_altscrypt(thr, (uint *) work->data, (uint *) work->target, rc = scanhash_altscrypt(thr, (uint *) work->data, (uint *) work->target,
(uint *) work->hash, work->blk.nonce, max_nonce, &final_nonce); (uint *) work->hash, work->blk.nonce, max_nonce, &final_nonce);
} else } else
#endif #endif
{ #ifdef USE_SHA256D
if(opt_sha256d) {
uchar hash1[64]; uchar hash1[64];
memcpy(&hash1[0], &hash1_init[0], sizeof(hash1)); memcpy(&hash1[0], &hash1_init[0], sizeof(hash1));
sha256_func func = sha256_funcs[opt_algo]; sha256_func func = sha256_funcs[opt_algo];
rc = (*func) (thr, work->midstate, work->data, hash1, work->hash, rc = (*func) (thr, work->midstate, work->data, hash1, work->hash,
work->target, max_nonce, &final_nonce, work->blk.nonce); work->target, max_nonce, &final_nonce, work->blk.nonce);
} else
#endif
{
usleep(1000);
} }


if(rc) { if(rc) {
Expand Down
Loading

0 comments on commit f33fbc1

Please sign in to comment.