cmake fixes, atomic changes,.clang-format

This commit is contained in:
rcxpony
2025-08-07 06:17:29 +05:00
parent fa31fc69b0
commit 279f949dff
3 changed files with 331 additions and 81 deletions

271
.clang-format Normal file
View File

@@ -0,0 +1,271 @@
BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveShortCaseStatements:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCaseArrows: false
AlignCaseColons: false
AlignConsecutiveTableGenBreakingDAGArgColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveTableGenCondOperatorColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveTableGenDefinitionColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignEscapedNewlines: Right
AlignOperands: DontAlign
AlignTrailingComments:
Kind: Never
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Never
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseExpressionOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAdjacentStringLiterals: true
BreakAfterAttributes: Leave
BreakAfterJavaFieldAnnotations: false
BreakAfterReturnType: None
BreakArrays: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Attach
BreakBeforeConceptDeclarations: Always
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakFunctionDefinitionParameters: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
BreakTemplateDeclarations: MultiLine
ColumnLimit: 0
CommentPragmas: "^ IWYU pragma:"
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: ^"(llvm|llvm-c|clang|clang-c)/
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: ^(<|"(gtest|gmock|isl|json)/)
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: .*
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: (Test)?$
IncludeIsMainSourceRegex: ""
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
BinaryMinDigits: 0
Decimal: 0
DecimalMinDigits: 0
Hex: 0
HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: true
AtStartOfFile: true
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ""
MacroBlockEnd: ""
MainIncludeChar: Quote
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PPIndentWidth: -1
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakScopeResolution: 500
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveParentheses: Leave
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SkipMacroDefinitionBody: false
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDeclarationName: false
AfterFunctionDefinitionName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterPlacementOperator: true
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: true
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParens: Never
SpacesInParensOptions:
ExceptDoubleParentheses: false
InConditionalStatements: false
InCStyleCasts: false
InEmptyParentheses: false
Other: false
SpacesInSquareBrackets: false
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
TableGenBreakInsideDAGArg: DontBreak
UseTab: Never
VerilogBreakBetweenInstancePorts: true
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE

View File

@@ -27,7 +27,22 @@ else()
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_AVX2=0)
endif()
set(CXX_ADDITIONAL_FLAGS "-fomit-frame-pointer -funroll-loops -ftree-vectorize -ftree-slp-vectorize -fdelete-null-pointer-checks -fno-exceptions -fno-rtti")
set(CMAKE_CXX_FLAGS "-O3 -march=native -ffast-math -pipe -Wall -Wextra -Wpedantic -Wconversion -Wuninitialized -Wsign-conversion -flto")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_ADDITIONAL_FLAGS}")
set(CXX_ADDITIONAL_FLAGS
"-fomit-frame-pointer \
-funroll-loops \
-ftree-vectorize \
-ftree-slp-vectorize \
-fdelete-null-pointer-checks \
-fno-exceptions \
-fno-rtti \
-funsafe-math-optimizations \
-fstrict-aliasing \
-fstrict-overflow \
-fno-stack-protector \
-fno-math-errno")
set(CXXFLAGSR "-march=native -O3 -ffast-math -pipe -Wall -Wextra -Wpedantic -Wconversion -Wuninitialized -Wsign-conversion -flto")
set(CXXFLAGSD "-O0 -pipe -Wall -Wextra -Wpedantic -Wconversion -Wuninitialized -Wsign-conversion -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CXXFLAGSR} ${CXX_ADDITIONAL_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CXXFLAGSD}")
target_link_libraries(${PROJECT_NAME} pthread sodium)

View File

