diff --git a/2023/07/19/Makefile b/2023/07/20/Makefile similarity index 100% rename from 2023/07/19/Makefile rename to 2023/07/20/Makefile diff --git a/2023/07/19/README.md b/2023/07/20/README.md similarity index 100% rename from 2023/07/19/README.md rename to 2023/07/20/README.md diff --git a/2023/07/19/benchmarks/benchmark.cpp b/2023/07/20/benchmarks/benchmark.cpp similarity index 97% rename from 2023/07/19/benchmarks/benchmark.cpp rename to 2023/07/20/benchmarks/benchmark.cpp index 78db0aeb..a325a88c 100644 --- a/2023/07/19/benchmarks/benchmark.cpp +++ b/2023/07/20/benchmarks/benchmark.cpp @@ -7,6 +7,45 @@ extern "C" { #include "base32.h" } + +int b32_pton(const char *src, uint8_t *target, size_t tsize) { + char ch; + size_t p = 0; + + memset(target, '\0', tsize); + while ((ch = *src++)) { + uint8_t d; + size_t b; + size_t n; + + if (p + 5 >= tsize * 8) + return -1; + + if (isspace((unsigned char)ch)) + continue; + + if (ch >= '0' && ch <= '9') + d = ch - '0'; + else if (ch >= 'A' && ch <= 'V') + d = ch - 'A' + 10; + else if (ch >= 'a' && ch <= 'v') + d = ch - 'a' + 10; + else + return -1; + + b = 7 - p % 8; + n = p / 8; + + if (b >= 4) + target[n] |= d << (b - 4); + else { + target[n] |= d >> (4 - b); + target[n + 1] |= d << (b + 4); + } + p += 5; + } + return (p + 7) / 8; +} void pretty_print(size_t volume, size_t bytes, std::string name, event_aggregate agg) { printf("%-30s : ", name.c_str()); @@ -542,7 +581,7 @@ int main() { bench([&inputs, &output, &sum]() { for (const std::string &s : inputs) { sum += base32hex_avx((uint8_t *)output.data(), - (const uint8_t *)s.c_str()); + (const uint8_t *)s.c_str()); } })); pretty_print(inputs.size(), bytes, "base32hex_simd", @@ -556,7 +595,7 @@ int main() { bench([&inputs, &output, &sum]() { for (const std::string &s : inputs) { sum += base32hex_fast((uint8_t *)output.data(), - (const uint8_t *)s.c_str()); + (const uint8_t *)s.c_str()); } })); pretty_print(inputs.size(), bytes, "base32hex_simple", @@ -573,5 +612,10 @@ int main() { (const uint8_t *)s.c_str()); } })); - + pretty_print( + inputs.size(), bytes, "b32_pton", bench([&inputs, &output, &sum]() { + for (const std::string &s : inputs) { + sum += b32_pton(s.c_str(), (uint8_t *)output.data(), output.size()); + } + })); } diff --git a/2023/07/19/benchmarks/performancecounters/apple_arm_events.h b/2023/07/20/benchmarks/performancecounters/apple_arm_events.h similarity index 100% rename from 2023/07/19/benchmarks/performancecounters/apple_arm_events.h rename to 2023/07/20/benchmarks/performancecounters/apple_arm_events.h diff --git a/2023/07/19/benchmarks/performancecounters/benchmarker.h b/2023/07/20/benchmarks/performancecounters/benchmarker.h similarity index 100% rename from 2023/07/19/benchmarks/performancecounters/benchmarker.h rename to 2023/07/20/benchmarks/performancecounters/benchmarker.h diff --git a/2023/07/19/benchmarks/performancecounters/event_counter.h b/2023/07/20/benchmarks/performancecounters/event_counter.h similarity index 100% rename from 2023/07/19/benchmarks/performancecounters/event_counter.h rename to 2023/07/20/benchmarks/performancecounters/event_counter.h diff --git a/2023/07/19/benchmarks/performancecounters/linux-perf-events.h b/2023/07/20/benchmarks/performancecounters/linux-perf-events.h similarity index 100% rename from 2023/07/19/benchmarks/performancecounters/linux-perf-events.h rename to 2023/07/20/benchmarks/performancecounters/linux-perf-events.h diff --git a/2023/07/19/include/base32.h b/2023/07/20/include/base32.h similarity index 89% rename from 2023/07/19/include/base32.h rename to 2023/07/20/include/base32.h index d595b805..06dd469b 100644 --- a/2023/07/19/include/base32.h +++ b/2023/07/20/include/base32.h @@ -4,7 +4,9 @@ #include #include // base32 encodes encodes 5 bytes to 8 characters. -// We implement base32hex. +// We implement base32hex. +// Base32: the "Base 32 Encoding with Extended Hex Alphabet" as +// specified in [RFC4648]. // // The functions return the // number of input bytes decoded (not counting padding). diff --git a/2023/07/19/scripts/bigtable.py b/2023/07/20/scripts/bigtable.py similarity index 90% rename from 2023/07/19/scripts/bigtable.py rename to 2023/07/20/scripts/bigtable.py index a7360d98..61e69eac 100644 --- a/2023/07/19/scripts/bigtable.py +++ b/2023/07/20/scripts/bigtable.py @@ -47,4 +47,13 @@ def swap_shift(x): for i in range(8): running |= swap_shift(0b11111 << (5 * (7 - i))) z.append(running) -print(z) \ No newline at end of file +print(z) + +w = [] +for i in range(256): + if(t[i] != 32): + w.append((t[i], chr(i))) +w.sort() +for (a,b) in w: + if(b.upper() == b): + print("'"+str(b)+"'",a,"") diff --git a/2023/07/19/src/base32.c b/2023/07/20/src/base32.c similarity index 100% rename from 2023/07/19/src/base32.c rename to 2023/07/20/src/base32.c diff --git a/2023/07/19/tests/unit.cpp b/2023/07/20/tests/unit.cpp similarity index 100% rename from 2023/07/19/tests/unit.cpp rename to 2023/07/20/tests/unit.cpp