avx2 opt
This commit is contained in:
parent
193575da8a
commit
79457de8b7
@ -4,7 +4,7 @@ find_package(OpenSSL REQUIRED)
|
|||||||
file(GLOB ${PROJECT_NAME}SOURCES *.cpp)
|
file(GLOB ${PROJECT_NAME}SOURCES *.cpp)
|
||||||
file(GLOB ${PROJECT_NAME}HEADERS *.h)
|
file(GLOB ${PROJECT_NAME}HEADERS *.h)
|
||||||
add_executable(${PROJECT_NAME} sources/main.cpp)
|
add_executable(${PROJECT_NAME} sources/main.cpp)
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "-march=native -O3 -ffast-math -ftree-vectorize -fdelete-null-pointer-checks -fno-exceptions -fno-rtti -finline-functions -pthread -fomit-frame-pointer -pipe -Wall -Wextra -flto=full")
|
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")
|
||||||
target_link_libraries(${PROJECT_NAME} pthread)
|
target_link_libraries(${PROJECT_NAME} pthread)
|
||||||
target_link_libraries(${PROJECT_NAME} sodium)
|
target_link_libraries(${PROJECT_NAME} sodium)
|
||||||
target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto)
|
target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto)
|
@ -12,14 +12,6 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
//using Key = std::array<unsigned char, 32>;
|
|
||||||
//using Address = std::array<unsigned char, 16>;
|
|
||||||
using Address = unsigned char[16];
|
|
||||||
using Key = unsigned char[32];
|
|
||||||
struct KeysBox {
|
|
||||||
Key PublicKey;
|
|
||||||
Key PrivateKey;
|
|
||||||
};
|
|
||||||
struct option {
|
struct option {
|
||||||
unsigned int proc = 0;
|
unsigned int proc = 0;
|
||||||
bool log = true;
|
bool log = true;
|
||||||
@ -49,7 +41,6 @@ int parameters(option& conf, std::string arg) {
|
|||||||
else if (arg == "--altitude" || arg == "-a") return 777;
|
else if (arg == "--altitude" || arg == "-a") return 777;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayConfig() {
|
void displayConfig() {
|
||||||
unsigned short processor_count = std::thread::hardware_concurrency();
|
unsigned short processor_count = std::thread::hardware_concurrency();
|
||||||
if (conf.proc == 0 || conf.proc > static_cast<unsigned int>(processor_count)) {
|
if (conf.proc == 0 || conf.proc > static_cast<unsigned int>(processor_count)) {
|
||||||
@ -57,11 +48,12 @@ void displayConfig() {
|
|||||||
}
|
}
|
||||||
std::cout << " Threads: " << conf.proc << ", " << "high addresses (2" << std::setw(2) << std::setfill('0') << std::hex << conf.high << "+)" << std::dec << std::endl;
|
std::cout << " Threads: " << conf.proc << ", " << "high addresses (2" << std::setw(2) << std::setfill('0') << std::hex << conf.high << "+)" << std::dec << std::endl;
|
||||||
}
|
}
|
||||||
KeysBox getKeyPair() noexcept {
|
using Address = unsigned char[16];
|
||||||
KeysBox keys;
|
using Key = unsigned char[32];
|
||||||
crypto_sign_ed25519_keypair(keys.PublicKey, keys.PrivateKey);
|
struct KeysBox {
|
||||||
return keys;
|
Key PublicKey;
|
||||||
}
|
Key PrivateKey;
|
||||||
|
};
|
||||||
std::string getAddress(const Address& rawAddr) {
|
std::string getAddress(const Address& rawAddr) {
|
||||||
char ipStrBuf[46];
|
char ipStrBuf[46];
|
||||||
inet_ntop(AF_INET6, rawAddr, ipStrBuf, 46);
|
inet_ntop(AF_INET6, rawAddr, ipStrBuf, 46);
|
||||||
@ -71,48 +63,50 @@ inline std::string keyToString(const unsigned char* key) {
|
|||||||
std::string result;
|
std::string result;
|
||||||
result.resize(64);
|
result.resize(64);
|
||||||
const char* hexDigits = "0123456789abcdef";
|
const char* hexDigits = "0123456789abcdef";
|
||||||
for (int i = 0; i < 32; ++i) {
|
for (unsigned char i = 0; i < 32; i++) {
|
||||||
result[2 * i] = hexDigits[key[i] >> 4];
|
result[2 * i] = hexDigits[key[i] >> 4];
|
||||||
result[2 * i + 1] = hexDigits[key[i] & 0x0F];
|
result[2 * i + 1] = hexDigits[key[i] & 0x0F];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
inline void bitwiseInverse(const unsigned char* key, Key inverted) noexcept {
|
inline void bitwiseInverse(const unsigned char* key, Key& inverted) noexcept {
|
||||||
for (size_t i = 0; i < 32; i++) {
|
__m256i chunk = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(key));
|
||||||
inverted[i] = ~key[i];
|
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 getOnes(const Key value) noexcept {
|
|
||||||
int leadOnes = 0;
|
int leadOnes = 0;
|
||||||
for (unsigned char i = 0; i < 5; i++) {
|
for (unsigned char i = 0; i < 17; i++) {
|
||||||
|
if (value[0] != 0xFF) return leadOnes;
|
||||||
if (value[i] == 0xFF) {
|
if (value[i] == 0xFF) {
|
||||||
leadOnes += 8;
|
leadOnes += 8;
|
||||||
} else {
|
} else {
|
||||||
for (int j = 7; j >= 0; j--) {
|
for (unsigned char j = 7; j < 8; j--) {
|
||||||
if (value[i] & (1 << j)) {
|
if (!(value[i] & (1 << j))) {
|
||||||
|
return leadOnes;
|
||||||
|
}
|
||||||
leadOnes++;
|
leadOnes++;
|
||||||
} else {
|
|
||||||
return leadOnes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return leadOnes;
|
return leadOnes;
|
||||||
}
|
}
|
||||||
void miner_thread() {
|
void miner_thread() noexcept {
|
||||||
Key inv;
|
Key inv;
|
||||||
|
KeysBox keys;
|
||||||
|
unsigned char ones;
|
||||||
while (true) {
|
while (true) {
|
||||||
KeysBox keys = getKeyPair();
|
crypto_sign_ed25519_keypair(keys.PublicKey, keys.PrivateKey);
|
||||||
bitwiseInverse(keys.PublicKey, inv);
|
bitwiseInverse(keys.PublicKey, inv);
|
||||||
int ones = getOnes(inv);
|
ones = getOnes(inv);
|
||||||
if (ones > conf.high) {
|
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());
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void startThreads() {
|
void startThreads() noexcept {
|
||||||
std::vector<std::thread> threads;
|
std::vector<std::thread> threads;
|
||||||
for (unsigned int i = 0; i < conf.proc; i++) {
|
for (unsigned char i = 0; i < conf.proc; i++) {
|
||||||
threads.emplace_back(miner_thread);
|
threads.emplace_back(miner_thread);
|
||||||
}
|
}
|
||||||
for (auto& thread : threads) {
|
for (auto& thread : threads) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user