Research-Stack/5-Applications/tools-scripts/utils/generate_diat_tables.py
Devin AI a496d8d3ce fix(infra): Q16_SCALE int not float, add missing Path/sys imports
- Q16_SCALE: float → int in lib/q16.py (int // float returns float,
  breaking Q16_16 integer contract in gccl_waveprobe, vcn_famm_transport)
- qr_spatial_hash.py: sys → _sys (only _sys was imported)
- Add missing 'from pathlib import Path' to 7 files that use Path()
  without importing it: test_fpga, compare_tier1_vs_tier2,
  generate_avm_gold_trace, burgers_triad_core, hot_path_cold_path,
  sabotage_prevention, generate_diat_tables
- hot_path_cold_path.py: also add missing 'import sys'

Co-Authored-By: Allaun Silverfox <bigdataiscoming+9i37y6j2@protonmail.com>
2026-06-16 01:16:31 +00:00

29 lines
947 B
Python

import math
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[3] / "4-Infrastructure"))
from lib.q16 import to_q16
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(y_inv):08x}\n")
f_sqrt.write(f"{to_q16(y_sqrt):08x}\n")
print("Success: Generated diat_inv_table.mem and diat_sqrt_table.mem")
if __name__ == "__main__":
generate_mem_files()