code wiki / _hdl_build / nx_fpga_lut.nx
nx_fpga_lut.nx
buildroot/runtime/_hdl_build/nx_fpga_lut.nx
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
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
| 20 | const FL_AND: i64 = 0 |
| 21 | const FL_OR: i64 = 1 |
| 22 | const FL_NOT: i64 = 2 |
| 23 | const FL_XOR: i64 = 3 |
| 24 | const FL_NAND: i64 = 4 |
| 25 | const FL_NOR: i64 = 5 |
| 26 | const FL_XNOR: i64 = 6 |
| 27 | const FL_MUX: i64 = 10 // (sel=a, in0=b, in1=c) |
| 28 | const FL_DFF: i64 = 23 // sequential |
functions
| 33 | func lut4_index(a: i64, b: i64, c: i64, d: i64) -> i64 |
| 36 | func lut4_eval(init: i64, a: i64, b: i64, c: i64, d: i64) -> i64 |
| 43 | func fl_gate_ref(kind: i64, a: i64, b: i64, c: i64, d: i64) -> i64 |
| 59 | func fl_kind_lutmappable(kind: i64) -> i64 called by 1: main |
| 74 | func fl_gate_to_lut4(kind: i64) -> i64 called by 12: fab_build_addsubfab_build_alufab_build_cmpmainmainseq_build_pc+6 calls 2: fl_gate_reflut4_index |
| 91 | func fl_dff_next(q_prev: i64, d: i64, tick: i64) -> i64 called by 1: main |