Skip to content

Commit

Permalink
Moving.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lemire committed Jul 20, 2023
1 parent 3bcd43e commit 514c76f
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 5 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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());
}
}));
}
4 changes: 3 additions & 1 deletion 2023/07/19/include/base32.h → 2023/07/20/include/base32.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include <stddef.h>
#include <stdint.h>
// 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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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("<tr><td>'"+str(b)+"'</td><td>",a,"</td></tr>")
File renamed without changes.
File renamed without changes.

0 comments on commit 514c76f

Please sign in to comment.