@@ -1,16 +1,14 @@
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <random>
#include <memory.h>
#include <thread>
#include <sodium.h>
#include "../libs/defines.h"
#include <arpa/inet.h>
#include <immintrin.h>
#include <defines.h>
#include <atomic>
#include <immintrin.h>
#include <iostream>
#include <memory.h>
#include <sodium.h>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
struct option {
unsigned proc = 0;
std::atomic<unsigned> high = 0x14;
@@ -22,21 +20,18 @@ int parameters(std::string arg) {
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;
if (ss.fail())
return 1;
return 0;
}
if (arg.find("--altitude") != npos || arg.find("-a") != npos) {
unsigned tmp_high;
ss >> std::hex >> tmp_high;
if (ss.fail()) return 1;
if (ss.fail())
return 1;
conf.high = tmp_high;
return 0;
}
/*
if (arg.find("--invert") != npos || arg.find("-i") != npos) {
return 0;
}
*/
}
if (arg == "--threads" || arg == "-t" || arg == "--altitude" || arg == "-a") {
return 777;
@@ -47,22 +42,21 @@ void displayConfig() {
unsigned processor_count = std::thread::hardware_concurrency();
if (conf.proc == 0 || conf.proc > static_cast<unsigned>(processor_count)) {
conf.proc = static_cast<unsigned>(processor_count);
}
printf("Threads: %u, high addresses (2%02x+)\n", conf.proc, conf.high.load());
}
using Address = unsigned char[16];
using Key = unsigned char[32];
inline std::string getAddress(const Address& rawAddr) noexcept {
inline std::string getAddress(const Address& rawAddr) {
char ipStrBuf[46];
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) {
char result[65];
const char* hexDigits = "0123456789abcdef";
#pragma unroll
for (unsigned char i = 0; i < 32; i++) {
for (int i = 0; i < 32; i++) {
result[2 * i] = hexDigits[key[i] >> 4];
result[2 * i + 1] = hexDigits[key[i] & 0x0F];
}
@@ -73,11 +67,12 @@ typedef struct alignas(32) {
Key PublicKey;
Key PrivateKey;
} KeysBox;
void getRawAddress(int lErase, Key& InvertedPublicKey, Address& rawAddr) noexcept {
void getRawAddress(unsigned lErase, Key& InvertedPublicKey, Address& rawAddr) {
lErase++;
const int bitsToShift = lErase % 8;
const int start = lErase / 8;
if (bitsToShift != 0) {
#pragma unroll
for (int i = start; i < start + 15; i++) {
InvertedPublicKey[i] = static_cast<unsigned char>((InvertedPublicKey[i] << bitsToShift) | (InvertedPublicKey[i + 1] >> (8 - bitsToShift)));
}
@@ -86,91 +81,60 @@ void getRawAddress(int lErase, Key& InvertedPublicKey, Address& rawAddr) noexcep
rawAddr[1] = static_cast<unsigned char>(lErase - 1);
memcpy(&rawAddr[2], &InvertedPublicKey[start], 14);
}
inline void invertKey(const uint8_t* __restrict key, Key& inverted) noexcept {
inline void invertKey(const unsigned char* __restrict key, Key& inverted) {
#if USE_AVX2
_mm256_storeu_si256(reinterpret_cast<__m256i*>(inverted), _mm256_xor_si256(_mm256_loadu_si256(reinterpret_cast<const __m256i*>(key)), _mm256_set1_epi8(0xFF)));
#else
for(int i = 0; i < 32; ++i) {
for (int i = 0; i < 32; ++i) {
inverted[i] = static_cast<unsigned char>(key[i] ^ 0xFF);
}
#endif
}
[[nodiscard]] inline unsigned char getZeros(const Key& v) noexcept {
unsigned char leadZeros = 0;
#pragma unroll 8
for (int i = 0; i < 32; i += 4) {
unsigned word = (static_cast<unsigned>(v[i]) << 24) | (static_cast<unsigned>(v[i + 1]) << 16) | (static_cast<unsigned>(v[i + 2]) << 8) | (static_cast<unsigned>(v[i + 3]));
inline unsigned getZeros(const Key& v) {
unsigned leadZeros = 0;
#pragma unroll
for (int i = 0; i < 32; i += 8) {
unsigned long long word = (static_cast<unsigned long long>(v[i]) << 56) | (static_cast<unsigned long long>(v[i + 1]) << 48) | (static_cast<unsigned long long>(v[i + 2]) << 40) | (static_cast<unsigned long long>(v[i + 3]) << 32) | (static_cast<unsigned long long>(v[i + 4]) << 24) | (static_cast<unsigned long long>(v[i + 5]) << 16) | (static_cast<unsigned long long>(v[i + 6]) << 8) | static_cast<unsigned long long>(v[i + 7]);
if (word == 0) {
leadZeros += 32;
leadZeros += 64;
} else {
leadZeros += static_cast<unsigned char>(__builtin_clz(word));
leadZeros += static_cast<unsigned>(__builtin_clzll(word));
break;
}
}
return leadZeros;
}
[[nodiscard]] inline long long xorshift64(unsigned long& state) noexcept {
state ^= state << 21;
state ^= state >> 35;
state ^= state << 4;
return static_cast<long long>(state * 2685821657736338717);
}
inline void rmbytes(unsigned char* __restrict buf, unsigned long& state) noexcept {
_mm256_storeu_si256((__m256i*) & buf[0], _mm256_set_epi64x(xorshift64(state), xorshift64(state), xorshift64(state), xorshift64(state)));
}
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));
crypto_scalarmult_ed25519_base(pk, h);
_mm256_storeu_si256(reinterpret_cast<__m256i*>(sk), _mm256_loadu_si256(reinterpret_cast<const __m256i*>(seed)));
_mm256_storeu_si256(reinterpret_cast<__m256i*>(sk + 32), _mm256_loadu_si256(reinterpret_cast<const __m256i*>(pk)));
}
void miner_thread() noexcept {
void miner_thread() {
alignas(32) Key inv;
alignas(32) Key seed;
KeysBox keys;
Address rawAddr;
std::random_device rd;
unsigned long state = static_cast<unsigned long>(rd());
printf("Using seed: %lu\n", state);
#ifdef DEBUG
unsigned x = 0;
#endif
while (WHCOND) {
#ifdef USE_AVX2
rmbytes(seed, state);
sign_keypair(keys.PublicKey, keys.PrivateKey, seed);
#else
crypto_sign_ed25519_seed_keypair(keys.PublicKey, keys.PrivateKey, seed);
#endif
if (unsigned char ones = getZeros(keys.PublicKey); ones > conf.high.load()) {
conf.high.store(ones);
while (true) {
crypto_sign_ed25519_keypair(keys.PublicKey, keys.PrivateKey);
unsigned ones = getZeros(keys.PublicKey);
unsigned current_high = conf.high.load(std::memory_order_relaxed);
while (ones > current_high && !conf.high.compare_exchange_strong(current_high, ones, std::memory_order_relaxed)) {
current_high = conf.high.load(std::memory_order_relaxed);
}
if (ones > current_high) {
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());
}
#ifdef DEBUG
if ((++x & 0xFFFF) == 0) {
printf("\rIters: %d", x);
fflush(stdout);
}
#endif
}
}
void startThreads() noexcept {
void startThreads() {
std::vector<std::thread> threads;
threads.reserve(conf.proc);
for (unsigned char x = 0; x < conf.proc; x++) {
for (unsigned x = 0; x < conf.proc; x++) {
threads.emplace_back(miner_thread);
}
for (auto& thread : threads) {
thread.join();
}
}
int main(int argc, char* argv[]) noexcept {
int main(int argc, char* argv[]) {
printf("BuildType: %s\nAVX2: %d\n", __BUILDTYPE__, USE_AVX2);
if (argc < 1) return 0;
if (argc < 1)
return 0;
for (int x = 0; x < argc; x++) {
if (int res = parameters(argv[x]); res == 777) {
if (++x >= argc) {