code wiki / _hdl_build / nx_alu_divider.nx

nx_alu_divider.nx

buildroot/runtime/_hdl_build/nx_alu_divider.nx

4779 B109 linesdepth 7pulls 7 transitivereach 41 importersview sourcekind librarytopic alu
docsdependenciesstructsconstsfunctions

about

nx_alu_divider.nx -- SYNTHESIZE a correct divider as a gate-network (the invention engine's FIRST real hardware invention; closes the SIL-1 stub where the ALU emitter emitted an ADD cell for DIV). There is no DIV cell kind by design -- division must be BUILT from primitives. This synthesizes a restoring divider (MSB-first, `width` stages) into an NxGsim netlist using only SHL/SHR/SUB/LT/XOR/MUX/OR/AND/CONST cells: rem=0, quo=0; for i = width-1 .. 0: rem_in = (rem << 1) | ((a >> i) & 1) ge = !(rem_in < b) rem = ge ? rem_in - b : rem_in quo = quo | (ge << i) The result is a pure combinational network the gate-level sim (nx_nxgate_sim) can verify 1:1 against behavioral a/b -- so the loop can PROVE a correct divider replaces the stub, not just CATCH the stub. (Operands assumed non-negative + small enough that signed LT == unsigned compare; the full 64-bit unsigned compare is a later widening, mechanical.) This is a gate-network GENERATOR -- parameterised by width, it emits the divider; that is the "invention" artifact, distinct from a hand-built netlist. license_tier: ORIGINAL

dependencies 2 imports · 13 importers

nx_nxgate_sim.nx nx_cell_sink.nx nx_alu_divider.nx nx_alu_divider_exhaustive_test.nx nx_alu_divider_floor_test.nx nx_alu_divider_proof_test.nx nx_alu_divider_r4.nx nx_alu_divider_test.nx nx_alu_netlist_build_div.nx nx_alu_select.nx nx_decode_kind.nx nx_eqsat_membership_proof.nx nx_eqsat_rule_proof_test.nx

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

imports: nx_nxgate_sim.nxnx_cell_sink.nx

imported by: nx_alu_divider_exhaustive_test.nxnx_alu_divider_floor_test.nxnx_alu_divider_proof_test.nxnx_alu_divider_r4.nxnx_alu_divider_test.nxnx_alu_netlist_build_div.nxnx_alu_select.nxnx_decode_kind.nxnx_eqsat_membership_proof.nxnx_eqsat_rule_proof_test.nxnx_mul_wide.nxnx_newton_struct.nxnx_rule_soundness.nx

structs

none

consts

none

functions

27func div_const(g: *NxGsim, val: i64) -> i64
42func div_op2(g: *NxGsim, kind: i64, a: i64, b: i64) -> i64
57func div_mux(g: *NxGsim, sel: i64, t: i64, f: i64) -> i64
77func nx_div_synth_sink(k: *NxCellSink, na: i64, nb: i64, width: i64, rem_out: *i64) -> i64
105func nx_div_synth(g: *NxGsim, na: i64, nb: i64, width: i64, rem_out: *i64) -> i64