From 18a2371883e44bef2e0d5a1ae93bcdc5314ac20b Mon Sep 17 00:00:00 2001 From: rcxpony Date: Mon, 10 Mar 2025 21:23:06 +0500 Subject: [PATCH] fixes --- CMakeLists.txt | 2 +- sources/main.cpp | 34 ++++++++++++++++------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6544d7c..cefac1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,6 @@ file(GLOB ${PROJECT_NAME}SOURCES *.cpp) file(GLOB ${PROJECT_NAME}HEADERS *.h) add_executable(${PROJECT_NAME} sources/main.cpp) set(CXX_ADDITIONAL_FLAGS "-mavx2 -fomit-frame-pointer -ftree-vectorize -ftree-slp-vectorize -fdelete-null-pointer-checks -fno-exceptions -fno-rtti") -set(CMAKE_CXX_FLAGS_RELEASE "-march=native -O3 -ffast-math -pipe -Wall -Wextra -Wpedantic -Wconversion -Wuninitialized -Wsign-conversion -flto=full") +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -mtune=native -ffast-math -pipe -Wall -Wextra -Wpedantic -Wconversion -Wuninitialized -Wsign-conversion -flto=full") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CXX_ADDITIONAL_FLAGS}") target_link_libraries(${PROJECT_NAME} pthread sodium) \ No newline at end of file diff --git a/sources/main.cpp b/sources/main.cpp index 4588967..92980e7 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -12,7 +12,7 @@ #include struct option { unsigned proc = 0; - std::atomic high = 0x14; + std::atomic high = 0x14; //std::string outputfile; }; static option conf; @@ -32,6 +32,11 @@ int parameters(std::string arg) { conf.high = tmp_high; return 0; } + /* + if (arg.find("--invert") != npos || arg.find("-i") != npos) { + return 0; + } + */ } if (arg == "--threads" || arg == "-t") return 777; else if (arg == "--altitude" || arg == "-a") return 777; @@ -42,7 +47,7 @@ void displayConfig() { if (conf.proc == 0 || conf.proc > static_cast(processor_count)) { conf.proc = static_cast(processor_count); } - std::cout << " Threads: " << conf.proc << ", " << "high addresses (2" << std::setw(2) << std::setfill('0') << std::hex << conf.high << "+)" << std::dec << std::endl; + printf("Threads: %u, high addresses (2%02x+)\n", conf.proc, conf.high.load()); } using Address = unsigned char[16]; using Key = unsigned char[32]; @@ -51,7 +56,7 @@ inline std::string getAddress(const Address& rawAddr) noexcept { inet_ntop(AF_INET6, rawAddr, ipStrBuf, 46); return std::string(ipStrBuf); } -inline std::string keyToString(const unsigned char* key) noexcept { +inline std::string KeyToString(const unsigned char* key) noexcept { char result[65]; const char* hexDigits = "0123456789abcdef"; for (size_t i = 0; i < 32; ++i) { @@ -78,22 +83,16 @@ void getRawAddress(int lErase, Key& InvertedPublicKey, Address& rawAddr) noexcep rawAddr[1] = static_cast(lErase - 1); memcpy(&rawAddr[2], &InvertedPublicKey[start], 14); } -inline void bitwiseInverse(const unsigned char* key, Key& inverted) noexcept { - __m256i chunk = _mm256_loadu_si256(reinterpret_cast(key)); - chunk = _mm256_xor_si256(chunk, _mm256_set1_epi8(0xFF)); - _mm256_storeu_si256(reinterpret_cast<__m256i*>(inverted), chunk); +inline void invertKey(const unsigned char* __restrict key, Key& inverted) noexcept { + _mm256_storeu_si256(reinterpret_cast<__m256i*>(inverted), _mm256_xor_si256(_mm256_loadu_si256(reinterpret_cast(key)), _mm256_set1_epi8(0xFF))); } [[nodiscard]] inline unsigned char zeroCounter(unsigned int x) noexcept { return x == 0 ? 32 : static_cast(__builtin_clz(x)); } -[[nodiscard]] inline unsigned char getZeros(const Key& value) noexcept { +[[nodiscard]] inline unsigned char getZeros(const Key& v) noexcept { unsigned char leadZeros = 0; for (unsigned char i = 0; i < 32; i += 4) { - unsigned int word = - (static_cast(value[i]) << 24) | - (static_cast(value[i + 1]) << 16) | - (static_cast(value[i + 2]) << 8) | - (static_cast(value[i + 3])); + unsigned word = (static_cast(v[i]) << 24) | (static_cast(v[i + 1]) << 16) | (static_cast(v[i + 2]) << 8) | (static_cast(v[i + 3])); if (word == 0) { leadZeros += 32; } else { @@ -109,7 +108,7 @@ inline void bitwiseInverse(const unsigned char* key, Key& inverted) noexcept { state ^= state << 4; return static_cast(state * 2685821657736338717); } -inline void rmbytes(unsigned char* buf, unsigned char size, unsigned long& state) noexcept { +inline void rmbytes(unsigned char* __restrict buf, unsigned char size, unsigned long& state) noexcept { for (unsigned char x = 0; x < size / 32; x++) { _mm256_storeu_si256((__m256i*) & buf[x * 32], _mm256_set_epi64x(xorshift64(state), xorshift64(state), xorshift64(state), xorshift64(state))); } @@ -117,7 +116,7 @@ inline void rmbytes(unsigned char* buf, unsigned char size, unsigned long& state buf[(size / 32) * 32 + x] = static_cast(xorshift64(state) & 0xFF); } } -inline void sign_keypair(unsigned char* pk, unsigned char* sk, const unsigned char* seed) noexcept { +inline void sign_keypair(unsigned char* __restrict pk, unsigned char* __restrict sk, const unsigned char* __restrict seed) noexcept { alignas(32) unsigned char h[64]; crypto_hash_sha512(h, seed, 32); h[31] = (h[31] & 0xF8) | (0x40 | (h[31] & 0x7F)); @@ -141,9 +140,9 @@ void miner_thread() noexcept { ones = getZeros(keys.PublicKey); if (ones > conf.high.load()) { conf.high.store(ones); - bitwiseInverse(keys.PublicKey, inv); + invertKey(keys.PublicKey, inv); getRawAddress(ones, inv, rawAddr); - printf("\nIPv6:\t%s\nPK:\t%s\nSK:\t%s\n", getAddress(rawAddr).c_str(), keyToString(keys.PublicKey).c_str(), keyToString(keys.PrivateKey).c_str()); + printf("\nIPv6:\t%s\nPK:\t%s\nSK:\t%s\n", getAddress(rawAddr).c_str(), KeyToString(keys.PublicKey).c_str(), KeyToString(keys.PrivateKey).c_str()); } } } @@ -177,7 +176,6 @@ int main(int argc, char* argv[]) noexcept { } } } - if (sodium_init() < 0) return -1; displayConfig(); startThreads(); return 0;