Skip to content

Commit

Permalink
Merge pull request tpruvot#14 from tpruvot/master
Browse files Browse the repository at this point in the history
Fix for issue tpruvot#13 + 2 new cpuminer features
  • Loading branch information
lucasjones committed Aug 2, 2014
2 parents 9119d7b + 8eb0a06 commit d971882
Show file tree
Hide file tree
Showing 36 changed files with 46,896 additions and 211 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ config.sub

mingw32-config.cache

*/.dirstamp

*.iml
*.iml
12 changes: 11 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ minerd_SOURCES = elist.h \
blake.c \
cryptonight.c \
x11.c \
x13.c \
x14.c \
x15.c \
sha3/sph_keccak.c \
sha3/sph_hefty1.c \
sha3/sph_groestl.c \
Expand All @@ -42,6 +45,10 @@ minerd_SOURCES = elist.h \
sha3/sph_cubehash.c \
sha3/sph_simd.c \
sha3/sph_echo.c \
sha3/sph_hamsi.c \
sha3/sph_fugue.c \
sha3/sph_shabal.c \
sha3/sph_whirlpool.c \
crypto/oaes_lib.c \
crypto/c_keccak.c \
crypto/c_groestl.c \
Expand All @@ -50,6 +57,7 @@ minerd_SOURCES = elist.h \
crypto/c_skein.c \
crypto/hash.c \
crypto/aesb.c
if USE_ASM
if ARCH_x86
minerd_SOURCES += sha2-x86.S scrypt-x86.S aesb-x86.S crypto/aesb-x86-impl.c
endif
Expand All @@ -59,11 +67,13 @@ endif
if ARCH_ARM
minerd_SOURCES += sha2-arm.S scrypt-arm.S
endif
endif

minerd_LDFLAGS = $(PTHREAD_FLAGS)
minerd_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@
minerd_CPPFLAGS = @LIBCURL_CPPFLAGS@
minerd_CFLAGS = -Ofast -flto -fuse-linker-plugin

if HAVE_WINDOWS
minerd_CFLAGS += -Wl,--stack,10485760
endif
endif
21 changes: 21 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
Version multi 1.0.4 (Tanguy Pruvot)

- Add x13 x14 and x15 algos (Sherlockcoin, X14Coin, Webcoin..)
- Add scrypt:N variants (Vertcoin)
- Fix thread khashes/s value output
- Add a configure option --disable-assembly

Version multi 1.0.3 (Lucas Jones)

- Add new algos :
x11 (Darkcoin [DRK], Hirocoin, Limecoin)
cryptonight (Bytecoin [BCN], Monero)
keccak (Maxcoin HelixCoin, CryptoMeth, Galleon, 365coin, Slothcoin, BitcointalkCoin)
hefty1 (Heavycoin)
quark (Quarkcoin)
skein (Skeincoin, Myriadcoin)
shavite3 (INKcoin)
blake (Blakecoin)

- See README.md

Version 2.3.3 - Feb 27, 2014

- The --url option is now mandatory
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ Algorithms
==========
#### Currently supported
*__scrypt__ (Litecoin, Dogecoin, Feathercoin, etc..)
*__scrypt:N__ (Vertcoin [VTC])
*__sha256d__ (Bitcoin, Freicoin, Peercoin/PPCoin, Terracoin, etc..)
*__x11__ (Darkcoin [DRK], Hirocoin, Limecoin)
*__x13__ (Sherlockcoin, [ACE], [B2B], [GRC], [XHC], etc..)
*__x14__ (X14, Webcoin [WEB])
*__x14__ (RadianceCoin [RCE])
*__cryptonight__ (Bytecoin [BCN], Monero)

#### Implemented, but untested
Expand All @@ -34,7 +38,6 @@ Algorithms
* ? blake (Blakecoin)

#### Planned support for
* *scrypt-n* (Vertcoin [VTC])
* *scrypt-jane* (YaCoin, CopperBars, Pennies, Tickets, etc..)
* *qubit* (Qubitcoin, Myriadcoin)
* *groestl* (Groestlcoin)
Expand Down
6 changes: 3 additions & 3 deletions blake.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef struct {
sph_blake256_context blake1;
} blakehash_context_holder;

blakehash_context_holder base_contexts;
static blakehash_context_holder base_contexts;

void init_blakehash_contexts()
{
Expand All @@ -35,7 +35,7 @@ static void blakehash(void *state, const void *input)
}

int scanhash_blake(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done)
uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t n = pdata[19] - 1;
const uint32_t first_nonce = pdata[19];
Expand Down Expand Up @@ -143,4 +143,4 @@ int scanhash_blake(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
*hashes_done = n - first_nonce + 1;
pdata[19] = n;
return 0;
}
}
11 changes: 9 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([cpuminer], [1.0.3])
AC_INIT([cpuminer], [1.0.4])

AC_PREREQ([2.59c])
AC_CANONICAL_SYSTEM
Expand Down Expand Up @@ -61,7 +61,13 @@ case $target in
;;
esac

