nx_nofloat_q4k_gate.nx
buildroot/runtime/nx_nofloat_q4k_gate.nx
about
nx_nofloat_q4k_gate.nx -- the REFEREE for nx_nofloat_q4k (LM4 resident-quant decode, /compare/engineshift 2026-09-02).
In-process teeth that need no model: a hand-built Q4_K super-block matrix with d=1.0, dmin=0, every scale 1 and every
min 0 makes each dequantised weight EXACTLY its 4-bit code, and the activation is chosen so the dynamic i16 pack is
exact, so nq_mm's Q16 output has ONE correct value that an independent i64 reference computes (both shift regimes,
and a full-width 18944 row for the overflow headroom); the route decision is a pure function tested on every branch
(Q4_K aligned -> in place; Q6_K -> i16; a non-256 width -> i16, never a silent in-place read); the i16 route must
equal mm_pool_i8 on the same inputs; the scale must never let max|x| wrap an i16 lane. Neg-control: one post-shift
off must NOT match the reference. T0 (gv_need the Q4_K_M fixture) censuses the fixture's tensor types so the
model-level serve gate can only claim the fused path where Q4_K tensors exist -- fixture-reached-the-condition.
nx_nofloat_q4k_gate [model.gguf] default /home/elderwesto/nx_stage/nx_15b_model.gguf
license_tier: ORIGINAL. Writes nothing. No hw writes.
dependencies 12 imports · 0 importers
diagram shows first 10 each side; +2 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_thread_pool.nxnx_gate_verdict.nxnx_gatekit_lib.nxnx_nofloat_llm.nxnx_q4k_dot_simd_lib.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
structs
| none |
consts
| 25 | const GQ_IN: i64 = 256 |
| 26 | const GQ_OUT: i64 = 3 |
| 27 | const GQ_WIDE_IN: i64 = 18944 // Qwen2.5-7B ffn width: the overflow-headroom case |
| 28 | const GQ_WIDE_OUT: i64 = 2 |
| 29 | const GQ_F16_ONE_LO: i64 = 0 // 0x3C00 = 1.0 in IEEE half, little-endian bytes |
| 30 | const GQ_F16_ONE_HI: i64 = 60 |
| 31 | const GQ_SB_BYTES: i64 = 144 |
| 32 | const GQ_SCALES_OFF: i64 = 4 |
| 33 | const GQ_QS_OFF: i64 = 16 |
| 34 | const GQ_QS_BYTES: i64 = 128 |
| 35 | const GQ_SCALE_ONE: i64 = 1 // 6-bit scale field = 1 (bytes 0..3); packed form for sub-blocks 4..7 = 0x01 in bytes 8..11 |
| 36 | const GQ_V_MAX: i64 = 32767 |
| 37 | const GQ_V_SHIFT24: i64 = 14 // x = v << 14 in Q24 -> sx = 2^14 exactly when max v = 32767 |
| 38 | const GQ_V_SHIFT16: i64 = 6 // x = v << 6 in Q16 -> sx = 2^6 |
| 39 | const GQ_REF_MUL: i64 = 64 // (q<<16 * v<<14) >> 24 = 64*q*v and (q<<16 * v<<6) >> 16 = 64*q*v |
| 40 | const GQ_NIBBLES: i64 = 16 |
| 41 | const GQ_LCG_A: i64 = 6364136223846793005 |
| 42 | const GQ_LCG_C: i64 = 1442695040888963407 |
| 43 | const GQ_LCG_MASK: i64 = 0x7FFFFFFFFFFFFFFF |
| 44 | const GQ_LCG_SEED: i64 = 88172645463325252 |
| 45 | const GQ_SMALL_IN: i64 = 16 |
| 46 | const GQ_SMALL_OUT: i64 = 3 |
| 47 | const GQ_SMALL_W: i64 = 40000 |
| 48 | const GQ_SMALL_X: i64 = 300000 |
| 49 | const GQ_Q24_BITS: i64 = 24 |
| 50 | const GQ_Q8_VALS: i64 = 32 |
| 51 | const GQ_Q8_BYTES: i64 = 34 |
| 52 | const GQ_Q8_SCALE_BYTES: i64 = 2 |
| 53 | const GQ_Q8_CODE_MAX: i64 = 127 |
functions
| 57 | func gq_lcg() -> i64 { g_gq_st = (g_gq_st*GQ_LCG_A + GQ_LCG_C) & GQ_LCG_MASK; return g_gq_st >> 16 } |
| 61 | func gq_build_q4k(out_dim: i64, in_dim: i64, wref: *i64) -> *u8 |
| 91 | func gq_fill_v(v: *i64, n: i64) -> i64 |
| 97 | func gq_ref(wref: *i64, v: *i64, in_dim: i64, o: i64) -> i64 { var s: i64 = 0; var k: i64 = 0; while k < in_dim { s = s + wref[o*in_dim+k]*v[k]; k = k + 1 } return s*GQ_REF_MUL } |
| 98 | func gq_all_rows_match(dst: *i64, wref: *i64, v: *i64, in_dim: i64, out_dim: i64) -> i64 |
| 103 | func gq_run(buf: *u8, out_dim: i64, in_dim: i64, v: *i64, vshift: i64, shift: i64, dst: *i64) -> i64 |
| 116 | func gq_build_q8(out_dim: i64, in_dim: i64, wref: *i64) -> *u8 |
| 138 | func gq_run_q8(buf: *u8, out_dim: i64, in_dim: i64, v: *i64, vshift: i64, shift: i64, dst: *i64) -> i64 |
| 149 | func gq_census(path: *u8, cnt: *i64) -> i64 |
| 168 | func main(argc: i64, argv: *i64) -> i64 |