Skip to main content

Module int

Module int 

Source
Expand description

Integer dialect: exact 32-bit integer graphs with loop-carried state.

A separate graph from the f64 RISC ExprGraph: the float ops are untouched, and nothing here is ever reassociated, contracted or simplified beyond folding constant-only nodes with the interpreter’s own semantics. The contract is bit-exactness: IntGraph::eval (the CPU reference), the generated WGSL (IntGraph::to_wgsl_fn) and the generated Rust (IntGraph::to_rust) compute the same bits.

  • Types: i32, u32, bool; i8/u8 exist only as storage (Elem) and widen on load.
  • Arithmetic wraps (+ − ×, negation); shift amounts are taken mod 32; >> is arithmetic on i32, logical on u32.
  • IntGraph::mul_wide: exact 32×32→64 as (lo, hi); WGSL (no 64-bit integers) gets 16-bit-limb helpers.
  • Loops: IntGraph::while_loop is structured SSA (scf.while): state values, a condition and a next-state over INode::State nodes. Results are INode::LoopOut nodes. Loops nest; every node belongs to the innermost loop whose state it depends on, so invariant code is hoisted by construction.
  • Buffers are read-only (IntGraph::load), except scratch buffers (IntGraph::buffer_rw): small fixed-length arrays read and written through ordered effects. An effect token (IntGraph::token) is threaded from store to store (IntGraph::store returns the next token); a scratch load (IntGraph::load_rw) depends on a token. The tokens only order the effects through data dependencies: every backend executes scratch loads and stores in the one shared schedule order (never inlined, never moved), so effects are deterministic and identical across backends whatever the graph. A builder that wants “load sees the state as of its token” makes every load of a token feed the store that consumes it. Everything else is pure. Results leave through the caller’s bindings of the outputs.

Structs§

Buffer
A buffer declaration.
IId
Handle to a node of an IntGraph.
IntGraph
Integer expression graph with structural interning.
Limits
Resource limits for IntGraph::from_bytes.
Loop
A structured while loop: s = init; while cond(s) { s = next(s) }.
Program
A graph compiled to register bytecode: the CPU reference evaluator.
WireError
Why a graph was rejected.

Enums§

BinOp
Binary integer ops (operands of one type, except shift amounts).
CmpOp
Comparisons (produce bool).
Elem
Storage element type of a read-only buffer.
INode
A node.
IType
Value type of a node.
UnOp
Unary ops.

Constants§

WGSL_PRELUDE
Helpers the WGSL lowering calls (exact high words of 32×32 products in 16-bit limbs). Include once per module.