if test x$have_x86 = xtrue -o x$have_x86_64 = xtrue
AC_ARG_ENABLE([assembly],
AS_HELP_STRING([--disable-assembly], [disable assembly-language routines]))
if test x$enable_assembly != xno; then
AC_DEFINE([USE_ASM], [1], [Define to 1 if assembly routines are wanted.])
fi

if test x$enable_assembly != xno -a x$have_x86_64 = xtrue
then
AC_MSG_CHECKING(whether we can compile AVX code)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[asm ("vmovdqa %ymm0, %ymm1");])],
Expand Down Expand Up @@ -108,6 +114,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([static __uint128_t i = 100;])],

AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue])
AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
AM_CONDITIONAL([USE_ASM], [test x$enable_assembly != xno])
AM_CONDITIONAL([ARCH_x86], [test x$have_x86 = xtrue])
AM_CONDITIONAL([ARCH_x86_64], [test x$have_x86_64 = xtrue])
AM_CONDITIONAL([ARCH_ARM], [test x$have_arm = xtrue])
Expand Down
87 changes: 68 additions & 19 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct workio_cmd {
} u;
};

enum mining_algo {
enum algos {
ALGO_SCRYPT, /* scrypt(1024,1,1) */
ALGO_SHA256D, /* SHA-256d */
ALGO_KECCAK, /* Keccak */
Expand All @@ -109,6 +109,9 @@ enum mining_algo {
ALGO_SHAVITE3, /* Shavite3 */
ALGO_BLAKE, /* Blake */
ALGO_X11, /* X11 */
ALGO_X13, /* X13 */
ALGO_X14, /* X14 */
ALGO_X15, /* X15 Whirlpool */
ALGO_CRYPTONIGHT, /* CryptoNight */
};

Expand All @@ -122,6 +125,9 @@ static const char *algo_names[] = {
[ALGO_SHAVITE3] = "shavite3",
[ALGO_BLAKE] = "blake",
[ALGO_X11] = "x11",
[ALGO_X13] = "x13",
[ALGO_X14] = "x14",
[ALGO_X15] = "x15",
[ALGO_CRYPTONIGHT] = "cryptonight",
};

Expand All @@ -144,7 +150,8 @@ int opt_timeout = 0;
static int opt_scantime = 5;
static json_t *opt_config;
static const bool opt_time = true;
static enum mining_algo opt_algo = ALGO_SCRYPT;
static enum algos opt_algo = ALGO_SCRYPT;
static int opt_scrypt_n = 1024;
static int opt_n_threads;
static int num_processors;
static char *rpc_url;
Expand Down Expand Up @@ -192,6 +199,7 @@ Usage: " PROGRAM_NAME " [OPTIONS]\n\
Options:\n\
-a, --algo=ALGO specify the algorithm to use\n\
scrypt scrypt(1024, 1, 1) (default)\n\
scrypt:N scrypt(N, 1, 1)\n\
sha256d SHA-256d\n\
keccak Keccak\n\
quark Quark\n\
Expand All @@ -200,6 +208,9 @@ Options:\n\
shavite3 Shavite3\n\
blake Blake\n\
x11 X11\n\
x13 X13\n\
x14 X14\n\
x15 X15\n\
cryptonight CryptoNight\n\
-o, --url=URL URL of mining server\n\
-O, --userpass=U:P username:password pair for mining server\n\
Expand Down Expand Up @@ -1047,12 +1058,17 @@ static void *miner_thread(void *userdata) {
}

if (opt_algo == ALGO_SCRYPT) {
scratchbuf = scrypt_buffer_alloc();
scratchbuf = scrypt_buffer_alloc(opt_scrypt_n);
if (!scratchbuf) {
applog(LOG_ERR, "scrypt buffer allocation failed");
pthread_mutex_lock(&applog_lock);
exit(1);
}
}
uint32_t *nonceptr = (uint32_t*) (((char*)work.data) + (jsonrpc_2 ? 39 : 76));

while (1) {
unsigned long hashes_done;
uint64_t hashes_done;
struct timeval tv_start, tv_end, diff;
int64_t max64;
int rc;
Expand Down Expand Up @@ -1106,11 +1122,20 @@ static void *miner_thread(void *userdata) {
if (max64 <= 0) {
switch (opt_algo) {
case ALGO_SCRYPT:
max64 = 0xfffLL;
max64 = opt_scrypt_n < 16 ? 0x3ffff : 0x3fffff / opt_scrypt_n;
break;
case ALGO_CRYPTONIGHT:
max64 = 0x40LL;
break;
case ALGO_X13:
max64 = 0x1ffff;
break;
case ALGO_X14:
max64 = 0x3ffff;
break;
case ALGO_X15:
max64 = 0x1ffff;
break;
default:
max64 = 0x1fffffLL;
break;
Expand All @@ -1128,7 +1153,7 @@ static void *miner_thread(void *userdata) {
switch (opt_algo) {
case ALGO_SCRYPT:
rc = scanhash_scrypt(thr_id, work.data, scratchbuf, work.target,
max_nonce, &hashes_done);
max_nonce, &hashes_done, opt_scrypt_n);
break;

case ALGO_SHA256D:
Expand Down Expand Up @@ -1167,6 +1192,18 @@ static void *miner_thread(void *userdata) {
rc = scanhash_x11(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_X13:
rc = scanhash_x13(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_X14:
rc = scanhash_x14(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_X15:
rc = scanhash_x15(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_CRYPTONIGHT:
rc = scanhash_cryptonight(thr_id, work.data, work.target,
max_nonce, &hashes_done);
Expand All @@ -1178,12 +1215,12 @@ static void *miner_thread(void *userdata) {
}

/* record scanhash elapsed time */
gettimeofday(&tv_end, NULL );
gettimeofday(&tv_end, NULL);
timeval_subtract(&diff, &tv_end, &tv_start);
if (diff.tv_usec || diff.tv_sec) {
pthread_mutex_lock(&stats_lock);
thr_hashrates[thr_id] = hashes_done
/ (diff.tv_sec + 1e-6 * diff.tv_usec);
thr_hashrates[thr_id] =
hashes_done / (diff.tv_sec + diff.tv_usec * 1e-6);
pthread_mutex_unlock(&stats_lock);
}
if (!opt_quiet) {
Expand All @@ -1194,8 +1231,8 @@ static void *miner_thread(void *userdata) {
break;
default:
sprintf(s, thr_hashrates[thr_id] >= 1e6 ? "%.0f" : "%.2f",
1e-3 * thr_hashrates[thr_id]);
applog(LOG_INFO, "thread %d: %lu hashes, %.2f khash/s", thr_id,
thr_hashrates[thr_id] / 1e3);
applog(LOG_INFO, "thread %d: %llu hashes, %s khash/s", thr_id,
hashes_done, s);
break;
}
Expand All @@ -1210,7 +1247,7 @@ static void *miner_thread(void *userdata) {
applog(LOG_INFO, "Total: %s H/s", hashrate);
break;
default:
sprintf(s, hashrate >= 1e6 ? "%.0f" : "%.2f", 1e-3 * hashrate);
sprintf(s, hashrate >= 1e6 ? "%.0f" : "%.2f", hashrate / 1000);
applog(LOG_INFO, "Total: %s khash/s", s);
break;
}
Expand Down Expand Up @@ -1459,13 +1496,13 @@ static void *stratum_thread(void *userdata) {

static void show_version_and_exit(void) {
printf(PACKAGE_STRING "\n built on " __DATE__ "\n features:"
#if defined(__i386__)
#if defined(USE_ASM) && defined(__i386__)
" i386"
#endif
#if defined(__x86_64__)
#if defined(USE_ASM) && defined(__x86_64__)
" x86_64"
#endif
#if defined(__i386__) || defined(__x86_64__)
#if defined(USE_ASM) && defined(__i386__) || defined(__x86_64__)
" SSE2"
#endif
#if defined(__x86_64__) && defined(USE_AVX)
Expand All @@ -1477,7 +1514,7 @@ static void show_version_and_exit(void) {
#if defined(__x86_64__) && defined(USE_XOP)
" XOP"
#endif
#if defined(__arm__) && defined(__APCS_32__)
#if defined(USE_ASM) && defined(__arm__) && defined(__APCS_32__)
" ARM"
#if defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || \
defined(__ARM_ARCH_5TEJ__) || defined(__ARM_ARCH_6__) || \
Expand Down Expand Up @@ -1518,9 +1555,21 @@ static void parse_arg(int key, char *arg) {
switch (key) {
case 'a':
for (i = 0; i < ARRAY_SIZE(algo_names); i++) {
if (algo_names[i] && !strcmp(arg, algo_names[i])) {
opt_algo = i;
break;
v = strlen(algo_names[i]);
if (!strncmp(arg, algo_names[i], v)) {
if (arg[v] == '\0') {
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
2 changes: 1 addition & 1 deletion cryptonight.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void cryptonight_hash_ctx_aes_ni(void* output, const void* input, size_t len, st
}

int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done) {
uint32_t max_nonce, uint64_t *hashes_done) {
uint32_t *nonceptr = (uint32_t*) (((char*)pdata) + 39);
uint32_t n = *nonceptr - 1;
const uint32_t first_nonce = n + 1;
Expand Down
2 changes: 1 addition & 1 deletion heavy.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void heavycoin_hash(unsigned char* output, const unsigned char* input, int len)
}

int scanhash_heavy(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done)
uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t hash[8];
uint32_t start_nonce = pdata[19];
Expand Down
2 changes: 1 addition & 1 deletion ink.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void inkhash(void *state, const void *input)
}

int scanhash_ink(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done)
uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t n = pdata[19] - 1;
const uint32_t first_nonce = pdata[19];
Expand Down
Loading

0 comments on commit d971882

Please sign in to comment.