Research-Stack/5-Applications/tools-scripts/utils/generate_diat_tables.py
allaun 475f6319ea chore(repo): push local 768-commit branch state onto clean remote baseline
This squashes all local history (768 commits) onto the scrubbed PR #90
baseline. Individual commits were lost during filter-repo corruption;
the working tree content is preserved intact.

Build: N/A (working tree state only)
2026-06-15 22:46:50 -05:00

27 lines
869 B
Python

import math
def to_q16_16(val):
return int(val * 65536) & 0xFFFFFFFF
def generate_mem_files():
# 256 entries, x = index / 16.0 (if we use ray_t[19:12] as addr)
# However, to avoid 1/0, we'll use x = max(0.0625, index / 16.0)
with open("0-Core-Formalism/core/hw/diat_inv_table.mem", "w") as f_inv, \
open("0-Core-Formalism/core/hw/diat_sqrt_table.mem", "w") as f_sqrt:
for i in range(256):
x = i / 16.0
if x == 0:
x = 1/16.0 # Smallest non-zero
y_inv = 1.0 / math.sqrt(x)
y_sqrt = math.sqrt(x)
f_inv.write(f"{to_q16_16(y_inv):08x}\n")
f_sqrt.write(f"{to_q16_16(y_sqrt):08x}\n")
print("Success: Generated diat_inv_table.mem and diat_sqrt_table.mem")
if __name__ == "__main__":
generate_mem_files()