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 / native / control / src / reuse.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note KV reuse admission v1. This module hashes nothing and deserializes no payload. |
| 3 | note The store must hash the exact payload with its existing SHA-256 owner before calling. |
| 4 | note Header words 0..7: format,semantic-profile,prefix-tokens,context-size,layout,dtype,rope-profile,reserved. |
| 5 | note Seven four-word identities: model,weights,engine,tokenizer,scope,prefix-tokens,numeric-target-config. |
| 6 | note Saved words 36..39 are payload SHA-256. Expected words 36..39 must be zero. |
| 7 | |
| 8 | fn kvvalid p view ulong 40 to ulong |
| 9 | if ne get p 0 1 |
| 10 | ret 100 |
| 11 | end |
| 12 | if ne get p 7 0 |
| 13 | ret 102 |
| 14 | end |
| 15 | for i ulong 6 |
| 16 | if eq get p add i 1 0 |
| 17 | ret 103 |
| 18 | end |
| 19 | end |
| 20 | if gt get p 2 get p 3 |
| 21 | ret 103 |
| 22 | end |
| 23 | if gt get p 5 4 |
| 24 | ret 103 |
| 25 | end |
| 26 | for g ulong 7 |
| 27 | bits = ulong 0 |
| 28 | for j ulong 4 |
| 29 | bits = or bits get p add 8 add mul g 4 j |
| 30 | end |
| 31 | if eq bits 0 |
| 32 | ret 104 |
| 33 | end |
| 34 | end |
| 35 | ret 0 |
| 36 | end |
| 37 | |
| 38 | fn kvmatch s view ulong 40 w view ulong 40 h view ulong 4 to ulong |
| 39 | err = kvvalid s |
| 40 | if ne err 0 |
| 41 | ret err |
| 42 | end |
| 43 | err = kvvalid w |
| 44 | if ne err 0 |
| 45 | ret err |
| 46 | end |
| 47 | bits = ulong 0 |
| 48 | for i ulong 4 |
| 49 | if ne get w add i 36 0 |
| 50 | ret 128 |
| 51 | end |
| 52 | bits = or bits get s add i 36 |
| 53 | end |
| 54 | if eq bits 0 |
| 55 | ret 104 |
| 56 | end |
| 57 | for i ulong 6 |
| 58 | if ne get s add i 1 get w add i 1 |
| 59 | ret add 111 i |
| 60 | end |
| 61 | end |
| 62 | for g ulong 7 |
| 63 | diff = ulong 0 |
| 64 | for j ulong 4 |
| 65 | at = add 8 add mul g 4 j |
| 66 | diff = or diff xor get s at get w at |
| 67 | end |
| 68 | if ne diff 0 |
| 69 | ret add 120 g |
| 70 | end |
| 71 | end |
| 72 | diff = ulong 0 |
| 73 | for i ulong 4 |
| 74 | diff = or diff xor get s add i 36 get h i |
| 75 | end |
| 76 | if ne diff 0 |
| 77 | ret 127 |
| 78 | end |
| 79 | ret 0 |
| 80 | end |