diff options
| author | batleram <batleram@gmail.com> | 2026-10-24 17:59:43 -0400 |
|---|---|---|
| committer | batleram <batleram@gmail.com> | 2026-10-24 17:59:43 -0400 |
| commit | f692f2b7c3a47f156aff5a457bbd9bddb0619249 (patch) | |
| tree | ee62e47ee0db77291765ca2cc225dd6e0569d377 /itoa_gen.py | |
| parent | fc1252710f8064bb144677e17a598933b4c68d13 (diff) | |
cleanup lut ~800ms
Diffstat (limited to 'itoa_gen.py')
| -rw-r--r-- | itoa_gen.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/itoa_gen.py b/itoa_gen.py index 0437c62..2c62ed5 100644 --- a/itoa_gen.py +++ b/itoa_gen.py @@ -1,15 +1,14 @@ with open("itoa_lut.h", "w") as f: f.write("#include <stdint.h>\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] = {") + f.write("typedef struct { char chars[3]; uint8_t len; } LutEntry;\n") + f.write("const LutEntry itoa_lut[256] = {\n") 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("};") + s = str(i) + while len(s) < 3: + s=s+chr(69) + out.append("{{"+",".join(map(lambda x: f"'{x}'", s))+"}, "+str(len(str(i)))+"}") + f.write(",\n".join(out)) + f.write("\n};") |
