Improve and modularize compile-time CPU detection.
Ideally, we should move this to autoconf.
This commit is contained in:
parent
500759cea1
commit
86eb37d631
3 changed files with 21 additions and 11 deletions
19
cpu-miner.c
19
cpu-miner.c
|
@ -37,8 +37,8 @@ enum {
|
|||
};
|
||||
|
||||
enum sha256_algos {
|
||||
ALGO_C,
|
||||
ALGO_4WAY
|
||||
ALGO_C, /* plain C */
|
||||
ALGO_4WAY, /* parallel SSE2 */
|
||||
};
|
||||
|
||||
static bool opt_debug;
|
||||
|
@ -63,7 +63,7 @@ static struct option_help options_help[] = {
|
|||
{ "algo XXX",
|
||||
"(-a XXX) Specify sha256 implementation:\n"
|
||||
"\tc\t\tLinux kernel sha256, implemented in C (default)"
|
||||
#ifdef __SSE2__
|
||||
#ifdef WANT_SSE2_4WAY
|
||||
"\n\t4way\t\ttcatm's 4-way SSE2 implementation (EXPERIMENTAL)"
|
||||
#endif
|
||||
},
|
||||
|
@ -301,18 +301,23 @@ static void *miner_thread(void *thr_id_int)
|
|||
gettimeofday(&tv_start, NULL);
|
||||
|
||||
/* scan nonces for a proof-of-work hash */
|
||||
if (opt_algo == ALGO_C)
|
||||
switch (opt_algo) {
|
||||
case ALGO_C:
|
||||
rc = scanhash(work.midstate, work.data + 64,
|
||||
work.hash1, work.hash, &hashes_done);
|
||||
#ifdef __SSE2__
|
||||
else {
|
||||
break;
|
||||
|
||||
#ifdef WANT_SSE2_4WAY
|
||||
case ALGO_4WAY: {
|
||||
unsigned int rc4 =
|
||||
ScanHash_4WaySSE2(work.midstate, work.data + 64,
|
||||
work.hash1, work.hash,
|
||||
&hashes_done);
|
||||
rc = (rc4 == -1) ? false : true;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
hashmeter(thr_id, &tv_start, hashes_done);
|
||||
|
||||
|
@ -347,7 +352,7 @@ static void parse_arg (int key, char *arg)
|
|||
case 'a':
|
||||
if (!strcmp(arg, "c"))
|
||||
opt_algo = ALGO_C;
|
||||
#ifdef __SSE2__
|
||||
#ifdef WANT_SSE2_4WAY
|
||||
else if (!strcmp(arg, "4way"))
|
||||
opt_algo = ALGO_4WAY;
|
||||
#endif
|
||||
|
|
4
miner.h
4
miner.h
|
@ -4,6 +4,10 @@
|
|||
#include <stdbool.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#ifdef __SSE2__
|
||||
#define WANT_SSE2_4WAY 1
|
||||
#endif
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
|
|
@ -4,14 +4,15 @@
|
|||
|
||||
// tcatm's 4-way 128-bit SSE2 SHA-256
|
||||
|
||||
#ifdef __SSE2__
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <xmmintrin.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "miner.h"
|
||||
|
||||
#ifdef WANT_SSE2_4WAY
|
||||
|
||||
#define NPAR 32
|
||||
|
||||
|
@ -467,4 +468,4 @@ static void DoubleBlockSHA256(const void* pin, void* pad, const void *pre, unsig
|
|||
|
||||
}
|
||||
|
||||
#endif /* __SSE2__ */
|
||||
#endif /* WANT_SSE2_4WAY */
|
||||
|
|
Loading…
Reference in a new issue