interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / ng / IR.md

1169 lines · 82165 bytes Raw Blame History Source

ΩIR: the Omega next-generation intermediate representation

Document:   seed/ng/IR.md (ΩIR wire version 9, tag omega.ng.ir.v1)
Status:     PROPOSED draft v0.1 (ng-ir lane, Hive NG M0). Witness: seed/ng/ngcheck.om (own reader).
            Text tools: seed/ng/ngas.om, ngdis.om. Reference interpreter: seed/ng/ngrun.om. Random
            programs: seed/ng/ngrand.om. In-memory form and the one ng reader/writer: seed/ng/src/ir.om (s14).
Decisions:  Hive NG D1b, D2 + D2b + D2c, D3, D7, D10, D11 (2026-11-07).
Family:     spec/one-layer-format.md (OSC binary IR). Versions 1..8 are untouched by this document.
Pin:        omega-mv 943d955531b9d4d9f70deb41756c0b46441dd5e0, omc sha256 5f90edea…6df.

ΩIR is the one program form inside the ng compiler (D1b: one binary built from seed/ng/src/ ir.om front.om opt.om a64.om gpu.om main.om): the front end writes it, the passes rewrite it, the AArch64 and sm_121 back ends read it. It is typed, in SSA form with block parameters, target-neutral, and carries the exact Omega meaning: every trap a program can raise is an explicit check op naming its trap code, every host word is an effect op, an ordering token makes trap order relative to every observable effect a dataflow edge, and only checked contracts become facts.

1. Principles

  1. One meaning per byte string, one byte string per unit. Fixed-width little-endian fields, no padding, every unused field is 0, every enumeration has a closed set of values. A reader refuses anything else; it never repairs, skips or guesses (OSC canonical law, one-layer-format s2).
  2. Arithmetic is total. No arithmetic or conversion op has undefined behaviour or traps. Traps come only from check ops (chk.*), trap, and the stack (s7.9). Removing a check can change which value a program computes; it can never make the program's behaviour undefined.
  3. Trap order is dataflow (D2c, D7). One ordering token threads every check, every effect (store, atomic, host word, call, launch, barrier) and every terminator (s6.4). A check can move only where its token edge lets it; the two legal ways to remove one are s15.
  4. Memory access is covered. Every memory access op must be dominated by a bounds check or a bounds fact on the same SSA values, and read the token at or after it (s8). The validator enforces this, so an optimizer deletes a check only by putting a fact in its place. The one exception is the run-time pool ops (s7.13), which hold their own bounds test and expose no address.
  5. Facts carry authority only when checked (D2c). A front-end fact must sit under the runtime check that establishes it; a pass-made fact names the pass whose proof it is (s7.10).
  6. Target facts are not IR. Calling convention, register classes, clobbers, subgroup width offered, shared memory budget, feature sets: these belong to a target descriptor checked by the backend. The IR states what a kernel requires (s6.3), never what a chip offers.
  7. Limits are implementation limits with an exit code (s12), never silent truncation.

2. Encoding primitives

u8 u16 u32 u64: unsigned little-endian, exactly that many bytes. There are no variable-length integers. A type id, value id, block id, function id and global id are each a u32.

3. Module

bytesfield
7magic 4F 53 43 31 49 52 00 (OSC1IR\0, the OSC family)
1version 9
16domain tag: the 14 bytes omega.ng.ir.v1 then two 00
4ntypes, then ntypes type entries (s4.2)
4nglobals, then nglobals global entries (s5)
4nfuncs, then nfuncs function records (s6)

Nothing follows the last function record. Identity = SHA-256 of the whole byte string. ΩIR has no name table: names are debug information and are not carried in v1 (a later tag may add a side table outside identity, as OSC v6 did).

Version discipline: a ΩIR reader refuses versions 1..8 and any tag other than the exact 16 bytes; OSC readers of versions 1..8 refuse version 9 by its version byte. A later ΩIR revision changes the tag (omega.ng.ir.v2), never the meaning of v1 bytes.

4. Types

4.1 Built-in scalar types (ids 0..31; no table entry)

idtypeidtype
0void (result only; "no result")8i32
1bool9i64
2u813f32 (IEEE binary32)
3u1614f64 (IEEE binary64)
4u3216f16 (IEEE binary16)
5u6417bf16
6i818fp8 e4m3 (OCP FP8, storage and MMA input only)
7i1619fp8 e5m2 (storage and MMA input only)
20tok, the ordering token (s6.4)

Ids 0..9, 13, 14 equal the OSC scalar tags (one-layer-format s3.4, s10.3). Ids 10, 11, 12, 15 and 21..31 are reserved and refused (they carry OSC ref/bytes/cells/GEDIT meanings in other versions). int below means ids 2..9; float means 13, 14, 16, 17; arith means int or float; num also includes the fp8 ids. tok is a value type only for token values: it is never a function parameter or result, a table type's element, an operand of a non-token op, or a const.

4.2 Type table (ids 32 + k)

Entry k of the table has id 32 + k. An entry refers only to built-in ids and to entries before it (no cycles). Two entries with identical bytes are refused (NONCANONICAL): type equality is id equality. Each entry is a kind byte, then its fields:

kindnamefieldsrules
1VECelem u32, lanes u32elem bool, int or float; lanes 2, 4, 8, 16, 32 or 64; lanes x element bytes <= 64 (bool counts 1 byte)
2ARRAYelem u32, count u32elem num, VEC or STRUCT; count 1..16777216
3STRUCTsize u32, nfields u32, per field: type u32, offset u32, order u8size 1..1073741824; nfields 1..64; field type num, ARRAY or STRUCT; fields strictly ascending by offset, non-overlapping, inside size; order 0 little-endian, 1 big-endian (only meaningful for int/float fields; 0 for ARRAY/STRUCT fields)
4REFtarget u32, access u8, space u8a reference to one memory object of type target (ARRAY or STRUCT); length known from the type
5SLICEelem u32, access u8, space u8a reference to a run of elements of type elem (num, VEC or STRUCT) with a run-time length
6FRAGrole u8, m u16, n u16, k u16, elem u32an MMA operand tile held by one subgroup (s7.8); role 0 A (m x k), 1 B (k x n), 2 C/D (m x n); m, n, k 1..256; elem num

