diff options
Diffstat (limited to 'minethd.cpp')
-rw-r--r-- | minethd.cpp | 122 |
1 files changed, 79 insertions, 43 deletions
diff --git a/minethd.cpp b/minethd.cpp index 90a6f31..cf26037 100644 --- a/minethd.cpp +++ b/minethd.cpp @@ -25,6 +25,7 @@ #include <cmath> #include <chrono> #include <thread> +#include <bitset> #include "console.h" #ifdef _WIN32 @@ -62,7 +63,7 @@ void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id) #include "executor.h" #include "minethd.h" #include "jconf.h" -#include "crypto/cryptonight.h" +#include "crypto/cryptonight_aesni.h" telemetry::telemetry(size_t iThd) { @@ -244,42 +245,29 @@ bool minethd::self_test() return false; } - bool bHasLp = ctx0->ctx_info[0] == 1 && ctx1->ctx_info[0] == 1; - size_t n = jconf::inst()->GetThreadCount(); - jconf::thd_cfg cfg; - for (size_t i = 0; i < n; i++) - { - jconf::inst()->GetThreadConfig(i, cfg); - - if(!bHasLp && cfg.bNoPrefetch) - { - printer::inst()->print_msg(L0, "Wrong config. You are running in slow memory mode with no_prefetch."); - cryptonight_free_ctx(ctx0); - cryptonight_free_ctx(ctx1); - return false; - } - } - unsigned char out[64]; bool bResult; - if(jconf::inst()->HaveHardwareAes()) - { - cryptonight_hash_ctx("This is a test", 14, out, ctx0); - bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; + cn_hash_fun hashf; + cn_hash_fun_dbl hashdf; - cryptonight_hash_ctx_np("This is a test", 14, out, ctx0); - bResult &= memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; + hashf = func_selector(jconf::inst()->HaveHardwareAes(), false, jconf::inst()->HaveMulx()); + hashf("This is a test", 14, out, ctx0); + bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; - cryptonight_double_hash_ctx("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1); - bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59" - "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0; - } - else - { - cryptonight_hash_ctx_soft("This is a test", 14, out, ctx0); - bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; - } + hashf = func_selector(jconf::inst()->HaveHardwareAes(), true, jconf::inst()->HaveMulx()); + hashf("This is a test", 14, out, ctx0); + bResult &= memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; + + hashdf = func_dbl_selector(jconf::inst()->HaveHardwareAes(), false, jconf::inst()->HaveMulx()); + hashdf("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1); + bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59" + "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0; + + hashdf = func_dbl_selector(jconf::inst()->HaveHardwareAes(), true, jconf::inst()->HaveMulx()); + hashdf("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1); + bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59" + "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0; cryptonight_free_ctx(ctx0); cryptonight_free_ctx(ctx1); @@ -350,21 +338,48 @@ void minethd::consume_work() iConsumeCnt++; } +minethd::cn_hash_fun minethd::func_selector(bool bHaveAes, bool bNoPrefetch, bool bMulx) +{ + // We have three independent flag bits in the functions + // therefore we will build a binary digit and select the + // function as a three digit binary + // Digit order SOFT_AES, NO_PREFETCH, MULX + + static const cn_hash_fun func_table[8] = { + cryptonight_hash<0x80000, MEMORY, false, false, false>, + cryptonight_hash<0x80000, MEMORY, false, false, true>, + cryptonight_hash<0x80000, MEMORY, false, true, false>, + cryptonight_hash<0x80000, MEMORY, false, true, true>, + cryptonight_hash<0x80000, MEMORY, true, false, false>, + cryptonight_hash<0x80000, MEMORY, true, false, true>, + cryptonight_hash<0x80000, MEMORY, true, true, false>, + cryptonight_hash<0x80000, MEMORY, true, true, true> + }; + + std::bitset<3> digit; + digit.set(0, bMulx); + digit.set(1, bNoPrefetch); + digit.set(2, !bHaveAes); + + return func_table[digit.to_ulong()]; +} + void minethd::work_main() { + cn_hash_fun hash_fun; cryptonight_ctx* ctx; uint64_t iCount = 0; uint64_t* piHashVal; uint32_t* piNonce; job_result result; + hash_fun = func_selector(jconf::inst()->HaveHardwareAes(), bNoPrefetch, jconf::inst()->HaveMulx()); ctx = minethd_alloc_ctx(); piHashVal = (uint64_t*)(result.bResult + 24); piNonce = (uint32_t*)(oWork.bWorkBlob + 39); iConsumeCnt++; - bool bHaveAes = jconf::inst()->HaveHardwareAes(); while (bQuit == 0) { if (oWork.bStall) @@ -401,15 +416,7 @@ void minethd::work_main() *piNonce = ++result.iNonce; - if(bHaveAes) - { - if(bNoPrefetch) - cryptonight_hash_ctx_np(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx); - else - cryptonight_hash_ctx(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx); - } - else - cryptonight_hash_ctx_soft(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx); + hash_fun(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx); if (*piHashVal < oWork.iTarget) executor::inst()->push_event(ex_event(result, oWork.iPoolId)); @@ -423,8 +430,35 @@ void minethd::work_main() cryptonight_free_ctx(ctx); } +minethd::cn_hash_fun_dbl minethd::func_dbl_selector(bool bHaveAes, bool bNoPrefetch, bool bMulx) +{ + // We have three independent flag bits in the functions + // therefore we will build a binary digit and select the + // function as a three digit binary + // Digit order SOFT_AES, NO_PREFETCH, MULX + + static const cn_hash_fun_dbl func_table[8] = { + cryptonight_double_hash<0x80000, MEMORY, false, false, false>, + cryptonight_double_hash<0x80000, MEMORY, false, false, true>, + cryptonight_double_hash<0x80000, MEMORY, false, true, false>, + cryptonight_double_hash<0x80000, MEMORY, false, true, true>, + cryptonight_double_hash<0x80000, MEMORY, true, false, false>, + cryptonight_double_hash<0x80000, MEMORY, true, false, true>, + cryptonight_double_hash<0x80000, MEMORY, true, true, false>, + cryptonight_double_hash<0x80000, MEMORY, true, true, true> + }; + + std::bitset<3> digit; + digit.set(0, bMulx); + digit.set(1, bNoPrefetch); + digit.set(2, !bHaveAes); + + return func_table[digit.to_ulong()]; +} + void minethd::double_work_main() { + cn_hash_fun_dbl hash_fun; cryptonight_ctx* ctx0; cryptonight_ctx* ctx1; uint64_t iCount = 0; @@ -435,6 +469,7 @@ void minethd::double_work_main() uint32_t iNonce; job_result res; + hash_fun = func_dbl_selector(jconf::inst()->HaveHardwareAes(), bNoPrefetch, jconf::inst()->HaveMulx()); ctx0 = minethd_alloc_ctx(); ctx1 = minethd_alloc_ctx(); @@ -484,7 +519,8 @@ void minethd::double_work_main() *piNonce0 = ++iNonce; *piNonce1 = ++iNonce; - cryptonight_double_hash_ctx(bDoubleWorkBlob, oWork.iWorkSize, bDoubleHashOut, ctx0, ctx1); + + hash_fun(bDoubleWorkBlob, oWork.iWorkSize, bDoubleHashOut, ctx0, ctx1); if (*piHashVal0 < oWork.iTarget) executor::inst()->push_event(ex_event(job_result(oWork.sJobID, iNonce-1, bDoubleHashOut), oWork.iPoolId)); |