From b14d9328b40dd2b2cc61ba60c593f70e09f0ec46 Mon Sep 17 00:00:00 2001 From: sudden6 Date: Thu, 16 Dec 2021 21:35:30 +0100 Subject: [PATCH] update build scripts --- other/analysis/run-clang | 3 ++- other/analysis/run-gcc | 3 ++- other/fun/BUILD.bazel | 11 +++++++++++ other/fun/cracker.c | 11 +++++++---- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/other/analysis/run-clang b/other/analysis/run-clang index 817170573..3ea775b92 100755 --- a/other/analysis/run-clang +++ b/other/analysis/run-clang @@ -23,4 +23,5 @@ clang++ -o /dev/null amalgamation.cc \ -Wno-sign-compare \ -Wno-unreachable-code-return \ -Wno-unused-parameter \ - -Wno-used-but-marked-unused + -Wno-used-but-marked-unused \ + -Wno-source-uses-openmp diff --git a/other/analysis/run-gcc b/other/analysis/run-gcc index a7033f13d..5fe0fe680 100755 --- a/other/analysis/run-gcc +++ b/other/analysis/run-gcc @@ -61,4 +61,5 @@ g++ -O3 -o /dev/null amalgamation.cc \ -Wunused-local-typedefs \ -Wunused-value \ -Wunused-but-set-parameter \ - -Wunused-but-set-variable + -Wunused-but-set-variable \ + -fopenmp diff --git a/other/fun/BUILD.bazel b/other/fun/BUILD.bazel index 33cb2c051..e730427d8 100644 --- a/other/fun/BUILD.bazel +++ b/other/fun/BUILD.bazel @@ -3,6 +3,17 @@ load("@rules_cc//cc:defs.bzl", "cc_binary") cc_binary( name = "cracker", srcs = ["cracker.c"], + copts = ["-fopenmp"], + linkopts = ["-fopenmp"], + deps = [ + "//c-toxcore/toxcore:ccompat", + "@libsodium", + ], +) + +cc_binary( + name = "cracker_simple", + srcs = ["cracker_simple.c"], deps = [ "//c-toxcore/testing:misc_tools", "@libsodium", diff --git a/other/fun/cracker.c b/other/fun/cracker.c index 33fd5b235..19569e8cc 100644 --- a/other/fun/cracker.c +++ b/other/fun/cracker.c @@ -20,6 +20,9 @@ #include #include +/* NULL compatibility macro */ +#include "../../toxcore/ccompat.h" + #define KEY_LEN 32 // Maximum number of bytes this program can crack in one run #define MAX_CRACK_BYTES 8 @@ -151,7 +154,7 @@ static void cracker_core(uint64_t range_start, uint64_t range_end, uint64_t rang } } -void print_stats(double seconds_passed, double keys_tried) +static void print_stats(double seconds_passed, double keys_tried) { printf("Runtime: %10lus, Keys tried %e/%e, Calculating %e keys/s\n", (unsigned long) seconds_passed, keys_tried, (double) UINT64_MAX, keys_tried / seconds_passed); @@ -186,7 +189,7 @@ int main(int argc, char *argv[]) printf("Searching for key with prefix: %s\n", argv[1]); - time_t start_time = time(NULL); + time_t start_time = time(nullptr); // Declare private key bytes as uint64_t[4] so we can lower the alignment without problems uint64_t priv_key_shadow[KEY_LEN / 8]; @@ -206,7 +209,7 @@ int main(int argc, char *argv[]) cracker_core(rem_start, UINT64_MAX, 1, priv_key_shadow, &longest_match, hex_prefix, prefix_chars_len); - double seconds_passed = difftime(time(NULL), start_time); + double seconds_passed = difftime(time(nullptr), start_time); double old_seconds_passed = seconds_passed; // Reduce time to first stats output @@ -221,7 +224,7 @@ int main(int argc, char *argv[]) for (uint64_t tries = 0; tries < rem_start; tries += batch_size) { cracker_core(tries, tries + batch_size, 0, priv_key_shadow, &longest_match, hex_prefix, prefix_chars_len); - seconds_passed = difftime(time(NULL), start_time); + seconds_passed = difftime(time(nullptr), start_time); // Use double type to avoid overflow in addition, we don't need precision here anyway double keys_tried = ((double) tries) + rem_batch_size + 1;