code wiki / _hdl_build / nx_clbg_fannkuch.nx
nx_clbg_fannkuch.nx
buildroot/runtime/_hdl_build/nx_clbg_fannkuch.nx
about
nx_clbg_fannkuch.nx -- struct-free, pure-integer fannkuch-redux(N).
Canonical Computer Language Benchmarks Game integer hot loop. Enumerates all
N! permutations of {0..N-1} via the "rotations" odometer (NOT lexicographic),
reversing the perm[0]+1 prefix until perm[0]==0 (counting flips) for each.
Outputs (written into a caller-owned 2-slot i64 buffer):
out[0] = checksum (sum of flips with alternating sign +,-,+,- in gen order)
out[1] = maxflips (max flip count over all permutations)
Golden (verified vs gcc -O2 C ref, 2026-06-13):
N=7 -> checksum 228 maxflips 16
N=10 -> checksum 73196 maxflips 38 (X-PERF-003a fixed N)
N=11 -> checksum 556355 maxflips 51
Sovereign-compiled (nx_cc_sovereign -> nxasm_x86_main, NO gcc); this is the
runtime measured by _xperf003a_gate. spec: knowledge/specs/2026-06-13-clbg-fannkuch-throughput.md
genealogy_id: clbg_fannkuch_redux
lineage_id: function
dependencies 2 imports · 0 importers
imports: nx_clock.nxnx_itoa_lib.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
| 24 | const FK_MAXN: i64 = 32 // perm arrays sized for N up to 32 (golden uses 10) |
| 25 | const FK_INTSZ: i64 = 8 // i64 per array slot |
| 26 | const FK_DEFAULT_N: i64 = 10 // X-PERF-003a fixed N (golden checksum 73196 / maxflips 38) |
| 27 | const FK_REPEAT: i64 = 5 // run the enumeration this many times -> stable timing floor |
functions
| 32 | func fannkuch_redux(n: i64, out: *i64) -> i64 called by 1: main |
| 119 | func fk_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: main |
| 124 | func fk_putn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 126 | func main() -> i64 |