summaryrefslogtreecommitdiff
path: root/itoa_gen.py
diff options
context:
space:
mode:
Diffstat (limited to 'itoa_gen.py')
-rw-r--r--itoa_gen.py17
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};")