mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-08-13 14:20:36 +00:00
- burgers_triad_core.py: restore local saturating q16_mul (uses q16_sat for 32-bit clamping + diagnostic counter); only import Q16_ONE from lib - generate_diat_tables.py: restore hardware-specific to_q16_hw with truncation + 0xFFFFFFFF mask (FPGA LUT semantics differ from lib rounding) - Remove dead imports: generate_avm_gold_trace (to_q16 unused), scale_space_solver (q16_mul unused), fractal_dimension (q16_div/q16_mul unused — file has its own local clamping versions) - Fix PEP8 E302 missing blank lines in underverse_closure.py Co-Authored-By: Allaun Silverfox <bigdataiscoming+9i37y6j2@protonmail.com>
30 lines
993 B
Python
30 lines
993 B
Python
import math
|
|
from pathlib import Path
|
|
|
|
|
|
def to_q16_hw(val: float) -> int:
|
|
"""Convert float to Q16.16 for FPGA LUT (truncation + 32-bit unsigned mask)."""
|
|
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_hw(y_inv):08x}\n")
|
|
f_sqrt.write(f"{to_q16_hw(y_sqrt):08x}\n")
|
|
|
|
print("Success: Generated diat_inv_table.mem and diat_sqrt_table.mem")
|
|
|
|
if __name__ == "__main__":
|
|
generate_mem_files()
|