code wiki / _hdl_build / nx_recip_synth.nx

nx_recip_synth.nx

buildroot/runtime/_hdl_build/nx_recip_synth.nx

9043 B166 linesdepth 9pulls 9 transitivereach 1 importersview sourcekind librarytopic recip
docsdependenciesstructsconstsfunctions

about

nx_recip_synth.nx -- the MULTIPLICATIVE (Newton-Raphson reciprocal) divider instantiated as an NxGsim GATE-NETWORK (the gate-network instantiation of the algorithm proven scalar in nx_alu_divider_newton.nx, maxcorr=1). This is the "first provable rung" (W=16): the SAME Newton math as the scalar proof, emitted as a pure combinational word-level netlist using ONLY the already-proven cell builders div_const / div_op2 / div_mux (nx_alu_divider.nx) over the gate-sim's MUL/SHL/SHR/SUB/ADD/LTU/XOR/AND/OR/MUX/CONST cells. WHY W=16 is the smallest GATE-NETWORK-provable variant: At W=16 every intermediate fits i64 with a PLAIN depth-1 MUL cell, so NO nx_mul_wide (128-bit organ) is needed -- verified bit-widths (D<=2^16): dn <= 2^16 (17b) dn*x = dx <= 2^33 (34b) 2F^2-dx = t <= 2^33 (34b) x*t <= 2^49 (49b) N*x <= 2^33 (34b) all <= 49 bits, so a single MUL cell (low 64 bits, no wrap) is EXACT here. The new code is therefore just the gate-emitter wrapper around 100%-proven math + proven cells -- no new unproven gate organ is exercised. The nx_mul_wide-dependent rungs (W>=24, x*t=73b) are the next milestone. data-dependent normalization (msb_pos / barrel-shift) is BUILT IN GATES here: - msb_synth : priority encoder over a runtime net (cascade of LTU/MUX), returns p with 2^p <= D < 2^(p+1) for D in [1, 2^16). - barrel SHL/SHR by a *net* count uses the sim's SHL/SHR cells directly (the cell takes b = the runtime shift-count net), so normalization Dn = D<<s and extraction (N*x)>>(17+p) are pure gates. The correction tail is UNROLLED to a fixed KCORR (data-INDEPENDENT, so the latency stays O(iters)+O(1)); the scalar proof showed maxcorr=1, so KCORR=2 is a safe constant. license_tier: ORIGINAL HONEST-METRIC NOTE (do not fool ourselves): nx_nxgate_sim assigns depth-1 to every word-level cell, so a MUL cell looks as cheap as an AND. This proves FUNCTIONAL 1:1 correctness of the gate-network, and the iteration COUNT (3 vs W=16 restoring stages) is a real cell-count/sequential-step win -- but NOT a true critical-path latency exceed until a real gate-delay model exists.

dependencies 1 imports · 1 importers

nx_mul_wide.nx nx_recip_synth.nx nx_recip_synth_test.nx

imports: nx_mul_wide.nx

imported by: nx_recip_synth_test.nx

structs

none

consts

40const RS_W: i64 = 16
41const RS_F: i64 = 65536 // 2^16 fixed-point scale (Q16)
42const RS_FF2: i64 = 8589934592 // 2 * F * F = 2^33
43const RS_ITERS: i64 = 3 // matches the proven scalar NW_ITERS
44const RS_KCORR: i64 = 2 // unrolled correction stages (proven maxcorr=1)

functions

55func msb_synth(g: *NxGsim, nd: i64) -> i64
called by 1: nx_recip_div_synth calls 2: div_constdiv_op2
74func recip_const_div17(g: *NxGsim, num: i64) -> i64
104func nx_recip_div_synth(g: *NxGsim, na: i64, nb: i64, rem_out: *i64) -> i64