code wiki / _hdl_build / nx_mul_wide_test.nx
nx_mul_wide_test.nx
buildroot/runtime/_hdl_build/nx_mul_wide_test.nx
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
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
structs
| none |
consts
| 13 | const T_MASK32: i64 = 4294967295 |
| 14 | const T_TWO32: i64 = 4294967296 |
| 15 | const T_P1: i64 = 2147483647 |
| 16 | const T_P2: i64 = 1000000007 |
| 17 | const T_P3: i64 = 998244353 |
| 18 | const T_LCG_A: i64 = 6364136223846793005 |
| 19 | const T_LCG_C: i64 = 1442695040888963407 |
functions
| 21 | func _emit_num(v: i64) -> i64 called by 1: main |
| 29 | func _nl() -> i64 { let z: *u8 = sys_mmap(2); z[0] = 10; sys_write(1, z, 1); return 0 } called by 1: main |
| 32 | func u_lt(x: i64, y: i64) -> i64 called by 1: ref_mul128 |
| 38 | func u_shr(a: i64, k: i64) -> i64 called by 1: ref_mul128 |
| 44 | func t_umod(x: i64, p: i64) -> i64 called by 1: t_check |
| 49 | func t_check(a: i64, b: i64, hi: i64, lo: i64, p: i64) -> i64 |
| 58 | func ref_mul128(a: i64, b: i64, hi_out: *i64) -> i64 |
| 80 | func _trial(g: *NxGsim, lonet: i64, hinet: i64, a: i64, b: i64) -> i64 { // 1 if all legs agree |
| 97 | func main() -> i64 |