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
omega-mv / docs / numeric / E1_SCALAR_CONTRACT.md
| 1 | # E1 scalar contract (WP-A) |
| 2 | |
| 3 | What each E1 scalar op must return, and where it runs today. Closes rows 1, 3 |
| 4 | and 4 of `E1_GAP_TABLE.md` for the CPU tier only. |
| 5 | |
| 6 | ## Rules for every op |
| 7 | |
| 8 | - Inputs and outputs are 32-bit words. Rounding is round to nearest, ties to |
| 9 | even. Subnormals are kept on input and output (no flush to zero). |
| 10 | - The FPCR must have FZ, DN, AH, FIZ, NEP, FZ16, AHP clear and RMode = RNE |
| 11 | (`OMEGA_NUMERIC_FPCR_REQUIRED_CLEAR`). The host tiers refuse otherwise. |
| 12 | - A NaN result is compared by class (any NaN equals any NaN). Payload and |
| 13 | the quiet bit are not part of the contract. |
| 14 | - Host `libm` defines nothing. The reference is integer code on bit patterns. |
| 15 | |
| 16 | ## The ops |
| 17 | |
| 18 | | Op | Result | Compared as | |
| 19 | |---|---|---| |
| 20 | | `FSETP_<P>_SEL` | `P(a, b) ? a : b`, the chosen word moved unchanged (NaN payload and the sign of zero kept) | `INT_EXACT` | |
| 21 | | `F2I_FLOOR` / `F2I_CEIL` / `F2I_RNI` | int32 of `a` rounded down / up / to nearest even; NaN gives 0; out of range saturates to `INT32_MIN` / `INT32_MAX` | `INT_EXACT` | |
| 22 | | `F2U` | uint32 of `a` toward zero; NaN and every negative give 0; above range gives `0xffffffff` | `INT_EXACT` | |
| 23 | | `I2FP_U32` | the bits of `a` read as uint32, converted to FP32 (RNE) | `BIT_EXACT` | |
| 24 | | `F32_TO_F16` | binary16 of `a` in bits [15:0], bits [31:16] zero; RNE; 65520 and above round to inf | `F16_BITS` | |
| 25 | | `F32_TO_BF16` | bfloat16 of `a` in bits [15:0], bits [31:16] zero; RNE; overflow rounds to inf | `BF16_BITS` | |
| 26 | | `F16_TO_F32` / `BF16_TO_F32` | exact FP32 of the 16-bit value in bits [15:0] of `a`; bits [31:16] ignored | `BIT_EXACT` | |
| 27 | | `FFMA_V` | `a * b + c` with one rounding, `c` read per element; exact zero sums are +0 unless both terms are -0 | `BIT_EXACT` | |
| 28 | |
| 29 | The 13 predicates `P`, with U meaning "also true when a or b is NaN" |
| 30 | (-0 equals +0 in all of them): |
| 31 | |
| 32 | | P | LT | LE | GT | EQ | NE | NUM | NAN | LTU | LEU | GTU | GEU | EQU | NEU | |
| 33 | |---|---|---|---|---|---|---|---|---|---|---|---|---|---| |
| 34 | | a < b | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | |
| 35 | | a == b | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | |
| 36 | | a > b | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | |
| 37 | | unordered | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
| 38 | |
| 39 | `F16_BITS` / `BF16_BITS`: both words must have bits [31:16] zero; a 16-bit NaN |
| 40 | equals any 16-bit NaN; everything else must match bit for bit |
| 41 | (`omega_numeric_compare_equal`). |
| 42 | |
| 43 | ## Status |
| 44 | |
| 45 | | Op | CPU tier | Independent of the reference? | GB10 | |
| 46 | |---|---|---|---| |
| 47 | | 13 `FSETP_*_SEL` | `fcmp` + `fcsel` (NE, EQU: two `fcsel`) | yes | encoded: `FSETP.<P>.AND P0` + `FSEL R9, R2, R5, P0` | |
| 48 | | `F2I_FLOOR` / `CEIL` / `RNI` | `fcvtms` / `fcvtps` / `fcvtns` | yes | encoded: `F2I.FLOOR.NTZ` / `F2I.CEIL.NTZ` / `F2I.NTZ` (variable latency, STG waits on its scoreboard) | |
| 49 | | `F2U` | `fcvtzu` | yes | encoded: `F2I.U32.TRUNC.NTZ` (variable latency) | |
| 50 | | `I2FP_U32` | `ucvtf` | yes | encoded: `I2FP.F32.U32` (fixed latency) | |
| 51 | | `F32_TO_F16` / `F16_TO_F32` | `fcvt` between `s` and `h` registers | yes | encoded: `F2F.F16.F32` (variable latency, stored unmasked: the hardware must write bits [31:16] = 0, which `F16_BITS` parity checks on every element) / `HADD2.F32 R9, -RZ, R2.H0_H0` (the ptxas form of `cvt.f32.f16`) | |
| 52 | | `F32_TO_BF16` | `bfcvt` (refused at run time if the CPU lacks BF16) | yes | encoded: `F2F.BF16.F32` (variable latency, stored unmasked; `BF16_BITS` parity checks bits [31:16] = 0) | |
| 53 | | `BF16_TO_F32` | 16-bit shift | **no**: AArch64 has no scalar BF16 widening instruction, so the CPU tier is the same shift the definition is; the oracle is the separate check | encoded: `SHF.L.U32 R9, R2, 0x10, RZ`, the ptxas form of `cvt.f32.bf16`. **Not an independent hardware conversion**: it is the same 16-bit shift as the definition | |
| 54 | | `FFMA_V` | `fmadd` with per-element `c` | yes (the reference is a 128-bit integer fma) | encoded: `LDC.64 R10, c[0x0][0x3a0]` (the c pointer, kernel argument words 8..9), `IMAD.WIDE.U32 R10, R9, 0x4, R10`, `LDG.E R11`, `FFMA R9, R2, R5, R11` | |
| 55 | |
| 56 | GB10 encodings were added by E1 WP-C. Every instruction word decodes under |
| 57 | nvdisasm 13.0.88 `-b SM121` to the intended instruction (provenance table in |
| 58 | `src/omega_numeric_provenance.c`); control words follow ptxas 13.0.88 sm_121 |
| 59 | output. The structural checker (`omega_numeric_check_patch`) refuses a patch |
| 60 | whose compare code, conversion mode or latency class does not match the op, |
| 61 | whose first instruction does not wait on the a/b loads, whose multi-instruction |
| 62 | form does not end with the STG + EXIT pair, or whose FFMA_V c path is not |
| 63 | LDC.64 R10 / IMAD.WIDE.U32 / LDG.E R11 (both scoreboarded) / FFMA R9, R2, R5, R11, |
| 64 | or in which an instruction that sets a scoreboard stalls fewer than 2 cycles |
| 65 | before its waiter. That last rule comes from the chip: the first Gate 5 run |
| 66 | (2026-10-01, FAIL receipt `evidence/OMEGA-NUMERIC-0/d40f37f9f653e631b4c5e4b8c69dc8951b5bb0e74d4f102cb711441e718f111a.json`, run on omega `b0c7b9c`, added to the repository on 2026-10-01 as a new file; its name is its internal `receipt_digest`, the file itself hashes to `ef5db55e...`) had the c load stall 1 cycle, the FFMA did not |
| 67 | see the barrier and read the stale address word (2349 of 4096 mismatches); with |
| 68 | stall 4 a chip diagnostic gave 4096 of 4096 correct. Gate 5 then PASSED on |
| 69 | omega 7211b59 + physics e95e3ed (receipt f4f6d362..., in |
| 70 | evidence/OMEGA-NUMERIC-0/): all 23 E1 scalar ops zero mismatches at n=4096. |
| 71 | Fixed-latency instructions must also stall at least 5 cycles (the chip-proven |
| 72 | ptxas value) and the FFMA_V LDG and IMAD words are checked in full. |
| 73 | The checker is structural only: it cannot show that a word computes the right |
| 74 | value. "Encoded" is not "correct on the chip": GB10 parity for each op |
| 75 | is one Gate 5 parity line at n=4096 with zero mismatches under the manifest |
| 76 | compare mode (`tests/run_numeric_gates.sh`, now 38 ops), recorded in the |
| 77 | chip receipt. |
| 78 | |
| 79 | ## How it is checked |
| 80 | |
| 81 | Three derivations per element: the integer reference (`src/omega_numeric.c`), |
| 82 | the CPU tier (AArch64 instructions, same file) and a second integer oracle |
| 83 | written differently (`tests/numeric_oracle.h`). |
| 84 | |
| 85 | - `E1_SCALAR_BOUNDARY_VALUES`: hand-worked cases (ties, saturation, subnormal |
| 86 | edges, overflow to inf, the fused-rounding cases of `FFMA_V`) plus every |
| 87 | predicate on 12 pairs covering less, equal (including -0 and +0), greater |
| 88 | and unordered. Expected bits are written out, not computed. |
| 89 | - `E1_SCALAR_CPU_EQUALS_REFERENCE`: 2^22 structured random inputs per op (about 96 million in all) |
| 90 | (random bits, integer and F16/BF16 ties, subnormals, near-max, NaN and inf, |
| 91 | equal and cancelling partners) and all 65536 inputs of the widening ops. |
| 92 | - `E1_SCALAR_INDEPENDENT_ORACLE`: the same inputs, oracle against both tiers. |
| 93 | - `make test-numeric-e1-exhaustive`: every 2^32 input of the nine unary ops |
| 94 | through all three derivations. Not part of Gate 5. |
| 95 | - `tools/numeric_oracle_mutations.sh` breaks the RNI tie rule in the |
| 96 | reference, the GTU condition in the CPU tier and the sticky bit of the |
| 97 | integer fma, and proves each is caught. |