From dc0347e4ca084e7639486df8013694bf9f8e47de Mon Sep 17 00:00:00 2001 From: VIP21 <31809608+VIP21@users.noreply.github.com> Date: Tue, 2 Oct 2018 09:00:05 -0700 Subject: [PATCH 001/102] Add files via upload --- simplemultialgo-master.zip | Bin 0 -> 3805 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 simplemultialgo-master.zip diff --git a/simplemultialgo-master.zip b/simplemultialgo-master.zip new file mode 100644 index 0000000000000000000000000000000000000000..0fcbea30cebc5f6a933a2047f8cffc2ca7e309a0 GIT binary patch literal 3805 zcma)ox_I*gUP!h5YGxm@P89Rw+41=+beM@#8*=0?(WXl>^vnOkI4cW_< zC1uG@~h-&;c&?+gjx`v7t(-1z(BpVv76F~G^v z#vY5YaltxUqOs<7d^Tt&XN;r3Ep2=N5LZc~qw!BP(cjVA4I7&|$ICvNfU&MaBcKztLzI3uK)@h4xxdi9%g4{v`CIZKH1+yxk%ZG z?{3sSAc+hF(JSlFM7<+QNwXn9lFKC{6-iSFZdcEKo>Y`B%>UL&=dPVcQWL|?+el|C zeJ%x^W$dZpk_r8csdIYPtFGd}N*^+8BGj0ZaL`Gqj#cdsN^7ZGeE_}J@OE=St$WnY z=fGh5OlexnRYuPF1aGP%#D|sx3B)(N-&1~-^MpnII9+KF0C3^YDO;M`+Bsr=rt78I zWz`I!s{6!4H+J)h)jm+_1F>IJoYleX);bZv-#pk;wXBa;(gq+ z2@YSO3P92xEN?Fj_Zd^OF(X%2*Q^YSKBA4!>)wkAo85t_1N;3%QfgBntSuo3w zwvr81_7p4}p~jY_VuCw|G&V0}_-)xQ(s7rC?u=74@T$o>{}tX>H(cdxkmxu)ZhRCX zm*2z-m9q-O`F$BMeJx}dG!jgt@K*KAv=m9F-?Xk=Dg1giyzB0?!63u>+CD5*$omqt zqbkBQj|d}C6r&AKkGK*z5^#yuK_#s}3%`3vz=TjYdE=8gZ`3jb#asc&J%aT_TGX-2 zN@2B(J8IVga_oNJj49j5XwTz~5Iyt9%}_yHmsh(f&u?S;b2ALIlpl;is2aZNhKnsL zQF|%YZ_cZBw^;?VxAV@?gRdh4>06 C?|8YR7fp@Qq#6?4$Qh`ixvi>vp4QVAzc| zEg$dHiIN9v{nAateTEIPAx!Qx`~U*RtNhfl}F*4mpgW8cxz?aB=B9V*m35_sJ-{`t)Qb zdL&H`RR|+?Xz-Vi9zOe`A*7$}6BXjhp-(sNmg;>;uwi$xIGhT4Wyr1nsl8V-V=YxM zAk%EsXI#8%+2IE3o24F*RO8<4t<}ta(Pn^$hYbDFjC=CS8I?<{7p3d03B8cuq?pD^B`T%}E z!=)_Lm14&iO5gEhJN-h@l9!cJ{p|?LYpPl|L&)kEbctLo)16lNOu})p>ElXe^x3enR?4bp6&3)>Tbuw?!(w+xX_@aeH+u{*;b0N&u0^- z{O%$8E#bl3<@Zf(3e%~>?XEjIw!M}x1?}AkVDrL5+*D&pf4IbiyjDZ~e2ttZG~@I2 zO7cNQZTn~j&c?6Cgl&KkM#4OURWc@uZ0fB_~tsFt(g z7Xo70?^voxs@eFH5*TLZUJ*vT`<5c;B;!x61P)_li7tWL0CT1kqEyScwbd$d;C2$> zK*cc2=l<{7_jXS$(Ls2%fT}{hL z7$K!FvGL6GX~Ca0@q83tk<2fW?IybV4fK2Y!TpDw#m5r1emwtBe#~9;cVXl=`FVq= zMs|HyFZtmfT{2*HJT~-67*0TwxCAk7lr(rXOMid$X|#UJ@gO|})BK{jXoAm-Us&-qaoStJqql*jL7+dBU5S<3)r+IH~(fC1t^3b(BV-w#7@>;w2Mex@F;qiQ#< zKqYnarEwumc5Y0c(nJOqa?p3W%9Z8`7m2ZaQC5T^e@Sh525iM{HQ7Kbi%U|Lvb1B= zedEjgvSL`PzjtxAxCUlZU%W)C+K~`v4R(+0Q(&5_4CFAtr7F$YHQ6HK7#KcU-Hf>c z-AjB&YV%G|kzaDrv;10&2U_kzD$Mocq|YLA44BguA;ZM(IbW(^RYjLit7c}JsyWxD zg?&-e3)M$-ZlM^J0^?)%^y(@UQ$-GgBk)m`F+ybvkF@dg6TyNSyK7CRfWFTVIG{3|Yjsb$YA786qsNiS z*M5v%?pRFI-0TVpx|5XAaInm^Z|aiRh!@vwkwnaCgf(9Fee9>kIRe!NNa?kJ)ScxM zQj0|iy$t<`nb{m>yJt6gGlR=!5|22vM)24=TWP8?0nEFOD)E=OZMC~?p^SE^1)m*D zMpkz=9=>+Z4-3p4RM+UzG1tXIE#xCVed#6zQb(#Mq>z{dK|aK^&sBD61p}vfa&0KL z{e5-7qInF(-Hk0eaG+k>P(`o9vt4f8Y*S#iL~LPwKoR-gCC;95#CB+!9=3X{8C>KUmmf$d)BE+qhuxy_7@JfwwlTC7pex**(Vhh|FZ6W7WMXZ z9^1u<7gEFC69}Co&Z{(RR4x}FJbIzvhadx_(Ov6M0Z0t74eVYFrftB)z5F_^KwZcM z^%5m%!p=9s>Lh+d+GEy8hJ7Q2t=i>tEgHQFaG)xd2QEqgz~}o);{pYBR@c0%6jNbh$UG{M-oarZ**4*6Ou- zU7^A0EQAb)BhS>;Z#R!v9-$2ya55C*D;~?xtV!v~g$S5~$K4^H!O3pH2~HrRy%!z5 zmp}3Bo^7$0%Gdhmq;2L$ZkQ}00`K+(cNpBO%YM1mu8=FKQh>;zFj>^ESUff_+8PB% zn!k`8K!%nU9gw6xciUhuELdD#+>_Bz1|FNO)0>AMeFW8y<^O0U{!9Dc&BS-iu_hi5 z>En4yV{%Gs@#{~2uur=7@6;b`!Q=PdTB=@8N{l#rKuGA^q|6xZ@a!;CqUtE9u zQ@Q`P2q&>8#qJjtNO&st-_myyds0n)VRuf)o}w)p%J>A|;|Y%+)8iUSk^ul*05b^M nL>Ph=go=rYL0}@rqA)QtGz0<@G(($+i=c&IP&5=`A_n~r%4R)F literal 0 HcmV?d00001 From de189ef83a1dfe82b546c2feff226bac39a95007 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 19 May 2018 14:44:50 +0700 Subject: [PATCH 002/102] Sync changes with proxy. --- src/common/net/Client.h | 22 ++++++++++++---------- src/common/net/Pool.cpp | 35 +++++++++++++++++++++++++---------- src/common/net/Pool.h | 2 ++ 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/common/net/Client.h b/src/common/net/Client.h index 27273092c8..4be8badba2 100644 --- a/src/common/net/Client.h +++ b/src/common/net/Client.h @@ -30,6 +30,7 @@ #include +#include "common/crypto/Algorithm.h" #include "common/net/Id.h" #include "common/net/Job.h" #include "common/net/Pool.h" @@ -66,16 +67,17 @@ class Client void setPool(const Pool &pool); void tick(uint64_t now); - inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; } - inline const char *host() const { return m_pool.host(); } - inline const char *ip() const { return m_ip; } - inline const Job &job() const { return m_job; } - inline int id() const { return m_id; } - inline SocketState state() const { return m_state; } - inline uint16_t port() const { return m_pool.port(); } - inline void setQuiet(bool quiet) { m_quiet = quiet; } - inline void setRetries(int retries) { m_retries = retries; } - inline void setRetryPause(int ms) { m_retryPause = ms; } + inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; } + inline const char *host() const { return m_pool.host(); } + inline const char *ip() const { return m_ip; } + inline const Job &job() const { return m_job; } + inline int id() const { return m_id; } + inline SocketState state() const { return m_state; } + inline uint16_t port() const { return m_pool.port(); } + inline void setAlgo(const xmrig::Algorithm &algo) { m_pool.setAlgo(algo); } + inline void setQuiet(bool quiet) { m_quiet = quiet; } + inline void setRetries(int retries) { m_retries = retries; } + inline void setRetryPause(int ms) { m_retryPause = ms; } private: enum Extensions { diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index ca73b3158a..c12e05d559 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -247,17 +247,15 @@ void Pool::adjust(xmrig::Algo algorithm) m_algorithm.setVariant(xmrig::VARIANT_1); } - m_algorithms.push_back(m_algorithm); + rebuild(); +} -# ifndef XMRIG_PROXY_PROJECT - if (m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { - addVariant(xmrig::VARIANT_1); - addVariant(xmrig::VARIANT_0); - addVariant(xmrig::VARIANT_XTL); - addVariant(xmrig::VARIANT_IPBC); - addVariant(xmrig::VARIANT_AUTO); - } -# endif + +void Pool::setAlgo(const xmrig::Algorithm &algorithm) +{ + m_algorithm = algorithm; + + rebuild(); } @@ -309,3 +307,20 @@ void Pool::addVariant(xmrig::Variant variant) m_algorithms.push_back(algorithm); } + + +void Pool::rebuild() +{ + m_algorithms.clear(); + m_algorithms.push_back(m_algorithm); + +# ifndef XMRIG_PROXY_PROJECT + if (m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { + addVariant(xmrig::VARIANT_1); + addVariant(xmrig::VARIANT_0); + addVariant(xmrig::VARIANT_XTL); + addVariant(xmrig::VARIANT_IPBC); + addVariant(xmrig::VARIANT_AUTO); + } +# endif +} diff --git a/src/common/net/Pool.h b/src/common/net/Pool.h index ad015bf2c8..eaabe54d34 100644 --- a/src/common/net/Pool.h +++ b/src/common/net/Pool.h @@ -78,6 +78,7 @@ class Pool bool setUserpass(const char *userpass); rapidjson::Value toJSON(rapidjson::Document &doc) const; void adjust(xmrig::Algo algorithm); + void setAlgo(const xmrig::Algorithm &algorithm); # ifdef APP_DEBUG void print() const; @@ -86,6 +87,7 @@ class Pool private: bool parseIPv6(const char *addr); void addVariant(xmrig::Variant variant); + void rebuild(); bool m_nicehash; int m_keepAlive; From 512d1a59c645dea3f30e400501acb869691b516e Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 20 May 2018 14:27:46 +0700 Subject: [PATCH 003/102] Small fix in CMakeLists.txt. --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b26b1d93ab..c71309c35d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,6 @@ set(HEADERS src/common/utils/c_str.h src/common/utils/mm_malloc.h src/common/xmrig.h - src/core/Config.cpp src/core/ConfigLoader_platform.h src/core/Controller.h src/Cpu.h From a21ece7fc5039d39bcdadcedadda2f5178bde0b2 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 1 Jun 2018 01:48:31 +0700 Subject: [PATCH 004/102] Sync changes with amd miner and update summary. --- CMakeLists.txt | 5 +-- src/Summary.cpp | 65 +++++++++++++++------------- src/common/config/CommonConfig.cpp | 68 +++++++++++++++--------------- src/common/config/CommonConfig.h | 3 +- src/common/xmrig.h | 6 +++ src/core/Config.cpp | 2 +- src/workers/Hashrate.cpp | 16 +++++-- src/workers/Hashrate.h | 6 ++- 8 files changed, 97 insertions(+), 74 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c71309c35d..a242970bc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ project(xmrig) option(WITH_LIBCPUID "Use Libcpuid" ON) option(WITH_AEON "CryptoNight-Lite support" ON) option(WITH_SUMO "CryptoNight-Heavy support" ON) -option(WITH_IPBC "CryptoNight-IPBC support" ON) option(WITH_HTTPD "HTTP REST API" ON) option(BUILD_STATIC "Build static binary" OFF) @@ -245,5 +244,5 @@ if (BUILD_STATIC) set(CMAKE_EXE_LINKER_FLAGS " -static") endif() -add_executable(xmrig ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES}) -target_link_libraries(xmrig ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) +add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES}) +target_link_libraries(${PROJECT_NAME} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) diff --git a/src/Summary.cpp b/src/Summary.cpp index e960dd8de1..fe538fda60 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -39,7 +39,7 @@ static void print_versions(xmrig::Config *config) { - char buf[16]; + char buf[16] = { 0 }; # if defined(__clang__) snprintf(buf, 16, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); @@ -47,24 +47,22 @@ static void print_versions(xmrig::Config *config) snprintf(buf, 16, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); # elif defined(_MSC_VER) snprintf(buf, 16, " MSVC/%d", MSVC_VERSION); -# else - buf[0] = '\0'; # endif - - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s%s" : " * VERSIONS: XMRig/%s libuv/%s%s", - APP_VERSION, uv_version_string(), buf); + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" libuv/%s%s") + : " * %-13s%s/%s libuv/%s%s", + "VERSIONS", APP_NAME, APP_VERSION, uv_version_string(), buf); } static void print_memory(xmrig::Config *config) { # ifdef _WIN32 if (config->isColors()) { - Log::i()->text("\x1B[01;32m * \x1B[01;37mHUGE PAGES: %s", - Mem::isHugepagesAvailable() ? "\x1B[01;32mavailable" : "\x1B[01;31munavailable"); + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", + "HUGE PAGES", Mem::isHugepagesAvailable() ? "\x1B[1;32mavailable" : "\x1B[01;31munavailable"); } else { - Log::i()->text(" * HUGE PAGES: %s", Mem::isHugepagesAvailable() ? "available" : "unavailable"); + Log::i()->text(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable"); } # endif } @@ -73,19 +71,20 @@ static void print_memory(xmrig::Config *config) { static void print_cpu(xmrig::Config *config) { if (config->isColors()) { - Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU: %s (%d) %sx64 %sAES-NI", + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s (%d) %sx64 %sAES-NI", + "CPU", Cpu::brand(), Cpu::sockets(), - Cpu::isX64() ? "\x1B[01;32m" : "\x1B[01;31m-", - Cpu::hasAES() ? "\x1B[01;32m" : "\x1B[01;31m-"); + Cpu::isX64() ? "\x1B[1;32m" : "\x1B[1;31m-", + Cpu::hasAES() ? "\x1B[1;32m" : "\x1B[1;31m-"); # ifndef XMRIG_NO_LIBCPUID - Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%.1f MB/%.1f MB", "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); # endif } else { - Log::i()->text(" * CPU: %s (%d) %sx64 %sAES-NI", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); + Log::i()->text(" * %-13s%s (%d) %sx64 %sAES-NI", "CPU", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); # ifndef XMRIG_NO_LIBCPUID - Log::i()->text(" * CPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); + Log::i()->text(" * %-13s%.1f MB/%.1f MB", "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); # endif } } @@ -94,27 +93,28 @@ static void print_cpu(xmrig::Config *config) static void print_threads(xmrig::Config *config) { if (config->threadsMode() != xmrig::Config::Advanced) { - char buf[32]; + char buf[32] = { 0 }; if (config->affinity() != -1L) { - snprintf(buf, 32, ", affinity=0x%" PRIX64, config->affinity()); - } - else { - buf[0] = '\0'; + snprintf(buf, sizeof buf, ", affinity=0x%" PRIX64, config->affinity()); } - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, %sdonate=%d%%%s" : " * THREADS: %d, %s, av=%d, %sdonate=%d%%%s", + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, av=%d, %sdonate=%d%%") WHITE_BOLD("%s") + : " * %-13s%d, %s, av=%d, %sdonate=%d%%%s", + "THREADS", config->threadsCount(), config->algorithm().name(), config->algoVariant(), - config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "", + config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "", config->donateLevel(), buf); } else { - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, %sdonate=%d%%" : " * THREADS: %d, %s, %sdonate=%d%%", + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, %sdonate=%d%%") + : " * %-13s%d, %s, %sdonate=%d%%", + "THREADS", config->threadsCount(), config->algorithm().name(), - config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "", + config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "", config->donateLevel()); } } @@ -125,9 +125,11 @@ static void print_pools(xmrig::Config *config) const std::vector &pools = config->pools(); for (size_t i = 0; i < pools.size(); ++i) { - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s" : " * POOL #%d: %s", + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") CYAN_BOLD("%s") " variant " WHITE_BOLD("%s") + : " * POOL #%-7d%s variant %s", i + 1, - pools[i].url() + pools[i].url(), + pools[i].algorithm().variantName() ); } @@ -147,8 +149,9 @@ static void print_api(xmrig::Config *config) return; } - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mAPI BIND: \x1B[01;36m%s:%d" : " * API BIND: %s:%d", - config->isApiIPv6() ? "[::]" : "0.0.0.0", port); + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN("%s:") CYAN_BOLD("%d") + : " * %-13s%s:%d", + "API BIND", config->isApiIPv6() ? "[::]" : "0.0.0.0", port); } #endif @@ -156,10 +159,12 @@ static void print_api(xmrig::Config *config) static void print_commands(xmrig::Config *config) { if (config->isColors()) { - Log::i()->text("\x1B[01;32m * \x1B[01;37mCOMMANDS: \x1B[01;35mh\x1B[01;37mashrate, \x1B[01;35mp\x1B[01;37mause, \x1B[01;35mr\x1B[01;37mesume"); + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ") + MAGENTA_BOLD("p") WHITE_BOLD("ause, ") + MAGENTA_BOLD("r") WHITE_BOLD("esume")); } else { - Log::i()->text(" * COMMANDS: 'h' hashrate, 'p' pause, 'r' resume"); + Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume"); } } diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 5eaf68fd91..155485d233 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -72,6 +72,40 @@ xmrig::CommonConfig::~CommonConfig() } +bool xmrig::CommonConfig::save() +{ + if (m_fileName.isNull()) { + return false; + } + + uv_fs_t req; + const int fd = uv_fs_open(uv_default_loop(), &req, m_fileName.data(), O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr); + if (fd < 0) { + return false; + } + + uv_fs_req_cleanup(&req); + + rapidjson::Document doc; + getJSON(doc); + + FILE *fp = fdopen(fd, "w"); + + char buf[4096]; + rapidjson::FileWriteStream os(fp, buf, sizeof(buf)); + rapidjson::PrettyWriter writer(os); + doc.Accept(writer); + + fclose(fp); + + uv_fs_close(uv_default_loop(), &req, fd, nullptr); + uv_fs_req_cleanup(&req); + + LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data()); + return true; +} + + bool xmrig::CommonConfig::finalize() { if (m_state == ReadyState) { @@ -254,40 +288,6 @@ bool xmrig::CommonConfig::parseUint64(int key, uint64_t arg) } -bool xmrig::CommonConfig::save() -{ - if (m_fileName.isNull()) { - return false; - } - - uv_fs_t req; - const int fd = uv_fs_open(uv_default_loop(), &req, m_fileName.data(), O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr); - if (fd < 0) { - return false; - } - - uv_fs_req_cleanup(&req); - - rapidjson::Document doc; - getJSON(doc); - - FILE *fp = fdopen(fd, "w"); - - char buf[4096]; - rapidjson::FileWriteStream os(fp, buf, sizeof(buf)); - rapidjson::PrettyWriter writer(os); - doc.Accept(writer); - - fclose(fp); - - uv_fs_close(uv_default_loop(), &req, fd, nullptr); - uv_fs_req_cleanup(&req); - - LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data()); - return true; -} - - void xmrig::CommonConfig::setFileName(const char *fileName) { m_fileName = fileName; diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index d54afe3a16..356f550dee 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -64,6 +64,8 @@ class CommonConfig : public IConfig inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } inline const char *fileName() const override { return m_fileName.data(); } + bool save() override; + protected: enum State { NoneState, @@ -75,7 +77,6 @@ class CommonConfig : public IConfig bool parseBoolean(int key, bool enable) override; bool parseString(int key, const char *arg) override; bool parseUint64(int key, uint64_t arg) override; - bool save() override; void setFileName(const char *fileName) override; Algorithm m_algorithm; diff --git a/src/common/xmrig.h b/src/common/xmrig.h index a6fda9fc09..43a2a2525e 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -66,6 +66,12 @@ enum Variant { }; +enum AlgoVerify { + VERIFY_HW_AES = 1, + VERIFY_SOFT_AES = 2 +}; + + enum AesMode { AES_AUTO, AES_HW, diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 4c28316437..232e702407 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -116,7 +116,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const Value threads(kArrayType); for (const IThread *thread : m_threads.list) { - threads.PushBack(thread->toConfig(doc), doc.GetAllocator()); + threads.PushBack(thread->toConfig(doc), allocator); } doc.AddMember("threads", threads, allocator); diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 42068eb726..2a75031803 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -35,7 +35,7 @@ #include "workers/Hashrate.h" -inline const char *format(double h, char* buf, size_t size) +inline static const char *format(double h, char *buf, size_t size) { if (isnormal(h)) { snprintf(buf, size, "%03.1f", h); @@ -91,6 +91,9 @@ double Hashrate::calc(size_t ms) const double Hashrate::calc(size_t threadId, size_t ms) const { assert(threadId < m_threads); + if (threadId >= m_threads) { + return nan(""); + } using namespace std::chrono; const uint64_t now = time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); @@ -149,14 +152,15 @@ void Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp) } -void Hashrate::print() +void Hashrate::print() const { char num1[8] = { 0 }; char num2[8] = { 0 }; char num3[8] = { 0 }; char num4[8] = { 0 }; - LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;37mspeed\x1B[0m 2.5s/60s/15m \x1B[01;36m%s \x1B[22;36m%s %s \x1B[01;36mH/s\x1B[0m max: \x1B[01;36m%s H/s" : "speed 2.5s/60s/15m %s %s %s H/s max: %s H/s", + LOG_INFO(m_controller->config()->isColors() ? WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("H/s") " max " CYAN_BOLD("%s H/s") + : "speed 10s/60s/15m %s %s %s H/s max %s H/s", format(calc(ShortInterval), num1, sizeof(num1)), format(calc(MediumInterval), num2, sizeof(num2)), format(calc(LargeInterval), num3, sizeof(num3)), @@ -180,6 +184,12 @@ void Hashrate::updateHighest() } +const char *Hashrate::format(double h, char *buf, size_t size) +{ + return ::format(h, buf, size); +} + + void Hashrate::onReport(uv_timer_t *handle) { static_cast(handle->data)->print(); diff --git a/src/workers/Hashrate.h b/src/workers/Hashrate.h index e79c757a43..e766f11706 100644 --- a/src/workers/Hashrate.h +++ b/src/workers/Hashrate.h @@ -38,7 +38,7 @@ class Hashrate { public: enum Intervals { - ShortInterval = 2500, + ShortInterval = 10000, MediumInterval = 60000, LargeInterval = 900000 }; @@ -47,13 +47,15 @@ class Hashrate double calc(size_t ms) const; double calc(size_t threadId, size_t ms) const; void add(size_t threadId, uint64_t count, uint64_t timestamp); - void print(); + void print() const; void stop(); void updateHighest(); inline double highest() const { return m_highest; } inline size_t threads() const { return m_threads; } + static const char *format(double h, char *buf, size_t size); + private: static void onReport(uv_timer_t *handle); From 3f14caacb16f2c112cb3b0e29364bf2f0c025ec0 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 1 Jun 2018 02:33:21 +0700 Subject: [PATCH 005/102] New detailed hashrate report. --- src/workers/Workers.cpp | 31 +++++++++++++++++++++++++++++++ src/workers/Workers.h | 1 + 2 files changed, 32 insertions(+) diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index f6ec04b7d1..0e75e73614 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -22,6 +22,7 @@ */ #include +#include #include @@ -55,6 +56,7 @@ uv_async_t Workers::m_async; uv_mutex_t Workers::m_mutex; uv_rwlock_t Workers::m_rwlock; uv_timer_t Workers::m_timer; +xmrig::Controller *Workers::m_controller = nullptr; Job Workers::job() @@ -89,6 +91,33 @@ size_t Workers::threads() void Workers::printHashrate(bool detail) { + assert(m_controller != nullptr); + if (!m_controller) { + return; + } + + if (detail) { + const bool isColors = m_controller->config()->isColors(); + char num1[8] = { 0 }; + char num2[8] = { 0 }; + char num3[8] = { 0 }; + + Log::i()->text("%s| THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |", isColors ? "\x1B[1;37m" : ""); + + size_t i = 0; + for (const xmrig::IThread *thread : m_controller->config()->threads()) { + Log::i()->text("| %6zu | %8" PRId64 " | %7s | %7s | %7s |", + thread->index(), + thread->affinity(), + Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::ShortInterval), num1, sizeof num1), + Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::MediumInterval), num2, sizeof num2), + Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::LargeInterval), num3, sizeof num3) + ); + + i++; + } + } + m_hashrate->print(); } @@ -131,6 +160,8 @@ void Workers::setJob(const Job &job, bool donate) void Workers::start(xmrig::Controller *controller) { + m_controller = controller; + const std::vector &threads = controller->config()->threads(); m_status.algo = controller->config()->algorithm().algo(); m_status.colors = controller->config()->isColors(); diff --git a/src/workers/Workers.h b/src/workers/Workers.h index ca01e69850..1d619ceacd 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -114,6 +114,7 @@ class Workers static uv_mutex_t m_mutex; static uv_rwlock_t m_rwlock; static uv_timer_t m_timer; + static xmrig::Controller *m_controller; }; From 2d316f4074d4649e5c6b77afdcaa02f8a105f5b5 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 2 Jun 2018 04:37:12 +0700 Subject: [PATCH 006/102] #446 Fixed SIGBUS error on 32 bit ARM CPUs. --- src/crypto/CryptoNight_monero.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index ea1622ab9b..942940a465 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -38,8 +38,9 @@ # define VARIANT1_INIT(part) \ uint64_t tweak1_2_##part = 0; \ if (VARIANT > 0) { \ - volatile const uint64_t a = *reinterpret_cast(input + 35 + part * size); \ - volatile const uint64_t b = *(reinterpret_cast(ctx[part]->state) + 24); \ + uint64_t a, b; \ + memcpy(&a, input + 35 + part * size, sizeof a); \ + memcpy(&b, ctx[part]->state + 192, sizeof b); \ tweak1_2_##part = a ^ b; \ } #endif From 0341831323600d6eb601dc418e00e00174fe18b0 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 3 Jun 2018 00:09:59 +0700 Subject: [PATCH 007/102] Use native checks instead of XMRIG_ARMv8. --- src/Cpu_arm.cpp | 5 ++++- src/crypto/CryptoNight_arm.h | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Cpu_arm.cpp b/src/Cpu_arm.cpp index 59ff84217b..3e259d0d85 100644 --- a/src/Cpu_arm.cpp +++ b/src/Cpu_arm.cpp @@ -47,8 +47,11 @@ void Cpu::initCommon() { memcpy(m_brand, "Unknown", 7); -# if defined(XMRIG_ARMv8) +# if defined (__arm64__) || defined (__aarch64__) m_flags |= X86_64; +# endif + +# if __ARM_FEATURE_CRYPTO m_flags |= AES; # endif } diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 284b1f5fd5..161a095ff1 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -73,7 +73,7 @@ static inline __attribute__((always_inline)) __m128i _mm_set_epi64x(const uint64 } -#ifdef XMRIG_ARMv8 +#if __ARM_FEATURE_CRYPTO static inline __attribute__((always_inline)) __m128i _mm_aesenc_si128(__m128i v, __m128i rkey) { alignas(16) const __m128i zero = { 0 }; @@ -82,6 +82,8 @@ static inline __attribute__((always_inline)) __m128i _mm_aesenc_si128(__m128i v, #else static inline __attribute__((always_inline)) __m128i _mm_aesenc_si128(__m128i v, __m128i rkey) { + alignas(16) const __m128i zero = { 0 }; + return zero; } #endif @@ -96,7 +98,7 @@ static inline __attribute__((always_inline)) uint64_t _mm_cvtsi128_si64(__m128i #define EXTRACT64(X) _mm_cvtsi128_si64(X) -#if defined(XMRIG_ARMv8) +#if defined (__arm64__) || defined (__aarch64__) static inline uint64_t __umul128(uint64_t a, uint64_t b, uint64_t* hi) { unsigned __int128 r = (unsigned __int128) a * (unsigned __int128) b; From 2d8ce519782aa97ff88f4c0b3d89e443713b9b79 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 3 Jun 2018 00:22:26 +0700 Subject: [PATCH 008/102] #446 Better fix, second variable always aligned. --- src/crypto/CryptoNight_monero.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index 942940a465..28572d88c0 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -38,10 +38,8 @@ # define VARIANT1_INIT(part) \ uint64_t tweak1_2_##part = 0; \ if (VARIANT > 0) { \ - uint64_t a, b; \ - memcpy(&a, input + 35 + part * size, sizeof a); \ - memcpy(&b, ctx[part]->state + 192, sizeof b); \ - tweak1_2_##part = a ^ b; \ + memcpy(&tweak1_2_##part, input + 35 + part * size, sizeof tweak1_2_##part); \ + tweak1_2_##part ^= *(reinterpret_cast(ctx[part]->state) + 24); \ } #endif From 6d0b30e9d692762ab0234f1da797d8b6b5bd6e9c Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 3 Jun 2018 02:56:49 +0700 Subject: [PATCH 009/102] #551 Fixed cn-heavy for ARMv8. --- src/crypto/CryptoNight_arm.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 161a095ff1..8c59f5968f 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -472,9 +472,10 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si idx0 = al0; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; - int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; - int64_t q = n / (d | 0x5); + const int64x2_t x = vld1q_s64(reinterpret_cast(&l0[idx0 & MASK])); + const int64_t n = vgetq_lane_s64(x, 0); + const int32_t d = vgetq_lane_s32(x, 2); + const int64_t q = n / (d | 0x5); ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; idx0 = d ^ q; From 45a8993abb103191bb5dbf1ba184716d4b36fc3e Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 3 Jun 2018 05:42:10 +0700 Subject: [PATCH 010/102] Fix double hash mode too. --- src/crypto/CryptoNight_arm.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 8c59f5968f..fd5bcb7bc3 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -580,10 +580,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ah0 ^= ch; idx0 = al0; - if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; - int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; - int64_t q = n / (d | 0x5); + if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { + const int64x2_t x = vld1q_s64(reinterpret_cast(&l0[idx0 & MASK])); + const int64_t n = vgetq_lane_s64(x, 0); + const int32_t d = vgetq_lane_s32(x, 2); + const int64_t q = n / (d | 0x5); ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; idx0 = d ^ q; @@ -615,9 +616,10 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si idx1 = al1; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l1[idx1 & MASK])[0]; - int32_t d = ((int32_t*)&l1[idx1 & MASK])[2]; - int64_t q = n / (d | 0x5); + const int64x2_t x = vld1q_s64(reinterpret_cast(&l1[idx1 & MASK])); + const int64_t n = vgetq_lane_s64(x, 0); + const int32_t d = vgetq_lane_s32(x, 2); + const int64_t q = n / (d | 0x5); ((int64_t*)&l1[idx1 & MASK])[0] = n ^ q; idx1 = d ^ q; From 8c2ee9b9ab6bac46ce68967531300b148c0e301b Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 4 Jun 2018 02:09:29 +0700 Subject: [PATCH 011/102] #672 Reverted back "cryptonight-light" and exit if no valid algorithm specified. --- src/common/config/CommonConfig.cpp | 3 ++- src/common/config/CommonConfig.h | 6 +++--- src/common/config/ConfigLoader.cpp | 8 +++++++- src/common/crypto/Algorithm.cpp | 1 + src/interfaces/IConfig.h | 2 ++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 155485d233..668bf0d8d1 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -38,6 +38,7 @@ xmrig::CommonConfig::CommonConfig() : + m_algorithm(CRYPTONIGHT, VARIANT_AUTO), m_adjusted(false), m_apiIPv6(false), m_apiRestricted(true), @@ -117,7 +118,7 @@ bool xmrig::CommonConfig::finalize() } if (!m_algorithm.isValid()) { - m_algorithm.setAlgo(CRYPTONIGHT); + return false; } for (Pool &pool : m_pools) { diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 356f550dee..95a02fb16b 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -48,7 +48,6 @@ class CommonConfig : public IConfig inline bool isBackground() const { return m_background; } inline bool isColors() const { return m_colors; } inline bool isSyslog() const { return m_syslog; } - inline const Algorithm &algorithm() const { return m_algorithm; } inline const char *apiToken() const { return m_apiToken.data(); } inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } inline const char *logFile() const { return m_logFile.data(); } @@ -61,8 +60,9 @@ class CommonConfig : public IConfig inline int retryPause() const { return m_retryPause; } inline void setColors(bool colors) { m_colors = colors; } - inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } - inline const char *fileName() const override { return m_fileName.data(); } + inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } + inline const Algorithm &algorithm() const override { return m_algorithm; } + inline const char *fileName() const override { return m_fileName.data(); } bool save() override; diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index 919ff00c1a..32d0850c02 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -170,7 +170,13 @@ xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator } if (!config->finalize()) { - fprintf(stderr, "No valid configuration found. Exiting.\n"); + if (!config->algorithm().isValid()) { + fprintf(stderr, "No valid algorithm specified. Exiting.\n"); + } + else { + fprintf(stderr, "No valid configuration found. Exiting.\n"); + } + delete config; return nullptr; } diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index fce4d7b8c5..f3f4c2f4f9 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -60,6 +60,7 @@ static AlgoData const algorithms[] = { # ifndef XMRIG_NO_AEON { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, + { "cryptonight-light", "cn-light", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, { "cryptonight-lite/0", "cn-lite/0", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 }, { "cryptonight-lite/1", "cn-lite/1", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, { "cryptonight-lite/ipbc", "cn-lite/ipbc", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_IPBC }, diff --git a/src/interfaces/IConfig.h b/src/interfaces/IConfig.h index 2422b891b8..77e262da66 100644 --- a/src/interfaces/IConfig.h +++ b/src/interfaces/IConfig.h @@ -24,6 +24,7 @@ #define __ICONFIG_H__ +#include "common/crypto/Algorithm.h" #include "rapidjson/fwd.h" @@ -97,6 +98,7 @@ class IConfig virtual bool parseString(int key, const char *arg) = 0; virtual bool parseUint64(int key, uint64_t arg) = 0; virtual bool save() = 0; + virtual const Algorithm &algorithm() const = 0; virtual const char *fileName() const = 0; virtual void getJSON(rapidjson::Document &doc) const = 0; virtual void parseJSON(const rapidjson::Document &doc) = 0; From 7496ba46a8d67ae5964bb2e24494887acc903edb Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 Jun 2018 07:34:58 +0700 Subject: [PATCH 012/102] Move files. --- CMakeLists.txt | 18 +++++++++--------- src/App.h | 2 +- src/api/ApiRouter.h | 2 +- src/common/config/CommonConfig.h | 2 +- src/common/config/ConfigLoader.cpp | 4 ++-- src/common/config/ConfigWatcher.cpp | 2 +- src/{ => common}/interfaces/IClientListener.h | 0 src/{ => common}/interfaces/IConfig.h | 6 ++++++ src/{ => common}/interfaces/IConfigCreator.h | 0 src/{ => common}/interfaces/IConsoleListener.h | 0 .../interfaces/IControllerListener.h | 0 src/{ => common}/interfaces/ILogBackend.h | 4 ++++ src/{ => common}/interfaces/IStrategy.h | 0 .../interfaces/IStrategyListener.h | 0 src/{ => common}/interfaces/IWatcherListener.h | 0 src/common/log/ConsoleLog.h | 2 +- src/common/log/FileLog.h | 2 +- src/common/log/Log.cpp | 2 +- src/common/log/Log.h | 2 +- src/common/net/Client.cpp | 2 +- src/common/net/Pool.cpp | 6 ++++++ src/common/net/strategies/FailoverStrategy.cpp | 2 +- src/common/net/strategies/FailoverStrategy.h | 4 ++-- .../net/strategies/SinglePoolStrategy.cpp | 2 +- src/common/net/strategies/SinglePoolStrategy.h | 4 ++-- src/core/ConfigCreator.h | 2 +- src/core/ConfigLoader_platform.h | 2 +- src/core/Controller.cpp | 2 +- src/core/Controller.h | 2 +- src/net/Network.h | 2 +- src/net/strategies/DonateStrategy.cpp | 2 +- src/net/strategies/DonateStrategy.h | 6 +++--- 32 files changed, 51 insertions(+), 35 deletions(-) rename src/{ => common}/interfaces/IClientListener.h (100%) rename src/{ => common}/interfaces/IConfig.h (95%) rename src/{ => common}/interfaces/IConfigCreator.h (100%) rename src/{ => common}/interfaces/IConsoleListener.h (100%) rename src/{ => common}/interfaces/IControllerListener.h (100%) rename src/{ => common}/interfaces/ILogBackend.h (94%) rename src/{ => common}/interfaces/IStrategy.h (100%) rename src/{ => common}/interfaces/IStrategyListener.h (100%) rename src/{ => common}/interfaces/IWatcherListener.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a242970bc4..e263808e1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,15 @@ set(HEADERS src/common/Console.h src/common/crypto/Algorithm.h src/common/crypto/keccak.h + src/common/interfaces/IClientListener.h + src/common/interfaces/IConfig.h + src/common/interfaces/IConfigCreator.h + src/common/interfaces/IConsoleListener.h + src/common/interfaces/IControllerListener.h + src/common/interfaces/ILogBackend.h + src/common/interfaces/IStrategy.h + src/common/interfaces/IStrategyListener.h + src/common/interfaces/IWatcherListener.h src/common/log/ConsoleLog.h src/common/log/FileLog.h src/common/log/Log.h @@ -38,17 +47,8 @@ set(HEADERS src/core/ConfigLoader_platform.h src/core/Controller.h src/Cpu.h - src/interfaces/IClientListener.h - src/interfaces/IConfig.h - src/interfaces/IConfigCreator.h - src/interfaces/IConsoleListener.h - src/interfaces/IControllerListener.h src/interfaces/IJobResultListener.h - src/interfaces/ILogBackend.h - src/interfaces/IStrategy.h - src/interfaces/IStrategyListener.h src/interfaces/IThread.h - src/interfaces/IWatcherListener.h src/interfaces/IWorker.h src/Mem.h src/net/JobResult.h diff --git a/src/App.h b/src/App.h index 22269f67c0..964400e6ba 100644 --- a/src/App.h +++ b/src/App.h @@ -28,7 +28,7 @@ #include -#include "interfaces/IConsoleListener.h" +#include "common/interfaces/IConsoleListener.h" class Console; diff --git a/src/api/ApiRouter.h b/src/api/ApiRouter.h index 3ed458d41a..9e32cdaee6 100644 --- a/src/api/ApiRouter.h +++ b/src/api/ApiRouter.h @@ -26,7 +26,7 @@ #include "api/NetworkState.h" -#include "interfaces/IControllerListener.h" +#include "common/interfaces/IControllerListener.h" #include "rapidjson/fwd.h" diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 95a02fb16b..2a329c7edf 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -28,10 +28,10 @@ #include +#include "common/interfaces/IConfig.h" #include "common/net/Pool.h" #include "common/utils/c_str.h" #include "common/xmrig.h" -#include "interfaces/IConfig.h" namespace xmrig { diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index 32d0850c02..cc5d9a4939 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -34,12 +34,12 @@ #include "common/config/ConfigLoader.h" #include "common/config/ConfigWatcher.h" +#include "common/interfaces/IConfig.h" +#include "common/interfaces/IWatcherListener.h" #include "common/net/Pool.h" #include "common/Platform.h" #include "core/ConfigCreator.h" #include "core/ConfigLoader_platform.h" -#include "interfaces/IConfig.h" -#include "interfaces/IWatcherListener.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" #include "rapidjson/filereadstream.h" diff --git a/src/common/config/ConfigWatcher.cpp b/src/common/config/ConfigWatcher.cpp index bde35f237a..14107b62c8 100644 --- a/src/common/config/ConfigWatcher.cpp +++ b/src/common/config/ConfigWatcher.cpp @@ -27,9 +27,9 @@ #include "common/config/ConfigLoader.h" #include "common/config/ConfigWatcher.h" +#include "common/interfaces/IWatcherListener.h" #include "common/log/Log.h" #include "core/ConfigCreator.h" -#include "interfaces/IWatcherListener.h" xmrig::ConfigWatcher::ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener) : diff --git a/src/interfaces/IClientListener.h b/src/common/interfaces/IClientListener.h similarity index 100% rename from src/interfaces/IClientListener.h rename to src/common/interfaces/IClientListener.h diff --git a/src/interfaces/IConfig.h b/src/common/interfaces/IConfig.h similarity index 95% rename from src/interfaces/IConfig.h rename to src/common/interfaces/IConfig.h index 77e262da66..62c7ba945a 100644 --- a/src/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -78,6 +78,12 @@ class IConfig ThreadsKey = 't', HardwareAESKey = 1011, + // xmrig amd + OclPlatform = 1400, + OclAffinity = 1401, + OclDevices = 1402, + OclLaunch = 1403, + // xmrig-proxy AccessLogFileKey = 'A', BindKey = 'b', diff --git a/src/interfaces/IConfigCreator.h b/src/common/interfaces/IConfigCreator.h similarity index 100% rename from src/interfaces/IConfigCreator.h rename to src/common/interfaces/IConfigCreator.h diff --git a/src/interfaces/IConsoleListener.h b/src/common/interfaces/IConsoleListener.h similarity index 100% rename from src/interfaces/IConsoleListener.h rename to src/common/interfaces/IConsoleListener.h diff --git a/src/interfaces/IControllerListener.h b/src/common/interfaces/IControllerListener.h similarity index 100% rename from src/interfaces/IControllerListener.h rename to src/common/interfaces/IControllerListener.h diff --git a/src/interfaces/ILogBackend.h b/src/common/interfaces/ILogBackend.h similarity index 94% rename from src/interfaces/ILogBackend.h rename to src/common/interfaces/ILogBackend.h index 6e3f5c1c01..85a04e9352 100644 --- a/src/interfaces/ILogBackend.h +++ b/src/common/interfaces/ILogBackend.h @@ -40,7 +40,11 @@ class ILogBackend DEBUG }; +# ifdef APP_DEBUG + constexpr static const size_t kBufferSize = 1024; +# else constexpr static const size_t kBufferSize = 512; +# endif virtual ~ILogBackend() {} diff --git a/src/interfaces/IStrategy.h b/src/common/interfaces/IStrategy.h similarity index 100% rename from src/interfaces/IStrategy.h rename to src/common/interfaces/IStrategy.h diff --git a/src/interfaces/IStrategyListener.h b/src/common/interfaces/IStrategyListener.h similarity index 100% rename from src/interfaces/IStrategyListener.h rename to src/common/interfaces/IStrategyListener.h diff --git a/src/interfaces/IWatcherListener.h b/src/common/interfaces/IWatcherListener.h similarity index 100% rename from src/interfaces/IWatcherListener.h rename to src/common/interfaces/IWatcherListener.h diff --git a/src/common/log/ConsoleLog.h b/src/common/log/ConsoleLog.h index 81813c816e..bac09a535d 100644 --- a/src/common/log/ConsoleLog.h +++ b/src/common/log/ConsoleLog.h @@ -28,7 +28,7 @@ #include -#include "interfaces/ILogBackend.h" +#include "common/interfaces/ILogBackend.h" namespace xmrig { diff --git a/src/common/log/FileLog.h b/src/common/log/FileLog.h index 2c25f0932f..8a58d4e409 100644 --- a/src/common/log/FileLog.h +++ b/src/common/log/FileLog.h @@ -28,7 +28,7 @@ #include -#include "interfaces/ILogBackend.h" +#include "common/interfaces/ILogBackend.h" namespace xmrig { diff --git a/src/common/log/Log.cpp b/src/common/log/Log.cpp index 763eb25b06..ccf3800878 100644 --- a/src/common/log/Log.cpp +++ b/src/common/log/Log.cpp @@ -29,8 +29,8 @@ #include +#include "common/interfaces/ILogBackend.h" #include "common/log/Log.h" -#include "interfaces/ILogBackend.h" Log *Log::m_self = nullptr; diff --git a/src/common/log/Log.h b/src/common/log/Log.h index c4803e3a00..bfa307173b 100644 --- a/src/common/log/Log.h +++ b/src/common/log/Log.h @@ -30,7 +30,7 @@ #include -#include "interfaces/ILogBackend.h" +#include "common/interfaces/ILogBackend.h" class Log diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index 921fa618bb..a552ed3cdf 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -29,9 +29,9 @@ #include +#include "common/interfaces/IClientListener.h" #include "common/log/Log.h" #include "common/net/Client.h" -#include "interfaces/IClientListener.h" #include "net/JobResult.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index c12e05d559..d594354531 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -101,6 +101,12 @@ bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const } } +# ifdef XMRIG_PROXY_PROJECT + if (m_algorithm.algo() == xmrig::CRYPTONIGHT && algorithm.algo() == xmrig::CRYPTONIGHT && m_algorithm.variant() == xmrig::VARIANT_XTL) { + return true; + } +# endif + return false; } diff --git a/src/common/net/strategies/FailoverStrategy.cpp b/src/common/net/strategies/FailoverStrategy.cpp index 295b4335e8..fab785906d 100644 --- a/src/common/net/strategies/FailoverStrategy.cpp +++ b/src/common/net/strategies/FailoverStrategy.cpp @@ -22,10 +22,10 @@ */ +#include "common/interfaces/IStrategyListener.h" #include "common/net/Client.h" #include "common/net/strategies/FailoverStrategy.h" #include "common/Platform.h" -#include "interfaces/IStrategyListener.h" FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : diff --git a/src/common/net/strategies/FailoverStrategy.h b/src/common/net/strategies/FailoverStrategy.h index f86b366a71..07095b3b1a 100644 --- a/src/common/net/strategies/FailoverStrategy.h +++ b/src/common/net/strategies/FailoverStrategy.h @@ -28,9 +28,9 @@ #include +#include "common/interfaces/IClientListener.h" +#include "common/interfaces/IStrategy.h" #include "common/net/Pool.h" -#include "interfaces/IClientListener.h" -#include "interfaces/IStrategy.h" class Client; diff --git a/src/common/net/strategies/SinglePoolStrategy.cpp b/src/common/net/strategies/SinglePoolStrategy.cpp index 21ce7b34d5..2cfc0976b0 100644 --- a/src/common/net/strategies/SinglePoolStrategy.cpp +++ b/src/common/net/strategies/SinglePoolStrategy.cpp @@ -22,10 +22,10 @@ */ +#include "common/interfaces/IStrategyListener.h" #include "common/net/Client.h" #include "common/net/strategies/SinglePoolStrategy.h" #include "common/Platform.h" -#include "interfaces/IStrategyListener.h" SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet) : diff --git a/src/common/net/strategies/SinglePoolStrategy.h b/src/common/net/strategies/SinglePoolStrategy.h index 41d90e349a..1a48d6786a 100644 --- a/src/common/net/strategies/SinglePoolStrategy.h +++ b/src/common/net/strategies/SinglePoolStrategy.h @@ -25,8 +25,8 @@ #define __SINGLEPOOLSTRATEGY_H__ -#include "interfaces/IClientListener.h" -#include "interfaces/IStrategy.h" +#include "common/interfaces/IClientListener.h" +#include "common/interfaces/IStrategy.h" class Client; diff --git a/src/core/ConfigCreator.h b/src/core/ConfigCreator.h index fcc6c5960a..054eb78c9d 100644 --- a/src/core/ConfigCreator.h +++ b/src/core/ConfigCreator.h @@ -24,8 +24,8 @@ #define __CONFIGCREATOR_H__ +#include "common/interfaces/IConfigCreator.h" #include "core/Config.h" -#include "interfaces/IConfigCreator.h" namespace xmrig { diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index 9704d5e307..bc6657d1b6 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -33,8 +33,8 @@ #endif +#include "common/interfaces/IConfig.h" #include "version.h" -#include "interfaces/IConfig.h" namespace xmrig { diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index ac64f173ba..ce73f03746 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -26,6 +26,7 @@ #include "common/config/ConfigLoader.h" +#include "common/interfaces/IControllerListener.h" #include "common/log/ConsoleLog.h" #include "common/log/FileLog.h" #include "common/log/Log.h" @@ -33,7 +34,6 @@ #include "core/Config.h" #include "core/Controller.h" #include "Cpu.h" -#include "interfaces/IControllerListener.h" #include "net/Network.h" diff --git a/src/core/Controller.h b/src/core/Controller.h index 25f91843c5..2c66af5323 100644 --- a/src/core/Controller.h +++ b/src/core/Controller.h @@ -25,7 +25,7 @@ #define __CONTROLLER_H__ -#include "interfaces/IWatcherListener.h" +#include "common/interfaces/IWatcherListener.h" class Network; diff --git a/src/net/Network.h b/src/net/Network.h index 353edc77c5..51e95d6d24 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -30,8 +30,8 @@ #include "api/NetworkState.h" +#include "common/interfaces/IStrategyListener.h" #include "interfaces/IJobResultListener.h" -#include "interfaces/IStrategyListener.h" class IStrategy; diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 7de776eff4..4d353655a3 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -23,13 +23,13 @@ #include "common/crypto/keccak.h" +#include "common/interfaces/IStrategyListener.h" #include "common/net/Client.h" #include "common/net/Job.h" #include "common/net/strategies/FailoverStrategy.h" #include "common/net/strategies/SinglePoolStrategy.h" #include "common/Platform.h" #include "common/xmrig.h" -#include "interfaces/IStrategyListener.h" #include "net/strategies/DonateStrategy.h" diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 66c0375c06..95ff6608a6 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -30,9 +30,9 @@ #include "common/net/Pool.h" -#include "interfaces/IClientListener.h" -#include "interfaces/IStrategy.h" -#include "interfaces/IStrategyListener.h" +#include "common/interfaces/IClientListener.h" +#include "common/interfaces/IStrategy.h" +#include "common/interfaces/IStrategyListener.h" class Client; From 98954cd20ce889e849e9e40ed1c580dcda68f7be Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 Jun 2018 11:48:31 +0700 Subject: [PATCH 013/102] Move dry-run option to common code. --- src/common/config/CommonConfig.cpp | 8 +++++++ src/common/config/CommonConfig.h | 2 ++ src/core/Config.cpp | 36 +++++++++++++----------------- src/core/Config.h | 2 -- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 668bf0d8d1..315b09d68e 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -44,6 +44,7 @@ xmrig::CommonConfig::CommonConfig() : m_apiRestricted(true), m_background(false), m_colors(true), + m_dryRun(false), m_syslog(false), # ifdef XMRIG_PROXY_PROJECT @@ -172,9 +173,15 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable) case ApiIPv6Key: /* ipv6 */ m_apiIPv6 = enable; + break; case ApiRestrictedKey: /* restricted */ m_apiRestricted = enable; + break; + + case IConfig::DryRunKey: /* --dry-run */ + m_dryRun = enable; + break; default: break; @@ -259,6 +266,7 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg) case KeepAliveKey: /* --keepalive */ case NicehashKey: /* --nicehash */ case ApiIPv6Key: /* --api-ipv6 */ + case DryRunKey: /* --dry-run */ return parseBoolean(key, true); case ColorKey: /* --no-color */ diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 2a329c7edf..ffebb6b250 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -47,6 +47,7 @@ class CommonConfig : public IConfig inline bool isApiRestricted() const { return m_apiRestricted; } inline bool isBackground() const { return m_background; } inline bool isColors() const { return m_colors; } + inline bool isDryRun() const { return m_dryRun; } inline bool isSyslog() const { return m_syslog; } inline const char *apiToken() const { return m_apiToken.data(); } inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } @@ -85,6 +86,7 @@ class CommonConfig : public IConfig bool m_apiRestricted; bool m_background; bool m_colors; + bool m_dryRun; bool m_syslog; bool m_watch; int m_apiPort; diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 232e702407..fa6afdb4dd 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -43,7 +43,6 @@ static char affinity_tmp[20] = { 0 }; xmrig::Config::Config() : xmrig::CommonConfig(), m_aesMode(AES_AUTO), m_algoVariant(AV_AUTO), - m_dryRun(false), m_hugePages(true), m_safe(false), m_maxCpuUsage(75), @@ -192,19 +191,15 @@ bool xmrig::Config::parseBoolean(int key, bool enable) } switch (key) { - case IConfig::SafeKey: /* --safe */ + case SafeKey: /* --safe */ m_safe = enable; break; - case IConfig::HugePagesKey: /* --no-huge-pages */ + case HugePagesKey: /* --no-huge-pages */ m_hugePages = enable; break; - case IConfig::DryRunKey: /* --dry-run */ - m_dryRun = enable; - break; - - case IConfig::HardwareAESKey: /* hw-aes config only */ + case HardwareAESKey: /* hw-aes config only */ m_aesMode = enable ? AES_HW : AES_SOFT; break; @@ -223,19 +218,18 @@ bool xmrig::Config::parseString(int key, const char *arg) } switch (key) { - case xmrig::IConfig::AVKey: /* --av */ - case xmrig::IConfig::MaxCPUUsageKey: /* --max-cpu-usage */ - case xmrig::IConfig::CPUPriorityKey: /* --cpu-priority */ + case AVKey: /* --av */ + case MaxCPUUsageKey: /* --max-cpu-usage */ + case CPUPriorityKey: /* --cpu-priority */ return parseUint64(key, strtol(arg, nullptr, 10)); - case xmrig::IConfig::SafeKey: /* --safe */ - case xmrig::IConfig::DryRunKey: /* --dry-run */ + case SafeKey: /* --safe */ return parseBoolean(key, true); - case xmrig::IConfig::HugePagesKey: /* --no-huge-pages */ + case HugePagesKey: /* --no-huge-pages */ return parseBoolean(key, false); - case xmrig::IConfig::ThreadsKey: /* --threads */ + case ThreadsKey: /* --threads */ if (strncmp(arg, "all", 3) == 0) { m_threads.count = Cpu::threads(); return true; @@ -243,7 +237,7 @@ bool xmrig::Config::parseString(int key, const char *arg) return parseUint64(key, strtol(arg, nullptr, 10)); - case xmrig::IConfig::CPUAffinityKey: /* --cpu-affinity */ + case CPUAffinityKey: /* --cpu-affinity */ { const char *p = strstr(arg, "0x"); return parseUint64(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10)); @@ -264,7 +258,7 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg) } switch (key) { - case xmrig::IConfig::CPUAffinityKey: /* --cpu-affinity */ + case CPUAffinityKey: /* --cpu-affinity */ if (arg) { m_threads.mask = arg; } @@ -303,25 +297,25 @@ void xmrig::Config::parseJSON(const rapidjson::Document &doc) bool xmrig::Config::parseInt(int key, int arg) { switch (key) { - case xmrig::IConfig::ThreadsKey: /* --threads */ + case ThreadsKey: /* --threads */ if (arg >= 0 && arg < 1024) { m_threads.count = arg; } break; - case xmrig::IConfig::AVKey: /* --av */ + case AVKey: /* --av */ if (arg >= AV_AUTO && arg < AV_MAX) { m_algoVariant = static_cast(arg); } break; - case xmrig::IConfig::MaxCPUUsageKey: /* --max-cpu-usage */ + case MaxCPUUsageKey: /* --max-cpu-usage */ if (m_maxCpuUsage > 0 && arg <= 100) { m_maxCpuUsage = arg; } break; - case xmrig::IConfig::CPUPriorityKey: /* --cpu-priority */ + case CPUPriorityKey: /* --cpu-priority */ if (arg >= 0 && arg <= 5) { m_priority = arg; } diff --git a/src/core/Config.h b/src/core/Config.h index 0c6a21732b..f0f1404fbc 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -77,7 +77,6 @@ class Config : public CommonConfig inline AesMode aesMode() const { return m_aesMode; } inline AlgoVariant algoVariant() const { return m_algoVariant; } - inline bool isDryRun() const { return m_dryRun; } inline bool isHugePages() const { return m_hugePages; } inline const std::vector &threads() const { return m_threads.list; } inline int priority() const { return m_priority; } @@ -117,7 +116,6 @@ class Config : public CommonConfig AesMode m_aesMode; AlgoVariant m_algoVariant; - bool m_dryRun; bool m_hugePages; bool m_safe; int m_maxCpuUsage; From 3e41bdd1bd1b4d1404009c6986eb68e3c968dbea Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 7 Jun 2018 07:17:30 +0700 Subject: [PATCH 014/102] Fix Linux build. --- src/common/log/SysLog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/log/SysLog.h b/src/common/log/SysLog.h index 1e49a48bb6..5cfeefcdb4 100644 --- a/src/common/log/SysLog.h +++ b/src/common/log/SysLog.h @@ -25,7 +25,7 @@ #define __SYSLOG_H__ -#include "interfaces/ILogBackend.h" +#include "common/interfaces/ILogBackend.h" class SysLog : public ILogBackend From 376d0c3978f0731fb597486834f1c995a337df54 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 10 Jun 2018 19:48:34 +0700 Subject: [PATCH 015/102] Added support for "cn/msr" also known as "cn-fast". --- src/common/crypto/Algorithm.cpp | 18 ++++----- src/common/net/Job.cpp | 10 ++--- src/common/net/Pool.cpp | 14 +++---- src/common/xmrig.h | 7 +++- src/crypto/CryptoNight_constants.h | 19 ++++++--- src/crypto/CryptoNight_test.h | 15 ++++++++ src/crypto/CryptoNight_x86.h | 20 +++++----- src/workers/CpuThread.cpp | 62 ++++++++++++++++++++++++------ src/workers/MultiWorker.cpp | 47 +++++++++++----------- src/workers/MultiWorker.h | 1 + 10 files changed, 137 insertions(+), 76 deletions(-) diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index f3f4c2f4f9..fbfd02311b 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -57,6 +57,7 @@ static AlgoData const algorithms[] = { { "cryptonight/0", "cn/0", xmrig::CRYPTONIGHT, xmrig::VARIANT_0 }, { "cryptonight/1", "cn/1", xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, { "cryptonight/xtl", "cn/xtl", xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL }, + { "cryptonight/msr", "cn/msr", xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR }, # ifndef XMRIG_NO_AEON { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, @@ -68,6 +69,8 @@ static AlgoData const algorithms[] = { # ifndef XMRIG_NO_SUMO { "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, + { "cryptonight-heavy/0", "cn-heavy/0", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, + { "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV }, # endif }; @@ -89,7 +92,9 @@ static const char *variants[] = { "0", "1", "ipbc", - "xtl" + "xtl", + "msr", + "xhv" }; @@ -145,11 +150,6 @@ void xmrig::Algorithm::parseAlgorithm(const char *algo) void xmrig::Algorithm::parseVariant(const char *variant) { - if (m_algo == CRYPTONIGHT_HEAVY) { - m_variant = VARIANT_0; - return; - } - m_variant = VARIANT_AUTO; for (size_t i = 0; i < ARRAY_SIZE(variants); i++) { @@ -163,7 +163,7 @@ void xmrig::Algorithm::parseVariant(const char *variant) void xmrig::Algorithm::parseVariant(int variant) { - if (variant >= VARIANT_AUTO && variant <= VARIANT_XTL) { + if (variant >= VARIANT_AUTO && variant < VARIANT_MAX) { m_variant = static_cast(variant); } else { @@ -175,10 +175,6 @@ void xmrig::Algorithm::parseVariant(int variant) void xmrig::Algorithm::setAlgo(Algo algo) { m_algo = algo; - - if (m_algo == CRYPTONIGHT_HEAVY) { - m_variant = VARIANT_0; - } } diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index 81c3b8f8d2..9a7ede8e9c 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -173,12 +173,12 @@ xmrig::Variant Job::variant() const return xmrig::VARIANT_1; } - if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { - if (m_algorithm.algo() == xmrig::CRYPTONIGHT) { - return xmrig::VARIANT_1; - } + if (m_algorithm.variant() == xmrig::VARIANT_MSR && m_blob[0] < 7) { + return xmrig::VARIANT_1; + } - return (m_blob[0] > 6 ? xmrig::VARIANT_1 : xmrig::VARIANT_0); + if (m_algorithm.variant() == xmrig::VARIANT_AUTO && m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { + return xmrig::VARIANT_1; } return m_algorithm.variant(); diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index d594354531..006d76a134 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -321,12 +321,12 @@ void Pool::rebuild() m_algorithms.push_back(m_algorithm); # ifndef XMRIG_PROXY_PROJECT - if (m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { - addVariant(xmrig::VARIANT_1); - addVariant(xmrig::VARIANT_0); - addVariant(xmrig::VARIANT_XTL); - addVariant(xmrig::VARIANT_IPBC); - addVariant(xmrig::VARIANT_AUTO); - } + addVariant(xmrig::VARIANT_1); + addVariant(xmrig::VARIANT_0); + addVariant(xmrig::VARIANT_XTL); + addVariant(xmrig::VARIANT_IPBC); + addVariant(xmrig::VARIANT_MSR); + addVariant(xmrig::VARIANT_XHV); + addVariant(xmrig::VARIANT_AUTO); # endif } diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 43a2a2525e..170f4832c1 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -61,8 +61,11 @@ enum Variant { VARIANT_AUTO = -1, // Autodetect VARIANT_0 = 0, // Original CryptoNight or CryptoNight-Heavy VARIANT_1 = 1, // CryptoNight variant 1 also known as Monero7 and CryptoNightV7 - VARIANT_IPBC = 2, // CryptoNight Lite variant 1 with XOR (IPBC only) - VARIANT_XTL = 3 // CryptoNight variant 1 (Stellite only) + VARIANT_IPBC = 2, // Modified CryptoNight Lite variant 1 with XOR (IPBC/TUBE only) + VARIANT_XTL = 3, // Modified CryptoNight variant 1 (Stellite only) + VARIANT_MSR = 4, // Modified CryptoNight variant 1 (Masari only) + VARIANT_XHV = 5, // Modified CryptoNight-Heavy (Haven Protocol only) + VARIANT_MAX }; diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 7e6627fd63..73f3e95815 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -38,6 +38,7 @@ namespace xmrig constexpr const size_t CRYPTONIGHT_MEMORY = 2 * 1024 * 1024; constexpr const uint32_t CRYPTONIGHT_MASK = 0x1FFFF0; constexpr const uint32_t CRYPTONIGHT_ITER = 0x80000; +constexpr const uint32_t CRYPTONIGHT_MSR_ITER = 0x40000; constexpr const size_t CRYPTONIGHT_LITE_MEMORY = 1 * 1024 * 1024; constexpr const uint32_t CRYPTONIGHT_LITE_MASK = 0xFFFF0; @@ -102,18 +103,24 @@ inline uint32_t cn_select_mask(Algo algorithm) } -template inline constexpr uint32_t cn_select_iter() { return 0; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } +template inline constexpr uint32_t cn_select_iter() { return 0; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_MSR_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } -inline uint32_t cn_select_iter(Algo algorithm) +inline uint32_t cn_select_iter(Algo algorithm, Variant variant) { switch(algorithm) { case CRYPTONIGHT: - return CRYPTONIGHT_ITER; + return variant == VARIANT_MSR ? CRYPTONIGHT_MSR_ITER : CRYPTONIGHT_ITER; case CRYPTONIGHT_LITE: return CRYPTONIGHT_LITE_ITER; diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index bf6013e8c7..8d8fe45519 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -99,6 +99,21 @@ const static uint8_t test_output_xtl[160] = { }; +// Masari (MSR) +const static uint8_t test_output_msr[160] = { + 0x3C, 0x7A, 0x61, 0x08, 0x4C, 0x5E, 0xB8, 0x65, 0xB4, 0x98, 0xAB, 0x2F, 0x5A, 0x1A, 0xC5, 0x2C, + 0x49, 0xC1, 0x77, 0xC2, 0xD0, 0x13, 0x34, 0x42, 0xD6, 0x5E, 0xD5, 0x14, 0x33, 0x5C, 0x82, 0xC5, + 0x69, 0xDF, 0x38, 0x51, 0x1B, 0xB3, 0xEB, 0x7D, 0xE7, 0x6B, 0x08, 0x8E, 0xB6, 0x7E, 0xB7, 0x1C, + 0x5F, 0x3C, 0x81, 0xC9, 0xF7, 0xCE, 0xAE, 0x28, 0xC0, 0xFE, 0xEB, 0xBA, 0x0B, 0x40, 0x38, 0x1D, + 0x44, 0xD0, 0xD5, 0xD3, 0x98, 0x1F, 0xA3, 0x0E, 0xE9, 0x89, 0x1A, 0xD7, 0x88, 0xCC, 0x25, 0x76, + 0x9C, 0xFF, 0x4D, 0x7F, 0x9C, 0xCF, 0x48, 0x07, 0x91, 0xF9, 0x82, 0xF5, 0x4C, 0xE9, 0xBD, 0x82, + 0x36, 0x36, 0x64, 0x14, 0xED, 0xB8, 0x54, 0xEE, 0x22, 0xA1, 0x66, 0xA3, 0x87, 0x10, 0x76, 0x1F, + 0x5A, 0xCD, 0x4C, 0x31, 0x4C, 0xBA, 0x41, 0xD2, 0xDB, 0x6C, 0x31, 0x2E, 0x7A, 0x64, 0x15, 0xFF, + 0xA6, 0xD9, 0xB9, 0x7D, 0x1C, 0x3C, 0x98, 0xDD, 0x16, 0xE6, 0xD3, 0xAA, 0xEF, 0xB6, 0xB3, 0x53, + 0x74, 0xD1, 0xAC, 0x5C, 0x04, 0x26, 0x7D, 0x71, 0xDE, 0xAB, 0x66, 0x28, 0x91, 0x3A, 0x6F, 0x4F +}; + + #ifndef XMRIG_NO_AEON const static uint8_t test_output_v0_lite[160] = { 0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E, diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 66bcf8b540..3aa2a927b4 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -403,11 +403,11 @@ static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp) } -template +template inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { @@ -493,11 +493,11 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { @@ -700,11 +700,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { @@ -790,11 +790,11 @@ inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { @@ -896,11 +896,11 @@ inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size } -template +template inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); if (VARIANT > 0 && size < 43) { diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index e42139c084..926a9ba3be 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -62,9 +62,15 @@ bool xmrig::CpuThread::isSoftAES(AlgoVariant av) xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant) { - assert(variant == VARIANT_0 || variant == VARIANT_1 || variant == VARIANT_IPBC || variant == VARIANT_XTL); - - static const cn_hash_fun func_table[90] = { + assert(variant == VARIANT_0 || + variant == VARIANT_1 || + variant == VARIANT_IPBC || + variant == VARIANT_XTL || + variant == VARIANT_MSR || + variant == VARIANT_XHV + ); + + static const cn_hash_fun func_table[180] = { cryptonight_single_hash, cryptonight_double_hash, cryptonight_single_hash, @@ -87,7 +93,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_IPBC cryptonight_single_hash, cryptonight_double_hash, @@ -100,6 +106,19 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV + # ifndef XMRIG_NO_AEON cryptonight_single_hash, cryptonight_double_hash, @@ -134,12 +153,16 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XTL + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_MSR + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif # ifndef XMRIG_NO_SUMO @@ -153,18 +176,33 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_triple_hash, cryptonight_quad_hash, cryptonight_penta_hash, + + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_IPBC + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XTL + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_MSR + + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif }; -# ifndef XMRIG_NO_SUMO - if (algorithm == CRYPTONIGHT_HEAVY) { - variant = VARIANT_0; - } -# endif - - const size_t index = 40 * algorithm + 10 * variant + av - 1; + const size_t index = VARIANT_MAX * 10 * algorithm + 10 * variant + av - 1; # ifndef NDEBUG cn_hash_fun func = func_table[index]; diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index c0f884466a..f3acf7f8ab 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -50,36 +50,23 @@ MultiWorker::~MultiWorker() template bool MultiWorker::selfTest() { - if (m_thread->fn(xmrig::VARIANT_0) == nullptr) { - return false; - } - - m_thread->fn(xmrig::VARIANT_0)(test_input, 76, m_hash, m_ctx); - - if (m_thread->algorithm() == xmrig::CRYPTONIGHT && memcmp(m_hash, test_output_v0, sizeof m_hash) == 0) { - m_thread->fn(xmrig::VARIANT_1)(test_input, 76, m_hash, m_ctx); - if (memcmp(m_hash, test_output_v1, sizeof m_hash) != 0) { - return false; - } - - m_thread->fn(xmrig::VARIANT_XTL)(test_input, 76, m_hash, m_ctx); - return memcmp(m_hash, test_output_xtl, sizeof m_hash) == 0; + if (m_thread->algorithm() == xmrig::CRYPTONIGHT) { + return verify(xmrig::VARIANT_0, test_output_v0) && + verify(xmrig::VARIANT_1, test_output_v1) && + verify(xmrig::VARIANT_XTL, test_output_xtl) && + verify(xmrig::VARIANT_MSR, test_output_msr); } # ifndef XMRIG_NO_AEON - if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE && memcmp(m_hash, test_output_v0_lite, sizeof m_hash) == 0) { - m_thread->fn(xmrig::VARIANT_1)(test_input, 76, m_hash, m_ctx); - if (memcmp(m_hash, test_output_v1_lite, sizeof m_hash) != 0) { - return false; - } - - m_thread->fn(xmrig::VARIANT_IPBC)(test_input, 76, m_hash, m_ctx); - return memcmp(m_hash, test_output_ipbc_lite, sizeof m_hash) == 0; + if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE) { + return verify(xmrig::VARIANT_0, test_output_v0_lite) && + verify(xmrig::VARIANT_1, test_output_v1_lite) && + verify(xmrig::VARIANT_IPBC, test_output_ipbc_lite); } # endif # ifndef XMRIG_NO_SUMO - return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && memcmp(m_hash, test_output_heavy, sizeof m_hash) == 0; + return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && verify(xmrig::VARIANT_0, test_output_heavy); # else return false; # endif @@ -140,6 +127,20 @@ bool MultiWorker::resume(const Job &job) } +template +bool MultiWorker::verify(xmrig::Variant variant, const uint8_t *referenceValue) +{ + + xmrig::CpuThread::cn_hash_fun func = m_thread->fn(variant); + if (!func) { + return false; + } + + func(test_input, 76, m_hash, m_ctx); + return memcmp(m_hash, referenceValue, sizeof m_hash) == 0; +} + + template void MultiWorker::consumeJob() { diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index d89bbb335b..d4a6910e72 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -48,6 +48,7 @@ class MultiWorker : public Worker private: bool resume(const Job &job); + bool verify(xmrig::Variant variant, const uint8_t *referenceValue); void consumeJob(); void save(const Job &job); From 6241d1fa0d0530b4a67268490de09ccbc2d2355e Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 11 Jun 2018 12:00:59 +0700 Subject: [PATCH 016/102] Added support for cn-heavy/xhv. --- src/common/net/Job.cpp | 12 ++--- src/crypto/CryptoNight_arm.h | 44 +++++++++++++----- src/crypto/CryptoNight_constants.h | 15 ++++++ src/crypto/CryptoNight_monero.h | 8 ++-- src/crypto/CryptoNight_test.h | 15 +++++- src/crypto/CryptoNight_x86.h | 74 ++++++++++++++++++++---------- src/workers/MultiWorker.cpp | 9 ++-- 7 files changed, 128 insertions(+), 49 deletions(-) diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index 9a7ede8e9c..80b521ea1a 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -165,10 +165,6 @@ bool Job::setTarget(const char *target) xmrig::Variant Job::variant() const { - if (m_algorithm.algo() == xmrig::CRYPTONIGHT_HEAVY) { - return xmrig::VARIANT_0; - } - if (m_algorithm.variant() == xmrig::VARIANT_XTL && m_blob[0] < 4) { return xmrig::VARIANT_1; } @@ -177,8 +173,12 @@ xmrig::Variant Job::variant() const return xmrig::VARIANT_1; } - if (m_algorithm.variant() == xmrig::VARIANT_AUTO && m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { - return xmrig::VARIANT_1; + if (m_algorithm.variant() == xmrig::VARIANT_XHV && m_blob[0] < 3) { + return xmrig::VARIANT_0; + } + + if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { + return m_algorithm.algo() == xmrig::CRYPTONIGHT_HEAVY ? xmrig::VARIANT_0 : xmrig::VARIANT_1; } return m_algorithm.variant(); diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index fd5bcb7bc3..46e1f5304f 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -402,10 +402,11 @@ template inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 32); return; } @@ -436,7 +437,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); } - if (VARIANT > 0) { + if (IS_MONERO) { cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); } else { _mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); @@ -455,7 +456,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; - if (VARIANT > 0) { + if (IS_MONERO) { if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } @@ -478,7 +479,13 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si const int64_t q = n / (d | 0x5); ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; - idx0 = d ^ q; + + if (VARIANT == xmrig::VARIANT_XHV) { + idx0 = (~d) ^ q; + } + else { + idx0 = d ^ q; + } } } @@ -493,10 +500,11 @@ template inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); - constexpr size_t ITERATIONS = xmrig::cn_select_iter(); + constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 64); return; } @@ -540,7 +548,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); } - if (VARIANT > 0) { + if (IS_MONERO) { cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); cryptonight_monero_tweak((uint64_t*)&l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); } else { @@ -564,7 +572,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; - if (VARIANT > 0) { + if (IS_MONERO) { if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } @@ -587,7 +595,13 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si const int64_t q = n / (d | 0x5); ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; - idx0 = d ^ q; + + if (VARIANT == xmrig::VARIANT_XHV) { + idx0 = (~d) ^ q; + } + else { + idx0 = d ^ q; + } } cl = ((uint64_t*) &l1[idx1 & MASK])[0]; @@ -599,7 +613,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l1[idx1 & MASK])[0] = al1; - if (VARIANT > 0) { + if (IS_MONERO) { if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; } @@ -622,7 +636,13 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si const int64_t q = n / (d | 0x5); ((int64_t*)&l1[idx1 & MASK])[0] = n ^ q; - idx1 = d ^ q; + + if (VARIANT == xmrig::VARIANT_XHV) { + idx1 = (~d) ^ q; + } + else { + idx1 = d ^ q; + } } } diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 73f3e95815..85a2ab854a 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -136,6 +136,21 @@ inline uint32_t cn_select_iter(Algo algorithm, Variant variant) } +template inline constexpr bool cn_is_monero() { return false; } +template<> inline constexpr bool cn_is_monero() { return false; } +template<> inline constexpr bool cn_is_monero() { return true; } +template<> inline constexpr bool cn_is_monero() { return true; } +template<> inline constexpr bool cn_is_monero() { return true; } +template<> inline constexpr bool cn_is_monero() { return true; } +template<> inline constexpr bool cn_is_monero() { return false; } + + +inline bool cn_is_monero(Variant variant) +{ + return variant > VARIANT_0 && variant < VARIANT_XHV; +} + + } /* namespace xmrig */ diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index 28572d88c0..a758fdbc5c 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -30,21 +30,21 @@ #ifndef XMRIG_ARM # define VARIANT1_INIT(part) \ uint64_t tweak1_2_##part = 0; \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ tweak1_2_##part = (*reinterpret_cast(input + 35 + part * size) ^ \ *(reinterpret_cast(ctx[part]->state) + 24)); \ } #else # define VARIANT1_INIT(part) \ uint64_t tweak1_2_##part = 0; \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ memcpy(&tweak1_2_##part, input + 35 + part * size, sizeof tweak1_2_##part); \ tweak1_2_##part ^= *(reinterpret_cast(ctx[part]->state) + 24); \ } #endif #define VARIANT1_1(p) \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ const uint8_t tmp = reinterpret_cast(p)[11]; \ static const uint32_t table = 0x75310; \ const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \ @@ -52,7 +52,7 @@ } #define VARIANT1_2(p, part) \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ (p) ^= tweak1_2_##part; \ } diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index 8d8fe45519..187ba07a3a 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -161,7 +161,7 @@ const static uint8_t test_output_ipbc_lite[160] = { #ifndef XMRIG_NO_SUMO -const static uint8_t test_output_heavy[160] = { +const static uint8_t test_output_v0_heavy[160] = { 0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64, 0xBB, 0xE1, 0x18, 0x7F, 0x55, 0x01, 0x4B, 0x39, 0xE5, 0xF3, 0xD6, 0x93, 0x28, 0xE4, 0x8F, 0xC2, 0x4D, 0x94, 0x7D, 0xD6, 0xDB, 0x6E, 0x07, 0x48, 0x26, 0x4A, 0x51, 0x2E, 0xAC, 0xF3, 0x25, 0x4A, @@ -173,6 +173,19 @@ const static uint8_t test_output_heavy[160] = { 0x53, 0x62, 0x0A, 0x54, 0x7D, 0x43, 0xEA, 0x18, 0x94, 0xED, 0xD8, 0x92, 0x06, 0x6A, 0xA1, 0x51, 0xAD, 0xB1, 0xFD, 0x89, 0xFB, 0x5C, 0xB4, 0x25, 0x6A, 0xDD, 0xB0, 0x09, 0xC5, 0x72, 0x87, 0xEB }; + +const static uint8_t test_output_xhv_heavy[160] = { + 0x5A, 0xC3, 0xF7, 0x85, 0xC4, 0x90, 0xC5, 0x85, 0x50, 0xEC, 0x95, 0xD2, 0x72, 0x65, 0x63, 0x57, + 0x7E, 0x7C, 0x1C, 0x21, 0x2D, 0x0C, 0xDE, 0x59, 0x12, 0x73, 0x20, 0x1E, 0x44, 0xFD, 0xD5, 0xB6, + 0x1F, 0x4E, 0xB2, 0x0A, 0x36, 0x51, 0x4B, 0xF5, 0x4D, 0xC9, 0xE0, 0x90, 0x2C, 0x16, 0x47, 0x3F, + 0xDE, 0x18, 0x29, 0x8E, 0xBB, 0x34, 0x2B, 0xEF, 0x7A, 0x04, 0x22, 0xD1, 0xB1, 0xF2, 0x48, 0xDA, + 0xE3, 0x7F, 0x4B, 0x4C, 0xB4, 0xDF, 0xE8, 0xD3, 0x70, 0xE2, 0xE7, 0x44, 0x25, 0x87, 0x12, 0xF9, + 0x8F, 0x28, 0x0B, 0xCE, 0x2C, 0xEE, 0xDD, 0x88, 0x94, 0x35, 0x48, 0x51, 0xAE, 0xC8, 0x9C, 0x0B, + 0xED, 0x2F, 0xE6, 0x0F, 0x39, 0x05, 0xB4, 0x4A, 0x8F, 0x38, 0x44, 0x2D, 0x4B, 0xE9, 0x7B, 0x81, + 0xC6, 0xB0, 0xE0, 0x0A, 0x39, 0x8C, 0x38, 0xFE, 0x63, 0x31, 0x47, 0x65, 0x0D, 0x2B, 0xF4, 0x96, + 0x13, 0x91, 0x89, 0xB4, 0x5B, 0xA9, 0x2A, 0x7A, 0x09, 0x65, 0x14, 0x20, 0x76, 0x24, 0x6C, 0x80, + 0x1D, 0x3F, 0x9F, 0xCD, 0x68, 0x39, 0xA9, 0x42, 0x27, 0xC1, 0x0C, 0x53, 0x98, 0x35, 0x60, 0x7A +}; #endif diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 3aa2a927b4..8ab65023da 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -409,8 +409,9 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 32); return; } @@ -441,7 +442,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); } - if (VARIANT > 0) { + if (IS_MONERO) { cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); } else { _mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); @@ -460,7 +461,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; - if (VARIANT > 0) { + if (IS_MONERO) { if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } @@ -477,12 +478,18 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si idx0 = al0; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; - int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; + int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; + int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; int64_t q = n / (d | 0x5); ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; - idx0 = d ^ q; + + if (VARIANT == xmrig::VARIANT_XHV) { + idx0 = (~d) ^ q; + } + else { + idx0 = d ^ q; + } } } @@ -499,8 +506,9 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 64); return; } @@ -544,7 +552,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); } - if (VARIANT > 0) { + if (IS_MONERO) { cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); cryptonight_monero_tweak((uint64_t*)&l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); } else { @@ -568,7 +576,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; - if (VARIANT > 0) { + if (IS_MONERO) { if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } @@ -585,12 +593,18 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si idx0 = al0; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; - int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; + int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; + int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; int64_t q = n / (d | 0x5); ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; - idx0 = d ^ q; + + if (VARIANT == xmrig::VARIANT_XHV) { + idx0 = (~d) ^ q; + } + else { + idx0 = d ^ q; + } } cl = ((uint64_t*) &l1[idx1 & MASK])[0]; @@ -602,7 +616,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l1[idx1 & MASK])[0] = al1; - if (VARIANT > 0) { + if (IS_MONERO) { if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; } @@ -619,12 +633,18 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si idx1 = al1; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l1[idx1 & MASK])[0]; - int32_t d = ((int32_t*)&l1[idx1 & MASK])[2]; + int64_t n = ((int64_t*)&l1[idx1 & MASK])[0]; + int32_t d = ((int32_t*)&l1[idx1 & MASK])[2]; int64_t q = n / (d | 0x5); ((int64_t*)&l1[idx1 & MASK])[0] = n ^ q; - idx1 = d ^ q; + + if (VARIANT == xmrig::VARIANT_XHV) { + idx1 = (~d) ^ q; + } + else { + idx1 = d ^ q; + } } } @@ -653,7 +673,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si \ b = _mm_xor_si128(b, c); \ \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ cryptonight_monero_tweak(reinterpret_cast(ptr), b); \ } else { \ _mm_store_si128(ptr, b); \ @@ -670,7 +690,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si lo = __umul128(idx, EXTRACT64(b), &hi); \ a = _mm_add_epi64(a, _mm_set_epi64x(lo, hi)); \ \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ _mm_store_si128(ptr, _mm_xor_si128(a, mc)); \ \ if (VARIANT == xmrig::VARIANT_IPBC) { \ @@ -688,13 +708,18 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si int32_t d = ((int32_t*)&l[idx & MASK])[2]; \ int64_t q = n / (d | 0x5); \ ((int64_t*)&l[idx & MASK])[0] = n ^ q; \ - idx = d ^ q; \ + if (VARIANT == xmrig::VARIANT_XHV) { \ + idx = (~d) ^ q; \ + } \ + else { \ + idx = d ^ q; \ + } \ } #define CONST_INIT(ctx, n) \ __m128i mc##n; \ - if (VARIANT > 0) { \ + if (IS_MONERO) { \ mc##n = _mm_set_epi64x(*reinterpret_cast(input + n * size + 35) ^ \ *(reinterpret_cast((ctx)->state) + 24), 0); \ } @@ -706,8 +731,9 @@ inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 32 * 3); return; } @@ -796,8 +822,9 @@ inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 32 * 4); return; } @@ -902,8 +929,9 @@ inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t siz constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); + constexpr bool IS_MONERO = xmrig::cn_is_monero(); - if (VARIANT > 0 && size < 43) { + if (IS_MONERO && size < 43) { memset(output, 0, 32 * 5); return; } diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index f3acf7f8ab..73f0dba7a3 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -66,10 +66,13 @@ bool MultiWorker::selfTest() # endif # ifndef XMRIG_NO_SUMO - return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && verify(xmrig::VARIANT_0, test_output_heavy); -# else - return false; + if (m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY) { + return verify(xmrig::VARIANT_0, test_output_v0_heavy) && + verify(xmrig::VARIANT_XHV, test_output_xhv_heavy); + } # endif + + return false; } From 00261e11c92d7cf7db0c6d7c3538c9a5fd46b503 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 11 Jun 2018 12:26:49 +0700 Subject: [PATCH 017/102] Fix command line option "-a cn-heavy". --- src/common/net/Pool.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 006d76a134..74e5012a4a 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -233,7 +233,10 @@ void Pool::adjust(xmrig::Algo algorithm) m_algorithm.setAlgo(algorithm); if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { - if (algorithm == xmrig::CRYPTONIGHT) { + if (algorithm == xmrig::CRYPTONIGHT_HEAVY) { + m_algorithm.setVariant(xmrig::VARIANT_0); + } + else { m_algorithm.setVariant(xmrig::VARIANT_1); } } From 0e3ccba576863b781e83824f104f9640603cecb0 Mon Sep 17 00:00:00 2001 From: xmrig Date: Mon, 11 Jun 2018 15:23:06 +0700 Subject: [PATCH 018/102] Update CHANGELOG.md --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c99e646f46..07fa9b870d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# v2.6.3 +- **Added support for new cryptonight-heavy variant xhv** (`cn-heavy/xhv`) for upcoming Haven Protocol fork. +- **Added support for new cryptonight variant msr** (`cn/msr`) also known as `cryptonight-fast` for upcoming Masari fork. +- [#446](https://github.com/xmrig/xmrig/issues/446) Likely fixed SIGBUS error on 32 bit ARM CPUs. +- [#551](https://github.com/xmrig/xmrig/issues/551) Fixed `cn-heavy` algorithm on ARMv8. +- [#614](https://github.com/xmrig/xmrig/issues/614) Fixed display issue with huge pages percentage when colors disabled. +- [#615](https://github.com/xmrig/xmrig/issues/615) Fixed build without libcpuid. +- [#629](https://github.com/xmrig/xmrig/pull/629) Fixed file logging with non-seekable files. +- [#672](https://github.com/xmrig/xmrig/pull/672) Reverted back `cryptonight-light` and exit if no valid algorithm specified. + # v2.6.2 - [#607](https://github.com/xmrig/xmrig/issues/607) Fixed donation bug. - [#610](https://github.com/xmrig/xmrig/issues/610) Fixed ARM build. From 142505b5ffaf9576384bbf3f6b8f606c852753a8 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 11 Jun 2018 15:44:45 +0700 Subject: [PATCH 019/102] Fix ARM build. --- src/crypto/CryptoNight_arm.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 46e1f5304f..845c027ec1 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -398,7 +398,7 @@ static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp) } -template +template inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); @@ -496,7 +496,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) { constexpr size_t MASK = xmrig::cn_select_mask(); @@ -657,19 +657,19 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si } -template +template inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) { } -template +template inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) { } -template +template inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) { } From f89946b5cf77d4d16bcc1429cf18dc64ef8f71ad Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 11 Jun 2018 16:09:50 +0700 Subject: [PATCH 020/102] v2.6.3 --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index f9f02dccab..96a6412bdf 100644 --- a/src/version.h +++ b/src/version.h @@ -27,7 +27,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "2.6.2" +#define APP_VERSION "2.6.3" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com" @@ -35,7 +35,7 @@ #define APP_VER_MAJOR 2 #define APP_VER_MINOR 6 -#define APP_VER_PATCH 2 +#define APP_VER_PATCH 3 #ifdef _MSC_VER # if (_MSC_VER >= 1910) From 7f22d2910c507949320f8e14483ad2e4f2dbf86c Mon Sep 17 00:00:00 2001 From: xmrig Date: Mon, 11 Jun 2018 18:34:24 +0700 Subject: [PATCH 021/102] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07fa9b870d..4b8f8a6719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # v2.6.3 - **Added support for new cryptonight-heavy variant xhv** (`cn-heavy/xhv`) for upcoming Haven Protocol fork. - **Added support for new cryptonight variant msr** (`cn/msr`) also known as `cryptonight-fast` for upcoming Masari fork. +- Added new detailed hashrate report. - [#446](https://github.com/xmrig/xmrig/issues/446) Likely fixed SIGBUS error on 32 bit ARM CPUs. - [#551](https://github.com/xmrig/xmrig/issues/551) Fixed `cn-heavy` algorithm on ARMv8. - [#614](https://github.com/xmrig/xmrig/issues/614) Fixed display issue with huge pages percentage when colors disabled. From 7074ed8871e439c6e5e8d8046fa0c7478d56ac24 Mon Sep 17 00:00:00 2001 From: xmrig Date: Wed, 13 Jun 2018 21:43:47 +0700 Subject: [PATCH 022/102] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 250ca54b12..a07470c986 100644 --- a/README.md +++ b/README.md @@ -124,10 +124,10 @@ Please note performance is highly dependent on system load. The numbers above ar ## Release checksums ### SHA-256 ``` -f8e1957e8bfd7f281a76d1e42694049c67f39dea90ac36e9d589c14cdf8924bc xmrig-2.6.1-xenial-amd64.tar.gz/xmrig-2.6.1/xmrig -472c7aaf5aacc1212bfd3f2f96daca4f42d64e2d0db0872891328e7d8503d0c8 xmrig-2.6.1-gcc-win32.zip/xmrig.exe -d53154cef24c884b2be539ac13bfb6e7dba6bbc53b62e91f2877637d43fa4b15 xmrig-2.6.1-gcc-win64.zip/xmrig.exe -a253381b617463e6e1193d49b8afbf720a1c376621da7429d97f192668cd59ad xmrig-2.6.1-msvc-win64.zip/xmrig.exe +dbc2b0f92df5098dc91a361febfda46382d347ae3085415f35e1637b7ebc67e9 xmrig-2.6.3-xenial-amd64.tar.gz/xmrig-2.6.3/xmrig +b54ffe80cd54ac486f03f064c09de80b6ec29f19ddebb50a8d7316a947045b85 xmrig-2.6.3-gcc-win32.zip/xmrig.exe +c828ed21bbaf71a808b26928ab1eb6f6355029f2b731a639043733e6b48e9d77 xmrig-2.6.3-gcc-win64.zip/xmrig.exe +2e7432d14546b510506ccc22df62ef334d424d02fbc6baaa7a0498a0102de156 xmrig-2.6.3-msvc-win64.zip/xmrig.exe ``` ## Contacts From e209dd7c69b28dbdcc63bafc7d5c8e1272ef55cc Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 14 Jun 2018 21:25:57 +0700 Subject: [PATCH 023/102] 2.6.4-dev --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index 96a6412bdf..37df900616 100644 --- a/src/version.h +++ b/src/version.h @@ -27,7 +27,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "2.6.3" +#define APP_VERSION "2.6.4-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com" @@ -35,7 +35,7 @@ #define APP_VER_MAJOR 2 #define APP_VER_MINOR 6 -#define APP_VER_PATCH 3 +#define APP_VER_PATCH 4 #ifdef _MSC_VER # if (_MSC_VER >= 1910) From 168196108853ec580c75190f7b65bc56ce3ae3df Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 14 Jun 2018 21:49:27 +0700 Subject: [PATCH 024/102] Sync changes with proxy. --- src/common/crypto/Algorithm.cpp | 19 +++++++++++-------- src/common/net/Client.cpp | 20 ++++++++++++++++---- src/common/net/Pool.cpp | 2 ++ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index fbfd02311b..7394030909 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -68,7 +68,7 @@ static AlgoData const algorithms[] = { # endif # ifndef XMRIG_NO_SUMO - { "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, + { "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_AUTO }, { "cryptonight-heavy/0", "cn-heavy/0", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, { "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV }, # endif @@ -77,13 +77,16 @@ static AlgoData const algorithms[] = { #ifdef XMRIG_PROXY_PROJECT static AlgoData const xmrStakAlgorithms[] = { - { "cryptonight-monerov7", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, - { "cryptonight_v7", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, - { "cryptonight_v7_stellite", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL }, - { "cryptonight_lite", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 }, - { "cryptonight-aeonv7", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, - { "cryptonight_lite_v7", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, - { "cryptonight_lite_v7_xor", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_IPBC }, + { "cryptonight-monerov7", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, + { "cryptonight_v7", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, + { "cryptonight_v7_stellite", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL }, + { "cryptonight_lite", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 }, + { "cryptonight-aeonv7", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, + { "cryptonight_lite_v7", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, + { "cryptonight_lite_v7_xor", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_IPBC }, + { "cryptonight_heavy", nullptr, xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, + { "cryptonight_haven", nullptr, xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV }, + { "cryptonight_masari", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR }, }; #endif diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index a552ed3cdf..f4553d9733 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -332,6 +332,12 @@ bool Client::parseLogin(const rapidjson::Value &result, int *code) bool Client::verifyAlgorithm(const xmrig::Algorithm &algorithm) const { +# ifdef XMRIG_PROXY_PROJECT + if (m_pool.algorithm().variant() == xmrig::VARIANT_AUTO) { + return true; + } +# endif + if (m_pool.isCompatible(algorithm)) { return true; } @@ -478,13 +484,19 @@ void Client::login() params.AddMember("rigid", StringRef(m_pool.rigId()), allocator); } - Value algo(kArrayType); +# ifdef XMRIG_PROXY_PROJECT + if (m_pool.algorithm().variant() != xmrig::VARIANT_AUTO) +# endif + { + Value algo(kArrayType); + + for (const auto &a : m_pool.algorithms()) { + algo.PushBack(StringRef(a.shortName()), allocator); + } - for (const auto &a : m_pool.algorithms()) { - algo.PushBack(StringRef(a.shortName()), allocator); + params.AddMember("algo", algo, allocator); } - params.AddMember("algo", algo, allocator); doc.AddMember("params", params, allocator); send(doc); diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 74e5012a4a..806664a011 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -232,6 +232,7 @@ void Pool::adjust(xmrig::Algo algorithm) if (!m_algorithm.isValid()) { m_algorithm.setAlgo(algorithm); +# ifndef XMRIG_PROXY_PROJECT if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { if (algorithm == xmrig::CRYPTONIGHT_HEAVY) { m_algorithm.setVariant(xmrig::VARIANT_0); @@ -240,6 +241,7 @@ void Pool::adjust(xmrig::Algo algorithm) m_algorithm.setVariant(xmrig::VARIANT_1); } } +# endif } if (strstr(m_host.data(), ".nicehash.com")) { From f6bdfe0d1e8eb4ffb4adb062f16a5035978f327b Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 14 Jun 2018 23:49:30 +0700 Subject: [PATCH 025/102] #692 Add support for global algorithm variant. --- src/common/config/CommonConfig.cpp | 2 +- src/common/net/Pool.cpp | 21 +++++++++++++-------- src/common/net/Pool.h | 2 +- src/net/strategies/DonateStrategy.cpp | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 315b09d68e..7e43b39de7 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -123,7 +123,7 @@ bool xmrig::CommonConfig::finalize() } for (Pool &pool : m_pools) { - pool.adjust(m_algorithm.algo()); + pool.adjust(m_algorithm); if (pool.isValid() && pool.algorithm().isValid()) { m_activePools.push_back(std::move(pool)); diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 806664a011..58be044e6c 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -223,22 +223,27 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const } -void Pool::adjust(xmrig::Algo algorithm) +void Pool::adjust(const xmrig::Algorithm &algorithm) { + using namespace xmrig; + if (!isValid()) { return; } if (!m_algorithm.isValid()) { - m_algorithm.setAlgo(algorithm); + m_algorithm.setAlgo(algorithm.algo()); # ifndef XMRIG_PROXY_PROJECT - if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { - if (algorithm == xmrig::CRYPTONIGHT_HEAVY) { - m_algorithm.setVariant(xmrig::VARIANT_0); + if (m_algorithm.variant() == VARIANT_AUTO) { + if (algorithm.variant() != VARIANT_AUTO) { + m_algorithm.setVariant(algorithm.variant()); + } + else if (algorithm.algo() == CRYPTONIGHT_HEAVY) { + m_algorithm.setVariant(VARIANT_0); } else { - m_algorithm.setVariant(xmrig::VARIANT_1); + m_algorithm.setVariant(VARIANT_1); } } # endif @@ -249,13 +254,13 @@ void Pool::adjust(xmrig::Algo algorithm) m_nicehash = true; if (strstr(m_host.data(), "cryptonightv7.")) { - m_algorithm.setVariant(xmrig::VARIANT_1); + m_algorithm.setVariant(VARIANT_1); } } if (strstr(m_host.data(), ".minergate.com")) { m_keepAlive = false; - m_algorithm.setVariant(xmrig::VARIANT_1); + m_algorithm.setVariant(VARIANT_1); } rebuild(); diff --git a/src/common/net/Pool.h b/src/common/net/Pool.h index eaabe54d34..e6ecef4a30 100644 --- a/src/common/net/Pool.h +++ b/src/common/net/Pool.h @@ -77,7 +77,7 @@ class Pool bool parse(const char *url); bool setUserpass(const char *userpass); rapidjson::Value toJSON(rapidjson::Document &doc) const; - void adjust(xmrig::Algo algorithm); + void adjust(const xmrig::Algorithm &algorithm); void setAlgo(const xmrig::Algorithm &algorithm); # ifdef APP_DEBUG diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 4d353655a3..395c53bbf6 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -68,7 +68,7 @@ DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IS } for (Pool &pool : m_pools) { - pool.adjust(algo); + pool.adjust(xmrig::Algorithm(algo, xmrig::VARIANT_AUTO)); } if (m_pools.size() > 1) { From 8b252e65696897d130ab54e8f9e045f684e9db1d Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 16 Jun 2018 16:08:08 +0700 Subject: [PATCH 026/102] Better variant detection for nicehash.com and minergate.com. --- src/common/net/Pool.cpp | 102 +++++++++++++++++++++++++++------------ src/common/net/Pool.h | 1 + src/common/utils/c_str.h | 6 +++ 3 files changed, 79 insertions(+), 30 deletions(-) diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 58be044e6c..83dbc2905a 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -225,42 +225,13 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const void Pool::adjust(const xmrig::Algorithm &algorithm) { - using namespace xmrig; - if (!isValid()) { return; } if (!m_algorithm.isValid()) { m_algorithm.setAlgo(algorithm.algo()); - -# ifndef XMRIG_PROXY_PROJECT - if (m_algorithm.variant() == VARIANT_AUTO) { - if (algorithm.variant() != VARIANT_AUTO) { - m_algorithm.setVariant(algorithm.variant()); - } - else if (algorithm.algo() == CRYPTONIGHT_HEAVY) { - m_algorithm.setVariant(VARIANT_0); - } - else { - m_algorithm.setVariant(VARIANT_1); - } - } -# endif - } - - if (strstr(m_host.data(), ".nicehash.com")) { - m_keepAlive = false; - m_nicehash = true; - - if (strstr(m_host.data(), "cryptonightv7.")) { - m_algorithm.setVariant(VARIANT_1); - } - } - - if (strstr(m_host.data(), ".minergate.com")) { - m_keepAlive = false; - m_algorithm.setVariant(VARIANT_1); + adjustVariant(algorithm.variant()); } rebuild(); @@ -325,9 +296,80 @@ void Pool::addVariant(xmrig::Variant variant) } +void Pool::adjustVariant(const xmrig::Variant variantHint) +{ +# ifndef XMRIG_PROXY_PROJECT + using namespace xmrig; + + if (m_host.contains(".nicehash.com")) { + m_keepAlive = false; + m_nicehash = true; + bool valid = true; + + if (m_host.contains("cryptonight.") && m_port == 3355) { + valid = m_algorithm.algo() == CRYPTONIGHT; + m_algorithm.setVariant(VARIANT_0); + } + else if (m_host.contains("cryptonightv7.") && m_port == 3363) { + valid = m_algorithm.algo() == CRYPTONIGHT; + m_algorithm.setVariant(VARIANT_1); + } + else if (m_host.contains("cryptonightheavy.") && m_port == 3364) { + valid = m_algorithm.algo() == CRYPTONIGHT_HEAVY; + m_algorithm.setVariant(VARIANT_0); + } + + if (!valid) { + m_algorithm.setAlgo(INVALID_ALGO); + } + + return; + } + + if (m_host.contains(".minergate.com")) { + m_keepAlive = false; + bool valid = true; + m_algorithm.setVariant(VARIANT_1); + + if (m_host.contains("xmr.pool.")) { + valid = m_algorithm.algo() == CRYPTONIGHT; + m_algorithm.setVariant(m_port == 45700 ? VARIANT_1 : VARIANT_0); + } + else if (m_host.contains("aeon.pool.") && m_port == 45690) { + valid = m_algorithm.algo() == CRYPTONIGHT_LITE; + m_algorithm.setVariant(VARIANT_1); + } + + if (!valid) { + m_algorithm.setAlgo(INVALID_ALGO); + } + + return; + } + + if (variantHint != VARIANT_AUTO) { + m_algorithm.setVariant(variantHint); + return; + } + + if (m_algorithm.algo() == CRYPTONIGHT_HEAVY) { + m_algorithm.setVariant(VARIANT_0); + } + else { + m_algorithm.setVariant(VARIANT_1); + } +# endif +} + + void Pool::rebuild() { m_algorithms.clear(); + + if (!m_algorithm.isValid()) { + return; + } + m_algorithms.push_back(m_algorithm); # ifndef XMRIG_PROXY_PROJECT diff --git a/src/common/net/Pool.h b/src/common/net/Pool.h index e6ecef4a30..57a30d1e23 100644 --- a/src/common/net/Pool.h +++ b/src/common/net/Pool.h @@ -87,6 +87,7 @@ class Pool private: bool parseIPv6(const char *addr); void addVariant(xmrig::Variant variant); + void adjustVariant(const xmrig::Variant variantHint); void rebuild(); bool m_nicehash; diff --git a/src/common/utils/c_str.h b/src/common/utils/c_str.h index 3cc4d3261a..7ce63754e2 100644 --- a/src/common/utils/c_str.h +++ b/src/common/utils/c_str.h @@ -72,6 +72,12 @@ class c_str } + inline bool contains(const char *str) const + { + return strstr(m_data, str) != nullptr; + } + + inline bool isNull() const { return m_data == nullptr; } inline const char *data() const { return m_data; } inline size_t size() const { return m_data == nullptr ? 0 : strlen(m_data); } From 19ed9da95c8f7037abb36832d0b836714c44f418 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 9 Jul 2018 00:23:27 +0700 Subject: [PATCH 027/102] #714 Simplify cn-heavy/xhv. --- src/crypto/CryptoNight_x86.h | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 8ab65023da..7c8adc69c2 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -485,11 +485,10 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; if (VARIANT == xmrig::VARIANT_XHV) { - idx0 = (~d) ^ q; - } - else { - idx0 = d ^ q; + d = ~d; } + + idx0 = d ^ q; } } @@ -600,11 +599,10 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; if (VARIANT == xmrig::VARIANT_XHV) { - idx0 = (~d) ^ q; - } - else { - idx0 = d ^ q; + d = ~d; } + + idx0 = d ^ q; } cl = ((uint64_t*) &l1[idx1 & MASK])[0]; @@ -640,11 +638,10 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((int64_t*)&l1[idx1 & MASK])[0] = n ^ q; if (VARIANT == xmrig::VARIANT_XHV) { - idx1 = (~d) ^ q; - } - else { - idx1 = d ^ q; + d = ~d; } + + idx1 = d ^ q; } } @@ -690,7 +687,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si lo = __umul128(idx, EXTRACT64(b), &hi); \ a = _mm_add_epi64(a, _mm_set_epi64x(lo, hi)); \ \ - if (IS_MONERO) { \ + if (IS_MONERO) { \ _mm_store_si128(ptr, _mm_xor_si128(a, mc)); \ \ if (VARIANT == xmrig::VARIANT_IPBC) { \ @@ -709,11 +706,10 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si int64_t q = n / (d | 0x5); \ ((int64_t*)&l[idx & MASK])[0] = n ^ q; \ if (VARIANT == xmrig::VARIANT_XHV) { \ - idx = (~d) ^ q; \ - } \ - else { \ - idx = d ^ q; \ + d = ~d; \ } \ + \ + idx = d ^ q; \ } From 71bee7bfcf432dceed07155dcbfaa36250c951ce Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 9 Jul 2018 16:12:45 +0700 Subject: [PATCH 028/102] Added "cn/xao" and "cn/rto". --- src/common/crypto/Algorithm.cpp | 20 ++++++--- src/common/net/Pool.cpp | 8 +++- src/common/xmrig.h | 4 +- src/crypto/CryptoNight_constants.h | 50 +++++++++++++++------ src/crypto/CryptoNight_x86.h | 8 ++-- src/workers/CpuThread.cpp | 70 ++++++++++++++++++++---------- src/workers/MultiWorker.cpp | 2 +- 7 files changed, 113 insertions(+), 49 deletions(-) diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index 7394030909..31035fb106 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -58,19 +58,21 @@ static AlgoData const algorithms[] = { { "cryptonight/1", "cn/1", xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, { "cryptonight/xtl", "cn/xtl", xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL }, { "cryptonight/msr", "cn/msr", xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR }, + { "cryptonight/xao", "cn/xao", xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO }, + { "cryptonight/rto", "cn/rto", xmrig::CRYPTONIGHT, xmrig::VARIANT_RTO }, # ifndef XMRIG_NO_AEON { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, { "cryptonight-light", "cn-light", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, { "cryptonight-lite/0", "cn-lite/0", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 }, { "cryptonight-lite/1", "cn-lite/1", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, - { "cryptonight-lite/ipbc", "cn-lite/ipbc", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_IPBC }, # endif # ifndef XMRIG_NO_SUMO - { "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_AUTO }, - { "cryptonight-heavy/0", "cn-heavy/0", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, - { "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV }, + { "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_AUTO }, + { "cryptonight-heavy/0", "cn-heavy/0", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, + { "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV }, + { "cryptonight-heavy/tube", "cn-heavy/tube", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_TUBE }, # endif }; @@ -83,10 +85,12 @@ static AlgoData const xmrStakAlgorithms[] = { { "cryptonight_lite", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 }, { "cryptonight-aeonv7", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, { "cryptonight_lite_v7", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, - { "cryptonight_lite_v7_xor", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_IPBC }, { "cryptonight_heavy", nullptr, xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, { "cryptonight_haven", nullptr, xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV }, { "cryptonight_masari", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR }, + { "cryptonight_masari", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR }, + { "cryptonight-bittube2", nullptr, xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_TUBE }, // bittube-miner + { "cryptonight_alloy", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO }, // xmr-stak-alloy }; #endif @@ -94,10 +98,12 @@ static AlgoData const xmrStakAlgorithms[] = { static const char *variants[] = { "0", "1", - "ipbc", + "tube", "xtl", "msr", - "xhv" + "xhv", + "xao", + "rto" }; diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 83dbc2905a..053f25070a 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -352,6 +352,10 @@ void Pool::adjustVariant(const xmrig::Variant variantHint) return; } + if (m_algorithm.variant() != VARIANT_AUTO) { + return; + } + if (m_algorithm.algo() == CRYPTONIGHT_HEAVY) { m_algorithm.setVariant(VARIANT_0); } @@ -376,9 +380,11 @@ void Pool::rebuild() addVariant(xmrig::VARIANT_1); addVariant(xmrig::VARIANT_0); addVariant(xmrig::VARIANT_XTL); - addVariant(xmrig::VARIANT_IPBC); + addVariant(xmrig::VARIANT_TUBE); addVariant(xmrig::VARIANT_MSR); addVariant(xmrig::VARIANT_XHV); + addVariant(xmrig::VARIANT_XAO); + addVariant(xmrig::VARIANT_RTO); addVariant(xmrig::VARIANT_AUTO); # endif } diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 170f4832c1..0ff945b90d 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -61,10 +61,12 @@ enum Variant { VARIANT_AUTO = -1, // Autodetect VARIANT_0 = 0, // Original CryptoNight or CryptoNight-Heavy VARIANT_1 = 1, // CryptoNight variant 1 also known as Monero7 and CryptoNightV7 - VARIANT_IPBC = 2, // Modified CryptoNight Lite variant 1 with XOR (IPBC/TUBE only) + VARIANT_TUBE = 2, // Modified CryptoNight-Heavy (TUBE only) VARIANT_XTL = 3, // Modified CryptoNight variant 1 (Stellite only) VARIANT_MSR = 4, // Modified CryptoNight variant 1 (Masari only) VARIANT_XHV = 5, // Modified CryptoNight-Heavy (Haven Protocol only) + VARIANT_XAO = 6, // Modified CryptoNight variant 1 (Alloy only) + VARIANT_RTO = 7, // Modified CryptoNight variant 1 (Arto only) VARIANT_MAX }; diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 85a2ab854a..08a755d405 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -39,6 +39,7 @@ constexpr const size_t CRYPTONIGHT_MEMORY = 2 * 1024 * 1024; constexpr const uint32_t CRYPTONIGHT_MASK = 0x1FFFF0; constexpr const uint32_t CRYPTONIGHT_ITER = 0x80000; constexpr const uint32_t CRYPTONIGHT_MSR_ITER = 0x40000; +constexpr const uint32_t CRYPTONIGHT_XAO_ITER = 0x100000; constexpr const size_t CRYPTONIGHT_LITE_MEMORY = 1 * 1024 * 1024; constexpr const uint32_t CRYPTONIGHT_LITE_MASK = 0xFFFF0; @@ -103,24 +104,37 @@ inline uint32_t cn_select_mask(Algo algorithm) } -template inline constexpr uint32_t cn_select_iter() { return 0; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_MSR_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } -template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } +template inline constexpr uint32_t cn_select_iter() { return 0; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_MSR_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_XAO_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } inline uint32_t cn_select_iter(Algo algorithm, Variant variant) { + switch (variant) { + case VARIANT_MSR: + return CRYPTONIGHT_MSR_ITER; + + case VARIANT_RTO: + return CRYPTONIGHT_XAO_ITER; + + default: + break; + } + switch(algorithm) { case CRYPTONIGHT: - return variant == VARIANT_MSR ? CRYPTONIGHT_MSR_ITER : CRYPTONIGHT_ITER; + return CRYPTONIGHT_ITER; case CRYPTONIGHT_LITE: return CRYPTONIGHT_LITE_ITER; @@ -139,15 +153,25 @@ inline uint32_t cn_select_iter(Algo algorithm, Variant variant) template inline constexpr bool cn_is_monero() { return false; } template<> inline constexpr bool cn_is_monero() { return false; } template<> inline constexpr bool cn_is_monero() { return true; } -template<> inline constexpr bool cn_is_monero() { return true; } +template<> inline constexpr bool cn_is_monero() { return true; } template<> inline constexpr bool cn_is_monero() { return true; } template<> inline constexpr bool cn_is_monero() { return true; } template<> inline constexpr bool cn_is_monero() { return false; } +template<> inline constexpr bool cn_is_monero() { return false; } +template<> inline constexpr bool cn_is_monero() { return true; } inline bool cn_is_monero(Variant variant) { - return variant > VARIANT_0 && variant < VARIANT_XHV; + switch (variant) { + case VARIANT_0: + case VARIANT_XHV: + case VARIANT_RTO: + return false; + + default: + return true; + } } diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 7c8adc69c2..86a1011ec9 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -462,7 +462,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_IPBC) { + if (VARIANT == xmrig::VARIANT_RTO) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } else { @@ -576,7 +576,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_IPBC) { + if (VARIANT == xmrig::VARIANT_RTO) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } else { @@ -615,7 +615,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l1[idx1 & MASK])[0] = al1; if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_IPBC) { + if (VARIANT == xmrig::VARIANT_RTO) { ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; } else { @@ -690,7 +690,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si if (IS_MONERO) { \ _mm_store_si128(ptr, _mm_xor_si128(a, mc)); \ \ - if (VARIANT == xmrig::VARIANT_IPBC) { \ + if (VARIANT == xmrig::VARIANT_RTO) { \ ((uint64_t*)ptr)[1] ^= ((uint64_t*)ptr)[0]; \ } \ } else { \ diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 926a9ba3be..7cef4f3adf 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -62,15 +62,9 @@ bool xmrig::CpuThread::isSoftAES(AlgoVariant av) xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant) { - assert(variant == VARIANT_0 || - variant == VARIANT_1 || - variant == VARIANT_IPBC || - variant == VARIANT_XTL || - variant == VARIANT_MSR || - variant == VARIANT_XHV - ); - - static const cn_hash_fun func_table[180] = { + assert(variant >= VARIANT_0 && variant < VARIANT_MAX); + + static const cn_hash_fun func_table[VARIANT_MAX * 10 * 3] = { cryptonight_single_hash, cryptonight_double_hash, cryptonight_single_hash, @@ -93,7 +87,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_IPBC + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TUBE cryptonight_single_hash, cryptonight_double_hash, @@ -119,6 +113,28 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + # ifndef XMRIG_NO_AEON cryptonight_single_hash, cryptonight_double_hash, @@ -142,20 +158,12 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, - cryptonight_single_hash, - cryptonight_double_hash, - cryptonight_single_hash, - cryptonight_double_hash, - cryptonight_triple_hash, - cryptonight_quad_hash, - cryptonight_penta_hash, - cryptonight_triple_hash, - cryptonight_quad_hash, - cryptonight_penta_hash, - + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TUBE nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XTL nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_MSR nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XAO + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RTO # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, @@ -163,6 +171,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif # ifndef XMRIG_NO_SUMO @@ -178,7 +188,18 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_penta_hash, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_IPBC + + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XTL nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_MSR @@ -192,6 +213,9 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_triple_hash, cryptonight_quad_hash, cryptonight_penta_hash, + + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XAO + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RTO # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, @@ -199,6 +223,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif }; diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 73f0dba7a3..686a84152c 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -61,7 +61,7 @@ bool MultiWorker::selfTest() if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE) { return verify(xmrig::VARIANT_0, test_output_v0_lite) && verify(xmrig::VARIANT_1, test_output_v1_lite) && - verify(xmrig::VARIANT_IPBC, test_output_ipbc_lite); + verify(xmrig::VARIANT_TUBE, test_output_ipbc_lite); } # endif From 084559d92aff322a519a91b6333c6350230a4f9a Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 9 Jul 2018 16:54:39 +0700 Subject: [PATCH 029/102] Add reference hashes for cn/xao and cn/rto. --- src/crypto/CryptoNight_test.h | 30 ++++++++++++++++++++++++++++++ src/workers/MultiWorker.cpp | 27 +++++++++++++++------------ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index 187ba07a3a..96a360918c 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -114,6 +114,36 @@ const static uint8_t test_output_msr[160] = { }; +// Alloy (XAO) +const static uint8_t test_output_xao[160] = { + 0x9A, 0x29, 0xD0, 0xC4, 0xAF, 0xDC, 0x63, 0x9B, 0x65, 0x53, 0xB1, 0xC8, 0x37, 0x35, 0x11, 0x4C, + 0x5D, 0x77, 0x16, 0x21, 0x42, 0x97, 0x5C, 0xB8, 0x50, 0xC0, 0xA5, 0x1F, 0x64, 0x07, 0xBD, 0x33, + 0xF1, 0xC9, 0x98, 0x40, 0x42, 0xDE, 0x39, 0xD1, 0xBA, 0x2D, 0xAD, 0xEC, 0xFE, 0xEA, 0xD8, 0x46, + 0x56, 0x1C, 0x32, 0x90, 0x42, 0x63, 0x10, 0x80, 0xD7, 0x01, 0xE4, 0xE6, 0x20, 0xB3, 0x60, 0x45, + 0x05, 0xE5, 0xC2, 0x18, 0xCD, 0x07, 0xA4, 0x40, 0x42, 0x91, 0xE2, 0xA4, 0x52, 0x54, 0x79, 0xBA, + 0xCD, 0x7E, 0x61, 0x2D, 0x7F, 0x7E, 0x69, 0x5E, 0xD7, 0xC0, 0x06, 0x65, 0xD7, 0xA1, 0xB8, 0xB8, + 0x1E, 0x31, 0x1C, 0xD3, 0xB7, 0xBC, 0x78, 0x3C, 0x01, 0xAF, 0x77, 0xAA, 0xF3, 0x0F, 0x4C, 0xF2, + 0xD1, 0x8B, 0x58, 0xC7, 0xEB, 0x99, 0x91, 0x53, 0x43, 0x71, 0x47, 0x99, 0x9E, 0x04, 0xA4, 0xEA, + 0xB8, 0xA3, 0xB0, 0x9E, 0x09, 0xF5, 0x57, 0x5C, 0xCF, 0x8A, 0xC6, 0xCA, 0x88, 0x51, 0x9A, 0x01, + 0x31, 0xCC, 0x0C, 0xA6, 0x53, 0xB5, 0x5F, 0xFD, 0x7D, 0x29, 0x3A, 0x35, 0xE9, 0x0E, 0x25, 0x6C +}; + + +// Arto (RTO) +const static uint8_t test_output_rto[160] = { + 0x82, 0x66, 0x1E, 0x1C, 0x6E, 0x64, 0x36, 0x66, 0x84, 0x06, 0x32, 0x7A, 0x9B, 0xB1, 0x13, 0x19, + 0xA5, 0x56, 0x16, 0x15, 0xDF, 0xEC, 0x1C, 0x9E, 0xE3, 0x88, 0x4A, 0x6C, 0x1C, 0xEB, 0x76, 0xA5, + 0xB3, 0xFB, 0xF4, 0x3F, 0x2B, 0x6A, 0x3A, 0x39, 0xA3, 0x6E, 0x08, 0x33, 0x67, 0x90, 0x31, 0xB9, + 0x3F, 0x27, 0xE4, 0x79, 0x32, 0x61, 0x6B, 0x5C, 0x8A, 0xF8, 0xAF, 0xC0, 0x60, 0xFD, 0x83, 0xB7, + 0x11, 0x11, 0x89, 0xB4, 0xDC, 0xAE, 0x40, 0xC8, 0x64, 0xAA, 0x4D, 0x19, 0x23, 0x7B, 0xD3, 0x27, + 0xB2, 0x0F, 0xA7, 0x50, 0x7D, 0xCA, 0xF5, 0x03, 0x06, 0xB2, 0x26, 0x62, 0xF3, 0x68, 0x2D, 0x30, + 0x6F, 0x93, 0x1E, 0xFF, 0xCD, 0x85, 0x40, 0x28, 0x5F, 0xC3, 0x8C, 0x76, 0x51, 0x9E, 0xD5, 0x06, + 0x32, 0xD6, 0x35, 0x83, 0xF6, 0x3B, 0x54, 0x4F, 0xA1, 0x9C, 0x13, 0xD8, 0xC4, 0x0E, 0x01, 0x2F, + 0x29, 0xDB, 0x8C, 0x1C, 0xB7, 0x06, 0x86, 0x79, 0x6D, 0xFF, 0x9F, 0x89, 0x3B, 0x3A, 0xA5, 0x79, + 0xE7, 0x81, 0x4E, 0x2A, 0xBD, 0x62, 0xC1, 0x1B, 0x7C, 0xB9, 0x33, 0x7B, 0xEE, 0x95, 0x80, 0xB3 +}; + + #ifndef XMRIG_NO_AEON const static uint8_t test_output_v0_lite[160] = { 0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E, diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 686a84152c..5e004635e3 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -50,25 +50,28 @@ MultiWorker::~MultiWorker() template bool MultiWorker::selfTest() { - if (m_thread->algorithm() == xmrig::CRYPTONIGHT) { - return verify(xmrig::VARIANT_0, test_output_v0) && - verify(xmrig::VARIANT_1, test_output_v1) && - verify(xmrig::VARIANT_XTL, test_output_xtl) && - verify(xmrig::VARIANT_MSR, test_output_msr); + using namespace xmrig; + + if (m_thread->algorithm() == CRYPTONIGHT) { + return verify(VARIANT_0, test_output_v0) && + verify(VARIANT_1, test_output_v1) && + verify(VARIANT_XTL, test_output_xtl) && + verify(VARIANT_MSR, test_output_msr) && + verify(VARIANT_XAO, test_output_xao) && + verify(VARIANT_RTO, test_output_rto); } # ifndef XMRIG_NO_AEON - if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE) { - return verify(xmrig::VARIANT_0, test_output_v0_lite) && - verify(xmrig::VARIANT_1, test_output_v1_lite) && - verify(xmrig::VARIANT_TUBE, test_output_ipbc_lite); + if (m_thread->algorithm() == CRYPTONIGHT_LITE) { + return verify(VARIANT_0, test_output_v0_lite) && + verify(VARIANT_1, test_output_v1_lite); } # endif # ifndef XMRIG_NO_SUMO - if (m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY) { - return verify(xmrig::VARIANT_0, test_output_v0_heavy) && - verify(xmrig::VARIANT_XHV, test_output_xhv_heavy); + if (m_thread->algorithm() == CRYPTONIGHT_HEAVY) { + return verify(VARIANT_0, test_output_v0_heavy) && + verify(VARIANT_XHV, test_output_xhv_heavy); } # endif From 51180def50e7e30dd81847b984d4a361bf642a43 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 9 Jul 2018 20:21:53 +0700 Subject: [PATCH 030/102] Add cn-heavy/tube. --- src/crypto/CryptoNight_test.h | 30 +++++++++---------- src/crypto/CryptoNight_x86.h | 56 ++++++++++++++++++++++++++++------- src/workers/MultiWorker.cpp | 5 ++-- 3 files changed, 64 insertions(+), 27 deletions(-) diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index 96a360918c..16296efbfc 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -172,21 +172,6 @@ const static uint8_t test_output_v1_lite[160] = { 0x8C, 0x2B, 0xA4, 0x1F, 0x60, 0x76, 0x39, 0xD7, 0xF6, 0x46, 0x77, 0x18, 0x20, 0xAD, 0xD4, 0xC9, 0x87, 0xF7, 0x37, 0xDA, 0xFD, 0xBA, 0xBA, 0xD2, 0xF2, 0x68, 0xDC, 0x26, 0x8D, 0x1B, 0x08, 0xC6 }; - - -// IPBC -const static uint8_t test_output_ipbc_lite[160] = { - 0xE4, 0x93, 0x8C, 0xAA, 0x59, 0x8D, 0x02, 0x8A, 0xB8, 0x6F, 0x25, 0xD2, 0xB1, 0x23, 0xD0, 0xD5, - 0x33, 0xE3, 0x9F, 0x37, 0xAC, 0xE5, 0xF8, 0xEB, 0x7A, 0xE8, 0x40, 0xEB, 0x5D, 0xB1, 0x35, 0x5F, - 0xB2, 0x47, 0x86, 0xF0, 0x7F, 0x6F, 0x4B, 0x55, 0x3E, 0xA1, 0xBB, 0xE8, 0xA1, 0x75, 0x00, 0x2D, - 0x07, 0x9A, 0x21, 0x0E, 0xBD, 0x06, 0x6A, 0xB0, 0xFD, 0x96, 0x9E, 0xE6, 0xE4, 0x69, 0x67, 0xBB, - 0x88, 0x45, 0x0B, 0x91, 0x0B, 0x7B, 0xCB, 0x21, 0x3C, 0x3C, 0x09, 0x30, 0x07, 0x71, 0x07, 0xD5, - 0xB8, 0x2D, 0x83, 0x09, 0xAF, 0x7E, 0xB2, 0xA8, 0xAC, 0x25, 0xDC, 0x10, 0xF8, 0x63, 0x6A, 0xBC, - 0x73, 0x01, 0x4E, 0xA8, 0x1C, 0xDA, 0x9A, 0x86, 0x17, 0xEC, 0xA8, 0xFB, 0xAA, 0x23, 0x23, 0x17, - 0xE1, 0x32, 0x68, 0x9C, 0x4C, 0xF4, 0x08, 0xED, 0xB0, 0x15, 0xC3, 0xA9, 0x0F, 0xF0, 0xA2, 0x7E, - 0xD9, 0xE4, 0x23, 0xA7, 0x9E, 0x91, 0xD8, 0x73, 0x94, 0xD6, 0x6C, 0x70, 0x9B, 0x8B, 0x72, 0x92, - 0xA3, 0xA4, 0x0A, 0xE2, 0x3C, 0x0A, 0x34, 0x88, 0xA1, 0x6D, 0xFE, 0x02, 0x44, 0x60, 0x7B, 0x3D -}; #endif @@ -216,6 +201,21 @@ const static uint8_t test_output_xhv_heavy[160] = { 0x13, 0x91, 0x89, 0xB4, 0x5B, 0xA9, 0x2A, 0x7A, 0x09, 0x65, 0x14, 0x20, 0x76, 0x24, 0x6C, 0x80, 0x1D, 0x3F, 0x9F, 0xCD, 0x68, 0x39, 0xA9, 0x42, 0x27, 0xC1, 0x0C, 0x53, 0x98, 0x35, 0x60, 0x7A }; + + +// TUBE +const static uint8_t test_output_tube_heavy[160] = { + 0xFE, 0x53, 0x35, 0x20, 0x76, 0xEA, 0xE6, 0x89, 0xFA, 0x3B, 0x4F, 0xDA, 0x61, 0x46, 0x34, 0xCF, + 0xC3, 0x12, 0xEE, 0x0C, 0x38, 0x7D, 0xF2, 0xB8, 0xB7, 0x4D, 0xA2, 0xA1, 0x59, 0x74, 0x12, 0x35, + 0xCD, 0x3F, 0x29, 0xDF, 0x07, 0x4A, 0x14, 0xAD, 0x0B, 0x98, 0x99, 0x37, 0xCA, 0x14, 0x68, 0xA3, + 0x8D, 0xAE, 0x86, 0xC1, 0xA3, 0x54, 0x05, 0xBE, 0xEA, 0x6D, 0x29, 0x24, 0x0C, 0x82, 0x97, 0x74, + 0xA0, 0x64, 0x77, 0xCD, 0x8D, 0x8A, 0xC3, 0x10, 0xB4, 0x89, 0x0E, 0xBB, 0x7D, 0xE6, 0x32, 0x8F, + 0xF4, 0x2D, 0xB6, 0x9E, 0x8A, 0xF9, 0xF8, 0xEE, 0x2C, 0xD0, 0x74, 0xED, 0xA9, 0xAA, 0xA1, 0xFB, + 0xE2, 0xC9, 0x89, 0x66, 0xD6, 0x66, 0x52, 0xA2, 0x16, 0xDA, 0x36, 0xA0, 0x10, 0x62, 0xD2, 0xB1, + 0x76, 0xD1, 0x31, 0xE9, 0x1C, 0x08, 0xB6, 0xCA, 0xAF, 0x89, 0xB9, 0x3D, 0x2C, 0xFA, 0x9A, 0x30, + 0x74, 0x6A, 0x96, 0xA1, 0x95, 0x6C, 0xBB, 0x46, 0x4D, 0xE0, 0xEB, 0x28, 0xBE, 0x2A, 0x8C, 0x34, + 0x57, 0x79, 0xBE, 0x52, 0xFB, 0xBC, 0x68, 0x43, 0x45, 0xF4, 0xDF, 0xA5, 0xA8, 0xFD, 0x55, 0xA6 +}; #endif diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 86a1011ec9..5fa2a2942a 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -386,6 +386,27 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output) } +static inline __m128i aes_round_tweak_div(__m128i& val, const __m128i& key) +{ + alignas(16) uint32_t k[4]; + alignas(16) uint32_t x[4]; + + _mm_store_si128((__m128i*)k, key); + val = _mm_xor_si128(val, _mm_cmpeq_epi32(_mm_setzero_si128(), _mm_setzero_si128())); // val = ~val; + _mm_store_si128((__m128i*)x, val); + #define BYTE(p, i) ((unsigned char*)&p)[i] + k[0] ^= saes_table[0][BYTE(x[0], 0)] ^ saes_table[1][BYTE(x[1], 1)] ^ saes_table[2][BYTE(x[2], 2)] ^ saes_table[3][BYTE(x[3], 3)]; + x[0] ^= k[0]; + k[1] ^= saes_table[0][BYTE(x[1], 0)] ^ saes_table[1][BYTE(x[2], 1)] ^ saes_table[2][BYTE(x[3], 2)] ^ saes_table[3][BYTE(x[0], 3)]; + x[1] ^= k[1]; + k[2] ^= saes_table[0][BYTE(x[2], 0)] ^ saes_table[1][BYTE(x[3], 1)] ^ saes_table[2][BYTE(x[0], 2)] ^ saes_table[3][BYTE(x[1], 3)]; + x[2] ^= k[2]; + k[3] ^= saes_table[0][BYTE(x[3], 0)] ^ saes_table[1][BYTE(x[0], 1)] ^ saes_table[2][BYTE(x[1], 2)] ^ saes_table[3][BYTE(x[2], 3)]; + #undef BYTE + + return _mm_load_si128((__m128i*)k);} + + template static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp) { @@ -433,12 +454,17 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si for (size_t i = 0; i < ITERATIONS; i++) { __m128i cx; + if (VARIANT == xmrig::VARIANT_TUBE || !SOFT_AES) { + cx = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); + } - if (SOFT_AES) { + if (VARIANT == xmrig::VARIANT_TUBE) { + cx = aes_round_tweak_div(cx, _mm_set_epi64x(ah0, al0)); + } + else if (SOFT_AES) { cx = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); } else { - cx = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); } @@ -462,7 +488,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_RTO) { + if (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } else { @@ -539,14 +565,20 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si for (size_t i = 0; i < ITERATIONS; i++) { __m128i cx0, cx1; + if (VARIANT == xmrig::VARIANT_TUBE || !SOFT_AES) { + cx0 = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); + cx1 = _mm_load_si128((__m128i *) &l1[idx1 & MASK]); + } - if (SOFT_AES) { + if (VARIANT == xmrig::VARIANT_TUBE) { + cx0 = aes_round_tweak_div(cx0, _mm_set_epi64x(ah0, al0)); + cx1 = aes_round_tweak_div(cx1, _mm_set_epi64x(ah1, al1)); + } + else if (SOFT_AES) { cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], _mm_set_epi64x(ah1, al1)); } else { - cx0 = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); - cx1 = _mm_load_si128((__m128i *) &l1[idx1 & MASK]); cx0 = _mm_aesenc_si128(cx0, _mm_set_epi64x(ah0, al0)); cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); } @@ -576,7 +608,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_RTO) { + if (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } else { @@ -615,7 +647,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l1[idx1 & MASK])[0] = al1; if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_RTO) { + if (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO) { ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; } else { @@ -662,7 +694,10 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si #define CN_STEP2(a, b, c, l, ptr, idx) \ - if (SOFT_AES) { \ + if (VARIANT == xmrig::VARIANT_TUBE) { \ + c = aes_round_tweak_div(c, a); \ + } \ + else if (SOFT_AES) { \ c = soft_aesenc(c, a); \ } else { \ c = _mm_aesenc_si128(c, a); \ @@ -690,7 +725,8 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si if (IS_MONERO) { \ _mm_store_si128(ptr, _mm_xor_si128(a, mc)); \ \ - if (VARIANT == xmrig::VARIANT_RTO) { \ + if (VARIANT == xmrig::VARIANT_TUBE || \ + VARIANT == xmrig::VARIANT_RTO) { \ ((uint64_t*)ptr)[1] ^= ((uint64_t*)ptr)[0]; \ } \ } else { \ diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 5e004635e3..5d43875c47 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -70,8 +70,9 @@ bool MultiWorker::selfTest() # ifndef XMRIG_NO_SUMO if (m_thread->algorithm() == CRYPTONIGHT_HEAVY) { - return verify(VARIANT_0, test_output_v0_heavy) && - verify(VARIANT_XHV, test_output_xhv_heavy); + return verify(VARIANT_0, test_output_v0_heavy) && + verify(VARIANT_XHV, test_output_xhv_heavy) && + verify(VARIANT_TUBE, test_output_tube_heavy); } # endif From c4d9cbea93036fc25564bd01e1b9ee314a9ca96b Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 9 Jul 2018 22:28:53 +0700 Subject: [PATCH 031/102] Optimize cn-heavy/tube. --- src/crypto/CryptoNight_x86.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 5fa2a2942a..199c190bbc 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -386,25 +386,26 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output) } -static inline __m128i aes_round_tweak_div(__m128i& val, const __m128i& key) +static inline __m128i aes_round_tweak_div(const __m128i &in, const __m128i &key) { alignas(16) uint32_t k[4]; alignas(16) uint32_t x[4]; - _mm_store_si128((__m128i*)k, key); - val = _mm_xor_si128(val, _mm_cmpeq_epi32(_mm_setzero_si128(), _mm_setzero_si128())); // val = ~val; - _mm_store_si128((__m128i*)x, val); - #define BYTE(p, i) ((unsigned char*)&p)[i] - k[0] ^= saes_table[0][BYTE(x[0], 0)] ^ saes_table[1][BYTE(x[1], 1)] ^ saes_table[2][BYTE(x[2], 2)] ^ saes_table[3][BYTE(x[3], 3)]; + _mm_store_si128((__m128i*) k, key); + _mm_store_si128((__m128i*) x, _mm_xor_si128(in, _mm_set_epi64x(0xffffffffffffffff, 0xffffffffffffffff))); + + #define BYTE(p, i) ((unsigned char*)&x[p])[i] + k[0] ^= saes_table[0][BYTE(0, 0)] ^ saes_table[1][BYTE(1, 1)] ^ saes_table[2][BYTE(2, 2)] ^ saes_table[3][BYTE(3, 3)]; x[0] ^= k[0]; - k[1] ^= saes_table[0][BYTE(x[1], 0)] ^ saes_table[1][BYTE(x[2], 1)] ^ saes_table[2][BYTE(x[3], 2)] ^ saes_table[3][BYTE(x[0], 3)]; + k[1] ^= saes_table[0][BYTE(1, 0)] ^ saes_table[1][BYTE(2, 1)] ^ saes_table[2][BYTE(3, 2)] ^ saes_table[3][BYTE(0, 3)]; x[1] ^= k[1]; - k[2] ^= saes_table[0][BYTE(x[2], 0)] ^ saes_table[1][BYTE(x[3], 1)] ^ saes_table[2][BYTE(x[0], 2)] ^ saes_table[3][BYTE(x[1], 3)]; + k[2] ^= saes_table[0][BYTE(2, 0)] ^ saes_table[1][BYTE(3, 1)] ^ saes_table[2][BYTE(0, 2)] ^ saes_table[3][BYTE(1, 3)]; x[2] ^= k[2]; - k[3] ^= saes_table[0][BYTE(x[3], 0)] ^ saes_table[1][BYTE(x[0], 1)] ^ saes_table[2][BYTE(x[1], 2)] ^ saes_table[3][BYTE(x[2], 3)]; + k[3] ^= saes_table[0][BYTE(3, 0)] ^ saes_table[1][BYTE(0, 1)] ^ saes_table[2][BYTE(1, 2)] ^ saes_table[3][BYTE(2, 3)]; #undef BYTE - return _mm_load_si128((__m128i*)k);} + return _mm_load_si128((__m128i*)k); +} template From 10c4c2f7896b2d4c62335886c6b93465bde35bc3 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 10 Jul 2018 00:29:16 +0700 Subject: [PATCH 032/102] Add new algorithms for ARM. --- src/crypto/CryptoNight_arm.h | 49 ++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 845c027ec1..efb5759e1e 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -382,6 +382,28 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output) } +static inline __m128i aes_round_tweak_div(const __m128i &in, const __m128i &key) +{ + alignas(16) uint32_t k[4]; + alignas(16) uint32_t x[4]; + + _mm_store_si128((__m128i*) k, key); + _mm_store_si128((__m128i*) x, _mm_xor_si128(in, _mm_set_epi64x(0xffffffffffffffff, 0xffffffffffffffff))); + + #define BYTE(p, i) ((unsigned char*)&x[p])[i] + k[0] ^= saes_table[0][BYTE(0, 0)] ^ saes_table[1][BYTE(1, 1)] ^ saes_table[2][BYTE(2, 2)] ^ saes_table[3][BYTE(3, 3)]; + x[0] ^= k[0]; + k[1] ^= saes_table[0][BYTE(1, 0)] ^ saes_table[1][BYTE(2, 1)] ^ saes_table[2][BYTE(3, 2)] ^ saes_table[3][BYTE(0, 3)]; + x[1] ^= k[1]; + k[2] ^= saes_table[0][BYTE(2, 0)] ^ saes_table[1][BYTE(3, 1)] ^ saes_table[2][BYTE(0, 2)] ^ saes_table[3][BYTE(1, 3)]; + x[2] ^= k[2]; + k[3] ^= saes_table[0][BYTE(3, 0)] ^ saes_table[1][BYTE(0, 1)] ^ saes_table[2][BYTE(1, 2)] ^ saes_table[3][BYTE(2, 3)]; + #undef BYTE + + return _mm_load_si128((__m128i*)k); +} + + template static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp) { @@ -428,12 +450,17 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si for (size_t i = 0; i < ITERATIONS; i++) { __m128i cx; + if (VARIANT == xmrig::VARIANT_TUBE || !SOFT_AES) { + cx = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); + } - if (SOFT_AES) { + if (VARIANT == xmrig::VARIANT_TUBE) { + cx = aes_round_tweak_div(cx, _mm_set_epi64x(ah0, al0)); + } + else if (SOFT_AES) { cx = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); } else { - cx = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); } @@ -457,7 +484,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_IPBC) { + if (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } else { @@ -536,14 +563,20 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si for (size_t i = 0; i < ITERATIONS; i++) { __m128i cx0, cx1; + if (VARIANT == xmrig::VARIANT_TUBE || !SOFT_AES) { + cx0 = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); + cx1 = _mm_load_si128((__m128i *) &l1[idx1 & MASK]); + } - if (SOFT_AES) { + if (VARIANT == xmrig::VARIANT_TUBE) { + cx0 = aes_round_tweak_div(cx0, _mm_set_epi64x(ah0, al0)); + cx1 = aes_round_tweak_div(cx1, _mm_set_epi64x(ah1, al1)); + } + else if (SOFT_AES) { cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], _mm_set_epi64x(ah1, al1)); } else { - cx0 = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); - cx1 = _mm_load_si128((__m128i *) &l1[idx1 & MASK]); cx0 = _mm_aesenc_si128(cx0, _mm_set_epi64x(ah0, al0)); cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); } @@ -573,7 +606,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_IPBC) { + if (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } else { @@ -614,7 +647,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l1[idx1 & MASK])[0] = al1; if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_IPBC) { + if (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO) { ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; } else { From f40a990831739ab1d855886c39e53ad51ad2d8a1 Mon Sep 17 00:00:00 2001 From: xmrig Date: Wed, 11 Jul 2018 20:42:16 +0700 Subject: [PATCH 033/102] Update CHANGELOG.md --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b8f8a6719..8ef9573d40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v2.6.4 +- [#700](https://github.com/xmrig/xmrig/issues/700) `cryptonight-lite/ipbc` replaced to `cryptonight-heavy/tube` for **Bittube (TUBE)**. +- Added `cryptonight/rto` (cryptonight variant 1 with IPBC/TUBE mod) variant for **Arto (RTO)** coin. +- Added `cryptonight/xao` (original cryptonight with bigger iteration count) variant for **Alloy (XAO)** coin. +- Better variant detection for **nicehash.com** and **minergate.com**. +- [#692](https://github.com/xmrig/xmrig/issues/692) Added support for specify both algorithm and variant via single `algo` option. + # v2.6.3 - **Added support for new cryptonight-heavy variant xhv** (`cn-heavy/xhv`) for upcoming Haven Protocol fork. - **Added support for new cryptonight variant msr** (`cn/msr`) also known as `cryptonight-fast` for upcoming Masari fork. From 0bd753ae910146e920b55d63b382960e6f0f3230 Mon Sep 17 00:00:00 2001 From: xmrig Date: Wed, 11 Jul 2018 20:50:55 +0700 Subject: [PATCH 034/102] Update ALGORITHMS.md --- doc/ALGORITHMS.md | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/doc/ALGORITHMS.md b/doc/ALGORITHMS.md index d9a34a16db..d62831dede 100644 --- a/doc/ALGORITHMS.md +++ b/doc/ALGORITHMS.md @@ -7,35 +7,7 @@ Algorithm selection splitted to 2 parts: * Global base algorithm per miner or proxy instance, `algo` option. Possible values: `cryptonight`, `cryptonight-lite`, `cryptonight-heavy`. * Algorithm variant specified separately for each pool, `variant` option. -Possible variants for `cryptonight`: - - * `0` Original cryptonight. - * `1` cryptonight variant 1, also known as cryptonight v7 or monero7. - * `"xtl"` Stellite coin variant. - -Possible variants for `cryptonight-lite`: - - * `0` Original cryptonight-lite. - * `1` cryptonight-lite variant 1, also known as cryptonight-lite v7 or aeon7. - * `"ipbc"` IPBC coin variant. - -For `cryptonight-heavy` currently no variants. - - -### Cheatsheet - -You mine **Sumokoin** or **Haven Protocol**? -Your algorithm is `cryptonight-heavy` no variant option need. - -You mine **Aeon**, **TurtleCoin** or **IPBC**? -Your base algorithm is `cryptonight-lite`: - -Variants: - * Aeon: `-1` autodetect. `0` right now, `1` after fork. - * TurtleCoin: `1`. - * IPBC: `"ipbc"`. - -In all other cases base algorithm is `cryptonight`. + * [Full table for supported algorithm and variants.](https://github.com/xmrig/xmrig-proxy/blob/master/doc/STRATUM_EXT.md#14-algorithm-names-and-variants) ### Mining algorithm negotiation If your pool support [mining algorithm negotiation](https://github.com/xmrig/xmrig-proxy/issues/168) miner will choice proper variant automaticaly and if you choice wrong base algorithm you will see error message. From ec2626254ce048191717a11271f61e49af042915 Mon Sep 17 00:00:00 2001 From: xmrig Date: Wed, 11 Jul 2018 20:51:30 +0700 Subject: [PATCH 035/102] Update ALGORITHMS.md --- doc/ALGORITHMS.md | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/ALGORITHMS.md b/doc/ALGORITHMS.md index d62831dede..f4a01e2669 100644 --- a/doc/ALGORITHMS.md +++ b/doc/ALGORITHMS.md @@ -6,7 +6,6 @@ Algorithm selection splitted to 2 parts: * Global base algorithm per miner or proxy instance, `algo` option. Possible values: `cryptonight`, `cryptonight-lite`, `cryptonight-heavy`. * Algorithm variant specified separately for each pool, `variant` option. - * [Full table for supported algorithm and variants.](https://github.com/xmrig/xmrig-proxy/blob/master/doc/STRATUM_EXT.md#14-algorithm-names-and-variants) ### Mining algorithm negotiation From fb4024c2c2d3ba5fe1c559ca4dbec108e37914bd Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 12 Jul 2018 00:48:30 +0700 Subject: [PATCH 036/102] v2.6.4 --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index 37df900616..76a3c77f6b 100644 --- a/src/version.h +++ b/src/version.h @@ -27,7 +27,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "2.6.4-dev" +#define APP_VERSION "2.6.4" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com" From 01c4dfd68df2cf8e42fd02625765e3099a7b491c Mon Sep 17 00:00:00 2001 From: xmrig Date: Thu, 12 Jul 2018 02:11:25 +0700 Subject: [PATCH 037/102] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a07470c986..6054b9f8bf 100644 --- a/README.md +++ b/README.md @@ -124,10 +124,10 @@ Please note performance is highly dependent on system load. The numbers above ar ## Release checksums ### SHA-256 ``` -dbc2b0f92df5098dc91a361febfda46382d347ae3085415f35e1637b7ebc67e9 xmrig-2.6.3-xenial-amd64.tar.gz/xmrig-2.6.3/xmrig -b54ffe80cd54ac486f03f064c09de80b6ec29f19ddebb50a8d7316a947045b85 xmrig-2.6.3-gcc-win32.zip/xmrig.exe -c828ed21bbaf71a808b26928ab1eb6f6355029f2b731a639043733e6b48e9d77 xmrig-2.6.3-gcc-win64.zip/xmrig.exe -2e7432d14546b510506ccc22df62ef334d424d02fbc6baaa7a0498a0102de156 xmrig-2.6.3-msvc-win64.zip/xmrig.exe +34d390a499d2098bce92e6b85b4858ee6255a7e2d4e03197ba4f6a759efe349c xmrig-2.6.4-xenial-amd64.tar.gz/xmrig-2.6.4/xmrig +cb6792c092c14f0f25d5774049a0adec403877a4564956220dcd9ba0fc488c82 xmrig-2.6.4-gcc-win32.zip/xmrig.exe +cb3c5619a8391f989c6a69135d890c3126eda9841b9dc591d44f02078a6fd49b xmrig-2.6.4-gcc-win64.zip/xmrig.exe +ea2e92bb10d0482880f8d389b7915948e11f672ca8559b0901d8a8fa8e9d733e xmrig-2.6.4-msvc-win64.zip/xmrig.exe ``` ## Contacts From ff58e5ffc093eaaf9e7d69a263e285285f8bbe92 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 20 Jul 2018 03:18:38 +0700 Subject: [PATCH 038/102] 2.6.5-dev --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index 76a3c77f6b..91a144e781 100644 --- a/src/version.h +++ b/src/version.h @@ -27,7 +27,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "2.6.4" +#define APP_VERSION "2.6.5-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com" @@ -35,7 +35,7 @@ #define APP_VER_MAJOR 2 #define APP_VER_MINOR 6 -#define APP_VER_PATCH 4 +#define APP_VER_PATCH 5 #ifdef _MSC_VER # if (_MSC_VER >= 1910) From 9a1e8109faa1005986b9e6997434576b81571f14 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 20 Jul 2018 03:37:07 +0700 Subject: [PATCH 039/102] Sync changes with AMD miner. --- CMakeLists.txt | 2 + src/common/crypto/keccak.h | 6 +++ src/common/interfaces/IConfig.h | 3 ++ src/common/log/BasicLog.cpp | 89 +++++++++++++++++++++++++++++++++ src/common/log/BasicLog.h | 55 ++++++++++++++++++++ src/common/log/Log.cpp | 9 ++++ src/common/log/Log.h | 5 +- src/common/utils/timestamp.h | 47 +++++++++++++++++ src/common/xmrig.h | 4 +- 9 files changed, 217 insertions(+), 3 deletions(-) create mode 100644 src/common/log/BasicLog.cpp create mode 100644 src/common/log/BasicLog.h create mode 100644 src/common/utils/timestamp.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e263808e1d..07397ac48b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ set(HEADERS src/common/interfaces/IStrategy.h src/common/interfaces/IStrategyListener.h src/common/interfaces/IWatcherListener.h + src/common/log/BasicLog.h src/common/log/ConsoleLog.h src/common/log/FileLog.h src/common/log/Log.h @@ -94,6 +95,7 @@ set(SOURCES src/common/Console.cpp src/common/crypto/Algorithm.cpp src/common/crypto/keccak.cpp + src/common/log/BasicLog.cpp src/common/log/ConsoleLog.cpp src/common/log/FileLog.cpp src/common/log/Log.cpp diff --git a/src/common/crypto/keccak.h b/src/common/crypto/keccak.h index 0413ec2d7c..da8d6c52a5 100644 --- a/src/common/crypto/keccak.h +++ b/src/common/crypto/keccak.h @@ -41,6 +41,12 @@ inline void keccak(const uint8_t *in, size_t inlen, uint8_t *md) keccak(in, static_cast(inlen), md, 200); } + +inline void keccak(const char *in, size_t inlen, uint8_t *md) +{ + keccak(reinterpret_cast(in), static_cast(inlen), md, 200); +} + // update the state void keccakf(uint64_t st[25], int norounds); diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 62c7ba945a..4b3f878850 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -83,6 +83,9 @@ class IConfig OclAffinity = 1401, OclDevices = 1402, OclLaunch = 1403, + OclCache = 1404, + OclPrint = 1405, + OclLoader = 1406, // xmrig-proxy AccessLogFileKey = 'A', diff --git a/src/common/log/BasicLog.cpp b/src/common/log/BasicLog.cpp new file mode 100644 index 0000000000..cb4defcdee --- /dev/null +++ b/src/common/log/BasicLog.cpp @@ -0,0 +1,89 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * + * 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 Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include +#include +#include +#include +#include + +#ifdef WIN32 +# include +# include +#endif + + +#include "common/log/BasicLog.h" +#include "common/log/Log.h" + + +BasicLog::BasicLog() +{ +} + + +void BasicLog::message(Level level, const char* fmt, va_list args) +{ + time_t now = time(nullptr); + tm stime; + +# ifdef _WIN32 + localtime_s(&stime, &now); +# else + localtime_r(&now, &stime); +# endif + + snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s", + stime.tm_year + 1900, + stime.tm_mon + 1, + stime.tm_mday, + stime.tm_hour, + stime.tm_min, + stime.tm_sec, + Log::colorByLevel(level, false), + fmt, + Log::endl(false) + ); + + print(args); +} + + +void BasicLog::text(const char* fmt, va_list args) +{ + snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(false)); + + print(args); +} + + +void BasicLog::print(va_list args) +{ + if (vsnprintf(m_buf, sizeof(m_buf) - 1, m_fmt, args) <= 0) { + return; + } + + fputs(m_buf, stdout); + fflush(stdout); +} diff --git a/src/common/log/BasicLog.h b/src/common/log/BasicLog.h new file mode 100644 index 0000000000..523538e957 --- /dev/null +++ b/src/common/log/BasicLog.h @@ -0,0 +1,55 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * + * 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 Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __BASICLOG_H__ +#define __BASICLOG_H__ + + +#include + + +#include "common/interfaces/ILogBackend.h" + + +namespace xmrig { + class Controller; +} + + +class BasicLog : public ILogBackend +{ +public: + BasicLog(); + + void message(Level level, const char *fmt, va_list args) override; + void text(const char *fmt, va_list args) override; + +private: + bool isWritable() const; + void print(va_list args); + + char m_buf[kBufferSize]; + char m_fmt[256]; +}; + +#endif /* __BASICLOG_H__ */ diff --git a/src/common/log/Log.cpp b/src/common/log/Log.cpp index ccf3800878..2af902099e 100644 --- a/src/common/log/Log.cpp +++ b/src/common/log/Log.cpp @@ -30,6 +30,7 @@ #include "common/interfaces/ILogBackend.h" +#include "common/log/BasicLog.h" #include "common/log/Log.h" @@ -109,6 +110,14 @@ const char *Log::endl(bool isColors) } +void Log::defaultInit() +{ + m_self = new Log(); + + add(new BasicLog()); +} + + Log::~Log() { for (auto backend : m_backends) { diff --git a/src/common/log/Log.h b/src/common/log/Log.h index bfa307173b..2774ae0c5f 100644 --- a/src/common/log/Log.h +++ b/src/common/log/Log.h @@ -36,7 +36,7 @@ class Log { public: - static inline Log* i() { assert(m_self != nullptr); return m_self; } + static inline Log* i() { if (!m_self) { defaultInit(); } return m_self; } static inline void add(ILogBackend *backend) { i()->m_backends.push_back(backend); } static inline void init() { if (!m_self) { new Log(); } } static inline void release() { assert(m_self != nullptr); delete m_self; } @@ -46,6 +46,7 @@ class Log static const char *colorByLevel(ILogBackend::Level level, bool isColors = true); static const char *endl(bool isColors = true); + static void defaultInit(); private: inline Log() { @@ -68,6 +69,8 @@ class Log #define RED(x) "\x1B[0;31m" x "\x1B[0m" #define GREEN_BOLD(x) "\x1B[1;32m" x "\x1B[0m" #define GREEN(x) "\x1B[0;32m" x "\x1B[0m" +#define YELLOW(x) "\x1B[0;33m" x "\x1B[0m" +#define YELLOW_BOLD(x) "\x1B[1;33m" x "\x1B[0m" #define MAGENTA_BOLD(x) "\x1B[1;35m" x "\x1B[0m" #define MAGENTA(x) "\x1B[0;35m" x "\x1B[0m" #define CYAN_BOLD(x) "\x1B[1;36m" x "\x1B[0m" diff --git a/src/common/utils/timestamp.h b/src/common/utils/timestamp.h new file mode 100644 index 0000000000..b4404b2e77 --- /dev/null +++ b/src/common/utils/timestamp.h @@ -0,0 +1,47 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * + * 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 Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __TIMESTAMP_H__ +#define __TIMESTAMP_H__ + + +#include + + +namespace xmrig { + + +int64_t currentMSecsSinceEpoch() +{ + using namespace std::chrono; + if (high_resolution_clock::is_steady) { + return time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); + } + + return time_point_cast(steady_clock::now()).time_since_epoch().count(); +} + + +} /* namespace xmrig */ + +#endif /* __TIMESTAMP_H__ */ diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 0ff945b90d..58a3540c73 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -33,7 +33,7 @@ enum Algo { INVALID_ALGO = -1, CRYPTONIGHT, /* CryptoNight (Monero) */ CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */ - CRYPTONIGHT_HEAVY /* CryptoNight-Heavy (SUMO) */ + CRYPTONIGHT_HEAVY /* CryptoNight-Heavy (RYO) */ }; @@ -65,7 +65,7 @@ enum Variant { VARIANT_XTL = 3, // Modified CryptoNight variant 1 (Stellite only) VARIANT_MSR = 4, // Modified CryptoNight variant 1 (Masari only) VARIANT_XHV = 5, // Modified CryptoNight-Heavy (Haven Protocol only) - VARIANT_XAO = 6, // Modified CryptoNight variant 1 (Alloy only) + VARIANT_XAO = 6, // Modified CryptoNight variant 0 (Alloy only) VARIANT_RTO = 7, // Modified CryptoNight variant 1 (Arto only) VARIANT_MAX }; From 2d34d1923d9b98829d2247ddc1d165ff592a1f2c Mon Sep 17 00:00:00 2001 From: xmrig Date: Sun, 29 Jul 2018 19:23:55 +0700 Subject: [PATCH 040/102] Update ALGORITHMS.md --- doc/ALGORITHMS.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/ALGORITHMS.md b/doc/ALGORITHMS.md index f4a01e2669..835a1d4917 100644 --- a/doc/ALGORITHMS.md +++ b/doc/ALGORITHMS.md @@ -7,8 +7,24 @@ Algorithm selection splitted to 2 parts: * Global base algorithm per miner or proxy instance, `algo` option. Possible values: `cryptonight`, `cryptonight-lite`, `cryptonight-heavy`. * Algorithm variant specified separately for each pool, `variant` option. * [Full table for supported algorithm and variants.](https://github.com/xmrig/xmrig-proxy/blob/master/doc/STRATUM_EXT.md#14-algorithm-names-and-variants) + +#### Example +```json +{ + "algo": "cryptonight", + ... + "pools": [ + { + "url": "...", + "variant": 1, + ... + } + ], + ... +} +``` -### Mining algorithm negotiation +## Mining algorithm negotiation If your pool support [mining algorithm negotiation](https://github.com/xmrig/xmrig-proxy/issues/168) miner will choice proper variant automaticaly and if you choice wrong base algorithm you will see error message. Pools with mining algorithm negotiation support. From 1ad0b0f705bb84ea66b8e9ea7aecea14faf94df9 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 28 Aug 2018 23:42:15 +0200 Subject: [PATCH 041/102] Cryptonight variant 2 support Reference code: https://github.com/monero-project/monero/pull/4218 --- src/common/crypto/Algorithm.cpp | 6 +- src/common/net/Job.cpp | 7 +- src/common/net/Pool.cpp | 2 + src/common/xmrig.h | 1 + src/crypto/CryptoNight_arm.h | 174 +++++---- src/crypto/CryptoNight_constants.h | 34 +- src/crypto/CryptoNight_monero.h | 72 +++- src/crypto/CryptoNight_test.h | 17 +- src/crypto/CryptoNight_x86.h | 558 ++++++++++++++--------------- src/workers/CpuThread.cpp | 15 + src/workers/MultiWorker.cpp | 1 + 11 files changed, 491 insertions(+), 396 deletions(-) diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index 31035fb106..05c890dc73 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -60,6 +60,7 @@ static AlgoData const algorithms[] = { { "cryptonight/msr", "cn/msr", xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR }, { "cryptonight/xao", "cn/xao", xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO }, { "cryptonight/rto", "cn/rto", xmrig::CRYPTONIGHT, xmrig::VARIANT_RTO }, + { "cryptonight/2", "cn/2", xmrig::CRYPTONIGHT, xmrig::VARIANT_2 }, # ifndef XMRIG_NO_AEON { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, @@ -81,6 +82,8 @@ static AlgoData const algorithms[] = { static AlgoData const xmrStakAlgorithms[] = { { "cryptonight-monerov7", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, { "cryptonight_v7", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, + { "cryptonight-monerov8", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_2 }, + { "cryptonight_v8", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_2 }, { "cryptonight_v7_stellite", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL }, { "cryptonight_lite", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 }, { "cryptonight-aeonv7", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, @@ -103,7 +106,8 @@ static const char *variants[] = { "msr", "xhv", "xao", - "rto" + "rto", + "2", }; diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index 80b521ea1a..e9f81e02ef 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -178,7 +178,12 @@ xmrig::Variant Job::variant() const } if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { - return m_algorithm.algo() == xmrig::CRYPTONIGHT_HEAVY ? xmrig::VARIANT_0 : xmrig::VARIANT_1; + if (m_algorithm.algo() == xmrig::CRYPTONIGHT_HEAVY) { + return xmrig::VARIANT_0; + } else if (m_algorithm.algo() == xmrig::CRYPTONIGHT_LITE) { + return xmrig::VARIANT_1; + } + return (m_blob[0] >= 8) ? xmrig::VARIANT_2 : xmrig::VARIANT_1; } return m_algorithm.variant(); diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 053f25070a..357cb330b1 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -211,6 +211,7 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const case xmrig::VARIANT_AUTO: case xmrig::VARIANT_0: case xmrig::VARIANT_1: + case xmrig::VARIANT_2: obj.AddMember("variant", m_algorithm.variant(), allocator); break; @@ -377,6 +378,7 @@ void Pool::rebuild() m_algorithms.push_back(m_algorithm); # ifndef XMRIG_PROXY_PROJECT + addVariant(xmrig::VARIANT_2); addVariant(xmrig::VARIANT_1); addVariant(xmrig::VARIANT_0); addVariant(xmrig::VARIANT_XTL); diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 58a3540c73..3e1b65dfd0 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -67,6 +67,7 @@ enum Variant { VARIANT_XHV = 5, // Modified CryptoNight-Heavy (Haven Protocol only) VARIANT_XAO = 6, // Modified CryptoNight variant 0 (Alloy only) VARIANT_RTO = 7, // Modified CryptoNight variant 1 (Arto only) + VARIANT_2 = 8, // CryptoNight variant 2 VARIANT_MAX }; diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index efb5759e1e..7f273765d5 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -404,19 +404,27 @@ static inline __m128i aes_round_tweak_div(const __m128i &in, const __m128i &key) } -template -static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp) +template +static inline void cryptonight_monero_tweak(const uint8_t* l, uint64_t idx, __m128i ax0, __m128i bx0, __m128i bx1, __m128i cx) { - mem_out[0] = EXTRACT64(tmp); + uint64_t* mem_out = (uint64_t*)&l[idx]; - uint64_t vh = vgetq_lane_u64(tmp, 1); + if (VARIANT == xmrig::VARIANT_2) { + VARIANT2_SHUFFLE(l, idx, ax0, bx0, bx1); + _mm_store_si128((__m128i *)mem_out, _mm_xor_si128(bx0, cx)); + } else { + __m128i tmp = _mm_xor_si128(bx0, cx); + mem_out[0] = EXTRACT64(tmp); - uint8_t x = vh >> 24; - static const uint16_t table = 0x7531; - const uint8_t index = (((x >> SHIFT) & 6) | (x & 1)) << 1; - vh ^= ((table >> index) & 0x3) << 28; + uint64_t vh = vgetq_lane_u64(tmp, 1); - mem_out[1] = vh; + uint8_t x = vh >> 24; + static const uint16_t table = 0x7531; + const uint8_t index = (((x >> (VARIANT == xmrig::VARIANT_XTL ? 4 : 3)) & 6) | (x & 1)) << 1; + vh ^= ((table >> index) & 0x3) << 28; + + mem_out[1] = vh; + } } @@ -426,27 +434,29 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_MONERO = xmrig::cn_is_monero(); + constexpr bool IS_V1 = xmrig::cn_uses_variant1(); - if (IS_MONERO && size < 43) { + if (IS_V1 && size < 43) { memset(output, 0, 32); return; } xmrig::keccak(input, size, ctx[0]->state); - VARIANT1_INIT(0); - cn_explode_scratchpad((__m128i*) ctx[0]->state, (__m128i*) ctx[0]->memory); const uint8_t* l0 = ctx[0]->memory; uint64_t* h0 = reinterpret_cast(ctx[0]->state); + VARIANT1_INIT(0); + VARIANT2_INIT(0); + uint64_t al0 = h0[0] ^ h0[4]; uint64_t ah0 = h0[1] ^ h0[5]; __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); + __m128i bx1 = _mm_set_epi64x(h0[9] ^ h0[11], h0[8] ^ h0[10]); - uint64_t idx0 = h0[0] ^ h0[4]; + uint64_t idx0 = al0; for (size_t i = 0; i < ITERATIONS; i++) { __m128i cx; @@ -454,44 +464,47 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si cx = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); } + const __m128i ax0 = _mm_set_epi64x(ah0, al0); if (VARIANT == xmrig::VARIANT_TUBE) { - cx = aes_round_tweak_div(cx, _mm_set_epi64x(ah0, al0)); + cx = aes_round_tweak_div(cx, ax0); } else if (SOFT_AES) { - cx = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); + cx = soft_aesenc((uint32_t*)&l0[idx0 & MASK], ax0); } else { - cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); + cx = _mm_aesenc_si128(cx, ax0); } - if (IS_MONERO) { - cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); + if (IS_V1 || VARIANT == xmrig::VARIANT_2) { + cryptonight_monero_tweak(l0, idx0 & MASK, ax0, bx0, bx1, cx); } else { _mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); } idx0 = EXTRACT64(cx); - bx0 = cx; uint64_t hi, lo, cl, ch; cl = ((uint64_t*) &l0[idx0 & MASK])[0]; ch = ((uint64_t*) &l0[idx0 & MASK])[1]; - lo = __umul128(idx0, cl, &hi); + if (VARIANT == xmrig::VARIANT_2) { + VARIANT2_INTEGER_MATH(0, cl, cx); + lo = __umul128(idx0, cl, &hi); + VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx0, bx1); + } + else { + lo = __umul128(idx0, cl, &hi); + } al0 += hi; ah0 += lo; ((uint64_t*)&l0[idx0 & MASK])[0] = al0; - if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO) { - ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; - } - else { - ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0; - } - } - else { + if (IS_V1 && (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO)) { + ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; + } else if (IS_V1) { + ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0; + } else { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0; } @@ -514,6 +527,8 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si idx0 = d ^ q; } } + bx1 = bx0; + bx0 = cx; } cn_implode_scratchpad((__m128i*) ctx[0]->memory, (__m128i*) ctx[0]->state); @@ -529,9 +544,9 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_MONERO = xmrig::cn_is_monero(); + constexpr bool IS_V1 = xmrig::cn_uses_variant1(); - if (IS_MONERO && size < 43) { + if (IS_V1 && size < 43) { memset(output, 0, 64); return; } @@ -539,14 +554,16 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si xmrig::keccak(input, size, ctx[0]->state); xmrig::keccak(input + size, size, ctx[1]->state); - VARIANT1_INIT(0); - VARIANT1_INIT(1); - const uint8_t* l0 = ctx[0]->memory; const uint8_t* l1 = ctx[1]->memory; uint64_t* h0 = reinterpret_cast(ctx[0]->state); uint64_t* h1 = reinterpret_cast(ctx[1]->state); + VARIANT1_INIT(0); + VARIANT1_INIT(1); + VARIANT2_INIT(0); + VARIANT2_INIT(1); + cn_explode_scratchpad((__m128i*) h0, (__m128i*) l0); cn_explode_scratchpad((__m128i*) h1, (__m128i*) l1); @@ -555,11 +572,13 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si uint64_t ah0 = h0[1] ^ h0[5]; uint64_t ah1 = h1[1] ^ h1[5]; - __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); - __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); + __m128i bx00 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); + __m128i bx01 = _mm_set_epi64x(h0[9] ^ h0[11], h0[8] ^ h0[10]); + __m128i bx10 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); + __m128i bx11 = _mm_set_epi64x(h1[9] ^ h1[11], h1[8] ^ h1[10]); - uint64_t idx0 = h0[0] ^ h0[4]; - uint64_t idx1 = h1[0] ^ h1[4]; + uint64_t idx0 = al0; + uint64_t idx1 = al1; for (size_t i = 0; i < ITERATIONS; i++) { __m128i cx0, cx1; @@ -568,52 +587,53 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si cx1 = _mm_load_si128((__m128i *) &l1[idx1 & MASK]); } + const __m128i ax0 = _mm_set_epi64x(ah0, al0); + const __m128i ax1 = _mm_set_epi64x(ah1, al1); if (VARIANT == xmrig::VARIANT_TUBE) { - cx0 = aes_round_tweak_div(cx0, _mm_set_epi64x(ah0, al0)); - cx1 = aes_round_tweak_div(cx1, _mm_set_epi64x(ah1, al1)); + cx0 = aes_round_tweak_div(cx0, ax0); + cx1 = aes_round_tweak_div(cx1, ax1); } else if (SOFT_AES) { - cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); - cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], _mm_set_epi64x(ah1, al1)); + cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], ax0); + cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], ax1); } else { - cx0 = _mm_aesenc_si128(cx0, _mm_set_epi64x(ah0, al0)); - cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); + cx0 = _mm_aesenc_si128(cx0, ax0); + cx1 = _mm_aesenc_si128(cx1, ax1); } - if (IS_MONERO) { - cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); - cryptonight_monero_tweak((uint64_t*)&l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + if (IS_V1 || (VARIANT == xmrig::VARIANT_2)) { + cryptonight_monero_tweak(l0, idx0 & MASK, ax0, bx00, bx01, cx0); + cryptonight_monero_tweak(l1, idx1 & MASK, ax1, bx10, bx11, cx1); } else { - _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); - _mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); - }; + _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx00, cx0)); + _mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx10, cx1)); + } idx0 = EXTRACT64(cx0); idx1 = EXTRACT64(cx1); - bx0 = cx0; - bx1 = cx1; - uint64_t hi, lo, cl, ch; cl = ((uint64_t*) &l0[idx0 & MASK])[0]; ch = ((uint64_t*) &l0[idx0 & MASK])[1]; - lo = __umul128(idx0, cl, &hi); + if (VARIANT == xmrig::VARIANT_2) { + VARIANT2_INTEGER_MATH(0, cl, cx0); + lo = __umul128(idx0, cl, &hi); + VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx00, bx01); + } else { + lo = __umul128(idx0, cl, &hi); + } al0 += hi; ah0 += lo; ((uint64_t*)&l0[idx0 & MASK])[0] = al0; - if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO) { - ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; - } - else { - ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0; - } - } - else { + if (IS_V1 && (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO)) { + ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; + } else if (IS_V1) { + ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0; + } else { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0; } @@ -639,22 +659,24 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si cl = ((uint64_t*) &l1[idx1 & MASK])[0]; ch = ((uint64_t*) &l1[idx1 & MASK])[1]; - lo = __umul128(idx1, cl, &hi); + if (VARIANT == xmrig::VARIANT_2) { + VARIANT2_INTEGER_MATH(1, cl, cx1); + lo = __umul128(idx1, cl, &hi); + VARIANT2_SHUFFLE(l1, idx1 & MASK, ax1, bx10, bx11); + } else { + lo = __umul128(idx1, cl, &hi); + } al1 += hi; ah1 += lo; ((uint64_t*)&l1[idx1 & MASK])[0] = al1; - if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO) { - ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; - } - else { - ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1; - } - } - else { + if (IS_V1 && (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO)) { + ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; + } else if (IS_V1) { + ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1; + } else { ((uint64_t*)&l1[idx1 & MASK])[1] = ah1; } @@ -677,6 +699,10 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si idx1 = d ^ q; } } + bx01 = bx00; + bx00 = cx0; + bx11 = bx10; + bx10 = cx1; } cn_implode_scratchpad((__m128i*) l0, (__m128i*) h0); diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 08a755d405..97a77bbdb5 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -107,6 +107,7 @@ inline uint32_t cn_select_mask(Algo algorithm) template inline constexpr uint32_t cn_select_iter() { return 0; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_MSR_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_XAO_ITER; } @@ -150,29 +151,16 @@ inline uint32_t cn_select_iter(Algo algorithm, Variant variant) } -template inline constexpr bool cn_is_monero() { return false; } -template<> inline constexpr bool cn_is_monero() { return false; } -template<> inline constexpr bool cn_is_monero() { return true; } -template<> inline constexpr bool cn_is_monero() { return true; } -template<> inline constexpr bool cn_is_monero() { return true; } -template<> inline constexpr bool cn_is_monero() { return true; } -template<> inline constexpr bool cn_is_monero() { return false; } -template<> inline constexpr bool cn_is_monero() { return false; } -template<> inline constexpr bool cn_is_monero() { return true; } - - -inline bool cn_is_monero(Variant variant) -{ - switch (variant) { - case VARIANT_0: - case VARIANT_XHV: - case VARIANT_RTO: - return false; - - default: - return true; - } -} +template inline constexpr bool cn_uses_variant1() { return false; } +template<> inline constexpr bool cn_uses_variant1() { return false; } +template<> inline constexpr bool cn_uses_variant1() { return true; } +template<> inline constexpr bool cn_uses_variant1() { return true; } +template<> inline constexpr bool cn_uses_variant1() { return true; } +template<> inline constexpr bool cn_uses_variant1() { return true; } +template<> inline constexpr bool cn_uses_variant1() { return false; } +template<> inline constexpr bool cn_uses_variant1() { return false; } +template<> inline constexpr bool cn_uses_variant1() { return true; } +template<> inline constexpr bool cn_uses_variant1() { return false; } } /* namespace xmrig */ diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index a758fdbc5c..3fb18d00f7 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -25,26 +25,27 @@ #ifndef __CRYPTONIGHT_MONERO_H__ #define __CRYPTONIGHT_MONERO_H__ +#include // VARIANT ALTERATIONS #ifndef XMRIG_ARM # define VARIANT1_INIT(part) \ uint64_t tweak1_2_##part = 0; \ - if (IS_MONERO) { \ + if (IS_V1) { \ tweak1_2_##part = (*reinterpret_cast(input + 35 + part * size) ^ \ *(reinterpret_cast(ctx[part]->state) + 24)); \ } #else # define VARIANT1_INIT(part) \ uint64_t tweak1_2_##part = 0; \ - if (IS_MONERO) { \ + if (IS_V1) { \ memcpy(&tweak1_2_##part, input + 35 + part * size, sizeof tweak1_2_##part); \ tweak1_2_##part ^= *(reinterpret_cast(ctx[part]->state) + 24); \ } #endif #define VARIANT1_1(p) \ - if (IS_MONERO) { \ + if (IS_V1) { \ const uint8_t tmp = reinterpret_cast(p)[11]; \ static const uint32_t table = 0x75310; \ const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \ @@ -52,9 +53,72 @@ } #define VARIANT1_2(p, part) \ - if (IS_MONERO) { \ + if (IS_V1) { \ (p) ^= tweak1_2_##part; \ } +#ifndef XMRIG_ARM +# define VARIANT2_INIT(part) \ + __m128i division_result_xmm_##part = _mm_cvtsi64_si128(h##part[12]); \ + __m128i sqrt_result_xmm_##part = _mm_cvtsi64_si128(h##part[13]); + +#ifdef _MSC_VER +# define VARIANT2_SET_ROUNDING_MODE() if (VARIANT == xmrig::VARIANT_2) { _control87(RC_DOWN, MCW_RC); } +#else +# define VARIANT2_SET_ROUNDING_MODE() if (VARIANT == xmrig::VARIANT_2) { std::fesetround(FE_DOWNWARD); } +#endif + +# define VARIANT2_INTEGER_MATH(part, cl, cx) \ + do { \ + const uint64_t sqrt_result = static_cast(_mm_cvtsi128_si64(sqrt_result_xmm_##part)); \ + const uint64_t cx_0 = _mm_cvtsi128_si64(cx); \ + cl ^= static_cast(_mm_cvtsi128_si64(division_result_xmm_##part)) ^ (sqrt_result << 32); \ + const uint32_t d = static_cast(cx_0 + (sqrt_result << 1)) | 0x80000001UL; \ + const uint64_t cx_1 = _mm_cvtsi128_si64(_mm_srli_si128(cx, 8)); \ + const uint64_t division_result = static_cast(cx_1 / d) + ((cx_1 % d) << 32); \ + division_result_xmm_##part = _mm_cvtsi64_si128(static_cast(division_result)); \ + sqrt_result_xmm_##part = int_sqrt_v2(cx_0 + division_result); \ + } while (0) + +# define VARIANT2_SHUFFLE(base_ptr, offset, _a, _b, _b1) \ + do { \ + const __m128i chunk1 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10))); \ + const __m128i chunk2 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20))); \ + const __m128i chunk3 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x30))); \ + _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10)), _mm_add_epi64(chunk3, _b1)); \ + _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20)), _mm_add_epi64(chunk1, _b)); \ + _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x30)), _mm_add_epi64(chunk2, _a)); \ + } while (0) + +#else +# define VARIANT2_INIT(part) \ + uint64_t division_result_##part = h##part[12]; \ + uint64_t sqrt_result_##part = h##part[13]; + +# define VARIANT2_INTEGER_MATH(part, cl, cx) \ + do { \ + const uint64_t cx_0 = _mm_cvtsi128_si64(cx); \ + cl ^= division_result_##part ^ (sqrt_result_##part << 32); \ + const uint32_t d = static_cast(cx_0 + (sqrt_result_##part << 1)) | 0x80000001UL; \ + const uint64_t cx_1 = _mm_cvtsi128_si64(_mm_srli_si128(cx, 8)); \ + division_result_##part = static_cast(cx_1 / d) + ((cx_1 % d) << 32); \ + const uint64_t sqrt_input = cx_0 + division_result_##part; \ + sqrt_result_##part = sqrt(sqrt_input + 18446744073709551616.0) * 2.0 - 8589934592.0; \ + const uint64_t s = sqrt_result_##part >> 1; \ + const uint64_t b = sqrt_result_##part & 1; \ + const uint64_t r2 = (uint64_t)(s) * (s + b) + (sqrt_result_##part << 32); \ + sqrt_result_##part += ((r2 + b > sqrt_input) ? -1 : 0) + ((r2 + (1ULL << 32) < sqrt_input - s) ? 1 : 0); \ + } while (0) + +# define VARIANT2_SHUFFLE(base_ptr, offset, _a, _b, _b1) \ + do { \ + const uint64x2_t chunk1 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x10))); \ + const uint64x2_t chunk2 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20))); \ + const uint64x2_t chunk3 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x30))); \ + vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x10)), vaddq_u64(chunk3, vreinterpretq_u64_u8(_b1))); \ + vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20)), vaddq_u64(chunk1, vreinterpretq_u64_u8(_b))); \ + vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x30)), vaddq_u64(chunk2, vreinterpretq_u64_u8(_a))); \ + } while (0) +#endif #endif /* __CRYPTONIGHT_MONERO_H__ */ diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index 16296efbfc..953f88d0e9 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -69,7 +69,7 @@ const static uint8_t test_output_v0[160] = { }; -// Monero v7 +// Cryptonight variant 1 (Monero v7) const static uint8_t test_output_v1[160] = { 0xF2, 0x2D, 0x3D, 0x62, 0x03, 0xD2, 0xA0, 0x8B, 0x41, 0xD9, 0x02, 0x72, 0x78, 0xD8, 0xBC, 0xC9, 0x83, 0xAC, 0xAD, 0xA9, 0xB6, 0x8E, 0x52, 0xE3, 0xC6, 0x89, 0x69, 0x2A, 0x50, 0xE9, 0x21, 0xD9, @@ -84,6 +84,21 @@ const static uint8_t test_output_v1[160] = { }; +// Cryptonight variant 2 (Monero v8) +const static uint8_t test_output_v2[160] = { + 0x6E, 0xEE, 0x53, 0xA3, 0xDA, 0xD1, 0x8C, 0x05, 0xB8, 0xCB, 0x32, 0x17, 0xAA, 0xEA, 0xEA, 0xB4, + 0x16, 0x11, 0x01, 0xA9, 0x08, 0x76, 0x37, 0x36, 0x6F, 0xDC, 0xCA, 0xC6, 0x92, 0x0D, 0xEA, 0x09, + 0x91, 0x03, 0x2F, 0x5B, 0x27, 0x4D, 0x94, 0x1D, 0x60, 0x50, 0xDC, 0x1F, 0x35, 0x57, 0xEC, 0x20, + 0xA6, 0xAC, 0x10, 0xDB, 0xCF, 0x36, 0x23, 0x8F, 0x96, 0xC7, 0x72, 0x8B, 0xF9, 0xE7, 0x30, 0xEB, + 0x50, 0x58, 0x4B, 0xFE, 0xAD, 0xC5, 0x13, 0x79, 0x50, 0x98, 0x1C, 0x67, 0xB2, 0xEB, 0xDA, 0x64, + 0xD4, 0xAA, 0xC4, 0xE8, 0xE5, 0xC9, 0xE7, 0x6B, 0x84, 0xC2, 0xD2, 0xE9, 0x1F, 0xA1, 0x0F, 0xDF, + 0x45, 0x06, 0x80, 0x25, 0x32, 0x6B, 0xC4, 0x66, 0x2A, 0x69, 0x9F, 0x1E, 0x1F, 0x4C, 0xBE, 0x89, + 0xFE, 0x61, 0xBB, 0x04, 0x79, 0xB5, 0x3B, 0x45, 0x58, 0xD9, 0x9C, 0x18, 0x7C, 0x48, 0x1B, 0x44, + 0x92, 0xC4, 0x4C, 0xD0, 0x8F, 0x16, 0x44, 0x79, 0x71, 0x48, 0x63, 0x0B, 0x51, 0xB6, 0x33, 0x8B, + 0x6B, 0x3F, 0xCC, 0x0A, 0x3A, 0x14, 0x3B, 0x49, 0x68, 0x46, 0xB9, 0x46, 0xC6, 0xA3, 0x03, 0x41 +}; + + // Stellite (XTL) const static uint8_t test_output_xtl[160] = { 0x8F, 0xE5, 0xF0, 0x5F, 0x02, 0x2A, 0x61, 0x7D, 0xE5, 0x3F, 0x79, 0x36, 0x4B, 0x25, 0xCB, 0xC3, diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 199c190bbc..e234d41d07 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -408,20 +408,46 @@ static inline __m128i aes_round_tweak_div(const __m128i &in, const __m128i &key) } -template -static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp) +static inline __m128i int_sqrt_v2(const uint64_t n0) { - mem_out[0] = EXTRACT64(tmp); + __m128d x = _mm_castsi128_pd(_mm_add_epi64(_mm_cvtsi64_si128(n0 >> 12), _mm_set_epi64x(0, 1023ULL << 52))); + x = _mm_sqrt_sd(_mm_setzero_pd(), x); + uint64_t r = static_cast(_mm_cvtsi128_si64(_mm_castpd_si128(x))); - tmp = _mm_castps_si128(_mm_movehl_ps(_mm_castsi128_ps(tmp), _mm_castsi128_ps(tmp))); - uint64_t vh = EXTRACT64(tmp); + const uint64_t s = r >> 20; + r >>= 19; - uint8_t x = vh >> 24; - static const uint16_t table = 0x7531; - const uint8_t index = (((x >> SHIFT) & 6) | (x & 1)) << 1; - vh ^= ((table >> index) & 0x3) << 28; + uint64_t x2 = (s - (1022ULL << 32)) * (r - s - (1022ULL << 32) + 1); +#if defined _MSC_VER || (__GNUC__ >= 7) + _addcarry_u64(_subborrow_u64(0, x2, n0, (unsigned long long int*)&x2), r, 0, (unsigned long long int*)&r); +#else + if (x2 < n0) ++r; +#endif - mem_out[1] = vh; + return _mm_cvtsi64_si128(r); +} + + +template +static inline void cryptonight_monero_tweak(uint64_t* mem_out, const uint8_t* l, uint64_t idx, __m128i ax0, __m128i bx0, __m128i bx1, __m128i cx) +{ + if (VARIANT == xmrig::VARIANT_2) { + VARIANT2_SHUFFLE(l, idx, ax0, bx0, bx1); + _mm_store_si128((__m128i *)mem_out, _mm_xor_si128(bx0, cx)); + } else { + __m128i tmp = _mm_xor_si128(bx0, cx); + mem_out[0] = EXTRACT64(tmp); + + tmp = _mm_castps_si128(_mm_movehl_ps(_mm_castsi128_ps(tmp), _mm_castsi128_ps(tmp))); + uint64_t vh = EXTRACT64(tmp); + + uint8_t x = static_cast(vh >> 24); + static const uint16_t table = 0x7531; + const uint8_t index = (((x >> (VARIANT == xmrig::VARIANT_XTL ? 4 : 3)) & 6) | (x & 1)) << 1; + vh ^= ((table >> index) & 0x3) << 28; + + mem_out[1] = vh; + } } @@ -431,92 +457,104 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_MONERO = xmrig::cn_is_monero(); + constexpr bool IS_V1 = xmrig::cn_uses_variant1(); - if (IS_MONERO && size < 43) { + if (IS_V1 && size < 43) { memset(output, 0, 32); return; } xmrig::keccak(input, size, ctx[0]->state); - VARIANT1_INIT(0) - cn_explode_scratchpad((__m128i*) ctx[0]->state, (__m128i*) ctx[0]->memory); const uint8_t* l0 = ctx[0]->memory; uint64_t* h0 = reinterpret_cast(ctx[0]->state); + VARIANT1_INIT(0); + VARIANT2_INIT(0); + VARIANT2_SET_ROUNDING_MODE(); + uint64_t al0 = h0[0] ^ h0[4]; uint64_t ah0 = h0[1] ^ h0[5]; __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); + __m128i bx1 = _mm_set_epi64x(h0[9] ^ h0[11], h0[8] ^ h0[10]); uint64_t idx0 = al0; + uint64_t* ptr0 = (uint64_t*) &l0[idx0 & MASK]; for (size_t i = 0; i < ITERATIONS; i++) { __m128i cx; if (VARIANT == xmrig::VARIANT_TUBE || !SOFT_AES) { - cx = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); + cx = _mm_load_si128((__m128i *) ptr0); } + const __m128i ax0 = _mm_set_epi64x(ah0, al0); if (VARIANT == xmrig::VARIANT_TUBE) { - cx = aes_round_tweak_div(cx, _mm_set_epi64x(ah0, al0)); + cx = aes_round_tweak_div(cx, ax0); } else if (SOFT_AES) { - cx = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); + cx = soft_aesenc((uint32_t*) ptr0, ax0); } else { - cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); + cx = _mm_aesenc_si128(cx, ax0); } - if (IS_MONERO) { - cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); + if (IS_V1 || VARIANT == xmrig::VARIANT_2) { + cryptonight_monero_tweak(ptr0, l0, idx0 & MASK, ax0, bx0, bx1, cx); } else { - _mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); + _mm_store_si128((__m128i *) ptr0, _mm_xor_si128(bx0, cx)); } idx0 = EXTRACT64(cx); - bx0 = cx; + ptr0 = (uint64_t*) &l0[idx0 & MASK]; uint64_t hi, lo, cl, ch; - cl = ((uint64_t*) &l0[idx0 & MASK])[0]; - ch = ((uint64_t*) &l0[idx0 & MASK])[1]; - lo = __umul128(idx0, cl, &hi); + cl = ptr0[0]; + ch = ptr0[1]; + if (VARIANT == xmrig::VARIANT_2) { + VARIANT2_INTEGER_MATH(0, cl, cx); + lo = __umul128(idx0, cl, &hi); + VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx0, bx1); + } + else { + lo = __umul128(idx0, cl, &hi); + } al0 += hi; ah0 += lo; - ((uint64_t*)&l0[idx0 & MASK])[0] = al0; + ptr0[0] = al0; - if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO) { - ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; - } - else { - ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0; - } - } - else { - ((uint64_t*)&l0[idx0 & MASK])[1] = ah0; + if (IS_V1 && (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO)) { + ptr0[1] = ah0 ^ tweak1_2_0 ^ al0; + } else if (IS_V1) { + ptr0[1] = ah0 ^ tweak1_2_0; + } else { + ptr0[1] = ah0; } al0 ^= cl; ah0 ^= ch; idx0 = al0; + ptr0 = (uint64_t*) &l0[idx0 & MASK]; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; - int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; + int64_t n = ((int64_t*)ptr0)[0]; + int32_t d = ((int32_t*)ptr0)[2]; int64_t q = n / (d | 0x5); - ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; + ((int64_t*) ptr0)[0] = n ^ q; if (VARIANT == xmrig::VARIANT_XHV) { d = ~d; } idx0 = d ^ q; + ptr0 = (uint64_t*)&l0[idx0 & MASK]; } + bx1 = bx0; + bx0 = cx; } cn_implode_scratchpad((__m128i*) ctx[0]->memory, (__m128i*) ctx[0]->state); @@ -532,9 +570,9 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_MONERO = xmrig::cn_is_monero(); + constexpr bool IS_V1 = xmrig::cn_uses_variant1(); - if (IS_MONERO && size < 43) { + if (IS_V1 && size < 43) { memset(output, 0, 64); return; } @@ -542,14 +580,17 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si xmrig::keccak(input, size, ctx[0]->state); xmrig::keccak(input + size, size, ctx[1]->state); - VARIANT1_INIT(0); - VARIANT1_INIT(1); - const uint8_t* l0 = ctx[0]->memory; const uint8_t* l1 = ctx[1]->memory; uint64_t* h0 = reinterpret_cast(ctx[0]->state); uint64_t* h1 = reinterpret_cast(ctx[1]->state); + VARIANT1_INIT(0); + VARIANT1_INIT(1); + VARIANT2_INIT(0); + VARIANT2_INIT(1); + VARIANT2_SET_ROUNDING_MODE(); + cn_explode_scratchpad((__m128i*) h0, (__m128i*) l0); cn_explode_scratchpad((__m128i*) h1, (__m128i*) l1); @@ -558,124 +599,142 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si uint64_t ah0 = h0[1] ^ h0[5]; uint64_t ah1 = h1[1] ^ h1[5]; - __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); - __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); + __m128i bx00 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); + __m128i bx01 = _mm_set_epi64x(h0[9] ^ h0[11], h0[8] ^ h0[10]); + __m128i bx10 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); + __m128i bx11 = _mm_set_epi64x(h1[9] ^ h1[11], h1[8] ^ h1[10]); uint64_t idx0 = al0; uint64_t idx1 = al1; + uint64_t* ptr0 = (uint64_t*)&l0[idx0 & MASK]; + uint64_t* ptr1 = (uint64_t*)&l1[idx1 & MASK]; for (size_t i = 0; i < ITERATIONS; i++) { __m128i cx0, cx1; if (VARIANT == xmrig::VARIANT_TUBE || !SOFT_AES) { - cx0 = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); - cx1 = _mm_load_si128((__m128i *) &l1[idx1 & MASK]); + cx0 = _mm_load_si128((__m128i *) ptr0); + cx1 = _mm_load_si128((__m128i *) ptr1); } + const __m128i ax0 = _mm_set_epi64x(ah0, al0); + const __m128i ax1 = _mm_set_epi64x(ah1, al1); if (VARIANT == xmrig::VARIANT_TUBE) { - cx0 = aes_round_tweak_div(cx0, _mm_set_epi64x(ah0, al0)); - cx1 = aes_round_tweak_div(cx1, _mm_set_epi64x(ah1, al1)); + cx0 = aes_round_tweak_div(cx0, ax0); + cx1 = aes_round_tweak_div(cx1, ax1); } else if (SOFT_AES) { - cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); - cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], _mm_set_epi64x(ah1, al1)); + cx0 = soft_aesenc((uint32_t*)ptr0, ax0); + cx1 = soft_aesenc((uint32_t*)ptr1, ax1); } else { - cx0 = _mm_aesenc_si128(cx0, _mm_set_epi64x(ah0, al0)); - cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); + cx0 = _mm_aesenc_si128(cx0, ax0); + cx1 = _mm_aesenc_si128(cx1, ax1); } - if (IS_MONERO) { - cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); - cryptonight_monero_tweak((uint64_t*)&l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + if (IS_V1 || (VARIANT == xmrig::VARIANT_2)) { + cryptonight_monero_tweak(ptr0, l0, idx0 & MASK, ax0, bx00, bx01, cx0); + cryptonight_monero_tweak(ptr1, l1, idx1 & MASK, ax1, bx10, bx11, cx1); } else { - _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); - _mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + _mm_store_si128((__m128i *) ptr0, _mm_xor_si128(bx00, cx0)); + _mm_store_si128((__m128i *) ptr1, _mm_xor_si128(bx10, cx1)); } idx0 = EXTRACT64(cx0); idx1 = EXTRACT64(cx1); - - bx0 = cx0; - bx1 = cx1; + ptr0 = (uint64_t*)&l0[idx0 & MASK]; + ptr1 = (uint64_t*)&l1[idx1 & MASK]; uint64_t hi, lo, cl, ch; - cl = ((uint64_t*) &l0[idx0 & MASK])[0]; - ch = ((uint64_t*) &l0[idx0 & MASK])[1]; - lo = __umul128(idx0, cl, &hi); + cl = ((uint64_t*)ptr0)[0]; + ch = ((uint64_t*)ptr0)[1]; + if (VARIANT == xmrig::VARIANT_2) { + VARIANT2_INTEGER_MATH(0, cl, cx0); + lo = __umul128(idx0, cl, &hi); + VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx00, bx01); + } else { + lo = __umul128(idx0, cl, &hi); + } al0 += hi; ah0 += lo; - ((uint64_t*)&l0[idx0 & MASK])[0] = al0; + ((uint64_t*)ptr0)[0] = al0; - if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO) { - ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; - } - else { - ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0; - } - } - else { - ((uint64_t*)&l0[idx0 & MASK])[1] = ah0; + if (IS_V1 && (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO)) { + ((uint64_t*)ptr0)[1] = ah0 ^ tweak1_2_0 ^ al0; + } else if (IS_V1) { + ((uint64_t*)ptr0)[1] = ah0 ^ tweak1_2_0; + } else { + ((uint64_t*)ptr0)[1] = ah0; } al0 ^= cl; ah0 ^= ch; idx0 = al0; + ptr0 = (uint64_t*)&l0[idx0 & MASK]; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; - int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; + int64_t n = ((int64_t*)ptr0)[0]; + int32_t d = ((int32_t*)ptr0)[2]; int64_t q = n / (d | 0x5); - ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; + ((int64_t*)ptr0)[0] = n ^ q; if (VARIANT == xmrig::VARIANT_XHV) { d = ~d; } idx0 = d ^ q; + ptr0 = (uint64_t*)&l0[idx0 & MASK]; } - cl = ((uint64_t*) &l1[idx1 & MASK])[0]; - ch = ((uint64_t*) &l1[idx1 & MASK])[1]; - lo = __umul128(idx1, cl, &hi); + cl = ptr1[0]; + ch = ptr1[1]; + if (VARIANT == xmrig::VARIANT_2) { + VARIANT2_INTEGER_MATH(1, cl, cx1); + lo = __umul128(idx1, cl, &hi); + VARIANT2_SHUFFLE(l1, idx1 & MASK, ax1, bx10, bx11); + } else { + lo = __umul128(idx1, cl, &hi); + } al1 += hi; ah1 += lo; - ((uint64_t*)&l1[idx1 & MASK])[0] = al1; + ptr1[0] = al1; - if (IS_MONERO) { - if (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO) { - ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; - } - else { - ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1; - } - } - else { - ((uint64_t*)&l1[idx1 & MASK])[1] = ah1; + if (IS_V1 && (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO)) { + ptr1[1] = ah1 ^ tweak1_2_1 ^ al1; + } else if (IS_V1) { + ptr1[1] = ah1 ^ tweak1_2_1; + } else { + ptr1[1] = ah1; } al1 ^= cl; ah1 ^= ch; idx1 = al1; + ptr1 = (uint64_t*)&l1[idx1 & MASK]; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)&l1[idx1 & MASK])[0]; - int32_t d = ((int32_t*)&l1[idx1 & MASK])[2]; + int64_t n = ((int64_t*)ptr1)[0]; + int32_t d = ((int32_t*)ptr1)[2]; int64_t q = n / (d | 0x5); - ((int64_t*)&l1[idx1 & MASK])[0] = n ^ q; + ((int64_t*)ptr1)[0] = n ^ q; if (VARIANT == xmrig::VARIANT_XHV) { d = ~d; } idx1 = d ^ q; + ptr1 = (uint64_t*)&l1[idx1 & MASK]; } + + bx01 = bx00; + bx00 = cx0; + bx11 = bx10; + bx10 = cx1; } cn_implode_scratchpad((__m128i*) l0, (__m128i*) h0); @@ -689,12 +748,12 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si } -#define CN_STEP1(a, b, c, l, ptr, idx) \ +#define CN_STEP1(a, b0, b1, c, l, ptr, idx) \ ptr = reinterpret_cast<__m128i*>(&l[idx & MASK]); \ c = _mm_load_si128(ptr); -#define CN_STEP2(a, b, c, l, ptr, idx) \ +#define CN_STEP2(a, b0, b1, c, l, ptr, idx) \ if (VARIANT == xmrig::VARIANT_TUBE) { \ c = aes_round_tweak_div(c, a); \ } \ @@ -704,26 +763,31 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si c = _mm_aesenc_si128(c, a); \ } \ \ - b = _mm_xor_si128(b, c); \ - \ - if (IS_MONERO) { \ - cryptonight_monero_tweak(reinterpret_cast(ptr), b); \ + if (IS_V1 || (VARIANT == xmrig::VARIANT_2)) { \ + cryptonight_monero_tweak((uint64_t*)ptr, l, idx & MASK, a, b0, b1, c); \ } else { \ - _mm_store_si128(ptr, b); \ + _mm_store_si128(ptr, _mm_xor_si128(b0, c)); \ } -#define CN_STEP3(a, b, c, l, ptr, idx) \ +#define CN_STEP3(part, a, b0, b1, c, l, ptr, idx) \ idx = EXTRACT64(c); \ ptr = reinterpret_cast<__m128i*>(&l[idx & MASK]); \ - b = _mm_load_si128(ptr); + uint64_t cl##part = ((uint64_t*)ptr)[0]; \ + uint64_t ch##part = ((uint64_t*)ptr)[1]; -#define CN_STEP4(a, b, c, l, mc, ptr, idx) \ - lo = __umul128(idx, EXTRACT64(b), &hi); \ +#define CN_STEP4(part, a, b0, b1, c, l, mc, ptr, idx) \ + if (VARIANT == xmrig::VARIANT_2) { \ + VARIANT2_INTEGER_MATH(part, cl##part, c); \ + lo = __umul128(idx, cl##part, &hi); \ + VARIANT2_SHUFFLE(l, idx & MASK, a, b0, b1); \ + } else { \ + lo = __umul128(idx, cl##part, &hi); \ + } \ a = _mm_add_epi64(a, _mm_set_epi64x(lo, hi)); \ \ - if (IS_MONERO) { \ + if (IS_V1) { \ _mm_store_si128(ptr, _mm_xor_si128(a, mc)); \ \ if (VARIANT == xmrig::VARIANT_TUBE || \ @@ -734,7 +798,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si _mm_store_si128(ptr, a); \ } \ \ - a = _mm_xor_si128(a, b); \ + a = _mm_xor_si128(a, _mm_set_epi64x(ch##part, cl##part)); \ idx = EXTRACT64(a); \ \ if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { \ @@ -747,15 +811,27 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si } \ \ idx = d ^ q; \ - } + } \ + b1 = b0; \ + b0 = c; #define CONST_INIT(ctx, n) \ __m128i mc##n; \ - if (IS_MONERO) { \ + __m128i division_result_xmm_##n; \ + __m128i sqrt_result_xmm_##n; \ + if (IS_V1) { \ mc##n = _mm_set_epi64x(*reinterpret_cast(input + n * size + 35) ^ \ *(reinterpret_cast((ctx)->state) + 24), 0); \ - } + } \ + if (VARIANT == xmrig::VARIANT_2) { \ + division_result_xmm_##n = _mm_cvtsi64_si128(h##n[12]); \ + sqrt_result_xmm_##n = _mm_cvtsi64_si128(h##n[13]); \ + } \ + __m128i ax##n = _mm_set_epi64x(h##n[1] ^ h##n[5], h##n[0] ^ h##n[4]); \ + __m128i bx##n##0 = _mm_set_epi64x(h##n[3] ^ h##n[7], h##n[2] ^ h##n[6]); \ + __m128i bx##n##1 = _mm_set_epi64x(h##n[9] ^ h##n[11], h##n[8] ^ h##n[10]); \ + __m128i cx##n = _mm_setzero_si128(); template @@ -764,9 +840,9 @@ inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_MONERO = xmrig::cn_is_monero(); + constexpr bool IS_V1 = xmrig::cn_uses_variant1(); - if (IS_MONERO && size < 43) { + if (IS_V1 && size < 43) { memset(output, 0, 32 * 3); return; } @@ -776,10 +852,6 @@ inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t si cn_explode_scratchpad(reinterpret_cast<__m128i*>(ctx[i]->state), reinterpret_cast<__m128i*>(ctx[i]->memory)); } - CONST_INIT(ctx[0], 0); - CONST_INIT(ctx[1], 1); - CONST_INIT(ctx[2], 2); - uint8_t* l0 = ctx[0]->memory; uint8_t* l1 = ctx[1]->memory; uint8_t* l2 = ctx[2]->memory; @@ -787,58 +859,35 @@ inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t si uint64_t* h1 = reinterpret_cast(ctx[1]->state); uint64_t* h2 = reinterpret_cast(ctx[2]->state); - __m128i ax0 = _mm_set_epi64x(h0[1] ^ h0[5], h0[0] ^ h0[4]); - __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); - __m128i ax1 = _mm_set_epi64x(h1[1] ^ h1[5], h1[0] ^ h1[4]); - __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); - __m128i ax2 = _mm_set_epi64x(h2[1] ^ h2[5], h2[0] ^ h2[4]); - __m128i bx2 = _mm_set_epi64x(h2[3] ^ h2[7], h2[2] ^ h2[6]); - __m128i cx0 = _mm_set_epi64x(0, 0); - __m128i cx1 = _mm_set_epi64x(0, 0); - __m128i cx2 = _mm_set_epi64x(0, 0); + CONST_INIT(ctx[0], 0); + CONST_INIT(ctx[1], 1); + CONST_INIT(ctx[2], 2); + VARIANT2_SET_ROUNDING_MODE(); uint64_t idx0, idx1, idx2; idx0 = EXTRACT64(ax0); idx1 = EXTRACT64(ax1); idx2 = EXTRACT64(ax2); - for (size_t i = 0; i < ITERATIONS / 2; i++) { + for (size_t i = 0; i < ITERATIONS; i++) { uint64_t hi, lo; __m128i *ptr0, *ptr1, *ptr2; - // EVEN ROUND - CN_STEP1(ax0, bx0, cx0, l0, ptr0, idx0); - CN_STEP1(ax1, bx1, cx1, l1, ptr1, idx1); - CN_STEP1(ax2, bx2, cx2, l2, ptr2, idx2); + CN_STEP1(ax0, bx00, bx01, cx0, l0, ptr0, idx0); + CN_STEP1(ax1, bx10, bx11, cx1, l1, ptr1, idx1); + CN_STEP1(ax2, bx20, bx21, cx2, l2, ptr2, idx2); - CN_STEP2(ax0, bx0, cx0, l0, ptr0, idx0); - CN_STEP2(ax1, bx1, cx1, l1, ptr1, idx1); - CN_STEP2(ax2, bx2, cx2, l2, ptr2, idx2); + CN_STEP2(ax0, bx00, bx01, cx0, l0, ptr0, idx0); + CN_STEP2(ax1, bx10, bx11, cx1, l1, ptr1, idx1); + CN_STEP2(ax2, bx20, bx21, cx2, l2, ptr2, idx2); - CN_STEP3(ax0, bx0, cx0, l0, ptr0, idx0); - CN_STEP3(ax1, bx1, cx1, l1, ptr1, idx1); - CN_STEP3(ax2, bx2, cx2, l2, ptr2, idx2); + CN_STEP3(0, ax0, bx00, bx01, cx0, l0, ptr0, idx0); + CN_STEP3(1, ax1, bx10, bx11, cx1, l1, ptr1, idx1); + CN_STEP3(2, ax2, bx20, bx21, cx2, l2, ptr2, idx2); - CN_STEP4(ax0, bx0, cx0, l0, mc0, ptr0, idx0); - CN_STEP4(ax1, bx1, cx1, l1, mc1, ptr1, idx1); - CN_STEP4(ax2, bx2, cx2, l2, mc2, ptr2, idx2); - - // ODD ROUND - CN_STEP1(ax0, cx0, bx0, l0, ptr0, idx0); - CN_STEP1(ax1, cx1, bx1, l1, ptr1, idx1); - CN_STEP1(ax2, cx2, bx2, l2, ptr2, idx2); - - CN_STEP2(ax0, cx0, bx0, l0, ptr0, idx0); - CN_STEP2(ax1, cx1, bx1, l1, ptr1, idx1); - CN_STEP2(ax2, cx2, bx2, l2, ptr2, idx2); - - CN_STEP3(ax0, cx0, bx0, l0, ptr0, idx0); - CN_STEP3(ax1, cx1, bx1, l1, ptr1, idx1); - CN_STEP3(ax2, cx2, bx2, l2, ptr2, idx2); - - CN_STEP4(ax0, cx0, bx0, l0, mc0, ptr0, idx0); - CN_STEP4(ax1, cx1, bx1, l1, mc1, ptr1, idx1); - CN_STEP4(ax2, cx2, bx2, l2, mc2, ptr2, idx2); + CN_STEP4(0, ax0, bx00, bx01, cx0, l0, mc0, ptr0, idx0); + CN_STEP4(1, ax1, bx10, bx11, cx1, l1, mc1, ptr1, idx1); + CN_STEP4(2, ax2, bx20, bx21, cx2, l2, mc2, ptr2, idx2); } for (size_t i = 0; i < 3; i++) { @@ -855,9 +904,9 @@ inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_MONERO = xmrig::cn_is_monero(); + constexpr bool IS_V1 = xmrig::cn_uses_variant1(); - if (IS_MONERO && size < 43) { + if (IS_V1 && size < 43) { memset(output, 0, 32 * 4); return; } @@ -867,11 +916,6 @@ inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size cn_explode_scratchpad(reinterpret_cast<__m128i*>(ctx[i]->state), reinterpret_cast<__m128i*>(ctx[i]->memory)); } - CONST_INIT(ctx[0], 0); - CONST_INIT(ctx[1], 1); - CONST_INIT(ctx[2], 2); - CONST_INIT(ctx[3], 3); - uint8_t* l0 = ctx[0]->memory; uint8_t* l1 = ctx[1]->memory; uint8_t* l2 = ctx[2]->memory; @@ -881,18 +925,11 @@ inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size uint64_t* h2 = reinterpret_cast(ctx[2]->state); uint64_t* h3 = reinterpret_cast(ctx[3]->state); - __m128i ax0 = _mm_set_epi64x(h0[1] ^ h0[5], h0[0] ^ h0[4]); - __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); - __m128i ax1 = _mm_set_epi64x(h1[1] ^ h1[5], h1[0] ^ h1[4]); - __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); - __m128i ax2 = _mm_set_epi64x(h2[1] ^ h2[5], h2[0] ^ h2[4]); - __m128i bx2 = _mm_set_epi64x(h2[3] ^ h2[7], h2[2] ^ h2[6]); - __m128i ax3 = _mm_set_epi64x(h3[1] ^ h3[5], h3[0] ^ h3[4]); - __m128i bx3 = _mm_set_epi64x(h3[3] ^ h3[7], h3[2] ^ h3[6]); - __m128i cx0 = _mm_set_epi64x(0, 0); - __m128i cx1 = _mm_set_epi64x(0, 0); - __m128i cx2 = _mm_set_epi64x(0, 0); - __m128i cx3 = _mm_set_epi64x(0, 0); + CONST_INIT(ctx[0], 0); + CONST_INIT(ctx[1], 1); + CONST_INIT(ctx[2], 2); + CONST_INIT(ctx[3], 3); + VARIANT2_SET_ROUNDING_MODE(); uint64_t idx0, idx1, idx2, idx3; idx0 = EXTRACT64(ax0); @@ -900,52 +937,30 @@ inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size idx2 = EXTRACT64(ax2); idx3 = EXTRACT64(ax3); - for (size_t i = 0; i < ITERATIONS / 2; i++) + for (size_t i = 0; i < ITERATIONS; i++) { uint64_t hi, lo; __m128i *ptr0, *ptr1, *ptr2, *ptr3; - // EVEN ROUND - CN_STEP1(ax0, bx0, cx0, l0, ptr0, idx0); - CN_STEP1(ax1, bx1, cx1, l1, ptr1, idx1); - CN_STEP1(ax2, bx2, cx2, l2, ptr2, idx2); - CN_STEP1(ax3, bx3, cx3, l3, ptr3, idx3); - - CN_STEP2(ax0, bx0, cx0, l0, ptr0, idx0); - CN_STEP2(ax1, bx1, cx1, l1, ptr1, idx1); - CN_STEP2(ax2, bx2, cx2, l2, ptr2, idx2); - CN_STEP2(ax3, bx3, cx3, l3, ptr3, idx3); - - CN_STEP3(ax0, bx0, cx0, l0, ptr0, idx0); - CN_STEP3(ax1, bx1, cx1, l1, ptr1, idx1); - CN_STEP3(ax2, bx2, cx2, l2, ptr2, idx2); - CN_STEP3(ax3, bx3, cx3, l3, ptr3, idx3); - - CN_STEP4(ax0, bx0, cx0, l0, mc0, ptr0, idx0); - CN_STEP4(ax1, bx1, cx1, l1, mc1, ptr1, idx1); - CN_STEP4(ax2, bx2, cx2, l2, mc2, ptr2, idx2); - CN_STEP4(ax3, bx3, cx3, l3, mc3, ptr3, idx3); - - // ODD ROUND - CN_STEP1(ax0, cx0, bx0, l0, ptr0, idx0); - CN_STEP1(ax1, cx1, bx1, l1, ptr1, idx1); - CN_STEP1(ax2, cx2, bx2, l2, ptr2, idx2); - CN_STEP1(ax3, cx3, bx3, l3, ptr3, idx3); - - CN_STEP2(ax0, cx0, bx0, l0, ptr0, idx0); - CN_STEP2(ax1, cx1, bx1, l1, ptr1, idx1); - CN_STEP2(ax2, cx2, bx2, l2, ptr2, idx2); - CN_STEP2(ax3, cx3, bx3, l3, ptr3, idx3); - - CN_STEP3(ax0, cx0, bx0, l0, ptr0, idx0); - CN_STEP3(ax1, cx1, bx1, l1, ptr1, idx1); - CN_STEP3(ax2, cx2, bx2, l2, ptr2, idx2); - CN_STEP3(ax3, cx3, bx3, l3, ptr3, idx3); - - CN_STEP4(ax0, cx0, bx0, l0, mc0, ptr0, idx0); - CN_STEP4(ax1, cx1, bx1, l1, mc1, ptr1, idx1); - CN_STEP4(ax2, cx2, bx2, l2, mc2, ptr2, idx2); - CN_STEP4(ax3, cx3, bx3, l3, mc3, ptr3, idx3); + CN_STEP1(ax0, bx00, bx01, cx0, l0, ptr0, idx0); + CN_STEP1(ax1, bx10, bx11, cx1, l1, ptr1, idx1); + CN_STEP1(ax2, bx20, bx21, cx2, l2, ptr2, idx2); + CN_STEP1(ax3, bx30, bx31, cx3, l3, ptr3, idx3); + + CN_STEP2(ax0, bx00, bx01, cx0, l0, ptr0, idx0); + CN_STEP2(ax1, bx10, bx11, cx1, l1, ptr1, idx1); + CN_STEP2(ax2, bx20, bx21, cx2, l2, ptr2, idx2); + CN_STEP2(ax3, bx30, bx31, cx3, l3, ptr3, idx3); + + CN_STEP3(0, ax0, bx00, bx01, cx0, l0, ptr0, idx0); + CN_STEP3(1, ax1, bx10, bx11, cx1, l1, ptr1, idx1); + CN_STEP3(2, ax2, bx20, bx21, cx2, l2, ptr2, idx2); + CN_STEP3(3, ax3, bx30, bx31, cx3, l3, ptr3, idx3); + + CN_STEP4(0, ax0, bx00, bx01, cx0, l0, mc0, ptr0, idx0); + CN_STEP4(1, ax1, bx10, bx11, cx1, l1, mc1, ptr1, idx1); + CN_STEP4(2, ax2, bx20, bx21, cx2, l2, mc2, ptr2, idx2); + CN_STEP4(3, ax3, bx30, bx31, cx3, l3, mc3, ptr3, idx3); } for (size_t i = 0; i < 4; i++) { @@ -962,9 +977,9 @@ inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t siz constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_MONERO = xmrig::cn_is_monero(); + constexpr bool IS_V1 = xmrig::cn_uses_variant1(); - if (IS_MONERO && size < 43) { + if (IS_V1 && size < 43) { memset(output, 0, 32 * 5); return; } @@ -974,12 +989,6 @@ inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t siz cn_explode_scratchpad(reinterpret_cast<__m128i*>(ctx[i]->state), reinterpret_cast<__m128i*>(ctx[i]->memory)); } - CONST_INIT(ctx[0], 0); - CONST_INIT(ctx[1], 1); - CONST_INIT(ctx[2], 2); - CONST_INIT(ctx[3], 3); - CONST_INIT(ctx[4], 4); - uint8_t* l0 = ctx[0]->memory; uint8_t* l1 = ctx[1]->memory; uint8_t* l2 = ctx[2]->memory; @@ -991,21 +1000,12 @@ inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t siz uint64_t* h3 = reinterpret_cast(ctx[3]->state); uint64_t* h4 = reinterpret_cast(ctx[4]->state); - __m128i ax0 = _mm_set_epi64x(h0[1] ^ h0[5], h0[0] ^ h0[4]); - __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); - __m128i ax1 = _mm_set_epi64x(h1[1] ^ h1[5], h1[0] ^ h1[4]); - __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); - __m128i ax2 = _mm_set_epi64x(h2[1] ^ h2[5], h2[0] ^ h2[4]); - __m128i bx2 = _mm_set_epi64x(h2[3] ^ h2[7], h2[2] ^ h2[6]); - __m128i ax3 = _mm_set_epi64x(h3[1] ^ h3[5], h3[0] ^ h3[4]); - __m128i bx3 = _mm_set_epi64x(h3[3] ^ h3[7], h3[2] ^ h3[6]); - __m128i ax4 = _mm_set_epi64x(h4[1] ^ h4[5], h4[0] ^ h4[4]); - __m128i bx4 = _mm_set_epi64x(h4[3] ^ h4[7], h4[2] ^ h4[6]); - __m128i cx0 = _mm_set_epi64x(0, 0); - __m128i cx1 = _mm_set_epi64x(0, 0); - __m128i cx2 = _mm_set_epi64x(0, 0); - __m128i cx3 = _mm_set_epi64x(0, 0); - __m128i cx4 = _mm_set_epi64x(0, 0); + CONST_INIT(ctx[0], 0); + CONST_INIT(ctx[1], 1); + CONST_INIT(ctx[2], 2); + CONST_INIT(ctx[3], 3); + CONST_INIT(ctx[4], 4); + VARIANT2_SET_ROUNDING_MODE(); uint64_t idx0, idx1, idx2, idx3, idx4; idx0 = EXTRACT64(ax0); @@ -1014,60 +1014,34 @@ inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t siz idx3 = EXTRACT64(ax3); idx4 = EXTRACT64(ax4); - for (size_t i = 0; i < ITERATIONS / 2; i++) + for (size_t i = 0; i < ITERATIONS; i++) { uint64_t hi, lo; __m128i *ptr0, *ptr1, *ptr2, *ptr3, *ptr4; - // EVEN ROUND - CN_STEP1(ax0, bx0, cx0, l0, ptr0, idx0); - CN_STEP1(ax1, bx1, cx1, l1, ptr1, idx1); - CN_STEP1(ax2, bx2, cx2, l2, ptr2, idx2); - CN_STEP1(ax3, bx3, cx3, l3, ptr3, idx3); - CN_STEP1(ax4, bx4, cx4, l4, ptr4, idx4); - - CN_STEP2(ax0, bx0, cx0, l0, ptr0, idx0); - CN_STEP2(ax1, bx1, cx1, l1, ptr1, idx1); - CN_STEP2(ax2, bx2, cx2, l2, ptr2, idx2); - CN_STEP2(ax3, bx3, cx3, l3, ptr3, idx3); - CN_STEP2(ax4, bx4, cx4, l4, ptr4, idx4); - - CN_STEP3(ax0, bx0, cx0, l0, ptr0, idx0); - CN_STEP3(ax1, bx1, cx1, l1, ptr1, idx1); - CN_STEP3(ax2, bx2, cx2, l2, ptr2, idx2); - CN_STEP3(ax3, bx3, cx3, l3, ptr3, idx3); - CN_STEP3(ax4, bx4, cx4, l4, ptr4, idx4); - - CN_STEP4(ax0, bx0, cx0, l0, mc0, ptr0, idx0); - CN_STEP4(ax1, bx1, cx1, l1, mc1, ptr1, idx1); - CN_STEP4(ax2, bx2, cx2, l2, mc2, ptr2, idx2); - CN_STEP4(ax3, bx3, cx3, l3, mc3, ptr3, idx3); - CN_STEP4(ax4, bx4, cx4, l4, mc4, ptr4, idx4); - - // ODD ROUND - CN_STEP1(ax0, cx0, bx0, l0, ptr0, idx0); - CN_STEP1(ax1, cx1, bx1, l1, ptr1, idx1); - CN_STEP1(ax2, cx2, bx2, l2, ptr2, idx2); - CN_STEP1(ax3, cx3, bx3, l3, ptr3, idx3); - CN_STEP1(ax4, cx4, bx4, l4, ptr4, idx4); - - CN_STEP2(ax0, cx0, bx0, l0, ptr0, idx0); - CN_STEP2(ax1, cx1, bx1, l1, ptr1, idx1); - CN_STEP2(ax2, cx2, bx2, l2, ptr2, idx2); - CN_STEP2(ax3, cx3, bx3, l3, ptr3, idx3); - CN_STEP2(ax4, cx4, bx4, l4, ptr4, idx4); - - CN_STEP3(ax0, cx0, bx0, l0, ptr0, idx0); - CN_STEP3(ax1, cx1, bx1, l1, ptr1, idx1); - CN_STEP3(ax2, cx2, bx2, l2, ptr2, idx2); - CN_STEP3(ax3, cx3, bx3, l3, ptr3, idx3); - CN_STEP3(ax4, cx4, bx4, l4, ptr4, idx4); - - CN_STEP4(ax0, cx0, bx0, l0, mc0, ptr0, idx0); - CN_STEP4(ax1, cx1, bx1, l1, mc1, ptr1, idx1); - CN_STEP4(ax2, cx2, bx2, l2, mc2, ptr2, idx2); - CN_STEP4(ax3, cx3, bx3, l3, mc3, ptr3, idx3); - CN_STEP4(ax4, cx4, bx4, l4, mc4, ptr4, idx4); + CN_STEP1(ax0, bx00, bx01, cx0, l0, ptr0, idx0); + CN_STEP1(ax1, bx10, bx11, cx1, l1, ptr1, idx1); + CN_STEP1(ax2, bx20, bx21, cx2, l2, ptr2, idx2); + CN_STEP1(ax3, bx30, bx31, cx3, l3, ptr3, idx3); + CN_STEP1(ax4, bx40, bx41, cx4, l4, ptr4, idx4); + + CN_STEP2(ax0, bx00, bx01, cx0, l0, ptr0, idx0); + CN_STEP2(ax1, bx10, bx11, cx1, l1, ptr1, idx1); + CN_STEP2(ax2, bx20, bx21, cx2, l2, ptr2, idx2); + CN_STEP2(ax3, bx30, bx31, cx3, l3, ptr3, idx3); + CN_STEP2(ax4, bx40, bx41, cx4, l4, ptr4, idx4); + + CN_STEP3(0, ax0, bx00, bx01, cx0, l0, ptr0, idx0); + CN_STEP3(1, ax1, bx10, bx11, cx1, l1, ptr1, idx1); + CN_STEP3(2, ax2, bx20, bx21, cx2, l2, ptr2, idx2); + CN_STEP3(3, ax3, bx30, bx31, cx3, l3, ptr3, idx3); + CN_STEP3(4, ax4, bx40, bx41, cx4, l4, ptr4, idx4); + + CN_STEP4(0, ax0, bx00, bx01, cx0, l0, mc0, ptr0, idx0); + CN_STEP4(1, ax1, bx10, bx11, cx1, l1, mc1, ptr1, idx1); + CN_STEP4(2, ax2, bx20, bx21, cx2, l2, mc2, ptr2, idx2); + CN_STEP4(3, ax3, bx30, bx31, cx3, l3, mc3, ptr3, idx3); + CN_STEP4(4, ax4, bx40, bx41, cx4, l4, mc4, ptr4, idx4); } for (size_t i = 0; i < 5; i++) { diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 7cef4f3adf..bdf09af4b5 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -135,6 +135,17 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + # ifndef XMRIG_NO_AEON cryptonight_single_hash, cryptonight_double_hash, @@ -164,6 +175,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XAO nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RTO + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_2 # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, @@ -173,6 +185,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif # ifndef XMRIG_NO_SUMO @@ -216,6 +229,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XAO nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RTO + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_2 # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, @@ -225,6 +239,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif }; diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 5d43875c47..475f99beed 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -55,6 +55,7 @@ bool MultiWorker::selfTest() if (m_thread->algorithm() == CRYPTONIGHT) { return verify(VARIANT_0, test_output_v0) && verify(VARIANT_1, test_output_v1) && + verify(VARIANT_2, test_output_v2) && verify(VARIANT_XTL, test_output_xtl) && verify(VARIANT_MSR, test_output_msr) && verify(VARIANT_XAO, test_output_xao) && From efbeed2b1e6ea230ba2b29a8772ade52c3853300 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 29 Aug 2018 19:52:33 +0200 Subject: [PATCH 042/102] Removed excess code for v0 & v1 --- src/crypto/CryptoNight_arm.h | 10 +++++++--- src/crypto/CryptoNight_x86.h | 14 ++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 7f273765d5..1df4ec5d65 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -527,7 +527,9 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si idx0 = d ^ q; } } - bx1 = bx0; + if (VARIANT == xmrig::VARIANT_2) { + bx1 = bx0; + } bx0 = cx; } @@ -699,9 +701,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si idx1 = d ^ q; } } - bx01 = bx00; + if (VARIANT == xmrig::VARIANT_2) { + bx01 = bx00; + bx11 = bx10; + } bx00 = cx0; - bx11 = bx10; bx10 = cx1; } diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index e234d41d07..e134abac97 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -553,7 +553,9 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si idx0 = d ^ q; ptr0 = (uint64_t*)&l0[idx0 & MASK]; } - bx1 = bx0; + if (VARIANT == xmrig::VARIANT_2) { + bx1 = bx0; + } bx0 = cx; } @@ -731,9 +733,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ptr1 = (uint64_t*)&l1[idx1 & MASK]; } - bx01 = bx00; + if (VARIANT == xmrig::VARIANT_2) { + bx01 = bx00; + bx11 = bx10; + } bx00 = cx0; - bx11 = bx10; bx10 = cx1; } @@ -812,7 +816,9 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si \ idx = d ^ q; \ } \ - b1 = b0; \ + if (VARIANT == xmrig::VARIANT_2) { \ + b1 = b0; \ + } \ b0 = c; From 8467b7b68eadc669183512183dfc19ba42199241 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 29 Aug 2018 20:15:08 +0200 Subject: [PATCH 043/102] Fixed performance degradation for v0 & v1 --- src/crypto/CryptoNight_x86.h | 90 ++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 51 deletions(-) diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index e134abac97..31d86105c0 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -481,12 +481,11 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si __m128i bx1 = _mm_set_epi64x(h0[9] ^ h0[11], h0[8] ^ h0[10]); uint64_t idx0 = al0; - uint64_t* ptr0 = (uint64_t*) &l0[idx0 & MASK]; for (size_t i = 0; i < ITERATIONS; i++) { __m128i cx; if (VARIANT == xmrig::VARIANT_TUBE || !SOFT_AES) { - cx = _mm_load_si128((__m128i *) ptr0); + cx = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); } const __m128i ax0 = _mm_set_epi64x(ah0, al0); @@ -494,24 +493,23 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si cx = aes_round_tweak_div(cx, ax0); } else if (SOFT_AES) { - cx = soft_aesenc((uint32_t*) ptr0, ax0); + cx = soft_aesenc((uint32_t*) &l0[idx0 & MASK], ax0); } else { cx = _mm_aesenc_si128(cx, ax0); } if (IS_V1 || VARIANT == xmrig::VARIANT_2) { - cryptonight_monero_tweak(ptr0, l0, idx0 & MASK, ax0, bx0, bx1, cx); + cryptonight_monero_tweak((uint64_t*) &l0[idx0 & MASK], l0, idx0 & MASK, ax0, bx0, bx1, cx); } else { - _mm_store_si128((__m128i *) ptr0, _mm_xor_si128(bx0, cx)); + _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); } idx0 = EXTRACT64(cx); - ptr0 = (uint64_t*) &l0[idx0 & MASK]; uint64_t hi, lo, cl, ch; - cl = ptr0[0]; - ch = ptr0[1]; + cl = ((uint64_t*) &l0[idx0 & MASK])[0]; + ch = ((uint64_t*) &l0[idx0 & MASK])[1]; if (VARIANT == xmrig::VARIANT_2) { VARIANT2_INTEGER_MATH(0, cl, cx); lo = __umul128(idx0, cl, &hi); @@ -524,34 +522,32 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si al0 += hi; ah0 += lo; - ptr0[0] = al0; + ((uint64_t*) &l0[idx0 & MASK])[0] = al0; if (IS_V1 && (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO)) { - ptr0[1] = ah0 ^ tweak1_2_0 ^ al0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } else if (IS_V1) { - ptr0[1] = ah0 ^ tweak1_2_0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0; } else { - ptr0[1] = ah0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; } al0 ^= cl; ah0 ^= ch; idx0 = al0; - ptr0 = (uint64_t*) &l0[idx0 & MASK]; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)ptr0)[0]; - int32_t d = ((int32_t*)ptr0)[2]; + int64_t n = ((int64_t*) &l0[idx0 & MASK])[0]; + int32_t d = ((int32_t*) &l0[idx0 & MASK])[2]; int64_t q = n / (d | 0x5); - ((int64_t*) ptr0)[0] = n ^ q; + ((int64_t*) &l0[idx0 & MASK])[0] = n ^ q; if (VARIANT == xmrig::VARIANT_XHV) { d = ~d; } idx0 = d ^ q; - ptr0 = (uint64_t*)&l0[idx0 & MASK]; } if (VARIANT == xmrig::VARIANT_2) { bx1 = bx0; @@ -608,14 +604,12 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si uint64_t idx0 = al0; uint64_t idx1 = al1; - uint64_t* ptr0 = (uint64_t*)&l0[idx0 & MASK]; - uint64_t* ptr1 = (uint64_t*)&l1[idx1 & MASK]; for (size_t i = 0; i < ITERATIONS; i++) { __m128i cx0, cx1; if (VARIANT == xmrig::VARIANT_TUBE || !SOFT_AES) { - cx0 = _mm_load_si128((__m128i *) ptr0); - cx1 = _mm_load_si128((__m128i *) ptr1); + cx0 = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); + cx1 = _mm_load_si128((__m128i *) &l1[idx1 & MASK]); } const __m128i ax0 = _mm_set_epi64x(ah0, al0); @@ -625,8 +619,8 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si cx1 = aes_round_tweak_div(cx1, ax1); } else if (SOFT_AES) { - cx0 = soft_aesenc((uint32_t*)ptr0, ax0); - cx1 = soft_aesenc((uint32_t*)ptr1, ax1); + cx0 = soft_aesenc((uint32_t*) &l0[idx0 & MASK], ax0); + cx1 = soft_aesenc((uint32_t*) &l1[idx1 & MASK], ax1); } else { cx0 = _mm_aesenc_si128(cx0, ax0); @@ -634,21 +628,19 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si } if (IS_V1 || (VARIANT == xmrig::VARIANT_2)) { - cryptonight_monero_tweak(ptr0, l0, idx0 & MASK, ax0, bx00, bx01, cx0); - cryptonight_monero_tweak(ptr1, l1, idx1 & MASK, ax1, bx10, bx11, cx1); + cryptonight_monero_tweak((uint64_t*) &l0[idx0 & MASK], l0, idx0 & MASK, ax0, bx00, bx01, cx0); + cryptonight_monero_tweak((uint64_t*) &l1[idx1 & MASK], l1, idx1 & MASK, ax1, bx10, bx11, cx1); } else { - _mm_store_si128((__m128i *) ptr0, _mm_xor_si128(bx00, cx0)); - _mm_store_si128((__m128i *) ptr1, _mm_xor_si128(bx10, cx1)); + _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx00, cx0)); + _mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx10, cx1)); } idx0 = EXTRACT64(cx0); idx1 = EXTRACT64(cx1); - ptr0 = (uint64_t*)&l0[idx0 & MASK]; - ptr1 = (uint64_t*)&l1[idx1 & MASK]; uint64_t hi, lo, cl, ch; - cl = ((uint64_t*)ptr0)[0]; - ch = ((uint64_t*)ptr0)[1]; + cl = ((uint64_t*) &l0[idx0 & MASK])[0]; + ch = ((uint64_t*) &l0[idx0 & MASK])[1]; if (VARIANT == xmrig::VARIANT_2) { VARIANT2_INTEGER_MATH(0, cl, cx0); lo = __umul128(idx0, cl, &hi); @@ -660,38 +652,36 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si al0 += hi; ah0 += lo; - ((uint64_t*)ptr0)[0] = al0; + ((uint64_t*) &l0[idx0 & MASK])[0] = al0; if (IS_V1 && (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO)) { - ((uint64_t*)ptr0)[1] = ah0 ^ tweak1_2_0 ^ al0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } else if (IS_V1) { - ((uint64_t*)ptr0)[1] = ah0 ^ tweak1_2_0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0; } else { - ((uint64_t*)ptr0)[1] = ah0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; } al0 ^= cl; ah0 ^= ch; idx0 = al0; - ptr0 = (uint64_t*)&l0[idx0 & MASK]; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)ptr0)[0]; - int32_t d = ((int32_t*)ptr0)[2]; + int64_t n = ((int64_t*) &l0[idx0 & MASK])[0]; + int32_t d = ((int32_t*) &l0[idx0 & MASK])[2]; int64_t q = n / (d | 0x5); - ((int64_t*)ptr0)[0] = n ^ q; + ((int64_t*) &l0[idx0 & MASK])[0] = n ^ q; if (VARIANT == xmrig::VARIANT_XHV) { d = ~d; } idx0 = d ^ q; - ptr0 = (uint64_t*)&l0[idx0 & MASK]; } - cl = ptr1[0]; - ch = ptr1[1]; + cl = ((uint64_t*) &l1[idx1 & MASK])[0]; + ch = ((uint64_t*) &l1[idx1 & MASK])[1]; if (VARIANT == xmrig::VARIANT_2) { VARIANT2_INTEGER_MATH(1, cl, cx1); lo = __umul128(idx1, cl, &hi); @@ -703,34 +693,32 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si al1 += hi; ah1 += lo; - ptr1[0] = al1; + ((uint64_t*)&l1[idx1 & MASK])[0] = al1; if (IS_V1 && (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO)) { - ptr1[1] = ah1 ^ tweak1_2_1 ^ al1; + ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; } else if (IS_V1) { - ptr1[1] = ah1 ^ tweak1_2_1; + ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1; } else { - ptr1[1] = ah1; + ((uint64_t*)&l1[idx1 & MASK])[1] = ah1; } al1 ^= cl; ah1 ^= ch; idx1 = al1; - ptr1 = (uint64_t*)&l1[idx1 & MASK]; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*)ptr1)[0]; - int32_t d = ((int32_t*)ptr1)[2]; + int64_t n = ((int64_t*) &l1[idx1 & MASK])[0]; + int32_t d = ((int32_t*) &l1[idx1 & MASK])[2]; int64_t q = n / (d | 0x5); - ((int64_t*)ptr1)[0] = n ^ q; + ((int64_t*) &l1[idx1 & MASK])[0] = n ^ q; if (VARIANT == xmrig::VARIANT_XHV) { d = ~d; } idx1 = d ^ q; - ptr1 = (uint64_t*)&l1[idx1 & MASK]; } if (VARIANT == xmrig::VARIANT_2) { From 22b4e1c3a59679767285fc6396d2acc6e9d15b75 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 29 Aug 2018 20:27:17 +0200 Subject: [PATCH 044/102] Fixed spaces --- src/crypto/CryptoNight_x86.h | 42 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 31d86105c0..00cf60b65a 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -493,16 +493,16 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si cx = aes_round_tweak_div(cx, ax0); } else if (SOFT_AES) { - cx = soft_aesenc((uint32_t*) &l0[idx0 & MASK], ax0); + cx = soft_aesenc((uint32_t*)&l0[idx0 & MASK], ax0); } else { cx = _mm_aesenc_si128(cx, ax0); } if (IS_V1 || VARIANT == xmrig::VARIANT_2) { - cryptonight_monero_tweak((uint64_t*) &l0[idx0 & MASK], l0, idx0 & MASK, ax0, bx0, bx1, cx); + cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], l0, idx0 & MASK, ax0, bx0, bx1, cx); } else { - _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); + _mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); } idx0 = EXTRACT64(cx); @@ -522,14 +522,14 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si al0 += hi; ah0 += lo; - ((uint64_t*) &l0[idx0 & MASK])[0] = al0; + ((uint64_t*)&l0[idx0 & MASK])[0] = al0; if (IS_V1 && (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO)) { - ((uint64_t*) &l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; + ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } else if (IS_V1) { - ((uint64_t*) &l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0; + ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0; } else { - ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; + ((uint64_t*)&l0[idx0 & MASK])[1] = ah0; } al0 ^= cl; @@ -537,11 +537,11 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si idx0 = al0; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*) &l0[idx0 & MASK])[0]; - int32_t d = ((int32_t*) &l0[idx0 & MASK])[2]; + int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; + int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; int64_t q = n / (d | 0x5); - ((int64_t*) &l0[idx0 & MASK])[0] = n ^ q; + ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; if (VARIANT == xmrig::VARIANT_XHV) { d = ~d; @@ -619,8 +619,8 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si cx1 = aes_round_tweak_div(cx1, ax1); } else if (SOFT_AES) { - cx0 = soft_aesenc((uint32_t*) &l0[idx0 & MASK], ax0); - cx1 = soft_aesenc((uint32_t*) &l1[idx1 & MASK], ax1); + cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], ax0); + cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], ax1); } else { cx0 = _mm_aesenc_si128(cx0, ax0); @@ -628,8 +628,8 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si } if (IS_V1 || (VARIANT == xmrig::VARIANT_2)) { - cryptonight_monero_tweak((uint64_t*) &l0[idx0 & MASK], l0, idx0 & MASK, ax0, bx00, bx01, cx0); - cryptonight_monero_tweak((uint64_t*) &l1[idx1 & MASK], l1, idx1 & MASK, ax1, bx10, bx11, cx1); + cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], l0, idx0 & MASK, ax0, bx00, bx01, cx0); + cryptonight_monero_tweak((uint64_t*)&l1[idx1 & MASK], l1, idx1 & MASK, ax1, bx10, bx11, cx1); } else { _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx00, cx0)); _mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx10, cx1)); @@ -652,7 +652,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si al0 += hi; ah0 += lo; - ((uint64_t*) &l0[idx0 & MASK])[0] = al0; + ((uint64_t*)&l0[idx0 & MASK])[0] = al0; if (IS_V1 && (VARIANT == xmrig::VARIANT_TUBE || VARIANT == xmrig::VARIANT_RTO)) { ((uint64_t*) &l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; @@ -667,11 +667,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si idx0 = al0; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*) &l0[idx0 & MASK])[0]; - int32_t d = ((int32_t*) &l0[idx0 & MASK])[2]; + int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; + int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; int64_t q = n / (d | 0x5); - ((int64_t*) &l0[idx0 & MASK])[0] = n ^ q; + ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; if (VARIANT == xmrig::VARIANT_XHV) { d = ~d; @@ -708,11 +708,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si idx1 = al1; if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*) &l1[idx1 & MASK])[0]; - int32_t d = ((int32_t*) &l1[idx1 & MASK])[2]; + int64_t n = ((int64_t*)&l1[idx1 & MASK])[0]; + int32_t d = ((int32_t*)&l1[idx1 & MASK])[2]; int64_t q = n / (d | 0x5); - ((int64_t*) &l1[idx1 & MASK])[0] = n ^ q; + ((int64_t*)&l1[idx1 & MASK])[0] = n ^ q; if (VARIANT == xmrig::VARIANT_XHV) { d = ~d; From cc09def4c4c9ee0cc786a1c8889eb105b871316f Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 31 Aug 2018 18:01:15 +0300 Subject: [PATCH 045/102] Sync changes. --- src/common/api/HttpRequest.cpp | 2 +- src/common/config/CommonConfig.cpp | 4 ++++ src/common/config/CommonConfig.h | 2 ++ src/common/crypto/keccak.h | 6 +++--- src/common/interfaces/IConfig.h | 17 ++++++++++++++--- src/common/interfaces/IControllerListener.h | 6 +++--- src/common/utils/timestamp.h | 8 ++++---- 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/common/api/HttpRequest.cpp b/src/common/api/HttpRequest.cpp index 01245dfc05..6898a3851f 100644 --- a/src/common/api/HttpRequest.cpp +++ b/src/common/api/HttpRequest.cpp @@ -147,7 +147,7 @@ int xmrig::HttpRequest::end(int status, MHD_Response *rsp) MHD_add_response_header(rsp, "Content-Type", "application/json"); MHD_add_response_header(rsp, "Access-Control-Allow-Origin", "*"); MHD_add_response_header(rsp, "Access-Control-Allow-Methods", "GET, PUT"); - MHD_add_response_header(rsp, "Access-Control-Allow-Headers", "Authorization"); + MHD_add_response_header(rsp, "Access-Control-Allow-Headers", "Authorization, Content-Type"); const int ret = MHD_queue_response(m_connection, status, rsp); MHD_destroy_response(rsp); diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 7e43b39de7..ca9017579b 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -251,6 +251,10 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg) m_apiWorkerId = arg; break; + case ApiIdKey: /* --api-id */ + m_apiId = arg; + break; + case UserAgentKey: /* --user-agent */ m_userAgent = arg; break; diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index ffebb6b250..fa27ea6a48 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -49,6 +49,7 @@ class CommonConfig : public IConfig inline bool isColors() const { return m_colors; } inline bool isDryRun() const { return m_dryRun; } inline bool isSyslog() const { return m_syslog; } + inline const char *apiId() const { return m_apiId.data(); } inline const char *apiToken() const { return m_apiToken.data(); } inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } inline const char *logFile() const { return m_logFile.data(); } @@ -97,6 +98,7 @@ class CommonConfig : public IConfig State m_state; std::vector m_activePools; std::vector m_pools; + xmrig::c_str m_apiId; xmrig::c_str m_apiToken; xmrig::c_str m_apiWorkerId; xmrig::c_str m_fileName; diff --git a/src/common/crypto/keccak.h b/src/common/crypto/keccak.h index da8d6c52a5..6121044aa7 100644 --- a/src/common/crypto/keccak.h +++ b/src/common/crypto/keccak.h @@ -23,8 +23,8 @@ */ -#ifndef KECCAK_H_ -#define KECCAK_H_ +#ifndef XMRIG_KECCAK_H +#define XMRIG_KECCAK_H #include #include @@ -52,4 +52,4 @@ void keccakf(uint64_t st[25], int norounds); } /* namespace xmrig */ -#endif /* KECCAK_H_ */ +#endif /* XMRIG_KECCAK_H */ diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 4b3f878850..fb622e37cb 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef __ICONFIG_H__ -#define __ICONFIG_H__ +#ifndef XMRIG_ICONFIG_H +#define XMRIG_ICONFIG_H #include "common/crypto/Algorithm.h" @@ -42,6 +42,7 @@ class IConfig ApiPort = 4000, ApiRestrictedKey = 4004, ApiWorkerIdKey = 4002, + ApiIdKey = 4005, BackgroundKey = 'B', ColorKey = 1002, ConfigKey = 'c', @@ -97,6 +98,16 @@ class IConfig PoolCoinKey = 'C', ReuseTimeoutKey = 1106, WorkersKey = 1103, + WorkersAdvKey = 1107, + + // xmrig nvidia + CudaMaxThreadsKey = 1200, + CudaBFactorKey = 1201, + CudaBSleepKey = 1202, + CudaDevicesKey = 1203, + CudaLaunchKey = 1204, + CudaAffinityKey = 1205, + CudaMaxUsageKey = 1206, }; virtual ~IConfig() {} @@ -118,4 +129,4 @@ class IConfig } /* namespace xmrig */ -#endif // __ICONFIG_H__ +#endif // XMRIG_ICONFIG_H diff --git a/src/common/interfaces/IControllerListener.h b/src/common/interfaces/IControllerListener.h index d607713834..35249bcde2 100644 --- a/src/common/interfaces/IControllerListener.h +++ b/src/common/interfaces/IControllerListener.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __ICONTROLLERLISTENER_H__ -#define __ICONTROLLERLISTENER_H__ +#ifndef XMRIG_ICONTROLLERLISTENER_H +#define XMRIG_ICONTROLLERLISTENER_H namespace xmrig { @@ -43,4 +43,4 @@ class IControllerListener } /* namespace xmrig */ -#endif // __ICONTROLLERLISTENER_H__ +#endif // XMRIG_ICONTROLLERLISTENER_H diff --git a/src/common/utils/timestamp.h b/src/common/utils/timestamp.h index b4404b2e77..6b6a8ab244 100644 --- a/src/common/utils/timestamp.h +++ b/src/common/utils/timestamp.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __TIMESTAMP_H__ -#define __TIMESTAMP_H__ +#ifndef XMRIG_TIMESTAMP_H +#define XMRIG_TIMESTAMP_H #include @@ -31,7 +31,7 @@ namespace xmrig { -int64_t currentMSecsSinceEpoch() +static inline int64_t currentMSecsSinceEpoch() { using namespace std::chrono; if (high_resolution_clock::is_steady) { @@ -44,4 +44,4 @@ int64_t currentMSecsSinceEpoch() } /* namespace xmrig */ -#endif /* __TIMESTAMP_H__ */ +#endif /* XMRIG_TIMESTAMP_H */ From 21ff3c248409cee0d9b588caa3b81d782d1ccc02 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 31 Aug 2018 18:30:51 +0300 Subject: [PATCH 046/102] * Fixed API ID collision. --- src/api/ApiRouter.cpp | 18 ++++++++++++------ src/api/ApiRouter.h | 4 ++-- src/core/Config.cpp | 1 + src/core/ConfigLoader_platform.h | 17 ++++++++++------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/api/ApiRouter.cpp b/src/api/ApiRouter.cpp index 07e425f18a..2c62696ac6 100644 --- a/src/api/ApiRouter.cpp +++ b/src/api/ApiRouter.cpp @@ -42,7 +42,6 @@ #include "core/Controller.h" #include "Cpu.h" #include "interfaces/IThread.h" -#include "Mem.h" #include "rapidjson/document.h" #include "rapidjson/prettywriter.h" #include "rapidjson/stringbuffer.h" @@ -67,7 +66,7 @@ ApiRouter::ApiRouter(xmrig::Controller *controller) : memset(m_workerId, 0, sizeof(m_workerId)); setWorkerId(controller->config()->apiWorkerId()); - genId(); + genId(controller->config()->apiId()); } @@ -145,10 +144,15 @@ void ApiRouter::finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) cons } -void ApiRouter::genId() +void ApiRouter::genId(const char *id) { memset(m_id, 0, sizeof(m_id)); + if (id && strlen(id) > 0) { + strncpy(m_id, id, sizeof(m_id) - 1); + return; + } + uv_interface_address_t *interfaces; int count = 0; @@ -160,11 +164,13 @@ void ApiRouter::genId() if (!interfaces[i].is_internal && interfaces[i].address.address4.sin_family == AF_INET) { uint8_t hash[200]; const size_t addrSize = sizeof(interfaces[i].phys_addr); - const size_t inSize = strlen(APP_KIND) + addrSize; + const size_t inSize = strlen(APP_KIND) + addrSize + sizeof(uint16_t); + const uint16_t port = static_cast(m_controller->config()->apiPort()); uint8_t *input = new uint8_t[inSize](); - memcpy(input, interfaces[i].phys_addr, addrSize); - memcpy(input + addrSize, APP_KIND, strlen(APP_KIND)); + memcpy(input, &port, sizeof(uint16_t)); + memcpy(input + sizeof(uint16_t), interfaces[i].phys_addr, addrSize); + memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, strlen(APP_KIND)); xmrig::keccak(input, inSize, hash); Job::toHex(hash, 8, m_id); diff --git a/src/api/ApiRouter.h b/src/api/ApiRouter.h index 9e32cdaee6..b781d5a28c 100644 --- a/src/api/ApiRouter.h +++ b/src/api/ApiRouter.h @@ -56,7 +56,7 @@ class ApiRouter : public xmrig::IControllerListener private: void finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const; - void genId(); + void genId(const char *id); void getConnection(rapidjson::Document &doc) const; void getHashrate(rapidjson::Document &doc) const; void getIdentify(rapidjson::Document &doc) const; @@ -66,7 +66,7 @@ class ApiRouter : public xmrig::IControllerListener void setWorkerId(const char *id); void updateWorkerId(const char *id, const char *previousId); - char m_id[17]; + char m_id[32]; char m_workerId[128]; NetworkState m_network; xmrig::Controller *m_controller; diff --git a/src/core/Config.cpp b/src/core/Config.cpp index fa6afdb4dd..0380c26d2a 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -75,6 +75,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const Value api(kObjectType); api.AddMember("port", apiPort(), allocator); api.AddMember("access-token", apiToken() ? Value(StringRef(apiToken())).Move() : Value(kNullType).Move(), allocator); + api.AddMember("id", apiId() ? Value(StringRef(apiId())).Move() : Value(kNullType).Move(), allocator); api.AddMember("worker-id", apiWorkerId() ? Value(StringRef(apiWorkerId())).Move() : Value(kNullType).Move(), allocator); api.AddMember("ipv6", isApiIPv6(), allocator); api.AddMember("restricted", isApiRestricted(), allocator); diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index bc6657d1b6..9872427160 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -22,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __CONFIGLOADER_PLATFORM_H__ -#define __CONFIGLOADER_PLATFORM_H__ +#ifndef XMRIG_CONFIGLOADER_PLATFORM_H +#define XMRIG_CONFIGLOADER_PLATFORM_H #ifdef _MSC_VER @@ -86,6 +86,7 @@ Options:\n\ --api-port=N port for the miner API\n\ --api-access-token=T access token for API\n\ --api-worker-id=ID custom worker-id for API\n\ + --api-id=ID custom instance ID for API\n\ --api-ipv6 enable IPv6 support for API\n\ --api-no-restricted enable full remote access (only if API token set)\n\ -h, --help display this help and exit\n\ @@ -101,6 +102,7 @@ static struct option const options[] = { { "api-access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey }, { "api-port", 1, nullptr, xmrig::IConfig::ApiPort }, { "api-worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey }, + { "api-id", 1, nullptr, xmrig::IConfig::ApiIdKey }, { "api-ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key }, { "api-no-restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey }, { "av", 1, nullptr, xmrig::IConfig::AVKey }, @@ -131,7 +133,7 @@ static struct option const options[] = { { "userpass", 1, nullptr, xmrig::IConfig::UserpassKey }, { "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey }, { "version", 0, nullptr, xmrig::IConfig::VersionKey }, - { 0, 0, 0, 0 } + { nullptr, 0, nullptr, 0 } }; @@ -155,7 +157,7 @@ static struct option const config_options[] = { { "threads", 1, nullptr, xmrig::IConfig::ThreadsKey }, { "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey }, { "hw-aes", 0, nullptr, xmrig::IConfig::HardwareAESKey }, - { 0, 0, 0, 0 } + { nullptr, 0, nullptr, 0 } }; @@ -168,7 +170,7 @@ static struct option const pool_options[] = { { "keepalive", 2, nullptr, xmrig::IConfig::KeepAliveKey }, { "variant", 1, nullptr, xmrig::IConfig::VariantKey }, { "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey }, - { 0, 0, 0, 0 } + { nullptr, 0, nullptr, 0 } }; @@ -178,10 +180,11 @@ static struct option const api_options[] = { { "worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey }, { "ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key }, { "restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey }, - { 0, 0, 0, 0 } + { "id", 1, nullptr, xmrig::IConfig::ApiIdKey }, + { nullptr, 0, nullptr, 0 } }; } /* namespace xmrig */ -#endif /* __CONFIGLOADER_PLATFORM_H__ */ +#endif /* XMRIG_CONFIGLOADER_PLATFORM_H */ From f9441456d40296865fc276330c5e00adde22b001 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 31 Aug 2018 21:51:34 +0300 Subject: [PATCH 047/102] Fixed gcc build. --- src/crypto/CryptoNight_monero.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index 3fb18d00f7..0ceb93fecd 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett + * Copyright 2018 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -22,9 +23,10 @@ * along with this program. If not, see . */ -#ifndef __CRYPTONIGHT_MONERO_H__ -#define __CRYPTONIGHT_MONERO_H__ +#ifndef XMRIG_CRYPTONIGHT_MONERO_H +#define XMRIG_CRYPTONIGHT_MONERO_H +#include #include // VARIANT ALTERATIONS @@ -121,4 +123,4 @@ vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x30)), vaddq_u64(chunk2, vreinterpretq_u64_u8(_a))); \ } while (0) #endif -#endif /* __CRYPTONIGHT_MONERO_H__ */ +#endif /* XMRIG_CRYPTONIGHT_MONERO_H */ From acb9854abbfdeb27174abc0e0ed55e205da94e01 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 31 Aug 2018 23:19:10 +0300 Subject: [PATCH 048/102] Fixed 32 bit support. --- src/crypto/CryptoNight_x86.h | 67 ++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 00cf60b65a..a0b676a538 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett + * Copyright 2018 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -22,8 +23,8 @@ * along with this program. If not, see . */ -#ifndef __CRYPTONIGHT_X86_H__ -#define __CRYPTONIGHT_X86_H__ +#ifndef XMRIG_CRYPTONIGHT_X86_H +#define XMRIG_CRYPTONIGHT_X86_H #ifdef __GNUC__ @@ -73,10 +74,7 @@ static inline void do_skein_hash(const uint8_t *input, size_t len, uint8_t *outp void (* const extra_hashes[4])(const uint8_t *, size_t, uint8_t *) = {do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash}; - #if defined(__x86_64__) || defined(_M_AMD64) -# define EXTRACT64(X) _mm_cvtsi128_si64(X) - # ifdef __GNUC__ static inline uint64_t __umul128(uint64_t a, uint64_t b, uint64_t* hi) { @@ -88,13 +86,14 @@ static inline uint64_t __umul128(uint64_t a, uint64_t b, uint64_t* hi) #define __umul128 _umul128 # endif #elif defined(__i386__) || defined(_M_IX86) -# define HI32(X) \ - _mm_srli_si128((X), 4) - +static inline int64_t _mm_cvtsi128_si64(__m128i a) +{ + return ((uint64_t)(uint32_t)_mm_cvtsi128_si32(a) | ((uint64_t)(uint32_t)_mm_cvtsi128_si32(_mm_srli_si128(a, 4)) << 32)); +} -# define EXTRACT64(X) \ - ((uint64_t)(uint32_t)_mm_cvtsi128_si32(X) | \ - ((uint64_t)(uint32_t)_mm_cvtsi128_si32(HI32(X)) << 32)) +static inline __m128i _mm_cvtsi64_si128(int64_t a) { + return _mm_set_epi64x(0, a); +} static inline uint64_t __umul128(uint64_t multiplier, uint64_t multiplicand, uint64_t *product_hi) { // multiplier = ab = a * 2^32 + b @@ -418,11 +417,11 @@ static inline __m128i int_sqrt_v2(const uint64_t n0) r >>= 19; uint64_t x2 = (s - (1022ULL << 32)) * (r - s - (1022ULL << 32) + 1); -#if defined _MSC_VER || (__GNUC__ >= 7) +# if (defined _MSC_VER || (__GNUC__ >= 7)) && (defined(__x86_64__) || defined(_M_AMD64)) _addcarry_u64(_subborrow_u64(0, x2, n0, (unsigned long long int*)&x2), r, 0, (unsigned long long int*)&r); -#else +# else if (x2 < n0) ++r; -#endif +# endif return _mm_cvtsi64_si128(r); } @@ -436,10 +435,10 @@ static inline void cryptonight_monero_tweak(uint64_t* mem_out, const uint8_t* l, _mm_store_si128((__m128i *)mem_out, _mm_xor_si128(bx0, cx)); } else { __m128i tmp = _mm_xor_si128(bx0, cx); - mem_out[0] = EXTRACT64(tmp); + mem_out[0] = _mm_cvtsi128_si64(tmp); tmp = _mm_castps_si128(_mm_movehl_ps(_mm_castsi128_ps(tmp), _mm_castsi128_ps(tmp))); - uint64_t vh = EXTRACT64(tmp); + uint64_t vh = _mm_cvtsi128_si64(tmp); uint8_t x = static_cast(vh >> 24); static const uint16_t table = 0x7531; @@ -505,7 +504,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si _mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); } - idx0 = EXTRACT64(cx); + idx0 = _mm_cvtsi128_si64(cx); uint64_t hi, lo, cl, ch; cl = ((uint64_t*) &l0[idx0 & MASK])[0]; @@ -635,8 +634,8 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si _mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx10, cx1)); } - idx0 = EXTRACT64(cx0); - idx1 = EXTRACT64(cx1); + idx0 = _mm_cvtsi128_si64(cx0); + idx1 = _mm_cvtsi128_si64(cx1); uint64_t hi, lo, cl, ch; cl = ((uint64_t*) &l0[idx0 & MASK])[0]; @@ -763,7 +762,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si #define CN_STEP3(part, a, b0, b1, c, l, ptr, idx) \ - idx = EXTRACT64(c); \ + idx = _mm_cvtsi128_si64(c); \ ptr = reinterpret_cast<__m128i*>(&l[idx & MASK]); \ uint64_t cl##part = ((uint64_t*)ptr)[0]; \ uint64_t ch##part = ((uint64_t*)ptr)[1]; @@ -791,7 +790,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si } \ \ a = _mm_xor_si128(a, _mm_set_epi64x(ch##part, cl##part)); \ - idx = EXTRACT64(a); \ + idx = _mm_cvtsi128_si64(a); \ \ if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { \ int64_t n = ((int64_t*)&l[idx & MASK])[0]; \ @@ -859,9 +858,9 @@ inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t si VARIANT2_SET_ROUNDING_MODE(); uint64_t idx0, idx1, idx2; - idx0 = EXTRACT64(ax0); - idx1 = EXTRACT64(ax1); - idx2 = EXTRACT64(ax2); + idx0 = _mm_cvtsi128_si64(ax0); + idx1 = _mm_cvtsi128_si64(ax1); + idx2 = _mm_cvtsi128_si64(ax2); for (size_t i = 0; i < ITERATIONS; i++) { uint64_t hi, lo; @@ -926,10 +925,10 @@ inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size VARIANT2_SET_ROUNDING_MODE(); uint64_t idx0, idx1, idx2, idx3; - idx0 = EXTRACT64(ax0); - idx1 = EXTRACT64(ax1); - idx2 = EXTRACT64(ax2); - idx3 = EXTRACT64(ax3); + idx0 = _mm_cvtsi128_si64(ax0); + idx1 = _mm_cvtsi128_si64(ax1); + idx2 = _mm_cvtsi128_si64(ax2); + idx3 = _mm_cvtsi128_si64(ax3); for (size_t i = 0; i < ITERATIONS; i++) { @@ -1002,11 +1001,11 @@ inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t siz VARIANT2_SET_ROUNDING_MODE(); uint64_t idx0, idx1, idx2, idx3, idx4; - idx0 = EXTRACT64(ax0); - idx1 = EXTRACT64(ax1); - idx2 = EXTRACT64(ax2); - idx3 = EXTRACT64(ax3); - idx4 = EXTRACT64(ax4); + idx0 = _mm_cvtsi128_si64(ax0); + idx1 = _mm_cvtsi128_si64(ax1); + idx2 = _mm_cvtsi128_si64(ax2); + idx3 = _mm_cvtsi128_si64(ax3); + idx4 = _mm_cvtsi128_si64(ax4); for (size_t i = 0; i < ITERATIONS; i++) { @@ -1045,4 +1044,4 @@ inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t siz } } -#endif /* __CRYPTONIGHT_X86_H__ */ +#endif /* XMRIG_CRYPTONIGHT_X86_H */ From 8081f5b7119e1bc873e5c8def7803ffd64e64c18 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 31 Aug 2018 23:32:33 +0300 Subject: [PATCH 049/102] Fix invalid hashes with gcc 7.1. --- src/crypto/CryptoNight_x86.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index a0b676a538..7145252456 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -417,7 +417,7 @@ static inline __m128i int_sqrt_v2(const uint64_t n0) r >>= 19; uint64_t x2 = (s - (1022ULL << 32)) * (r - s - (1022ULL << 32) + 1); -# if (defined _MSC_VER || (__GNUC__ >= 7)) && (defined(__x86_64__) || defined(_M_AMD64)) +# if (defined(_MSC_VER) || __GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ > 1)) && (defined(__x86_64__) || defined(_M_AMD64)) _addcarry_u64(_subborrow_u64(0, x2, n0, (unsigned long long int*)&x2), r, 0, (unsigned long long int*)&r); # else if (x2 < n0) ++r; From 8ae4429a0c46b7207bfd176366d75e8033426372 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 31 Aug 2018 23:55:50 +0300 Subject: [PATCH 050/102] Fixed numeric variant 2 in config file. --- src/common/crypto/Algorithm.cpp | 21 ++++++++++++++++----- src/common/crypto/Algorithm.h | 5 +++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index 05c890dc73..a3cf48b2de 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett + * Copyright 2018 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -176,11 +177,21 @@ void xmrig::Algorithm::parseVariant(const char *variant) void xmrig::Algorithm::parseVariant(int variant) { - if (variant >= VARIANT_AUTO && variant < VARIANT_MAX) { - m_variant = static_cast(variant); - } - else { - assert(false); + assert(variant >= -1 && variant <= 2); + + switch (variant) { + case -1: + case 0: + case 1: + m_variant = static_cast(variant); + break; + + case 2: + m_variant = VARIANT_2; + break; + + default: + break; } } diff --git a/src/common/crypto/Algorithm.h b/src/common/crypto/Algorithm.h index bcf029d8ff..731fa79373 100644 --- a/src/common/crypto/Algorithm.h +++ b/src/common/crypto/Algorithm.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett + * Copyright 2018 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -22,8 +23,8 @@ * along with this program. If not, see . */ -#ifndef __ALGORITHM_H__ -#define __ALGORITHM_H__ +#ifndef XMRIG_ALGORITHM_H +#define XMRIG_ALGORITHM_H #include From 9b99b439b9cc583bb6fb39f4da79707c304bcdc9 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 1 Sep 2018 00:00:38 +0300 Subject: [PATCH 051/102] Small fixes. --- src/crypto/CryptoNight_arm.h | 18 ++++++++---------- src/crypto/CryptoNight_x86.h | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 1df4ec5d65..3ede8111d7 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -7,6 +7,7 @@ * Copyright 2016 Imran Yusuff * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett + * Copyright 2018 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -23,8 +24,8 @@ * along with this program. If not, see . */ -#ifndef __CRYPTONIGHT_ARM_H__ -#define __CRYPTONIGHT_ARM_H__ +#ifndef XMRIG_CRYPTONIGHT_ARM_H +#define XMRIG_CRYPTONIGHT_ARM_H #include "common/crypto/keccak.h" @@ -95,9 +96,6 @@ static inline __attribute__((always_inline)) uint64_t _mm_cvtsi128_si64(__m128i } -#define EXTRACT64(X) _mm_cvtsi128_si64(X) - - #if defined (__arm64__) || defined (__aarch64__) static inline uint64_t __umul128(uint64_t a, uint64_t b, uint64_t* hi) { @@ -404,7 +402,7 @@ static inline __m128i aes_round_tweak_div(const __m128i &in, const __m128i &key) } -template +template static inline void cryptonight_monero_tweak(const uint8_t* l, uint64_t idx, __m128i ax0, __m128i bx0, __m128i bx1, __m128i cx) { uint64_t* mem_out = (uint64_t*)&l[idx]; @@ -414,7 +412,7 @@ static inline void cryptonight_monero_tweak(const uint8_t* l, uint64_t idx, __m1 _mm_store_si128((__m128i *)mem_out, _mm_xor_si128(bx0, cx)); } else { __m128i tmp = _mm_xor_si128(bx0, cx); - mem_out[0] = EXTRACT64(tmp); + mem_out[0] = _mm_cvtsi128_si64(tmp); uint64_t vh = vgetq_lane_u64(tmp, 1); @@ -481,7 +479,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si _mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); } - idx0 = EXTRACT64(cx); + idx0 = _mm_cvtsi128_si64(cx); uint64_t hi, lo, cl, ch; cl = ((uint64_t*) &l0[idx0 & MASK])[0]; @@ -612,8 +610,8 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si _mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx10, cx1)); } - idx0 = EXTRACT64(cx0); - idx1 = EXTRACT64(cx1); + idx0 = _mm_cvtsi128_si64(cx0); + idx1 = _mm_cvtsi128_si64(cx1); uint64_t hi, lo, cl, ch; cl = ((uint64_t*) &l0[idx0 & MASK])[0]; diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 7145252456..bbed8c3831 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -427,7 +427,7 @@ static inline __m128i int_sqrt_v2(const uint64_t n0) } -template +template static inline void cryptonight_monero_tweak(uint64_t* mem_out, const uint8_t* l, uint64_t idx, __m128i ax0, __m128i bx0, __m128i bx1, __m128i cx) { if (VARIANT == xmrig::VARIANT_2) { From 6f7b706927dd5f10b6410f945ede46af5e993ec1 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 1 Sep 2018 00:31:31 +0300 Subject: [PATCH 052/102] Fixed automatic variant. --- src/common/net/Job.cpp | 14 ++------------ src/common/net/Job.h | 7 ++++--- src/common/net/Pool.cpp | 3 ++- src/common/net/Pool.h | 7 ++++--- src/net/Network.cpp | 5 ++++- src/workers/MultiWorker.cpp | 1 + src/workers/MultiWorker.h | 7 ++++--- 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index e9f81e02ef..3d2d88ad32 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett + * Copyright 2018 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -165,24 +166,13 @@ bool Job::setTarget(const char *target) xmrig::Variant Job::variant() const { - if (m_algorithm.variant() == xmrig::VARIANT_XTL && m_blob[0] < 4) { - return xmrig::VARIANT_1; - } - - if (m_algorithm.variant() == xmrig::VARIANT_MSR && m_blob[0] < 7) { - return xmrig::VARIANT_1; - } - - if (m_algorithm.variant() == xmrig::VARIANT_XHV && m_blob[0] < 3) { - return xmrig::VARIANT_0; - } - if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { if (m_algorithm.algo() == xmrig::CRYPTONIGHT_HEAVY) { return xmrig::VARIANT_0; } else if (m_algorithm.algo() == xmrig::CRYPTONIGHT_LITE) { return xmrig::VARIANT_1; } + return (m_blob[0] >= 8) ? xmrig::VARIANT_2 : xmrig::VARIANT_1; } diff --git a/src/common/net/Job.h b/src/common/net/Job.h index 049eb7d4d9..7ea539a228 100644 --- a/src/common/net/Job.h +++ b/src/common/net/Job.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett + * Copyright 2018 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -22,8 +23,8 @@ * along with this program. If not, see . */ -#ifndef __JOB_H__ -#define __JOB_H__ +#ifndef XMRIG_JOB_H +#define XMRIG_JOB_H #include @@ -100,4 +101,4 @@ class Job # endif }; -#endif /* __JOB_H__ */ +#endif /* XMRIG_JOB_H */ diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 357cb330b1..49f4e54c7b 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -360,7 +361,7 @@ void Pool::adjustVariant(const xmrig::Variant variantHint) if (m_algorithm.algo() == CRYPTONIGHT_HEAVY) { m_algorithm.setVariant(VARIANT_0); } - else { + else if (m_algorithm.algo() == CRYPTONIGHT_LITE) { m_algorithm.setVariant(VARIANT_1); } # endif diff --git a/src/common/net/Pool.h b/src/common/net/Pool.h index 57a30d1e23..0641b851df 100644 --- a/src/common/net/Pool.h +++ b/src/common/net/Pool.h @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -21,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __POOL_H__ -#define __POOL_H__ +#ifndef XMRIG_POOL_H +#define XMRIG_POOL_H #include @@ -105,4 +106,4 @@ class Pool typedef std::vector Pools; -#endif /* __POOL_H__ */ +#endif /* XMRIG_POOL_H */ diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 7293a0ac90..cc979635bb 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -166,9 +166,12 @@ bool Network::isColors() const void Network::setJob(Client *client, const Job &job, bool donate) { + xmrig::Algorithm algorithm = job.algorithm(); + algorithm.setVariant(job.variant()); + LOG_INFO(isColors() ? MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%d") " algo " WHITE_BOLD("%s") : "new job from %s:%d diff %d algo %s", - client->host(), client->port(), job.diff(), job.algorithm().shortName()); + client->host(), client->port(), job.diff(), algorithm.shortName()); m_state.diff = job.diff(); Workers::setJob(job, donate); diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 475f99beed..1916b205c9 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett + * Copyright 2018 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index d4a6910e72..c08e4fbe61 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -6,6 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett + * Copyright 2018 SChernykh * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -22,8 +23,8 @@ * along with this program. If not, see . */ -#ifndef __MULTIWORKER_H__ -#define __MULTIWORKER_H__ +#ifndef XMRIG_MULTIWORKER_H +#define XMRIG_MULTIWORKER_H #include "common/net/Job.h" @@ -71,4 +72,4 @@ class MultiWorker : public Worker }; -#endif /* __MULTIWORKER_H__ */ +#endif /* XMRIG_MULTIWORKER_H */ From 2e00a909927cd881b4a22db5267b779dd79ba483 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 3 Sep 2018 01:26:19 +0300 Subject: [PATCH 053/102] Add WITH_DEBUG_LOG CMake option. --- CMakeLists.txt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07397ac48b..62ec419ed9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 2.8) project(xmrig) -option(WITH_LIBCPUID "Use Libcpuid" ON) -option(WITH_AEON "CryptoNight-Lite support" ON) -option(WITH_SUMO "CryptoNight-Heavy support" ON) -option(WITH_HTTPD "HTTP REST API" ON) -option(BUILD_STATIC "Build static binary" OFF) +option(WITH_LIBCPUID "Use Libcpuid" ON) +option(WITH_AEON "CryptoNight-Lite support" ON) +option(WITH_SUMO "CryptoNight-Heavy support" ON) +option(WITH_HTTPD "HTTP REST API" ON) +option(WITH_DEBUG_LOG "Enable debug log output" OFF) +option(BUILD_STATIC "Build static binary" OFF) include (CheckIncludeFile) include (cmake/cpu.cmake) @@ -170,7 +171,6 @@ endif() add_definitions(/D__STDC_FORMAT_MACROS) add_definitions(/DUNICODE) -#add_definitions(/DAPP_DEBUG) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") @@ -246,5 +246,9 @@ if (BUILD_STATIC) set(CMAKE_EXE_LINKER_FLAGS " -static") endif() +if (WITH_DEBUG_LOG) + add_definitions(/DAPP_DEBUG) +endif() + add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES}) target_link_libraries(${PROJECT_NAME} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) From bef0889cd621be67deb27a5918ab843b18e9f96d Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 3 Sep 2018 15:39:55 +0300 Subject: [PATCH 054/102] Rewrite automatic variant handling. --- src/common/net/Client.cpp | 6 ++--- src/common/net/Job.cpp | 46 +++++++++++++++++++++++-------------- src/common/net/Job.h | 10 +++++--- src/net/Network.cpp | 5 +--- src/workers/MultiWorker.cpp | 2 +- 5 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index f4553d9733..2a9db44456 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -270,17 +270,17 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) } if (params.HasMember("algo")) { - job.algorithm().parseAlgorithm(params["algo"].GetString()); + job.setAlgorithm(params["algo"].GetString()); } if (params.HasMember("variant")) { const rapidjson::Value &variant = params["variant"]; if (variant.IsInt()) { - job.algorithm().parseVariant(variant.GetInt()); + job.setVariant(variant.GetInt()); } else if (variant.IsString()){ - job.algorithm().parseVariant(variant.GetString()); + job.setVariant(variant.GetString()); } } diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index 3d2d88ad32..bb5f6a12cd 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -59,6 +59,7 @@ static inline char hf_bin2hex(unsigned char c) Job::Job() : + m_autoVariant(false), m_nicehash(false), m_poolId(-2), m_threadId(-1), @@ -70,7 +71,8 @@ Job::Job() : } -Job::Job(int poolId, bool nicehash, xmrig::Algorithm algorithm, const xmrig::Id &clientId) : +Job::Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId) : + m_autoVariant(algorithm.variant() == xmrig::VARIANT_AUTO), m_nicehash(nicehash), m_poolId(poolId), m_threadId(-1), @@ -113,6 +115,10 @@ bool Job::setBlob(const char *blob) m_nicehash = true; } + if (m_autoVariant) { + m_algorithm.setVariant(variant()); + } + # ifdef XMRIG_PROXY_PROJECT memset(m_rawBlob, 0, sizeof(m_rawBlob)); memcpy(m_rawBlob, blob, m_size * 2); @@ -164,22 +170,6 @@ bool Job::setTarget(const char *target) } -xmrig::Variant Job::variant() const -{ - if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { - if (m_algorithm.algo() == xmrig::CRYPTONIGHT_HEAVY) { - return xmrig::VARIANT_0; - } else if (m_algorithm.algo() == xmrig::CRYPTONIGHT_LITE) { - return xmrig::VARIANT_1; - } - - return (m_blob[0] >= 8) ? xmrig::VARIANT_2 : xmrig::VARIANT_1; - } - - return m_algorithm.variant(); -} - - bool Job::fromHex(const char* in, unsigned int len, unsigned char* out) { bool error = false; @@ -224,3 +214,25 @@ bool Job::operator!=(const Job &other) const { return m_id != other.m_id || memcmp(m_blob, other.m_blob, sizeof(m_blob)) != 0; } + + +xmrig::Variant Job::variant() const +{ + using namespace xmrig; + + switch (m_algorithm.algo()) { + case CRYPTONIGHT: + return (m_blob[0] >= 8) ? VARIANT_2 : VARIANT_1; + + case CRYPTONIGHT_LITE: + return VARIANT_1; + + case CRYPTONIGHT_HEAVY: + return VARIANT_0; + + default: + break; + } + + return m_algorithm.variant(); +} diff --git a/src/common/net/Job.h b/src/common/net/Job.h index 7ea539a228..8bd1b8adc7 100644 --- a/src/common/net/Job.h +++ b/src/common/net/Job.h @@ -39,12 +39,11 @@ class Job { public: Job(); - Job(int poolId, bool nicehash, xmrig::Algorithm algorithm, const xmrig::Id &clientId); + Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId); ~Job(); bool setBlob(const char *blob); bool setTarget(const char *target); - xmrig::Variant variant() const; inline bool isNicehash() const { return m_nicehash; } inline bool isValid() const { return m_size > 0 && m_diff > 0; } @@ -61,10 +60,12 @@ class Job inline uint32_t diff() const { return static_cast(m_diff); } inline uint64_t target() const { return m_target; } inline void reset() { m_size = 0; m_diff = 0; } + inline void setAlgorithm(const char *algo) { m_algorithm.parseAlgorithm(algo); } inline void setClientId(const xmrig::Id &id) { m_clientId = id; } inline void setPoolId(int poolId) { m_poolId = poolId; } inline void setThreadId(int threadId) { m_threadId = threadId; } - inline xmrig::Algorithm &algorithm() { return m_algorithm; } + inline void setVariant(const char *variant) { m_algorithm.parseVariant(variant); } + inline void setVariant(int variant) { m_algorithm.parseVariant(variant); } # ifdef XMRIG_PROXY_PROJECT inline char *rawBlob() { return m_rawBlob; } @@ -84,6 +85,9 @@ class Job bool operator!=(const Job &other) const; private: + xmrig::Variant variant() const; + + bool m_autoVariant; bool m_nicehash; int m_poolId; int m_threadId; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index cc979635bb..7293a0ac90 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -166,12 +166,9 @@ bool Network::isColors() const void Network::setJob(Client *client, const Job &job, bool donate) { - xmrig::Algorithm algorithm = job.algorithm(); - algorithm.setVariant(job.variant()); - LOG_INFO(isColors() ? MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%d") " algo " WHITE_BOLD("%s") : "new job from %s:%d diff %d algo %s", - client->host(), client->port(), job.diff(), algorithm.shortName()); + client->host(), client->port(), job.diff(), job.algorithm().shortName()); m_state.diff = job.diff(); Workers::setJob(job, donate); diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 1916b205c9..a6dbc73ac3 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -104,7 +104,7 @@ void MultiWorker::start() storeStats(); } - m_thread->fn(m_state.job.variant())(m_state.blob, m_state.job.size(), m_hash, m_ctx); + m_thread->fn(m_state.job.algorithm().variant())(m_state.blob, m_state.job.size(), m_hash, m_ctx); for (size_t i = 0; i < N; ++i) { if (*reinterpret_cast(m_hash + (i * 32) + 24) < m_state.job.target()) { From f2668ce64f5593279de3501ec992a0c7f5496485 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 10 Sep 2018 18:35:12 +0300 Subject: [PATCH 055/102] "xmrig::cn_uses_variant1" replaced to "xmrig::cn_base_variant". --- src/crypto/CryptoNight_arm.h | 4 ++-- src/crypto/CryptoNight_constants.h | 20 ++++++++++---------- src/crypto/CryptoNight_x86.h | 10 +++++----- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 3ede8111d7..4cd5eba55c 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -432,7 +432,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_V1 = xmrig::cn_uses_variant1(); + constexpr bool IS_V1 = xmrig::cn_base_variant() == xmrig::VARIANT_1; if (IS_V1 && size < 43) { memset(output, 0, 32); @@ -544,7 +544,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_V1 = xmrig::cn_uses_variant1(); + constexpr bool IS_V1 = xmrig::cn_base_variant() == xmrig::VARIANT_1; if (IS_V1 && size < 43) { memset(output, 0, 64); diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 97a77bbdb5..f13891a768 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -151,16 +151,16 @@ inline uint32_t cn_select_iter(Algo algorithm, Variant variant) } -template inline constexpr bool cn_uses_variant1() { return false; } -template<> inline constexpr bool cn_uses_variant1() { return false; } -template<> inline constexpr bool cn_uses_variant1() { return true; } -template<> inline constexpr bool cn_uses_variant1() { return true; } -template<> inline constexpr bool cn_uses_variant1() { return true; } -template<> inline constexpr bool cn_uses_variant1() { return true; } -template<> inline constexpr bool cn_uses_variant1() { return false; } -template<> inline constexpr bool cn_uses_variant1() { return false; } -template<> inline constexpr bool cn_uses_variant1() { return true; } -template<> inline constexpr bool cn_uses_variant1() { return false; } +template inline constexpr Variant cn_base_variant() { return VARIANT_0; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_0; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_0; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_0; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_1; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } } /* namespace xmrig */ diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index bbed8c3831..be8792287d 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -456,7 +456,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_V1 = xmrig::cn_uses_variant1(); + constexpr bool IS_V1 = xmrig::cn_base_variant() == xmrig::VARIANT_1; if (IS_V1 && size < 43) { memset(output, 0, 32); @@ -567,7 +567,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_V1 = xmrig::cn_uses_variant1(); + constexpr bool IS_V1 = xmrig::cn_base_variant() == xmrig::VARIANT_1; if (IS_V1 && size < 43) { memset(output, 0, 64); @@ -833,7 +833,7 @@ inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t si constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_V1 = xmrig::cn_uses_variant1(); + constexpr bool IS_V1 = xmrig::cn_base_variant() == xmrig::VARIANT_1; if (IS_V1 && size < 43) { memset(output, 0, 32 * 3); @@ -897,7 +897,7 @@ inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_V1 = xmrig::cn_uses_variant1(); + constexpr bool IS_V1 = xmrig::cn_base_variant() == xmrig::VARIANT_1;; if (IS_V1 && size < 43) { memset(output, 0, 32 * 4); @@ -970,7 +970,7 @@ inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t siz constexpr size_t MASK = xmrig::cn_select_mask(); constexpr size_t ITERATIONS = xmrig::cn_select_iter(); constexpr size_t MEM = xmrig::cn_select_memory(); - constexpr bool IS_V1 = xmrig::cn_uses_variant1(); + constexpr bool IS_V1 = xmrig::cn_base_variant() == xmrig::VARIANT_1; if (IS_V1 && size < 43) { memset(output, 0, 32 * 5); From 4f4a11db67e13db9346ae3ddbbc0dadd7800e025 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 13 Sep 2018 11:20:10 +0300 Subject: [PATCH 056/102] v2.8.0-dev --- src/version.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/version.h b/src/version.h index 91a144e781..2a1720eac1 100644 --- a/src/version.h +++ b/src/version.h @@ -21,21 +21,21 @@ * along with this program. If not, see . */ -#ifndef __VERSION_H__ -#define __VERSION_H__ +#ifndef XMRIG_VERSION_H +#define XMRIG_VERSION_H #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "2.6.5-dev" +#define APP_VERSION "2.8.0-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com" #define APP_KIND "cpu" #define APP_VER_MAJOR 2 -#define APP_VER_MINOR 6 -#define APP_VER_PATCH 5 +#define APP_VER_MINOR 8 +#define APP_VER_PATCH 0 #ifdef _MSC_VER # if (_MSC_VER >= 1910) @@ -53,4 +53,4 @@ # endif #endif -#endif /* __VERSION_H__ */ +#endif /* XMRIG_VERSION_H */ From 10d1624b69e9d54781ef3920bfc4d078dfc7bafd Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 14 Sep 2018 21:42:42 +0300 Subject: [PATCH 057/102] Suppress rapidjson warnings on gcc 8 --- cmake/flags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 498f2165b4..8bc1480429 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -15,7 +15,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES GNU) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-strict-aliasing") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions -fno-rtti") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions -fno-rtti -Wno-class-memaccess") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -s") if (XMRIG_ARMv8) From 1502c77ac885167841d5a494d02a94720434fb23 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 14 Sep 2018 22:04:52 +0300 Subject: [PATCH 058/102] Fix compile error on macOS. --- src/crypto/CryptoNight_monero.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index 0ceb93fecd..80750c6c3e 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -68,7 +68,7 @@ #ifdef _MSC_VER # define VARIANT2_SET_ROUNDING_MODE() if (VARIANT == xmrig::VARIANT_2) { _control87(RC_DOWN, MCW_RC); } #else -# define VARIANT2_SET_ROUNDING_MODE() if (VARIANT == xmrig::VARIANT_2) { std::fesetround(FE_DOWNWARD); } +# define VARIANT2_SET_ROUNDING_MODE() if (VARIANT == xmrig::VARIANT_2) { fesetround(FE_DOWNWARD); } #endif # define VARIANT2_INTEGER_MATH(part, cl, cx) \ From 413aab245a8ada469314ac534ae3ab0afba09622 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 15 Sep 2018 16:48:57 +0300 Subject: [PATCH 059/102] Added debug thread log. --- src/Summary.cpp | 2 ++ src/common/interfaces/IConfig.h | 18 +++++++++++------- src/interfaces/IThread.h | 10 +++++++--- src/workers/CpuThread.cpp | 12 ++++++++++++ src/workers/CpuThread.h | 10 +++++++--- src/workers/Workers.cpp | 8 ++++++++ 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/Summary.cpp b/src/Summary.cpp index fe538fda60..76842d5b1c 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -134,9 +134,11 @@ static void print_pools(xmrig::Config *config) } # ifdef APP_DEBUG + LOG_NOTICE("POOLS --------------------------------------------------------------------"); for (const Pool &pool : pools) { pool.print(); } + LOG_NOTICE("--------------------------------------------------------------------------"); # endif } diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index fb622e37cb..95a4babf7b 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -80,13 +80,17 @@ class IConfig HardwareAESKey = 1011, // xmrig amd - OclPlatform = 1400, - OclAffinity = 1401, - OclDevices = 1402, - OclLaunch = 1403, - OclCache = 1404, - OclPrint = 1405, - OclLoader = 1406, + OclPlatformKey = 1400, + OclAffinityKey = 1401, + OclDevicesKey = 1402, + OclLaunchKey = 1403, + OclCacheKey = 1404, + OclPrintKey = 1405, + OclLoaderKey = 1406, + OclSridedIndexKey = 1407, + OclMemChunkKey = 1408, + OclUnrollKey = 1409, + OclCompModeKey = 1410, // xmrig-proxy AccessLogFileKey = 'A', diff --git a/src/interfaces/IThread.h b/src/interfaces/IThread.h index 2e9e3c3989..3a8708e634 100644 --- a/src/interfaces/IThread.h +++ b/src/interfaces/IThread.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef __ITHREAD_H__ -#define __ITHREAD_H__ +#ifndef XMRIG_ITHREAD_H +#define XMRIG_ITHREAD_H #include @@ -64,10 +64,14 @@ class IThread # ifndef XMRIG_NO_API virtual rapidjson::Value toAPI(rapidjson::Document &doc) const = 0; # endif + +# ifdef APP_DEBUG + virtual void print() const = 0; +# endif }; } /* namespace xmrig */ -#endif // __ITHREAD_H__ +#endif // XMRIG_ITHREAD_H diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index bdf09af4b5..ca7681f065 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -24,6 +24,7 @@ #include +#include "common/log/Log.h" #include "common/net/Pool.h" #include "rapidjson/document.h" #include "workers/CpuThread.h" @@ -361,6 +362,17 @@ xmrig::IThread::Multiway xmrig::CpuThread::multiway(AlgoVariant av) } +#ifdef APP_DEBUG +void xmrig::CpuThread::print() const +{ + LOG_DEBUG(GREEN_BOLD("CPU thread: ") " index " WHITE_BOLD("%zu") ", multiway " WHITE_BOLD("%d") ", av " WHITE_BOLD("%d") ",", + index(), static_cast(multiway()), static_cast(m_av)); + + LOG_DEBUG(" affine_to_cpu: %" PRId64, affinity()); +} +#endif + + #ifndef XMRIG_NO_API rapidjson::Value xmrig::CpuThread::toAPI(rapidjson::Document &doc) const { diff --git a/src/workers/CpuThread.h b/src/workers/CpuThread.h index 0e364764cd..622dc3a259 100644 --- a/src/workers/CpuThread.h +++ b/src/workers/CpuThread.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __CPUTHREAD_H__ -#define __CPUTHREAD_H__ +#ifndef XMRIG_CPUTHREAD_H +#define XMRIG_CPUTHREAD_H #include "common/xmrig.h" @@ -80,6 +80,10 @@ class CpuThread : public IThread inline Type type() const override { return CPU; } protected: +# ifdef APP_DEBUG + void print() const override; +# endif + # ifndef XMRIG_NO_API rapidjson::Value toAPI(rapidjson::Document &doc) const override; # endif @@ -101,4 +105,4 @@ class CpuThread : public IThread } /* namespace xmrig */ -#endif /* __CPUTHREAD_H__ */ +#endif /* XMRIG_CPUTHREAD_H */ diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 0e75e73614..5deb14f766 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -160,6 +160,14 @@ void Workers::setJob(const Job &job, bool donate) void Workers::start(xmrig::Controller *controller) { +# ifdef APP_DEBUG + LOG_NOTICE("THREADS ------------------------------------------------------------------"); + for (const xmrig::IThread *thread : controller->config()->threads()) { + thread->print(); + } + LOG_NOTICE("--------------------------------------------------------------------------"); +# endif + m_controller = controller; const std::vector &threads = controller->config()->threads(); From 552e10eb630a937e7269c1af163e599b0331050f Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 16 Sep 2018 03:06:54 +0300 Subject: [PATCH 060/102] Initial TLS support. --- CMakeLists.txt | 8 +- cmake/OpenSSL.cmake | 18 +++ src/common/Platform.cpp | 26 +++++ src/common/Platform.h | 8 +- src/common/Platform_mac.cpp | 13 +-- src/common/Platform_unix.cpp | 14 +-- src/common/Platform_win.cpp | 13 +-- src/common/config/CommonConfig.cpp | 9 ++ src/common/interfaces/IConfig.h | 20 ++-- src/common/net/Client.cpp | 174 ++++++++++++++++++++++++----- src/common/net/Client.h | 29 ++++- src/common/net/Pool.cpp | 16 ++- src/common/net/Pool.h | 51 +++++---- src/common/net/Tls.cpp | 136 ++++++++++++++++++++++ src/common/net/Tls.h | 58 ++++++++++ src/core/ConfigLoader_platform.h | 22 ++-- 16 files changed, 494 insertions(+), 121 deletions(-) create mode 100644 cmake/OpenSSL.cmake create mode 100644 src/common/net/Tls.cpp create mode 100644 src/common/net/Tls.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 62ec419ed9..8d38b1a042 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ option(WITH_AEON "CryptoNight-Lite support" ON) option(WITH_SUMO "CryptoNight-Heavy support" ON) option(WITH_HTTPD "HTTP REST API" ON) option(WITH_DEBUG_LOG "Enable debug log output" OFF) +option(WITH_TLS "Enable OpenSSL support" OFF) option(BUILD_STATIC "Build static binary" OFF) include (CheckIncludeFile) @@ -194,6 +195,8 @@ else() endif() endif() +include(cmake/OpenSSL.cmake) + CHECK_INCLUDE_FILE (syslog.h HAVE_SYSLOG_H) if (HAVE_SYSLOG_H) add_definitions(/DHAVE_SYSLOG_H) @@ -233,6 +236,7 @@ if (WITH_HTTPD) message(FATAL_ERROR "microhttpd NOT found: use `-DWITH_HTTPD=OFF` to build without http deamon support") endif() else() + set(HTTPD_SOURCES "") set(MHD_LIBRARY "") add_definitions(/DXMRIG_NO_HTTPD) add_definitions(/DXMRIG_NO_API) @@ -250,5 +254,5 @@ if (WITH_DEBUG_LOG) add_definitions(/DAPP_DEBUG) endif() -add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES}) -target_link_libraries(${PROJECT_NAME} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) +add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES} ${TLS_SOURCES}) +target_link_libraries(${PROJECT_NAME} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) diff --git a/cmake/OpenSSL.cmake b/cmake/OpenSSL.cmake new file mode 100644 index 0000000000..154a827894 --- /dev/null +++ b/cmake/OpenSSL.cmake @@ -0,0 +1,18 @@ +if (WITH_TLS) + set(OPENSSL_ROOT_DIR ${XMRIG_DEPS}) + set(OPENSSL_USE_STATIC_LIBS TRUE) + set(OPENSSL_MSVC_STATIC_RT TRUE) + + find_package(OpenSSL) + + if (OPENSSL_FOUND) + set(TLS_SOURCES src/common/net/Tls.h src/common/net/Tls.cpp) + include_directories(${OPENSSL_INCLUDE_DIR}) + else() + message(FATAL_ERROR "OpenSSL NOT found: use `-DWITH_TLS=OFF` to build without TLS support") + endif() +else() + set(TLS_SOURCES "") + set(OPENSSL_LIBRARIES "") + add_definitions(/DXMRIG_NO_TLS) +endif() diff --git a/src/common/Platform.cpp b/src/common/Platform.cpp index 52b55987f9..a95f78e7e0 100644 --- a/src/common/Platform.cpp +++ b/src/common/Platform.cpp @@ -26,6 +26,12 @@ #include +#ifndef XMRIG_NO_TLS +# include +# include +#endif + + #include "Platform.h" @@ -61,3 +67,23 @@ const char *Platform::defaultConfigName() *m_defaultConfigName = '\0'; return nullptr; } + + +void Platform::init(const char *userAgent) +{ +# ifndef XMRIG_NO_TLS + SSL_library_init(); + SSL_load_error_strings(); + ERR_load_BIO_strings(); + ERR_load_crypto_strings(); + SSL_load_error_strings(); + OpenSSL_add_all_digests(); +# endif + + if (userAgent) { + m_userAgent = userAgent; + } + else { + m_userAgent = createUserAgent(); + } +} diff --git a/src/common/Platform.h b/src/common/Platform.h index 8704604a86..5dfb9ff7f2 100644 --- a/src/common/Platform.h +++ b/src/common/Platform.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __PLATFORM_H__ -#define __PLATFORM_H__ +#ifndef XMRIG_PLATFORM_H +#define XMRIG_PLATFORM_H #include @@ -43,9 +43,11 @@ class Platform static inline const char *userAgent() { return m_userAgent.data(); } private: + static char *createUserAgent(); + static char m_defaultConfigName[520]; static xmrig::c_str m_userAgent; }; -#endif /* __PLATFORM_H__ */ +#endif /* XMRIG_PLATFORM_H */ diff --git a/src/common/Platform_mac.cpp b/src/common/Platform_mac.cpp index b8181cc49c..d0c533b083 100644 --- a/src/common/Platform_mac.cpp +++ b/src/common/Platform_mac.cpp @@ -38,7 +38,7 @@ #endif -static inline char *createUserAgent() +char *Platform::createUserAgent() { const size_t max = 160; @@ -65,17 +65,6 @@ bool Platform::setThreadAffinity(uint64_t cpu_id) } -void Platform::init(const char *userAgent) -{ - if (userAgent) { - m_userAgent = userAgent; - } - else { - m_userAgent = createUserAgent(); - } -} - - void Platform::setProcessPriority(int priority) { diff --git a/src/common/Platform_unix.cpp b/src/common/Platform_unix.cpp index 97b32ee8d5..058920ec56 100644 --- a/src/common/Platform_unix.cpp +++ b/src/common/Platform_unix.cpp @@ -52,7 +52,7 @@ typedef cpuset_t cpu_set_t; #endif -static inline char *createUserAgent() +char *Platform::createUserAgent() { const size_t max = 160; @@ -92,23 +92,11 @@ bool Platform::setThreadAffinity(uint64_t cpu_id) } -void Platform::init(const char *userAgent) -{ - if (userAgent) { - m_userAgent = userAgent; - } - else { - m_userAgent = createUserAgent(); - } -} - - void Platform::setProcessPriority(int priority) { } - void Platform::setThreadPriority(int priority) { if (priority == -1) { diff --git a/src/common/Platform_win.cpp b/src/common/Platform_win.cpp index 47f4186713..32b850d14f 100644 --- a/src/common/Platform_win.cpp +++ b/src/common/Platform_win.cpp @@ -55,7 +55,7 @@ static inline OSVERSIONINFOEX winOsVersion() } -static inline char *createUserAgent() +char *Platform::createUserAgent() { const auto osver = winOsVersion(); const size_t max = 160; @@ -94,17 +94,6 @@ bool Platform::setThreadAffinity(uint64_t cpu_id) } -void Platform::init(const char *userAgent) -{ - if (userAgent) { - m_userAgent = userAgent; - } - else { - m_userAgent = createUserAgent(); - } -} - - void Platform::setProcessPriority(int priority) { if (priority == -1) { diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index ca9017579b..f22a632c13 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -157,6 +157,10 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable) m_pools.back().setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0); break; + case TlsKey: /* --tls */ + m_pools.back().setTLS(enable); + break; + # ifndef XMRIG_PROXY_PROJECT case NicehashKey: /* --nicehash */ m_pools.back().setNicehash(enable); @@ -235,6 +239,10 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg) m_pools.back().setRigId(arg); break; + case FingerprintKey: /* --tls-fingerprint */ + m_pools.back().setFingerprint(arg); + break; + case VariantKey: /* --variant */ m_pools.back().algorithm().parseVariant(arg); break; @@ -269,6 +277,7 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg) case SyslogKey: /* --syslog */ case KeepAliveKey: /* --keepalive */ case NicehashKey: /* --nicehash */ + case TlsKey: /* --tls */ case ApiIPv6Key: /* --api-ipv6 */ case DryRunKey: /* --dry-run */ return parseBoolean(key, true); diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 95a4babf7b..ece8e3b476 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -63,6 +63,8 @@ class IConfig VerboseKey = 1100, VersionKey = 'V', WatchKey = 1105, + TlsKey = 1013, + FingerprintKey = 1014, // xmrig common CPUPriorityKey = 1021, @@ -80,17 +82,13 @@ class IConfig HardwareAESKey = 1011, // xmrig amd - OclPlatformKey = 1400, - OclAffinityKey = 1401, - OclDevicesKey = 1402, - OclLaunchKey = 1403, - OclCacheKey = 1404, - OclPrintKey = 1405, - OclLoaderKey = 1406, - OclSridedIndexKey = 1407, - OclMemChunkKey = 1408, - OclUnrollKey = 1409, - OclCompModeKey = 1410, + OclPlatform = 1400, + OclAffinity = 1401, + OclDevices = 1402, + OclLaunch = 1403, + OclCache = 1404, + OclPrint = 1405, + OclLoader = 1406, // xmrig-proxy AccessLogFileKey = 'A', diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index 2a9db44456..1057c47421 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -29,6 +29,13 @@ #include +#ifndef XMRIG_NO_TLS +# include +# include +# include "common/net/Tls.h" +#endif + + #include "common/interfaces/IClientListener.h" #include "common/log/Log.h" #include "common/net/Client.h" @@ -48,6 +55,17 @@ int64_t Client::m_sequence = 1; xmrig::Storage Client::m_storage; +#ifdef APP_DEBUG +static const char *states[] = { + "unconnected", + "host-lookup", + "connecting", + "connected", + "closing" +}; +#endif + + Client::Client(int id, const char *agent, IClientListener *listener) : m_ipv6(false), m_nicehash(false), @@ -61,6 +79,7 @@ Client::Client(int id, const char *agent, IClientListener *listener) : m_failures(0), m_recvBufPos(0), m_state(UnconnectedState), + m_tls(nullptr), m_expire(0), m_jobs(0), m_keepAlive(0), @@ -92,6 +111,12 @@ Client::~Client() void Client::connect() { +# ifndef XMRIG_NO_TLS + if (m_pool.isTLS()) { + m_tls = new Tls(this); + } +# endif + resolve(m_pool.host()); } @@ -122,6 +147,7 @@ void Client::deleteLater() } + void Client::setPool(const Pool &pool) { if (!pool.isValid()) { @@ -160,6 +186,12 @@ bool Client::disconnect() } +bool Client::isTLS() const +{ + return m_pool.isTLS() && m_tls; +} + + int64_t Client::submit(const JobResult &result) { using namespace rapidjson; @@ -330,6 +362,39 @@ bool Client::parseLogin(const rapidjson::Value &result, int *code) } +bool Client::send(BIO *bio) +{ +# ifndef XMRIG_NO_TLS + uv_buf_t buf; + buf.len = BIO_get_mem_data(bio, &buf.base); + + if (buf.len == 0) { + return true; + } + + LOG_DEBUG("[%s] TLS send (%d bytes)", m_pool.url(), static_cast(buf.len)); + + bool result = false; + if (state() == ConnectedState && uv_is_writable(m_stream)) { + result = uv_try_write(m_stream, &buf, 1) > 0; + + if (!result) { + close(); + } + } + else { + LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", m_pool.url(), m_state); + } + + BIO_reset(bio); + + return result; +# else + return false; +# endif +} + + bool Client::verifyAlgorithm(const xmrig::Algorithm &algorithm) const { # ifdef XMRIG_PROXY_PROJECT @@ -404,16 +469,27 @@ int64_t Client::send(const rapidjson::Document &doc) int64_t Client::send(size_t size) { LOG_DEBUG("[%s] send (%d bytes): \"%s\"", m_pool.url(), size, m_sendBuf); - if (state() != ConnectedState || !uv_is_writable(m_stream)) { - LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", m_pool.url(), m_state); - return -1; + +# ifndef XMRIG_NO_TLS + if (isTLS()) { + if (!m_tls->send(m_sendBuf, size)) { + return -1; + } } + else +# endif + { + if (state() != ConnectedState || !uv_is_writable(m_stream)) { + LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", m_pool.url(), m_state); + return -1; + } - uv_buf_t buf = uv_buf_init(m_sendBuf, (unsigned int) size); + uv_buf_t buf = uv_buf_init(m_sendBuf, (unsigned int) size); - if (uv_try_write(m_stream, &buf, 1) < 0) { - close(); - return -1; + if (uv_try_write(m_stream, &buf, 1) < 0) { + close(); + return -1; + } } m_expire = uv_now(uv_default_loop()) + kResponseTimeout; @@ -463,6 +539,22 @@ void Client::connect(sockaddr *addr) } +void Client::handshake() +{ +# ifndef XMRIG_NO_TLS + if (isTLS()) { + m_expire = uv_now(uv_default_loop()) + kResponseTimeout; + + m_tls->handshake(); + } + else +# endif + { + login(); + } +} + + void Client::login() { using namespace rapidjson; @@ -511,6 +603,13 @@ void Client::onClose() m_socket = nullptr; setState(UnconnectedState); +# ifndef XMRIG_NO_TLS + if (m_tls) { + delete m_tls; + m_tls = nullptr; + } +# endif + reconnect(); } @@ -665,6 +764,35 @@ void Client::ping() } +void Client::read() +{ + char* end; + char* start = m_recvBuf.base; + size_t remaining = m_recvBufPos; + + while ((end = static_cast(memchr(start, '\n', remaining))) != nullptr) { + end++; + size_t len = end - start; + parse(start, len); + + remaining -= len; + start = end; + } + + if (remaining == 0) { + m_recvBufPos = 0; + return; + } + + if (start == m_recvBuf.base) { + return; + } + + memcpy(m_recvBuf.base, start, remaining); + m_recvBufPos = remaining; +} + + void Client::reconnect() { if (!m_listener) { @@ -689,7 +817,7 @@ void Client::reconnect() void Client::setState(SocketState state) { - LOG_DEBUG("[%s] state: %d", m_pool.url(), state); + LOG_DEBUG("[%s] state: \"%s\"", m_pool.url(), states[state]); if (m_state == state) { return; @@ -757,7 +885,7 @@ void Client::onConnect(uv_connect_t *req, int status) uv_read_start(client->m_stream, Client::onAllocBuffer, Client::onRead); delete req; - client->login(); + client->handshake(); } @@ -789,30 +917,18 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) client->m_recvBufPos += nread; - char* end; - char* start = client->m_recvBuf.base; - size_t remaining = client->m_recvBufPos; - - while ((end = static_cast(memchr(start, '\n', remaining))) != nullptr) { - end++; - size_t len = end - start; - client->parse(start, len); +# ifndef XMRIG_NO_TLS + if (client->isTLS()) { + LOG_DEBUG("[%s] TLS received (%d bytes)", client->m_pool.url(), static_cast(nread)); - remaining -= len; - start = end; - } - - if (remaining == 0) { + client->m_tls->read(client->m_recvBuf.base, client->m_recvBufPos); client->m_recvBufPos = 0; - return; } - - if (start == client->m_recvBuf.base) { - return; + else +# endif + { + client->read(); } - - memcpy(client->m_recvBuf.base, start, remaining); - client->m_recvBufPos = remaining; } diff --git a/src/common/net/Client.h b/src/common/net/Client.h index 4be8badba2..893fabfc8f 100644 --- a/src/common/net/Client.h +++ b/src/common/net/Client.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __CLIENT_H__ -#define __CLIENT_H__ +#ifndef XMRIG_CLIENT_H +#define XMRIG_CLIENT_H #include @@ -43,6 +43,9 @@ class IClientListener; class JobResult; +typedef struct bio_st BIO; + + class Client { public: @@ -54,12 +57,19 @@ class Client ClosingState }; - constexpr static int kResponseTimeout = 20 * 1000; + constexpr static int kResponseTimeout = 20 * 1000; + +# ifndef XMRIG_NO_TLS + constexpr static int kInputBufferSize = 1024 * 16; +# else + constexpr static int kInputBufferSize = 1024 * 2; +# endif Client(int id, const char *agent, IClientListener *listener); ~Client(); bool disconnect(); + bool isTLS() const; int64_t submit(const JobResult &result); void connect(); void connect(const Pool &pool); @@ -80,6 +90,9 @@ class Client inline void setRetryPause(int ms) { m_retryPause = ms; } private: + class Tls; + + enum Extensions { NicehashExt = 1, AlgoExt = 2 @@ -89,12 +102,14 @@ class Client bool isCriticalError(const char *message); bool parseJob(const rapidjson::Value ¶ms, int *code); bool parseLogin(const rapidjson::Value &result, int *code); + bool send(BIO *bio); bool verifyAlgorithm(const xmrig::Algorithm &algorithm) const; int resolve(const char *host); int64_t send(const rapidjson::Document &doc); int64_t send(size_t size); void connect(const std::vector &ipv4, const std::vector &ipv6); void connect(sockaddr *addr); + void handshake(); void login(); void onClose(); void parse(char *line, size_t len); @@ -102,6 +117,7 @@ class Client void parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error); void parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error); void ping(); + void read(); void reconnect(); void setState(SocketState state); void startTimeout(); @@ -120,9 +136,9 @@ class Client bool m_ipv6; bool m_nicehash; bool m_quiet; - char m_buf[2048]; + char m_buf[kInputBufferSize]; char m_ip[46]; - char m_sendBuf[768]; + char m_sendBuf[1024]; const char *m_agent; IClientListener *m_listener; int m_extensions; @@ -135,6 +151,7 @@ class Client size_t m_recvBufPos; SocketState m_state; std::map m_results; + Tls *m_tls; uint64_t m_expire; uint64_t m_jobs; uint64_t m_keepAlive; @@ -150,4 +167,4 @@ class Client }; -#endif /* __CLIENT_H__ */ +#endif /* XMRIG_CLIENT_H */ diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 49f4e54c7b..02bf5fa54d 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -46,6 +46,7 @@ Pool::Pool() : m_nicehash(false), + m_tls(false), m_keepAlive(0), m_port(kDefaultPort) { @@ -65,6 +66,7 @@ Pool::Pool() : */ Pool::Pool(const char *url) : m_nicehash(false), + m_tls(false), m_keepAlive(0), m_port(kDefaultPort) { @@ -72,8 +74,9 @@ Pool::Pool(const char *url) : } -Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash) : +Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls) : m_nicehash(nicehash), + m_tls(tls), m_keepAlive(keepAlive), m_port(port), m_host(host), @@ -134,7 +137,13 @@ bool Pool::parse(const char *url) const char *base = url; if (p) { - if (strncasecmp(url, "stratum+tcp://", 14)) { + if (strncasecmp(url, "stratum+tcp://", 14) == 0) { + m_tls = false; + } + else if (strncasecmp(url, "stratum+ssl://", 14) == 0) { + m_tls = true; + } + else { return false; } @@ -221,6 +230,9 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const break; } + obj.AddMember("tls", isTLS(), allocator); + obj.AddMember("tls-fingerprint", fingerprint() ? Value(StringRef(fingerprint())).Move() : Value(kNullType).Move(), allocator); + return obj; } diff --git a/src/common/net/Pool.h b/src/common/net/Pool.h index 0641b851df..123cc131f6 100644 --- a/src/common/net/Pool.h +++ b/src/common/net/Pool.h @@ -45,30 +45,35 @@ class Pool Pool(); Pool(const char *url); Pool(const char *host, - uint16_t port, - const char *user = nullptr, - const char *password = nullptr, - int keepAlive = 0, - bool nicehash = false + uint16_t port, + const char *user = nullptr, + const char *password = nullptr, + int keepAlive = 0, + bool nicehash = false, + bool tls = false ); - inline bool isNicehash() const { return m_nicehash; } - inline bool isValid() const { return !m_host.isNull() && m_port > 0; } - inline const char *host() const { return m_host.data(); } - inline const char *password() const { return !m_password.isNull() ? m_password.data() : kDefaultPassword; } - inline const char *rigId() const { return m_rigId.data(); } - inline const char *url() const { return m_url.data(); } - inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; } - inline const xmrig::Algorithm &algorithm() const { return m_algorithm; } - inline const xmrig::Algorithms &algorithms() const { return m_algorithms; } - inline int keepAlive() const { return m_keepAlive; } - inline uint16_t port() const { return m_port; } - inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; } - inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } - inline void setPassword(const char *password) { m_password = password; } - inline void setRigId(const char *rigId) { m_rigId = rigId; } - inline void setUser(const char *user) { m_user = user; } - inline xmrig::Algorithm &algorithm() { return m_algorithm; } + inline bool isNicehash() const { return m_nicehash; } + inline bool isTLS() const { return m_tls; } + inline bool isValid() const { return !m_host.isNull() && m_port > 0; } + inline const char *fingerprint() const { return m_fingerprint.data(); } + inline const char *host() const { return m_host.data(); } + inline const char *password() const { return !m_password.isNull() ? m_password.data() : kDefaultPassword; } + inline const char *rigId() const { return m_rigId.data(); } + inline const char *url() const { return m_url.data(); } + inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; } + inline const xmrig::Algorithm &algorithm() const { return m_algorithm; } + inline const xmrig::Algorithms &algorithms() const { return m_algorithms; } + inline int keepAlive() const { return m_keepAlive; } + inline uint16_t port() const { return m_port; } + inline void setFingerprint(const char *fingerprint) { m_fingerprint = fingerprint; } + inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; } + inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } + inline void setPassword(const char *password) { m_password = password; } + inline void setRigId(const char *rigId) { m_rigId = rigId; } + inline void setTLS(bool tls) { m_tls = tls; } + inline void setUser(const char *user) { m_user = user; } + inline xmrig::Algorithm &algorithm() { return m_algorithm; } inline bool operator!=(const Pool &other) const { return !isEqual(other); } inline bool operator==(const Pool &other) const { return isEqual(other); } @@ -92,10 +97,12 @@ class Pool void rebuild(); bool m_nicehash; + bool m_tls; int m_keepAlive; uint16_t m_port; xmrig::Algorithm m_algorithm; xmrig::Algorithms m_algorithms; + xmrig::c_str m_fingerprint; xmrig::c_str m_host; xmrig::c_str m_password; xmrig::c_str m_rigId; diff --git a/src/common/net/Tls.cpp b/src/common/net/Tls.cpp new file mode 100644 index 0000000000..679e5d2403 --- /dev/null +++ b/src/common/net/Tls.cpp @@ -0,0 +1,136 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018 Lee Clagett + * Copyright 2018 SChernykh + * Copyright 2016-2018 XMRig , + * + * 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 Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include + + +#include "common/net/Client.h" +#include "common/net/Tls.h" +#include "common/log/Log.h" + + +Client::Tls::Tls(Client *client) : + m_buf(), + m_client(client), + m_ssl(nullptr) +{ + m_ctx = SSL_CTX_new(SSLv23_method()); + assert(m_ctx != nullptr); + + if (!m_ctx) { + return; + } + + m_writeBio = BIO_new(BIO_s_mem()); + m_readBio = BIO_new(BIO_s_mem()); + SSL_CTX_set_options(m_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3); +} + + +Client::Tls::~Tls() +{ + if (m_ctx) { + SSL_CTX_free(m_ctx); + } + + if (m_ssl) { + SSL_free(m_ssl); + } +} + + +bool Client::Tls::handshake() +{ + m_ssl = SSL_new(m_ctx); + assert(m_ssl != nullptr); + + if (!m_ssl) { + return false; + } + + SSL_set_connect_state(m_ssl); + SSL_set_bio(m_ssl, m_readBio, m_writeBio); + SSL_do_handshake(m_ssl); + + return send(); +} + + +bool Client::Tls::send(const char *data, size_t size) +{ + SSL_write(m_ssl, data, size); + + return send(); +} + + +void Client::Tls::read(const char *data, size_t size) +{ + BIO_write(m_readBio, data, size); + + if (!SSL_is_init_finished(m_ssl)) { + const int rc = SSL_connect(m_ssl); + + if (rc < 0 && SSL_get_error(m_ssl, rc) == SSL_ERROR_WANT_READ) { + send(); + } + + if (rc == 1) { + if (!verify()) { + LOG_ERR("[%s] TLS certificate verification failed", m_client->m_pool.url()); + m_client->close(); + + return; + } + + m_client->login(); + } + + return; + } + + int bytes_read = 0; + while ((bytes_read = SSL_read(m_ssl, m_buf, sizeof(m_buf))) > 0) { + m_client->parse(m_buf, bytes_read); + } +} + + +bool Client::Tls::send() +{ + return m_client->send(m_writeBio); +} + + +bool Client::Tls::verify() +{ + X509* cert = SSL_get_peer_certificate(m_ssl); + if (cert == nullptr) { + return false; + } + + return true; +} diff --git a/src/common/net/Tls.h b/src/common/net/Tls.h new file mode 100644 index 0000000000..1347423786 --- /dev/null +++ b/src/common/net/Tls.h @@ -0,0 +1,58 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * + * 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 Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_TLS_H +#define XMRIG_TLS_H + + +#include + + +#include "common/net/Client.h" + + +class Client::Tls +{ +public: + Tls(Client *client); + ~Tls(); + + bool handshake(); + bool send(const char *data, size_t size); + + void read(const char *data, size_t size); + +private: + bool send(); + bool verify(); + + BIO *m_readBio; + BIO *m_writeBio; + char m_buf[1024 * 2]; + Client *m_client; + SSL *m_ssl; + SSL_CTX *m_ctx; +}; + + +#endif /* XMRIG_TLS_H */ diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index 9872427160..c034f3e754 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -132,6 +132,8 @@ static struct option const options[] = { { "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey }, { "userpass", 1, nullptr, xmrig::IConfig::UserpassKey }, { "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey }, + { "tls", 0, nullptr, xmrig::IConfig::TlsKey }, + { "tls-fingerprint", 1, nullptr, xmrig::IConfig::FingerprintKey }, { "version", 0, nullptr, xmrig::IConfig::VersionKey }, { nullptr, 0, nullptr, 0 } }; @@ -162,15 +164,17 @@ static struct option const config_options[] = { static struct option const pool_options[] = { - { "url", 1, nullptr, xmrig::IConfig::UrlKey }, - { "pass", 1, nullptr, xmrig::IConfig::PasswordKey }, - { "user", 1, nullptr, xmrig::IConfig::UserKey }, - { "userpass", 1, nullptr, xmrig::IConfig::UserpassKey }, - { "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey }, - { "keepalive", 2, nullptr, xmrig::IConfig::KeepAliveKey }, - { "variant", 1, nullptr, xmrig::IConfig::VariantKey }, - { "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey }, - { nullptr, 0, nullptr, 0 } + { "url", 1, nullptr, xmrig::IConfig::UrlKey }, + { "pass", 1, nullptr, xmrig::IConfig::PasswordKey }, + { "user", 1, nullptr, xmrig::IConfig::UserKey }, + { "userpass", 1, nullptr, xmrig::IConfig::UserpassKey }, + { "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey }, + { "keepalive", 2, nullptr, xmrig::IConfig::KeepAliveKey }, + { "variant", 1, nullptr, xmrig::IConfig::VariantKey }, + { "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey }, + { "tls", 0, nullptr, xmrig::IConfig::TlsKey }, + { "tls-fingerprint", 1, nullptr, xmrig::IConfig::FingerprintKey }, + { nullptr, 0, nullptr, 0 } }; From 4fa0329aba9d4c02ec4be5b6773799125f50576d Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 16 Sep 2018 05:04:20 +0300 Subject: [PATCH 061/102] Move shared summary to xmrig::CommonConfig. --- src/Summary.cpp | 65 +----------------- src/common/config/CommonConfig.cpp | 105 ++++++++++++++++++++++++++++- src/common/config/CommonConfig.h | 9 ++- src/common/config/ConfigLoader.cpp | 14 +++- 4 files changed, 126 insertions(+), 67 deletions(-) diff --git a/src/Summary.cpp b/src/Summary.cpp index 76842d5b1c..5feb6d7ed1 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -37,24 +37,6 @@ #include "version.h" -static void print_versions(xmrig::Config *config) -{ - char buf[16] = { 0 }; - -# if defined(__clang__) - snprintf(buf, 16, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); -# elif defined(__GNUC__) - snprintf(buf, 16, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); -# elif defined(_MSC_VER) - snprintf(buf, 16, " MSVC/%d", MSVC_VERSION); -# endif - - Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" libuv/%s%s") - : " * %-13s%s/%s libuv/%s%s", - "VERSIONS", APP_NAME, APP_VERSION, uv_version_string(), buf); -} - - static void print_memory(xmrig::Config *config) { # ifdef _WIN32 if (config->isColors()) { @@ -120,44 +102,6 @@ static void print_threads(xmrig::Config *config) } -static void print_pools(xmrig::Config *config) -{ - const std::vector &pools = config->pools(); - - for (size_t i = 0; i < pools.size(); ++i) { - Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") CYAN_BOLD("%s") " variant " WHITE_BOLD("%s") - : " * POOL #%-7d%s variant %s", - i + 1, - pools[i].url(), - pools[i].algorithm().variantName() - ); - } - -# ifdef APP_DEBUG - LOG_NOTICE("POOLS --------------------------------------------------------------------"); - for (const Pool &pool : pools) { - pool.print(); - } - LOG_NOTICE("--------------------------------------------------------------------------"); -# endif -} - - -#ifndef XMRIG_NO_API -static void print_api(xmrig::Config *config) -{ - const int port = config->apiPort(); - if (port == 0) { - return; - } - - Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN("%s:") CYAN_BOLD("%d") - : " * %-13s%s:%d", - "API BIND", config->isApiIPv6() ? "[::]" : "0.0.0.0", port); -} -#endif - - static void print_commands(xmrig::Config *config) { if (config->isColors()) { @@ -173,15 +117,12 @@ static void print_commands(xmrig::Config *config) void Summary::print(xmrig::Controller *controller) { - print_versions(controller->config()); + controller->config()->printVersions(); print_memory(controller->config()); print_cpu(controller->config()); print_threads(controller->config()); - print_pools(controller->config()); - -# ifndef XMRIG_NO_API - print_api(controller->config()); -# endif + controller->config()->printPools(); + controller->config()->printAPI(); print_commands(controller->config()); } diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index f22a632c13..a9df89d7ad 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -29,12 +29,23 @@ #include +#ifndef XMRIG_NO_HTTPD +# include +#endif + + +#ifndef XMRIG_NO_TLS +# include +#endif + + #include "common/config/CommonConfig.h" #include "common/log/Log.h" #include "donate.h" #include "rapidjson/document.h" #include "rapidjson/filewritestream.h" #include "rapidjson/prettywriter.h" +#include "version.h" xmrig::CommonConfig::CommonConfig() : @@ -69,8 +80,100 @@ xmrig::CommonConfig::CommonConfig() : } -xmrig::CommonConfig::~CommonConfig() +void xmrig::CommonConfig::printAPI() +{ +# ifndef XMRIG_NO_API + if (apiPort() == 0) { + return; + } + + Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN("%s:") CYAN_BOLD("%d") + : " * %-13s%s:%d", + "API BIND", isApiIPv6() ? "[::]" : "0.0.0.0", apiPort()); +# endif +} + + +void xmrig::CommonConfig::printPools() { + for (size_t i = 0; i < m_activePools.size(); ++i) { + if (!isColors()) { + Log::i()->text(" * POOL #%-7zu%s variant=%s, TLS=%d", + i + 1, + m_activePools[i].url(), + m_activePools[i].algorithm().variantName(), + static_cast(m_activePools[i].isTLS()) + ); + } + else { + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m variant " WHITE_BOLD("%s"), + i + 1, + m_activePools[i].isTLS() ? 32 : 36, + m_activePools[i].url(), + m_activePools[i].algorithm().variantName() + ); + } + } + +# ifdef APP_DEBUG + LOG_NOTICE("POOLS --------------------------------------------------------------------"); + for (const Pool &pool : m_activePools) { + pool.print(); + } + LOG_NOTICE("--------------------------------------------------------------------------"); +# endif +} + + +void xmrig::CommonConfig::printVersions() +{ + char buf[256] = { 0 }; + +# if defined(__clang__) + snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); +# elif defined(__GNUC__) + snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); +# elif defined(_MSC_VER) + snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION); +# endif + + Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s") + : " * %-13s%s/%s %s", + "ABOUT", APP_NAME, APP_VERSION, buf); + +# if defined(XMRIG_AMD_PROJECT) +# if CL_VERSION_2_0 + const char *ocl = "2.0"; +# elif CL_VERSION_1_2 + const char *ocl = "1.2"; +# elif CL_VERSION_1_1 + const char *ocl = "1.1"; +# elif CL_VERSION_1_0 + const char *ocl = "1.0"; +# else + const char *ocl = "0.0"; +# endif + int length = snprintf(buf, sizeof buf, "OpenCL/%s ", ocl); +# else + memset(buf, 0, 16); + int length = 0; +# endif + +# if !defined(XMRIG_NO_TLS) && defined(OPENSSL_VERSION_TEXT) + { + constexpr const char *v = OPENSSL_VERSION_TEXT + 8; + length += snprintf(buf + length, (sizeof buf) - length, "OpenSSL/%.*s ", static_cast(strchr(v, ' ') - v), v); + } +# endif + +# ifndef XMRIG_NO_HTTPD + length += snprintf(buf + length, (sizeof buf) - length, "microhttpd/%s ", MHD_get_version()); +# endif + + + Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s") + : " * %-13slibuv/%s %s", + "LIBS", uv_version_string(), buf); } diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index fa27ea6a48..7643a1a5fb 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __COMMONCONFIG_H__ -#define __COMMONCONFIG_H__ +#ifndef XMRIG_COMMONCONFIG_H +#define XMRIG_COMMONCONFIG_H #include @@ -41,7 +41,6 @@ class CommonConfig : public IConfig { public: CommonConfig(); - ~CommonConfig(); inline bool isApiIPv6() const { return m_apiIPv6; } inline bool isApiRestricted() const { return m_apiRestricted; } @@ -68,6 +67,10 @@ class CommonConfig : public IConfig bool save() override; + void printAPI(); + void printPools(); + void printVersions(); + protected: enum State { NoneState, diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index cc5d9a4939..484c2f8fb8 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -32,6 +32,11 @@ #endif +#ifndef XMRIG_NO_TLS +# include +#endif + + #include "common/config/ConfigLoader.h" #include "common/config/ConfigWatcher.h" #include "common/interfaces/IConfig.h" @@ -313,6 +318,13 @@ void xmrig::ConfigLoader::showVersion() printf("\nlibuv/%s\n", uv_version_string()); # ifndef XMRIG_NO_HTTPD - printf("libmicrohttpd/%s\n", MHD_get_version()); + printf("microhttpd/%s\n", MHD_get_version()); +# endif + +# if !defined(XMRIG_NO_TLS) && defined(OPENSSL_VERSION_TEXT) + { + constexpr const char *v = OPENSSL_VERSION_TEXT + 8; + printf("OpenSSL/%.*s\n", static_cast(strchr(v, ' ') - v), v); + } # endif } From 62085ad56c67cd28d2a2fb241ea8b6b341e3f5c0 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 16 Sep 2018 06:35:49 +0300 Subject: [PATCH 062/102] Show TLS version. --- src/Summary.cpp | 6 +++--- src/common/net/Client.cpp | 20 ++++++++++++++++++-- src/common/net/Client.h | 3 ++- src/common/net/Tls.cpp | 30 ++++++++++++++++++------------ src/common/net/Tls.h | 3 ++- src/net/Network.cpp | 5 ++++- 6 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/Summary.cpp b/src/Summary.cpp index 5feb6d7ed1..de6b1234c7 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -53,18 +53,18 @@ static void print_memory(xmrig::Config *config) { static void print_cpu(xmrig::Config *config) { if (config->isColors()) { - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s (%d) %sx64 %sAES-NI", + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%d)") " %sx64 %sAES", "CPU", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "\x1B[1;32m" : "\x1B[1;31m-", Cpu::hasAES() ? "\x1B[1;32m" : "\x1B[1;31m-"); # ifndef XMRIG_NO_LIBCPUID - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%.1f MB/%.1f MB", "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%.1f MB/%.1f MB"), "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); # endif } else { - Log::i()->text(" * %-13s%s (%d) %sx64 %sAES-NI", "CPU", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); + Log::i()->text(" * %-13s%s (%d) %sx64 %sAES", "CPU", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); # ifndef XMRIG_NO_LIBCPUID Log::i()->text(" * %-13s%.1f MB/%.1f MB", "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); # endif diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index 1057c47421..d789ac8966 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -186,9 +186,15 @@ bool Client::disconnect() } -bool Client::isTLS() const +const char *Client::tlsVersion() const { - return m_pool.isTLS() && m_tls; +# ifndef XMRIG_NO_TLS + if (isTLS()) { + return m_tls->tlsVersion(); + } +# endif + + return nullptr; } @@ -277,6 +283,16 @@ bool Client::isCriticalError(const char *message) } +bool Client::isTLS() const +{ +# ifndef XMRIG_NO_TLS + return m_pool.isTLS() && m_tls; +# else + return false; +# endif +} + + bool Client::parseJob(const rapidjson::Value ¶ms, int *code) { if (!params.IsObject()) { diff --git a/src/common/net/Client.h b/src/common/net/Client.h index 893fabfc8f..b387988576 100644 --- a/src/common/net/Client.h +++ b/src/common/net/Client.h @@ -69,7 +69,7 @@ class Client ~Client(); bool disconnect(); - bool isTLS() const; + const char *tlsVersion() const; int64_t submit(const JobResult &result); void connect(); void connect(const Pool &pool); @@ -100,6 +100,7 @@ class Client bool close(); bool isCriticalError(const char *message); + bool isTLS() const; bool parseJob(const rapidjson::Value ¶ms, int *code); bool parseLogin(const rapidjson::Value &result, int *code); bool send(BIO *bio); diff --git a/src/common/net/Tls.cpp b/src/common/net/Tls.cpp index 679e5d2403..2cfc0e527f 100644 --- a/src/common/net/Tls.cpp +++ b/src/common/net/Tls.cpp @@ -33,6 +33,7 @@ Client::Tls::Tls(Client *client) : + m_ready(false), m_buf(), m_client(client), m_ssl(nullptr) @@ -87,26 +88,31 @@ bool Client::Tls::send(const char *data, size_t size) } +const char *Client::Tls::tlsVersion() const +{ + return m_ready ? SSL_get_version(m_ssl) : nullptr; +} + + void Client::Tls::read(const char *data, size_t size) { BIO_write(m_readBio, data, size); if (!SSL_is_init_finished(m_ssl)) { - const int rc = SSL_connect(m_ssl); - - if (rc < 0 && SSL_get_error(m_ssl, rc) == SSL_ERROR_WANT_READ) { - send(); - } + const int rc = SSL_connect(m_ssl); - if (rc == 1) { - if (!verify()) { - LOG_ERR("[%s] TLS certificate verification failed", m_client->m_pool.url()); - m_client->close(); + if (rc < 0 && SSL_get_error(m_ssl, rc) == SSL_ERROR_WANT_READ) { + send(); + } else if (rc == 1) { + if (!verify()) { + LOG_ERR("[%s] TLS certificate verification failed", m_client->m_pool.url()); + m_client->close(); - return; - } + return; + } - m_client->login(); + m_ready = true; + m_client->login(); } return; diff --git a/src/common/net/Tls.h b/src/common/net/Tls.h index 1347423786..ee3b59ef00 100644 --- a/src/common/net/Tls.h +++ b/src/common/net/Tls.h @@ -39,7 +39,7 @@ class Client::Tls bool handshake(); bool send(const char *data, size_t size); - + const char *tlsVersion() const; void read(const char *data, size_t size); private: @@ -48,6 +48,7 @@ class Client::Tls BIO *m_readBio; BIO *m_writeBio; + bool m_ready; char m_buf[1024 * 2]; Client *m_client; SSL *m_ssl; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 7293a0ac90..9997f7e71e 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -101,7 +101,10 @@ void Network::onActive(IStrategy *strategy, Client *client) m_state.setPool(client->host(), client->port(), client->ip()); - LOG_INFO(isColors() ? "\x1B[01;37muse pool \x1B[01;36m%s:%d \x1B[01;30m%s" : "use pool %s:%d %s", client->host(), client->port(), client->ip()); + const char *tlsVersion = client->tlsVersion(); + LOG_INFO(isColors() ? WHITE_BOLD("use pool ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " \x1B[01;30m%s " + : "use pool %s:%d %s %s", + client->host(), client->port(), tlsVersion ? tlsVersion : "", client->ip()); } From 798debd1151b8a9d0506304e555260f7a2d92c0e Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 16 Sep 2018 08:14:22 +0300 Subject: [PATCH 063/102] Added TLS fingerprint validation. --- src/common/net/Client.cpp | 14 +++++++++- src/common/net/Client.h | 1 + src/common/net/Tls.cpp | 58 +++++++++++++++++++++++++++++++++++---- src/common/net/Tls.h | 7 +++-- src/net/Network.cpp | 7 ++++- 5 files changed, 78 insertions(+), 9 deletions(-) diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index d789ac8966..b039727de5 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -186,11 +186,23 @@ bool Client::disconnect() } +const char *Client::tlsFingerprint() const +{ +# ifndef XMRIG_NO_TLS + if (isTLS() && m_pool.fingerprint() == nullptr) { + return m_tls->fingerprint(); + } +# endif + + return nullptr; +} + + const char *Client::tlsVersion() const { # ifndef XMRIG_NO_TLS if (isTLS()) { - return m_tls->tlsVersion(); + return m_tls->version(); } # endif diff --git a/src/common/net/Client.h b/src/common/net/Client.h index b387988576..55105c0ba3 100644 --- a/src/common/net/Client.h +++ b/src/common/net/Client.h @@ -69,6 +69,7 @@ class Client ~Client(); bool disconnect(); + const char *tlsFingerprint() const; const char *tlsVersion() const; int64_t submit(const JobResult &result); void connect(); diff --git a/src/common/net/Tls.cpp b/src/common/net/Tls.cpp index 2cfc0e527f..182d86ff59 100644 --- a/src/common/net/Tls.cpp +++ b/src/common/net/Tls.cpp @@ -32,9 +32,15 @@ #include "common/log/Log.h" +#ifdef _MSC_VER +# define strncasecmp(x,y,z) _strnicmp(x,y,z) +#endif + + Client::Tls::Tls(Client *client) : m_ready(false), m_buf(), + m_fingerprint(), m_client(client), m_ssl(nullptr) { @@ -88,7 +94,13 @@ bool Client::Tls::send(const char *data, size_t size) } -const char *Client::Tls::tlsVersion() const +const char *Client::Tls::fingerprint() const +{ + return m_ready ? m_fingerprint : nullptr; +} + + +const char *Client::Tls::version() const { return m_ready ? SSL_get_version(m_ssl) : nullptr; } @@ -104,13 +116,15 @@ void Client::Tls::read(const char *data, size_t size) if (rc < 0 && SSL_get_error(m_ssl, rc) == SSL_ERROR_WANT_READ) { send(); } else if (rc == 1) { - if (!verify()) { - LOG_ERR("[%s] TLS certificate verification failed", m_client->m_pool.url()); + X509 *cert = SSL_get_peer_certificate(m_ssl); + if (!verify(cert)) { + X509_free(cert); m_client->close(); return; } + X509_free(cert); m_ready = true; m_client->login(); } @@ -131,12 +145,46 @@ bool Client::Tls::send() } -bool Client::Tls::verify() +bool Client::Tls::verify(X509 *cert) { - X509* cert = SSL_get_peer_certificate(m_ssl); if (cert == nullptr) { + LOG_ERR("[%s] Failed to get server certificate", m_client->m_pool.url()); + + return false; + } + + if (!verifyFingerprint(cert)) { + LOG_ERR("[%s] Failed to verify server certificate fingerprint", m_client->m_pool.url()); + + const char *fingerprint = m_client->m_pool.fingerprint(); + if (strlen(m_fingerprint) == 64 && fingerprint != nullptr) { + LOG_ERR("\"%s\" was given", m_fingerprint); + LOG_ERR("\"%s\" was configured", fingerprint); + } + return false; } return true; } + + +bool Client::Tls::verifyFingerprint(X509 *cert) +{ + const EVP_MD *digest = EVP_get_digestbyname("sha256"); + if (digest == nullptr) { + return false; + } + + unsigned char md[EVP_MAX_MD_SIZE]; + unsigned int dlen; + + if (X509_digest(cert, digest, md, &dlen) != 1) { + return false; + } + + Job::toHex(md, 32, m_fingerprint); + const char *fingerprint = m_client->m_pool.fingerprint(); + + return fingerprint == nullptr || strncasecmp(m_fingerprint, fingerprint, 64) == 0; +} diff --git a/src/common/net/Tls.h b/src/common/net/Tls.h index ee3b59ef00..6e38f32f7f 100644 --- a/src/common/net/Tls.h +++ b/src/common/net/Tls.h @@ -39,17 +39,20 @@ class Client::Tls bool handshake(); bool send(const char *data, size_t size); - const char *tlsVersion() const; + const char *fingerprint() const; + const char *version() const; void read(const char *data, size_t size); private: bool send(); - bool verify(); + bool verify(X509 *cert); + bool verifyFingerprint(X509 *cert); BIO *m_readBio; BIO *m_writeBio; bool m_ready; char m_buf[1024 * 2]; + char m_fingerprint[32 * 2 + 8]; Client *m_client; SSL *m_ssl; SSL_CTX *m_ctx; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 9997f7e71e..703e0ccfa3 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -102,9 +102,14 @@ void Network::onActive(IStrategy *strategy, Client *client) m_state.setPool(client->host(), client->port(), client->ip()); const char *tlsVersion = client->tlsVersion(); - LOG_INFO(isColors() ? WHITE_BOLD("use pool ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " \x1B[01;30m%s " + LOG_INFO(isColors() ? WHITE_BOLD("use pool ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " \x1B[1;30m%s " : "use pool %s:%d %s %s", client->host(), client->port(), tlsVersion ? tlsVersion : "", client->ip()); + + const char *fingerprint = client->tlsFingerprint(); + if (fingerprint != nullptr) { + LOG_INFO("\x1B[1;30mfingerprint (SHA-256): \"%s\"", fingerprint); + } } From 410ec20c1a80c317f65d73f55d48bebcb7a062ce Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 17 Sep 2018 01:02:17 +0300 Subject: [PATCH 064/102] Skip TLS pools if miner built without TLS support. --- src/common/config/CommonConfig.cpp | 6 ++++++ src/common/net/Pool.cpp | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index a9df89d7ad..b39e0e2fcd 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -229,6 +229,12 @@ bool xmrig::CommonConfig::finalize() pool.adjust(m_algorithm); if (pool.isValid() && pool.algorithm().isValid()) { +# ifdef XMRIG_NO_TLS + if (pool.isTLS()) { + continue; + } +# endif + m_activePools.push_back(std::move(pool)); } } diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 02bf5fa54d..141e511586 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -117,15 +117,17 @@ bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const bool Pool::isEqual(const Pool &other) const { - return (m_nicehash == other.m_nicehash - && m_keepAlive == other.m_keepAlive - && m_port == other.m_port - && m_algorithm == other.m_algorithm - && m_host == other.m_host - && m_password == other.m_password - && m_rigId == other.m_rigId - && m_url == other.m_url - && m_user == other.m_user); + return (m_nicehash == other.m_nicehash + && m_tls == other.m_tls + && m_keepAlive == other.m_keepAlive + && m_port == other.m_port + && m_algorithm == other.m_algorithm + && m_fingerprint == other.m_fingerprint + && m_host == other.m_host + && m_password == other.m_password + && m_rigId == other.m_rigId + && m_url == other.m_url + && m_user == other.m_user); } From 638df14b486a045a158b49e69744f28c4a45b00b Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 17 Sep 2018 01:43:44 +0300 Subject: [PATCH 065/102] Fix gcc build with OpenSSL 1.1.1 --- cmake/OpenSSL.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/OpenSSL.cmake b/cmake/OpenSSL.cmake index 154a827894..d0c0d1641a 100644 --- a/cmake/OpenSSL.cmake +++ b/cmake/OpenSSL.cmake @@ -11,6 +11,10 @@ if (WITH_TLS) else() message(FATAL_ERROR "OpenSSL NOT found: use `-DWITH_TLS=OFF` to build without TLS support") endif() + + if (WIN32) + set(EXTRA_LIBS ${EXTRA_LIBS} Crypt32) + endif() else() set(TLS_SOURCES "") set(OPENSSL_LIBRARIES "") From a1a254c92f3432c4de98facc5d0a2c3d117cd92a Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 17 Sep 2018 06:37:53 +0300 Subject: [PATCH 066/102] Fix Linux build. --- CMakeLists.txt | 2 +- src/common/net/Client.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d38b1a042..317724e3f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,7 +156,7 @@ else() src/Mem_unix.cpp ) - set(EXTRA_LIBS pthread rt) + set(EXTRA_LIBS pthread rt dl) endif() if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD) diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index b039727de5..3a93789b61 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -414,7 +414,7 @@ bool Client::send(BIO *bio) LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", m_pool.url(), m_state); } - BIO_reset(bio); + (void) BIO_reset(bio); return result; # else From 4a6452c4c6feb28d223ffc002dcc6c781746044b Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 17 Sep 2018 09:24:18 +0300 Subject: [PATCH 067/102] Enable TLS by default. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 317724e3f8..b779b74d4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ option(WITH_AEON "CryptoNight-Lite support" ON) option(WITH_SUMO "CryptoNight-Heavy support" ON) option(WITH_HTTPD "HTTP REST API" ON) option(WITH_DEBUG_LOG "Enable debug log output" OFF) -option(WITH_TLS "Enable OpenSSL support" OFF) +option(WITH_TLS "Enable OpenSSL support" ON) option(BUILD_STATIC "Build static binary" OFF) include (CheckIncludeFile) From b4c0a8e1a12e4e17aa3dee5db4d6f7982071ac73 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 18 Sep 2018 04:04:25 +0300 Subject: [PATCH 068/102] Sync changes. --- src/common/config/CommonConfig.cpp | 18 +++++++++++++++++- src/common/interfaces/IConfig.h | 18 +++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index b39e0e2fcd..b70d5e3d5b 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -39,6 +39,20 @@ #endif +#ifdef XMRIG_AMD_PROJECT +# if defined(__APPLE__) +# include +# else +# include "3rdparty/CL/cl.h" +# endif +#endif + + +#ifdef XMRIG_NVIDIA_PROJECT +# include "nvidia/cryptonight.h" +#endif + + #include "common/config/CommonConfig.h" #include "common/log/Log.h" #include "donate.h" @@ -154,6 +168,9 @@ void xmrig::CommonConfig::printVersions() const char *ocl = "0.0"; # endif int length = snprintf(buf, sizeof buf, "OpenCL/%s ", ocl); +# elif defined(XMRIG_NVIDIA_PROJECT) + const int cudaVersion = cuda_get_runtime_version(); + int length = snprintf(buf, sizeof buf, "CUDA/%d.%d ", cudaVersion / 1000, cudaVersion % 100); # else memset(buf, 0, 16); int length = 0; @@ -170,7 +187,6 @@ void xmrig::CommonConfig::printVersions() length += snprintf(buf + length, (sizeof buf) - length, "microhttpd/%s ", MHD_get_version()); # endif - Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s") : " * %-13slibuv/%s %s", "LIBS", uv_version_string(), buf); diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index ece8e3b476..d359316344 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -82,13 +82,17 @@ class IConfig HardwareAESKey = 1011, // xmrig amd - OclPlatform = 1400, - OclAffinity = 1401, - OclDevices = 1402, - OclLaunch = 1403, - OclCache = 1404, - OclPrint = 1405, - OclLoader = 1406, + OclPlatformKey = 1400, + OclAffinityKey = 1401, + OclDevicesKey = 1402, + OclLaunchKey = 1403, + OclCacheKey = 1404, + OclPrintKey = 1405, + OclLoaderKey = 1406, + OclSridedIndexKey = 1407, + OclMemChunkKey = 1408, + OclUnrollKey = 1409, + OclCompModeKey = 1410, // xmrig-proxy AccessLogFileKey = 'A', From 1804170f8d3b9c214c913e0cc4c012774fef1e6f Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 20 Sep 2018 07:33:32 +0300 Subject: [PATCH 069/102] # Fixed send buffer overflow and increase send buffer size. --- src/common/net/Client.cpp | 4 +++- src/common/net/Client.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index 3a93789b61..6a79749d85 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -482,7 +482,9 @@ int64_t Client::send(const rapidjson::Document &doc) doc.Accept(writer); const size_t size = buffer.GetSize(); - if (size > (sizeof(m_buf) - 2)) { + if (size > (sizeof(m_sendBuf) - 2)) { + LOG_ERR("[%s] send failed: \"send buffer overflow: %zu > %zu\"", m_pool.url(), size, (sizeof(m_sendBuf) - 2)); + close(); return -1; } diff --git a/src/common/net/Client.h b/src/common/net/Client.h index 55105c0ba3..d641833840 100644 --- a/src/common/net/Client.h +++ b/src/common/net/Client.h @@ -140,7 +140,7 @@ class Client bool m_quiet; char m_buf[kInputBufferSize]; char m_ip[46]; - char m_sendBuf[1024]; + char m_sendBuf[2048]; const char *m_agent; IClientListener *m_listener; int m_extensions; From f80294144d1ba5dad8e36510bdbdd57401772d12 Mon Sep 17 00:00:00 2001 From: xmrig Date: Sat, 22 Sep 2018 08:42:15 +0300 Subject: [PATCH 070/102] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ef9573d40..d64bb2b786 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v2.8.0 +- **[#753](https://github.com/xmrig/xmrig/issues/753) Added new algorithm [CryptoNight variant 2](https://github.com/xmrig/xmrig/issues/753) for Monero fork, thanks [@SChernykh](https://github.com/SChernykh).** +- **Added SSL/TLS support for secure connections to pools.** +- [#245](https://github.com/xmrig/xmrig-proxy/issues/245) Fixed API ID collision when run multiple miners on same machine. +- [#757](https://github.com/xmrig/xmrig/issues/757) Fixed send buffer overflow. + # v2.6.4 - [#700](https://github.com/xmrig/xmrig/issues/700) `cryptonight-lite/ipbc` replaced to `cryptonight-heavy/tube` for **Bittube (TUBE)**. - Added `cryptonight/rto` (cryptonight variant 1 with IPBC/TUBE mod) variant for **Arto (RTO)** coin. From fbd227cba7ffe569be856d35496a66867bfd7d58 Mon Sep 17 00:00:00 2001 From: xmrig Date: Sat, 22 Sep 2018 08:54:56 +0300 Subject: [PATCH 071/102] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d64bb2b786..4e1e2412c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # v2.8.0 - **[#753](https://github.com/xmrig/xmrig/issues/753) Added new algorithm [CryptoNight variant 2](https://github.com/xmrig/xmrig/issues/753) for Monero fork, thanks [@SChernykh](https://github.com/SChernykh).** -- **Added SSL/TLS support for secure connections to pools.** +- [#758](https://github.com/xmrig/xmrig/issues/758) **Added SSL/TLS support for secure connections to pools.** - [#245](https://github.com/xmrig/xmrig-proxy/issues/245) Fixed API ID collision when run multiple miners on same machine. - [#757](https://github.com/xmrig/xmrig/issues/757) Fixed send buffer overflow. From dd6fb4a08fe214eb37cbc17e2d2f6da67637099d Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 22 Sep 2018 15:54:31 +0300 Subject: [PATCH 072/102] Fix for automatic variant specified by pool/proxy. --- src/common/net/Job.cpp | 10 ++++++++++ src/common/net/Job.h | 2 +- src/common/xmrig.h | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index bb5f6a12cd..2bfb39f0e0 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -170,6 +170,16 @@ bool Job::setTarget(const char *target) } +void Job::setAlgorithm(const char *algo) +{ + m_algorithm.parseAlgorithm(algo); + + if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { + m_algorithm.setVariant(variant()); + } +} + + bool Job::fromHex(const char* in, unsigned int len, unsigned char* out) { bool error = false; diff --git a/src/common/net/Job.h b/src/common/net/Job.h index 8bd1b8adc7..b561b9c1b8 100644 --- a/src/common/net/Job.h +++ b/src/common/net/Job.h @@ -44,6 +44,7 @@ class Job bool setBlob(const char *blob); bool setTarget(const char *target); + void setAlgorithm(const char *algo); inline bool isNicehash() const { return m_nicehash; } inline bool isValid() const { return m_size > 0 && m_diff > 0; } @@ -60,7 +61,6 @@ class Job inline uint32_t diff() const { return static_cast(m_diff); } inline uint64_t target() const { return m_target; } inline void reset() { m_size = 0; m_diff = 0; } - inline void setAlgorithm(const char *algo) { m_algorithm.parseAlgorithm(algo); } inline void setClientId(const xmrig::Id &id) { m_clientId = id; } inline void setPoolId(int poolId) { m_poolId = poolId; } inline void setThreadId(int threadId) { m_threadId = threadId; } diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 3e1b65dfd0..e1c7702e1a 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __XMRIG_H__ -#define __XMRIG_H__ +#ifndef XMRIG_XMRIG_H +#define XMRIG_XMRIG_H namespace xmrig @@ -85,7 +85,16 @@ enum AesMode { }; +enum OclVendor { + OCL_VENDOR_UNKNOWN = -2, + OCL_VENDOR_MANUAL = -1, + OCL_VENDOR_AMD = 0, + OCL_VENDOR_NVIDIA = 1, + OCL_VENDOR_INTEL = 2 +}; + + } /* namespace xmrig */ -#endif /* __XMRIG_H__ */ +#endif /* XMRIG_XMRIG_H */ From e1ab479f30947e0109dad6c9edb8764186f91820 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 22 Sep 2018 16:01:27 +0300 Subject: [PATCH 073/102] Don't use static OpenSSL on Linux by default. --- cmake/OpenSSL.cmake | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmake/OpenSSL.cmake b/cmake/OpenSSL.cmake index d0c0d1641a..ed287e7e3c 100644 --- a/cmake/OpenSSL.cmake +++ b/cmake/OpenSSL.cmake @@ -1,7 +1,12 @@ if (WITH_TLS) set(OPENSSL_ROOT_DIR ${XMRIG_DEPS}) - set(OPENSSL_USE_STATIC_LIBS TRUE) - set(OPENSSL_MSVC_STATIC_RT TRUE) + + if (WIN32) + set(OPENSSL_USE_STATIC_LIBS TRUE) + set(OPENSSL_MSVC_STATIC_RT TRUE) + + set(EXTRA_LIBS ${EXTRA_LIBS} Crypt32) + endif() find_package(OpenSSL) @@ -11,10 +16,6 @@ if (WITH_TLS) else() message(FATAL_ERROR "OpenSSL NOT found: use `-DWITH_TLS=OFF` to build without TLS support") endif() - - if (WIN32) - set(EXTRA_LIBS ${EXTRA_LIBS} Crypt32) - endif() else() set(TLS_SOURCES "") set(OPENSSL_LIBRARIES "") From a3db47ee5018a5849bb5e9f8ccf4199a47b04799 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sat, 22 Sep 2018 17:21:32 +0200 Subject: [PATCH 074/102] Cryptonight variant 2 - final version Reference code: https://github.com/monero-project/monero/pull/4404 I tested it on x86 with av=1-10 and on ARM with av=1-4, self test passed. --- src/crypto/CryptoNight_arm.h | 6 +++--- src/crypto/CryptoNight_monero.h | 24 ++++++++++++++++++++++++ src/crypto/CryptoNight_test.h | 20 ++++++++++---------- src/crypto/CryptoNight_x86.h | 8 ++++---- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 4cd5eba55c..4fcebc3eeb 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -487,7 +487,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si if (VARIANT == xmrig::VARIANT_2) { VARIANT2_INTEGER_MATH(0, cl, cx); lo = __umul128(idx0, cl, &hi); - VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx0, bx1); + VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx0, bx1, hi, lo); } else { lo = __umul128(idx0, cl, &hi); @@ -619,7 +619,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si if (VARIANT == xmrig::VARIANT_2) { VARIANT2_INTEGER_MATH(0, cl, cx0); lo = __umul128(idx0, cl, &hi); - VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx00, bx01); + VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx00, bx01, hi, lo); } else { lo = __umul128(idx0, cl, &hi); } @@ -662,7 +662,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si if (VARIANT == xmrig::VARIANT_2) { VARIANT2_INTEGER_MATH(1, cl, cx1); lo = __umul128(idx1, cl, &hi); - VARIANT2_SHUFFLE(l1, idx1 & MASK, ax1, bx10, bx11); + VARIANT2_SHUFFLE2(l1, idx1 & MASK, ax1, bx10, bx11, hi, lo); } else { lo = __umul128(idx1, cl, &hi); } diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index 80750c6c3e..522290268a 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -93,6 +93,18 @@ _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x30)), _mm_add_epi64(chunk2, _a)); \ } while (0) +# define VARIANT2_SHUFFLE2(base_ptr, offset, _a, _b, _b1, hi, lo) \ + do { \ + const __m128i chunk1 = _mm_xor_si128(_mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10))), _mm_set_epi64x(lo, hi)); \ + const __m128i chunk2 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20))); \ + hi ^= ((uint64_t*)((base_ptr) + ((offset) ^ 0x20)))[0]; \ + lo ^= ((uint64_t*)((base_ptr) + ((offset) ^ 0x20)))[1]; \ + const __m128i chunk3 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x30))); \ + _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10)), _mm_add_epi64(chunk3, _b1)); \ + _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20)), _mm_add_epi64(chunk1, _b)); \ + _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x30)), _mm_add_epi64(chunk2, _a)); \ + } while (0) + #else # define VARIANT2_INIT(part) \ uint64_t division_result_##part = h##part[12]; \ @@ -122,5 +134,17 @@ vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20)), vaddq_u64(chunk1, vreinterpretq_u64_u8(_b))); \ vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x30)), vaddq_u64(chunk2, vreinterpretq_u64_u8(_a))); \ } while (0) + +# define VARIANT2_SHUFFLE2(base_ptr, offset, _a, _b, _b1, hi, lo) \ + do { \ + const uint64x2_t chunk1 = veorq_u64(vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x10))), vcombine_u64(vcreate_u64(hi), vcreate_u64(lo))); \ + const uint64x2_t chunk2 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20))); \ + hi ^= ((uint64_t*)((base_ptr) + ((offset) ^ 0x20)))[0]; \ + lo ^= ((uint64_t*)((base_ptr) + ((offset) ^ 0x20)))[1]; \ + const uint64x2_t chunk3 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x30))); \ + vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x10)), vaddq_u64(chunk3, vreinterpretq_u64_u8(_b1))); \ + vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20)), vaddq_u64(chunk1, vreinterpretq_u64_u8(_b))); \ + vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x30)), vaddq_u64(chunk2, vreinterpretq_u64_u8(_a))); \ + } while (0) #endif #endif /* XMRIG_CRYPTONIGHT_MONERO_H */ diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index 953f88d0e9..95e12197b8 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -86,16 +86,16 @@ const static uint8_t test_output_v1[160] = { // Cryptonight variant 2 (Monero v8) const static uint8_t test_output_v2[160] = { - 0x6E, 0xEE, 0x53, 0xA3, 0xDA, 0xD1, 0x8C, 0x05, 0xB8, 0xCB, 0x32, 0x17, 0xAA, 0xEA, 0xEA, 0xB4, - 0x16, 0x11, 0x01, 0xA9, 0x08, 0x76, 0x37, 0x36, 0x6F, 0xDC, 0xCA, 0xC6, 0x92, 0x0D, 0xEA, 0x09, - 0x91, 0x03, 0x2F, 0x5B, 0x27, 0x4D, 0x94, 0x1D, 0x60, 0x50, 0xDC, 0x1F, 0x35, 0x57, 0xEC, 0x20, - 0xA6, 0xAC, 0x10, 0xDB, 0xCF, 0x36, 0x23, 0x8F, 0x96, 0xC7, 0x72, 0x8B, 0xF9, 0xE7, 0x30, 0xEB, - 0x50, 0x58, 0x4B, 0xFE, 0xAD, 0xC5, 0x13, 0x79, 0x50, 0x98, 0x1C, 0x67, 0xB2, 0xEB, 0xDA, 0x64, - 0xD4, 0xAA, 0xC4, 0xE8, 0xE5, 0xC9, 0xE7, 0x6B, 0x84, 0xC2, 0xD2, 0xE9, 0x1F, 0xA1, 0x0F, 0xDF, - 0x45, 0x06, 0x80, 0x25, 0x32, 0x6B, 0xC4, 0x66, 0x2A, 0x69, 0x9F, 0x1E, 0x1F, 0x4C, 0xBE, 0x89, - 0xFE, 0x61, 0xBB, 0x04, 0x79, 0xB5, 0x3B, 0x45, 0x58, 0xD9, 0x9C, 0x18, 0x7C, 0x48, 0x1B, 0x44, - 0x92, 0xC4, 0x4C, 0xD0, 0x8F, 0x16, 0x44, 0x79, 0x71, 0x48, 0x63, 0x0B, 0x51, 0xB6, 0x33, 0x8B, - 0x6B, 0x3F, 0xCC, 0x0A, 0x3A, 0x14, 0x3B, 0x49, 0x68, 0x46, 0xB9, 0x46, 0xC6, 0xA3, 0x03, 0x41 + 0x97, 0x37, 0x82, 0x82, 0xCF, 0x10, 0xE7, 0xAD, 0x03, 0x3F, 0x7B, 0x80, 0x74, 0xC4, 0x0E, 0x14, + 0xD0, 0x6E, 0x7F, 0x60, 0x9D, 0xDD, 0xDA, 0x78, 0x76, 0x80, 0xB5, 0x8C, 0x05, 0xF4, 0x3D, 0x21, + 0x87, 0x1F, 0xCD, 0x68, 0x23, 0xF6, 0xA8, 0x79, 0xBB, 0x3F, 0x33, 0x95, 0x1C, 0x8E, 0x8E, 0x89, + 0x1D, 0x40, 0x43, 0x88, 0x0B, 0x02, 0xDF, 0xA1, 0xBB, 0x3B, 0xE4, 0x98, 0xB5, 0x0E, 0x75, 0x78, + 0xE6, 0x0D, 0x24, 0x0F, 0x65, 0x85, 0x60, 0x3A, 0x4A, 0xE5, 0x5F, 0x54, 0x9B, 0xC8, 0x79, 0x93, + 0xEB, 0x3D, 0x98, 0x2C, 0xFE, 0x9B, 0xFB, 0x15, 0xB6, 0x88, 0x21, 0x94, 0xB0, 0x05, 0x86, 0x5C, + 0x59, 0x8B, 0x93, 0x7A, 0xDA, 0xD2, 0xA2, 0x14, 0xED, 0xB7, 0xC4, 0x5D, 0xA1, 0xEF, 0x26, 0xF3, + 0xC7, 0x73, 0x29, 0x4D, 0xF1, 0xC8, 0x2C, 0xE0, 0xD0, 0xE9, 0xED, 0x0C, 0x70, 0x75, 0x05, 0x3E, + 0x5B, 0xF6, 0xA0, 0x6E, 0xEA, 0xDE, 0x87, 0x0B, 0x06, 0x29, 0x03, 0xBF, 0xB4, 0x85, 0x9D, 0x04, + 0x75, 0x1A, 0xCD, 0x1E, 0xD6, 0xAA, 0x1B, 0x05, 0x24, 0x6A, 0x2C, 0x80, 0x69, 0x68, 0xDC, 0x97 }; diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index be8792287d..1cb066873e 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -512,7 +512,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si if (VARIANT == xmrig::VARIANT_2) { VARIANT2_INTEGER_MATH(0, cl, cx); lo = __umul128(idx0, cl, &hi); - VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx0, bx1); + VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx0, bx1, hi, lo); } else { lo = __umul128(idx0, cl, &hi); @@ -643,7 +643,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si if (VARIANT == xmrig::VARIANT_2) { VARIANT2_INTEGER_MATH(0, cl, cx0); lo = __umul128(idx0, cl, &hi); - VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx00, bx01); + VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx00, bx01, hi, lo); } else { lo = __umul128(idx0, cl, &hi); } @@ -684,7 +684,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si if (VARIANT == xmrig::VARIANT_2) { VARIANT2_INTEGER_MATH(1, cl, cx1); lo = __umul128(idx1, cl, &hi); - VARIANT2_SHUFFLE(l1, idx1 & MASK, ax1, bx10, bx11); + VARIANT2_SHUFFLE2(l1, idx1 & MASK, ax1, bx10, bx11, hi, lo); } else { lo = __umul128(idx1, cl, &hi); } @@ -772,7 +772,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si if (VARIANT == xmrig::VARIANT_2) { \ VARIANT2_INTEGER_MATH(part, cl##part, c); \ lo = __umul128(idx, cl##part, &hi); \ - VARIANT2_SHUFFLE(l, idx & MASK, a, b0, b1); \ + VARIANT2_SHUFFLE2(l, idx & MASK, a, b0, b1, hi, lo); \ } else { \ lo = __umul128(idx, cl##part, &hi); \ } \ From 232da420fc8db0077149cc6d0d848794886e648c Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 23 Sep 2018 13:05:03 +0300 Subject: [PATCH 075/102] Update libcpuid to recent git version. --- src/3rdparty/libcpuid/asm-bits.c | 1661 +++++++++++---------- src/3rdparty/libcpuid/asm-bits.h | 124 +- src/3rdparty/libcpuid/cpuid_main.c | 56 +- src/3rdparty/libcpuid/libcpuid.h | 39 +- src/3rdparty/libcpuid/libcpuid_internal.h | 5 +- src/3rdparty/libcpuid/libcpuid_types.h | 28 +- src/3rdparty/libcpuid/recog_amd.c | 4 + src/3rdparty/libcpuid/recog_intel.c | 3 +- 8 files changed, 991 insertions(+), 929 deletions(-) diff --git a/src/3rdparty/libcpuid/asm-bits.c b/src/3rdparty/libcpuid/asm-bits.c index b8e32284f5..bfabd404e5 100644 --- a/src/3rdparty/libcpuid/asm-bits.c +++ b/src/3rdparty/libcpuid/asm-bits.c @@ -1,825 +1,836 @@ -/* - * Copyright 2008 Veselin Georgiev, - * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "libcpuid.h" -#include "asm-bits.h" - -int cpuid_exists_by_eflags(void) -{ -#if defined(PLATFORM_X64) - return 1; /* CPUID is always present on the x86_64 */ -#elif defined(PLATFORM_X86) -# if defined(COMPILER_GCC) - int result; - __asm __volatile( - " pushfl\n" - " pop %%eax\n" - " mov %%eax, %%ecx\n" - " xor $0x200000, %%eax\n" - " push %%eax\n" - " popfl\n" - " pushfl\n" - " pop %%eax\n" - " xor %%ecx, %%eax\n" - " mov %%eax, %0\n" - " push %%ecx\n" - " popfl\n" - : "=m"(result) - : :"eax", "ecx", "memory"); - return (result != 0); -# elif defined(COMPILER_MICROSOFT) - int result; - __asm { - pushfd - pop eax - mov ecx, eax - xor eax, 0x200000 - push eax - popfd - pushfd - pop eax - xor eax, ecx - mov result, eax - push ecx - popfd - }; - return (result != 0); -# else - return 0; -# endif /* COMPILER_MICROSOFT */ -#else - return 0; -#endif /* PLATFORM_X86 */ -} - -#ifdef INLINE_ASM_SUPPORTED -/* - * with MSVC/AMD64, the exec_cpuid() and cpu_rdtsc() functions - * are implemented in separate .asm files. Otherwise, use inline assembly - */ -void exec_cpuid(uint32_t *regs) -{ -#ifdef COMPILER_GCC -# ifdef PLATFORM_X64 - __asm __volatile( - " mov %0, %%rdi\n" - - " push %%rbx\n" - " push %%rcx\n" - " push %%rdx\n" - - " mov (%%rdi), %%eax\n" - " mov 4(%%rdi), %%ebx\n" - " mov 8(%%rdi), %%ecx\n" - " mov 12(%%rdi), %%edx\n" - - " cpuid\n" - - " movl %%eax, (%%rdi)\n" - " movl %%ebx, 4(%%rdi)\n" - " movl %%ecx, 8(%%rdi)\n" - " movl %%edx, 12(%%rdi)\n" - " pop %%rdx\n" - " pop %%rcx\n" - " pop %%rbx\n" - : - :"m"(regs) - :"memory", "eax", "rdi" - ); -# else - __asm __volatile( - " mov %0, %%edi\n" - - " push %%ebx\n" - " push %%ecx\n" - " push %%edx\n" - - " mov (%%edi), %%eax\n" - " mov 4(%%edi), %%ebx\n" - " mov 8(%%edi), %%ecx\n" - " mov 12(%%edi), %%edx\n" - - " cpuid\n" - - " mov %%eax, (%%edi)\n" - " mov %%ebx, 4(%%edi)\n" - " mov %%ecx, 8(%%edi)\n" - " mov %%edx, 12(%%edi)\n" - " pop %%edx\n" - " pop %%ecx\n" - " pop %%ebx\n" - : - :"m"(regs) - :"memory", "eax", "edi" - ); -# endif /* COMPILER_GCC */ -#else -# ifdef COMPILER_MICROSOFT - __asm { - push ebx - push ecx - push edx - push edi - mov edi, regs - - mov eax, [edi] - mov ebx, [edi+4] - mov ecx, [edi+8] - mov edx, [edi+12] - - cpuid - - mov [edi], eax - mov [edi+4], ebx - mov [edi+8], ecx - mov [edi+12], edx - - pop edi - pop edx - pop ecx - pop ebx - } -# else -# error "Unsupported compiler" -# endif /* COMPILER_MICROSOFT */ -#endif -} -#endif /* INLINE_ASSEMBLY_SUPPORTED */ - -#ifdef INLINE_ASM_SUPPORTED -void cpu_rdtsc(uint64_t* result) -{ - uint32_t low_part, hi_part; -#ifdef COMPILER_GCC - __asm __volatile ( - " rdtsc\n" - " mov %%eax, %0\n" - " mov %%edx, %1\n" - :"=m"(low_part), "=m"(hi_part)::"memory", "eax", "edx" - ); -#else -# ifdef COMPILER_MICROSOFT - __asm { - rdtsc - mov low_part, eax - mov hi_part, edx - }; -# else -# error "Unsupported compiler" -# endif /* COMPILER_MICROSOFT */ -#endif /* COMPILER_GCC */ - *result = (uint64_t)low_part + (((uint64_t) hi_part) << 32); -} -#endif /* INLINE_ASM_SUPPORTED */ - -#ifdef INLINE_ASM_SUPPORTED -void busy_sse_loop(int cycles) -{ -#ifdef COMPILER_GCC -#ifndef __APPLE__ -# define XALIGN ".balign 16\n" -#else -# define XALIGN ".align 4\n" -#endif - __asm __volatile ( - " xorps %%xmm0, %%xmm0\n" - " xorps %%xmm1, %%xmm1\n" - " xorps %%xmm2, %%xmm2\n" - " xorps %%xmm3, %%xmm3\n" - " xorps %%xmm4, %%xmm4\n" - " xorps %%xmm5, %%xmm5\n" - " xorps %%xmm6, %%xmm6\n" - " xorps %%xmm7, %%xmm7\n" - XALIGN - /* ".bsLoop:\n" */ - "1:\n" - // 0: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - // 1: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - // 2: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - // 3: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - // 4: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - // 5: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - // 6: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - // 7: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - // 8: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - // 9: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //10: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //11: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //12: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //13: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //14: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //15: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //16: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //17: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //18: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //19: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //20: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //21: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //22: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //23: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //24: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //25: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //26: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //27: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //28: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //29: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //30: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - //31: - " addps %%xmm1, %%xmm0\n" - " addps %%xmm2, %%xmm1\n" - " addps %%xmm3, %%xmm2\n" - " addps %%xmm4, %%xmm3\n" - " addps %%xmm5, %%xmm4\n" - " addps %%xmm6, %%xmm5\n" - " addps %%xmm7, %%xmm6\n" - " addps %%xmm0, %%xmm7\n" - - " dec %%eax\n" - /* "jnz .bsLoop\n" */ - " jnz 1b\n" - ::"a"(cycles) - ); -#else -# ifdef COMPILER_MICROSOFT - __asm { - mov eax, cycles - xorps xmm0, xmm0 - xorps xmm1, xmm1 - xorps xmm2, xmm2 - xorps xmm3, xmm3 - xorps xmm4, xmm4 - xorps xmm5, xmm5 - xorps xmm6, xmm6 - xorps xmm7, xmm7 - //-- - align 16 -bsLoop: - // 0: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 1: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 2: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 3: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 4: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 5: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 6: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 7: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 8: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 9: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 10: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 11: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 12: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 13: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 14: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 15: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 16: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 17: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 18: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 19: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 20: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 21: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 22: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 23: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 24: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 25: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 26: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 27: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 28: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 29: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 30: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - // 31: - addps xmm0, xmm1 - addps xmm1, xmm2 - addps xmm2, xmm3 - addps xmm3, xmm4 - addps xmm4, xmm5 - addps xmm5, xmm6 - addps xmm6, xmm7 - addps xmm7, xmm0 - //---------------------- - dec eax - jnz bsLoop - } -# else -# error "Unsupported compiler" -# endif /* COMPILER_MICROSOFT */ -#endif /* COMPILER_GCC */ -} -#endif /* INLINE_ASSEMBLY_SUPPORTED */ +/* + * Copyright 2008 Veselin Georgiev, + * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "libcpuid.h" +#include "asm-bits.h" + +int cpuid_exists_by_eflags(void) +{ +#if defined(PLATFORM_X64) + return 1; /* CPUID is always present on the x86_64 */ +#elif defined(PLATFORM_X86) +# if defined(COMPILER_GCC) || defined(COMPILER_CLANG) + int result; + __asm __volatile( + " pushfl\n" + " pop %%eax\n" + " mov %%eax, %%ecx\n" + " xor $0x200000, %%eax\n" + " push %%eax\n" + " popfl\n" + " pushfl\n" + " pop %%eax\n" + " xor %%ecx, %%eax\n" + " mov %%eax, %0\n" + " push %%ecx\n" + " popfl\n" + : "=m"(result) + : :"eax", "ecx", "memory"); + return (result != 0); +# elif defined(COMPILER_MICROSOFT) + int result; + __asm { + pushfd + pop eax + mov ecx, eax + xor eax, 0x200000 + push eax + popfd + pushfd + pop eax + xor eax, ecx + mov result, eax + push ecx + popfd + }; + return (result != 0); +# else + return 0; +# endif /* COMPILER_MICROSOFT */ +#elif defined(PLATFORM_ARM) + return 0; +#else + return 0; +#endif /* PLATFORM_X86 */ +} + +#ifdef INLINE_ASM_SUPPORTED +/* + * with MSVC/AMD64, the exec_cpuid() and cpu_rdtsc() functions + * are implemented in separate .asm files. Otherwise, use inline assembly + */ +void exec_cpuid(uint32_t *regs) +{ +# if defined(COMPILER_GCC) || defined(COMPILER_CLANG) +# ifdef PLATFORM_X64 + __asm __volatile( + " mov %0, %%rdi\n" + + " push %%rbx\n" + " push %%rcx\n" + " push %%rdx\n" + + " mov (%%rdi), %%eax\n" + " mov 4(%%rdi), %%ebx\n" + " mov 8(%%rdi), %%ecx\n" + " mov 12(%%rdi), %%edx\n" + + " cpuid\n" + + " movl %%eax, (%%rdi)\n" + " movl %%ebx, 4(%%rdi)\n" + " movl %%ecx, 8(%%rdi)\n" + " movl %%edx, 12(%%rdi)\n" + " pop %%rdx\n" + " pop %%rcx\n" + " pop %%rbx\n" + : + :"m"(regs) + :"memory", "eax", "rdi" + ); +# elif defined(PLATFORM_X86) + __asm __volatile( + " mov %0, %%edi\n" + + " push %%ebx\n" + " push %%ecx\n" + " push %%edx\n" + + " mov (%%edi), %%eax\n" + " mov 4(%%edi), %%ebx\n" + " mov 8(%%edi), %%ecx\n" + " mov 12(%%edi), %%edx\n" + + " cpuid\n" + + " mov %%eax, (%%edi)\n" + " mov %%ebx, 4(%%edi)\n" + " mov %%ecx, 8(%%edi)\n" + " mov %%edx, 12(%%edi)\n" + " pop %%edx\n" + " pop %%ecx\n" + " pop %%ebx\n" + : + :"m"(regs) + :"memory", "eax", "edi" + ); +# elif defined(PLATFORM_ARM) +# endif /* COMPILER_GCC */ +#else +# ifdef COMPILER_MICROSOFT + __asm { + push ebx + push ecx + push edx + push edi + mov edi, regs + + mov eax, [edi] + mov ebx, [edi+4] + mov ecx, [edi+8] + mov edx, [edi+12] + + cpuid + + mov [edi], eax + mov [edi+4], ebx + mov [edi+8], ecx + mov [edi+12], edx + + pop edi + pop edx + pop ecx + pop ebx + } +# else +# error "Unsupported compiler" +# endif /* COMPILER_MICROSOFT */ +#endif +} +#endif /* INLINE_ASSEMBLY_SUPPORTED */ + +#ifdef INLINE_ASM_SUPPORTED +void cpu_rdtsc(uint64_t* result) +{ + uint32_t low_part, hi_part; +#if defined(COMPILER_GCC) || defined(COMPILER_CLANG) +#ifdef PLATFORM_ARM + low_part = 0; + hi_part = 0; +#else + __asm __volatile ( + " rdtsc\n" + " mov %%eax, %0\n" + " mov %%edx, %1\n" + :"=m"(low_part), "=m"(hi_part)::"memory", "eax", "edx" + ); +#endif +#else +# ifdef COMPILER_MICROSOFT + __asm { + rdtsc + mov low_part, eax + mov hi_part, edx + }; +# else +# error "Unsupported compiler" +# endif /* COMPILER_MICROSOFT */ +#endif /* COMPILER_GCC */ + *result = (uint64_t)low_part + (((uint64_t) hi_part) << 32); +} +#endif /* INLINE_ASM_SUPPORTED */ + +#ifdef INLINE_ASM_SUPPORTED +void busy_sse_loop(int cycles) +{ +# if defined(COMPILER_GCC) || defined(COMPILER_CLANG) +#ifndef __APPLE__ +# define XALIGN ".balign 16\n" +#else +# define XALIGN ".align 4\n" +#endif +#ifdef PLATFORM_ARM +#else + __asm __volatile ( + " xorps %%xmm0, %%xmm0\n" + " xorps %%xmm1, %%xmm1\n" + " xorps %%xmm2, %%xmm2\n" + " xorps %%xmm3, %%xmm3\n" + " xorps %%xmm4, %%xmm4\n" + " xorps %%xmm5, %%xmm5\n" + " xorps %%xmm6, %%xmm6\n" + " xorps %%xmm7, %%xmm7\n" + XALIGN + /* ".bsLoop:\n" */ + "1:\n" + // 0: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + // 1: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + // 2: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + // 3: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + // 4: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + // 5: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + // 6: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + // 7: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + // 8: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + // 9: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //10: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //11: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //12: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //13: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //14: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //15: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //16: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //17: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //18: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //19: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //20: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //21: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //22: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //23: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //24: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //25: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //26: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //27: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //28: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //29: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //30: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + //31: + " addps %%xmm1, %%xmm0\n" + " addps %%xmm2, %%xmm1\n" + " addps %%xmm3, %%xmm2\n" + " addps %%xmm4, %%xmm3\n" + " addps %%xmm5, %%xmm4\n" + " addps %%xmm6, %%xmm5\n" + " addps %%xmm7, %%xmm6\n" + " addps %%xmm0, %%xmm7\n" + + " dec %%eax\n" + /* "jnz .bsLoop\n" */ + " jnz 1b\n" + ::"a"(cycles) + ); +#endif +#else +# ifdef COMPILER_MICROSOFT + __asm { + mov eax, cycles + xorps xmm0, xmm0 + xorps xmm1, xmm1 + xorps xmm2, xmm2 + xorps xmm3, xmm3 + xorps xmm4, xmm4 + xorps xmm5, xmm5 + xorps xmm6, xmm6 + xorps xmm7, xmm7 + //-- + align 16 +bsLoop: + // 0: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 1: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 2: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 3: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 4: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 5: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 6: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 7: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 8: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 9: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 10: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 11: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 12: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 13: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 14: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 15: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 16: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 17: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 18: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 19: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 20: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 21: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 22: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 23: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 24: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 25: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 26: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 27: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 28: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 29: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 30: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + // 31: + addps xmm0, xmm1 + addps xmm1, xmm2 + addps xmm2, xmm3 + addps xmm3, xmm4 + addps xmm4, xmm5 + addps xmm5, xmm6 + addps xmm6, xmm7 + addps xmm7, xmm0 + //---------------------- + dec eax + jnz bsLoop + } +# else +# error "Unsupported compiler" +# endif /* COMPILER_MICROSOFT */ +#endif /* COMPILER_GCC */ +} +#endif /* INLINE_ASSEMBLY_SUPPORTED */ \ No newline at end of file diff --git a/src/3rdparty/libcpuid/asm-bits.h b/src/3rdparty/libcpuid/asm-bits.h index 3a03e11ce8..9049e2fe98 100644 --- a/src/3rdparty/libcpuid/asm-bits.h +++ b/src/3rdparty/libcpuid/asm-bits.h @@ -1,53 +1,71 @@ -/* - * Copyright 2008 Veselin Georgiev, - * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __ASM_BITS_H__ -#define __ASM_BITS_H__ -#include "libcpuid.h" - -/* Determine Compiler: */ -#if defined(_MSC_VER) -# define COMPILER_MICROSOFT -#elif defined(__GNUC__) -# define COMPILER_GCC -#endif - -/* Determine Platform */ -#if defined(__x86_64__) || defined(_M_AMD64) -# define PLATFORM_X64 -#elif defined(__i386__) || defined(_M_IX86) -# define PLATFORM_X86 -#endif - -/* Under Windows/AMD64 with MSVC, inline assembly isn't supported */ -#if (defined(COMPILER_GCC) && defined(PLATFORM_X64)) || defined(PLATFORM_X86) -# define INLINE_ASM_SUPPORTED -#endif - -int cpuid_exists_by_eflags(void); -void exec_cpuid(uint32_t *regs); -void busy_sse_loop(int cycles); - -#endif /* __ASM_BITS_H__ */ +/* + * Copyright 2008 Veselin Georgiev, + * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __ASM_BITS_H__ +#define __ASM_BITS_H__ +#include "libcpuid.h" + +/* Determine Compiler: */ +#if defined(_MSC_VER) +#if !defined(COMPILER_MICROSOFT) +# define COMPILER_MICROSOFT +#endif +#elif defined(__GNUC__) +#if !defined(COMPILER_GCC) +# define COMPILER_GCC +#endif +#elif defined(__clang__) +#if !defined(COMPILER_CLANG) +# define COMPILER_CLANG +#endif +#endif + +/* Determine Platform */ +#if defined(__x86_64__) || defined(_M_AMD64) +#if !defined(PLATFORM_X64) +# define PLATFORM_X64 +#endif +#elif defined(__i386__) || defined(_M_IX86) +#if !defined(PLATFORM_X86) +# define PLATFORM_X86 +#endif +#elif defined(__ARMEL__) +#if !defined(PLATFORM_ARM) +# define PLATFORM_ARM +#endif +#endif + +/* Under Windows/AMD64 with MSVC, inline assembly isn't supported */ +#if (((defined(COMPILER_GCC) || defined(COMPILER_CLANG))) && \ + (defined(PLATFORM_X64) || defined(PLATFORM_X86) || defined(PLATFORM_ARM))) || \ + (defined(COMPILER_MICROSOFT) && defined(PLATFORM_X86)) +# define INLINE_ASM_SUPPORTED +#endif + +int cpuid_exists_by_eflags(void); +void exec_cpuid(uint32_t *regs); +void busy_sse_loop(int cycles); + +#endif /* __ASM_BITS_H__ */ diff --git a/src/3rdparty/libcpuid/cpuid_main.c b/src/3rdparty/libcpuid/cpuid_main.c index f22c7dd699..61cb638db0 100644 --- a/src/3rdparty/libcpuid/cpuid_main.c +++ b/src/3rdparty/libcpuid/cpuid_main.c @@ -221,42 +221,42 @@ static void load_features_common(struct cpu_raw_data_t* raw, struct cpu_id_t* da static cpu_vendor_t cpuid_vendor_identify(const uint32_t *raw_vendor, char *vendor_str) { - int i; - cpu_vendor_t vendor = VENDOR_UNKNOWN; - const struct { cpu_vendor_t vendor; char match[16]; } - matchtable[NUM_CPU_VENDORS] = { - /* source: http://www.sandpile.org/ia32/cpuid.htm */ - { VENDOR_INTEL , "GenuineIntel" }, - { VENDOR_AMD , "AuthenticAMD" }, - { VENDOR_CYRIX , "CyrixInstead" }, - { VENDOR_NEXGEN , "NexGenDriven" }, - { VENDOR_TRANSMETA , "GenuineTMx86" }, - { VENDOR_UMC , "UMC UMC UMC " }, - { VENDOR_CENTAUR , "CentaurHauls" }, - { VENDOR_RISE , "RiseRiseRise" }, - { VENDOR_SIS , "SiS SiS SiS " }, - { VENDOR_NSC , "Geode by NSC" }, - }; + int i; + cpu_vendor_t vendor = VENDOR_UNKNOWN; + const struct { cpu_vendor_t vendor; char match[16]; } + matchtable[NUM_CPU_VENDORS] = { + /* source: http://www.sandpile.org/ia32/cpuid.htm */ + { VENDOR_INTEL , "GenuineIntel" }, + { VENDOR_AMD , "AuthenticAMD" }, + { VENDOR_CYRIX , "CyrixInstead" }, + { VENDOR_NEXGEN , "NexGenDriven" }, + { VENDOR_TRANSMETA , "GenuineTMx86" }, + { VENDOR_UMC , "UMC UMC UMC " }, + { VENDOR_CENTAUR , "CentaurHauls" }, + { VENDOR_RISE , "RiseRiseRise" }, + { VENDOR_SIS , "SiS SiS SiS " }, + { VENDOR_NSC , "Geode by NSC" }, + }; - memcpy(vendor_str + 0, &raw_vendor[1], 4); - memcpy(vendor_str + 4, &raw_vendor[3], 4); - memcpy(vendor_str + 8, &raw_vendor[2], 4); - vendor_str[12] = 0; + memcpy(vendor_str + 0, &raw_vendor[1], 4); + memcpy(vendor_str + 4, &raw_vendor[3], 4); + memcpy(vendor_str + 8, &raw_vendor[2], 4); + vendor_str[12] = 0; - /* Determine vendor: */ - for (i = 0; i < NUM_CPU_VENDORS; i++) - if (!strcmp(vendor_str, matchtable[i].match)) { - vendor = matchtable[i].vendor; - break; - } - return vendor; + /* Determine vendor: */ + for (i = 0; i < NUM_CPU_VENDORS; i++) + if (!strcmp(vendor_str, matchtable[i].match)) { + vendor = matchtable[i].vendor; + break; + } + return vendor; } static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* data) { int i, j, basic, xmodel, xfamily, ext; char brandstr[64] = {0}; - data->vendor = cpuid_vendor_identify(raw->basic_cpuid[0], data->vendor_str); + data->vendor = cpuid_vendor_identify(raw->basic_cpuid[0], data->vendor_str); if (data->vendor == VENDOR_UNKNOWN) return set_error(ERR_CPU_UNKN); diff --git a/src/3rdparty/libcpuid/libcpuid.h b/src/3rdparty/libcpuid/libcpuid.h index c44990c316..847e5a4a84 100644 --- a/src/3rdparty/libcpuid/libcpuid.h +++ b/src/3rdparty/libcpuid/libcpuid.h @@ -60,7 +60,7 @@ */ /** @mainpage A simple libcpuid introduction - * + * * LibCPUID provides CPU identification and access to the CPUID and RDTSC * instructions on the x86. *

@@ -82,6 +82,7 @@ */ /** @defgroup libcpuid LibCPUID + * @brief LibCPUID provides CPU identification @{ */ /* Include some integer type specifications: */ @@ -535,23 +536,23 @@ typedef enum { * @brief Describes common library error codes */ typedef enum { - ERR_OK = 0, /*!< "No error" */ - ERR_NO_CPUID = -1, /*!< "CPUID instruction is not supported" */ - ERR_NO_RDTSC = -2, /*!< "RDTSC instruction is not supported" */ - ERR_NO_MEM = -3, /*!< "Memory allocation failed" */ - ERR_OPEN = -4, /*!< "File open operation failed" */ - ERR_BADFMT = -5, /*!< "Bad file format" */ - ERR_NOT_IMP = -6, /*!< "Not implemented" */ - ERR_CPU_UNKN = -7, /*!< "Unsupported processor" */ - ERR_NO_RDMSR = -8, /*!< "RDMSR instruction is not supported" */ - ERR_NO_DRIVER= -9, /*!< "RDMSR driver error (generic)" */ - ERR_NO_PERMS = -10, /*!< "No permissions to install RDMSR driver" */ - ERR_EXTRACT = -11, /*!< "Cannot extract RDMSR driver (read only media?)" */ - ERR_HANDLE = -12, /*!< "Bad handle" */ - ERR_INVMSR = -13, /*!< "Invalid MSR" */ - ERR_INVCNB = -14, /*!< "Invalid core number" */ - ERR_HANDLE_R = -15, /*!< "Error on handle read" */ - ERR_INVRANGE = -16, /*!< "Invalid given range" */ + ERR_OK = 0, /*!< No error */ + ERR_NO_CPUID = -1, /*!< CPUID instruction is not supported */ + ERR_NO_RDTSC = -2, /*!< RDTSC instruction is not supported */ + ERR_NO_MEM = -3, /*!< Memory allocation failed */ + ERR_OPEN = -4, /*!< File open operation failed */ + ERR_BADFMT = -5, /*!< Bad file format */ + ERR_NOT_IMP = -6, /*!< Not implemented */ + ERR_CPU_UNKN = -7, /*!< Unsupported processor */ + ERR_NO_RDMSR = -8, /*!< RDMSR instruction is not supported */ + ERR_NO_DRIVER= -9, /*!< RDMSR driver error (generic) */ + ERR_NO_PERMS = -10, /*!< No permissions to install RDMSR driver */ + ERR_EXTRACT = -11, /*!< Cannot extract RDMSR driver (read only media?) */ + ERR_HANDLE = -12, /*!< Bad handle */ + ERR_INVMSR = -13, /*!< Invalid MSR */ + ERR_INVCNB = -14, /*!< Invalid core number */ + ERR_HANDLE_R = -15, /*!< Error on handle read */ + ERR_INVRANGE = -16, /*!< Invalid given range */ } cpu_error_t; /** @@ -668,7 +669,7 @@ struct cpu_epc_t cpuid_get_epc(int index, const struct cpu_raw_data_t* raw); const char* cpuid_lib_version(void); #ifdef __cplusplus -}; /* extern "C" */ +} /* extern "C" */ #endif diff --git a/src/3rdparty/libcpuid/libcpuid_internal.h b/src/3rdparty/libcpuid/libcpuid_internal.h index 038aa2092d..6480461625 100644 --- a/src/3rdparty/libcpuid/libcpuid_internal.h +++ b/src/3rdparty/libcpuid/libcpuid_internal.h @@ -75,8 +75,9 @@ enum _intel_bits_t { _3 = LBIT( 14 ), _5 = LBIT( 15 ), _7 = LBIT( 16 ), - XEON_ = LBIT( 17 ), - ATOM_ = LBIT( 18 ), + _9 = LBIT( 17 ), + XEON_ = LBIT( 18 ), + ATOM_ = LBIT( 19 ), }; typedef enum _intel_bits_t intel_bits_t; diff --git a/src/3rdparty/libcpuid/libcpuid_types.h b/src/3rdparty/libcpuid/libcpuid_types.h index 9e897275f8..0e667aa671 100644 --- a/src/3rdparty/libcpuid/libcpuid_types.h +++ b/src/3rdparty/libcpuid/libcpuid_types.h @@ -32,6 +32,32 @@ #ifndef __LIBCPUID_TYPES_H__ #define __LIBCPUID_TYPES_H__ -#include +#if !defined(_MSC_VER) || _MSC_VER >= 1600 +# include +#else +/* we have to provide our own: */ +# if !defined(__int32_t_defined) +typedef int int32_t; +# endif + +# if !defined(__uint32_t_defined) +typedef unsigned uint32_t; +# endif + +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +#if (defined _MSC_VER) && (_MSC_VER <= 1300) + /* MSVC 6.0: no long longs ... */ + typedef signed __int64 int64_t; + typedef unsigned __int64 uint64_t; +#else + /* all other sane compilers: */ + typedef signed long long int64_t; + typedef unsigned long long uint64_t; +#endif + +#endif #endif /* __LIBCPUID_TYPES_H__ */ diff --git a/src/3rdparty/libcpuid/recog_amd.c b/src/3rdparty/libcpuid/recog_amd.c index 352d733b8e..4726f63396 100644 --- a/src/3rdparty/libcpuid/recog_amd.c +++ b/src/3rdparty/libcpuid/recog_amd.c @@ -49,6 +49,10 @@ enum _amd_model_codes_t { _1400, _1500, _1600, + _1900, + _2400, + _2500, + _2700, }; static void load_amd_features(struct cpu_raw_data_t* raw, struct cpu_id_t* data) diff --git a/src/3rdparty/libcpuid/recog_intel.c b/src/3rdparty/libcpuid/recog_intel.c index 5467c19f0f..397d750e1e 100644 --- a/src/3rdparty/libcpuid/recog_intel.c +++ b/src/3rdparty/libcpuid/recog_intel.c @@ -376,7 +376,7 @@ static intel_code_and_bits_t get_brand_code_and_bits(struct cpu_id_t* data) bits |= bit_matchtable[i].bit; } - if ((i = match_pattern(bs, "Core(TM) [im][357]")) != 0) { + if ((i = match_pattern(bs, "Core(TM) [im][3579]")) != 0) { bits |= CORE_; i--; switch (bs[i + 9]) { @@ -387,6 +387,7 @@ static intel_code_and_bits_t get_brand_code_and_bits(struct cpu_id_t* data) case '3': bits |= _3; break; case '5': bits |= _5; break; case '7': bits |= _7; break; + case '9': bits |= _9; break; } } for (i = 0; i < COUNT_OF(matchtable); i++) From 6c445050f9c30f597c82e11f0a9d7f2dd9999b78 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 23 Sep 2018 17:51:56 +0300 Subject: [PATCH 076/102] Old static class Cpu replaced to interface ICpuInfo. --- CMakeLists.txt | 13 +- src/App.cpp | 2 +- src/Cpu.h | 66 ---------- src/Summary.cpp | 18 +-- src/api/ApiRouter.cpp | 11 +- .../cpu/BasicCpuInfo.cpp} | 52 ++------ src/common/cpu/BasicCpuInfo.h | 70 ++++++++++ .../cpu/BasicCpuInfo_arm.cpp} | 34 ++--- src/{Cpu_unix.cpp => common/cpu/Cpu.cpp} | 41 +++--- src/{Cpu_mac.cpp => common/cpu/Cpu.h} | 28 ++-- src/common/interfaces/ICpuInfo.h | 59 +++++++++ src/common/xmrig.h | 8 ++ src/core/Config.cpp | 18 +-- src/core/Controller.cpp | 2 +- src/{Cpu.cpp => core/cpu/AdvancedCpuInfo.cpp} | 124 ++++++++---------- src/core/cpu/AdvancedCpuInfo.h | 75 +++++++++++ src/{Cpu_win.cpp => core/cpu/Cpu.cpp} | 38 ++++-- src/workers/Worker.cpp | 4 +- 18 files changed, 394 insertions(+), 269 deletions(-) delete mode 100644 src/Cpu.h rename src/{Cpu_stub.cpp => common/cpu/BasicCpuInfo.cpp} (77%) create mode 100644 src/common/cpu/BasicCpuInfo.h rename src/{Cpu_arm.cpp => common/cpu/BasicCpuInfo_arm.cpp} (74%) rename src/{Cpu_unix.cpp => common/cpu/Cpu.cpp} (71%) rename src/{Cpu_mac.cpp => common/cpu/Cpu.h} (75%) create mode 100644 src/common/interfaces/ICpuInfo.h rename src/{Cpu.cpp => core/cpu/AdvancedCpuInfo.cpp} (57%) create mode 100644 src/core/cpu/AdvancedCpuInfo.h rename src/{Cpu_win.cpp => core/cpu/Cpu.cpp} (69%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b779b74d4c..6f7d629104 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ set(HEADERS src/common/config/ConfigLoader.h src/common/config/ConfigWatcher.h src/common/Console.h + src/common/cpu/Cpu.h src/common/crypto/Algorithm.h src/common/crypto/keccak.h src/common/interfaces/IClientListener.h @@ -27,6 +28,7 @@ set(HEADERS src/common/interfaces/IConfigCreator.h src/common/interfaces/IConsoleListener.h src/common/interfaces/IControllerListener.h + src/common/interfaces/ICpuInfo.h src/common/interfaces/ILogBackend.h src/common/interfaces/IStrategy.h src/common/interfaces/IStrategyListener.h @@ -49,7 +51,6 @@ set(HEADERS src/common/xmrig.h src/core/ConfigLoader_platform.h src/core/Controller.h - src/Cpu.h src/interfaces/IJobResultListener.h src/interfaces/IThread.h src/interfaces/IWorker.h @@ -135,7 +136,6 @@ if (WIN32) res/app.rc src/App_win.cpp src/common/Platform_win.cpp - src/Cpu_win.cpp src/Mem_win.cpp ) @@ -145,14 +145,12 @@ elseif (APPLE) set(SOURCES_OS src/App_unix.cpp src/common/Platform_mac.cpp - src/Cpu_mac.cpp src/Mem_unix.cpp ) else() set(SOURCES_OS src/App_unix.cpp src/common/Platform_unix.cpp - src/Cpu_unix.cpp src/Mem_unix.cpp ) @@ -184,14 +182,15 @@ if (WITH_LIBCPUID) include_directories(src/3rdparty/libcpuid) set(CPUID_LIB cpuid) - set(SOURCES_CPUID src/Cpu.cpp) + set(SOURCES_CPUID src/core/cpu/AdvancedCpuInfo.h src/core/cpu/AdvancedCpuInfo.cpp src/core/cpu/Cpu.cpp) else() add_definitions(/DXMRIG_NO_LIBCPUID) + set(SOURCES_CPUID src/common/cpu/BasicCpuInfo.h src/common/cpu/Cpu.cpp) if (XMRIG_ARM) - set(SOURCES_CPUID src/Cpu_arm.cpp) + set(SOURCES_CPUID ${SOURCES_CPUID} src/common/cpu/BasicCpuInfo_arm.cpp) else() - set(SOURCES_CPUID src/Cpu_stub.cpp) + set(SOURCES_CPUID ${SOURCES_CPUID} src/common/cpu/BasicCpuInfo.cpp) endif() endif() diff --git a/src/App.cpp b/src/App.cpp index adcc575245..134e4ef56e 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -29,11 +29,11 @@ #include "api/Api.h" #include "App.h" #include "common/Console.h" +#include "common/cpu/Cpu.h" #include "common/log/Log.h" #include "common/Platform.h" #include "core/Config.h" #include "core/Controller.h" -#include "Cpu.h" #include "crypto/CryptoNight.h" #include "Mem.h" #include "net/Network.h" diff --git a/src/Cpu.h b/src/Cpu.h deleted file mode 100644 index a125bae807..0000000000 --- a/src/Cpu.h +++ /dev/null @@ -1,66 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , - * - * 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 Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __CPU_H__ -#define __CPU_H__ - - -#include - - -class Cpu -{ -public: - enum Flags { - X86_64 = 1, - AES = 2, - BMI2 = 4 - }; - - static size_t optimalThreadsCount(size_t size, int maxCpuUsage); - static void init(); - - static inline bool hasAES() { return (m_flags & AES) != 0; } - static inline bool isX64() { return (m_flags & X86_64) != 0; } - static inline const char *brand() { return m_brand; } - static inline int cores() { return m_totalCores; } - static inline int l2() { return m_l2_cache; } - static inline int l3() { return m_l3_cache; } - static inline int sockets() { return m_sockets; } - static inline int threads() { return m_totalThreads; } - -private: - static void initCommon(); - - static bool m_l2_exclusive; - static char m_brand[64]; - static int m_flags; - static int m_l2_cache; - static int m_l3_cache; - static int m_sockets; - static int m_totalCores; - static size_t m_totalThreads; -}; - - -#endif /* __CPU_H__ */ diff --git a/src/Summary.cpp b/src/Summary.cpp index de6b1234c7..ba220e5b10 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -27,11 +27,11 @@ #include +#include "common/cpu/Cpu.h" #include "common/log/Log.h" #include "common/net/Pool.h" #include "core/Config.h" #include "core/Controller.h" -#include "Cpu.h" #include "Mem.h" #include "Summary.h" #include "version.h" @@ -52,21 +52,23 @@ static void print_memory(xmrig::Config *config) { static void print_cpu(xmrig::Config *config) { + using namespace xmrig; + if (config->isColors()) { Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%d)") " %sx64 %sAES", "CPU", - Cpu::brand(), - Cpu::sockets(), - Cpu::isX64() ? "\x1B[1;32m" : "\x1B[1;31m-", - Cpu::hasAES() ? "\x1B[1;32m" : "\x1B[1;31m-"); + Cpu::info()->brand(), + Cpu::info()->sockets(), + Cpu::info()->isX64() ? "\x1B[1;32m" : "\x1B[1;31m-", + Cpu::info()->hasAES() ? "\x1B[1;32m" : "\x1B[1;31m-"); # ifndef XMRIG_NO_LIBCPUID - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%.1f MB/%.1f MB"), "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%.1f MB/%.1f MB"), "CPU L2/L3", Cpu::info()->L2() / 1024.0, Cpu::info()->L3() / 1024.0); # endif } else { - Log::i()->text(" * %-13s%s (%d) %sx64 %sAES", "CPU", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); + Log::i()->text(" * %-13s%s (%d) %sx64 %sAES", "CPU", Cpu::info()->brand(), Cpu::info()->sockets(), Cpu::info()->isX64() ? "" : "-", Cpu::info()->hasAES() ? "" : "-"); # ifndef XMRIG_NO_LIBCPUID - Log::i()->text(" * %-13s%.1f MB/%.1f MB", "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); + Log::i()->text(" * %-13s%.1f MB/%.1f MB", "CPU L2/L3", Cpu::info()->L2() / 1024.0, Cpu::info()->L3() / 1024.0); # endif } } diff --git a/src/api/ApiRouter.cpp b/src/api/ApiRouter.cpp index 2c62696ac6..dd7accf69e 100644 --- a/src/api/ApiRouter.cpp +++ b/src/api/ApiRouter.cpp @@ -35,12 +35,12 @@ #include "api/ApiRouter.h" #include "common/api/HttpReply.h" #include "common/api/HttpRequest.h" +#include "common/cpu/Cpu.h" #include "common/crypto/keccak.h" #include "common/net/Job.h" #include "common/Platform.h" #include "core/Config.h" #include "core/Controller.h" -#include "Cpu.h" #include "interfaces/IThread.h" #include "rapidjson/document.h" #include "rapidjson/prettywriter.h" @@ -238,13 +238,14 @@ void ApiRouter::getIdentify(rapidjson::Document &doc) const void ApiRouter::getMiner(rapidjson::Document &doc) const { + using namespace xmrig; auto &allocator = doc.GetAllocator(); rapidjson::Value cpu(rapidjson::kObjectType); - cpu.AddMember("brand", rapidjson::StringRef(Cpu::brand()), allocator); - cpu.AddMember("aes", Cpu::hasAES(), allocator); - cpu.AddMember("x64", Cpu::isX64(), allocator); - cpu.AddMember("sockets", Cpu::sockets(), allocator); + cpu.AddMember("brand", rapidjson::StringRef(Cpu::info()->brand()), allocator); + cpu.AddMember("aes", Cpu::info()->hasAES(), allocator); + cpu.AddMember("x64", Cpu::info()->isX64(), allocator); + cpu.AddMember("sockets", Cpu::info()->sockets(), allocator); doc.AddMember("version", APP_VERSION, allocator); doc.AddMember("kind", APP_KIND, allocator); diff --git a/src/Cpu_stub.cpp b/src/common/cpu/BasicCpuInfo.cpp similarity index 77% rename from src/Cpu_stub.cpp rename to src/common/cpu/BasicCpuInfo.cpp index 8b27ad657b..66af53ccf1 100644 --- a/src/Cpu_stub.cpp +++ b/src/common/cpu/BasicCpuInfo.cpp @@ -21,6 +21,9 @@ * along with this program. If not, see . */ +#include +#include + #ifdef _MSC_VER # include @@ -32,14 +35,8 @@ # define bit_AES (1 << 25) #endif -#ifndef bit_BMI2 -# define bit_BMI2 (1 << 8) -#endif - -#include - -#include "Cpu.h" +#include "common/cpu/BasicCpuInfo.h" #define VENDOR_ID (0) @@ -96,43 +93,18 @@ static inline bool has_aes_ni() } -static inline bool has_bmi2() { - int cpu_info[4] = { 0 }; - cpuid(EXTENDED_FEATURES, cpu_info); - - return (cpu_info[EBX_Reg] & bit_BMI2) != 0; -} - - -char Cpu::m_brand[64] = { 0 }; -int Cpu::m_flags = 0; -int Cpu::m_l2_cache = 0; -int Cpu::m_l3_cache = 0; -int Cpu::m_sockets = 1; -int Cpu::m_totalCores = 0; -size_t Cpu::m_totalThreads = 0; - - -size_t Cpu::optimalThreadsCount(size_t size, int maxCpuUsage) +xmrig::BasicCpuInfo::BasicCpuInfo() : + m_aes(has_aes_ni()), + m_brand(), + m_threads(std::thread::hardware_concurrency()) { - const size_t count = m_totalThreads / 2; - return count < 1 ? 1 : count; + cpu_brand_string(m_brand); } -void Cpu::initCommon() +size_t xmrig::BasicCpuInfo::optimalThreadsCount(size_t memSize, int maxCpuUsage) const { - cpu_brand_string(m_brand); + const size_t count = threads() / 2; -# if defined(__x86_64__) || defined(_M_AMD64) - m_flags |= X86_64; -# endif - - if (has_aes_ni()) { - m_flags |= AES; - } - - if (has_bmi2()) { - m_flags |= BMI2; - } + return count < 1 ? 1 : count; } diff --git a/src/common/cpu/BasicCpuInfo.h b/src/common/cpu/BasicCpuInfo.h new file mode 100644 index 0000000000..f9d710d6f1 --- /dev/null +++ b/src/common/cpu/BasicCpuInfo.h @@ -0,0 +1,70 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * + * + * 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 Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_BASICCPUINFO_H +#define XMRIG_BASICCPUINFO_H + + +#include "common/interfaces/ICpuInfo.h" + + +namespace xmrig { + + +class BasicCpuInfo : public ICpuInfo +{ +public: + BasicCpuInfo(); + +protected: + size_t optimalThreadsCount(size_t memSize, int maxCpuUsage) const override; + + inline Assembly assembly() const override { return ASM_NONE; } + inline bool hasAES() const override { return m_aes; } + inline bool isSupported() const override { return true; } + inline const char *brand() const override { return m_brand; } + inline int32_t cores() const override { return -1; } + inline int32_t L2() const override { return -1; } + inline int32_t L3() const override { return -1; } + inline int32_t nodes() const override { return -1; } + inline int32_t sockets() const override { return 1; } + inline int32_t threads() const override { return m_threads; } + +# if defined(__x86_64__) || defined(_M_AMD64) || defined (__arm64__) || defined (__aarch64__) + inline bool isX64() const override { return true; } +# else + inline bool isX64() const override { return false; } +# endif + +private: + bool m_aes; + char m_brand[64]; + int32_t m_threads; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_BASICCPUINFO_H */ diff --git a/src/Cpu_arm.cpp b/src/common/cpu/BasicCpuInfo_arm.cpp similarity index 74% rename from src/Cpu_arm.cpp rename to src/common/cpu/BasicCpuInfo_arm.cpp index 3e259d0d85..34eb73882e 100644 --- a/src/Cpu_arm.cpp +++ b/src/common/cpu/BasicCpuInfo_arm.cpp @@ -21,37 +21,27 @@ * along with this program. If not, see . */ - #include +#include -#include "Cpu.h" - - -char Cpu::m_brand[64] = { 0 }; -int Cpu::m_flags = 0; -int Cpu::m_l2_cache = 0; -int Cpu::m_l3_cache = 0; -int Cpu::m_sockets = 1; -int Cpu::m_totalCores = 0; -size_t Cpu::m_totalThreads = 0; - - -size_t Cpu::optimalThreadsCount(size_t size, int maxCpuUsage) -{ - return m_totalThreads; -} +#include "common/cpu/BasicCpuInfo.h" -void Cpu::initCommon() +xmrig::BasicCpuInfo::BasicCpuInfo() : + m_aes(false), + m_brand(), + m_threads(std::thread::hardware_concurrency()) { memcpy(m_brand, "Unknown", 7); -# if defined (__arm64__) || defined (__aarch64__) - m_flags |= X86_64; -# endif - # if __ARM_FEATURE_CRYPTO m_flags |= AES; # endif } + + +size_t xmrig::BasicCpuInfo::optimalThreadsCount(size_t memSize, int maxCpuUsage) const +{ + return threads(); +} diff --git a/src/Cpu_unix.cpp b/src/common/cpu/Cpu.cpp similarity index 71% rename from src/Cpu_unix.cpp rename to src/common/cpu/Cpu.cpp index b895c8979f..b1bb28ac73 100644 --- a/src/Cpu_unix.cpp +++ b/src/common/cpu/Cpu.cpp @@ -22,33 +22,36 @@ */ -#ifdef __FreeBSD__ -# include -# include -# include -# include -#endif +#include -#include -#include -#include -#include +#include "common/cpu/BasicCpuInfo.h" +#include "common/cpu/Cpu.h" -#include "Cpu.h" +static xmrig::ICpuInfo *cpuInfo = nullptr; -#ifdef __FreeBSD__ -typedef cpuset_t cpu_set_t; -#endif +xmrig::ICpuInfo *xmrig::Cpu::info() +{ + assert(cpuInfo != nullptr); + + return cpuInfo; +} + + +void xmrig::Cpu::init() +{ + assert(cpuInfo == nullptr); + + cpuInfo = new BasicCpuInfo(); +} -void Cpu::init() +void xmrig::Cpu::release() { -# ifdef XMRIG_NO_LIBCPUID - m_totalThreads = sysconf(_SC_NPROCESSORS_CONF); -# endif + assert(cpuInfo != nullptr); - initCommon(); + delete cpuInfo; + cpuInfo = nullptr; } diff --git a/src/Cpu_mac.cpp b/src/common/cpu/Cpu.h similarity index 75% rename from src/Cpu_mac.cpp rename to src/common/cpu/Cpu.h index 085148bc4b..1d5a9fb1d1 100644 --- a/src/Cpu_mac.cpp +++ b/src/common/cpu/Cpu.h @@ -4,7 +4,7 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -21,20 +21,26 @@ * along with this program. If not, see . */ +#ifndef XMRIG_CPU_H +#define XMRIG_CPU_H + -#include -#include -#include +#include "common/interfaces/ICpuInfo.h" -#include "Cpu.h" +namespace xmrig { -void Cpu::init() +class Cpu { -# ifdef XMRIG_NO_LIBCPUID - m_totalThreads = sysconf(_SC_NPROCESSORS_CONF); -# endif +public: + static ICpuInfo *info(); + static void init(); + static void release(); +}; + + +} /* namespace xmrig */ + - initCommon(); -} +#endif /* XMRIG_CPU_H */ diff --git a/src/common/interfaces/ICpuInfo.h b/src/common/interfaces/ICpuInfo.h new file mode 100644 index 0000000000..c959bf52a8 --- /dev/null +++ b/src/common/interfaces/ICpuInfo.h @@ -0,0 +1,59 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2016-2018 XMRig + * + * 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 Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_CPUINFO_H +#define XMRIG_CPUINFO_H + + +#include + + +#include "common/xmrig.h" + + +namespace xmrig { + + +class ICpuInfo +{ +public: + virtual ~ICpuInfo() {} + + virtual bool hasAES() const = 0; + virtual bool isSupported() const = 0; + virtual bool isX64() const = 0; + virtual const char *brand() const = 0; + virtual int32_t cores() const = 0; + virtual int32_t L2() const = 0; + virtual int32_t L3() const = 0; + virtual int32_t nodes() const = 0; + virtual int32_t sockets() const = 0; + virtual int32_t threads() const = 0; + virtual size_t optimalThreadsCount(size_t memSize, int maxCpuUsage) const = 0; + virtual xmrig::Assembly assembly() const = 0; +}; + + +} /* namespace xmrig */ + + +#endif // XMRIG_CPUINFO_H diff --git a/src/common/xmrig.h b/src/common/xmrig.h index e1c7702e1a..820bc4fbe3 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -94,6 +94,14 @@ enum OclVendor { }; +enum Assembly { + ASM_NONE, + ASM_AUTO, + ASM_INTEL, + ASM_RYZEN +}; + + } /* namespace xmrig */ diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 0380c26d2a..d99bfb0959 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -27,9 +27,9 @@ #include "common/config/ConfigLoader.h" +#include "common/cpu/Cpu.h" #include "core/Config.h" #include "core/ConfigCreator.h" -#include "Cpu.h" #include "crypto/CryptoNight_constants.h" #include "rapidjson/document.h" #include "rapidjson/filewritestream.h" @@ -153,7 +153,7 @@ bool xmrig::Config::finalize() if (!m_threads.cpu.empty()) { m_threads.mode = Advanced; - const bool softAES = (m_aesMode == AES_AUTO ? (Cpu::hasAES() ? AES_HW : AES_SOFT) : m_aesMode) == AES_SOFT; + const bool softAES = (m_aesMode == AES_AUTO ? (Cpu::info()->hasAES() ? AES_HW : AES_SOFT) : m_aesMode) == AES_SOFT; for (size_t i = 0; i < m_threads.cpu.size(); ++i) { m_threads.list.push_back(CpuThread::createFromData(i, m_algorithm.algo(), m_threads.cpu[i], m_priority, softAES)); @@ -168,10 +168,10 @@ bool xmrig::Config::finalize() const size_t size = CpuThread::multiway(av) * cn_select_memory(m_algorithm.algo()) / 1024; if (!m_threads.count) { - m_threads.count = Cpu::optimalThreadsCount(size, m_maxCpuUsage); + m_threads.count = Cpu::info()->optimalThreadsCount(size, m_maxCpuUsage); } else if (m_safe) { - const size_t count = Cpu::optimalThreadsCount(size, m_maxCpuUsage); + const size_t count = Cpu::info()->optimalThreadsCount(size, m_maxCpuUsage); if (m_threads.count > count) { m_threads.count = count; } @@ -232,7 +232,7 @@ bool xmrig::Config::parseString(int key, const char *arg) case ThreadsKey: /* --threads */ if (strncmp(arg, "all", 3) == 0) { - m_threads.count = Cpu::threads(); + m_threads.count = Cpu::info()->threads(); return true; } @@ -339,10 +339,10 @@ xmrig::AlgoVariant xmrig::Config::getAlgoVariant() const # endif if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) { - return Cpu::hasAES() ? AV_SINGLE : AV_SINGLE_SOFT; + return Cpu::info()->hasAES() ? AV_SINGLE : AV_SINGLE_SOFT; } - if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV_DOUBLE) { + if (m_safe && !Cpu::info()->hasAES() && m_algoVariant <= AV_DOUBLE) { return static_cast(m_algoVariant + 2); } @@ -354,10 +354,10 @@ xmrig::AlgoVariant xmrig::Config::getAlgoVariant() const xmrig::AlgoVariant xmrig::Config::getAlgoVariantLite() const { if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) { - return Cpu::hasAES() ? AV_DOUBLE : AV_DOUBLE_SOFT; + return Cpu::info()->hasAES() ? AV_DOUBLE : AV_DOUBLE_SOFT; } - if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV_DOUBLE) { + if (m_safe && !Cpu::info()->hasAES() && m_algoVariant <= AV_DOUBLE) { return static_cast(m_algoVariant + 2); } diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index ce73f03746..792ac9399b 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -26,6 +26,7 @@ #include "common/config/ConfigLoader.h" +#include "common/cpu/Cpu.h" #include "common/interfaces/IControllerListener.h" #include "common/log/ConsoleLog.h" #include "common/log/FileLog.h" @@ -33,7 +34,6 @@ #include "common/Platform.h" #include "core/Config.h" #include "core/Controller.h" -#include "Cpu.h" #include "net/Network.h" diff --git a/src/Cpu.cpp b/src/core/cpu/AdvancedCpuInfo.cpp similarity index 57% rename from src/Cpu.cpp rename to src/core/cpu/AdvancedCpuInfo.cpp index eebe585d8f..009a2bcbd6 100644 --- a/src/Cpu.cpp +++ b/src/core/cpu/AdvancedCpuInfo.cpp @@ -21,65 +21,24 @@ * along with this program. If not, see . */ - #include #include #include +#include -#include "Cpu.h" - - -bool Cpu::m_l2_exclusive = false; -char Cpu::m_brand[64] = { 0 }; -int Cpu::m_flags = 0; -int Cpu::m_l2_cache = 0; -int Cpu::m_l3_cache = 0; -int Cpu::m_sockets = 1; -int Cpu::m_totalCores = 0; -size_t Cpu::m_totalThreads = 0; - - -size_t Cpu::optimalThreadsCount(size_t size, int maxCpuUsage) -{ - if (m_totalThreads == 1) { - return 1; - } - - size_t cache = 0; - if (m_l3_cache) { - cache = m_l2_exclusive ? (m_l2_cache + m_l3_cache) : m_l3_cache; - } - else { - cache = m_l2_cache; - } - - size_t count = 0; - - if (cache) { - count = cache / size; - - if (cache % size >= size / 2) { - count++; - } - } - else { - count = m_totalThreads / 2; - } - - if (count > m_totalThreads) { - count = m_totalThreads; - } - - if (((float) count / m_totalThreads * 100) > maxCpuUsage) { - count = (int) ceil((float) m_totalThreads * (maxCpuUsage / 100.0)); - } - - return count < 1 ? 1 : count; -} +#include "core/cpu/AdvancedCpuInfo.h" -void Cpu::initCommon() +xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : + m_aes(false), + m_L2_exclusive(false), + m_brand(), + m_cores(0), + m_L2(0), + m_L3(0), + m_sockets(1), + m_threads(std::thread::hardware_concurrency()) { struct cpu_raw_data_t raw = { 0 }; struct cpu_id_t data = { 0 }; @@ -89,40 +48,67 @@ void Cpu::initCommon() strncpy(m_brand, data.brand_str, sizeof(m_brand) - 1); - m_totalThreads = data.total_logical_cpus; - m_sockets = m_totalThreads / data.num_logical_cpus; - + m_sockets = threads() / data.num_logical_cpus; if (m_sockets == 0) { m_sockets = 1; } - m_totalCores = data.num_cores * m_sockets; - m_l3_cache = data.l3_cache > 0 ? data.l3_cache * m_sockets : 0; + m_cores = data.num_cores * m_sockets; + m_L3 = data.l3_cache > 0 ? data.l3_cache * m_sockets : 0; // Workaround for AMD CPUs https://github.com/anrieff/libcpuid/issues/97 if (data.vendor == VENDOR_AMD && data.ext_family >= 0x15 && data.ext_family < 0x17) { - m_l2_cache = data.l2_cache * (m_totalCores / 2) * m_sockets; - m_l2_exclusive = true; + m_L2 = data.l2_cache * (cores() / 2) * m_sockets; + m_L2_exclusive = true; } // Workaround for Intel Pentium Dual-Core, Core Duo, Core 2 Duo, Core 2 Quad and their Xeon homologue // These processors have L2 cache shared by 2 cores. else if (data.vendor == VENDOR_INTEL && data.ext_family == 0x06 && (data.ext_model == 0x0E || data.ext_model == 0x0F || data.ext_model == 0x17)) { - int l2_count_per_socket = m_totalCores > 1 ? m_totalCores / 2 : 1; - m_l2_cache = data.l2_cache > 0 ? data.l2_cache * l2_count_per_socket * m_sockets : 0; + int l2_count_per_socket = cores() > 1 ? cores() / 2 : 1; + m_L2 = data.l2_cache > 0 ? data.l2_cache * l2_count_per_socket * m_sockets : 0; } else{ - m_l2_cache = data.l2_cache > 0 ? data.l2_cache * m_totalCores * m_sockets : 0; + m_L2 = data.l2_cache > 0 ? data.l2_cache * cores() * m_sockets : 0; } -# if defined(__x86_64__) || defined(_M_AMD64) - m_flags |= X86_64; -# endif + m_aes = data.flags[CPU_FEATURE_AES]; +} + - if (data.flags[CPU_FEATURE_AES]) { - m_flags |= AES; +size_t xmrig::AdvancedCpuInfo::optimalThreadsCount(size_t memSize, int maxCpuUsage) const +{ + if (threads() == 1) { + return 1; } - if (data.flags[CPU_FEATURE_BMI2]) { - m_flags |= BMI2; + size_t cache = 0; + if (m_L3) { + cache = m_L2_exclusive ? (m_L2 + m_L3) : m_L3; + } + else { + cache = m_L2; } + + size_t count = 0; + + if (cache) { + count = cache / memSize; + + if (cache % memSize >= memSize / 2) { + count++; + } + } + else { + count = threads() / 2; + } + + if (count > (size_t) threads()) { + count = threads(); + } + + if (((float) count / threads() * 100) > maxCpuUsage) { + count = (int) ceil((float) threads() * (maxCpuUsage / 100.0)); + } + + return count < 1 ? 1 : count; } diff --git a/src/core/cpu/AdvancedCpuInfo.h b/src/core/cpu/AdvancedCpuInfo.h new file mode 100644 index 0000000000..96fd329a28 --- /dev/null +++ b/src/core/cpu/AdvancedCpuInfo.h @@ -0,0 +1,75 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * + * + * 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 Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_ADVANCEDCPUINFO_H +#define XMRIG_ADVANCEDCPUINFO_H + + +#include "common/interfaces/ICpuInfo.h" + + +namespace xmrig { + + +class AdvancedCpuInfo : public ICpuInfo +{ +public: + AdvancedCpuInfo(); + +protected: + size_t optimalThreadsCount(size_t memSize, int maxCpuUsage) const override; + + inline Assembly assembly() const override { return ASM_NONE; } + inline bool hasAES() const override { return m_aes; } + inline bool isSupported() const override { return true; } + inline const char *brand() const override { return m_brand; } + inline int32_t cores() const override { return m_cores; } + inline int32_t L2() const override { return m_L2; } + inline int32_t L3() const override { return m_L3; } + inline int32_t nodes() const override { return -1; } + inline int32_t sockets() const override { return m_sockets; } + inline int32_t threads() const override { return m_threads; } + +# if defined(__x86_64__) || defined(_M_AMD64) + inline bool isX64() const override { return true; } +# else + inline bool isX64() const override { return false; } +# endif + +private: + bool m_aes; + bool m_L2_exclusive; + char m_brand[64]; + int32_t m_cores; + int32_t m_L2; + int32_t m_L3; + int32_t m_sockets; + int32_t m_threads; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_ADVANCEDCPUINFO_H */ diff --git a/src/Cpu_win.cpp b/src/core/cpu/Cpu.cpp similarity index 69% rename from src/Cpu_win.cpp rename to src/core/cpu/Cpu.cpp index 7258f72661..773255d27d 100644 --- a/src/Cpu_win.cpp +++ b/src/core/cpu/Cpu.cpp @@ -22,20 +22,40 @@ */ -#include +#include -#include "Cpu.h" +#include "common/cpu/Cpu.h" -void Cpu::init() +#ifndef XMRIG_NO_LIBCPUID +# include "core/cpu/AdvancedCpuInfo.h" +#endif + + +static xmrig::ICpuInfo *cpuInfo = nullptr; + + +xmrig::ICpuInfo *xmrig::Cpu::info() { -# ifdef XMRIG_NO_LIBCPUID - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); + assert(cpuInfo != nullptr); + + return cpuInfo; +} + - m_totalThreads = sysinfo.dwNumberOfProcessors; -# endif +void xmrig::Cpu::init() +{ + assert(cpuInfo == nullptr); + + cpuInfo = new AdvancedCpuInfo(); +} + + +void xmrig::Cpu::release() +{ + assert(cpuInfo != nullptr); - initCommon(); + delete cpuInfo; + cpuInfo = nullptr; } diff --git a/src/workers/Worker.cpp b/src/workers/Worker.cpp index 567b3e0857..c569908c62 100644 --- a/src/workers/Worker.cpp +++ b/src/workers/Worker.cpp @@ -24,8 +24,8 @@ #include +#include "common/cpu/Cpu.h" #include "common/Platform.h" -#include "Cpu.h" #include "workers/CpuThread.h" #include "workers/Handle.h" #include "workers/Worker.h" @@ -41,7 +41,7 @@ Worker::Worker(Handle *handle) : m_sequence(0), m_thread(static_cast(handle->config())) { - if (Cpu::threads() > 1 && m_thread->affinity() != -1L) { + if (xmrig::Cpu::info()->threads() > 1 && m_thread->affinity() != -1L) { Platform::setThreadAffinity(m_thread->affinity()); } From 852ffee8cc5b941d4d1448294dc0ef00297372ed Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 23 Sep 2018 18:07:44 +0300 Subject: [PATCH 077/102] Fix Linux build. --- src/common/interfaces/ICpuInfo.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/interfaces/ICpuInfo.h b/src/common/interfaces/ICpuInfo.h index c959bf52a8..267616d0ab 100644 --- a/src/common/interfaces/ICpuInfo.h +++ b/src/common/interfaces/ICpuInfo.h @@ -24,6 +24,7 @@ #define XMRIG_CPUINFO_H +#include #include From 8a2e749875f2dae640e66eb2cae0a33b51537c82 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 23 Sep 2018 19:09:05 +0300 Subject: [PATCH 078/102] Auto-detect proper asm variant. --- src/common/cpu/BasicCpuInfo_arm.cpp | 2 +- src/core/cpu/AdvancedCpuInfo.cpp | 12 +++++++++++- src/core/cpu/AdvancedCpuInfo.h | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/common/cpu/BasicCpuInfo_arm.cpp b/src/common/cpu/BasicCpuInfo_arm.cpp index 34eb73882e..c1c127db60 100644 --- a/src/common/cpu/BasicCpuInfo_arm.cpp +++ b/src/common/cpu/BasicCpuInfo_arm.cpp @@ -36,7 +36,7 @@ xmrig::BasicCpuInfo::BasicCpuInfo() : memcpy(m_brand, "Unknown", 7); # if __ARM_FEATURE_CRYPTO - m_flags |= AES; + m_aes = true; # endif } diff --git a/src/core/cpu/AdvancedCpuInfo.cpp b/src/core/cpu/AdvancedCpuInfo.cpp index 009a2bcbd6..ac5508c385 100644 --- a/src/core/cpu/AdvancedCpuInfo.cpp +++ b/src/core/cpu/AdvancedCpuInfo.cpp @@ -31,6 +31,7 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : + m_assembly(ASM_NONE), m_aes(false), m_L2_exclusive(false), m_brand(), @@ -71,7 +72,16 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : m_L2 = data.l2_cache > 0 ? data.l2_cache * cores() * m_sockets : 0; } - m_aes = data.flags[CPU_FEATURE_AES]; + if (data.flags[CPU_FEATURE_AES]) { + m_aes = true; + + if (data.vendor == VENDOR_AMD && data.ext_family >= 23) { + m_assembly = ASM_RYZEN; + } + else if (data.vendor == VENDOR_INTEL && data.ext_model >= 42) { + m_assembly = ASM_INTEL; + } + } } diff --git a/src/core/cpu/AdvancedCpuInfo.h b/src/core/cpu/AdvancedCpuInfo.h index 96fd329a28..5e8967ad2f 100644 --- a/src/core/cpu/AdvancedCpuInfo.h +++ b/src/core/cpu/AdvancedCpuInfo.h @@ -7,7 +7,6 @@ * Copyright 2017-2018 XMR-Stak , * Copyright 2016-2018 XMRig , * - * * 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 Software Foundation, either version 3 of the License, or @@ -40,7 +39,7 @@ class AdvancedCpuInfo : public ICpuInfo protected: size_t optimalThreadsCount(size_t memSize, int maxCpuUsage) const override; - inline Assembly assembly() const override { return ASM_NONE; } + inline Assembly assembly() const override { return m_assembly; } inline bool hasAES() const override { return m_aes; } inline bool isSupported() const override { return true; } inline const char *brand() const override { return m_brand; } @@ -58,6 +57,7 @@ class AdvancedCpuInfo : public ICpuInfo # endif private: + Assembly m_assembly; bool m_aes; bool m_L2_exclusive; char m_brand[64]; From 8f537fd41897ca0592628414074f5106dcf50131 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 23 Sep 2018 20:16:33 +0300 Subject: [PATCH 079/102] Initial compile with ASM. --- CMakeLists.txt | 4 +- cmake/asm.cmake | 23 +++ src/crypto/asm/cnv2_main_loop.S | 21 +++ src/crypto/asm/cnv2_main_loop.asm | 18 ++ src/crypto/asm/cnv2_main_loop_ivybridge.inc | 183 ++++++++++++++++++++ src/crypto/asm/cnv2_main_loop_ryzen.inc | 179 +++++++++++++++++++ 6 files changed, 427 insertions(+), 1 deletion(-) create mode 100644 cmake/asm.cmake create mode 100644 src/crypto/asm/cnv2_main_loop.S create mode 100644 src/crypto/asm/cnv2_main_loop.asm create mode 100644 src/crypto/asm/cnv2_main_loop_ivybridge.inc create mode 100644 src/crypto/asm/cnv2_main_loop_ryzen.inc diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f7d629104..22bf9a78df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ option(WITH_SUMO "CryptoNight-Heavy support" ON) option(WITH_HTTPD "HTTP REST API" ON) option(WITH_DEBUG_LOG "Enable debug log output" OFF) option(WITH_TLS "Enable OpenSSL support" ON) +option(WITH_ASM "Enable ASM PoW implementations" ON) option(BUILD_STATIC "Build static binary" OFF) include (CheckIncludeFile) @@ -195,6 +196,7 @@ else() endif() include(cmake/OpenSSL.cmake) +include(cmake/asm.cmake) CHECK_INCLUDE_FILE (syslog.h HAVE_SYSLOG_H) if (HAVE_SYSLOG_H) @@ -254,4 +256,4 @@ if (WITH_DEBUG_LOG) endif() add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES} ${TLS_SOURCES}) -target_link_libraries(${PROJECT_NAME} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) +target_link_libraries(${PROJECT_NAME} ${${XMRIG_ASM_LIBRARY}} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) diff --git a/cmake/asm.cmake b/cmake/asm.cmake new file mode 100644 index 0000000000..02093810a7 --- /dev/null +++ b/cmake/asm.cmake @@ -0,0 +1,23 @@ +if (WITH_ASM AND NOT XMRIG_ARM) + set(XMRIG_ASM_LIBRARY "xmrig-asm") + + if (CMAKE_CXX_COMPILER_ID MATCHES MSVC) + enable_language(ASM_MASM) + set_property(SOURCE "src/crypto/asm/cnv2_main_loop.asm" PROPERTY ASM_MASM) + add_library(${XMRIG_ASM_LIBRARY} STATIC + "src/crypto/asm/cnv2_main_loop.asm" + ) + else() + enable_language(ASM) + set_property(SOURCE "src/crypto/asm/cnv2_main_loop.S" PROPERTY C) + add_library(${XMRIG_ASM_LIBRARY} STATIC + "src/crypto/asm/cnv2_main_loop.S" + ) + endif() + + set_property(TARGET ${XMRIG_ASM_LIBRARY} PROPERTY LINKER_LANGUAGE C) +else() +# set(XMRIG_ASM_SOURCES "") + set(XMRIG_ASM_LIBRARY "") + add_definitions(/DXMRIG_NO_ASM) +endif() diff --git a/src/crypto/asm/cnv2_main_loop.S b/src/crypto/asm/cnv2_main_loop.S new file mode 100644 index 0000000000..dc5a82f58b --- /dev/null +++ b/src/crypto/asm/cnv2_main_loop.S @@ -0,0 +1,21 @@ +#define ALIGN .align +.intel_syntax noprefix +.section .text +.global cnv2_mainloop_ivybridge_asm +.global cnv2_mainloop_ryzen_asm + +ALIGN 64 +cnv2_mainloop_ivybridge_asm: + sub rsp, 48 + mov rcx, rdi + #include "cnv2_main_loop_ivybridge.inc" + add rsp, 48 + ret 0 + +ALIGN 64 +cnv2_mainloop_ryzen_asm: + sub rsp, 48 + mov rcx, rdi + #include "cnv2_main_loop_ryzen.inc" + add rsp, 48 + ret 0 diff --git a/src/crypto/asm/cnv2_main_loop.asm b/src/crypto/asm/cnv2_main_loop.asm new file mode 100644 index 0000000000..7ec895c490 --- /dev/null +++ b/src/crypto/asm/cnv2_main_loop.asm @@ -0,0 +1,18 @@ +_TEXT_CNV2_MAINLOOP SEGMENT PAGE READ EXECUTE +PUBLIC cnv2_mainloop_ivybridge_asm +PUBLIC cnv2_mainloop_ryzen_asm + +ALIGN 64 +cnv2_mainloop_ivybridge_asm PROC + INCLUDE cnv2_main_loop_ivybridge.inc + ret 0 +cnv2_mainloop_ivybridge_asm ENDP + +ALIGN 64 +cnv2_mainloop_ryzen_asm PROC + INCLUDE cnv2_main_loop_ryzen.inc + ret 0 +cnv2_mainloop_ryzen_asm ENDP + +_TEXT_CNV2_MAINLOOP ENDS +END diff --git a/src/crypto/asm/cnv2_main_loop_ivybridge.inc b/src/crypto/asm/cnv2_main_loop_ivybridge.inc new file mode 100644 index 0000000000..0985d1bd1f --- /dev/null +++ b/src/crypto/asm/cnv2_main_loop_ivybridge.inc @@ -0,0 +1,183 @@ + mov QWORD PTR [rsp+24], rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 80 + + stmxcsr DWORD PTR [rsp] + mov DWORD PTR [rsp+4], 24448 + ldmxcsr DWORD PTR [rsp+4] + + mov rax, QWORD PTR [rcx+48] + mov r9, rcx + xor rax, QWORD PTR [rcx+16] + mov esi, 524288 + mov r8, QWORD PTR [rcx+32] + mov r13d, -2147483647 + xor r8, QWORD PTR [rcx] + mov r11, QWORD PTR [rcx+40] + mov r10, r8 + mov rdx, QWORD PTR [rcx+56] + movq xmm4, rax + xor rdx, QWORD PTR [rcx+24] + xor r11, QWORD PTR [rcx+8] + mov rbx, QWORD PTR [rcx+224] + mov rax, QWORD PTR [r9+80] + xor rax, QWORD PTR [r9+64] + movq xmm0, rdx + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r9+72] + movq xmm3, QWORD PTR [r9+104] + movaps XMMWORD PTR [rsp+64], xmm6 + movaps XMMWORD PTR [rsp+48], xmm7 + movaps XMMWORD PTR [rsp+32], xmm8 + and r10d, 2097136 + movq xmm5, rax + + xor eax, eax + mov QWORD PTR [rsp+16], rax + + mov ax, 1023 + shl rax, 52 + movq xmm8, rax + mov r15, QWORD PTR [r9+96] + punpcklqdq xmm4, xmm0 + movq xmm0, rcx + punpcklqdq xmm5, xmm0 + + ALIGN 64 +$main_loop_ivybridge: + movdqu xmm6, XMMWORD PTR [r10+rbx] + lea rdx, QWORD PTR [r10+rbx] + mov ecx, r10d + mov eax, r10d + mov rdi, r15 + xor ecx, 16 + xor eax, 32 + xor r10d, 48 + movq xmm0, r11 + movq xmm7, r8 + punpcklqdq xmm7, xmm0 + aesenc xmm6, xmm7 + movdqu xmm1, XMMWORD PTR [rax+rbx] + movdqu xmm0, XMMWORD PTR [r10+rbx] + paddq xmm1, xmm7 + movdqu xmm2, XMMWORD PTR [rcx+rbx] + paddq xmm0, xmm5 + paddq xmm2, xmm4 + movdqu XMMWORD PTR [rcx+rbx], xmm0 + movq rcx, xmm3 + movdqu XMMWORD PTR [rax+rbx], xmm2 + mov rax, rcx + movdqu XMMWORD PTR [r10+rbx], xmm1 + shl rax, 32 + xor rdi, rax + movq rbp, xmm6 + movdqa xmm0, xmm6 + pxor xmm0, xmm4 + mov r10, rbp + and r10d, 2097136 + movdqu XMMWORD PTR [rdx], xmm0 + xor rdi, QWORD PTR [r10+rbx] + lea r14, QWORD PTR [r10+rbx] + xor r10d, 32 + mov r12, QWORD PTR [r14+8] + xor edx, edx + lea r9d, DWORD PTR [ecx+ecx] + add r9d, ebp + movdqa xmm0, xmm6 + psrldq xmm0, 8 + or r9d, r13d + movq rax, xmm0 + div r9 + xorps xmm3, xmm3 + mov eax, eax + shl rdx, 32 + add rdx, rax + lea r9, QWORD PTR [rdx+rbp] + mov r15, rdx + mov rax, r9 + shr rax, 12 + movq xmm0, rax + paddq xmm0, xmm8 + sqrtsd xmm3, xmm0 + psubq xmm3, XMMWORD PTR [rsp+16] + movq rdx, xmm3 + test edx, 524287 + je $sqrt_fixup_ivybridge + psrlq xmm3, 19 +$sqrt_fixup_ivybridge_ret: + + mov ecx, r10d + mov rax, rdi + mul rbp + movq xmm2, rdx + xor rdx, [rcx+rbx] + movq xmm0, rax + xor rax, [rcx+rbx+8] + punpcklqdq xmm2, xmm0 + + mov r9d, r10d + xor r9d, 48 + xor r10d, 16 + pxor xmm2, XMMWORD PTR [r9+rbx] + movdqu xmm0, XMMWORD PTR [r10+rbx] + paddq xmm0, xmm5 + movdqu xmm1, XMMWORD PTR [rcx+rbx] + paddq xmm2, xmm4 + paddq xmm1, xmm7 + movdqa xmm5, xmm4 + movdqu XMMWORD PTR [r9+rbx], xmm0 + movdqa xmm4, xmm6 + movdqu XMMWORD PTR [rcx+rbx], xmm2 + movdqu XMMWORD PTR [r10+rbx], xmm1 + add r8, rdx + mov QWORD PTR [r14], r8 + xor r8, rdi + mov r10, r8 + add r11, rax + mov QWORD PTR [r14+8], r11 + and r10d, 2097136 + xor r11, r12 + dec rsi + jne $main_loop_ivybridge + + ldmxcsr DWORD PTR [rsp] + mov rbx, QWORD PTR [rsp+160] + movaps xmm6, XMMWORD PTR [rsp+64] + movaps xmm7, XMMWORD PTR [rsp+48] + movaps xmm8, XMMWORD PTR [rsp+32] + add rsp, 80 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + jmp $cnv2_main_loop_ivybridge_endp + +$sqrt_fixup_ivybridge: + dec rdx + mov r13d, -1022 + shl r13, 32 + mov rax, rdx + shr rdx, 19 + shr rax, 20 + mov rcx, rdx + sub rcx, rax + add rax, r13 + not r13 + sub rcx, r13 + mov r13d, -2147483647 + imul rcx, rax + sub rcx, r9 + adc rdx, 0 + movq xmm3, rdx + jmp $sqrt_fixup_ivybridge_ret + +$cnv2_main_loop_ivybridge_endp: diff --git a/src/crypto/asm/cnv2_main_loop_ryzen.inc b/src/crypto/asm/cnv2_main_loop_ryzen.inc new file mode 100644 index 0000000000..3294548edf --- /dev/null +++ b/src/crypto/asm/cnv2_main_loop_ryzen.inc @@ -0,0 +1,179 @@ + mov QWORD PTR [rsp+16], rbx + mov QWORD PTR [rsp+24], rbp + mov QWORD PTR [rsp+32], rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 64 + + stmxcsr DWORD PTR [rsp] + mov DWORD PTR [rsp+4], 24448 + ldmxcsr DWORD PTR [rsp+4] + + mov rax, QWORD PTR [rcx+48] + mov r9, rcx + xor rax, QWORD PTR [rcx+16] + mov ebp, 524288 + mov r8, QWORD PTR [rcx+32] + xor r8, QWORD PTR [rcx] + mov r11, QWORD PTR [rcx+40] + mov r10, r8 + mov rdx, QWORD PTR [rcx+56] + movq xmm3, rax + xor rdx, QWORD PTR [rcx+24] + xor r11, QWORD PTR [rcx+8] + mov rbx, QWORD PTR [rcx+224] + mov rax, QWORD PTR [r9+80] + xor rax, QWORD PTR [r9+64] + movq xmm0, rdx + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r9+72] + mov rdi, QWORD PTR [r9+104] + and r10d, 2097136 + movaps XMMWORD PTR [rsp+48], xmm6 + movq xmm4, rax + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+16], xmm8 + xorps xmm8, xmm8 + mov ax, 1023 + shl rax, 52 + movq xmm7, rax + mov r15, QWORD PTR [r9+96] + punpcklqdq xmm3, xmm0 + movq xmm0, rcx + punpcklqdq xmm4, xmm0 + + ALIGN 64 +$main_loop_ryzen: + movdqa xmm5, XMMWORD PTR [r10+rbx] + movq xmm0, r11 + movq xmm6, r8 + punpcklqdq xmm6, xmm0 + lea rdx, QWORD PTR [r10+rbx] + lea r9, QWORD PTR [rdi+rdi] + shl rdi, 32 + + mov ecx, r10d + mov eax, r10d + xor ecx, 16 + xor eax, 32 + xor r10d, 48 + aesenc xmm5, xmm6 + movdqa xmm2, XMMWORD PTR [rcx+rbx] + movdqa xmm1, XMMWORD PTR [rax+rbx] + movdqa xmm0, XMMWORD PTR [r10+rbx] + paddq xmm2, xmm3 + paddq xmm1, xmm6 + paddq xmm0, xmm4 + movdqa XMMWORD PTR [rcx+rbx], xmm0 + movdqa XMMWORD PTR [rax+rbx], xmm2 + movdqa XMMWORD PTR [r10+rbx], xmm1 + + movaps xmm1, xmm8 + mov rsi, r15 + xor rsi, rdi + movq r14, xmm5 + movdqa xmm0, xmm5 + pxor xmm0, xmm3 + mov r10, r14 + and r10d, 2097136 + movdqa XMMWORD PTR [rdx], xmm0 + xor rsi, QWORD PTR [r10+rbx] + lea r12, QWORD PTR [r10+rbx] + mov r13, QWORD PTR [r10+rbx+8] + + add r9d, r14d + or r9d, -2147483647 + xor edx, edx + movdqa xmm0, xmm5 + psrldq xmm0, 8 + movq rax, xmm0 + + div r9 + movq xmm0, rax + movq xmm1, rdx + punpckldq xmm0, xmm1 + movq r15, xmm0 + paddq xmm0, xmm5 + movdqa xmm2, xmm0 + psrlq xmm0, 12 + paddq xmm0, xmm7 + sqrtsd xmm1, xmm0 + movq rdi, xmm1 + test rdi, 524287 + je $sqrt_fixup_ryzen + shr rdi, 19 + +$sqrt_fixup_ryzen_ret: + mov rax, rsi + mul r14 + movq xmm1, rax + movq xmm0, rdx + punpcklqdq xmm0, xmm1 + + mov r9d, r10d + mov ecx, r10d + xor r9d, 16 + xor ecx, 32 + xor r10d, 48 + movdqa xmm1, XMMWORD PTR [rcx+rbx] + xor rdx, [rcx+rbx] + xor rax, [rcx+rbx+8] + movdqa xmm2, XMMWORD PTR [r9+rbx] + pxor xmm2, xmm0 + paddq xmm4, XMMWORD PTR [r10+rbx] + paddq xmm2, xmm3 + paddq xmm1, xmm6 + movdqa XMMWORD PTR [r9+rbx], xmm4 + movdqa XMMWORD PTR [rcx+rbx], xmm2 + movdqa XMMWORD PTR [r10+rbx], xmm1 + + movdqa xmm4, xmm3 + add r8, rdx + add r11, rax + mov QWORD PTR [r12], r8 + xor r8, rsi + mov QWORD PTR [r12+8], r11 + mov r10, r8 + xor r11, r13 + and r10d, 2097136 + movdqa xmm3, xmm5 + dec ebp + jne $main_loop_ryzen + + ldmxcsr DWORD PTR [rsp] + movaps xmm6, XMMWORD PTR [rsp+48] + lea r11, QWORD PTR [rsp+64] + mov rbx, QWORD PTR [r11+56] + mov rbp, QWORD PTR [r11+64] + mov rsi, QWORD PTR [r11+72] + movaps xmm8, XMMWORD PTR [r11-48] + movaps xmm7, XMMWORD PTR [rsp+32] + mov rsp, r11 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + jmp $cnv2_main_loop_ryzen_endp + +$sqrt_fixup_ryzen: + movq r9, xmm2 + dec rdi + mov edx, -1022 + shl rdx, 32 + mov rax, rdi + shr rdi, 19 + shr rax, 20 + mov rcx, rdi + sub rcx, rax + lea rcx, [rcx+rdx+1] + add rax, rdx + imul rcx, rax + sub rcx, r9 + adc rdi, 0 + jmp $sqrt_fixup_ryzen_ret + +$cnv2_main_loop_ryzen_endp: From c28329949c829f66d2d98b22bf3d24753732907f Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 23 Sep 2018 20:45:10 +0300 Subject: [PATCH 080/102] Fix macOS/Clang build. --- src/crypto/asm/cnv2_main_loop.S | 18 ++++++++++++------ src/crypto/asm/cnv2_main_loop_ivybridge.inc | 18 +++++++++--------- src/crypto/asm/cnv2_main_loop_ryzen.inc | 18 +++++++++--------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/crypto/asm/cnv2_main_loop.S b/src/crypto/asm/cnv2_main_loop.S index dc5a82f58b..580a458809 100644 --- a/src/crypto/asm/cnv2_main_loop.S +++ b/src/crypto/asm/cnv2_main_loop.S @@ -1,19 +1,25 @@ #define ALIGN .align .intel_syntax noprefix +#ifdef __APPLE__ +# define FN_PREFIX(fn) _ ## fn +.text +#else +# define FN_PREFIX(fn) fn .section .text -.global cnv2_mainloop_ivybridge_asm -.global cnv2_mainloop_ryzen_asm +#endif +.global FN_PREFIX(cnv2_mainloop_ivybridge_asm) +.global FN_PREFIX(cnv2_mainloop_ryzen_asm) -ALIGN 64 -cnv2_mainloop_ivybridge_asm: +ALIGN 16 +FN_PREFIX(cnv2_mainloop_ivybridge_asm): sub rsp, 48 mov rcx, rdi #include "cnv2_main_loop_ivybridge.inc" add rsp, 48 ret 0 -ALIGN 64 -cnv2_mainloop_ryzen_asm: +ALIGN 16 +FN_PREFIX(cnv2_mainloop_ryzen_asm): sub rsp, 48 mov rcx, rdi #include "cnv2_main_loop_ryzen.inc" diff --git a/src/crypto/asm/cnv2_main_loop_ivybridge.inc b/src/crypto/asm/cnv2_main_loop_ivybridge.inc index 0985d1bd1f..a253a5495d 100644 --- a/src/crypto/asm/cnv2_main_loop_ivybridge.inc +++ b/src/crypto/asm/cnv2_main_loop_ivybridge.inc @@ -49,8 +49,8 @@ movq xmm0, rcx punpcklqdq xmm5, xmm0 - ALIGN 64 -$main_loop_ivybridge: + ALIGN 16 +main_loop_ivybridge: movdqu xmm6, XMMWORD PTR [r10+rbx] lea rdx, QWORD PTR [r10+rbx] mov ecx, r10d @@ -108,9 +108,9 @@ $main_loop_ivybridge: psubq xmm3, XMMWORD PTR [rsp+16] movq rdx, xmm3 test edx, 524287 - je $sqrt_fixup_ivybridge + je sqrt_fixup_ivybridge psrlq xmm3, 19 -$sqrt_fixup_ivybridge_ret: +sqrt_fixup_ivybridge_ret: mov ecx, r10d mov rax, rdi @@ -144,7 +144,7 @@ $sqrt_fixup_ivybridge_ret: and r10d, 2097136 xor r11, r12 dec rsi - jne $main_loop_ivybridge + jne main_loop_ivybridge ldmxcsr DWORD PTR [rsp] mov rbx, QWORD PTR [rsp+160] @@ -159,9 +159,9 @@ $sqrt_fixup_ivybridge_ret: pop rdi pop rsi pop rbp - jmp $cnv2_main_loop_ivybridge_endp + jmp cnv2_main_loop_ivybridge_endp -$sqrt_fixup_ivybridge: +sqrt_fixup_ivybridge: dec rdx mov r13d, -1022 shl r13, 32 @@ -178,6 +178,6 @@ $sqrt_fixup_ivybridge: sub rcx, r9 adc rdx, 0 movq xmm3, rdx - jmp $sqrt_fixup_ivybridge_ret + jmp sqrt_fixup_ivybridge_ret -$cnv2_main_loop_ivybridge_endp: +cnv2_main_loop_ivybridge_endp: diff --git a/src/crypto/asm/cnv2_main_loop_ryzen.inc b/src/crypto/asm/cnv2_main_loop_ryzen.inc index 3294548edf..d386aa2dfc 100644 --- a/src/crypto/asm/cnv2_main_loop_ryzen.inc +++ b/src/crypto/asm/cnv2_main_loop_ryzen.inc @@ -45,8 +45,8 @@ movq xmm0, rcx punpcklqdq xmm4, xmm0 - ALIGN 64 -$main_loop_ryzen: + ALIGN 16 +main_loop_ryzen: movdqa xmm5, XMMWORD PTR [r10+rbx] movq xmm0, r11 movq xmm6, r8 @@ -103,10 +103,10 @@ $main_loop_ryzen: sqrtsd xmm1, xmm0 movq rdi, xmm1 test rdi, 524287 - je $sqrt_fixup_ryzen + je sqrt_fixup_ryzen shr rdi, 19 -$sqrt_fixup_ryzen_ret: +sqrt_fixup_ryzen_ret: mov rax, rsi mul r14 movq xmm1, rax @@ -141,7 +141,7 @@ $sqrt_fixup_ryzen_ret: and r10d, 2097136 movdqa xmm3, xmm5 dec ebp - jne $main_loop_ryzen + jne main_loop_ryzen ldmxcsr DWORD PTR [rsp] movaps xmm6, XMMWORD PTR [rsp+48] @@ -157,9 +157,9 @@ $sqrt_fixup_ryzen_ret: pop r13 pop r12 pop rdi - jmp $cnv2_main_loop_ryzen_endp + jmp cnv2_main_loop_ryzen_endp -$sqrt_fixup_ryzen: +sqrt_fixup_ryzen: movq r9, xmm2 dec rdi mov edx, -1022 @@ -174,6 +174,6 @@ $sqrt_fixup_ryzen: imul rcx, rax sub rcx, r9 adc rdi, 0 - jmp $sqrt_fixup_ryzen_ret + jmp sqrt_fixup_ryzen_ret -$cnv2_main_loop_ryzen_endp: +cnv2_main_loop_ryzen_endp: From dbb3464a10ee15be222bf86e7953af08f7124e70 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 24 Sep 2018 09:51:21 +0300 Subject: [PATCH 081/102] Initial ASM wrapper. --- CMakeLists.txt | 2 +- cmake/asm.cmake | 1 - src/crypto/CryptoNight.h | 10 +++--- src/crypto/CryptoNight_x86.h | 25 ++++++++++++++ src/crypto/asm/cnv2_main_loop_ivybridge.inc | 37 +++++++++++---------- src/workers/CpuThread.cpp | 5 ++- src/workers/Worker.h | 7 ++-- 7 files changed, 58 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22bf9a78df..1b3fe6f2cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,4 +256,4 @@ if (WITH_DEBUG_LOG) endif() add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES} ${TLS_SOURCES}) -target_link_libraries(${PROJECT_NAME} ${${XMRIG_ASM_LIBRARY}} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) +target_link_libraries(${PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) diff --git a/cmake/asm.cmake b/cmake/asm.cmake index 02093810a7..3a0bc89453 100644 --- a/cmake/asm.cmake +++ b/cmake/asm.cmake @@ -17,7 +17,6 @@ if (WITH_ASM AND NOT XMRIG_ARM) set_property(TARGET ${XMRIG_ASM_LIBRARY} PROPERTY LINKER_LANGUAGE C) else() -# set(XMRIG_ASM_SOURCES "") set(XMRIG_ASM_LIBRARY "") add_definitions(/DXMRIG_NO_ASM) endif() diff --git a/src/crypto/CryptoNight.h b/src/crypto/CryptoNight.h index e8e86dc42d..680f1740ee 100644 --- a/src/crypto/CryptoNight.h +++ b/src/crypto/CryptoNight.h @@ -22,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __CRYPTONIGHT_H__ -#define __CRYPTONIGHT_H__ +#ifndef XMRIG_CRYPTONIGHT_H +#define XMRIG_CRYPTONIGHT_H #include @@ -31,9 +31,9 @@ struct cryptonight_ctx { - alignas(16) uint8_t state[200]; - alignas(16) uint8_t* memory; + alignas(16) uint8_t state[224]; + alignas(16) uint8_t *memory; }; -#endif /* __CRYPTONIGHT_H__ */ +#endif /* XMRIG_CRYPTONIGHT_H */ diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 1cb066873e..064dbdc285 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -561,6 +561,31 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si } +extern "C" void cnv2_mainloop_ivybridge_asm(cryptonight_ctx *ctx); +extern "C" void cnv2_mainloop_ryzen_asm(cryptonight_ctx *ctx); + + +template +inline void cryptonight_single_hash_asm(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) +{ + constexpr size_t MEM = xmrig::cn_select_memory(); + + xmrig::keccak(input, size, ctx[0]->state); + cn_explode_scratchpad((__m128i*) ctx[0]->state, (__m128i*) ctx[0]->memory); + + if (ASM == xmrig::ASM_INTEL) { + cnv2_mainloop_ivybridge_asm(ctx[0]); + } + else { + cnv2_mainloop_ryzen_asm(ctx[0]); + } + + cn_implode_scratchpad((__m128i*) ctx[0]->memory, (__m128i*) ctx[0]->state); + xmrig::keccakf(reinterpret_cast(ctx[0]->state), 24); + extra_hashes[ctx[0]->state[0] & 3](ctx[0]->state, 200, output); +} + + template inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { diff --git a/src/crypto/asm/cnv2_main_loop_ivybridge.inc b/src/crypto/asm/cnv2_main_loop_ivybridge.inc index a253a5495d..8c2c2d3b0d 100644 --- a/src/crypto/asm/cnv2_main_loop_ivybridge.inc +++ b/src/crypto/asm/cnv2_main_loop_ivybridge.inc @@ -48,10 +48,10 @@ punpcklqdq xmm4, xmm0 movq xmm0, rcx punpcklqdq xmm5, xmm0 + movdqu xmm6, XMMWORD PTR [r10+rbx] ALIGN 16 main_loop_ivybridge: - movdqu xmm6, XMMWORD PTR [r10+rbx] lea rdx, QWORD PTR [r10+rbx] mov ecx, r10d mov eax, r10d @@ -63,28 +63,29 @@ main_loop_ivybridge: movq xmm7, r8 punpcklqdq xmm7, xmm0 aesenc xmm6, xmm7 + movq rbp, xmm6 + mov r9, rbp + and r9d, 2097136 + movdqu xmm2, XMMWORD PTR [rcx+rbx] movdqu xmm1, XMMWORD PTR [rax+rbx] movdqu xmm0, XMMWORD PTR [r10+rbx] paddq xmm1, xmm7 - movdqu xmm2, XMMWORD PTR [rcx+rbx] paddq xmm0, xmm5 paddq xmm2, xmm4 movdqu XMMWORD PTR [rcx+rbx], xmm0 - movq rcx, xmm3 movdqu XMMWORD PTR [rax+rbx], xmm2 - mov rax, rcx movdqu XMMWORD PTR [r10+rbx], xmm1 + mov r10, r9 + xor r10d, 32 + movq rcx, xmm3 + mov rax, rcx shl rax, 32 xor rdi, rax - movq rbp, xmm6 movdqa xmm0, xmm6 pxor xmm0, xmm4 - mov r10, rbp - and r10d, 2097136 movdqu XMMWORD PTR [rdx], xmm0 - xor rdi, QWORD PTR [r10+rbx] - lea r14, QWORD PTR [r10+rbx] - xor r10d, 32 + xor rdi, QWORD PTR [r9+rbx] + lea r14, QWORD PTR [r9+rbx] mov r12, QWORD PTR [r14+8] xor edx, edx lea r9d, DWORD PTR [ecx+ecx] @@ -117,8 +118,15 @@ sqrt_fixup_ivybridge_ret: mul rbp movq xmm2, rdx xor rdx, [rcx+rbx] + add r8, rdx + mov QWORD PTR [r14], r8 + xor r8, rdi + mov edi, r8d + and edi, 2097136 movq xmm0, rax xor rax, [rcx+rbx+8] + add r11, rax + mov QWORD PTR [r14+8], r11 punpcklqdq xmm2, xmm0 mov r9d, r10d @@ -135,13 +143,8 @@ sqrt_fixup_ivybridge_ret: movdqa xmm4, xmm6 movdqu XMMWORD PTR [rcx+rbx], xmm2 movdqu XMMWORD PTR [r10+rbx], xmm1 - add r8, rdx - mov QWORD PTR [r14], r8 - xor r8, rdi - mov r10, r8 - add r11, rax - mov QWORD PTR [r14+8], r11 - and r10d, 2097136 + movdqu xmm6, [rdi+rbx] + mov r10d, edi xor r11, r12 dec rsi jne main_loop_ivybridge diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index ca7681f065..d9d60f51c3 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -65,7 +65,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a { assert(variant >= VARIANT_0 && variant < VARIANT_MAX); - static const cn_hash_fun func_table[VARIANT_MAX * 10 * 3] = { + constexpr const size_t count = VARIANT_MAX * 10 * 3; + static const cn_hash_fun func_table[count + 2] = { cryptonight_single_hash, cryptonight_double_hash, cryptonight_single_hash, @@ -242,6 +243,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif + cryptonight_single_hash_asm, + cryptonight_single_hash_asm }; const size_t index = VARIANT_MAX * 10 * algorithm + 10 * variant + av - 1; diff --git a/src/workers/Worker.h b/src/workers/Worker.h index aad9e3c5e3..73e250330e 100644 --- a/src/workers/Worker.h +++ b/src/workers/Worker.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __WORKER_H__ -#define __WORKER_H__ +#ifndef XMRIG_WORKER_H +#define XMRIG_WORKER_H #include @@ -33,7 +33,6 @@ #include "Mem.h" -struct cryptonight_ctx; class Handle; @@ -67,4 +66,4 @@ class Worker : public IWorker }; -#endif /* __WORKER_H__ */ +#endif /* XMRIG_WORKER_H */ From c0a688fbc8e369d3a341160810d0496c5201ab98 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 24 Sep 2018 14:19:26 +0300 Subject: [PATCH 082/102] Implemented "asm" option. --- CMakeLists.txt | 2 +- cmake/asm.cmake | 2 + src/Summary.cpp | 29 +++++++++ src/common/interfaces/IConfig.h | 1 + src/common/xmrig.h | 3 +- src/core/Config.cpp | 21 +++++-- src/core/Config.h | 9 +-- src/core/ConfigLoader_platform.h | 2 + src/core/cpu/AdvancedCpuInfo.cpp | 2 +- src/crypto/Asm.cpp | 100 +++++++++++++++++++++++++++++++ src/crypto/Asm.h | 50 ++++++++++++++++ src/crypto/CryptoNight_x86.h | 2 + src/workers/CpuThread.cpp | 71 +++++++++++++++++----- src/workers/CpuThread.h | 15 +++-- 14 files changed, 275 insertions(+), 34 deletions(-) create mode 100644 src/crypto/Asm.cpp create mode 100644 src/crypto/Asm.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b3fe6f2cd..1becac5ce4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,5 +255,5 @@ if (WITH_DEBUG_LOG) add_definitions(/DAPP_DEBUG) endif() -add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES} ${TLS_SOURCES}) +add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES} ${TLS_SOURCES} ${XMRIG_ASM_SOURCES}) target_link_libraries(${PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) diff --git a/cmake/asm.cmake b/cmake/asm.cmake index 3a0bc89453..a9b76ffda4 100644 --- a/cmake/asm.cmake +++ b/cmake/asm.cmake @@ -15,8 +15,10 @@ if (WITH_ASM AND NOT XMRIG_ARM) ) endif() + set(XMRIG_ASM_SOURCES src/crypto/Asm.h src/crypto/Asm.cpp) set_property(TARGET ${XMRIG_ASM_LIBRARY} PROPERTY LINKER_LANGUAGE C) else() + set(XMRIG_ASM_SOURCES "") set(XMRIG_ASM_LIBRARY "") add_definitions(/DXMRIG_NO_ASM) endif() diff --git a/src/Summary.cpp b/src/Summary.cpp index ba220e5b10..3c1d06a708 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -32,11 +32,28 @@ #include "common/net/Pool.h" #include "core/Config.h" #include "core/Controller.h" +#include "crypto/Asm.h" #include "Mem.h" #include "Summary.h" #include "version.h" +#ifndef XMRIG_NO_ASM +static const char *coloredAsmNames[] = { + "\x1B[1;31mnone\x1B[0m", + "auto", + "\x1B[1;32mintel\x1B[0m", + "\x1B[1;32mryzen\x1B[0m" +}; + + +inline static const char *asmName(xmrig::Assembly assembly, bool colors) +{ + return colors ? coloredAsmNames[assembly] : xmrig::Asm::toString(assembly); +} +#endif + + static void print_memory(xmrig::Config *config) { # ifdef _WIN32 if (config->isColors()) { @@ -101,6 +118,18 @@ static void print_threads(xmrig::Config *config) config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "", config->donateLevel()); } + +# ifndef XMRIG_NO_ASM + if (config->assembly() == xmrig::ASM_AUTO) { + const xmrig::Assembly assembly = xmrig::Cpu::info()->assembly(); + + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13sauto:%s") + : " * %-13sauto:%s", "ASSEMBLY", asmName(assembly, config->isColors())); + } + else { + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s") : " * %-13s%s", "ASSEMBLY", asmName(config->assembly(), config->isColors())); + } +# endif } diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index d359316344..0fcac2d15a 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -80,6 +80,7 @@ class IConfig SafeKey = 1005, ThreadsKey = 't', HardwareAESKey = 1011, + AssemblyKey = 1015, // xmrig amd OclPlatformKey = 1400, diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 820bc4fbe3..52650f0d28 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -98,7 +98,8 @@ enum Assembly { ASM_NONE, ASM_AUTO, ASM_INTEL, - ASM_RYZEN + ASM_RYZEN, + ASM_MAX }; diff --git a/src/core/Config.cpp b/src/core/Config.cpp index d99bfb0959..20a3aece0f 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -30,6 +30,7 @@ #include "common/cpu/Cpu.h" #include "core/Config.h" #include "core/ConfigCreator.h" +#include "crypto/Asm.h" #include "crypto/CryptoNight_constants.h" #include "rapidjson/document.h" #include "rapidjson/filewritestream.h" @@ -43,6 +44,7 @@ static char affinity_tmp[20] = { 0 }; xmrig::Config::Config() : xmrig::CommonConfig(), m_aesMode(AES_AUTO), m_algoVariant(AV_AUTO), + m_assembly(ASM_AUTO), m_hugePages(true), m_safe(false), m_maxCpuUsage(75), @@ -51,11 +53,6 @@ xmrig::Config::Config() : xmrig::CommonConfig(), } -xmrig::Config::~Config() -{ -} - - bool xmrig::Config::reload(const char *json) { return xmrig::ConfigLoader::reload(this, json); @@ -178,7 +175,7 @@ bool xmrig::Config::finalize() } for (size_t i = 0; i < m_threads.count; ++i) { - m_threads.list.push_back(CpuThread::createFromAV(i, m_algorithm.algo(), av, m_threads.mask, m_priority)); + m_threads.list.push_back(CpuThread::createFromAV(i, m_algorithm.algo(), av, m_threads.mask, m_priority, m_assembly)); } return true; @@ -204,6 +201,12 @@ bool xmrig::Config::parseBoolean(int key, bool enable) m_aesMode = enable ? AES_HW : AES_SOFT; break; +# ifndef XMRIG_NO_ASM + case AssemblyKey: + m_assembly = Asm::parse(enable); + break; +# endif + default: break; } @@ -244,6 +247,12 @@ bool xmrig::Config::parseString(int key, const char *arg) return parseUint64(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10)); } +# ifndef XMRIG_NO_ASM + case AssemblyKey: /* --asm */ + m_assembly = Asm::parse(arg); + break; +# endif + default: break; } diff --git a/src/core/Config.h b/src/core/Config.h index f0f1404fbc..95afc34cd1 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __CONFIG_H__ -#define __CONFIG_H__ +#ifndef XMRIG_CONFIG_H +#define XMRIG_CONFIG_H #include @@ -69,7 +69,6 @@ class Config : public CommonConfig Config(); - ~Config(); bool reload(const char *json); @@ -77,6 +76,7 @@ class Config : public CommonConfig inline AesMode aesMode() const { return m_aesMode; } inline AlgoVariant algoVariant() const { return m_algoVariant; } + inline Assembly assembly() const { return m_assembly; } inline bool isHugePages() const { return m_hugePages; } inline const std::vector &threads() const { return m_threads.list; } inline int priority() const { return m_priority; } @@ -116,6 +116,7 @@ class Config : public CommonConfig AesMode m_aesMode; AlgoVariant m_algoVariant; + Assembly m_assembly; bool m_hugePages; bool m_safe; int m_maxCpuUsage; @@ -126,4 +127,4 @@ class Config : public CommonConfig } /* namespace xmrig */ -#endif /* __CONFIG_H__ */ +#endif /* XMRIG_CONFIG_H */ diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index c034f3e754..3b95a90fc2 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -135,6 +135,7 @@ static struct option const options[] = { { "tls", 0, nullptr, xmrig::IConfig::TlsKey }, { "tls-fingerprint", 1, nullptr, xmrig::IConfig::FingerprintKey }, { "version", 0, nullptr, xmrig::IConfig::VersionKey }, + { "asm", 1, nullptr, xmrig::IConfig::AssemblyKey }, { nullptr, 0, nullptr, 0 } }; @@ -159,6 +160,7 @@ static struct option const config_options[] = { { "threads", 1, nullptr, xmrig::IConfig::ThreadsKey }, { "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey }, { "hw-aes", 0, nullptr, xmrig::IConfig::HardwareAESKey }, + { "asm", 1, nullptr, xmrig::IConfig::AssemblyKey }, { nullptr, 0, nullptr, 0 } }; diff --git a/src/core/cpu/AdvancedCpuInfo.cpp b/src/core/cpu/AdvancedCpuInfo.cpp index ac5508c385..1f86a42052 100644 --- a/src/core/cpu/AdvancedCpuInfo.cpp +++ b/src/core/cpu/AdvancedCpuInfo.cpp @@ -47,7 +47,7 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : cpuid_get_raw_data(&raw); cpu_identify(&raw, &data); - strncpy(m_brand, data.brand_str, sizeof(m_brand) - 1); + strncpy(m_brand, data.brand_str, sizeof(m_brand)); m_sockets = threads() / data.num_logical_cpus; if (m_sockets == 0) { diff --git a/src/crypto/Asm.cpp b/src/crypto/Asm.cpp new file mode 100644 index 0000000000..79dd1cc9cd --- /dev/null +++ b/src/crypto/Asm.cpp @@ -0,0 +1,100 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * + * 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 Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include +#include + + +#ifdef _MSC_VER +# define strncasecmp _strnicmp +# define strcasecmp _stricmp +#endif + + +#include "crypto/Asm.h" +#include "rapidjson/document.h" + + +static const char *asmNames[] = { + "none", + "auto", + "intel", + "ryzen" +}; + + +xmrig::Assembly xmrig::Asm::parse(const char *assembly, Assembly defaultValue) +{ + constexpr size_t const size = sizeof(asmNames) / sizeof((asmNames)[0]); + assert(assembly != nullptr); + assert(ASM_MAX == size); + + if (assembly == nullptr) { + return defaultValue; + } + + for (size_t i = 0; i < size; i++) { + if (strcasecmp(assembly, asmNames[i]) == 0) { + return static_cast(i); + } + } + + return defaultValue; +} + + +xmrig::Assembly xmrig::Asm::parse(const rapidjson::Value &value, Assembly defaultValue) +{ + if (value.IsBool()) { + return parse(value.IsBool()); + } + + if (value.IsString()) { + return parse(value.GetString(), defaultValue); + } + + return defaultValue; +} + + +const char *xmrig::Asm::toString(Assembly assembly) +{ + return asmNames[assembly]; +} + + +rapidjson::Value xmrig::Asm::toJSON(Assembly assembly) +{ + using namespace rapidjson; + + if (assembly == ASM_NONE) { + return Value(false); + } + + if (assembly == ASM_AUTO) { + return Value(true); + } + + return Value(StringRef(toString(assembly))); +} diff --git a/src/crypto/Asm.h b/src/crypto/Asm.h new file mode 100644 index 0000000000..3b755fd64e --- /dev/null +++ b/src/crypto/Asm.h @@ -0,0 +1,50 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * + * 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 Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_ASM_H +#define XMRIG_ASM_H + + +#include "common/xmrig.h" +#include "rapidjson/fwd.h" + + +namespace xmrig { + + +class Asm +{ +public: + static Assembly parse(const char *assembly, Assembly defaultValue = ASM_AUTO); + static Assembly parse(const rapidjson::Value &value, Assembly defaultValue = ASM_AUTO); + static const char *toString(Assembly assembly); + static rapidjson::Value toJSON(Assembly assembly); + + inline static Assembly parse(bool enable) { return enable ? ASM_AUTO : ASM_NONE; } +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_ASM_H */ diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 064dbdc285..42ea37b55f 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -561,6 +561,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si } +#ifndef XMRIG_NO_ASM extern "C" void cnv2_mainloop_ivybridge_asm(cryptonight_ctx *ctx); extern "C" void cnv2_mainloop_ryzen_asm(cryptonight_ctx *ctx); @@ -584,6 +585,7 @@ inline void cryptonight_single_hash_asm(const uint8_t *__restrict__ input, size_ xmrig::keccakf(reinterpret_cast(ctx[0]->state), 24); extra_hashes[ctx[0]->state[0] & 3](ctx[0]->state, 200, output); } +#endif template diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index d9d60f51c3..ff6be5859d 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -24,8 +24,10 @@ #include +#include "common/cpu/Cpu.h" #include "common/log/Log.h" #include "common/net/Pool.h" +#include "crypto/Asm.h" #include "rapidjson/document.h" #include "workers/CpuThread.h" @@ -37,9 +39,10 @@ #endif -xmrig::CpuThread::CpuThread(size_t index, Algo algorithm, AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch) : +xmrig::CpuThread::CpuThread(size_t index, Algo algorithm, AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch, Assembly assembly) : m_algorithm(algorithm), m_av(av), + m_assembly(assembly), m_prefetch(prefetch), m_softAES(softAES), m_priority(priority), @@ -50,23 +53,23 @@ xmrig::CpuThread::CpuThread(size_t index, Algo algorithm, AlgoVariant av, Multiw } -xmrig::CpuThread::~CpuThread() -{ -} - - bool xmrig::CpuThread::isSoftAES(AlgoVariant av) { return av == AV_SINGLE_SOFT || av == AV_DOUBLE_SOFT || av > AV_PENTA; } -xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant) +xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant, Assembly assembly) { assert(variant >= VARIANT_0 && variant < VARIANT_MAX); +# ifndef XMRIG_NO_ASM + constexpr const size_t count = VARIANT_MAX * 10 * 3 + 2; +# else constexpr const size_t count = VARIANT_MAX * 10 * 3; - static const cn_hash_fun func_table[count + 2] = { +# endif + + static const cn_hash_fun func_table[count] = { cryptonight_single_hash, cryptonight_double_hash, cryptonight_single_hash, @@ -243,13 +246,14 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif +# ifndef XMRIG_NO_ASM cryptonight_single_hash_asm, cryptonight_single_hash_asm +# endif }; - const size_t index = VARIANT_MAX * 10 * algorithm + 10 * variant + av - 1; - # ifndef NDEBUG + const size_t index = fnIndex(algorithm, av, variant, assembly); cn_hash_fun func = func_table[index]; assert(index < sizeof(func_table) / sizeof(func_table[0])); @@ -257,12 +261,12 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a return func; # else - return func_table[index]; + return func_table[fnIndex(algorithm, av, variant, assembly)]; # endif } -xmrig::CpuThread *xmrig::CpuThread::createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority) +xmrig::CpuThread *xmrig::CpuThread::createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority, Assembly assembly) { assert(av > AV_AUTO && av < AV_MAX); @@ -285,7 +289,7 @@ xmrig::CpuThread *xmrig::CpuThread::createFromAV(size_t index, Algo algorithm, A } } - return new CpuThread(index, algorithm, av, multiway(av), cpuId, priority, isSoftAES(av), false); + return new CpuThread(index, algorithm, av, multiway(av), cpuId, priority, isSoftAES(av), false, assembly); } @@ -303,7 +307,7 @@ xmrig::CpuThread *xmrig::CpuThread::createFromData(size_t index, Algo algorithm, assert(av > AV_AUTO && av < AV_MAX); - return new CpuThread(index, algorithm, static_cast(av), multiway, data.affinity, priority, softAES, false); + return new CpuThread(index, algorithm, static_cast(av), multiway, data.affinity, priority, softAES, false, data.assembly); } @@ -325,11 +329,14 @@ xmrig::CpuThread::Data xmrig::CpuThread::parse(const rapidjson::Value &object) } const auto &affinity = object["affine_to_cpu"]; - if (affinity.IsUint64()) { data.affinity = affinity.GetInt64(); } +# ifndef XMRIG_NO_ASM + data.assembly = Asm::parse(object["asm"]); +# endif + return data; } @@ -371,7 +378,11 @@ void xmrig::CpuThread::print() const LOG_DEBUG(GREEN_BOLD("CPU thread: ") " index " WHITE_BOLD("%zu") ", multiway " WHITE_BOLD("%d") ", av " WHITE_BOLD("%d") ",", index(), static_cast(multiway()), static_cast(m_av)); +# ifndef XMRIG_NO_ASM + LOG_DEBUG(" assembly: %s, affine_to_cpu: %" PRId64, Asm::toString(m_assembly), affinity()); +# else LOG_DEBUG(" affine_to_cpu: %" PRId64, affinity()); +# endif } #endif @@ -406,5 +417,35 @@ rapidjson::Value xmrig::CpuThread::toConfig(rapidjson::Document &doc) const obj.AddMember("low_power_mode", multiway(), allocator); obj.AddMember("affine_to_cpu", affinity() == -1L ? Value(kFalseType) : Value(affinity()), allocator); +# ifndef XMRIG_NO_ASM + obj.AddMember("asm", Asm::toJSON(m_assembly), allocator); +# endif + return obj; } + + +size_t xmrig::CpuThread::fnIndex(Algo algorithm, AlgoVariant av, Variant variant, Assembly assembly) +{ + const size_t index = VARIANT_MAX * 10 * algorithm + 10 * variant + av - 1; + +# ifndef XMRIG_NO_ASM + if (assembly == ASM_AUTO) { + assembly = Cpu::info()->assembly(); + } + + if (assembly == ASM_NONE) { + return index; + } + + constexpr const size_t offset = VARIANT_MAX * 10 * 3; + + if (algorithm == CRYPTONIGHT && variant == VARIANT_2) { + if (av == AV_SINGLE) { + return offset + assembly - 2; + } + } +# endif + + return index; +} diff --git a/src/workers/CpuThread.h b/src/workers/CpuThread.h index 622dc3a259..29ab96964e 100644 --- a/src/workers/CpuThread.h +++ b/src/workers/CpuThread.h @@ -40,7 +40,7 @@ class CpuThread : public IThread public: struct Data { - inline Data() : valid(false), affinity(-1L), multiway(SingleWay) {} + inline Data() : assembly(ASM_AUTO), valid(false), affinity(-1L), multiway(SingleWay) {} inline void setMultiway(int value) { @@ -50,27 +50,27 @@ class CpuThread : public IThread } } + Assembly assembly; bool valid; int64_t affinity; Multiway multiway; }; - CpuThread(size_t index, Algo algorithm, AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch); - ~CpuThread(); + CpuThread(size_t index, Algo algorithm, AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch, Assembly assembly); typedef void (*cn_hash_fun)(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx **ctx); static bool isSoftAES(AlgoVariant av); - static cn_hash_fun fn(Algo algorithm, AlgoVariant av, Variant variant); - static CpuThread *createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority); + static cn_hash_fun fn(Algo algorithm, AlgoVariant av, Variant variant, Assembly assembly); + static CpuThread *createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority, Assembly assembly); static CpuThread *createFromData(size_t index, Algo algorithm, const CpuThread::Data &data, int priority, bool softAES); static Data parse(const rapidjson::Value &object); static Multiway multiway(AlgoVariant av); inline bool isPrefetch() const { return m_prefetch; } inline bool isSoftAES() const { return m_softAES; } - inline cn_hash_fun fn(Variant variant) const { return fn(m_algorithm, m_av, variant); } + inline cn_hash_fun fn(Variant variant) const { return fn(m_algorithm, m_av, variant, m_assembly); } inline Algo algorithm() const override { return m_algorithm; } inline int priority() const override { return m_priority; } @@ -91,8 +91,11 @@ class CpuThread : public IThread rapidjson::Value toConfig(rapidjson::Document &doc) const override; private: + static size_t fnIndex(Algo algorithm, AlgoVariant av, Variant variant, Assembly assembly); + const Algo m_algorithm; const AlgoVariant m_av; + const Assembly m_assembly; const bool m_prefetch; const bool m_softAES; const int m_priority; From a6966525938a0faf52766a5b356b0e35cbfb1eb6 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 24 Sep 2018 14:57:30 +0300 Subject: [PATCH 083/102] Fix 32bit build. --- cmake/asm.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/asm.cmake b/cmake/asm.cmake index a9b76ffda4..d6c88e99fd 100644 --- a/cmake/asm.cmake +++ b/cmake/asm.cmake @@ -1,4 +1,4 @@ -if (WITH_ASM AND NOT XMRIG_ARM) +if (WITH_ASM AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8) set(XMRIG_ASM_LIBRARY "xmrig-asm") if (CMAKE_CXX_COMPILER_ID MATCHES MSVC) From f7cfbc6271a0e50bd236fbf0ac36cc3032576a8d Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 24 Sep 2018 20:43:31 +0300 Subject: [PATCH 084/102] Fixed crash when use ASM code for MSYS2, thanks @SChernykh. --- cmake/asm.cmake | 21 ++++++++++++--------- src/crypto/asm/cnv2_main_loop_win.S | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 src/crypto/asm/cnv2_main_loop_win.S diff --git a/cmake/asm.cmake b/cmake/asm.cmake index d6c88e99fd..cb50f0d95e 100644 --- a/cmake/asm.cmake +++ b/cmake/asm.cmake @@ -1,20 +1,23 @@ if (WITH_ASM AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8) set(XMRIG_ASM_LIBRARY "xmrig-asm") - if (CMAKE_CXX_COMPILER_ID MATCHES MSVC) + if (CMAKE_C_COMPILER_ID MATCHES MSVC) enable_language(ASM_MASM) - set_property(SOURCE "src/crypto/asm/cnv2_main_loop.asm" PROPERTY ASM_MASM) - add_library(${XMRIG_ASM_LIBRARY} STATIC - "src/crypto/asm/cnv2_main_loop.asm" - ) + set(XMRIG_ASM_FILE "src/crypto/asm/cnv2_main_loop.asm") + set_property(SOURCE ${XMRIG_ASM_FILE} PROPERTY ASM_MASM) else() enable_language(ASM) - set_property(SOURCE "src/crypto/asm/cnv2_main_loop.S" PROPERTY C) - add_library(${XMRIG_ASM_LIBRARY} STATIC - "src/crypto/asm/cnv2_main_loop.S" - ) + + if (WIN32 AND CMAKE_C_COMPILER_ID MATCHES GNU) + set(XMRIG_ASM_FILE "src/crypto/asm/cnv2_main_loop_win.S") + else() + set(XMRIG_ASM_FILE "src/crypto/asm/cnv2_main_loop.S") + endif() + + set_property(SOURCE ${XMRIG_ASM_FILE} PROPERTY C) endif() + add_library(${XMRIG_ASM_LIBRARY} STATIC ${XMRIG_ASM_FILE}) set(XMRIG_ASM_SOURCES src/crypto/Asm.h src/crypto/Asm.cpp) set_property(TARGET ${XMRIG_ASM_LIBRARY} PROPERTY LINKER_LANGUAGE C) else() diff --git a/src/crypto/asm/cnv2_main_loop_win.S b/src/crypto/asm/cnv2_main_loop_win.S new file mode 100644 index 0000000000..3c2028b61c --- /dev/null +++ b/src/crypto/asm/cnv2_main_loop_win.S @@ -0,0 +1,15 @@ +#define ALIGN .align +.intel_syntax noprefix +.section .text +.global cnv2_mainloop_ivybridge_asm +.global cnv2_mainloop_ryzen_asm + +ALIGN 16 +cnv2_mainloop_ivybridge_asm: + #include "cnv2_main_loop_ivybridge.inc" + ret 0 + +ALIGN 16 +cnv2_mainloop_ryzen_asm: + #include "cnv2_main_loop_ryzen.inc" + ret 0 From 13e664c442b1e202f751a6b7777feec894742e91 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 25 Sep 2018 09:25:47 +0300 Subject: [PATCH 085/102] Added ASM code for double hash mode, thanks @SChernykh. --- src/crypto/CryptoNight_x86.h | 29 +- .../asm/cnv2_double_main_loop_sandybridge.inc | 410 ++++++++++++++++++ src/crypto/asm/cnv2_main_loop.S | 10 + src/crypto/asm/cnv2_main_loop.asm | 7 + src/crypto/asm/cnv2_main_loop_win.S | 6 + src/workers/CpuThread.cpp | 9 +- 6 files changed, 467 insertions(+), 4 deletions(-) create mode 100644 src/crypto/asm/cnv2_double_main_loop_sandybridge.inc diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 42ea37b55f..b1a723245c 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -564,6 +564,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si #ifndef XMRIG_NO_ASM extern "C" void cnv2_mainloop_ivybridge_asm(cryptonight_ctx *ctx); extern "C" void cnv2_mainloop_ryzen_asm(cryptonight_ctx *ctx); +extern "C" void cnv2_double_mainloop_sandybridge_asm(cryptonight_ctx* ctx0, cryptonight_ctx* ctx1); template @@ -572,7 +573,7 @@ inline void cryptonight_single_hash_asm(const uint8_t *__restrict__ input, size_ constexpr size_t MEM = xmrig::cn_select_memory(); xmrig::keccak(input, size, ctx[0]->state); - cn_explode_scratchpad((__m128i*) ctx[0]->state, (__m128i*) ctx[0]->memory); + cn_explode_scratchpad(reinterpret_cast<__m128i*>(ctx[0]->state), reinterpret_cast<__m128i*>(ctx[0]->memory)); if (ASM == xmrig::ASM_INTEL) { cnv2_mainloop_ivybridge_asm(ctx[0]); @@ -581,10 +582,34 @@ inline void cryptonight_single_hash_asm(const uint8_t *__restrict__ input, size_ cnv2_mainloop_ryzen_asm(ctx[0]); } - cn_implode_scratchpad((__m128i*) ctx[0]->memory, (__m128i*) ctx[0]->state); + cn_implode_scratchpad(reinterpret_cast<__m128i*>(ctx[0]->memory), reinterpret_cast<__m128i*>(ctx[0]->state)); xmrig::keccakf(reinterpret_cast(ctx[0]->state), 24); extra_hashes[ctx[0]->state[0] & 3](ctx[0]->state, 200, output); } + + +template +inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) +{ + constexpr size_t MEM = xmrig::cn_select_memory(); + + xmrig::keccak(input, size, ctx[0]->state); + xmrig::keccak(input + size, size, ctx[1]->state); + + cn_explode_scratchpad(reinterpret_cast<__m128i*>(ctx[0]->state), reinterpret_cast<__m128i*>(ctx[0]->memory)); + cn_explode_scratchpad(reinterpret_cast<__m128i*>(ctx[1]->state), reinterpret_cast<__m128i*>(ctx[1]->memory)); + + cnv2_double_mainloop_sandybridge_asm(ctx[0], ctx[1]); + + cn_implode_scratchpad(reinterpret_cast<__m128i*>(ctx[0]->memory), reinterpret_cast<__m128i*>(ctx[0]->state)); + cn_implode_scratchpad(reinterpret_cast<__m128i*>(ctx[1]->memory), reinterpret_cast<__m128i*>(ctx[1]->state)); + + xmrig::keccakf(reinterpret_cast(ctx[0]->state), 24); + xmrig::keccakf(reinterpret_cast(ctx[1]->state), 24); + + extra_hashes[ctx[0]->state[0] & 3](ctx[0]->state, 200, output); + extra_hashes[ctx[1]->state[0] & 3](ctx[1]->state, 200, output + 32); +} #endif diff --git a/src/crypto/asm/cnv2_double_main_loop_sandybridge.inc b/src/crypto/asm/cnv2_double_main_loop_sandybridge.inc new file mode 100644 index 0000000000..e8251bc7ff --- /dev/null +++ b/src/crypto/asm/cnv2_double_main_loop_sandybridge.inc @@ -0,0 +1,410 @@ + mov rax, rsp + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 184 + + stmxcsr DWORD PTR [rsp+272] + mov DWORD PTR [rsp+276], 24448 + ldmxcsr DWORD PTR [rsp+276] + + mov r13, QWORD PTR [rcx+224] + mov r9, rdx + mov r10, QWORD PTR [rcx+32] + mov r8, rcx + xor r10, QWORD PTR [rcx] + mov r14d, 524288 + mov r11, QWORD PTR [rcx+40] + xor r11, QWORD PTR [rcx+8] + mov rsi, QWORD PTR [rdx+224] + mov rdx, QWORD PTR [rcx+56] + xor rdx, QWORD PTR [rcx+24] + mov rdi, QWORD PTR [r9+32] + xor rdi, QWORD PTR [r9] + mov rbp, QWORD PTR [r9+40] + xor rbp, QWORD PTR [r9+8] + movq xmm0, rdx + movaps XMMWORD PTR [rax-88], xmm6 + movaps XMMWORD PTR [rax-104], xmm7 + movaps XMMWORD PTR [rax-120], xmm8 + movaps XMMWORD PTR [rsp+112], xmm9 + movaps XMMWORD PTR [rsp+96], xmm10 + movaps XMMWORD PTR [rsp+80], xmm11 + movaps XMMWORD PTR [rsp+64], xmm12 + movaps XMMWORD PTR [rsp+48], xmm13 + movaps XMMWORD PTR [rsp+32], xmm14 + movaps XMMWORD PTR [rsp+16], xmm15 + mov rdx, r10 + movq xmm4, QWORD PTR [r8+96] + and edx, 2097136 + mov rax, QWORD PTR [rcx+48] + xorps xmm13, xmm13 + xor rax, QWORD PTR [rcx+16] + mov rcx, QWORD PTR [rcx+88] + xor rcx, QWORD PTR [r8+72] + movq xmm5, QWORD PTR [r8+104] + movq xmm7, rax + + mov eax, 1 + shl rax, 52 + movq xmm14, rax + punpcklqdq xmm14, xmm14 + + mov eax, 1023 + shl rax, 52 + movq xmm12, rax + punpcklqdq xmm12, xmm12 + + mov rax, QWORD PTR [r8+80] + xor rax, QWORD PTR [r8+64] + punpcklqdq xmm7, xmm0 + movq xmm0, rcx + mov rcx, QWORD PTR [r9+56] + xor rcx, QWORD PTR [r9+24] + movq xmm3, rax + mov rax, QWORD PTR [r9+48] + xor rax, QWORD PTR [r9+16] + punpcklqdq xmm3, xmm0 + movq xmm0, rcx + mov QWORD PTR [rsp], r13 + mov rcx, QWORD PTR [r9+88] + xor rcx, QWORD PTR [r9+72] + movq xmm6, rax + mov rax, QWORD PTR [r9+80] + xor rax, QWORD PTR [r9+64] + punpcklqdq xmm6, xmm0 + movq xmm0, rcx + mov QWORD PTR [rsp+256], r10 + mov rcx, rdi + mov QWORD PTR [rsp+264], r11 + movq xmm8, rax + and ecx, 2097136 + punpcklqdq xmm8, xmm0 + movq xmm0, QWORD PTR [r9+96] + punpcklqdq xmm4, xmm0 + movq xmm0, QWORD PTR [r9+104] + lea r8, QWORD PTR [rcx+rsi] + movdqu xmm11, XMMWORD PTR [r8] + punpcklqdq xmm5, xmm0 + lea r9, QWORD PTR [rdx+r13] + movdqu xmm15, XMMWORD PTR [r9] + + ALIGN 16 +main_loop_double_sandybridge: + movdqu xmm9, xmm15 + mov eax, edx + mov ebx, edx + xor eax, 16 + xor ebx, 32 + xor edx, 48 + + movq xmm0, r11 + movq xmm2, r10 + punpcklqdq xmm2, xmm0 + aesenc xmm9, xmm2 + + movdqu xmm0, XMMWORD PTR [rax+r13] + movdqu xmm1, XMMWORD PTR [rbx+r13] + paddq xmm0, xmm7 + paddq xmm1, xmm2 + movdqu XMMWORD PTR [rbx+r13], xmm0 + movdqu xmm0, XMMWORD PTR [rdx+r13] + movdqu XMMWORD PTR [rdx+r13], xmm1 + paddq xmm0, xmm3 + movdqu XMMWORD PTR [rax+r13], xmm0 + + movq r11, xmm9 + mov edx, r11d + and edx, 2097136 + movdqa xmm0, xmm9 + pxor xmm0, xmm7 + movdqu XMMWORD PTR [r9], xmm0 + + lea rbx, QWORD PTR [rdx+r13] + mov r10, QWORD PTR [rdx+r13] + + movdqu xmm10, xmm11 + movq xmm0, rbp + movq xmm11, rdi + punpcklqdq xmm11, xmm0 + aesenc xmm10, xmm11 + + mov eax, ecx + mov r12d, ecx + xor eax, 16 + xor r12d, 32 + xor ecx, 48 + + movdqu xmm0, XMMWORD PTR [rax+rsi] + paddq xmm0, xmm6 + movdqu xmm1, XMMWORD PTR [r12+rsi] + movdqu XMMWORD PTR [r12+rsi], xmm0 + paddq xmm1, xmm11 + movdqu xmm0, XMMWORD PTR [rcx+rsi] + movdqu XMMWORD PTR [rcx+rsi], xmm1 + paddq xmm0, xmm8 + movdqu XMMWORD PTR [rax+rsi], xmm0 + + movq rcx, xmm10 + and ecx, 2097136 + + movdqa xmm0, xmm10 + pxor xmm0, xmm6 + movdqu XMMWORD PTR [r8], xmm0 + mov r12, QWORD PTR [rcx+rsi] + + mov r9, QWORD PTR [rbx+8] + + xor edx, 16 + mov r8d, edx + mov r15d, edx + + movq rdx, xmm5 + shl rdx, 32 + movq rax, xmm4 + xor rdx, rax + xor r10, rdx + mov rax, r10 + mul r11 + mov r11d, r8d + xor r11d, 48 + movq xmm0, rdx + xor rdx, [r11+r13] + movq xmm1, rax + xor rax, [r11+r13+8] + punpcklqdq xmm0, xmm1 + + pxor xmm0, XMMWORD PTR [r8+r13] + xor r8d, 32 + movdqu xmm1, XMMWORD PTR [r11+r13] + paddq xmm0, xmm7 + paddq xmm1, xmm2 + movdqu XMMWORD PTR [r11+r13], xmm0 + movdqu xmm0, XMMWORD PTR [r8+r13] + movdqu XMMWORD PTR [r8+r13], xmm1 + paddq xmm0, xmm3 + movdqu XMMWORD PTR [r15+r13], xmm0 + + mov r11, QWORD PTR [rsp+256] + add r11, rdx + mov rdx, QWORD PTR [rsp+264] + add rdx, rax + mov QWORD PTR [rbx], r11 + xor r11, r10 + mov QWORD PTR [rbx+8], rdx + xor rdx, r9 + mov QWORD PTR [rsp+256], r11 + and r11d, 2097136 + mov QWORD PTR [rsp+264], rdx + mov QWORD PTR [rsp+8], r11 + lea r15, QWORD PTR [r11+r13] + movdqu xmm15, XMMWORD PTR [r11+r13] + lea r13, QWORD PTR [rsi+rcx] + movdqa xmm0, xmm5 + psrldq xmm0, 8 + movaps xmm2, xmm13 + movq r10, xmm0 + psllq xmm5, 1 + shl r10, 32 + movdqa xmm0, xmm9 + psrldq xmm0, 8 + movdqa xmm1, xmm10 + movq r11, xmm0 + psrldq xmm1, 8 + movq r8, xmm1 + psrldq xmm4, 8 + movaps xmm0, xmm13 + movq rax, xmm4 + xor r10, rax + movaps xmm1, xmm13 + xor r10, r12 + lea rax, QWORD PTR [r11+1] + shr rax, 1 + movdqa xmm3, xmm9 + punpcklqdq xmm3, xmm10 + paddq xmm5, xmm3 + movq rdx, xmm5 + psrldq xmm5, 8 + cvtsi2sd xmm2, rax + or edx, -2147483647 + lea rax, QWORD PTR [r8+1] + shr rax, 1 + movq r9, xmm5 + cvtsi2sd xmm0, rax + or r9d, -2147483647 + cvtsi2sd xmm1, rdx + unpcklpd xmm2, xmm0 + movaps xmm0, xmm13 + cvtsi2sd xmm0, r9 + unpcklpd xmm1, xmm0 + divpd xmm2, xmm1 + paddq xmm2, xmm14 + cvttsd2si rax, xmm2 + psrldq xmm2, 8 + mov rbx, rax + imul rax, rdx + sub r11, rax + js div_fix_1_sandybridge +div_fix_1_ret_sandybridge: + + cvttsd2si rdx, xmm2 + mov rax, rdx + imul rax, r9 + movd xmm2, r11d + movd xmm4, ebx + sub r8, rax + js div_fix_2_sandybridge +div_fix_2_ret_sandybridge: + + movd xmm1, r8d + movd xmm0, edx + punpckldq xmm2, xmm1 + punpckldq xmm4, xmm0 + punpckldq xmm4, xmm2 + paddq xmm3, xmm4 + movdqa xmm0, xmm3 + psrlq xmm0, 12 + paddq xmm0, xmm12 + sqrtpd xmm1, xmm0 + movq r9, xmm1 + movdqa xmm5, xmm1 + psrlq xmm5, 19 + test r9, 524287 + je sqrt_fix_1_sandybridge +sqrt_fix_1_ret_sandybridge: + + movq r9, xmm10 + psrldq xmm1, 8 + movq r8, xmm1 + test r8, 524287 + je sqrt_fix_2_sandybridge +sqrt_fix_2_ret_sandybridge: + + mov r12d, ecx + mov r8d, ecx + xor r12d, 16 + xor r8d, 32 + xor ecx, 48 + mov rax, r10 + mul r9 + movq xmm0, rax + movq xmm3, rdx + punpcklqdq xmm3, xmm0 + + movdqu xmm0, XMMWORD PTR [r12+rsi] + pxor xmm0, xmm3 + movdqu xmm1, XMMWORD PTR [r8+rsi] + xor rdx, [r8+rsi] + xor rax, [r8+rsi+8] + movdqu xmm3, XMMWORD PTR [rcx+rsi] + paddq xmm0, xmm6 + paddq xmm1, xmm11 + paddq xmm3, xmm8 + movdqu XMMWORD PTR [r8+rsi], xmm0 + movdqu XMMWORD PTR [rcx+rsi], xmm1 + movdqu XMMWORD PTR [r12+rsi], xmm3 + + add rdi, rdx + mov QWORD PTR [r13], rdi + xor rdi, r10 + mov ecx, edi + and ecx, 2097136 + lea r8, QWORD PTR [rcx+rsi] + + mov rdx, QWORD PTR [r13+8] + add rbp, rax + mov QWORD PTR [r13+8], rbp + movdqu xmm11, XMMWORD PTR [rcx+rsi] + xor rbp, rdx + mov r13, QWORD PTR [rsp] + movdqa xmm3, xmm7 + mov rdx, QWORD PTR [rsp+8] + movdqa xmm8, xmm6 + mov r10, QWORD PTR [rsp+256] + movdqa xmm7, xmm9 + mov r11, QWORD PTR [rsp+264] + movdqa xmm6, xmm10 + mov r9, r15 + dec r14d + jne main_loop_double_sandybridge + + ldmxcsr DWORD PTR [rsp+272] + movaps xmm13, XMMWORD PTR [rsp+48] + lea r11, QWORD PTR [rsp+184] + movaps xmm6, XMMWORD PTR [r11-24] + movaps xmm7, XMMWORD PTR [r11-40] + movaps xmm8, XMMWORD PTR [r11-56] + movaps xmm9, XMMWORD PTR [r11-72] + movaps xmm10, XMMWORD PTR [r11-88] + movaps xmm11, XMMWORD PTR [r11-104] + movaps xmm12, XMMWORD PTR [r11-120] + movaps xmm14, XMMWORD PTR [rsp+32] + movaps xmm15, XMMWORD PTR [rsp+16] + mov rsp, r11 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + pop rbx + jmp cnv2_double_mainloop_asm_sandybridge_endp + +div_fix_1_sandybridge: + dec rbx + add r11, rdx + jmp div_fix_1_ret_sandybridge + +div_fix_2_sandybridge: + dec rdx + add r8, r9 + jmp div_fix_2_ret_sandybridge + +sqrt_fix_1_sandybridge: + movq r8, xmm3 + movdqa xmm0, xmm5 + psrldq xmm0, 8 + dec r9 + mov r11d, -1022 + shl r11, 32 + mov rax, r9 + shr r9, 19 + shr rax, 20 + mov rdx, r9 + sub rdx, rax + lea rdx, [rdx+r11+1] + add rax, r11 + imul rdx, rax + sub rdx, r8 + adc r9, 0 + movq xmm5, r9 + punpcklqdq xmm5, xmm0 + jmp sqrt_fix_1_ret_sandybridge + +sqrt_fix_2_sandybridge: + psrldq xmm3, 8 + movq r11, xmm3 + dec r8 + mov ebx, -1022 + shl rbx, 32 + mov rax, r8 + shr r8, 19 + shr rax, 20 + mov rdx, r8 + sub rdx, rax + lea rdx, [rdx+rbx+1] + add rax, rbx + imul rdx, rax + sub rdx, r11 + adc r8, 0 + movq xmm0, r8 + punpcklqdq xmm5, xmm0 + jmp sqrt_fix_2_ret_sandybridge + +cnv2_double_mainloop_asm_sandybridge_endp: diff --git a/src/crypto/asm/cnv2_main_loop.S b/src/crypto/asm/cnv2_main_loop.S index 580a458809..4dbcbbda71 100644 --- a/src/crypto/asm/cnv2_main_loop.S +++ b/src/crypto/asm/cnv2_main_loop.S @@ -9,6 +9,7 @@ #endif .global FN_PREFIX(cnv2_mainloop_ivybridge_asm) .global FN_PREFIX(cnv2_mainloop_ryzen_asm) +.global FN_PREFIX(cnv2_double_mainloop_sandybridge_asm) ALIGN 16 FN_PREFIX(cnv2_mainloop_ivybridge_asm): @@ -25,3 +26,12 @@ FN_PREFIX(cnv2_mainloop_ryzen_asm): #include "cnv2_main_loop_ryzen.inc" add rsp, 48 ret 0 + +ALIGN 16 +FN_PREFIX(cnv2_double_mainloop_sandybridge_asm): + sub rsp, 48 + mov rcx, rdi + mov rdx, rsi + #include "cnv2_double_main_loop_sandybridge.inc" + add rsp, 48 + ret 0 diff --git a/src/crypto/asm/cnv2_main_loop.asm b/src/crypto/asm/cnv2_main_loop.asm index 7ec895c490..d952226752 100644 --- a/src/crypto/asm/cnv2_main_loop.asm +++ b/src/crypto/asm/cnv2_main_loop.asm @@ -1,6 +1,7 @@ _TEXT_CNV2_MAINLOOP SEGMENT PAGE READ EXECUTE PUBLIC cnv2_mainloop_ivybridge_asm PUBLIC cnv2_mainloop_ryzen_asm +PUBLIC cnv2_double_mainloop_sandybridge_asm ALIGN 64 cnv2_mainloop_ivybridge_asm PROC @@ -14,5 +15,11 @@ cnv2_mainloop_ryzen_asm PROC ret 0 cnv2_mainloop_ryzen_asm ENDP +ALIGN 64 +cnv2_double_mainloop_sandybridge_asm PROC + INCLUDE cnv2_double_main_loop_sandybridge.inc + ret 0 +cnv2_double_mainloop_sandybridge_asm ENDP + _TEXT_CNV2_MAINLOOP ENDS END diff --git a/src/crypto/asm/cnv2_main_loop_win.S b/src/crypto/asm/cnv2_main_loop_win.S index 3c2028b61c..f06e4fa462 100644 --- a/src/crypto/asm/cnv2_main_loop_win.S +++ b/src/crypto/asm/cnv2_main_loop_win.S @@ -3,6 +3,7 @@ .section .text .global cnv2_mainloop_ivybridge_asm .global cnv2_mainloop_ryzen_asm +.global cnv2_double_mainloop_sandybridge_asm ALIGN 16 cnv2_mainloop_ivybridge_asm: @@ -13,3 +14,8 @@ ALIGN 16 cnv2_mainloop_ryzen_asm: #include "cnv2_main_loop_ryzen.inc" ret 0 + +ALIGN 16 +cnv2_double_mainloop_sandybridge_asm: + #include "cnv2_double_main_loop_sandybridge.inc" + ret 0 diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index ff6be5859d..4b52814866 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -64,7 +64,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a assert(variant >= VARIANT_0 && variant < VARIANT_MAX); # ifndef XMRIG_NO_ASM - constexpr const size_t count = VARIANT_MAX * 10 * 3 + 2; + constexpr const size_t count = VARIANT_MAX * 10 * 3 + 3; # else constexpr const size_t count = VARIANT_MAX * 10 * 3; # endif @@ -248,7 +248,8 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a # endif # ifndef XMRIG_NO_ASM cryptonight_single_hash_asm, - cryptonight_single_hash_asm + cryptonight_single_hash_asm, + cryptonight_double_hash_asm # endif }; @@ -444,6 +445,10 @@ size_t xmrig::CpuThread::fnIndex(Algo algorithm, AlgoVariant av, Variant variant if (av == AV_SINGLE) { return offset + assembly - 2; } + + if (av == AV_DOUBLE) { + return offset + 2; + } } # endif From 4a3a4c00c4d86fd551e5f7cbc86718c20aa6337d Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 25 Sep 2018 09:40:09 +0300 Subject: [PATCH 086/102] Fix template declaration. --- src/crypto/CryptoNight_x86.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index b1a723245c..8dcdd41446 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -588,7 +588,7 @@ inline void cryptonight_single_hash_asm(const uint8_t *__restrict__ input, size_ } -template +template inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) { constexpr size_t MEM = xmrig::cn_select_memory(); From 006c83821dffd7badafe7bdd51957854943fc4a1 Mon Sep 17 00:00:00 2001 From: xmrig Date: Tue, 25 Sep 2018 10:15:41 +0300 Subject: [PATCH 087/102] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e1e2412c2..c75025e29f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # v2.8.0 - **[#753](https://github.com/xmrig/xmrig/issues/753) Added new algorithm [CryptoNight variant 2](https://github.com/xmrig/xmrig/issues/753) for Monero fork, thanks [@SChernykh](https://github.com/SChernykh).** + - Added global and per thread option `"asm"` and and command line equivalent. - [#758](https://github.com/xmrig/xmrig/issues/758) **Added SSL/TLS support for secure connections to pools.** + - Added per pool options `"tls"` and `"tls-fingerprint"` and command line equivalents. - [#245](https://github.com/xmrig/xmrig-proxy/issues/245) Fixed API ID collision when run multiple miners on same machine. - [#757](https://github.com/xmrig/xmrig/issues/757) Fixed send buffer overflow. From 7a16ee6a8802991a6f82f1c18baa6bba2454186e Mon Sep 17 00:00:00 2001 From: xmrig Date: Tue, 25 Sep 2018 10:16:29 +0300 Subject: [PATCH 088/102] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c75025e29f..bd3f23fb01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # v2.8.0 - **[#753](https://github.com/xmrig/xmrig/issues/753) Added new algorithm [CryptoNight variant 2](https://github.com/xmrig/xmrig/issues/753) for Monero fork, thanks [@SChernykh](https://github.com/SChernykh).** - Added global and per thread option `"asm"` and and command line equivalent. -- [#758](https://github.com/xmrig/xmrig/issues/758) **Added SSL/TLS support for secure connections to pools.** +- **[#758](https://github.com/xmrig/xmrig/issues/758) Added SSL/TLS support for secure connections to pools.** - Added per pool options `"tls"` and `"tls-fingerprint"` and command line equivalents. - [#245](https://github.com/xmrig/xmrig-proxy/issues/245) Fixed API ID collision when run multiple miners on same machine. - [#757](https://github.com/xmrig/xmrig/issues/757) Fixed send buffer overflow. From 5419d9a3d462bb8cb5399170cfc1871e667d9de4 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 26 Sep 2018 20:35:27 +0300 Subject: [PATCH 089/102] New donations proxy addresses with SSL/TLS support. --- src/net/strategies/DonateStrategy.cpp | 20 +++++--------------- src/net/strategies/DonateStrategy.h | 6 +++--- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 395c53bbf6..6fc90842e3 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -33,10 +33,6 @@ #include "net/strategies/DonateStrategy.h" -const static char *kDonatePool1 = "miner.fee.xmrig.com"; -const static char *kDonatePool2 = "emergency.fee.xmrig.com"; - - static inline float randomf(float min, float max) { return (max - min) * ((((float) rand()) / (float) RAND_MAX)) + min; } @@ -55,17 +51,11 @@ DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IS xmrig::keccak(reinterpret_cast(user), strlen(user), hash); Job::toHex(hash, 32, userId); - if (algo == xmrig::CRYPTONIGHT) { - m_pools.push_back(Pool(kDonatePool1, 6666, userId, nullptr, false, true)); - m_pools.push_back(Pool(kDonatePool1, 80, userId, nullptr, false, true)); - m_pools.push_back(Pool(kDonatePool2, 5555, "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", "emergency", false, false)); - } - else if (algo == xmrig::CRYPTONIGHT_HEAVY) { - m_pools.push_back(Pool(kDonatePool1, 8888, userId, nullptr, false, true)); - } - else { - m_pools.push_back(Pool(kDonatePool1, 5555, userId, nullptr, false, true)); - } +# ifndef XMRIG_NO_TLS + m_pools.push_back(Pool("donate.ssl.xmrig.com", 443, userId, nullptr, false, true, true)); +# endif + + m_pools.push_back(Pool("donate.v2.xmrig.com", 3333, userId, nullptr, false, true)); for (Pool &pool : m_pools) { pool.adjust(xmrig::Algorithm(algo, xmrig::VARIANT_AUTO)); diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 95ff6608a6..e75e41a4b8 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __DONATESTRATEGY_H__ -#define __DONATESTRATEGY_H__ +#ifndef XMRIG_DONATESTRATEGY_H +#define XMRIG_DONATESTRATEGY_H #include @@ -76,4 +76,4 @@ class DonateStrategy : public IStrategy, public IStrategyListener uv_timer_t m_timer; }; -#endif /* __DONATESTRATEGY_H__ */ +#endif /* XMRIG_DONATESTRATEGY_H */ From 7fa3d09f0bfae0f2f135f5eb092ab5ca5d7d122a Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 27 Sep 2018 17:17:19 +0300 Subject: [PATCH 090/102] Fix missing "asm" in generated config. --- src/core/Config.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 20a3aece0f..79b19265c5 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -69,6 +69,10 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("algo", StringRef(algorithm().name()), allocator); +# ifndef XMRIG_NO_ASM + doc.AddMember("asm", Asm::toJSON(m_assembly), allocator); +# endif + Value api(kObjectType); api.AddMember("port", apiPort(), allocator); api.AddMember("access-token", apiToken() ? Value(StringRef(apiToken())).Move() : Value(kNullType).Move(), allocator); From d82e809401106712b64548e6f300ee0c392756ea Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 27 Sep 2018 19:07:04 +0300 Subject: [PATCH 091/102] Add "autosave" config option. --- src/common/config/CommonConfig.cpp | 9 +++++++-- src/common/config/CommonConfig.h | 2 ++ src/common/interfaces/IConfig.h | 1 + src/config.json | 13 +++++++++---- src/core/Config.cpp | 17 ++++++++++------- src/core/Config.h | 2 ++ src/core/ConfigLoader_platform.h | 1 + src/workers/Workers.cpp | 4 ++++ 8 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index b70d5e3d5b..beb2d0c92e 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -67,6 +67,7 @@ xmrig::CommonConfig::CommonConfig() : m_adjusted(false), m_apiIPv6(false), m_apiRestricted(true), + m_autoSave(true), m_background(false), m_colors(true), m_dryRun(false), @@ -217,7 +218,7 @@ bool xmrig::CommonConfig::save() rapidjson::PrettyWriter writer(os); doc.Accept(writer); - fclose(fp); + fflush(fp); uv_fs_close(uv_default_loop(), &req, fd, nullptr); uv_fs_req_cleanup(&req); @@ -308,10 +309,14 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable) m_apiRestricted = enable; break; - case IConfig::DryRunKey: /* --dry-run */ + case DryRunKey: /* --dry-run */ m_dryRun = enable; break; + case AutoSaveKey: + m_autoSave = enable; + break; + default: break; } diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 7643a1a5fb..422a6bb2f5 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -44,6 +44,7 @@ class CommonConfig : public IConfig inline bool isApiIPv6() const { return m_apiIPv6; } inline bool isApiRestricted() const { return m_apiRestricted; } + inline bool isAutoSave() const { return m_autoSave; } inline bool isBackground() const { return m_background; } inline bool isColors() const { return m_colors; } inline bool isDryRun() const { return m_dryRun; } @@ -88,6 +89,7 @@ class CommonConfig : public IConfig bool m_adjusted; bool m_apiIPv6; bool m_apiRestricted; + bool m_autoSave; bool m_background; bool m_colors; bool m_dryRun; diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 0fcac2d15a..69f2ffab93 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -65,6 +65,7 @@ class IConfig WatchKey = 1105, TlsKey = 1013, FingerprintKey = 1014, + AutoSaveKey = 1016, // xmrig common CPUPriorityKey = 1021, diff --git a/src/config.json b/src/config.json index b2dad4c9e5..d4fb42f376 100644 --- a/src/config.json +++ b/src/config.json @@ -3,10 +3,13 @@ "api": { "port": 0, "access-token": null, + "id": null, "worker-id": null, "ipv6": false, - "restricted": true + "restricted": false }, + "asm": true, + "autosave": true, "av": 0, "background": false, "colors": true, @@ -19,13 +22,15 @@ "max-cpu-usage": 75, "pools": [ { - "url": "proxy.fee.xmrig.com:9999", - "user": "YOUR_WALLET", + "url": "donate.v2.xmrig.com:3333", + "user": "YOUR_WALLET_ADDRESS", "pass": "x", "rig-id": null, "nicehash": false, "keepalive": false, - "variant": 1 + "variant": 1, + "tls": false, + "tls-fingerprint": null } ], "print-time": 60, diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 79b19265c5..c8891c77dc 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -47,6 +47,7 @@ xmrig::Config::Config() : xmrig::CommonConfig(), m_assembly(ASM_AUTO), m_hugePages(true), m_safe(false), + m_shouldSave(false), m_maxCpuUsage(75), m_priority(-1) { @@ -69,10 +70,6 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("algo", StringRef(algorithm().name()), allocator); -# ifndef XMRIG_NO_ASM - doc.AddMember("asm", Asm::toJSON(m_assembly), allocator); -# endif - Value api(kObjectType); api.AddMember("port", apiPort(), allocator); api.AddMember("access-token", apiToken() ? Value(StringRef(apiToken())).Move() : Value(kNullType).Move(), allocator); @@ -82,6 +79,11 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const api.AddMember("restricted", isApiRestricted(), allocator); doc.AddMember("api", api, allocator); +# ifndef XMRIG_NO_ASM + doc.AddMember("asm", Asm::toJSON(m_assembly), allocator); +# endif + + doc.AddMember("autosave", isAutoSave(), allocator); doc.AddMember("av", algoVariant(), allocator); doc.AddMember("background", isBackground(), allocator); doc.AddMember("colors", isColors(), allocator); @@ -113,7 +115,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("retry-pause", retryPause(), allocator); doc.AddMember("safe", m_safe, allocator); - if (threadsMode() == Advanced) { + if (threadsMode() != Simple) { Value threads(kArrayType); for (const IThread *thread : m_threads.list) { @@ -123,7 +125,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("threads", threads, allocator); } else { - doc.AddMember("threads", threadsMode() == Automatic ? Value(kNullType) : Value(threadsCount()), allocator); + doc.AddMember("threads", threadsCount(), allocator); } doc.AddMember("user-agent", userAgent() ? Value(StringRef(userAgent())).Move() : Value(kNullType).Move(), allocator); @@ -163,7 +165,7 @@ bool xmrig::Config::finalize() return true; } - const AlgoVariant av = getAlgoVariant(); + const AlgoVariant av = getAlgoVariant(); m_threads.mode = m_threads.count ? Simple : Automatic; const size_t size = CpuThread::multiway(av) * cn_select_memory(m_algorithm.algo()) / 1024; @@ -182,6 +184,7 @@ bool xmrig::Config::finalize() m_threads.list.push_back(CpuThread::createFromAV(i, m_algorithm.algo(), av, m_threads.mask, m_priority, m_assembly)); } + m_shouldSave = m_threads.mode == Automatic; return true; } diff --git a/src/core/Config.h b/src/core/Config.h index 95afc34cd1..eb33ee1457 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -78,6 +78,7 @@ class Config : public CommonConfig inline AlgoVariant algoVariant() const { return m_algoVariant; } inline Assembly assembly() const { return m_assembly; } inline bool isHugePages() const { return m_hugePages; } + inline bool isShouldSave() const { return m_shouldSave && isAutoSave(); } inline const std::vector &threads() const { return m_threads.list; } inline int priority() const { return m_priority; } inline int threadsCount() const { return m_threads.list.size(); } @@ -119,6 +120,7 @@ class Config : public CommonConfig Assembly m_assembly; bool m_hugePages; bool m_safe; + bool m_shouldSave; int m_maxCpuUsage; int m_priority; Threads m_threads; diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index 3b95a90fc2..a932b23505 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -161,6 +161,7 @@ static struct option const config_options[] = { { "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey }, { "hw-aes", 0, nullptr, xmrig::IConfig::HardwareAESKey }, { "asm", 1, nullptr, xmrig::IConfig::AssemblyKey }, + { "autosave", 0, nullptr, xmrig::IConfig::AutoSaveKey }, { nullptr, 0, nullptr, 0 } }; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 5deb14f766..a5109e9b03 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -200,6 +200,10 @@ void Workers::start(xmrig::Controller *controller) m_workers.push_back(handle); handle->start(Workers::onReady); } + + if (controller->config()->isShouldSave()) { + controller->config()->save(); + } } From bf6113d93316d02cb66e0c65869f2167f1822388 Mon Sep 17 00:00:00 2001 From: xmrig Date: Fri, 28 Sep 2018 12:36:14 +0300 Subject: [PATCH 092/102] Update README.md --- README.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6054b9f8bf..48f1352286 100644 --- a/README.md +++ b/README.md @@ -87,11 +87,22 @@ Use [config.xmrig.com](https://config.xmrig.com/xmrig) to generate, edit or shar Also you can use configuration via config file, default **config.json**. You can load multiple config files and combine it with command line options. ## Algorithm variations -Since version 0.8.0. -* `--av=1` For CPUs with hardware AES. -* `--av=2` Lower power mode (double hash) of `1`. -* `--av=3` Software AES implementation. -* `--av=4` Lower power mode (double hash) of `3`. + +- `av` option used for automatic and simple threads mode (when you specify only threads count). +- For [advanced threads mode](https://github.com/xmrig/xmrig/issues/563) each thread configured individually and `av` option not used. + +| av | Hashes per round | Hardware AES | +|----|------------------|--------------| +| 1 | 1 (Single) | yes | +| 2 | 2 (Double) | yes | +| 3 | 1 (Single) | no | +| 4 | 2 (Double) | no | +| 5 | 3 (Triple) | yes | +| 6 | 4 (Quard) | yes | +| 7 | 5 (Penta) | yes | +| 8 | 3 (Triple) | no | +| 9 | 4 (Quard) | no | +| 10 | 5 (Penta) | no | ## Common Issues ### HUGE PAGES unavailable From 6b74b2d8e5be67e12c1c904a57c225e590076486 Mon Sep 17 00:00:00 2001 From: xmrig Date: Fri, 28 Sep 2018 12:37:21 +0300 Subject: [PATCH 093/102] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 48f1352286..6e39b5f7c1 100644 --- a/README.md +++ b/README.md @@ -111,8 +111,7 @@ Also you can use configuration via config file, default **config.json**. You can ## Other information * No HTTP support, only stratum protocol support. -* No TLS support. -* Default donation 5% (5 minutes in 100 minutes) can be reduced to 1% via command line option `--donate-level`. +* Default donation 5% (5 minutes in 100 minutes) can be reduced to 1% via option `donate-level`. ### CPU mining performance From 03f16a4943e11686bbe5e5b206caadaf8e56d5c9 Mon Sep 17 00:00:00 2001 From: Roboto12 <43680809+Roboto12@users.noreply.github.com> Date: Fri, 28 Sep 2018 19:18:37 +0300 Subject: [PATCH 094/102] Update Asm.cpp parse(value.IsBool()) should be changed to parse(value.GetBool()), otherwise if the 'asm' parameter in config has a boolean value, it will be parse as 'true' even if it's actually 'false'. --- src/crypto/Asm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/Asm.cpp b/src/crypto/Asm.cpp index 79dd1cc9cd..48c1beb8e8 100644 --- a/src/crypto/Asm.cpp +++ b/src/crypto/Asm.cpp @@ -67,7 +67,7 @@ xmrig::Assembly xmrig::Asm::parse(const char *assembly, Assembly defaultValue) xmrig::Assembly xmrig::Asm::parse(const rapidjson::Value &value, Assembly defaultValue) { if (value.IsBool()) { - return parse(value.IsBool()); + return parse(value.GetBool()); } if (value.IsString()) { From a9c75a950c13ef9127fb52f058460c0fc6cd4d0f Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 29 Sep 2018 18:05:38 +0300 Subject: [PATCH 095/102] Fix default value for "restricted" option. --- src/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.json b/src/config.json index d4fb42f376..2670d3a3b8 100644 --- a/src/config.json +++ b/src/config.json @@ -6,7 +6,7 @@ "id": null, "worker-id": null, "ipv6": false, - "restricted": false + "restricted": true }, "asm": true, "autosave": true, From 65f9f8fdf10068322c89a7e2366cc5dbf2b0c8ce Mon Sep 17 00:00:00 2001 From: xmrig Date: Sun, 30 Sep 2018 16:20:20 +0300 Subject: [PATCH 096/102] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd3f23fb01..c584926935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Added global and per thread option `"asm"` and and command line equivalent. - **[#758](https://github.com/xmrig/xmrig/issues/758) Added SSL/TLS support for secure connections to pools.** - Added per pool options `"tls"` and `"tls-fingerprint"` and command line equivalents. +- [#767](https://github.com/xmrig/xmrig/issues/767) Added config autosave feature, same with GPU miners. - [#245](https://github.com/xmrig/xmrig-proxy/issues/245) Fixed API ID collision when run multiple miners on same machine. - [#757](https://github.com/xmrig/xmrig/issues/757) Fixed send buffer overflow. From 6ef7e1642d6afc9567e50671186fb97f46960ebf Mon Sep 17 00:00:00 2001 From: xmrig Date: Sun, 30 Sep 2018 17:44:10 +0300 Subject: [PATCH 097/102] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e39b5f7c1..77b8f39403 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # XMRig -:warning: **If you mine Monero, Aeon, Sumokoin, Turtlecoin, Stellite, GRAFT, Haven Protocol, IPBC, [PLEASE READ](https://github.com/xmrig/xmrig/issues/482)!** :warning: +:warning: **[Monero will change PoW algorithm on October 18](https://github.com/xmrig/xmrig/issues/753), all miners and proxy should be updated to v2.8+** :warning: [![Github All Releases](https://img.shields.io/github/downloads/xmrig/xmrig/total.svg)](https://github.com/xmrig/xmrig/releases) [![GitHub release](https://img.shields.io/github/release/xmrig/xmrig/all.svg)](https://github.com/xmrig/xmrig/releases) From c23dddb8cac61249e98ac6d2fe35f661303b1ebd Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 30 Sep 2018 17:57:25 +0300 Subject: [PATCH 098/102] Update default config.json. --- src/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.json b/src/config.json index 2670d3a3b8..ae85b1f7b6 100644 --- a/src/config.json +++ b/src/config.json @@ -28,7 +28,7 @@ "rig-id": null, "nicehash": false, "keepalive": false, - "variant": 1, + "variant": -1, "tls": false, "tls-fingerprint": null } From f1ba3e49a2d906aa3b0bb6da4135198ca1f43245 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 30 Sep 2018 20:06:46 +0300 Subject: [PATCH 099/102] v2.8.0-rc --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index 2a1720eac1..6e5bf15317 100644 --- a/src/version.h +++ b/src/version.h @@ -27,7 +27,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "2.8.0-dev" +#define APP_VERSION "2.8.0-rc" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com" From 3e3d46f6a357653aa36f0c17ee317ada1dc1dcb9 Mon Sep 17 00:00:00 2001 From: xmrig Date: Mon, 1 Oct 2018 13:36:03 +0300 Subject: [PATCH 100/102] Update README.md --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 77b8f39403..81b1baeabf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # XMRig -:warning: **[Monero will change PoW algorithm on October 18](https://github.com/xmrig/xmrig/issues/753), all miners and proxy should be updated to v2.8+** :warning: +:warning: **[Monero will change PoW algorithm on October 18](https://github.com/xmrig/xmrig/issues/753), all miners and proxy should be updated to [v2.8+](https://github.com/xmrig/xmrig/releases/tag/v2.8.0-rc)** :warning: [![Github All Releases](https://img.shields.io/github/downloads/xmrig/xmrig/total.svg)](https://github.com/xmrig/xmrig/releases) [![GitHub release](https://img.shields.io/github/release/xmrig/xmrig/all.svg)](https://github.com/xmrig/xmrig/releases) @@ -134,12 +134,17 @@ Please note performance is highly dependent on system load. The numbers above ar ## Release checksums ### SHA-256 ``` -34d390a499d2098bce92e6b85b4858ee6255a7e2d4e03197ba4f6a759efe349c xmrig-2.6.4-xenial-amd64.tar.gz/xmrig-2.6.4/xmrig -cb6792c092c14f0f25d5774049a0adec403877a4564956220dcd9ba0fc488c82 xmrig-2.6.4-gcc-win32.zip/xmrig.exe -cb3c5619a8391f989c6a69135d890c3126eda9841b9dc591d44f02078a6fd49b xmrig-2.6.4-gcc-win64.zip/xmrig.exe -ea2e92bb10d0482880f8d389b7915948e11f672ca8559b0901d8a8fa8e9d733e xmrig-2.6.4-msvc-win64.zip/xmrig.exe +ea6a71732937e06d5434b863bedd2d627c500e8ce30b30a02054015bb3aae3fc xmrig-2.8.0-xenial-amd64.tar.gz/xmrig-2.8.0/xmrig +a067de09a2d49c39317d6a98e420fcd80ef040c8cecb6b21317cbe4eabbdb995 xmrig-2.8.0-xenial-amd64.tar.gz/xmrig-2.8.0/xmrig-notls +89b7b4616faec76c40dab714046ea08ebcd6c558299d17d44639e6bc62c54186 xmrig-2.8.0-gcc-win32.zip/xmrig.exe +0fae870bef4223905b24bb00283b3bba7ece547a09a540033beb9a2a33335124 xmrig-2.8.0-gcc-win32.zip/xmrig-notls.exe +953df29ef354d541b89a70a36ddf16d8a9d5f2c37419d3aacd1352ff6ff539e8 xmrig-2.8.0-gcc-win64.zip/xmrig.exe +84d73422a43b46879d88f87a492e99c81d5d632eb3be79793fc0b895196f131d xmrig-2.8.0-gcc-win64.zip/xmrig-notls.exe +8e1302fe632249a713d7af0b7f3f50ad6e707d71d00fcd1f3be56abc024f98ac xmrig-2.8.0-msvc-win64.zip/xmrig.exe +0042b5e7b14a4f8aca748a4c7656a0ec6705bc593c26f9987a25b10fa471f004 xmrig-2.8.0-msvc-win64.zip/xmrig-notls.exe ``` ## Contacts * support@xmrig.com * [reddit](https://www.reddit.com/user/XMRig/) +* [twitter](https://twitter.com/xmrig_dev) From f3d77bbef27abdc65722b7c7d02ca6a72cb1e16c Mon Sep 17 00:00:00 2001 From: VIP21 <31809608+VIP21@users.noreply.github.com> Date: Tue, 2 Oct 2018 09:00:05 -0700 Subject: [PATCH 101/102] Add files via upload --- simplemultialgo-master.zip | Bin 0 -> 3805 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 simplemultialgo-master.zip diff --git a/simplemultialgo-master.zip b/simplemultialgo-master.zip new file mode 100644 index 0000000000000000000000000000000000000000..0fcbea30cebc5f6a933a2047f8cffc2ca7e309a0 GIT binary patch literal 3805 zcma)ox_I*gUP!h5YGxm@P89Rw+41=+beM@#8*=0?(WXl>^vnOkI4cW_< zC1uG@~h-&;c&?+gjx`v7t(-1z(BpVv76F~G^v z#vY5YaltxUqOs<7d^Tt&XN;r3Ep2=N5LZc~qw!BP(cjVA4I7&|$ICvNfU&MaBcKztLzI3uK)@h4xxdi9%g4{v`CIZKH1+yxk%ZG z?{3sSAc+hF(JSlFM7<+QNwXn9lFKC{6-iSFZdcEKo>Y`B%>UL&=dPVcQWL|?+el|C zeJ%x^W$dZpk_r8csdIYPtFGd}N*^+8BGj0ZaL`Gqj#cdsN^7ZGeE_}J@OE=St$WnY z=fGh5OlexnRYuPF1aGP%#D|sx3B)(N-&1~-^MpnII9+KF0C3^YDO;M`+Bsr=rt78I zWz`I!s{6!4H+J)h)jm+_1F>IJoYleX);bZv-#pk;wXBa;(gq+ z2@YSO3P92xEN?Fj_Zd^OF(X%2*Q^YSKBA4!>)wkAo85t_1N;3%QfgBntSuo3w zwvr81_7p4}p~jY_VuCw|G&V0}_-)xQ(s7rC?u=74@T$o>{}tX>H(cdxkmxu)ZhRCX zm*2z-m9q-O`F$BMeJx}dG!jgt@K*KAv=m9F-?Xk=Dg1giyzB0?!63u>+CD5*$omqt zqbkBQj|d}C6r&AKkGK*z5^#yuK_#s}3%`3vz=TjYdE=8gZ`3jb#asc&J%aT_TGX-2 zN@2B(J8IVga_oNJj49j5XwTz~5Iyt9%}_yHmsh(f&u?S;b2ALIlpl;is2aZNhKnsL zQF|%YZ_cZBw^;?VxAV@?gRdh4>06 C?|8YR7fp@Qq#6?4$Qh`ixvi>vp4QVAzc| zEg$dHiIN9v{nAateTEIPAx!Qx`~U*RtNhfl}F*4mpgW8cxz?aB=B9V*m35_sJ-{`t)Qb zdL&H`RR|+?Xz-Vi9zOe`A*7$}6BXjhp-(sNmg;>;uwi$xIGhT4Wyr1nsl8V-V=YxM zAk%EsXI#8%+2IE3o24F*RO8<4t<}ta(Pn^$hYbDFjC=CS8I?<{7p3d03B8cuq?pD^B`T%}E z!=)_Lm14&iO5gEhJN-h@l9!cJ{p|?LYpPl|L&)kEbctLo)16lNOu})p>ElXe^x3enR?4bp6&3)>Tbuw?!(w+xX_@aeH+u{*;b0N&u0^- z{O%$8E#bl3<@Zf(3e%~>?XEjIw!M}x1?}AkVDrL5+*D&pf4IbiyjDZ~e2ttZG~@I2 zO7cNQZTn~j&c?6Cgl&KkM#4OURWc@uZ0fB_~tsFt(g z7Xo70?^voxs@eFH5*TLZUJ*vT`<5c;B;!x61P)_li7tWL0CT1kqEyScwbd$d;C2$> zK*cc2=l<{7_jXS$(Ls2%fT}{hL z7$K!FvGL6GX~Ca0@q83tk<2fW?IybV4fK2Y!TpDw#m5r1emwtBe#~9;cVXl=`FVq= zMs|HyFZtmfT{2*HJT~-67*0TwxCAk7lr(rXOMid$X|#UJ@gO|})BK{jXoAm-Us&-qaoStJqql*jL7+dBU5S<3)r+IH~(fC1t^3b(BV-w#7@>;w2Mex@F;qiQ#< zKqYnarEwumc5Y0c(nJOqa?p3W%9Z8`7m2ZaQC5T^e@Sh525iM{HQ7Kbi%U|Lvb1B= zedEjgvSL`PzjtxAxCUlZU%W)C+K~`v4R(+0Q(&5_4CFAtr7F$YHQ6HK7#KcU-Hf>c z-AjB&YV%G|kzaDrv;10&2U_kzD$Mocq|YLA44BguA;ZM(IbW(^RYjLit7c}JsyWxD zg?&-e3)M$-ZlM^J0^?)%^y(@UQ$-GgBk)m`F+ybvkF@dg6TyNSyK7CRfWFTVIG{3|Yjsb$YA786qsNiS z*M5v%?pRFI-0TVpx|5XAaInm^Z|aiRh!@vwkwnaCgf(9Fee9>kIRe!NNa?kJ)ScxM zQj0|iy$t<`nb{m>yJt6gGlR=!5|22vM)24=TWP8?0nEFOD)E=OZMC~?p^SE^1)m*D zMpkz=9=>+Z4-3p4RM+UzG1tXIE#xCVed#6zQb(#Mq>z{dK|aK^&sBD61p}vfa&0KL z{e5-7qInF(-Hk0eaG+k>P(`o9vt4f8Y*S#iL~LPwKoR-gCC;95#CB+!9=3X{8C>KUmmf$d)BE+qhuxy_7@JfwwlTC7pex**(Vhh|FZ6W7WMXZ z9^1u<7gEFC69}Co&Z{(RR4x}FJbIzvhadx_(Ov6M0Z0t74eVYFrftB)z5F_^KwZcM z^%5m%!p=9s>Lh+d+GEy8hJ7Q2t=i>tEgHQFaG)xd2QEqgz~}o);{pYBR@c0%6jNbh$UG{M-oarZ**4*6Ou- zU7^A0EQAb)BhS>;Z#R!v9-$2ya55C*D;~?xtV!v~g$S5~$K4^H!O3pH2~HrRy%!z5 zmp}3Bo^7$0%Gdhmq;2L$ZkQ}00`K+(cNpBO%YM1mu8=FKQh>;zFj>^ESUff_+8PB% zn!k`8K!%nU9gw6xciUhuELdD#+>_Bz1|FNO)0>AMeFW8y<^O0U{!9Dc&BS-iu_hi5 z>En4yV{%Gs@#{~2uur=7@6;b`!Q=PdTB=@8N{l#rKuGA^q|6xZ@a!;CqUtE9u zQ@Q`P2q&>8#qJjtNO&st-_myyds0n)VRuf)o}w)p%J>A|;|Y%+)8iUSk^ul*05b^M nL>Ph=go=rYL0}@rqA)QtGz0<@G(($+i=c&IP&5=`A_n~r%4R)F literal 0 HcmV?d00001 From 0607df652d1cf8fe0d28efc4398e028b60392e37 Mon Sep 17 00:00:00 2001 From: VIP21 Date: Mon, 21 Jan 2019 07:20:14 -1200 Subject: [PATCH 102/102] Revert "Add files via upload" This reverts commit dc0347e4ca084e7639486df8013694bf9f8e47de. --- simplemultialgo-master.zip | Bin 3805 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 simplemultialgo-master.zip diff --git a/simplemultialgo-master.zip b/simplemultialgo-master.zip deleted file mode 100644 index 0fcbea30cebc5f6a933a2047f8cffc2ca7e309a0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3805 zcma)ox_I*gUP!h5YGxm@P89Rw+41=+beM@#8*=0?(WXl>^vnOkI4cW_< zC1uG@~h-&;c&?+gjx`v7t(-1z(BpVv76F~G^v z#vY5YaltxUqOs<7d^Tt&XN;r3Ep2=N5LZc~qw!BP(cjVA4I7&|$ICvNfU&MaBcKztLzI3uK)@h4xxdi9%g4{v`CIZKH1+yxk%ZG z?{3sSAc+hF(JSlFM7<+QNwXn9lFKC{6-iSFZdcEKo>Y`B%>UL&=dPVcQWL|?+el|C zeJ%x^W$dZpk_r8csdIYPtFGd}N*^+8BGj0ZaL`Gqj#cdsN^7ZGeE_}J@OE=St$WnY z=fGh5OlexnRYuPF1aGP%#D|sx3B)(N-&1~-^MpnII9+KF0C3^YDO;M`+Bsr=rt78I zWz`I!s{6!4H+J)h)jm+_1F>IJoYleX);bZv-#pk;wXBa;(gq+ z2@YSO3P92xEN?Fj_Zd^OF(X%2*Q^YSKBA4!>)wkAo85t_1N;3%QfgBntSuo3w zwvr81_7p4}p~jY_VuCw|G&V0}_-)xQ(s7rC?u=74@T$o>{}tX>H(cdxkmxu)ZhRCX zm*2z-m9q-O`F$BMeJx}dG!jgt@K*KAv=m9F-?Xk=Dg1giyzB0?!63u>+CD5*$omqt zqbkBQj|d}C6r&AKkGK*z5^#yuK_#s}3%`3vz=TjYdE=8gZ`3jb#asc&J%aT_TGX-2 zN@2B(J8IVga_oNJj49j5XwTz~5Iyt9%}_yHmsh(f&u?S;b2ALIlpl;is2aZNhKnsL zQF|%YZ_cZBw^;?VxAV@?gRdh4>06 C?|8YR7fp@Qq#6?4$Qh`ixvi>vp4QVAzc| zEg$dHiIN9v{nAateTEIPAx!Qx`~U*RtNhfl}F*4mpgW8cxz?aB=B9V*m35_sJ-{`t)Qb zdL&H`RR|+?Xz-Vi9zOe`A*7$}6BXjhp-(sNmg;>;uwi$xIGhT4Wyr1nsl8V-V=YxM zAk%EsXI#8%+2IE3o24F*RO8<4t<}ta(Pn^$hYbDFjC=CS8I?<{7p3d03B8cuq?pD^B`T%}E z!=)_Lm14&iO5gEhJN-h@l9!cJ{p|?LYpPl|L&)kEbctLo)16lNOu})p>ElXe^x3enR?4bp6&3)>Tbuw?!(w+xX_@aeH+u{*;b0N&u0^- z{O%$8E#bl3<@Zf(3e%~>?XEjIw!M}x1?}AkVDrL5+*D&pf4IbiyjDZ~e2ttZG~@I2 zO7cNQZTn~j&c?6Cgl&KkM#4OURWc@uZ0fB_~tsFt(g z7Xo70?^voxs@eFH5*TLZUJ*vT`<5c;B;!x61P)_li7tWL0CT1kqEyScwbd$d;C2$> zK*cc2=l<{7_jXS$(Ls2%fT}{hL z7$K!FvGL6GX~Ca0@q83tk<2fW?IybV4fK2Y!TpDw#m5r1emwtBe#~9;cVXl=`FVq= zMs|HyFZtmfT{2*HJT~-67*0TwxCAk7lr(rXOMid$X|#UJ@gO|})BK{jXoAm-Us&-qaoStJqql*jL7+dBU5S<3)r+IH~(fC1t^3b(BV-w#7@>;w2Mex@F;qiQ#< zKqYnarEwumc5Y0c(nJOqa?p3W%9Z8`7m2ZaQC5T^e@Sh525iM{HQ7Kbi%U|Lvb1B= zedEjgvSL`PzjtxAxCUlZU%W)C+K~`v4R(+0Q(&5_4CFAtr7F$YHQ6HK7#KcU-Hf>c z-AjB&YV%G|kzaDrv;10&2U_kzD$Mocq|YLA44BguA;ZM(IbW(^RYjLit7c}JsyWxD zg?&-e3)M$-ZlM^J0^?)%^y(@UQ$-GgBk)m`F+ybvkF@dg6TyNSyK7CRfWFTVIG{3|Yjsb$YA786qsNiS z*M5v%?pRFI-0TVpx|5XAaInm^Z|aiRh!@vwkwnaCgf(9Fee9>kIRe!NNa?kJ)ScxM zQj0|iy$t<`nb{m>yJt6gGlR=!5|22vM)24=TWP8?0nEFOD)E=OZMC~?p^SE^1)m*D zMpkz=9=>+Z4-3p4RM+UzG1tXIE#xCVed#6zQb(#Mq>z{dK|aK^&sBD61p}vfa&0KL z{e5-7qInF(-Hk0eaG+k>P(`o9vt4f8Y*S#iL~LPwKoR-gCC;95#CB+!9=3X{8C>KUmmf$d)BE+qhuxy_7@JfwwlTC7pex**(Vhh|FZ6W7WMXZ z9^1u<7gEFC69}Co&Z{(RR4x}FJbIzvhadx_(Ov6M0Z0t74eVYFrftB)z5F_^KwZcM z^%5m%!p=9s>Lh+d+GEy8hJ7Q2t=i>tEgHQFaG)xd2QEqgz~}o);{pYBR@c0%6jNbh$UG{M-oarZ**4*6Ou- zU7^A0EQAb)BhS>;Z#R!v9-$2ya55C*D;~?xtV!v~g$S5~$K4^H!O3pH2~HrRy%!z5 zmp}3Bo^7$0%Gdhmq;2L$ZkQ}00`K+(cNpBO%YM1mu8=FKQh>;zFj>^ESUff_+8PB% zn!k`8K!%nU9gw6xciUhuELdD#+>_Bz1|FNO)0>AMeFW8y<^O0U{!9Dc&BS-iu_hi5 z>En4yV{%Gs@#{~2uur=7@6;b`!Q=PdTB=@8N{l#rKuGA^q|6xZ@a!;CqUtE9u zQ@Q`P2q&>8#qJjtNO&st-_myyds0n)VRuf)o}w)p%J>A|;|Y%+)8iUSk^ul*05b^M nL>Ph=go=rYL0}@rqA)QtGz0<@G(($+i=c&IP&5=`A_n~r%4R)F