code wiki / (root) / nx_q4k_simd2_gate.nx

nx_q4k_simd2_gate.nx

buildroot/runtime/nx_q4k_simd2_gate.nx

11977 B203 linesdepth 9pulls 25 transitivereach 0 importersview sourcekind gate/prooftopic q4k
docsdependenciesstructsconstsfunctions

about

nx_q4k_simd2_gate.nx -- the REFEREE for __q4k_unpack32s (the nx_cc intrinsic) and nx_q4k_dot_simd2 (2026-09-02, LM4c). The intrinsic is proven at TWO levels. (1) LANE LEVEL: on packed bytes whose nibbles and scales are chosen so every expected lane is known, out[k] must equal (byte_k & 15) * sc_lo and out[32+k] must equal (byte_k >> 4) * sc_hi for all 64 lanes, including the extreme lane value 15*63 = 945 (no lane carry) and a zero scale; and a run over 5000 pseudo-random byte blocks must agree lane-for-lane with the scalar spread+multiply nx_q4k_dot_simd_lib already trusts (ds_spread4). (2) DOT LEVEL: on 200 pseudo-random Q4_K super-block rows with real-shaped d, dmin, scales and mins, nx_q4k_dot_simd2 must return EXACTLY what nx_q4k_dot_simd returns (both are exact integer functions of the same bytes) and exactly what the scalar reference nx_q4k_dot_row_col returns. Neg-controls: a corrupted lane must NOT match (the lane tooth can fail) and a flipped nibble byte must change the dot (the dot tooth can fail). A timing line reports simd2 vs simd over the same rows (a number, never a verdict -- the decode benchmark is the speed ruler). nx_q4k_simd2_gate (no args; needs a compiler that knows __q4k_unpack32s, else it does not build) license_tier: ORIGINAL. Writes nothing. No hw writes.

dependencies 15 imports · 0 importers

nx_syscalls.nx nx_tier.nx nx_le.nx nx_tensor.nx nx_gguf.nx nx_gguf_load.nx nx_dequant_iter.nx nx_q4k_matmul.nx nx_clock.nx nx_gate_verdict.nx nx_q4k_simd2_gate.nx

diagram shows first 10 each side; +5 more imports, +0 more importers in the complete lists below.

imports: nx_syscalls.nxnx_tier.nxnx_le.nxnx_tensor.nxnx_gguf.nxnx_gguf_load.nxnx_dequant_iter.nxnx_q4k_matmul.nxnx_clock.nxnx_gate_verdict.nxnx_q4k_dot_simd_lib.nxnx_q4k_dot_simd2_lib.nxnx_thread_pool.nxnx_nofloat_llm.nxnx_nofloat_q4k.nx

imported by: nobody (leaf or entry point)

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

main gv_head gv_puts sys_write gv_ctr sys_mmap nxa_die sys_write ↻ sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sys_mmap ↻ gv_check gv_puts ↻ g2_lanes_ok g2_lane nx_le_read_u16 g2_lane ↻ g2_lcg g2_scalar_unpack nx_le_read_u64 nx_le_read_u32 ds_spread4 g2_bufs_equal gv_puts ↻ gv_num sys_mmap ↻ sys_write ↻ sys_munmap nx_q4k_iter_alloc sys_mmap ↻

structs

none

consts

29const G2_LCG_A: i64 = 6364136223846793005
30const G2_LCG_C: i64 = 1442695040888963407
31const G2_LCG_MASK: i64 = 0x7FFFFFFFFFFFFFFF
32const G2_LCG_SEED: i64 = 424242424242
33const G2_BYTES: i64 = 32
34const G2_LANES: i64 = 64
35const G2_LANE_MAX: i64 = 945 // 15 * 63
36const G2_SC_MAX: i64 = 63
37const G2_RAND_BLOCKS: i64 = 5000
38const G2_ROWS: i64 = 200
39const G2_NBLK: i64 = 14 // 3584-wide row: the 7B attention shape
40const G2_SB: i64 = 144
41const G2_COL_MAX: i64 = 32767
42const G2_TIMING_ITERS: i64 = 2000
43const G2_QBUF_BYTES: i64 = 128
44const G2_NIBBLE_MASK: i64 = 15
45const G2_NIB_SHIFT: i64 = 4
46const G2_SC_HI_SHIFT: i64 = 16

functions

49func g2_lcg() -> i64 { g_g2_st = (g_g2_st*G2_LCG_A + G2_LCG_C) & G2_LCG_MASK; return g_g2_st >> 16 }
called by 2: g2_fill_rowmain
52func g2_lane(p: *u8, k: i64) -> i64 { var v: i64 = nx_le_read_u16(p, k*2); if v >= 32768 { v = v - 65536 } return v }
called by 2: g2_lanes_okmain calls 1: nx_le_read_u16
55func g2_lanes_ok(qs: *u8, out: *u8, sclo: i64, schi: i64) -> i64
called by 1: main calls 1: g2_lane
68func g2_scalar_unpack(qs: *u8, out: *i64, sclo: i64, schi: i64) -> i64
called by 1: main calls 2: nx_le_read_u64ds_spread4
82func g2_bufs_equal(a: *u8, b: *u8, n: i64) -> i64 { var i: i64 = 0; while i < n { if a[i] != b[i] { return 0 } i = i + 1 } return 1 }
called by 1: main
85func g2_fill_row(buf: *u8, nblk: i64) -> i64
called by 1: main calls 1: g2_lcg
112func main() -> i64