From 843319450030a08b082b51b0629cf9bb9ad99b59 Mon Sep 17 00:00:00 2001 From: rcxpony Date: Tue, 4 Mar 2025 03:01:12 +0500 Subject: [PATCH] fixes --- CMakeLists.txt | 5 +++-- sources/main.cpp | 46 +++++++++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b91d4c6..e1475e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,8 @@ find_package(OpenSSL REQUIRED) file(GLOB ${PROJECT_NAME}SOURCES *.cpp) file(GLOB ${PROJECT_NAME}HEADERS *.h) add_executable(${PROJECT_NAME} sources/main.cpp) -set(CMAKE_CXX_FLAGS_RELEASE "-march=native -O3 -ffast-math -mavx2 -m64 -ftree-vectorize -ftree-slp-vectorize -fdelete-null-pointer-checks -fno-exceptions -fno-rtti -finline-functions -pthread -fomit-frame-pointer -pipe -Wall -Wextra -flto=full") +set(CXX_ADDITIONAL_FLAGS "-mavx2 -fomit-frame-pointer -ftree-vectorize -ftree-slp-vectorize -fdelete-null-pointer-checks -fno-exceptions -fno-rtti -pthread -fomit-frame-pointer") +set(CMAKE_CXX_FLAGS_RELEASE "-march=native -O3 -ffast-math -pipe -Wall -Wextra -Wpedantic -Wconversion -Wuninitialized -Wsign-conversion -flto=full") target_link_libraries(${PROJECT_NAME} pthread) target_link_libraries(${PROJECT_NAME} sodium) -target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto) \ No newline at end of file +#target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto) \ No newline at end of file diff --git a/sources/main.cpp b/sources/main.cpp index 9618747..6e3d676 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -22,8 +22,7 @@ static option conf; int parameters(option& conf, std::string arg) { if (arg.find(" ") != std::string::npos) { const unsigned long npos = std::string::npos; - int position = arg.find(" "); - std::istringstream ss(arg.substr(position + 1)); + std::istringstream ss(arg.substr(arg.find(" ") + 1)); if (arg.find("--threads") != npos || arg.find("-t") != npos) { ss >> conf.proc; if (ss.fail()) return 1; @@ -42,9 +41,9 @@ int parameters(option& conf, std::string arg) { return 0; } void displayConfig() { - unsigned short processor_count = std::thread::hardware_concurrency(); - if (conf.proc == 0 || conf.proc > static_cast(processor_count)) { - conf.proc = static_cast(processor_count); + unsigned processor_count = std::thread::hardware_concurrency(); + 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; } @@ -69,36 +68,36 @@ struct KeysBox { Key PublicKey; Key PrivateKey; }; -inline void bitwiseInverse(const unsigned char* key, Key& inverted) noexcept { +/* +[[gnu::always_inline]] 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 unsigned char getOnes(const Key& value) noexcept { - int leadOnes = 0; - for (unsigned char i = 0; i < 32; i++) { - if (value[0] != 0xFF && value[1] != 0xFF) return leadOnes; - if (value[i] == 0xFF) { - leadOnes += 8; +*/ +[[nodiscard]] inline unsigned char getZeros(const Key& value) noexcept { + unsigned char leadZeros = 0; +#pragma unroll + for (unsigned char i = 0; i < 6; i++) { + if (value[i] == 0x00) { + leadZeros += 8; } else { - for (unsigned char j = 7; j < 8; j--) { - if (!(value[i] & (1 << j))) { - return leadOnes; - } - leadOnes++; + unsigned char byte = value[i]; + while (!(byte & 0x80)) { + leadZeros++; + byte <<= 1; } + return leadZeros; } } - return leadOnes; + return leadZeros; } void miner_thread() noexcept { - Key inv; KeysBox keys; - unsigned char ones; + unsigned char ones = 0; while (true) { crypto_sign_ed25519_keypair(keys.PublicKey, keys.PrivateKey); - bitwiseInverse(keys.PublicKey, inv); - ones = getOnes(inv); + ones = getZeros(keys.PublicKey); if (ones > conf.high) { printf("\nAddr:\t2%x/%d\nPK:\t%s\nSK:\t%s\n", conf.high = ones, ones, keyToString(keys.PublicKey).c_str(), keyToString(keys.PrivateKey).c_str()); } @@ -135,6 +134,7 @@ int main(int argc, char* argv[]) { } displayConfig(); startThreads(); + return 0; } /* void getRawAddress(int lErase, Key& InvertedPublicKey, Address& rawAddr) { @@ -171,4 +171,4 @@ void logKeys(const Address& raw, const KeysBox& keys) { output.close(); } } -*/ \ No newline at end of file +*/