diff options
| author | batleram <batleram@gmail.com> | 2026-10-24 17:28:26 -0400 |
|---|---|---|
| committer | batleram <batleram@gmail.com> | 2026-10-24 17:28:26 -0400 |
| commit | deeaf5134dcd156500436ad57ba3d6e814a21849 (patch) | |
| tree | c69425a8915ec9d783d1db5201734866db1cb2b9 /itoa_gen.py | |
| parent | a38f91aff987f01cc885771554b4cd142599df3f (diff) | |
Hardcode templating ~800ms
Diffstat (limited to 'itoa_gen.py')
| -rw-r--r-- | itoa_gen.py | 15 |
1 files changed, 15 insertions, 0 deletions
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 <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] = {") + 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("};") + |
