From deeaf5134dcd156500436ad57ba3d6e814a21849 Mon Sep 17 00:00:00 2001 From: batleram Date: Sat, 24 Oct 2026 17:28:26 -0400 Subject: Hardcode templating ~800ms --- itoa_gen.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 itoa_gen.py (limited to 'itoa_gen.py') diff --git a/itoa_gen.py b/itoa_gen.py new file mode 100644 index 0000000..0437c62 --- /dev/null +++ b/itoa_gen.py @@ -0,0 +1,15 @@ +with open("itoa_lut.h", "w") as f: + f.write("#include \n") + f.write("typedef union { struct { char chars[3]; uint8_t len; } fields; uint32_t bits; } LutEntry;\n") + f.write("const uint32_t itoa_lut[256] = {") + out = [] + for i in range(0, 256): + running=len(str(i)) + for j in reversed(range(3)): + running = running << 8 + if j < len(str(i)): + running += ord(str(i)[j]) + out.append(hex(running)) + f.write(", ".join(out)) + f.write("};") + -- cgit v1.2.3