Skip to content

Commit

Permalink
Add support for scrypt(N, 1, 1)
Browse files Browse the repository at this point in the history
Backport from cpuminer 2.4

Signed-off-by: Tanguy Pruvot <[email protected]>
  • Loading branch information
pooler authored and tpruvot committed Aug 2, 2014
1 parent 9119d7b commit c0841fb
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 156 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Algorithms
==========
#### Currently supported
*__scrypt__ (Litecoin, Dogecoin, Feathercoin, etc..)
*__scrypt:N__ (Vertcoin [VTC])
*__sha256d__ (Bitcoin, Freicoin, Peercoin/PPCoin, Terracoin, etc..)
*__x11__ (Darkcoin [DRK], Hirocoin, Limecoin)
*__cryptonight__ (Bytecoin [BCN], Monero)
Expand All @@ -34,7 +35,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
35 changes: 27 additions & 8 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 Down Expand Up @@ -144,7 +144,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 +193,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 Down Expand Up @@ -1047,7 +1049,12 @@ 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));

Expand Down Expand Up @@ -1106,7 +1113,7 @@ 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;
Expand All @@ -1128,7 +1135,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 @@ -1518,9 +1525,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
4 changes: 2 additions & 2 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ void sha256_transform_8way(uint32_t *state, const uint32_t *block, int swap);
extern int scanhash_sha256d(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);

extern unsigned char *scrypt_buffer_alloc();
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,
uint32_t max_nonce, unsigned long *hashes_done);
uint32_t max_nonce, unsigned long *hashes_done, int N);

