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 / docs / osc / OSC-4-DESIGN.md

617 lines · 50920 bytes Raw Blame History Rendered
1# OSC-4: floats, large buffers, extern C, syscalls, long loops (design)
2
3Status: design, not yet implemented. Target: the host program of a language-model
4trainer written in Omega instead of Rust. Style follows OSC-2-DESIGN.md; every claim
5about existing code carries a file:line tag against commit 6c1827ba; unconfirmed
6items are marked UNVERIFIED. Each slice ships as one PR with red-before-green
7tests and a dual-run fuzz leg reporting `mismatches=0` (tests/compiler/test_osc_compiler.c:572-575).
8
9## 0. Ground truth this design stands on
10
111. OSC today is integer only. OscScalar has VOID, BOOL, U8..U64, I8..I64, REF,
12 BYTES, CELLS (src/compiler/osc_ir.h:44-54). The validator refuses
13 "arith BIN needs identical integer types" (src/compiler/osc_ir.c:158) and
14 "CAST needs integer types" (src/compiler/osc_ir.c:179-180).
152. Neither encoder has a floating-point instruction. The validating encoder's ops
16 are OSC_A64_ADD_IMM..OSC_A64_LDRB_REG, all X forms (src/compiler/osc_a64.h:28-64);
17 a grep for fmov|fadd|fmul|fcvt|scvtf|fcmp|fsub|fdiv|fsqrt|fneg|fabs|frint|fmadd|
18 fpcr|float|double over src/aarch64_encoder.[ch], src/compiler/osc_a64.[ch] and
19 src/compiler/osc_cg.c is empty. src/aarch64_encoder.c is the frozen legacy
20 writer, untouched by OSC work (docs/osc/OSC-1-DESIGN.md:202-216).
213. There is no register allocator. osc_cg.c keeps every vreg in a stack slot
22 at [sp, #8*(v+1)], the runtime pointer at [sp, #0], and uses fixed scratch
23 registers x9..x13 plus x16 for BLR (src/compiler/osc_cg.c:5-11, :104-106).
24 src/compiler/osc_alloc.c is the explicit memory allocator (OscAlloc, OscAllocMeter,
25 docs/osc/OSC-1-DESIGN.md:257-278), not a register allocator. The brief's
26 phrase "how osc_alloc.c handles a second register class" rests on a wrong
27 premise; section 1.7 gives the V-register scheme in the same fixed-scratch
28 style instead.
294. Arrays are tiny. OSC_MAX_ARRAY_LEN is 64 (src/compiler/osc_ir.h:37), the pool is
30 `uint64_t cells[OSC_RT_SLOTS][OSC_MAX_ARRAY_LEN]` with 64 slots (src/compiler/osc_rt.h:32, :101),
31 OscType.len and OscRtEvent.len are uint16_t (src/compiler/osc_ir.h:67, src/compiler/osc_rt.h:64).
32 Parameter-only slices `bytes` / `cells` exist with a pointer vreg and a length
33 vreg at a+1 (src/compiler/osc_parse.c:230-235; SLOAD/SSTORE src/compiler/osc_cg.c:449-470;
34 `osc_ir_slice_args_ok` src/compiler/osc_ir.c:705-720). OSC-EXT-BYTES-DESIGN.md
35 still says "on branch osh/osc-ext-bytes"; the code is merged on main (e55e2af9, eb8dedf7). Stale line.
365. Loops are capped at one million. `#define LOOP_BOUND_MAX 1000000`
37 (src/compiler/osc_parse.c:11) is enforced in the parser for `while ... bound N`
38 (src/compiler/osc_parse.c:895-922) and `for` literal ranges (:924-946). While
39 lowers to a u64 counter, CMP GE, TRAP LOOP_BOUND (src/compiler/osc_lower.c:509-540).
40 The interpreter also caps steps at OSC_INTERP_MAX_STEPS = 1<<32 (src/compiler/osc_interp.h:17).
416. `extern` and `syscall` are already reserved words that the lexer refuses
42 (src/compiler/osc_lex.c:22-27), so turning them into keywords breaks no program.
437. Determinism doctrine: interpreter and native agree on trap code, return value
44 and event log (docs/adr/OMEGA-SYSTEMS-CORE-0000.md:14-24 decisions 6, 9, 10;
45 `osc_rt_same_outcome` src/compiler/osc_rt.c:313-336). IR versions are never
46 reinterpreted: OSC_IR_VERSION_MAX is 5 (src/compiler/osc_ir.h:257), `unit_version`
47 picks the smallest (src/compiler/osc_ir.c:612-618). Traps run 1..14 (src/compiler/osc_ir.h:151-176).
48 OscRt entry points sit at fixed offsets 0..96, new ones appended (src/compiler/osc_rt.h:85-99, osc_rt.c:12-25).
498. Compiler flags: OSC_CFLAGS is `-std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2 ...`
50 with no `-ffp-contract=off` (mk/compiler.mk:22). Other makefiles already use
51 `-ffp-contract=off -fno-fast-math` (mk/tensor.mk:24, mk/omega-gpu-engine.mk:76).
52 Compiler on this box: gcc 13.3.0.
539. Customer surface in this repo: `int omega_gpu_matmul_f32(uint32_t m, uint32_t k,
54 uint32_t n, ...)` (src/omega_gpu_matmul_api.h:109) and `int omega_gpu_rmsnorm_f32(uint32_t rows,
55 uint32_t dim, const float *x, const float *weight, float eps, float *out, OmegaGpuEwInfo *info)`
56 (src/omega_gpu_elementwise_api.h:121), archived in libomega_gpu.a (mk/prime_race_gb10.mk:2-3,25).
57 The Rust trainer declares the same two externs (aien-lm-rs/crates/aien-lm-sys/src/lib.rs:26-55).
58 UNVERIFIED: no `tk_*` kernel exists in this repo or in aien-lm-rs; names and
59 signatures must come from aien-dev-ba before Slice C tests are written.
60
61## 1. Slice A: f32 and f64 scalars and fixed arrays
62
63### 1.1 Subset statement
641. Two new scalar types `f32` and `f64`: IEEE-754 binary32 and binary64.
652. Float literals: `1.0`, `0.5e-3`, `3.0f32`, `1.0f64`. A literal with no suffix
66 takes its type from the context exactly like integer literals; an unresolvable
67 width is refused with the existing AMBIGUOUS_WIDTH diagnostic (src/compiler/osc_check.c:1192, :1326, :1350).
683. Operators on floats: `+ - * /`, unary `-`, comparisons `== != < <= > >=`.
69 No `%`, no bit operators, no `&&`-style short circuits beyond what exists for bool.
704. Conversions with `as`: int to f32/f64, f32/f64 to int, f32 <-> f64, and bit
71 casts spelled `x as u32 bits` / `x as f32 bits` (same widths only). Bit casts
72 are the only way to inspect NaN payloads or the sign of zero.
735. `let`, params, returns, and `own [f32; N]` / `own [f64; N]` arrays with the
74 existing N range 1..OSC_MAX_ARRAY_LEN (src/compiler/osc_ir.h:37); Slice B
75 raises that range.
766. Intrinsics `sqrt(x)`, `abs(x)`, `min(a, b)`, `max(a, b)` on one float type; `min`/`max` follow
77 FMINNM/FMAXNM, the IEEE minNum/maxNum rule: if exactly one operand is a quiet NaN the other is
78 returned, otherwise NaNs propagate as in 1.3 item 4; -0.0 orders below +0.0. No `fma` or `pow`;
79 `exp` and `log` reach the trainer as `extern fn expf/logf` (3.1), never as intrinsics.
80
81### 1.2 Grammar delta (against docs/osc/OSC-1-DESIGN.md:42-83)
82```
83type := ... | "f32" | "f64"
84literal := ... | FLOAT # digits "." digits [exp] [("f32"|"f64")]
85expr := ... | expr "as" type ["bits"]
86 | ("sqrt"|"abs") "(" expr ")" | ("min"|"max") "(" expr "," expr ")"
87```
88Lexer: `.` is currently OT_DOT (src/compiler/osc_lex.c:169) and integer
89literals are the only numbers; a FLOAT token is accepted only when a digit
90precedes the dot, so `a.b` member syntax (none today) stays free.
91`f32`, `f64`, `sqrt`, `abs`, `min`, `max`, `bits` become keywords (src/compiler/osc_lex.c:9-18).
92
93### 1.3 Semantics (shared by interpreter and native)
941. Rounding is round-to-nearest-even for every operation. FPCR stays at the
95 process default (RMode 00, FZ 0, DN 0, exceptions untrapped); OSC never
96 writes FPCR. Subnormals are kept, never flushed.
972. No fused operations. There is no FMADD/FMSUB/FNMADD/FNMSUB in the encoder and
98 the lowering never produces one. `a * b + c` is two IR ops and two rounds.
993. Interpreter arithmetic is plain C `float` / `double` on values held in `volatile` locals, compiled
100 with `-ffp-contract=off -fno-fast-math -fno-math-errno` added to OSC_CFLAGS (mk/compiler.mk:22).
101 FLT_EVAL_METHOD is 0 on AArch64 GCC, so there is no excess precision. Each op is one C expression
102 per IR op: no reassociation. `sqrt`/`sqrtf` are the only libm calls: IEEE makes them correctly
103 rounded, so they match FSQRT, and -fno-math-errno lets GCC inline them.
1044. NaN: arithmetic on NaN yields the hardware's default-propagated NaN (first
105 operand's payload, quieted). The interpreter runs on the same CPU, so the bits
106 agree there; NaN payload equality across machines is outside the contract.
107 Tests compare f32/f64 results by bit pattern on the same host.
1085. -0.0: `==` treats -0.0 == +0.0 as true (FCMP semantics). Bit casts expose the sign.
109 No trap distinguishes them.
1106. Comparisons with NaN: `<`, `<=`, `>`, `>=`, `==` are false; `!=` is true. These
111 are the unordered results of FCMP consumed with conditions MI/LS/GT/GE/EQ/NE
112 as listed in 1.6. Interpreter uses the C operators, which match.
1137. Division by zero, overflow, invalid: no traps; inf and NaN flow on. This
114 differs on purpose from integer `/` (tests/compiler/neg/ovf_zero_divisor.osc):
115 a trainer must be able to see a loss go inf and report it, not die.
1168. Float to int `as`: FCVTZS/FCVTZU semantics (truncate, saturate, NaN -> 0); the
117 interpreter saturates explicitly and never relies on C's undefined conversion.
1189. Int to float: SCVTF/UCVTF (RNE). f32 <-> f64: FCVT (RNE).
11910. Interpreter NEG is `-x`, never `0.0 - x` (0.0 - (+0.0) is +0.0; FNEG gives -0.0).
12011. Interpreter MIN/MAX spell out the minNum/maxNum rule of 1.1 item 6 in C (NaN tests, then the
121 signed-zero order, then `<`); C `fmin`/`fmax` are never called.
12212. f32 literals are parsed with `strtof`, f64 with `strtod`; never strtod then cast (double rounding).
12313. Item 7 is a permanent language rule, not an OSC-4 exception. The ADR docs/adr/OMEGA-SYSTEMS-CORE-0000.md
124 is frozen, so the Slice A PR does not edit the text of decision 6; it appends a dated clarification
125 note under decision 6 stating that inf and NaN are values, not invariant violations (reviewer
126 condition 2, 2026-10-16).
127
128### 1.4 Static refusals (new diagnostic kinds appended after SLICE_ALIAS, src/compiler/osc_diag.h:12-56)
129| Kind | Transition | Cause |
130|---|---|---|
131| FLOAT_MIXED | check | arithmetic or compare between f32 and f64, or float and int, without `as` |
132| FLOAT_BITOP | check | `% & \| ^ << >>` applied to a float |
133| FLOAT_INDEX | check | float used as array index, loop bound or `bound` |
134| FLOAT_BITS_WIDTH | check | `as ... bits` between sizes that differ (f32 bits only to/from u32/i32, f64 only to/from u64/i64) |
135| FLOAT_CONST_RANGE | check | literal that does not round to a finite value of its type (overflow to inf is refused at compile time) |
136| AMBIGUOUS_WIDTH | check | unsuffixed float literal with no context type (existing kind) |
137
138### 1.5 IR (version 6; OSC_IR_VERSION_MAX becomes 6, src/compiler/osc_ir.h:257)
1391. OscScalar gains OSC_S_F32 and OSC_S_F64 appended after CELLS (src/compiler/osc_ir.h:44-54).
140 `osc_scalar_is_int` (src/compiler/osc_ir.c:26) stays false for them.
1412. New OscOp values appended after SSTORE (src/compiler/osc_ir.h:74-127):
142 FBIN (sub: ADD SUB MUL DIV MIN MAX), FUN (sub: NEG ABS SQRT), FCMP (sub: EQ NE LT LE GT GE,
143 dst bool), FCVT (float <-> float), ITOF (sub: signed/unsigned), FTOI (sub: signed/unsigned,
144 dst width from type), FBITS (bit cast). CONST carries float bits in `imm`
145 (OscInsn.imm is uint64_t, src/compiler/osc_ir.h:179-190); f32 constants
146 occupy the low 32 bits, upper 32 zero.
1473. Validator rules beside the integer ones (src/compiler/osc_ir.c:158, :179): FBIN/FCMP
148 need identical float types; FUN a float; FCVT two distinct float types; ITOF
149 int -> float; FTOI float -> int; FBITS equal widths. Violations are decoder
150 refusals in the style of src/compiler/osc_ir.h:268-283.
1514. `unit_version` returns 6 when any float type or op is present (src/compiler/osc_ir.c:612-618).
152
153### 1.6 Native lowering and AArch64 encodings
154Vreg slots stay 8 bytes. An f64 fills the slot. An f32 occupies the low 4 bytes
155and the upper 4 bytes are always zero: results are moved out with FMOV Wd, Sn
156(which zero-extends) and stored with the existing STR_UOFF; loads use LDR S
157from the slot. This keeps `osc_rt_call_native` (src/compiler/osc_rt.c:300) and
158the `expect-run` harness untouched: f32/f64 arguments and returns travel as bit
159patterns in uint64_t.
160
161Scratch V registers: d16..d20, mirroring x9..x13 (src/compiler/osc_cg.c:7-9).
162v16..v31 are caller-saved and not argument registers under AAPCS64, and
163v8..v15 (callee-saved low halves) are avoided entirely. No V register is live
164across a BL, so Slice C's extern calls need no V saves.
165
166New OscA64Op entries (appended before OSC_A64_NOPS, src/compiler/osc_a64.h:28-64),
167their fixed bits and the golden word for the backend test in the
168`enc_expect(insn, word, name)` style (tests/compiler/test_osc_backend.c:619-626).
169Field layout for every scalar FP data-processing op: Rd bits 4:0, Rn bits 9:5,
170Rm bits 20:16, type bits 23:22 (00 = S, 01 = D). MEASURED (2026-10-16): the words
171below are now backed by `golden/aarch64_fp_golden.md` and `golden/aarch64_fp_golden.h`
172(sibling of this checkout, ~/workspace/osc4/golden/): 87 forms,
1731365 samples assembled by GNU as 2.42 on this box and disassembled with objdump,
174re-encoded from derived field layouts with 0 mismatches, and a negative control
175(one deliberately corrupted word gives exactly 1 mismatch). FCMP NZCV measured on
176this CPU: less = 1000, equal = 0110, greater = 0010, unordered (NaN) = 0011, so the
177condition choices in 1.6 (LT -> MI, LE -> LS, GT, GE, EQ, NE) read false on NaN as
178intended. Two facts the table adds: `fmov d0, #0.0` is not encodable (zero has no
179FMOV-immediate form; use `fmov dD, xzr` / `fmov sD, wzr`), and FMOV immediates take
180the 8-bit imm8 code, not the float (1.0 = 0x70, 2.0 = 0x00, 0.5 = 0x60, -1.0 = 0xF0).
181The builder still runs `docs-read omega` before touching the encoder (the standing rules in `README.md` and
182`ENGINEERING-NOTES.md`; manual-guard hook) and adds `enc_expect` goldens taken from the .h table.
183
184| Op | Fixed bits (S / D) | Golden example | Word |
185|---|---|---|---|
186| FMOV_RR | 0x1E204000 / 0x1E604000 | fmov d0, d1 | 0x1E604020 |
187| FMOV_XD (Xn -> Dd) | 0x9E670000 | fmov d0, x1 | 0x9E670020 |
188| FMOV_DX (Dn -> Xd) | 0x9E660000 | fmov x0, d1 | 0x9E660020 |
189| FMOV_WS (Wn -> Sd) | 0x1E270000 | fmov s0, w1 | 0x1E270020 |
190| FMOV_SW (Sn -> Wd) | 0x1E260000 | fmov w0, s1 | 0x1E260020 |
191| FADD | 0x1E202800 / 0x1E602800 | fadd d0, d1, d2 | 0x1E622820 |
192| FSUB | 0x1E203800 / 0x1E603800 | fsub d0, d1, d2 | 0x1E623820 |
193| FMUL | 0x1E200800 / 0x1E600800 | fmul d0, d1, d2 | 0x1E620820 |
194| FDIV | 0x1E201800 / 0x1E601800 | fdiv d0, d1, d2 | 0x1E621820 |
195| FMAXNM | 0x1E206800 / 0x1E606800 | fmaxnm d0, d1, d2 | 0x1E626820 |
196| FMINNM | 0x1E207800 / 0x1E607800 | fminnm d0, d1, d2 | 0x1E627820 |
197| FSQRT | 0x1E21C000 / 0x1E61C000 | fsqrt d0, d1 | 0x1E61C020 |
198| FNEG | 0x1E214000 / 0x1E614000 | fneg d0, d1 | 0x1E614020 |
199| FABS | 0x1E20C000 / 0x1E60C000 | fabs d0, d1 | 0x1E60C020 |
200| FCMP | 0x1E202000 / 0x1E602000 | fcmp d0, d1 | 0x1E612000 |
201| FCVT_SD (Dn -> Sd) | 0x1E624000 | fcvt s0, d1 | 0x1E624020 |
202| FCVT_DS (Sn -> Dd) | 0x1E22C000 | fcvt d0, s1 | 0x1E22C020 |
203| SCVTF_X | 0x9E220000 / 0x9E620000 | scvtf d0, x1 | 0x9E620020 |
204| UCVTF_X | 0x9E230000 / 0x9E630000 | ucvtf d0, x1 | 0x9E630020 |
205| FCVTZS_X | 0x9E380000 / 0x9E780000 | fcvtzs x0, d1 | 0x9E780020 |
206| FCVTZU_X | 0x9E390000 / 0x9E790000 | fcvtzu x0, d1 | 0x9E790020 |
207| LDR_S_UOFF / LDR_D_UOFF | 0xBD400000 / 0xFD400000, imm12 scaled by 4 / 8 | ldr d0, [sp, #8] | 0xFD4007E0 |
208| STR_S_UOFF / STR_D_UOFF | 0xBD000000 / 0xFD000000 | str d0, [sp, #8] | 0xFD0007E0 |
209| LDR_S_REG / LDR_D_REG | 0xBC607800 / 0xFC607800 (LSL #2 / #3) | ldr d0, [x1, x2, lsl #3] | 0xFC627820 |
210| STR_S_REG / STR_D_REG | 0xBC207800 / 0xFC207800 | str d0, [x1, x2, lsl #3] | 0xFC227820 |
211
212Not added: FMADD/FMSUB (forbidden), FRINTx (no rounding intrinsics), FCCMP
213(every compare is one FCMP plus one CSINC), FMIN/FMAX non-NM, W-form converts
214(narrow ints widen through the existing SBFM/UBFM first, same value). Each new
215op gets one `enc_expect` golden, one decoder round trip and one field-flip mutant
216in test_osc_backend.c; the mirror decoder (src/compiler/osc_a64.c:244) and
217`osc_a64_reencode` (:235) learn the new classes.
218
219Lowering sketch (one IR op -> fixed sequence, in src/compiler/osc_cg.c next to gen_bin :187-268 and gen_cast :299-319):
2201. FBIN: LDR d16, slot(a); LDR d17, slot(b); F<op> d16, d16, d17; STR d16, slot(dst).
2212. FCMP: LDR d16/d17; FCMP; CSINC x9, xzr, xzr, inv(cond) (src/compiler/osc_a64.c:316);
222 STR x9. Conditions EQ, NE, LT -> MI, LE -> LS, GT, GE (unordered reads false).
2233. ITOF/FTOI/FCVT/FUN: LDR, one instruction, STR. CONST float: `mat` (src/compiler/osc_cg.c:108-133)
224 into x9 then STR. ALOAD/ASTORE on float arrays: unchanged (cells are uint64).
225
226### 1.7 ABI for floats between OSC functions
227Unchanged convention: params x0..x5, return x0 (docs/osc/OSC-1-DESIGN.md:202-216).
228Floats travel as bit patterns in X registers (FMOV_DX before BL, slot store after).
229V registers are never part of the OSC-internal ABI. Host callers pass float
230bits in `const uint64_t *args` (src/compiler/osc_rt.h:148) and oscc OUT lines
231print them as hex bits with a new entry kind 13 (f32) and 14 (f64) after the
232existing 1..9, 11, 12 (src/compiler/oscc_main.c:62-63).
233`canon` for F32 (src/compiler/osc_interp.c:23) is "low 32 bits, upper 32 zero, NaN payload untouched";
234F64 keeps all 64 bits, so the argument check at osc_interp.c:221 refuses only dirty upper halves.
235
236### 1.8 Evidence
2371. Red first: one tests/compiler/neg/*.osc per kind in 1.4 with the
238 `// expect: KIND object=.. line=..` header (tests/compiler/neg/ovf_zero_divisor.osc).
2392. Goldens f_adam_step.osc, f_cast_sat.osc, f_nan_cmp.osc, f_neg_zero.osc whose
240 `// expect-run:` VALUE is the bit pattern, checked against a 20-line C oracle.
2413. Fuzz: the dual-run generator gains float ops and constants, and `gen_arg`
242 (tests/compiler/test_osc_compiler.c:143) emits f32/f64 argument patterns including quiet and
243 signalling NaN, both infinities, -0.0 and subnormals; `mismatches=0` over 100k programs plus
244 the ASan/UBSan leg (mk/compiler.mk:23).
2454. Backend: 25 `enc_expect` goldens, round trips, mutants. determinism.sh passes on version 6 units.
246
247### 1.9 Limits
248No fused ops, no FRINT, no transcendental intrinsics, no f16/bf16, no SIMD, no
249float `%`, no float array constants. These omissions buy bit-exact agreement.
250
251## 2. Slice B: large buffers and typed slices
252
253### 2.1 Subset statement
2541. Raising OSC_MAX_ARRAY_LEN to hundreds of millions is refused: the pool is an
255 inline 64x64 uint64 array (src/compiler/osc_rt.h:101), OscType.len is uint16_t
256 (src/compiler/osc_ir.h:67) and OscRtEvent.len is uint16_t (src/compiler/osc_rt.h:64).
257 Instead a new buffer kind `buf` is added: a heap-backed, host-visible, typed,
258 runtime-length region.
2592. Types: `&[T]` and `&mut [T]` for T in {u8, u16, u32, u64, i32, i64, f32, f64}
260 generalising `bytes` (u8, read) and `cells` (u64) of OSC-EXT-BYTES. The two
261 old names stay as aliases (`bytes` = `&[u8]`, `cells` = `&mut [u64]`) so the
262 47 existing goldens and version 5 units stay valid.
2633. Slices stay parameter-only (SLICE_ESCAPE, SLICE_VALUE of docs/osc/OSC-EXT-BYTES-DESIGN.md
264 kept). Buffers are created by the host (harness, oscc, or Slice D `mmap`) and
265 handed in as slices: millions of elements with no new ownership rules.
2664. `len(s)` yields u64; `s[i]` reads or writes one T.
267
268### 2.2 IR and validation
2691. OscScalar gains SLICE_RO and SLICE_RW with an element scalar stored in
270 OscType (the existing `elem` field, src/compiler/osc_ir.h:66, whose OscScalar gains F32 and F64 in Slice A). BYTES and
271 CELLS are decoded as SLICE_RO/u8 and SLICE_RW/u64 for version 5 units.
2722. SLOAD/SSTORE gain `sub` = element width (1, 2, 4, 8); `osc_ir_slice_args_ok`
273 (src/compiler/osc_ir.c:705-720) also checks pointer alignment and length * width overflow.
2743. Version 6 if it lands with Slice A, 7 otherwise; `unit_version` picks the smallest.
275
276### 2.3 Bounds checks, cheap and deterministic
2771. Native: index vreg in x9, length vreg (a+1) in x10, `CMP x9, x10; B.HS trap`
278 via the existing `bounds_r` (src/compiler/osc_cg.c:182-185); the new element
279 forms use LDR/STR register-offset with LSL by log2(width) (LDRH/LDRW forms for
280 u16/u32 added to the encoder alongside the FP table: LDRH_REG 0x78606800,
281 LDR_W_REG 0xB8606800, STRH_REG 0x78206800, STR_W_REG 0xB8206800, STRB_REG 0x38206800;
282 UNVERIFIED until docs-read and enc_expect).
2832. Interpreter: `sload`/`sstore` (src/compiler/osc_interp.c:139-147) compare the
284 same unsigned index against the same length and load through a width switch.
2853. The out-of-range trap stays whatever SLOAD raises today (UNVERIFIED which of
286 codes 1..14, src/compiler/osc_ir.h:151-176; the builder copies it, no new code).
2874. No bounds-check elimination: one compare per access, a 124M-element loop
288 stays under a second on Grace.
289
290### 2.4 Evidence
291Goldens sum_u16.osc (2^20 elements), saxpy_f32.osc, fill_f64.osc. Fuzz over random
292lengths 0..2^20, widths and index streams with out-of-range probes, `mismatches=0`.
293One harness test maps a 512 MB `&[u16]` to prove nothing truncates at 2^16 or 2^31.
294
295## 3. Slice C: extern C calls
296
297### 3.1 Subset statement
298```
299extern fn NAME "(" [param {"," param}] ")" ["->" type] ";"
300```
301Params and returns limited to: integers (u8..u64, i8..i64), f32, f64, and slices
302(`&[T]`, `&mut [T]`) which cross as a pointer only. Every slice parameter of an
303`extern fn` must be followed immediately by an explicit `u64` length parameter
304(`x: &[f32], n: u64` spells the C prototype `const float *x, uint64_t n`); the
305checker passes `len(x)` is NOT implied, the Omega author writes it, and a slice
306parameter with no following `u64` is the static refusal EXTERN_SLICE_LEN (reviewer
307condition 3, 2026-10-16). At most 8 integer-class and 8
308float-class arguments; no struct arguments; no variadics; `OmegaGpuEwInfo *info`
309style out-structs cross as `&mut [u8]` of the right byte size, filled by C.
310The static table (3.2 item 4) is the allowlist: an extern not in it cannot be called,
311whatever the flag says.
312First extern table entries (beside the two GPU entry points of 0.9): `extern fn expf(x: f32) -> f32;`
313and `extern fn logf(x: f32) -> f32;`, which give train.osc its cross-entropy. Assumption: both engines
314and the Rust trainer call the same glibc libm (2.39 on this box); Rust's f32::exp/ln lower to libm
315expf/logf on linux-gnu. glibc expf/logf are not promised correctly rounded, so identity needs the
316same libm build. Slice C ships a red check for this: a test runs `ldd` on the OSC harness binary and
317on the Rust trainer binary and fails unless both resolve libm.so.6 to the same path and the two files
318have the same SHA-256; the check stays red (and Slice C does not merge) until that identity is observed
319(reviewer condition 3, 2026-10-16).
320
321### 3.2 AAPCS64 lowering
3221. Integer-class args in x0..x7, float-class in v0..v7, counted separately. More
323 than 8 of either class is the static refusal EXTERN_ARITY (no stack args).
3242. Nothing is saved before BLR: every vreg already lives in its stack slot and
325 x7 (rt) is reloaded from [sp, #0] after the call (src/compiler/osc_cg.c:5-11).
326 The frame is a multiple of 16 (osc_cg.c:330-341) so SP alignment holds. The target
327 address is loaded into x16 from the extern table (item 4), then BLR x16 (src/compiler/osc_a64.c:333).
3283. Return: x0 for ints (widened with SBFM/UBFM), v0 for floats (FMOV_DX then
329 slot store). x9..x16 and v16..v31 are dead across the call by construction.
3304. Target address: the unit records extern names; `osc_native_load` resolves them against a static
331 table `{name, fnptr}` compiled into oscc and the test harness (no dlsym, no dlopen; both link -lm).
332 Unknown name: load-time refusal EXTERN_UNRESOLVED. The resolved pointers sit in an array reached
333 through a new OscRt field `externs` (`uint64_t (**externs)(void)`, offset 104) appended after
334 h_store, followed by the entry `log_ext` (offset 112, 3.4), so the fixed-offset region grows by
335 16 bytes, not 8, and host-side state from src/compiler/osc_rt.h:100 moves down 16 bytes (native code
336 never reads it by offset). Two `_Static_assert`s beside osc_rt.c:12-25 pin offsets 104 and 112.
337 `osc_rt_init` sets `externs = NULL` and `log_ext = osc_rt_log_ext`; the host that owns the table
338 (oscc, the test harness) stores its pointer after init. Every runner (oscc run, test harness,
339 determinism.sh's runs) refuses to start a unit that declares an extern while `rt->externs` is
340 NULL: refusal EXTERN_NO_TABLE before any native code runs. Call k is
341 `ldr x16, [sp, #0]; ldr x16, [x16, #104]; ldr x16, [x16, #8*k]; blr x16`, the runtime-entry shape
342 of osc_cg.c:10. No address lives in the code, so oscc's code SHA-256 stays reproducible and
343 determinism.sh is unaffected (reviewer condition 1, 2026-10-16).
3445. Argument storage: EXTERN takes up to 16 argument vregs, more than OscInsn.args[OSC_MAX_PARAMS]
345 (src/compiler/osc_ir.h:187) holds. Its `imm` indexes a per-function side table of
346 `{uint16_t ext; uint8_t n; int16_t v[16];}`, so OscInsn and version 5 decoding stay unchanged.
347
348### 3.3 Interpreter
349The same registered host-function table; the interpreter dispatches on
350(int count, float count, return kind) through a macro-generated `switch` over C
351function pointer types in osc_interp.c (81 shapes for 0..8 by 0..8).
352
353### 3.4 Effect doctrine
354An extern call is an effect. Under decision 6 (docs/adr/OMEGA-SYSTEMS-CORE-0000.md:14-24)
355the C side returns int status and never unwinds; Omega must check it. Concretely: no C function in
356the static table may call `rt->trap`, `longjmp`, `exit` or anything else that leaves its frame
357abnormally (rt->trap longjmps over the C frame, which is undefined behaviour); an extern that
358cannot do its job returns a status word and Omega traps or branches on it. OSC-3 item 4
359(effects/capabilities) is not shipped (docs/osc/OSC-3-DESIGN.md:312-318); until it
360is, `extern fn` needs `oscc --allow-extern`. The flag is recorded in the unit header (a new header
361byte, 0 or 1), the unit SHA-256 therefore covers it, and determinism.sh compares it like every other
362header field: two compiles that differ only in the flag are different units, never "the same unit
363with a different gate". When OSC-3 item 4 ships, each extern declares its effects there and the flag
364is retired (reviewer condition 3, 2026-10-16).
365Dual-run equivalence: both engines call the same C function with the same argument bits, then log
366an EXTERN event (new kind 11 after POOL_CLOSE = 10, src/compiler/osc_rt.h:58) whose fold covers the
367extern index, every argument word and the return word, appended after the 8 header bytes the way pool
368events fold their generation (osc_rt.c:87-88). The fold reaches `ev_hash`, which osc_rt_same_outcome
369compares (osc_rt.c:314).
370How `log_ext` receives up to 16 argument words plus the return word (reviewer condition 1): the
371lowering reserves 17 contiguous 8-byte words at the top of the frame (`ext area`, frame stays a
372multiple of 16). Before the call it copies the n argument vregs (3.2 item 5) into ext[0..n-1] and
373loads x0..x7 / v0..v7 from there; after the BLR it stores the return word (x0 or FMOV_DX v0) into
374ext[16] and into the dst slot. It then calls the OscRt entry at offset 112,
375`void log_ext(OscRt *rt, uint64_t ext_index, uint64_t n, const uint64_t *words)`, with
376`words = &ext[0]` (4 integer arguments, no V registers live, the runtime-entry shape of osc_cg.c:10).
377`osc_rt_log_ext` writes the 8 header bytes `{kind = 11, slot = (uint8_t)n, len = (uint16_t)ext_index,
378serial = (uint32_t)n}`, then folds ext_index as a u64, then words[0..n-1], then words[16] (the return
379word), each as 8 little-endian bytes. The interpreter calls the same `osc_rt_log_ext` with the same
380words, so the two folds are byte-identical. A void extern logs return word 0.
381Nondeterministic externs are the host's problem.
382
383### 3.5 Evidence
384Goldens calling a harness-defined test function (int, double, uint32 args) and
385`omega_gpu_rmsnorm_f32` on a 4-row input, output bits compared with the Rust
386path. Negatives for EXTERN_ARITY, EXTERN_SLICE_LEN, EXTERN_UNRESOLVED, EXTERN_NO_TABLE (unit with an extern run
387against an OscRt whose `externs` is NULL), and a unit compiled without --allow-extern. The libm identity
388`ldd` check of 3.1 is a red check: it must fail first against a deliberately different library path and
389then pass against the real trainer binary before Slice C merges.
390
391## 4. Slice D: syscall primitive and std-in-Omega
392
393### 4.1 Subset statement
394```
395syscall "(" expr {"," expr} ")" # 1 to 7 args: nr, a0..a5, all u64/i64, yields i64
396```
397`syscall` becomes a keyword (reserved today, src/compiler/osc_lex.c:25). Allowed
398only in units compiled with `oscc --allow-syscall` (same gate as externs).
399
400### 4.2 Lowering
401Native: load nr into x8, a0..a5 into x0..x5 (from slots), `SVC #0` (new op OSC_A64_SVC, word
4020xD4000001, UNVERIFIED pending docs-read), store x0 to dst; a failing call leaves -errno in x0.
403Interpreter: `syscall(2)` from glibc with the same six arguments; glibc returns -1 and sets errno,
404so the interpreter yields `r == -1 ? -errno : r` (no std/os.osc call returns -1 on success) and
405both engines agree on failing calls. A SYSCALL event (kind 12) folds nr, the six argument words and
406the result into `ev_hash` as EXTERN does (3.4). Determinism covers the same program, host and inputs only.
407
408### 4.3 std-in-Omega (one file, `std/os.osc`, no C)
409Numbers from /usr/include/asm-generic/unistd.h on this aarch64 box:
410`__NR_openat 56` (:158), `__NR_close 57` (:160), `__NR3264_lseek 62` (:170, `__NR_lseek` :864),
411`__NR_read 63` (:172), `__NR_write 64` (:174), `__NR_exit_group 94` (:260), `__NR_clock_gettime 113` (:318),
412`__NR_munmap 215` (:556), `__NR3264_mmap 222` (:570) with `__NR_mmap __NR3264_mmap` (:870).
413Functions: `write(fd, buf: &[u8], n) -> i64`, `openat(dirfd, path: &[u8], flags, mode) -> i64`,
414`read`, `close`, `lseek(fd, off, whence) -> i64`, `mmap(addr, len, prot, flags, fd, off) -> i64`,
415`munmap`, `clock_gettime(clk, out: &mut [u64]) -> i64` (length 2: tv_sec, tv_nsec), `exit_group(code)`.
416The shard size is `lseek(fd, 0, SEEK_END)` (SEEK_END 2, /usr/include/unistd.h:318), never hard-coded;
417fstat (`__NR3264_fstat 80`, :212) is left out because it needs the struct stat byte layout.
418Paths are NUL-terminated byte arrays. Slice pointers reach `syscall` as u64 through a gated `addr(s)`
419intrinsic (ADDR op). An `mmap` result becomes a slice through `slice_from(addr, len)`, legal only
420under `oscc --allow-syscall`; it traps on addr 0, misalignment for the element width or len * width
421overflow, the checks of `osc_ir_slice_args_ok` (src/compiler/osc_ir.c:705-720). UNVERIFIED whether
422the checker accepts it without a new unsafe-block form (`unsafe` is reserved, src/compiler/osc_lex.c:25).
423For acceptance 2 the harness maps the shard and passes it in as a slice.
424Exit status: oscc only compiles today (exit 0, 1 or 2, src/compiler/oscc_main.c:104-163). The new
425runner exits 100 + trap code (101..114) on a trap and std `exit_group` traps on codes >= 100, so a
426trap is never mistaken for `exit_group(0)`.
427
428### 4.4 Evidence
429Goldens hello_write.osc (returns 6), clock_monotonic.osc, mmap_anon_u16.osc
430(map 200 MB, fill, sum, unmap), exit_code.osc run as a child process, trap_exit.osc expecting
431exit 100 + k. Negatives: SYSCALL_GATED, `slice_from` without --allow-syscall.
432
433## 5. Slice E: long loops and runtime-length for
434
4351. `LOOP_BOUND_MAX` rises from 1000000 to 1<<40 (src/compiler/osc_parse.c:11,
436 :910-922, :936-944). The u64 counter lowering (src/compiler/osc_lower.c:509-540) needs
437 no change: `kconst lim` already takes a 64-bit immediate through `mat`.
4382. `for i in 0..len(s)` with a runtime u64 end: lowering emits the same counter
439 with a CMP against the slice length vreg instead of a literal; the parser's
440 literal-only rule (src/compiler/osc_parse.c:924-946) is relaxed to allow `len(IDENT)`.
441 The checker still proves: the induction variable is not assigned in the body,
442 the bound is a u64 known not to change (slice lengths are immutable), and the
443 trip count is at most the slice length, which is at most 2^40 by the host check.
4443. OSC_INTERP_MAX_STEPS (1<<32, src/compiler/osc_interp.h:17) becomes a run-time
445 parameter: 1<<32 for fuzz, 1<<44 for trainer runs. Native has no step cap; the
446 dual-run harness compares only programs that finish under the interpreter cap, as today.
4474. Evidence: loop_2p33.osc (2^33 iterations natively, interpreter skipped above the
448 cap and counted like `traces_skipped_overflow`, tests/compiler/test_osc_compiler.c:492),
449 for_len.osc over a 2^20 slice, negative LOOP_BOUND_RANGE for 1<<41.
450
451## 6. First Omega-written trainer piece and acceptance
452
4531. A+B acceptance: `adamw_step(pmv: &mut [f32], g: &[f32], hp: &[u64])` over 124_000_000
454 elements, in Omega. A slice takes two parameter registers (src/compiler/osc_parse.c:1070-1075),
455 so three slices use exactly the six of OSC_MAX_PARAMS (src/compiler/osc_ir.h:33). `pmv` holds p, m
456 and v back to back (3N elements, N = len(g)); hp[0] to hp[4] hold lr, b1, b2, eps, wd as f32 bit
457 patterns in the low 32 bits (read with `(hp[i] as u32) as f32 bits`) and hp[5] holds the step.
458 Oracle: a C file compiled with `-O0 -ffp-contract=off` doing the same operation order
459 (m = b1*m + (1-b1)*g; v = b2*v + (1-b2)*g*g; bias corrections 1 - b1^step and 1 - b2^step in
460 f32 by `step` repeated multiplies, no pow; p = p - lr*(mhat/(sqrt(vhat)+eps) + wd*p)).
461 Pass = all 124M output words identical by bit pattern, native and interpreter
462 (interpreter on N = 1M for time). UNVERIFIED: aien-lm-rs has no
463 AdamW and src/train/tg_sgd.h:1-3 defers Adam/AdamW, so the C oracle is the reference.
4642. C+D+E acceptance: a host trainer `train.osc` that takes a uint16 LE token shard (200 MB, size
465 from `lseek`, mapped by the harness for this run, 4.3), builds batches, calls `omega_gpu_matmul_f32`
466 and `omega_gpu_rmsnorm_f32` through `extern fn`, computes cross-entropy with `extern fn expf/logf`
467 (3.1) and the LR schedule in f32/f64, runs adamw_step, writes a log line per step with `write`,
468 exits 0. Pass = same loss bits per step as the Rust trainer for 20 steps on the same shard, same
469 exit code. `omega_gpu_matmul_f32` rounds f32 inputs to bf16 on the host, round-to-nearest-even
470 (src/omega_gpu_matmul_api.h:107-108), so both trainers must feed identical f32 inputs.
471
472## 7. Velocity and estimate
473
474From `git log --format='%h %ad %s' --date=short -- src/compiler docs/osc`:
475
476| Date | Commits | What shipped |
477|---|---|---|
478| 2026-09-29 | a927bd6c | OSC-0/0B freeze (#76) |
479| 2026-10-01 | b81f8500 | OSC-1 whole subset (#144), lane started 2026-09-29/30 |
480| 2026-10-01 | 0abdb08a 845dce4d c7736224 7e713e30 | OSC-2 items 1-4 (#148-#151), 09:13Z to 11:29Z |
481| 2026-10-01 | 38a6dea0 104541a7 334117d1 103ec7d4 | OSC-3 items 0-3 (#156 #166 #175), ext-bytes design |
482| 2026-10-02/04 | dce821cc 3c82389f cb7cc216 | VC1 stages 4, 6 (#223 #224), compiler crumb (#265) |
483| 2026-10-07/08 | e55e2af9 eb8dedf7 6eaac642 bcb9751a f7b43890 | ext-bytes impl and review fixes, oscc OUT |
484| 2026-10-12/13 | e0ff7201 fb13b3bb 18531691 5901baa5 | docs, explicit allocation (#435) |
485| 2026-10-14 | 1edf41a5 | strict IR decoder (#444/#449) |
486
487Reading: an OSC-2 or OSC-3 sized item ships in 1 to 3 hours of builder time; a
488whole subset (OSC-1) took about 2 calendar days; ext-bytes took 6 days from
489design to merge, mostly waiting. A review round (eb8dedf7) adds about half a day.
490
491Estimate, one builder agent per slice, in builder-days (working time including review rounds):
4921. Slice A floats: 2.5 days (encoder table with docs-read 0.5, IR+validator+interp 0.5,
493 lowering 0.5, lexer/parser/checker 0.5, fuzz and goldens 0.5). Main risk: encoder
494 word mistakes, mitigated by the objdump cross-check.
4952. Slice B buffers: 1.5 days, in parallel with A (f32/f64 element widths added when A merges).
4963. Slice C extern: 1.5 days after A (needs the FMOV ops and v0..v7 moves).
4974. Slice D syscall and std: 1 day after C's gating flag; parser work can start earlier.
4985. Slice E loops: 0.5 day, any time after B.
4996. Acceptance 1 (AdamW 124M): 1 day after A+B. Acceptance 2 (trainer): 2 days after
500 C+D+E, dominated by the Rust comparison and GPU time under the quiet lock.
501Critical path A (2.5) -> C (1.5) -> D (1) -> trainer acceptance (2) = 7 builder-days; with B, E
502and AdamW in parallel, all of OSC-4 is 7 to 9 builder-days. The git log shows 3 to 4 day gaps
503between pushes (10-04 to 10-07, 10-08 to 10-12), so plan 10 to 14 calendar days.
504
505## 8. Open questions
506
507For aien-dev-ba (GPU engine and compiler dispatcher):
5081. Exact names and C prototypes of the `tk_*` kernels the trainer must call (none in this repo).
5092. Is `omega_gpu_matmul_f32`'s host-side bf16 rounding stable across calls so a bit-exact oracle is possible?
5103. Which `OmegaGpuEwInfo` fields does the trainer read, so its byte size can be fixed in Omega?
5114. Who allocates the parameter buffers: Omega via mmap (Slice D) or the GPU engine returning host pointers?
512
513For the advisor:
5141. Accept "floats as bit patterns in X registers" for the OSC-internal ABI (no V-register ABI until a real need)?
5152. Accept no float traps (inf/NaN flow) as a permanent language rule or only for OSC-4?
5163. Gate `extern` and `syscall` behind oscc flags now, or wait for OSC-3 item 4 capabilities?
5174. Is a host-specific code SHA-256 for units with externs acceptable, given the IR SHA-256 stays reproducible?
5185. Should Slice B's `&[T]` replace `bytes`/`cells` names outright instead of aliasing them?
519
520## 9. Plain-language summary for Drake
521
5221. My own compiler can only count with whole numbers today. Training needs decimals, so the first job is teaching it decimal math.
5232. I do decimal math the plain way, one step at a time, never the "fast combined" way, so the slow checker and the fast machine code always get the same answer bit for bit.
5243. The compiler's arrays hold at most 64 numbers today. The trainer needs hundreds of millions, so I add a way to hand it big memory blocks and check every access.
5254. I let Omega programs call the existing GPU routines written in C, using the standard calling rules every program on this chip follows.
5265. I let Omega talk to Linux directly for files, memory and the clock, with the nine call numbers copied from the system's own header.
5276. Loops can run a trillion times instead of a million, and the checker still proves they end.
5287. Each piece ships as its own small change with failing tests written first and a random-program cross-check that must show zero disagreements.
5298. The first real proof is an Omega routine updating 124 million weights exactly like a reference C program, bit for bit.
5309. The second proof is a whole training loop written in Omega matching the Rust one for 20 steps.
53110. Honest estimate from past speed: 7 to 9 days of builder work, which is 10 to 14 days on the calendar once waiting for reviews is counted; 2.5 working days for the decimal-math piece alone.
532
533## Changes folded in (2026-10-16)
534
5351. Citations: 0.4 and 1.1 item 5 now osc_ir.h:37; 0.5 and 5 item 3 now osc_interp.h:17; 6.2 drops UNVERIFIED, cites :107-108.
5362. 1.1 item 6 states the minNum/maxNum rule; 1.3 item 11 has the interpreter spell it out, no fmin/fmax.
5373. 1.3 item 3 (-fno-math-errno, sqrt inlined), item 10 (NEG is `-x`), item 12 (strtof/strtod).
5384. 1.7 defines canon() for F32; 1.8 item 3 extends gen_arg with NaN, inf, -0.0 and subnormals.
5395. 3.2 items 2 and 4: extern table via OscRt `externs` at offset 104; no address in code.
5406. 3.2 item 5: EXTERN side table of up to 16 argument vregs; OscInsn unchanged.
5417. 3.4 (EXTERN event, kind 11) and 4.2 (SYSCALL event, kind 12) fold argument words into ev_hash.
5428. 4.2: interpreter returns `-errno` when glibc syscall() returns -1.
5439. 4.3: lseek 62 added (shard size via SEEK_END); fstat 80 verified but left out.
54410. 6.1: `adamw_step(pmv: &mut [f32], g: &[f32], hp: &[u64])`, three slices = six registers.
54511. 3.1 adds `extern fn expf/logf` with the glibc-shared assumption; 6.2 uses them for cross-entropy.
54612. 4.3: slice_from gated by --allow-syscall with osc_ir_slice_args_ok checks; clock_gettime takes `&mut [u64]` of length 2; 4.4 negative.
54713. 1.3 item 13 (doctrine amendment); 4.3 exit status 100 + trap code; 4.4 trap_exit.osc.
54814. 7 and 9 item 10: 7 to 9 builder-days, 10 to 14 calendar days.
549
550## Advisor review (Fable 5.1, 2026-10-16)
551
552Read-only review against commit 6c1827ba. No builds were run.
553
554### Claims checked against the source (12)
555
5561. Fixed scratch registers, no register allocator: confirmed. osc_cg.c:5-11 (header comment: slots at [sp,#8*(v+1)], operands in x9..x13, runtime via x16 BLR), osc_cg.c:104-106 (slot/ld/st helpers). Note OSC-1-DESIGN.md:208 says x9..x15; the code comment says x9..x13. Harmless, but pick one.
5572. OSC_MAX_ARRAY_LEN is 64: confirmed, but it lives at osc_ir.h:37, not :41 (:41 is OSC_MAX_FIELDS). Fix the three citations in sections 0.4, 1.1 and 1.5.
5583. OSC_IR_VERSION_MAX is 5: confirmed, osc_ir.h:257. unit_version picks the smallest: confirmed, osc_ir.c:612-618. Traps 1..14: confirmed, osc_ir.h:151-176. OscInsn.imm is uint64_t: confirmed, osc_ir.h:188.
5594. Cells pool and runtime table: confirmed. OSC_RT_SLOTS 64 at osc_rt.h:32, `cells[OSC_RT_SLOTS][OSC_MAX_ARRAY_LEN]` at :101, OscRtEvent.len uint16_t at :64, entry points at offsets 0..96 at :85-99, osc_rt_call_native at :148 and osc_rt.c:300, osc_rt_same_outcome at osc_rt.c:313-336.
5605. Interpreter arithmetic is integer only, no libm: confirmed. do_bin at osc_interp.c:49-65 uses i128 and canon(); no math.h is included anywhere in src/compiler. sload/sstore at :139-147 as cited.
5616. OSC_INTERP_MAX_STEPS is 1<<32: confirmed, but at osc_interp.h:17 (the file has 32 lines), not :402. Fix in sections 0.5 and 5.3.
5627. Ext-bytes code merged on main: confirmed. e55e2af9 and eb8dedf7 are both ancestors of HEAD and on main; OSC-EXT-BYTES-DESIGN.md:3 still says "on branch osh/osc-ext-bytes" (stale, as the design says).
5638. Build flags and harness: confirmed. OSC_CFLAGS at mk/compiler.mk:22 has no -ffp-contract=off; OSC_ASAN at :23; fuzz gates grep `mismatches=0` at :157-160; determinism.sh at :154. Dual-run compare at tests/compiler/test_osc_compiler.c:572-575 (osc_rt_same_outcome plus return value). mk/tensor.mk:24 and mk/omega-gpu-engine.mk:76 carry -ffp-contract=off as cited.
5649. Syscall numbers: all nine confirmed at the quoted lines of /usr/include/asm-generic/unistd.h (openat 56 :158, close 57 :160, read 63 :172, write 64 :174, exit_group 94 :260, clock_gettime 113 :318, munmap 215 :556, __NR3264_mmap 222 :570, mmap alias :870); the aarch64 header includes asm-generic at /usr/include/aarch64-linux-gnu/asm/unistd.h:25. gcc 13.3.0 and FLT_EVAL_METHOD 0 confirmed on this box.
56510. AAPCS64 claims: correct. x0..x7 and v0..v7 are argument registers, v8..v15 have callee-saved low halves, v16..v31 are caller-saved, x16 is a scratch IP register, x8 is the Linux syscall number register. Caveat: x7 is an argument register, so an extern with 8 integer-class args overwrites rt; the design's reload from [sp,#0] covers it.
56611. Velocity table: every hash and date confirmed by `git log --date=short` (a927bd6c 09-29; b81f8500 and the OSC-2/OSC-3 items 10-01; dce821cc/3c82389f 10-02; cb7cc216 10-04; e55e2af9..f7b43890 10-07/08; e0ff7201..5901baa5 10-12/13; 1edf41a5 10-14).
56712. bf16 host rounding: confirmed, src/omega_gpu_matmul_api.h:107-108 ("rounded to bf16 on the host first (round-to-nearest-even)"). The design's UNVERIFIED tag in 6.2 can be dropped. The Rust externs match (aien-lm-rs crates/aien-lm-sys/src/lib.rs:27-55). tg_sgd.h:1-3 defers Adam, as stated.
568
569Encoding cross-check against golden/aarch64_fp_golden: fmov d0,d1 = 0x1E604020, fmov d0,x1 = 0x9E670020, fmov x0,d1 = 0x9E660020, fadd d0,d1,d2 = 0x1E622820 (base 0x1e602800 at md:213), fcmp d0,d1 = 0x1E612000, fsqrt d0,d1 = 0x1E61C020, fcvt s0,d1 = 0x1E624020, scvtf d0,x1 = 0x9E620020, fcvtzs x0,d1 = 0x9E780020, ldr d0,[sp,#8] = 0xFD4007E0 (base 0xfd400000 at md:1149), ldr d0,[x1,x2,lsl #3] = 0xFC627820. All eleven match the design. Every base word in the 1.6 table that I looked up (FSUB, FMUL, FDIV, FMAXNM, FMINNM, FNEG, FABS, FCVT_DS, UCVTF, FCVTZU, FMOV_WS, FMOV_SW, STR_S/D_UOFF, LDR/STR_S_REG) also matches. No encoding mismatch found.
570
571### Judgement
572
5731. Floats as bit patterns in X registers: sound and the right call. The slot model, osc_rt_call_native and the harness stay untouched, and identity holds because both engines see the same 64-bit words. Two conditions: canon() for F32 must be "low 32 bits, upper zero, payload untouched" (the interpreter refuses non-canonical args at osc_interp.c:221), and gen_arg (test_osc_compiler.c:143) must emit float patterns including NaN, inf, -0.0 and subnormals.
5742. No float traps: consistent with decision 6. Inf and NaN are values, not invariant violations, and the result is deterministic on one host. Make it a permanent language rule, recorded as a one-line amendment to the doctrine, not an OSC-4 exception.
5753. -ffp-contract=off and FLT_EVAL_METHOD 0 are necessary but not sufficient. Four things must be stated or the interpreter will drift from native: (a) FMINNM/FMAXNM return the non-NaN operand when one side is a quiet NaN; the design's "NaN-propagating" is wrong, and C fmin/fmax must not be used; write the minNum rule out explicitly in C. (b) NEG must be `-x`, never `0.0 - x` (0.0 - (+0.0) is +0.0, FNEG gives -0.0). (c) sqrt is the only libm call; it is correctly rounded by IEEE so it matches FSQRT, but add -fno-math-errno so GCC inlines it. (d) f32 literals must be parsed with strtof, never strtod then cast (double rounding). Autovectorization is not a hazard here: AdvSIMD and scalar FP on AArch64 share FPCR and NaN rules, and the interpreter does one op per IR instruction anyway.
5764. Extern design: safe (static table, no dlsym, gated, load-time refusal). An extern is an effect under decision 6; logging an EXTERN event with the argument bits folded into ev_hash makes osc_rt_same_outcome cover it. Materialising the absolute address in code is the weak point: it makes the code SHA host-specific and breaks determinism.sh. Put the extern table pointer in OscRt as the next appended entry (offset 104) and call through `ldr x16,[x7slot]; ldr x16,[x16,#104]; ldr x16,[x16,#8*k]; blr x16`, the same shape osc_cg.c:10 already uses for runtime entries. Code SHA stays reproducible and no address lives in the code.
5775. Syscall slice: minimal and correctly numbered, with two gaps. glibc syscall(2) returns -1 and sets errno while the raw SVC returns -errno in x0; the interpreter must return `r == -1 ? -errno : r` or the two engines disagree on every failing call. And there is no way to learn the shard size: add lseek (62) or fstat (80).
5786. Ordering is right (A before C, B and E parallel). The estimate holds as builder-days; the git log shows 3 to 4 day gaps between pushes, so plan 10 to 14 calendar days and keep 7 to 9 as the builder figure.
5797. Missing items that would sink acceptance: (a) adamw_step as written needs 14 argument registers (4 slices = 8, plus 6 scalars); OSC_MAX_PARAMS is 6 (osc_ir.h:33), so it cannot be compiled; pack the five hyperparameters and step into one `&[f32]`/`&[u64]` pair or widen the ABI first. (b) EXTERN with up to 16 arguments does not fit OscInsn.args[OSC_MAX_PARAMS]; it needs its own argument storage. (c) Loss needs exp and log; without them train.osc cannot compute cross-entropy; use `extern fn expf/logf` from the same glibc the Rust trainer links (Rust lowers f32::exp to libm expf on linux-gnu), or take the loss from a GPU kernel. (d) `slice_from(addr, len)` is an unchecked soundness hole; gate it behind --allow-syscall, refuse addr 0 and len*width overflow (same checks as osc_ir_slice_args_ok), and let the harness map the shard for the acceptance run. (e) clock_gettime should fill a `&mut [u64]` of length 2, not bytes. (f) The oscc runner must map a trap to a distinct non-zero exit code so a trap is never mistaken for `exit_group(0)`.
580
581### Verdict: APPROVE WITH CHANGES
582
5831. Fix the citations: OSC_MAX_ARRAY_LEN is osc_ir.h:37; OSC_INTERP_MAX_STEPS is osc_interp.h:17; drop the UNVERIFIED tag on bf16 rounding (matmul_api.h:107-108).
5842. Correct 1.1.6 and 1.3: FMINNM/FMAXNM return the non-NaN side; the interpreter implements minNum/maxNum explicitly in C, never via fmin/fmax.
5853. State in 1.3 that interpreter NEG is `-x`, f32 literals use strtof, f64 use strtod, and -fno-math-errno joins -ffp-contract=off -fno-fast-math in OSC_CFLAGS.
5864. Define canon() for F32 (low 32 bits, payload preserved) and extend gen_arg with NaN, inf, -0.0 and subnormal patterns.
5875. Replace the materialised extern address with an extern table reached through an appended OscRt entry at offset 104, so the code SHA stays reproducible.
5886. Give the EXTERN instruction its own argument storage (up to 16) instead of OscInsn.args[OSC_MAX_PARAMS].
5897. Fold extern and syscall argument bits into the event hash so osc_rt_same_outcome catches a divergence.
5908. In 4.2, have the interpreter return `-errno` when glibc syscall() returns -1, matching the raw SVC result.
5919. Add lseek (62) or fstat (80) to std/os.osc so the shard size is not hard-coded.
59210. Rewrite the adamw_step acceptance signature to fit six parameter registers (hyperparameters in one slice) or make widening the ABI an explicit first step.
59311. Add `extern fn expf/logf` (or a GPU-side loss) to Slice C so train.osc can compute cross-entropy, and state the libm-identity assumption against the Rust build.
59412. Gate `slice_from` behind --allow-syscall with the osc_ir_slice_args_ok checks, and use `&mut [u64]` of length 2 for clock_gettime.
59513. Make "no float traps" a permanent rule by a one-line doctrine amendment, and require the oscc runner to map traps to a distinct non-zero exit code.
59614. Restate the estimate as 7 to 9 builder-days and 10 to 14 calendar days.
597
598## Reviewer conditions (aien-dev-ba, 2026-10-16)
599
600aien-dev-ba answered the three questions the advisor review left open. The answers are binding on
601Slices A and C; the affected sections (1.3 item 13, 3.1, 3.2 item 4, 3.4, 3.5) were rewritten to match.
602
6031. **OscRt grows by 16 bytes, not 8.** `externs` sits at offset 104 and `log_ext` at offset 112, so
604 host-side state moves 16 bytes. Slice C adds `_Static_assert`s for both offsets, `osc_rt_init`
605 initialises both fields (`externs = NULL`, `log_ext = osc_rt_log_ext`), every runner refuses an
606 extern-using unit while `externs` is NULL (EXTERN_NO_TABLE), and 3.4 now specifies how `log_ext`
607 receives up to 16 argument words plus the return word (a 17-word ext area in the frame, one pointer
608 argument, fold order ext_index, args, return).
6092. **inf and NaN as values.** The ADR OMEGA-SYSTEMS-CORE-0000 is frozen. Slice A does not edit the
610 text of decision 6; it appends a dated clarification note under decision 6 saying that inf and NaN
611 are ordinary values, not invariant violations, so float arithmetic raises no trap.
6123. **extern is an effect, with conditions.** No unwinding or longjmp from C: an extern never calls
613 `rt->trap`, it returns a status word. The static `{name, fnptr}` table is the allowlist.
614 `--allow-extern` is recorded in the unit header and compared by determinism.sh. A slice-taking
615 extern also takes an explicit `u64` length (EXTERN_SLICE_LEN otherwise). Effects are declared per
616 extern when OSC-3 item 4 ships, and the flag retires then. The libm identity `ldd` check (3.1) is a
617 red check in Slice C.