code wiki / _hdl_build / nx_mul_wide_test.nx

nx_mul_wide_test.nx

buildroot/runtime/_hdl_build/nx_mul_wide_test.nx

5083 B134 linesdepth 9pulls 9 transitivereach 0 importersview sourcekind gate/prooftopic mul
docsdependenciesstructsconstsfunctions

about

nx_mul_wide_test.nx -- TRIANGULATED validation of the 64x64->128 multiplier. Three INDEPENDENT legs must agree (a bug would have to fool all three): LEG A gate-network (32-bit-limb schoolbook) -> (hiA, loA) LEG B independent 128-bit shift-add reference (bit-by-bit, two-word accumulator w/ unsigned carry -- a DIFFERENT algorithm) -> (hiB, loB) LEG C modular Freivalds: hi*2^64+lo == a*b (mod p) over 3 primes + sanity loA == a*b (the i64 product = the true low 64 bits) Triangulation (operator: build bottom-up, cross-check with both 64-bit and a 128-bit reference). Known answer (FAIL LOUD): "<ok> <total> ", ok == total.

dependencies 1 imports · 0 importers

nx_mul_wide.nx nx_mul_wide_test.nx

imports: nx_mul_wide.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_mul_wide_synth nx_sink_init_mem nx_mul_wide_sink nx_sink_const nx_hdl_wire nx_hdl_signal_alloc nx_hdl_kind_is_valid nx_hdl_width_is_valid nx_sink_cell nx_hdl_wire ↻ sys_mmap _trial nx_gsim_run nx_gsim_kind_supported nx_gsim_eval_cell ref_mul128 u_shr u_lt t_check t_umod _emit_num _nl

structs

none

consts

13const T_MASK32: i64 = 4294967295
14const T_TWO32: i64 = 4294967296
15const T_P1: i64 = 2147483647
16const T_P2: i64 = 1000000007
17const T_P3: i64 = 998244353
18const T_LCG_A: i64 = 6364136223846793005
19const T_LCG_C: i64 = 1442695040888963407

functions

21func _emit_num(v: i64) -> i64
called by 1: main
29func _nl() -> i64 { let z: *u8 = sys_mmap(2); z[0] = 10; sys_write(1, z, 1); return 0 }
called by 1: main
32func u_lt(x: i64, y: i64) -> i64
called by 1: ref_mul128
38func u_shr(a: i64, k: i64) -> i64
called by 1: ref_mul128
44func t_umod(x: i64, p: i64) -> i64
called by 1: t_check
49func t_check(a: i64, b: i64, hi: i64, lo: i64, p: i64) -> i64
called by 1: _trial calls 1: t_umod
58func ref_mul128(a: i64, b: i64, hi_out: *i64) -> i64
called by 1: _trial calls 2: u_shru_lt
80func _trial(g: *NxGsim, lonet: i64, hinet: i64, a: i64, b: i64) -> i64 { // 1 if all legs agree
called by 1: main calls 3: nx_gsim_runref_mul128t_check
97func main() -> i64