code wiki / _hdl_build / nx_fpga_lut.nx

nx_fpga_lut.nx

buildroot/runtime/_hdl_build/nx_fpga_lut.nx

4720 B94 linesdepth 2pulls 2 transitivereach 79 importersview sourcekind librarytopic fpga
docsdependenciesstructsconstsfunctions

about

nx_fpga_lut.nx -- LIB: RUNG 4 of the sovereign FPGA-boot SIMULATOR (operator 2026-06-22: "for the fpga if there is a way to simulate it lets build that from the hardware rung up on specs"). The FPGA's ATOM is the 4-input Look-Up Table (LUT4): 16 SRAM config bits that, loaded by the bitstream, make ONE cell compute ANY boolean function of 4 inputs. This lib models the LUT4 + DFF fabric primitives PER SPEC and the TECH-MAP that compiles the team's gate-netlist primitives (nishi_synth_gates NX_GATE_KIND_*) into LUT4 init bits = the per-LUT bitstream. This is the bedrock the higher rungs (place -> route -> bitstream -> fabric-config-sim -> boot) stack on. Built on the VERIFIED lower rungs: rv64im_min_sim (behavioral), synth_emit_alu_gates (netlist), nx_nxgate_sim (gate eval). NEVER-BRICK (#26) BY CONSTRUCTION: pure integer, NO float, NO syscall that writes any real/persistent hardware state -- a LUT is evaluated in memory. Bounded (a LUT4 has exactly 16 input combinations), total (every input yields 0/1), deterministic (same input -> same bit). A simulator cannot brick anything; the gate asserts these. Kind codes MIRROR nishi_synth_gates.nx (sealed enum) so the tech-map is over the SAME primitives the netlist emitter uses (local consts avoid dragging that file's heavy hdl-primitive deps; codes are a stable sealed set). license_tier: ORIGINAL

dependencies 1 imports · 17 importers

nx_syscalls.nx nx_fpga_lut.nx nx_fpga_adder.nx nx_fpga_addsub.nx nx_fpga_alu.nx nx_fpga_bitstream_gate.nx nx_fpga_cmp.nx nx_fpga_decode.nx nx_fpga_fabric.nx nx_fpga_lut_gate.nx nx_fpga_pc.nx nx_fpga_pnr_gate.nx

diagram shows first 10 each side; +0 more imports, +7 more importers in the complete lists below.

imports: nx_syscalls.nx

imported by: nx_fpga_adder.nxnx_fpga_addsub.nxnx_fpga_alu.nxnx_fpga_bitstream_gate.nxnx_fpga_cmp.nxnx_fpga_decode.nxnx_fpga_fabric.nxnx_fpga_lut_gate.nxnx_fpga_pc.nxnx_fpga_pnr_gate.nxnx_fpga_ram.nxnx_fpga_regfile.nxnx_fpga_seq.nxnx_fpga_shift.nxnx_jtag_load_gate.nxnx_nbit.nxnx_nrtl.nx

structs

none

consts

20const FL_AND: i64 = 0
21const FL_OR: i64 = 1
22const FL_NOT: i64 = 2
23const FL_XOR: i64 = 3
24const FL_NAND: i64 = 4
25const FL_NOR: i64 = 5
26const FL_XNOR: i64 = 6
27const FL_MUX: i64 = 10 // (sel=a, in0=b, in1=c)
28const FL_DFF: i64 = 23 // sequential

functions

33func lut4_index(a: i64, b: i64, c: i64, d: i64) -> i64
36func lut4_eval(init: i64, a: i64, b: i64, c: i64, d: i64) -> i64
43func fl_gate_ref(kind: i64, a: i64, b: i64, c: i64, d: i64) -> i64
called by 2: fl_gate_to_lut4main
59func fl_kind_lutmappable(kind: i64) -> i64
called by 1: main
74func fl_gate_to_lut4(kind: i64) -> i64
91func fl_dff_next(q_prev: i64, d: i64, tick: i64) -> i64
called by 1: main