access: 0 read-only (Omega view, text), 1 read-write (Omega edit, out, fresh, local arrays). space (numbers 1..4 from omega-mv#883 E3): 0 HOST (CPU process memory: stack, globals, text), 1 GLOBAL (device global), 2 SHARED (block-shared), 3 CONSTANT (device constant, access must be 0), 4 PRIVATE (per-thread device memory). OM-1 cell structs are STRUCTs whose fields sit at multiples of 8 bytes; OM-2 layouts are STRUCTs with their stated offsets and byte order.

Memory layout of ARRAY and SLICE elements is packed at the element's size (one-layer-format s10.2): bool, u8, i8, fp8 1 byte; u16, i16, f16, bf16 2; u32, i32, f32 4; u64, i64, f64 8; VEC lanes x element; STRUCT its size. Scalars in memory are little-endian unless a STRUCT field says big.

5. Globals

Entry: type u32 (an ARRAY for classes 0 and 1; a scalar element type for class 2), class u8, then for class 1 the initial bytes:

classmeaningdata
0mutable, zero-filled once per program instance (Omega global)none
1read-only with initial bytes (Omega text, constant tables)exactly the array's byte size

Global ids are table indices. gaddr (s7.5) gives a REF to one; a REF with access 1 to a class 1 global is refused (TYPE).

Class 2, run-time pool (s7.13). type is not an ARRAY but the element type id itself, one of the native pool scalars: u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 (ids 2..9, 13, 14). Never bool, vectors, structs, ARRAYs, REFs, SLICEs or the reduced-precision floats (TYPE). There are no data bytes. The pool starts with zero elements; its length only grows (pool.grow), and its storage is zero-filled and may move whenever it grows. Because the storage can move, no REF or SLICE to it can exist: gaddr of a class 2 global is TYPE, no op takes a pool as a value, and every access names the global id as an immediate (s7.13). A class byte above 2 is NONCANONICAL. Classes 0 and 1 and every existing op are unchanged.

6. Functions

6.1 Record

bytesfield
1kind: 0 function, 1 kernel, 2 export (an entry a host calls in function mode)
1flags: bit 0 inline hint; bit 1 the callback function (below); other bits 0
4nparams 0..64, then nparams param type ids (u32 each)
4result type id (0 = void)
kernel only: 4+4+4tx ty tz: threads per block on each axis, each 1..4096, product 1..4096
kernel only: 1subgroup: 0 any, else the required subgroup width 4, 8, 16, 32, 64 or 128
4nblocks 1..65536, then the blocks

Block: nbparams u32 0..64, nbparams param type ids, nops u32 >= 1, then the ops (s7.1). Block 0 (the entry) has no parameters and is never a branch target. Every other block has at least one parameter, and its parameter 0 has type tok (s6.4); no other parameter is tok.

Any function may call any non-kernel function, including itself and later ones. A kernel's result is void; a kernel calls no function and no function calls a kernel except through launch (s7.7).

Callback function (flags bit 1). At most one function of a unit, of kind 0, with exactly six u64 parameters and result u64. It is the function library code calls back in a Mach-O program (s7.11, library words; seed/ng/a64/DESIGN.md s14); to every other consumer it is an ordinary function. Any other kind or signature, or a second such function, is FIELD (13) at the function record.

Program entry (D11). A unit is a program: exactly one function has kind 2 (export), no parameters and result i32. It is the process entry (Omega fn main to int), and its result is the exit status. Other exports (with parameters or another result) are entries a host calls in function mode. A unit with no such function, or with several, is refused ENTRY (exit 30).

6.2 Values (SSA)

Every value is defined exactly once. Value ids are implicit, never stored. In each function: value 0 is the entry token (type tok), values 1 .. nparams are the parameters, then, block by block in order, each block's parameters, then each op's definitions in op order. A token op (s6.4) defines its new token first and then its result if ty != 0; any other op defines one value when ty != 0 and none otherwise (checks and facts take ty as a parameter and define only the token or nothing, s7.1). A use names a value id.

6.3 Kernels (one form for CPU and GPU)

A kernel describes the work of one thread; a launch runs it over a grid of blocks of tx*ty*tz threads. The same kernel IR is lowered by src/a64.om (threads as loops and NEON lanes) and by src/gpu.om (threads as sm_121 threads). subgroup is what the kernel requires; the target offers its own width in its descriptor, and the backend refuses a mismatch (omega-mv#883 E3 s1). Shared memory budget, nesting depth, thread maximum and feature set are target-descriptor checks done by the backend, not by ngcheck. The race, divergence and sync rules of docs/omegese/GPU.md (s6, s8 on c1/chip-fix) are kernel-checker obligations of the GPU lane (M5); ngcheck checks the structural rules of s9.

6.4 The ordering token (D2c)

At every point of a block there is exactly one current token: value 0 at the start of block 0, parameter 0 at the start of any other block. Ops are of three token classes (the tk column of s7.12):

classopsrule
E effectevery chk.*, store fstore vstore fill atom atomcas mmast alloca sync call launch host, and the pool ops pool.grow pool.store pool.read pool.writeoperand 0 is the current token; the op defines a new token, which becomes current
R readerload fload vload mmald slice, and the pool ops pool.len pool.loadoperand 0 is a token defined in this block at or before the current one, or one that dominates the block (the memory state it reads; s8 bounds which)
T terminatorbr cbr ret retv trap exitoperand 0 of br's arguments, and operand 0 of the others, is the current token

All other ops take no token. A token value is used only as operand 0 of an E, R or T op (TOKEN, exit 28, otherwise; also when an E or T op names a token that is not current). The token is linear for E and T ops: on every path each token is consumed by exactly one E or T op (the one right after it on the chain), because only the current token may be consumed and consuming it replaces it. So the tokens of a function form one chain along every path, and every check, every observable effect and every exit sits at a fixed place on it: a check cannot pass a store, a host word, a call, a trap or another check without a rewrite that the validator sees. Reader ops (R) read the chain without consuming it, so loads are not linear: an optimizer may give a load an older token when it proves no store between the two writes the loaded element, and s8 rule 3 forbids an older token than the check that covers it, so a load is never hoisted above its bounds check. ngcheck checks the structural rule and s8, not alias proofs.

In the operand lists of s7 the token operand is not repeated: for E and R ops it is the first operand on the wire, before the listed ones.

7. Ops

7.1 Encoding of an op

bytesfield
1op (s7.2 onward)
4ty: the result type id, 0 when the op has no result; for chk.conv the destination type (s7.9)
8imm, present only when the row has an imm column; 0 when its meaning says unused
4n, present only for variadic rows (br, call, host, launch)
4 eachoperands: the token (E, R and T ops except br), the row's fixed operands, then n variadic operands

Operand kinds: b block id (br operand 0, cbr operands 2 and 3), f function id (call operand 1, launch operand 1); every other operand is a value id. Every ty, imm and operand is checked against its row: a value outside the row's types is TYPE. The full row table, with the field layout every reader uses, is s7.12.

Terminators are br cbr ret retv trap exit (and nothing else). Each block ends with exactly one terminator, and no terminator appears before its end (UNTERMINATED).

Notation in the tables: T the result type; operand types in parentheses; same means the same type id as T; the token operand is not listed (s6.4).

7.2 Constants and selection (1..9)

opnametyimmoperandsmeaning
1constnumbits-the value of type T whose bits are imm (canonical form below)
2selectany value type-c (bool), a, b (same)a if c else b

Canonical const imm: bool 0 or 1; unsigned ints zero-extended (high bits 0); signed ints sign-extended two's complement of the width; f32, f16, bf16, fp8 in the low 16/8/32 bits with the rest 0; f64 all 64 bits. Any other imm is NONCANONICAL. Vectors are built with vsplat/vinsert.

7.3 Arithmetic, bitwise, comparison (10..39)

All operate on a scalar or on a VEC (lane by lane); the operands have type T unless stated.

opnametypesmeaning (total)
10addarithint: modulo 2^w. float: IEEE, round to nearest even
11subarithas add
12mularithas add
13divarithint: toward zero; divisor 0 gives 0; signed MIN / -1 gives MIN. float: IEEE
14remintsign of the dividend; divisor 0 gives 0; MIN rem -1 gives 0
15negarith (1 operand)int: 0 - a modulo 2^w. float: flip the sign bit only
16andbool, intbitwise (bool: logical)
17orbool, intas and
18xorbool, intas and
19notbool, int (1 operand)bitwise complement (bool: logical)
20shlintamount b taken modulo w; bits shifted out are lost
21shrintamount modulo w; arithmetic for signed, logical for unsigned
22rotlunsigned intamount modulo w
23rotrunsigned intamount modulo w
24minarithint: by signedness. float: IEEE minNum as Omega fmin (AArch64 FMINNM): one quiet NaN gives the other operand; a signaling NaN in either operand gives a quiet NaN; two NaNs give a quiet NaN; min(-0, +0) and min(+0, -0) are -0
25maxarithfloat: as min, maximum (FMAXNM); max(-0, +0) and max(+0, -0) are +0
26fsqrtfloat (1 operand)IEEE square root, correctly rounded
27fabsfloat (1 operand)clear the sign bit
28fmathfloat (1 operand), immtranscendental with accuracy class, below
30..35eq ne lt le gt geoperands int, bool (eq, ne only) or float; ty bool, or VEC of bool with the operands' lanesint by signedness; float IEEE ordered: any NaN gives false except ne
36convty num; operand num of another type; immnumeric conversion, below
37bitcastty and operand of equal bit widthreinterpret bits (one-layer-format s10.2 sets, extended to f16/bf16 with u16/i16 and fp8 with u8/i8)

Float min/max (contract correction 2026-11-10, NgIrOracle head 2): the earlier draft rule "a NaN operand gives the other" did not match the language. OMEGESE s9.9 defines fmin/fmax as FMINNM/FMAXNM and the seeded compiler measures so: fmin(sNaN, 1.0f32) is the quiet NaN 0x7fc00001; fmin(qNaN, 1.0) is 1.0; signed zeros as in the rows above. The quiet NaN's payload is unspecified, like every arithmetic NaN. x86-64 back ends: MINSS/MAXSS do not implement this rule (they return the second operand for any NaN and do not order signed zeros); they need an explicit NaN and zero sequence.

Float arithmetic never contracts separate ops into a fused op; only fma is fused. A NaN produced by arithmetic may have any quiet-NaN payload; const, memory ops, select, bitcast, neg and fabs preserve every bit (one-layer-format s10.3). f16 and bf16 arithmetic rounds each op to the type. fp8 types are refused by every op of this section except conv and bitcast.

fmath imm: bits 0..7 function (0 exp, 1 exp2, 2 log2, 3 inv (1/x), 4 rsq (1/sqrt x), 5 sin, 6 cos, 7 tanh); bits 8..15 accuracy class (0 CR correctly rounded, 1 ULP(n), 2 FAST target-stated bound); bits 16..23 n for ULP (1..255, else 0); bit 24 denormal inputs and outputs may flush to zero (0 = kept); other bits 0. The class is what the program requires; a backend that cannot meet it refuses (omega-mv#883 E3 s4). Omegese GPU exp/inv/root lower to class FAST with bit 24.

conv imm: bits 0..1 rounding for a float destination (0 nearest even, 1 toward zero), bit 2 saturate to the largest finite value instead of infinity (float destinations only); other bits 0; an int destination requires imm 0. Rules (one-layer-format s10.3): int to int keeps the low w bits of the source value (sign- or zero-extended first by the source's signedness), so it never traps; chk.conv (s7.9) gives Omega's trap 5. int to float rounds per imm. float to int truncates toward zero and saturates to the destination range; NaN gives 0. float to float rounds per imm. bool is not a conv operand or result: compare instead.

7.4 Fused multiply-add (46)

opnametyoperandsmeaning
46fmafloat or VEC of floata, b, c (same)a x b + c rounded once (OSC v8 MAD, number kept)

7.5 Memory (42, 43, 47, 48, 50..59)

r is a REF or SLICE; i an index of type u32 or u64, counted in elements of the target array or slice. All accesses are covered (s8). Opcode numbers 42, 43, 47 keep OSC v8's GLOAD, GSTORE and ATOM, generalized to every space.

opnametyimmoperandsmeaning
42loadelement type-r, ielement i
43store0-r (access 1), i, v (element type)element i = v
47atomelement type (u32, i32, u64, i64, f32)op, scope, orderr (access 1), i, vatomic read-modify-write; result is the old value
48atomcaselement typescope, orderr (access 1), i, expect, newif element i == expect then store new; result is the old value
50allocaREF (access 1, space 0 or 4) to ARRAY or STRUCT--fresh zero-filled storage for this invocation; entry block only
51fill0-r (access 1, ARRAY or SLICE), v (element)every element = v
52gaddrREF to the global's type, space 0global id-the global's storage
53lenu64-r (ARRAY REF or SLICE)element count
54sliceSLICE (same elem and space, access <= r's)-r, off (u64), n (u64)elements off .. off+n-1; covered by a chk.slice or fact.slice on (r, off, n)
55floadthe field's scalar typefield indexr (REF to STRUCT)the field
56fstore0field indexr (access 1), vthe field = v
57frefREF to the field's ARRAY or STRUCT, same access and spacefield indexr (REF to STRUCT)the sub-object
58vloadVEC (lanes L of the element type)-r, ielements i .. i+L-1
59vstore0-r (access 1), i, v (VEC)elements i .. i+L-1 = v

atom imm: bits 0..7 op (0 add, 1 min, 2 max, 3 and, 4 or, 5 xor, 6 exch); bits 8..15 scope (0 subgroup, 1 block, 2 device, 3 system); bits 16..23 order (0 relaxed, 1 acquire-release); others

  1. atomcas uses bits 8..23 the same way, bits 0..7 are 0. Integer add wraps; float add rounds to nearest even. In a function (not a kernel) the only thread is the caller, so an atomic is its plain read-modify-write.

STRUCT elements are storage-only (v1). An ARRAY or SLICE may have STRUCT elements (s4.2), and alloca, gaddr, len and slice take such storage, but no value is ever a STRUCT or an ARRAY (value types are scalar, VEC, REF, SLICE or FRAG). So load, store, atom, atomcas, fill, vload and vstore need a scalar (or, for load/store, VEC) element and refuse a STRUCT element with TYPE at the op, and no op yields a REF to one element. Fields are reached only through a REF to the STRUCT itself (gaddr, alloca, or fref of an enclosing STRUCT) with fload, fstore and fref; per-record data is laid out as a STRUCT of ARRAY fields: fref to the field's ARRAY, then load/store element i under its chk.bounds. Omega has no arrays of structs (a struct is one new object), so the front end needs no other route; an element-reference op is a later extension. Fixtures: r-struct-elem.oir (TYPE), k-soa.oir (accepted).

7.6 Control (60..66)

opnametyimmoperandsmeaning
60br0-b, then n valuesjump to b; the n values (n = b's parameter count, same types in order; value 0 of them is the current token) become its parameters (BLOCK_ARITY)
61cbr0-c (bool), bt, bfjump to bt if c else bf, passing the current token; bt and bf have exactly one parameter, the token (BLOCK_ARITY)
62ret0--return from a void function or kernel
63retv0-v (the function's result type)return v
64callthe callee's result-f, then n argumentscall f (any non-kernel function; n and types equal f's parameters)
65trap0code 1..14-trap with code (Omega trap N, exit 100+code)
66exit0-v (i32)end the process with status v (Omega exit); functions and exports only

trap in a kernel ends the thread (kernel traps below).

7.7 Kernel ops (40, 41, 44, 45, 67)

opnametyimmoperandsmeaning
40gpu.idu32which-0 thread.x, 1 block.x, 2 blocks.x, 3 block.y, 4 blocks.y (OSC v8 THREAD, BLOCK, BLOCKS, BATCH, BATCHES), 5 thread.y, 6 thread.z, 7 block.z, 8 blocks.z, 9 lane in subgroup, 10 subgroup index in block
41sharedREF (access 1, space 2) to ARRAY--block-shared storage, zero at kernel start; kernel entry block only
44sync0--block barrier
45shflu32, i32, f32 (or u64, i64, f64)modev (same), d (u32)mode 1 DOWN, 2 UP, 3 XOR, 4 IDX (E3 numbers); d must be a const: 1..127 for DOWN/UP, 0..127 for XOR/IDX, and below subgroup when the kernel declares one. A source lane outside the subgroup gives the caller's own v
67launch0-f (a kernel), gx, gy, gz (u32), then n argumentsrun kernel f on a grid of gx x gy x gz blocks and wait; functions and exports only

gpu.id, shared, sync and shfl appear only in kernels; launch and exit only outside them (EFFECT).

Kernel traps (D10). The trap state of a launch is one sticky code. A thread that fails a check or reaches trap records its code (only its first; later checks of that thread record nothing). When the launch ends, if any thread recorded a code, launch traps in the caller with the code of the trapping thread with the lowest linear id: block linear id first, then thread linear id, that is ((block.z x blocks.y + block.y) x blocks.x + block.x) x (tx x ty x tz) + (thread.z x ty + thread.y) x tx + thread.x. This is the code a sequential lowering that runs threads in linear order reports, so src/a64.om and src/gpu.om agree. Kernel stores and atomics are unordered relative to traps: after a trapping launch every location the kernel could write has an unspecified value. Obligation on every back end: a trap never strands threads at a barrier. A trapped thread still arrives at every sync it would reach (one way: it keeps running with its stores and atomics suppressed and its loads reading 0, every loop being fuel-bounded; another: the barrier counts it as arrived); src/gpu.om states which mechanism it uses. Without a trap the launch returns normally and every kernel write is visible to the caller after launch. Inside a kernel the token orders a thread's own checks and effects; it orders nothing between threads (only sync and atomics do).

src/gpu.om (ng-gpu, PROPOSED, ~/handoffs/hive-ng/gpu/IR-GPU-DRAFT.md) takes the second way: a trapping thread does a device-scope 64-bit unsigned atomic min of (linear id << 4) | code into one per-launch trap word (initialised to all ones, CPU-visible and uncached) and exits; the host reads the word after the launch, so the lowest linear id wins as above. Exited threads release barriers (PTX ISA 9.4, exit; that BAR.SYNC on GB10 does the same is untested until ng-gpu's chip check). Its target-descriptor limits: fewer than 2^60 threads per launch, and an encoder with a 64-bit atomic min.

7.8 Vectors and tiles (100..106)

opnametyimmoperandsmeaning
100vsplatVEC-s (element)every lane = s
101vextractelementlanev (VEC)lane imm (< lanes)
102vinsertVEClanev (same), s (element)v with lane imm = s
103vreduceelementopv (VEC)op 0 add, 1 min, 2 max, 3 and, 4 or, 5 xor. Pairwise order: lanes [0, L/2) combine with [L/2, L) lane by lane, repeated until one lane
104mmaldFRAG (role 0, 1 or 2)layoutr, i, ld (u64), e (u64)load a tile from r: element (row, col) at i + row x ld + col for layout 0 (row-major), i + col x ld + row for layout 1; positions at or past i + e read as 0
105mmast0layoutr (access 1), i, ld, e, d (FRAG role 2)store a tile, positions at or past i + e not written
106mmaFRAG role 2classa (role 0), b (role 1), c (role 2) with equal m, n, kD = A x B + C. class 0: the reference, for each (row, col) c then k = 0 .. K-1 in order, each step one fma in D's element type; class 2 FAST: a target-stated bound, never compared bit for bit

FRAG values are cooperative over one subgroup and appear only in kernels (EFFECT outside). Their register layout is the backend's; ΩIR reaches them only through mmald, mmast and mma.

7.9 Checks (70..82): the only ops that trap

A check is an E op (s6.4): it reads the current token and defines the next one, and defines no other value. Its imm is the trap code, which must equal the code in the row (CHECK_CODE); only chk.true takes any code 1..14. Code 0 is always CHECK_CODE. On failure the program traps with that code (exit 100 + code) and no later effect on the token chain happens; on success nothing happens. Operands have the type the row names.

opnamety parameteroperandscodefails when
70chk.add0a, b (int, equal)1the exact a + b is outside the type
71chk.sub0a, b1the exact a - b is outside the type
72chk.mul0a, b1the exact a x b is outside the type
73chk.neg0a1the exact -a is outside the type
74chk.divz0b (int)2b = 0
75chk.divovf0a, b (signed int)1a = MIN and b = -1 (div only; rem does not trap)
76chk.shl0a, b (signed int)1the exact a x 2^b is outside the type (b already in range)
77chk.shift0b (int)7b < 0 or b >= the width of b's type (Omega rotates: amount and value share a type; an Omega shift whose amount has another integer type reaches it after conv to u64, lt the width, chk.true 7 and conv: seed/ng/front/README.md)
78chk.convthe destination type (int)v (int or float)5v (truncated toward zero, if float) is NaN or outside the destination
79chk.bounds0r, i, e (u64)3i + e > len r (exact, no wrap) or e = 0
80chk.slice0r, off (u64), n (u64)3off > len r or n > len r - off
81chk.fuel0k (u64), m (u64)4k >= m (a loop about to run its (k+1)-th pass with bound m)
82chk.true0c (bool)any 1..14c is false (contracts: 9 requires, 10 ensures, invariant, holds)

For unsigned operands chk.add/sub/mul/neg fail on any wrap; Omega functions wrap unsigned values and never emit them, Omegese kernels trap on u32 overflow and do.

chk.fuel order: the front end emits a while loop the way omc runs it (seed/omc/omc.om 9469-9505, note at 9470-9471): at the loop head the condition is evaluated first; when it is false the loop exits without a fuel check; when it is true chk.fuel 4 k N runs (k = passes completed), then k + 1, then the body. So a loop that runs zero times never traps 4, and a loop whose condition is still true after exactly N passes traps 4.

Trap 6 (stack) is not a check op: call and alloca may trap 6 when the back end's stack is exhausted, before any effect of the callee or allocation. NG frames differ in size from omc's, so the differential gate compares trap 6 only when both compilers trap 6, and records stack-depth cases as BEYOND_OMC (D9).

7.10 Facts (90..93): non-executing

A fact has no result, no token and no run-time effect. It states a property that holds whenever control reaches it; consumers (passes, back ends) may rely on it. imm is the origin. D2c gives a fact authority only through a check or a proof:

Other origin values are NONCANONICAL.

opnameoperandsstates
90fact.truec (bool)c is true
91fact.rangev (int), lo, hi (same type, each defined by const, lo <= hi)lo <= v <= hi
92fact.inboundsr, i, e (u64)i + e <= len r and e >= 1
93fact.slicer, off, n (u64)off <= len r and n <= len r - off

7.11 Effects (110): host words

opnametyimmoperandsmeaning
110hosti64, or 0 for class cpuword idn argumentsthe Omega host word with that keyword id; result as OMEGESE s10: a count or minus the Linux errno

imm is the keyword id of the pinned seed/omc/omc.om keyword lookup (read 53, write 54, fclose 100 through vfioirq 232, execenv 233, prlimit 235 and the scheduler words cpuset 236 through getprio 240; exit, const, qty, fma and the x86efi word efi are not host words). The normative table is seed/ng/hostwords.tsv (columns id word args class, 99 rows, extracted from OMEGESE s10, seed/host/MAPPING.md and the typing code of seed/omc/omc.om at the pin); ngcheck --table prints the table it compiles in and the gate requires those bytes to equal the file. Argument letters, one per source argument:

letteroperandstype
i1i32
l1i64
L1u64
u1u32, defined by a const (Omega requires a literal request number)
r3: A, off, nA a u8 SLICE or REF to a u8 ARRAY, any access; off, n u64
w3: A, off, nas r, access 1
S3: A, off, nvfioctl only: as w, except as r when the preceding u request is 15210 (omc.om 7610, 7660)

Every slice is covered by chk.slice/fact.slice on the same three values (s8). The words of class cpu (cpufence, cpurelax) have no result (ty 0); every other word has ty i64. host appears only in functions and exports (EFFECT). Host effects happen in program order; an optimizer never reorders, duplicates or removes a host op.

Reference interpreter host policy. ngrun FILE.ir [STEPS] [--scratch NEW-DIR] [-- ARGS...] executes only host words whose effects are deterministic or confined, so a differential test can compare stdout and exit status with a native run. argcnt and argread see FILE.ir as argument 0 and the ARGS after -- as arguments 1.., so the count equals that of a native program given the same ARGS; envcnt/envread read ngrun's own environment. monons, realns, getuid, geteuid, getgid, getegid, cpufence and cpurelax execute natively; IR.md defines no fixed-value clock mode, so clock results are live and a test may compare only their sign. sleepns 0 executes; a negative interval traps 3 as the native word does; any other interval is refused as nondeterministic. File words run only with --scratch: ngrun creates NEW-DIR (mode 0700; it must not exist), opens it with O_DIRECTORY|O_NOFOLLOW and makes it the working directory. A path over 4095 bytes or holding a zero byte, and a renames or link packet that is malformed (count other than 2, a record past the end, trailing bytes, an empty record, a zero byte), an empty stat, lstat or readlnk path, and a stat, lstat or fstat output under 128 bytes, trap 3 as the native word does, before any check below and with or without --scratch. Every path must then be one nonempty component (no /, not . or ..); renames and link packets must hold exactly two such names. Opens add O_NOFOLLOW, and chdir opens the name with O_PATH|O_DIRECTORY|O_NOFOLLOW and changes directory with fchdir, so neither follows a final link. stat, chmod, chown, truncate and faccess, which follow a final link natively, open the name with O_PATH|O_NOFOLLOW, return -40 (ELOOP) when it is a link, and otherwise act on /proc/self/fd/N, the inode that open found; the kernel's EINVAL checks that precede the lookup (faccess mode outside 0..7, truncate length below 0) come first. So a link another process plants in NEW-DIR while ngrun runs is never followed. The interpreted program cannot create a link itself (symlnk is refused), so a native run and ngrun agree on every result. Descriptors are virtual: stdin (0) may be read and stdout/stderr (1, 2) written, and fclose may close any of the three, as a native program may; every other operation needs a descriptor created by an interpreted fopen or memfd. memfd names no path and runs without --scratch. A refused word prints ngrun: refused host class C word W at OFFSET on stderr and exits C before any effect. A word refused below whose native form traps 3 on its operands before any kernel call traps 3 first, as natively: waitio events outside 0..65535, a peercred output under 12 bytes, a pollfds length that is not a multiple of 8 or is over 8192, a waitpid output under 4 bytes, a pipefds output under 8 bytes, and an execprog, execpure, execenv or symlnk packet that breaks the packed-list rules of OMEGESE s10 (an exec argument packet, that of execprog, execpure or the first of execenv, is 2..65536 bytes with count 1..1024, as the pinned omc 564c5835 lowers it; a symlnk packet and the execenv environment 2..4096 bytes with count 1..64; records inside the packet, no trailing bytes, no zero byte; a nonempty first record for the exec words, exactly two nonempty records for symlnk, every execenv environment record nonempty). The device class (117) is refused without this check: its native trap conditions (mapping-table and device-descriptor checks) are not mirrored, so a device word with such operands exits 117 where a native run traps 3.

exitclasswords
115processfork dupfd waitpid execprog execpure execenv killpid pipefds getpid getppid setsid getpgid setpgid getsid cpuset cpuget setprio getprio
116limitsprlimit
117devicedevctl mapnew mapdrop mapread mapwrite devcall uvmctl mapaddr mapget mapset maphold mapbind vfioctl vfiomap vfiomapw eventfd vfioirq libfn libptr libcall
118networksocknew listen accept connect bind recv send waitio sockname sockopt shutdown peercred pollfds sendmsg peername
119outside scratchany path or descriptor word without --scratch, an absolute or multi-component path, ./.., a descriptor ngrun did not create (including pread/pwrite on 0..2)
120nondeterministicrandom, sleepns with a positive interval, cpunow
121unsafe filesystemsymlnk, syncfs, a blocking or shared-wait flock
122unclassifieda host word id with no row here (unreachable for accepted units)
123descriptor tablemore than 256 live virtual descriptors

These exits sit above the trap range 101..114 and below 124 (step limit), 125 (unsupported op) and 126 (access outside storage). They describe the reference interpreter, not program semantics: native code may execute every word.

Library words (class lib, ng only). hostwords.tsv is the table of omc's words and stays that: the gate audits it against the pinned omc source. ng's own words have their own table, seed/ng/hostwords-ng.tsv (same columns, 3 rows), which ngcheck compiles in after the first (--table prints the first only). In a unit whose first line is target macos the front end reads these three more keywords, and gives the function named libback (six ulong parameters, result ulong) flags bit 1: with it, libfn k for k 2..17 is the address of callback entry k - 2, a C function that runs libback(k - 2, x0, x1, x2, x3, x4) and returns its result; in every other unit they are ordinary names, as omc reads them (omc refuses target macos, error 25). They are the one gateway from an Omega program to code outside it, and only the Mach-O target has them (@ng a64 refuses each: a64: unsupported 241..243, exit 5; ngrun refuses them as class 117). Their value is the raw 64-bit result, not a count or an errno.

idwordvalue
241libfn kthe address of dlopen (k = 0) or dlsym (k = 1), bound by dyld when the program starts; 0 for any other k
242libptr A off nthe address of byte off of the writable byte slice (checked like every slice)
243libcall F A off ncalls the function at address F with the C calling convention. The slice is the register file, at least 128 bytes: x0..x7 from bytes 0..63 and d0..d7 from bytes 64..127, little-endian. After the call x0 and x1 are written back at 0 and 8, d0..d3 at 64..95, and the value is x0. A slice of fewer than 128 bytes, or F = 0, traps 3 before anything is called

What the called function does is outside the language: a wrong address, a wrong argument or a function that writes through a pointer it was given is not caught. a64/DESIGN.md s13 has the lowering.

Scheduler host words. The affinity and priority words cpuset 236, cpuget 237, cpunow 238, setprio 239 and getprio 240 are on Radicle main (c106bae0, omc f4fa7951; OMEGESE s10 rows 1071-1075). Their rows are in hostwords.tsv with class sched (not cpu: each has an i64 result), and ngrun refuses them by class: cpuset, cpuget, setprio and getprio as 115 process (they read or change scheduling state of the process), cpunow as 120 nondeterministic (the CPU a thread runs on may change between calls).

7.12 Row table (the layout every reader uses)

tk: token class (s6.4): P none, E effect, R reader, T terminator. imm: y when the op carries the 8-byte imm. fix: fixed operands after the token. var: y when a u32 n and n more operands follow. ty: r a result type (nonzero), o optional result (0 = none), p a parameter (no result value), 0 always 0.

opnametkimmfixvarty
1constPy0-r
2selectP-3-r
10..14, 16..18, 20..25add sub mul div rem and or xor shl shr rotl rotr min maxP-2-r
15, 19, 26, 27neg not fsqrt fabsP-1-r
28fmathPy1-r
30..35eq ne lt le gt geP-2-r
36convPy1-r
37bitcastP-1-r
40gpu.idPy0-r
41sharedP-0-r
42loadR-2-r
43storeE-3-0
44syncE-0-0
45shflPy2-r
46fmaP-3-r
47atomEy3-r
48atomcasEy4-r
50allocaE-0-r
51fillE-2-0
52gaddrPy0-r
53lenP-1-r
54sliceR-3-r
55floadRy1-r
56fstoreEy2-0
57frefPy1-r
58vloadR-2-r
59vstoreE-3-0
60brT-1y0
61cbrT-3-0
62retT-0-0
63retvT-1-0
64callE-1yo
65trapTy0-0
66exitT-1-0
67launchE-4y0
70, 71, 72, 75, 76, 81chk.add chk.sub chk.mul chk.divovf chk.shl chk.fuelEy2-0
73, 74, 77, 82chk.neg chk.divz chk.shift chk.trueEy1-0
78chk.convEy1-p
79, 80chk.bounds chk.sliceEy3-0
90fact.truePy1-0
91, 92, 93fact.range fact.inbounds fact.slicePy3-0
100vsplatP-1-r
101vextractPy1-r
102vinsertPy2-r
103vreducePy1-r
104mmaldRy4-r
105mmastEy5-0
106mmaPy3-r
110hostEy0yo
111pool.growEy1-r
112pool.lenRy0-r
113pool.loadRy1-r
114pool.storeEy2-0
115, 116pool.read pool.writeEy3-r

For the pool rows (111..116) the imm is the pool's global id, written on the wire exactly as the gaddr imm is (the in-memory form holds the handle, the writer subtracts 1, the reader adds 1; s14).

Every op byte not in the table is UNKNOWN_OP. shfl, mma, mmald, mmast and sync are convergent: an optimizer never moves them into or out of a branch, and never duplicates them.

7.13 Run-time pool ops (111..116)

Each op names its pool by the global id in imm (a class 2 global, s5); none takes a pool, a REF or a SLICE as an operand and none returns one. Every op is self-contained and checked: the bounds test is part of the op, so none needs a chk.bounds, chk.slice or fact, and none is an access op of s8. The current length and base are read from the pool's descriptor when the op executes, after every operand has been evaluated, so storage that moved while an operand was being computed (a call inside an operand that grew the pool) is never used stale. u64 is type id 5, i64 type id 9, i32 type id 8.

opnametyimmoperands (after the token)meaning
111pool.growi64pool idn (u64)E. Make the pool at least n elements. Result 0: grown, or n <= length (no shrink); new elements are zero, old ones kept. -22: n times the element size is 2^63 bytes or more; the pool is unchanged. -12: the host refused (or, in ngrun, the 16 MiB budget would be exceeded); the pool is unchanged. Advances the token.
112pool.lenu64pool id-R. The current element count. Reads the token, does not advance it.
113pool.loadthe pool's element typepool idi (u64)R. Element i. Trap 3 (exit 103) if i is at or past the current length.
114pool.store0pool idi (u64), v (element type)E. Element i = v. Index and value are both evaluated, then the descriptor is resolved, then the bound is checked; trap 3 (exit 103) before any store when i is at or past the length. Advances the token.
115pool.readi64pool idfd (i32), off (u64), n (u64)E. Host read of n bytes from fd into bytes off .. off+n-1 of the pool. Trap 3 (exit 103) unless off <= length and n <= length - off. Result: the byte count, or minus the Linux errno. Advances the token.
116pool.writei64pool idfd (i32), off (u64), n (u64)E. As pool.read, writing those bytes to fd.

Rules ngcheck enforces (exit classes of s11, from ck_tpool and ck_place): the id must name a global (REF 24) of class 2 (TYPE 16); pool.len has type u64; pool.grow type i64 with a u64 operand; pool.load the element type with a u64 index; pool.store a u64 index and an element-typed value; pool.read and pool.write type i64, an i32 descriptor, u64 offset and count, and a u8 pool (TYPE 16 for any other element type). Pool ops are refused in a kernel (EFFECT 22). A gaddr of a class 2 global is TYPE 16. A class 2 global whose type is not one of the ten native scalars is TYPE 16; a class above 2 is NONCANONICAL 13.

Order and meaning of pool.grow results, taken from the implementations:

7.13.1 Text and wire

Text: global @gN ELEMENT pool (class 2; ELEMENT is the built-in scalar name, for example u32), and for the ops the imm prints as @gN right after the (optional) result type, as gaddr does:

global @g0 u32 pool
%2 %3 = pool.grow i64 @g0 %0 %1
%6 = pool.store @g0 %2 %4 %5
%7 = pool.load u32 @g0 %6 %4

(See the complete fixture tests/ir/x-pool.oir.) ngas reads the word pool as class 2 and takes the ops' imm as @gN; ngdis prints them back. The wire version byte (9) and the tag are not changed by this addition; a reader built before it refuses class 2 (NONCANONICAL) and ops 111..116 (UNKNOWN_OP).

7.13.2 Back ends and the reference interpreter

7.13.3 Regression coverage

gate-ir.om checks the x-pool* run pairs, malformed r*-pool-* inputs, byte/text round trips, and o-pool before and after optimization. Its pool mutants corrupt stored bytes, zero filling, and relocation of another pool. front/gate-front-ir.om compares the canonical source pool cases and pool-widths-order.om with omc. a64/rgate.om compares both register-save modes and exercises native bounds, descriptor-update and float-index mutants. Release receipts must bind the complete gate results to their source and compiler identities.

Pool I/O retains the interpreter's host policy (s7.11), including descriptor ownership restrictions. A refused pool read/write names host word 53/54 in the existing diagnostic.

8. Coverage (the memory safety rule)

An access op A with token operand t is covered by a check or fact op C when

  1. C has the operands the table names (same SSA ids), and
  2. C dominates A (earlier in the same block, or in a block that dominates A's block), and
  3. when C is a check, its defined token is t or dominates t on the chain (so A reads memory only after C has run; a fact has no token and needs only 2).
accesscovered by chk.bounds or fact.inbounds onwith e
load, store, atom, atomcas(r, i, e)e defined by a const >= 1
vload, vstore(r, i, e)e defined by a const >= the lanes
mmald, mmast(r, i, e)e is the op's own e operand
slice, each host slicechk.slice or fact.slice on (r, off, n)-

fload, fstore and fref need no coverage: the field lies inside the STRUCT by the type table. A REF obtained from gaddr, alloca, shared or fref is still covered this way: the check is explicit even when the bound is a constant, and a pass replaces a proven check by a fact (s15). An uncovered access is UNCHECKED.

The pool ops (s7.13) are the one family outside this table: each carries its own bounds test against the pool's current length, so they need no chk.* or fact and ngcheck demands none. A pool has no REF, so a check on a pool can never be separated from its access by a growth that moves the storage.

9. Structural rules ngcheck enforces

  1. Every id names an existing object of the right kind: type, global, function, block, value (REF).
  2. Types per row (TYPE); writes need access 1; CONSTANT space is read-only; tok only where s4.1 allows it.
  3. Block 0 has no parameters (BLOCK_ARITY, at the block's offset) and is not a branch target (REF); other blocks start with one tok parameter (BLOCK_ARITY). alloca and shared only in block 0 (EFFECT).
  4. Every block reachable; SSA dominance (s6.2).
  5. Terminators (s7.1); br arity and types; cbr targets with exactly the token parameter.
  6. retv only in non-void functions with the result type; ret only in void ones.
  7. Kernel ops (gpu.id shared sync shfl mmald mmast mma and FRAG values) only in kernels; host, exit, launch and call only outside them; a kernel's result is void; launch's callee is a kernel and call's is not (EFFECT).
  8. The token chain (TOKEN, s6.4), check codes (CHECK_CODE), coverage (UNCHECKED), facts (FACT).
  9. Canonical fields (NONCANONICAL): reserved bits, const imm form, duplicate types, ty not 0 where the row says 0, flags, order of a non-scalar field, enumerations.
  10. Exactly one program entry (ENTRY, s6.1).

10. Canonical text form (D3)

ngdis prints, and ngas reads, exactly one text per unit. Byte-exact round trips are a gate: ngdis(ngas(t)) == t for every fixture text and ngas(ngdis(b)) == b for every assembled binary. ngas reads only canonical text: it refuses anything ngdis would not print (no comments, single spaces, no trailing spaces, every line ends with one LF, decimal numbers without leading zeros or +). ngas checks syntax and numbering only; semantic refusals are ngcheck's, so a fixture for any semantic class is canonical text. Example:

omegair 1
type %t32 = vec i32 4
type %t33 = array u8 64
type %t34 = struct 16 u64@0:le i32@8:be
type %t35 = ref edit host %t33
type %t36 = slice view host u8
type %t37 = frag a 16 8 16 f16
type %t38 = array u8 5
global @g0 %t33 zero
global @g1 %t38 data 68656c6c6f
fn @f0 flags 0 %1:i32 %2:i32 -> i32
block ^0
%3 = chk.add 1 %0 %1 %2
%4 = add i32 %1 %2
retv %3 %4
end
kernel @f1 flags 0 threads 256 1 1 subgroup 32 -> void
block ^0
%1 = gpu.id u32 0
ret %0
end
export @f2 flags 0 -> i32
block ^0
%1 = const i32 0
retv %0 %1
end

Ids are printed as stored, in range or not, so every semantic refusal has a text fixture. What the text cannot spell, ngdis refuses with the s11 code and ngdis: refused class C at OFFSET on stderr: MAGIC, VERSION, TRUNCATED, TRAILING, UNKNOWN_OP, LIMIT (below), IO, and NONCANONICAL for an enumeration outside its set (type kind, access, space, field order, frag role, global class, function kind), a nonzero ty on a row whose ty column is 0, or a const imm that is not canonical for its scalar type. Its text is complete only on exit 0: a refusal found before 1 MiB of text leaves stdout empty, one found later leaves the text already written. ngas refuses non-canonical text with ngas: syntax error at line N and exit 3 (out of order or misnumbered type, global, function, block or value ids; the wrong number of defined values for the row and ty; a fixed-operand count that differs from the row; a const outside its type; a global's data length), input or output over 16 MiB with exit 23, unreadable input with exit 27.

Text tool capacities. Both text tools hold what the text can spell, so their limits are the table sizes, not ngcheck's semantic limits: input over 16777216 bytes is LIMIT (ngdis reads one byte past the buffer: more input is ngdis: refused class 23 at 16777216, a read error class 27 at the bytes read); more than 65536 types, globals, functions, blocks in one function, or parameters of one function or block is LIMIT, ngdis: refused class 23 at the count's offset, checked before the entries, and ngas: limit at line N (the line of the first item over) with exit 23. The parameter limit stays 65536 in the text tools so that ngcheck's 64-parameter LIMIT keeps a text fixture.

seed/ng/tests/ir/ holds the fixtures: canonical text (NAME.oir), and the cases file that seed/ng/gate-ir.om runs: text cases with their ngcheck class and offset, ngas syntax refusals, byte mutations of assembled fixtures for what text cannot spell (MAGIC, VERSION, TRUNCATED, NONCANONICAL, TRAILING, UNKNOWN_OP, counts over s12), each judged by ngcheck and ngdis alike and by ng ir-copy as s14 states, and inputs the gate generates at the capacities (16777216 bytes and one more, 65537 types, globals, functions, blocks and parameters). Run pairs (x-NAME.oir with x-NAME.om, the same program in Omega) are the D9 differential of this document's semantics: seed/ng/ngrun.om, the reference interpreter of s7, runs the ΩIR, omc compiles and runs the Omega, and exit status, stdout and stderr must be equal, traps at the exact boundaries included (overflow at 2^63, fuel at exactly 1e6 passes, index == len, MIN div -1, shift by the width, a conversion one past the range and one at the bottom of it, a signed shift left that reaches the minimum). What Omega cannot state (u64 checked add and mul, chk.bounds with e = 0, wrapping narrow neg, the trap 6 depth) the gate checks on ngrun alone (N cases). Random programs (seed/ng/ngrand.om, the D9 differential source for back ends): ngrand SEED writes a unit built with src/ir.om from a byte tape that SEED fills; every tape gives a unit ngcheck accepts (typed SSA, one token chain, checks with their codes, diamonds joined by block parameters, counted loops under chk.fuel, calls to lower helpers, i64 memory under chk.bounds, host write), and byte 0 is always the smallest choice, so ngrand shrink SEED STATUS OUT CMD... minimizes a unit by deleting and zeroing tape bytes while the predicate CMD exits STATUS. The gate runs seeds 1..1000 (ngcheck's whole ACCEPT line, ngas(ngdis(b)) == b, ngrun ends cleanly), one shrink with ngrun as the predicate, and a mutant ngrand that drops one token edge, which ngcheck must refuse TOKEN. ngrun has no second oracle on these units: a back end diffing against ngrun is the differential, and its disagreements judge both.

Reference-interpreter float checks. The supported scalar f32/f64 subset includes bitcast, nearest-even and toward-zero conversions (imm 0, 1, 4, 5 for float destinations), and fused FMA. Integer destinations still require imm 0: they already truncate toward zero and saturate; the former unsupported rounding-mode defect concerned float destinations, not float-to-int. Bitcasts retain the entire declared width, including the sign bit and NaN payload. FMA is one operation at the declared precision, not a widened or multiply-then-add evaluation.

The IR gate builds tests/ir/float-oracle.om with the pinned seeded omc and runs it natively. That independent executable emits a unit containing expected raw-bit checks computed with native omc bitcasts, conversions and FMA. It links the IR writer, never ngrun. For each float width it checks 18 signed special/boundary bit patterns (zeros, infinities, quiet and signaling NaNs with payloads, minimum and maximum subnormals, minimum normals and maximum finite values) and 1024 deterministic random patterns. It checks float-to-int for all eight integer widths, 16 probes at each destination's boundaries, integer-to-float in every defined mode at integer range and precision boundaries, and f64-to-f32 in every defined mode. The native toward-zero f64-to-f32 reference decodes the sign, exponent and significand as integers; it does not use ngrun's predecessor-of-nearest algorithm. A separate mutant removes that predecessor step. NaN conversions are compared by NaN classification; bitcasts and FMA compare raw bits. FMA includes three explicit witnesses and the same special/random sweep: two fused-versus-unfused cases and one f32 case (0x3f7ff001 * 0x33800800 + 1, exactly 1 + 2^-24 + 2^-60) where an f64 FMA narrowed to f32 double-rounds to 0x3f800000 instead of 0x3f800001. The oracle exits 3 unless native omc reproduces the exact Wolfram-checked bits of all three. The native oracle prints its measured check count and finite fused-versus-unfused difference count on stderr. tests/ir/intcv-oracle.om independently exercises all 16 unsigned-to-signed width pairs at eight boundary inputs each (128 native comparisons), including source MAX and MAX-1. Another 256 native comparisons check f32/f64 chk.conv at 16 boundary probes for each integer type, using an independent integer decoder of the float sign, exponent and significand rather than ngrun's float comparisons. It emits the IR before performing the equivalent checked native conversion, so its native exit is the expected IR exit (0 or trap 5). The gate compares exit, stdout and stderr. Sign-bit erasure, RTZ refusal, unfused f32 and f64 FMA, f32 FMA widened to f64 then narrowed, and the former unsigned-to-signed check each have a separately killed interpreter mutant. These are host semantic checks, not hardware qualification of either NG back end; the integer random-IR generator still has no second independent oracle.

11. Refusal classes and ngcheck exit codes

ngcheck reads binary ΩIR on stdin. Accept: exit 0 and one stdout line ACCEPT <sha256 hex> fns=N blocks=N ops=N. Refusal: no stdout, exit code below, and one stderr line ngcheck: <CLASS> at <byte offset> (offset of the field, op or record at fault, decimal). The first fault ends the run. Phase 1 reads the unit front to back and checks every rule that needs only the record at hand: header, type table and globals completely (a type-table or global fault is reported at its entry's offset), function and block headers, op rows and every count against s12 (at the count's offset); then the program entry (ENTRY: at the function count when there is none, at the second entry's record otherwise). Phase 2 checks each function in order: terminators (UNTERMINATED), branch targets and their arity (REF, BLOCK_ARITY), reachability (UNREACHABLE), then each op in block and op order: operand ids, definitions and the token (REF, USE_BEFORE_DEF, DOMINANCE, TOKEN), its ty against the row, placement (EFFECT), codes and origins (CHECK_CODE, NONCANONICAL), typing (TYPE, and BLOCK_ARITY for br argument types), then coverage and facts (UNCHECKED, FACT). Op faults are reported at the op's offset, block faults at the block's, function faults at the function record's.

exitclassmeaning
10MAGICfirst 7 bytes are not OSC1IR\0
11VERSIONversion byte is not 9, or the tag is not exact
12TRUNCATEDinput ends inside a field
13NONCANONICALa reserved bit or unused field nonzero, a duplicate type, a const imm not in canonical form, an enumeration outside its set
14TRAILINGbytes after the last function
15UNKNOWN_OPan op byte with no row
16TYPEan operand, result or parameter type breaks its row
17USE_BEFORE_DEFa value used before its definition in the same block, or an id past the function's values
18DOMINANCEa value used in a block its definition does not dominate
19BLOCK_ARITYbr arguments differ from the target's parameters; a cbr target with other than the token parameter; a non-entry block without its token parameter; an entry block (block 0) with parameters
20UNTERMINATEDa block without a terminator at its end, or a terminator before its end
21CHECK_CODEa check without its exact trap code, or trap/chk.true code outside 1..14
22EFFECTan op in a function kind or block that does not allow it (s9 rules 3 and 7), an unknown host word
23LIMITa count over s12
24REFan id names no object of its kind; a branch to block 0
25UNCHECKEDa memory access or slice without coverage (s8)
26UNREACHABLEa block not reachable from block 0
27IOstandard input could not be read
28TOKENa token used outside operand 0 of an E, R or T op, an E or T op not using the current token, a reader using a token after the current one
29FACTan origin 0 fact without its dominating check (s7.10)
30ENTRYno program entry, or more than one (s6.1, D11)

12. Limits (implementation limits of the v1 tools)

itemlimit
input bytes16777216
types65536
struct fields, whole module65536 (64 per struct)
globals65536 (class-1 data within the input limit)
functions65536
parameters (function, block)64
blocks per function65536; whole module 1048576
ops per function1048576; whole module 4194304
values per function2097152
call/host/launch arguments64

A count above its limit is LIMIT (exit 23) at the count's offset, checked before reading what it counts. ngcheck keeps every number of this table; the text tools use the capacities of s10 (65536 for every table, parameters included), which are never below them. src/ir.om (ng, ngrun, ngrand) keeps them too, but two (no-caps arena, 2026-11-11): its input is region 0 of the arena (ar_m, 128 MiB), so ng and ngrun read a payload of any size the arena holds (past that, LIMIT at the bytes read, with ng's ng-use record), and its globals and their data are arena regions, so ng reads and writes a module of more than 65536 globals (ngrun keeps its own 65536-entry address table: more is LIMIT at offset 0). The ΩIR builder (front-ir, ngrand, the oracles) refuses a table it would fill with `ng: refused class 23 (IR.md s12 table full while building) and exit 23, never an index past it (ir_lim`).

13. Mapping from Omega (for src/front.om)

t is the current token; each E op makes the next one.

OmegaΩIR
global P T * (run-time pool)a class 2 global of element type T (s5); the front end gives it a private name kind and never a REF
len Ppool.len
get P ithe index is evaluated, then pool.load (its own bound test, trap 3)
put P i vindex, then value, then pool.store; the descriptor is read after both
r = enlarge P nn (u64) evaluated, then pool.grow; its i64 result is r
read fd P off n, write fd P off npool.read, pool.write (u8 pools only), no separate chk.slice
signed add x yt1 = chk.add 1 t x y, then add
div a b signedchk.divz 2 b, chk.divovf 1 a b, then div
rem a bchk.divz 2 b, rem
shl a b signedchk.shift 7 b, chk.shl 1 a b, shl
uchar x (narrowing)chk.conv u8 5 x, conv u8 x
get A ichk.bounds 3 A i e1 (e1 a const u64 1), then load reading the new token
while c bound Nheader block with counter k; evaluate c; on true chk.fuel 4 k N then the body (the condition before the fuel check, as omc.om 9469-9505)
requires c (om2, checked build)chk.true 9 c at entry, then fact.true 0 c
requires c (unchecked build)nothing: no check, no fact (D2c)
trap Ntrap N
host wordchk.slice on each slice, then host
Omegese GPU kernelkind 1, gpu.id, shared, sync, shfl, fma, fmath FAST

14. In-memory ΩIR: seed/ng/src/ir.om (D1b)

ir.om holds ΩIR in global tables and owns the one binary reader and writer of the ng binary. Its first code line is om2 (D11), so the whole ng unit is om2: every lane file compiles as part of an om2 unit (at is reserved there, error 16). Stages build and read these tables directly; nothing is serialized between stages. Names follow D1b: functions ir_*, globals i_* (at most 8 bytes). Other lanes read the tables and call the ir_* functions; they never write a table directly.

Handles. Every handle is a uint, and 0 means none. Types use their wire type ids (s4). Globals, functions, blocks, ops and values are numbered from 1 in creation order across the whole module. The writer turns handles into wire ids: global g is wire id g-1, function f is f-1, a block is its position in its function's block list, and values are numbered by s6.2 (ir_num).

Tables (index = handle; counters in i_n):

tablecontents
i_ncounters: 0 table types, 1 struct fields, 2 globals, 3 functions, 4 blocks, 5 ops, 6 values, 7 operand slots, 8 global data bytes
i_tk i_t1 .. i_t5type id -> kind (s4.2, 0 for built-ins) and fields in wire order: VEC elem, lanes; ARRAY elem, count; STRUCT size, nfields, first field; REF target, access, space; SLICE elem, access, space; FRAG role, m, n, k, elem
i_xty i_xof i_xorstruct field -> type, offset, order
i_gty i_gcl i_gd0 i_gdatglobal -> type, class, first data byte in the i_gdat pool
i_fk i_ffl i_frs i_fnp i_ftk i_fp1 i_fb1 i_fbt i_fnb i_ftx i_fty i_ftz i_fsgfunction -> kind, flags, result type, parameter count, entry token value, first parameter value, first and last block, block count, kernel threads x, y, z, subgroup
i_bf i_bnx i_bp1 i_bnp i_bo1 i_bot i_bnoblock -> function, next block, first parameter value, parameter count, first and last op, op count
i_oop i_oty i_oim i_ona i_oa0 i_ob i_onx i_otk i_orsop -> opcode, ty, imm (ulong), operand count (token included), first slot in i_arg, block, next op, defined token value, defined result value
i_argoperand slots: value handles, block handles (br, cbr), function handles (call, launch)
i_vty i_vk i_vo i_vnx i_vnovalue -> type, kind (0 entry token, 1 function parameter, 2 block parameter, 3 op token, 4 op result), owner (function, block or op), next parameter in its list, wire id (after ir_num)

Builder (each returns the new handle or type id; capacity overrun traps 3 at the table, the front end refuses earlier):

calleffect
ir_initempty module
ir_tvec e l, ir_tarr e c, ir_tref t a s, ir_tslc e a s, ir_tfrg r m n k ethe type id, creating it once (equal types are one id)
ir_tsb size, ir_tsf t off ord, ir_tsebegin a struct, add a field, finish: the type id (deduplicated)
ir_glob t cls, ir_gbyt g ba global; append one data byte to a class-1 global
ir_fnew kind flags resa function, with its entry token value
ir_fpar f t, ir_fker f x y z sgadd a parameter value; set a kernel's threads and subgroup
ir_blk fappend a block; every block after the first gets its tok parameter 0 at once
ir_bpar b tadd a block parameter value
ir_btok b, ir_ftok fa block's token parameter; a function's entry token
ir_op b op ty imm nappend an op with n operand slots (token included); defines its token and result values by the row (s7.12)
ir_set o k hset operand slot k
ir_res o, ir_otok o, ir_arg o kthe op's result value, defined token, operand k
ir_num ffill i_vno for f by s6.2; returns f's value count

Reader and writer: ir_read off stop parses i_in[off..stop) into empty tables and returns 0 or a refusal class of s11, with ir_badat the absolute offset in i_in. It refuses what it needs to build sound tables (classes 10..15, 23, and REF/USE_BEFORE_DEF/BLOCK_ARITY/UNTERMINATED/TYPE where an id, a count or a global's data size cannot be resolved) and leaves every semantic rule to ngcheck. ir_wr writes the tables to i_out and returns the byte count. ir_wr after ir_read reproduces the input bytes exactly for every unit ir_read accepts. The gate runs ng ir-copy on every fixture unit, every byte mutation and the generated binaries (full, over, types): where ngcheck refuses with a structural class (MAGIC, VERSION, TRUNCATED, TRAILING, UNKNOWN_OP, LIMIT, IO) ng must print the same class and offset with empty stdout, except where that refusal is a LIMIT of s12 that ng's reader no longer has (the input size and the globals count, no-caps arena): there ngcheck keeps its LIMIT and the gate row pins the verdict of this reader (the class of s11 and the offset) for ng (for example M a-fib 31 1 23 28 13 42: a globals count of 16777216; the reader resolves a global's type only for class 1, so it reads on to the first class byte outside s5, NONCANONICAL at that record). Otherwise ng must give the bytes back exactly or, where ngcheck refuses, refuse with a class of s11 and empty stdout. In the tables a gaddr imm, and the imm of each pool op 111..116 (s7.13), is the global's handle (the writer subtracts 1, the reader adds 1); every other imm is the wire value.

Register budget: omc gives a function 16 registers, and each global array read in one expression costs one, and an expression in a loop's or a branch's head holds its registers to the block's end. Keep table reads to two or three per statement (the ir_* code shows the pattern); an arena table read is three (get ar_m add get ar_rb R i), so a crowded line reads through ar_w / ar_c / ar_u.

main.om reads the first input line (the mode, at most 63 bytes and its newline) apart, so the payload after it is region 0 of the arena (ar_rdin) from offset 0, as large as the arena holds. @ng ir-copy reads the ΩIR binary payload and writes it back (reader/writer round trip). A refusal prints ng: refused class C at OFFSET, offset in the payload, empty stdout, and exits C: a payload the arena cannot hold is class 23 at the bytes read (then the ng-use record), an unreadable one class 27; an unknown mode is `ng: unknown modeand exit 2.@ng optreads the payload like@ng ir-copy`, runs the optimizer of src/opt.om (s15.1) and writes the result; @ng opt-count runs the same passes and prints one line of counts instead of the unit. Stage lanes add their modes (@ng dump-ir <stage> after the front end or a pass, @ng ingest-ir <stage> before a back end) beside their code.

15. What a pass may do to a check (D7)

A check is never moved above an earlier effect, an earlier trap or a loop that may run zero times; the token chain makes the first two visible to the validator, and the differential gate with zero-trip mutants guards the third. A pass removes a check in exactly two ways:

  1. Delete a check that a dominating fact or check proves cannot fail, replacing it by the fact (chk.bounds by fact.inbounds with the pass's origin), so the coverage rule still holds.
  2. Version a loop: a guard on the loop entry tests that every index stays in range and the trip count stays below the fuel bound; the fast copy carries facts in place of the checks, and the original loop, checks intact, runs when the guard fails.

Every pass that does either has mutants that attack trap order and zero-trip hoisting (D9).

15.1 Loop-invariant code motion, bounds-check elimination and rotation (src/opt.om, D16)

src/opt.om (unit order ir, opt, main; functions op_*) rewrites the ir.om tables in place, per function:

  1. Preheaders. A natural loop is a header h with a back edge u -> h where h dominates u (Cooper, Harvey and Kennedy dominators over reverse postorder); its blocks reach a latch without passing h. When h has exactly one predecessor outside the loop and it ends in br h, that block is the preheader; otherwise a new block with h's parameter types, ending in br h with them, is placed before h and every outside predecessor (br or cbr) branches to it instead. A new block is added only within the limits of s12 (blocks, ops and values per function and per unit); a loop that would need one past them keeps none, and LICM leaves that loop alone. 1a. PHI. A block parameter other than the token whose arguments, over every br that targets its block, are one value v or the parameter itself is replaced by v: its uses take v, and it leaves the block's parameter list and each such br its argument (a block with a parameter past its token is reached only by br, s9 rule 5). v dominates the block (s6.2): every block is reachable (s9 rule 4), and on any path from block 0 the edge that first enters the block comes from a predecessor the block does not dominate, so that br passes v, not the parameter, and v dominates its end. One parameter per round, to a fixed point. A value an outer loop carries unchanged through an inner loop's header is such a parameter, so LICM then sees its uses as invariant. PHI, BCE and LICM repeat in that order while one of them changes something: LICM's merging can give two br arguments one value only after PHI ran (ngrand seed 523 kept a redundant parameter after one round). Fixture o-phi (one parameter stays, one goes); a PHI that kept a parameter's first argument even where another br passes a different one changes its run (exit 16 for 18).
  2. BCE (pass origin 1, item 1 of s15). A chk.bounds r i e is replaced in place by fact.inbounds 1 r i e when e is a const >= 1, r is a REF to an ARRAY of count L, and i < X is known where the check runs with X - 1 + e <= L: i is a const (X = i + 1), or a block on the check's dominator path has one predecessor, ending in a cbr on lt/le/gt/ge of i and a const, so that block runs only after the test proved i < X. A chk.divz of a nonzero const is deleted. Uses of a deleted check's output token take its input token. ngcheck judges the fact's placement, not its truth (s7.10); the gate's BCE mutant (X - 1 + e <= L + 1) makes the boundary fixture o-bce1 (L = 4, i < 5) write past the array, and the run differs.
  3. LICM, innermost loop first. An op moves to the end of the preheader when it is class P (s6.4), defines a value, is not shared, is not convergent (sync, shfl, mmald, mmast, mma, refused by number: s7.12 forbids moving them into or out of a branch, and the loop body is the branch of the header's test; the gate's convergent mutant drops shfl from that list and the pinned o-shfl row differs), and every operand is defined outside the loop. P ops are total (s7.3: division by zero gives 0), so running one on a path where the loop runs zero times changes nothing. Checks, loads, stores, calls, host words, facts and terminators never move: they carry the token chain, and that is where coverage (s8) and trap order (above) live. An op equal to one already in the preheader (op, type, imm, operands) is dropped and its uses take the earlier value.
  4. ROT. When the header ends in cbr with one target inside the loop and one outside, and the one latch ends in br h, the header is placed right after the latch. Block order changes no value (uses are judged by dominance, s6.2); it is the layout a back end emits, so the back branch falls through into the test and a pass of the loop takes one conditional branch.

The gate runs every O/L fixture and every Q seed through @ng opt: ngcheck's whole ACCEPT line on the output, the text round trip, ngrun before and after equal, and a second run that finds nothing to move; each O/L line also pins the @ng opt-count row of its input (o-shfl: a kernel loop whose invariant shfl stays put). Its mutants hoist a load past the loop's stores and checks past their guard (both refused by ngcheck: the hoisted op keeps an in-loop token, s6.4), merge preheader ops of different imm (a run differs) and let BCE delete a check one element past its proof (a run differs).