diff --git a/algorithm.c b/algorithm.c index 406a84c6..b53fd297 100644 --- a/algorithm.c +++ b/algorithm.c @@ -951,7 +951,7 @@ static cl_int queue_blake_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_un static algorithm_settings_t algos[] = { // kernels starting from this will have difficulty calculated by using litecoin algorithm #define A_SCRYPT(a) \ - { a, ALGO_SCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFFFFFFULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, scrypt_regenhash, queue_scrypt_kernel, gen_hash, append_scrypt_compiler_options } + { a, ALGO_SCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFFFFFFULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, scrypt_regenhash, NULL, queue_scrypt_kernel, gen_hash, append_scrypt_compiler_options } A_SCRYPT("ckolivas"), A_SCRYPT("alexkarnew"), A_SCRYPT("alexkarnold"), @@ -962,33 +962,33 @@ static algorithm_settings_t algos[] = { #undef A_SCRYPT #define A_NEOSCRYPT(a) \ - { a, ALGO_NEOSCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, neoscrypt_regenhash, queue_neoscrypt_kernel, gen_hash, append_neoscrypt_compiler_options } + { a, ALGO_NEOSCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, neoscrypt_regenhash, NULL, queue_neoscrypt_kernel, gen_hash, append_neoscrypt_compiler_options } A_NEOSCRYPT("neoscrypt"), #undef A_NEOSCRYPT #define A_PLUCK(a) \ - { a, ALGO_PLUCK, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, pluck_regenhash, queue_pluck_kernel, gen_hash, append_neoscrypt_compiler_options } + { a, ALGO_PLUCK, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, pluck_regenhash, NULL, queue_pluck_kernel, gen_hash, append_neoscrypt_compiler_options } A_PLUCK("pluck"), #undef A_PLUCK #define A_CREDITS(a) \ - { a, ALGO_CRE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, credits_regenhash, queue_credits_kernel, gen_hash, NULL} + { a, ALGO_CRE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, credits_regenhash, NULL, queue_credits_kernel, gen_hash, NULL} A_CREDITS("credits"), #undef A_CREDITS #define A_YESCRYPT(a) \ - { a, ALGO_YESCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, yescrypt_regenhash, queue_yescrypt_kernel, gen_hash, append_neoscrypt_compiler_options} + { a, ALGO_YESCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, yescrypt_regenhash, NULL, queue_yescrypt_kernel, gen_hash, append_neoscrypt_compiler_options} A_YESCRYPT("yescrypt"), #undef A_YESCRYPT #define A_YESCRYPT_MULTI(a) \ - { a, ALGO_YESCRYPT_MULTI, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 6,-1,CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE , yescrypt_regenhash, queue_yescrypt_multikernel, gen_hash, append_neoscrypt_compiler_options} + { a, ALGO_YESCRYPT_MULTI, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 6,-1,CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE , yescrypt_regenhash, NULL, queue_yescrypt_multikernel, gen_hash, append_neoscrypt_compiler_options} A_YESCRYPT_MULTI("yescrypt-multi"), #undef A_YESCRYPT_MULTI // kernels starting from this will have difficulty calculated by using quarkcoin algorithm #define A_QUARK(a, b) \ - { a, ALGO_QUARK, "", 256, 256, 256, 0, 0, 0xFF, 0xFFFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, gen_hash, append_x11_compiler_options } + { a, ALGO_QUARK, "", 256, 256, 256, 0, 0, 0xFF, 0xFFFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, NULL, queue_sph_kernel, gen_hash, append_x11_compiler_options } A_QUARK("quarkcoin", quarkcoin_regenhash), A_QUARK("qubitcoin", qubitcoin_regenhash), A_QUARK("animecoin", animecoin_regenhash), @@ -997,48 +997,48 @@ static algorithm_settings_t algos[] = { // kernels starting from this will have difficulty calculated by using bitcoin algorithm #define A_DARK(a, b) \ - { a, ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, gen_hash, append_x11_compiler_options } + { a, ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, NULL, queue_sph_kernel, gen_hash, append_x11_compiler_options } A_DARK("darkcoin", darkcoin_regenhash), A_DARK("inkcoin", inkcoin_regenhash), A_DARK("myriadcoin-groestl", myriadcoin_groestl_regenhash), #undef A_DARK - { "twecoin", ALGO_TWE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, twecoin_regenhash, queue_sph_kernel, sha256, NULL }, - { "maxcoin", ALGO_KECCAK, "", 1, 256, 1, 4, 15, 0x0F, 0xFFFFULL, 0x000000ffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, maxcoin_regenhash, queue_maxcoin_kernel, sha256, NULL }, + { "twecoin", ALGO_TWE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, twecoin_regenhash, NULL, queue_sph_kernel, sha256, NULL }, + { "maxcoin", ALGO_KECCAK, "", 1, 256, 1, 4, 15, 0x0F, 0xFFFFULL, 0x000000ffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, maxcoin_regenhash, NULL, queue_maxcoin_kernel, sha256, NULL }, - { "darkcoin-mod", ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, darkcoin_regenhash, queue_darkcoin_mod_kernel, gen_hash, append_x11_compiler_options }, + { "darkcoin-mod", ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, darkcoin_regenhash, NULL, queue_darkcoin_mod_kernel, gen_hash, append_x11_compiler_options }, - { "marucoin", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, marucoin_regenhash, queue_sph_kernel, gen_hash, append_x13_compiler_options }, - { "marucoin-mod", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 12, 8 * 16 * 4194304, 0, marucoin_regenhash, queue_marucoin_mod_kernel, gen_hash, append_x13_compiler_options }, - { "marucoin-modold", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, marucoin_regenhash, queue_marucoin_mod_old_kernel, gen_hash, append_x13_compiler_options }, + { "marucoin", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, marucoin_regenhash, NULL, queue_sph_kernel, gen_hash, append_x13_compiler_options }, + { "marucoin-mod", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 12, 8 * 16 * 4194304, 0, marucoin_regenhash, NULL, queue_marucoin_mod_kernel, gen_hash, append_x13_compiler_options }, + { "marucoin-modold", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, marucoin_regenhash, NULL, queue_marucoin_mod_old_kernel, gen_hash, append_x13_compiler_options }, - { "x14", ALGO_X14, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 13, 8 * 16 * 4194304, 0, x14_regenhash, queue_x14_kernel, gen_hash, append_x13_compiler_options }, - { "x14old", ALGO_X14, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, x14_regenhash, queue_x14_old_kernel, gen_hash, append_x13_compiler_options }, + { "x14", ALGO_X14, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 13, 8 * 16 * 4194304, 0, x14_regenhash, NULL, queue_x14_kernel, gen_hash, append_x13_compiler_options }, + { "x14old", ALGO_X14, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, x14_regenhash, NULL, queue_x14_old_kernel, gen_hash, append_x13_compiler_options }, - { "bitblock", ALGO_X15, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 14, 4 * 16 * 4194304, 0, bitblock_regenhash, queue_bitblock_kernel, gen_hash, append_x13_compiler_options }, - { "bitblockold", ALGO_X15, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 4 * 16 * 4194304, 0, bitblock_regenhash, queue_bitblockold_kernel, gen_hash, append_x13_compiler_options }, + { "bitblock", ALGO_X15, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 14, 4 * 16 * 4194304, 0, bitblock_regenhash, NULL, queue_bitblock_kernel, gen_hash, append_x13_compiler_options }, + { "bitblockold", ALGO_X15, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 4 * 16 * 4194304, 0, bitblock_regenhash, NULL, queue_bitblockold_kernel, gen_hash, append_x13_compiler_options }, - { "talkcoin-mod", ALGO_NIST, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 8 * 16 * 4194304, 0, talkcoin_regenhash, queue_talkcoin_mod_kernel, gen_hash, append_x11_compiler_options }, + { "talkcoin-mod", ALGO_NIST, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 8 * 16 * 4194304, 0, talkcoin_regenhash, NULL, queue_talkcoin_mod_kernel, gen_hash, append_x11_compiler_options }, - { "fresh", ALGO_FRESH, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 4 * 16 * 4194304, 0, fresh_regenhash, queue_fresh_kernel, gen_hash, NULL }, + { "fresh", ALGO_FRESH, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 4 * 16 * 4194304, 0, fresh_regenhash, NULL, queue_fresh_kernel, gen_hash, NULL }, - { "lyra2re", ALGO_LYRA2RE, "", 1, 128, 128, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 2 * 8 * 4194304, 0, lyra2re_regenhash, queue_lyra2re_kernel, gen_hash, NULL }, - { "lyra2rev2", ALGO_LYRA2REV2, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 6, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, lyra2rev2_regenhash, queue_lyra2rev2_kernel, gen_hash, append_neoscrypt_compiler_options }, + { "lyra2re", ALGO_LYRA2RE, "", 1, 128, 128, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 2 * 8 * 4194304, 0, lyra2re_regenhash, precalc_hash_blake256, queue_lyra2re_kernel, gen_hash, NULL }, + { "lyra2rev2", ALGO_LYRA2REV2, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 6, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, lyra2rev2_regenhash, precalc_hash_blake256, queue_lyra2rev2_kernel, gen_hash, append_neoscrypt_compiler_options }, // kernels starting from this will have difficulty calculated by using fuguecoin algorithm #define A_FUGUE(a, b, c) \ - { a, ALGO_FUGUE, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, c, NULL } + { a, ALGO_FUGUE, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, NULL, queue_sph_kernel, c, NULL } A_FUGUE("fuguecoin", fuguecoin_regenhash, sha256), A_FUGUE("groestlcoin", groestlcoin_regenhash, sha256), A_FUGUE("diamond", groestlcoin_regenhash, gen_hash), #undef A_FUGUE - { "whirlcoin", ALGO_WHIRL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 3, 8 * 16 * 4194304, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, whirlcoin_regenhash, queue_whirlcoin_kernel, sha256, NULL }, - { "whirlpoolx", ALGO_WHIRLPOOLX, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000FFFFUL, 0, 0, 0, whirlpoolx_regenhash, queue_whirlpoolx_kernel, gen_hash, NULL }, + { "whirlcoin", ALGO_WHIRL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 3, 8 * 16 * 4194304, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, whirlcoin_regenhash, NULL, queue_whirlcoin_kernel, sha256, NULL }, + { "whirlpoolx", ALGO_WHIRLPOOLX, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000FFFFUL, 0, 0, 0, whirlpoolx_regenhash, NULL, queue_whirlpoolx_kernel, gen_hash, NULL }, - { "blake256r8", ALGO_BLAKECOIN, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, 0, blakecoin_regenhash, queue_blake_kernel, sha256, NULL }, - { "blake256r14", ALGO_BLAKE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x00000000UL, 0, 128, 0, blake256_regenhash, queue_blake_kernel, gen_hash, NULL }, - { "vanilla", ALGO_VANILLA, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, 0, blakecoin_regenhash, queue_blake_kernel, gen_hash, NULL }, + { "blake256r8", ALGO_BLAKECOIN, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, 0, blakecoin_regenhash, precalc_hash_blakecoin, queue_blake_kernel, sha256, NULL }, + { "blake256r14", ALGO_BLAKE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x00000000UL, 0, 128, 0, blake256_regenhash, precalc_hash_blake256, queue_blake_kernel, gen_hash, NULL }, + { "vanilla", ALGO_VANILLA, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, 0, blakecoin_regenhash, precalc_hash_blakecoin, queue_blake_kernel, gen_hash, NULL }, // Terminator (do not remove) { NULL, ALGO_UNK, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL } @@ -1069,6 +1069,7 @@ void copy_algorithm_settings(algorithm_t* dest, const char* algo) dest->rw_buffer_size = src->rw_buffer_size; dest->cq_properties = src->cq_properties; dest->regenhash = src->regenhash; + dest->precalc_hash = src->precalc_hash; dest->queue_kernel = src->queue_kernel; dest->gen_hash = src->gen_hash; dest->set_compile_options = src->set_compile_options; diff --git a/algorithm.h b/algorithm.h index c227b43d..afbd2f7a 100644 --- a/algorithm.h +++ b/algorithm.h @@ -70,6 +70,7 @@ typedef struct _algorithm_t { long rw_buffer_size; cl_command_queue_properties cq_properties; void(*regenhash)(struct work *); + void(*precalc_hash)(struct _dev_blk_ctx *, uint32_t *, uint32_t *); cl_int(*queue_kernel)(struct __clState *, struct _dev_blk_ctx *, cl_uint); void(*gen_hash)(const unsigned char *, unsigned int, unsigned char *); void(*set_compile_options)(struct _build_kernel_data *, struct cgpu_info *, struct _algorithm_t *); @@ -92,6 +93,7 @@ typedef struct _algorithm_settings_t long rw_buffer_size; cl_command_queue_properties cq_properties; void (*regenhash)(struct work *); + void (*precalc_hash)(struct _dev_blk_ctx *, uint32_t *, uint32_t *); cl_int (*queue_kernel)(struct __clState *, struct _dev_blk_ctx *, cl_uint); void (*gen_hash)(const unsigned char *, unsigned int, unsigned char *); void (*set_compile_options)(build_kernel_data *, struct cgpu_info *, algorithm_t *); diff --git a/algorithm/blake256.c b/algorithm/blake256.c index e347bc23..ddd86122 100644 --- a/algorithm/blake256.c +++ b/algorithm/blake256.c @@ -62,9 +62,33 @@ inline void blake256hash(void *state, const void *input) sph_blake256_close(&ctx_blake, state); } -static const uint32_t diff1targ = 0x0000ffff; +void precalc_hash_blake256(dev_blk_ctx *blk, uint32_t *state, uint32_t *pdata) +{ + sph_blake256_context ctx_blake; + uint32_t data[16]; + + be32enc_vect(data, (const uint32_t *)pdata, 16); + + sph_blake256_init(&ctx_blake); + sph_blake256(&ctx_blake, data, 64); + + blk->ctx_a = ctx_blake.H[0]; + blk->ctx_b = ctx_blake.H[1]; + blk->ctx_c = ctx_blake.H[2]; + blk->ctx_d = ctx_blake.H[3]; + blk->ctx_e = ctx_blake.H[4]; + blk->ctx_f = ctx_blake.H[5]; + blk->ctx_g = ctx_blake.H[6]; + blk->ctx_h = ctx_blake.H[7]; + + blk->cty_a = pdata[16]; + blk->cty_b = pdata[17]; + blk->cty_c = pdata[18]; +} +static const uint32_t diff1targ = 0x0000ffff; + /* Used externally as confirmation of correct OCL code */ int blake256_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce) { diff --git a/algorithm/blake256.h b/algorithm/blake256.h index 535a7399..f021585d 100644 --- a/algorithm/blake256.h +++ b/algorithm/blake256.h @@ -4,6 +4,7 @@ #include "miner.h" extern int blake256_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce); +extern void precalc_hash_blake256(dev_blk_ctx *blk, uint32_t *state, uint32_t *pdata); extern void blake256_regenhash(struct work *work); #endif /* BLAKE256_H */ \ No newline at end of file diff --git a/algorithm/blakecoin.c b/algorithm/blakecoin.c index 58974c91..6a118cef 100644 --- a/algorithm/blakecoin.c +++ b/algorithm/blakecoin.c @@ -62,9 +62,33 @@ inline void blakecoinhash(void *state, const void *input) sph_blake256r8_close(&ctx_blake, state); } -static const uint32_t diff1targ = 0x0000ffff; +void precalc_hash_blakecoin(dev_blk_ctx *blk, uint32_t *state, uint32_t *pdata) +{ + sph_blake256_context ctx_blake; + uint32_t data[16]; + + be32enc_vect(data, (const uint32_t *)pdata, 16); + + sph_blake256_init(&ctx_blake); + sph_blake256r8(&ctx_blake, data, 64); + + blk->ctx_a = ctx_blake.H[0]; + blk->ctx_b = ctx_blake.H[1]; + blk->ctx_c = ctx_blake.H[2]; + blk->ctx_d = ctx_blake.H[3]; + blk->ctx_e = ctx_blake.H[4]; + blk->ctx_f = ctx_blake.H[5]; + blk->ctx_g = ctx_blake.H[6]; + blk->ctx_h = ctx_blake.H[7]; + + blk->cty_a = pdata[16]; + blk->cty_b = pdata[17]; + blk->cty_c = pdata[18]; +} +static const uint32_t diff1targ = 0x0000ffff; + /* Used externally as confirmation of correct OCL code */ int blakecoin_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce) { diff --git a/algorithm/blakecoin.h b/algorithm/blakecoin.h index 28b9b3d7..dcaeff71 100644 --- a/algorithm/blakecoin.h +++ b/algorithm/blakecoin.h @@ -4,6 +4,7 @@ #include "miner.h" extern int blakecoin_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce); +extern void precalc_hash_blakecoin(dev_blk_ctx *blk, uint32_t *state, uint32_t *data); extern void blakecoin_regenhash(struct work *work); #endif /* BLAKECOIN_H */ \ No newline at end of file diff --git a/driver-opencl.c b/driver-opencl.c index e89cc350..0e368782 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -1366,20 +1366,8 @@ static bool opencl_thread_init(struct thr_info *thr) static bool opencl_prepare_work(struct thr_info __maybe_unused *thr, struct work *work) { - if (work->pool->algorithm.type == ALGO_LYRA2RE || - work->pool->algorithm.type == ALGO_LYRA2REV2 || - work->pool->algorithm.type == ALGO_BLAKE) { - work->blk.work = work; - precalc_hash_blake256(&work->blk, 0, (uint32_t *)(work->data), 14); - } - else if (work->pool->algorithm.type == ALGO_BLAKECOIN || - work->pool->algorithm.type == ALGO_VANILLA) { - work->blk.work = work; - precalc_hash_blake256(&work->blk, 0, (uint32_t *)(work->data), 8); - } - else { - work->blk.work = work; - } + work->blk.work = work; + if (work->pool->algorithm.precalc_hash) work->pool->algorithm.precalc_hash(&work->blk, 0, (uint32_t *)(work->data)); thr->pool_no = work->pool->pool_no; return true; } diff --git a/findnonce.c b/findnonce.c index 42af361f..72dcaaef 100644 --- a/findnonce.c +++ b/findnonce.c @@ -234,136 +234,3 @@ void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t *res) free(pcd); } } - -typedef struct -{ - uint32_t h[8]; - uint32_t t; -} blake_state256; - -int NB_ROUNDS32; - -const uint8_t blake_sigma[][16] = -{ - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, - { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }, - { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 }, - { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 }, - { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 }, - { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }, - { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 }, - { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 }, - { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 }, - { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 }, - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, - { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }, - { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 }, - { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 }, - { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 }, - { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } -}; - -const uint32_t blake_u256[16] = -{ - 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, - 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, - 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, - 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917 -}; - -#define ROT32(x,n) (((x)<<(32-n))|( (x)>>(n))) -//#define ROT32(x,n) (rotate((uint)x, (uint)32-n)) -#define ADD32(x,y) ((uint32_t)((x) + (y))) -#define XOR32(x,y) ((uint32_t)((x) ^ (y))) - -#define G(a,b,c,d,i) \ -do { \ - v[a] += XOR32(m[blake_sigma[r][i]], blake_u256[blake_sigma[r][i + 1]]) + v[b]; \ - v[d] = ROT32(XOR32(v[d], v[a]), 16); \ - v[c] += v[d]; \ - v[b] = ROT32(XOR32(v[b], v[c]), 12); \ - v[a] += XOR32(m[blake_sigma[r][i + 1]], blake_u256[blake_sigma[r][i]]) + v[b]; \ - v[d] = ROT32(XOR32(v[d], v[a]), 8); \ - v[c] += v[d]; \ - v[b] = ROT32(XOR32(v[b], v[c]), 7); \ -} while (0) - -// compress a block -void blake256_compress_block(blake_state256 *S, uint32_t *m) -{ - uint32_t v[16]; - int i, r; - for (i = 0; i < 8; ++i) v[i] = S->h[i]; - - v[8] = blake_u256[0]; - v[9] = blake_u256[1]; - v[10] = blake_u256[2]; - v[11] = blake_u256[3]; - v[12] = blake_u256[4]; - v[13] = blake_u256[5]; - v[14] = blake_u256[6]; - v[15] = blake_u256[7]; - - v[12] ^= S->t; - v[13] ^= S->t; - - for (r = 0; r < NB_ROUNDS32; ++r) - { - /* column step */ - G(0, 4, 8, 12, 0); - G(1, 5, 9, 13, 2); - G(2, 6, 10, 14, 4); - G(3, 7, 11, 15, 6); - /* diagonal step */ - G(0, 5, 10, 15, 8); - G(1, 6, 11, 12, 10); - G(2, 7, 8, 13, 12); - G(3, 4, 9, 14, 14); - } - - for (i = 0; i < 16; ++i) S->h[i & 7] ^= v[i]; -} - -void blake256_init(blake_state256 *S) -{ - S->h[0] = 0x6a09e667; - S->h[1] = 0xbb67ae85; - S->h[2] = 0x3c6ef372; - S->h[3] = 0xa54ff53a; - S->h[4] = 0x510e527f; - S->h[5] = 0x9b05688c; - S->h[6] = 0x1f83d9ab; - S->h[7] = 0x5be0cd19; - S->t = 0; -} - -void blake256_update(blake_state256 *S, const uint32_t *in) -{ - uint32_t m[16]; - int i; - S->t = 512; - for (i = 0; i < 16; ++i) m[i] = in[i]; - blake256_compress_block(S, m); -} - -void precalc_hash_blake256(dev_blk_ctx *blk, uint32_t *state, uint32_t *data, int blake256_rounds) -{ - NB_ROUNDS32 = blake256_rounds; - - blake_state256 S; - blake256_init(&S); - blake256_update(&S, data); - - blk->ctx_a = S.h[0]; - blk->ctx_b = S.h[1]; - blk->ctx_c = S.h[2]; - blk->ctx_d = S.h[3]; - blk->ctx_e = S.h[4]; - blk->ctx_f = S.h[5]; - blk->ctx_g = S.h[6]; - blk->ctx_h = S.h[7]; - - blk->cty_a = data[16]; - blk->cty_b = data[17]; - blk->cty_c = data[18]; -} diff --git a/findnonce.h b/findnonce.h index e268ce1b..9376a57b 100644 --- a/findnonce.h +++ b/findnonce.h @@ -10,6 +10,5 @@ extern void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data); extern void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t *res); -extern void precalc_hash_blake256(dev_blk_ctx *blk, uint32_t *state, uint32_t *data, int blake256_rounds); #endif /*FINDNONCE_H*/