code wiki / _hdl_build / nx_karatsuba_test.nx

nx_karatsuba_test.nx

buildroot/runtime/_hdl_build/nx_karatsuba_test.nx

3034 B62 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind gate/proof
docsdependenciesstructsconstsfunctions

about

nx_karatsuba_test.nx -- ALGORITHM-LEVEL search space #2: Karatsuba multiplication. To multiply x*y, split each into halves (x=x1*B+x0): the schoolbook way needs 4 sub-multiplies (x0y0, x0y1, x1y0, x1y1); Karatsuba needs only 3 (z0=x0y0, z2=x1y1, z1=(x0+x1)(y0+y1)-z0-z2), trading a multiply for cheap adds. NO compiler turns schoolbook into Karatsuba -- the win is ALGORITHMIC -- so the team's Karatsuba beats whatever gcc/clang/rust emit for the naive bignum multiply, on the right operand sizes. Verified here BY EXECUTION: karatsuba == native over many inputs, and it uses 3 multiplies not 4. (16-bit operands, 8-bit halves, fits i64.)

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_karatsuba_test.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap ka_main ka_puts sys_write sys_mmap ↻ karatsuba ka_num sys_mmap ↻ sys_write ↻ sys_exit

structs

none

consts

11const KB: i64 = 256 // half-base 2^8

functions

14func karatsuba(x: i64, y: i64, mc: *i64) -> i64
called by 1: ka_main
23func ka_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 1: ka_main calls 1: sys_write
24func ka_num(v: i64) -> i64
called by 1: ka_main calls 2: sys_mmapsys_write
33func ka_main(r: *i64) -> i64
called by 1: main calls 4: ka_putssys_mmapkaratsubaka_num
56func main() -> i64