extern int scanhash_keccak(int thr_id, uint32_t *pdata,
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);
Expand Down
3 changes: 3 additions & 0 deletions minerd.1
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ Possible values are:
.B scrypt
scrypt(1024, 1, 1) (used by Litecoin)
.TP
.B scrypt:\fIN\fR
scrypt(\fIN\fR, 1, 1) (\fIN\fR must be a power of 2 greater than 1)
.TP
.B sha256d
SHA-256d (used by Bitcoin)
.RE
Expand Down
85 changes: 49 additions & 36 deletions scrypt-arm.S
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012 [email protected]
* Copyright 2012, 2014 [email protected]
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
Expand Down Expand Up @@ -472,14 +472,16 @@ scrypt_core:
_scrypt_core:
stmfd sp!, {r4-r11, lr}
mov r12, sp
sub sp, sp, #21*4
sub sp, sp, #22*4
bic sp, sp, #63
str r12, [sp, #20*4]
str r2, [sp, #21*4]

scrypt_shuffle

ldr r2, [sp, #21*4]
str r0, [sp, #16*4]
add r12, r1, #1024*32*4
add r12, r1, r2, lsl #7
str r12, [sp, #18*4]
scrypt_core_loop1:
add lr, r0, #16*4
Expand Down Expand Up @@ -517,12 +519,14 @@ scrypt_core_loop1:
cmp r1, r12
bne scrypt_core_loop1

ldr r12, [sp, #21*4]
ldr r4, [r0, #16*4]
sub r1, r1, #1024*32*4
sub r2, r12, #1
str r2, [sp, #21*4]
sub r1, r1, r12, lsl #7
str r1, [sp, #17*4]
mov r4, r4, lsl #32-10
mov r12, #1024
add r1, r1, r4, lsr #32-10-7
and r4, r4, r2
add r1, r1, r4, lsl #7
scrypt_core_loop2:
add r2, r0, #16*4
add r3, r1, #16*4
Expand Down Expand Up @@ -553,9 +557,10 @@ scrypt_core_loop2:
mov r1, sp
ldr r3, [sp, #17*4]
add r0, r0, #16*4
ldr r2, [sp, #21*4]
scrypt_core_macro3_x4
mov r4, r4, lsl #32-10
add r3, r3, r4, lsr #32-10-7
and r4, r4, r2
add r3, r3, r4, lsl #7
str r3, [sp, #19*4]
#ifdef __ARM_ARCH_5E_OR_6_OR_7__
pld [r3, #16*4]
Expand Down Expand Up @@ -794,10 +799,11 @@ _scrypt_core_3way:
mov r12, sp
sub sp, sp, #24*16
bic sp, sp, #63
str r12, [sp, #4*16+3*4]
str r2, [sp, #4*16+3*4]
str r12, [sp, #4*16+4*4]

mov r2, r0
vldmia r2!, {q8-q15}
mov r3, r0
vldmia r3!, {q8-q15}
vmov.u64 q0, #0xffffffff
vmov.u32 q1, q8
vmov.u32 q2, q12
Expand All @@ -809,7 +815,7 @@ _scrypt_core_3way:
vbif.u32 q14, q15, q0
vbif.u32 q11, q1, q0
vbif.u32 q15, q2, q0
vldmia r2!, {q0-q7}
vldmia r3!, {q0-q7}
vswp.u32 d17, d21
vswp.u32 d25, d29
vswp.u32 d18, d22
Expand All @@ -826,7 +832,7 @@ _scrypt_core_3way:
vbif.u32 q6, q7, q8
vbif.u32 q3, q9, q8
vbif.u32 q7, q10, q8
vldmia r2, {q8-q15}
vldmia r3, {q8-q15}
vswp.u32 d1, d5
vswp.u32 d9, d13
vswp.u32 d2, d6
Expand All @@ -852,7 +858,7 @@ _scrypt_core_3way:

add lr, sp, #128
vldmia lr, {q0-q7}
add r2, r1, #1024*32*4
add r2, r1, r2, lsl #7
str r0, [sp, #4*16+0*4]
str r2, [sp, #4*16+2*4]
scrypt_core_3way_loop1:
Expand All @@ -863,12 +869,13 @@ scrypt_core_3way_loop1:
scrypt_core_macro1a_x4
scrypt_core_macro1a_x4
scrypt_core_macro1a_x4
ldr r2, [sp, #4*16+3*4]
scrypt_core_macro1a_x4
sub r1, r1, #4*16

add r1, r1, #1024*32*4
add r1, r1, r2, lsl #7
vstmia r1, {q0-q7}
add r3, r1, #1024*32*4
add r3, r1, r2, lsl #7
vstmia r3, {q8-q15}

add lr, sp, #128
Expand Down Expand Up @@ -957,20 +964,22 @@ scrypt_core_3way_loop1:
cmp r1, r2
bne scrypt_core_3way_loop1

ldr r2, [sp, #4*16+3*4]
add r5, sp, #256+4*16
vstmia r5, {q12-q15}

sub r1, r1, #1024*32*4
sub r1, r1, r2, lsl #7
str r1, [sp, #4*16+1*4]
mov r2, #1024
scrypt_core_3way_loop2:
str r2, [sp, #4*16+2*4]

ldr r0, [sp, #4*16+0*4]
ldr r1, [sp, #4*16+1*4]
ldr r2, [sp, #4*16+3*4]
ldr r4, [r0, #16*4]
mov r4, r4, lsl #32-10
add r1, r1, r4, lsr #32-10-7
sub r2, r2, #1
and r4, r4, r2
add r1, r1, r4, lsl #7
add r2, r0, #16*4
add r3, r1, #16*4
mov r12, sp
Expand All @@ -980,29 +989,31 @@ scrypt_core_3way_loop2:
scrypt_core_macro1b_x4

ldr r1, [sp, #4*16+1*4]
add r1, r1, #1024*32*4
add r3, r1, #1024*32*4
ldr r2, [sp, #4*16+3*4]
add r1, r1, r2, lsl #7
add r3, r1, r2, lsl #7
sub r2, r2, #1
vmov r6, r7, d8
mov r6, r6, lsl #32-10
add r6, r1, r6, lsr #32-10-7
and r6, r6, r2
add r6, r1, r6, lsl #7
vmov r7, r8, d24
add lr, sp, #128
vldmia lr, {q0-q3}
pld [r6]
pld [r6, #8*4]
pld [r6, #8*4]
pld [r6, #16*4]
pld [r6, #24*4]
pld [r6, #24*4]
vldmia r6, {q8-q15}
mov r7, r7, lsl #32-10
add r7, r3, r7, lsr #32-10-7
and r7, r7, r2
add r7, r3, r7, lsl #7
veor.u32 q8, q8, q0
veor.u32 q9, q9, q1
veor.u32 q10, q10, q2
veor.u32 q11, q11, q3
pld [r7]
pld [r7, #8*4]
pld [r7, #8*4]
pld [r7, #16*4]
pld [r7, #24*4]
pld [r7, #24*4]
veor.u32 q12, q12, q4
veor.u32 q13, q13, q5
veor.u32 q14, q14, q6
Expand Down Expand Up @@ -1079,15 +1090,17 @@ scrypt_core_3way_loop2:

ldr r0, [sp, #4*16+0*4]
ldr r3, [sp, #4*16+1*4]
ldr r2, [sp, #4*16+3*4]
mov r1, sp
add r0, r0, #16*4
sub r2, r2, #1
scrypt_core_macro3_x4
mov r4, r4, lsl #32-10
add r3, r3, r4, lsr #32-10-7
and r4, r4, r2
add r3, r3, r4, lsl #7
pld [r3, #16*4]
pld [r3]
pld [r3, #24*4]
pld [r3, #8*4]
pld [r3, #24*4]
pld [r3, #8*4]
scrypt_core_macro3_x6
scrypt_core_macro3_x6

Expand Down Expand Up @@ -1164,7 +1177,7 @@ scrypt_core_3way_loop2:
vswp.u32 d26, d30
vstmia r0, {q8-q15}

ldr sp, [sp, #4*16+3*4]
ldr sp, [sp, #4*16+4*4]
vpop {q4-q7}
ldmfd sp!, {r4-r11, pc}

Expand Down
Loading

0 comments on commit c0841fb

Please sign in to comment.