Expand description
The TCG3 rANS lane decoder as tang-expr integer graphs.
One residual per evaluation: the lane’s 32-bit rANS state and word
position go in and come out (loop-carried state), with renormalization,
16-bit word fetch from the stream, and the binarization (static priors or
the learned mixture CDF). The same graph is lowered to the WGSL kernel
(replacing the hand-written res_static_gen / res_learned_gen) and run
by the CPU interpreter; a stream can also ship its own graphs
(crate::shipdec).
The graphs are pure, so if becomes a predicate: a decision under a
false predicate still computes its step but keeps the old state (and its
word fetch reads in bounds or 0). Loops carry the predicate in their
condition, so they run exactly the hand-written trip counts.
ABI (both roles): buffer 0 mt (u32: priors / σ and 2^x tables),
buffer 1 stream (u32, two little-endian 16-bit words each);
params p0 = x, p1 = pos, p2 = end (lane state and word bound), then
- static:
p3 = sig,p4 = e,p5 = cls,p6 = sctx,p7 = off_init(allu32); - learned:
p3..p7= the net outputso0..o4(i32),p8 = off_sig,p9 = off_pow(u32); - adaptive learned (per-lane APM,
crate::lmodel3::Adapt): the learned params, thenp10 = off_stretch(the stretch table inmt),p11 = wa,p12 = lim,p13 = mask(u32), and scratch buffer 2adt(136u32words,(p << 8) | countper bin, reset per block by the host);
outputs x', pos' (u32), r (i32), plus the final effect token
(u32, always 0) for the adaptive role.
Structs§
- CpuRes
- CPU evaluation of residual graphs (the interpreter; one per thread).
- Lane
- One lane’s rANS state (as
lane_startin the kernel).
Constants§
- BUFS
- Buffer ABI of the residual graphs.
- LEARNED_
AD_ PARAMS - Param types of the adaptive learned graph.
- LEARNED_
PARAMS - Param types of the learned graph.
- OUTS
- Output types of both residual graphs.
- OUTS_AD
- Output types of the adaptive learned graph (the last is the effect token).
- RW_AD
- Scratch-buffer ABI of the adaptive learned graph: the lane’s APM bins
(
adt[ad_b + i]in the kernel’s workgroup memory). - STATIC_
PARAMS - Param types of the static graph.
Functions§
- builtin_
wgsl - The built-in residual decoders as WGSL.
- builtin_
wgsl_ ad builtin_wgslwith the adaptive learned decoder.- cpu_mt
mtfor CPU decoding: priors at 0, then the σ, 2^x and stretch tables (the kernel’s layout); returns the buffer and(off_sig, off_pow).- learned_
ad_ graph - The learned-mixture residual decoder through the per-lane adaptive probability maps (the adaptive role, see the module docs).
- learned_
graph - The learned-mixture residual decoder (
res_learned_gen). - splice_
res - Replace the
// RES_BEGIN…// RES_ENDregion of a kernel source. - static_
graph - The static-prior residual decoder (
res_static_gen). - stream_
words - Stream bytes as the kernels see them:
u32words, little endian. - wgsl
- WGSL for
res_static_gen/res_learned_genfrom the given graphs (guarded: bounds-checked loads, for untrusted graphs). A learned graph with four outputs is the adaptive role: it reads the kernel’sad_*state andadtbins (set up per block byad_reset).