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 / tools / pi-drive-27b / specdraft.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note tools/pi-drive-27b/specdraft.om -- pure Omega (OM-1) L2-resident CPU prompt-lookup |
| 3 | note speculative drafter for GB10 CPU+GPU co-execution (Cortex-X925, <128 KiB static state). |
| 4 | note Library unit (no fn main); concatenate ahead of a driver unit and compile with seed/out/omc. |
| 5 | |
| 6 | const SDCAP ulong 8192 |
| 7 | const SDMASK ulong 8191 |
| 8 | const SDMAXK ulong 8 |
| 9 | const SDMAXN ulong 4 |
| 10 | |
| 11 | note Static state: 64 KiB token ring + 176 B buffers/counters = 65712 B (<128 KiB L2 resident). |
| 12 | global sdctx ulong 8192 |
| 13 | global sdlen ulong 1 |
| 14 | global sddraftbuf ulong 8 |
| 15 | global sdtgtbuf ulong 9 |
| 16 | global sdtotal_draft ulong 1 |
| 17 | global sdtotal_acc ulong 1 |
| 18 | global sdsteps ulong 1 |
| 19 | global sdlast_ng ulong 1 |
| 20 | |
| 21 | note Reset ring state, draft/target buffers, and acceptance counters. |
| 22 | fn sdreset to void |
| 23 | put sdlen 0 0 |
| 24 | put sdtotal_draft 0 0 |
| 25 | put sdtotal_acc 0 0 |
| 26 | put sdsteps 0 0 |
| 27 | put sdlast_ng 0 0 |
| 28 | i = ulong 0 |
| 29 | while lt i SDMAXK bound 8 |
| 30 | put sddraftbuf i 0 |
| 31 | i = add i 1 |
| 32 | end |
| 33 | j = ulong 0 |
| 34 | while lt j 9 bound 9 |
| 35 | put sdtgtbuf j 0 |
| 36 | j = add j 1 |
| 37 | end |
| 38 | k = ulong 0 |
| 39 | while lt k SDCAP bound 8192 |
| 40 | put sdctx k 0 |
| 41 | k = add k 1 |
| 42 | end |
| 43 | end |
| 44 | |
| 45 | note Append one token to the bounded 8192-token ring and advance monotonic sdlen. |
| 46 | fn sdpush tok ulong to void |
| 47 | n = get sdlen 0 |
| 48 | idx = and n SDMASK |
| 49 | put sdctx idx tok |
| 50 | put sdlen 0 add n 1 |
| 51 | end |
| 52 | |
| 53 | note Read token at logical position pos from the ring. |
| 54 | fn sdget pos ulong to ulong |
| 55 | idx = and pos SDMASK |
| 56 | ret get sdctx idx |
| 57 | end |
| 58 | |
| 59 | note Earliest live logical position retained in the 8192-token ring. |
| 60 | fn sdstart to ulong |
| 61 | n = get sdlen 0 |
| 62 | if gt n SDCAP |
| 63 | ret sub n SDCAP |
| 64 | end |
| 65 | ret 0 |
| 66 | end |
| 67 | |
| 68 | note Compare ng-gram at logical pos against suffix at logical suf. |
| 69 | fn sdmatch pos ulong suf ulong ng ulong to bool |
| 70 | i = ulong 0 |
| 71 | while lt i ng bound 4 |
| 72 | a = sdget add pos i |
| 73 | b = sdget add suf i |
| 74 | if ne a b |
| 75 | ret false |
| 76 | end |
| 77 | i = add i 1 |
| 78 | end |
| 79 | ret true |
| 80 | end |
| 81 | |
| 82 | note Search backwards in live ring [sdstart..sdlen) for prior match of current ng-gram suffix. |
| 83 | note Returns continuation start pos + ng (>0 and <sdlen) on hit, or 0 on miss. |
| 84 | fn sdfind ng ulong to ulong |
| 85 | n = get sdlen 0 |
| 86 | lo = sdstart |
| 87 | live = sub n lo |
| 88 | if le live ng |
| 89 | ret 0 |
| 90 | end |
| 91 | suf = sub n ng |
| 92 | rcnt = sub suf lo |
| 93 | off = ulong 1 |
| 94 | while le off rcnt bound 8192 |
| 95 | pos = sub suf off |
| 96 | if sdmatch pos suf ng |
| 97 | ret add pos ng |
| 98 | end |
| 99 | off = add off 1 |
| 100 | end |
| 101 | ret 0 |
| 102 | end |
| 103 | |
| 104 | note Propose up to k (<= 8) draft tokens into sddraftbuf by searching backwards for |
| 105 | note longest matching suffix of length 4, 3, 2, then 1. Returns drafted count 0..k. |
| 106 | fn sddraft k ulong to ulong |
| 107 | put sdlast_ng 0 0 |
| 108 | if eq k 0 |
| 109 | ret 0 |
| 110 | end |
| 111 | if gt k SDMAXK |
| 112 | ret 0 |
| 113 | end |
| 114 | n = get sdlen 0 |
| 115 | if lt n 2 |
| 116 | ret 0 |
| 117 | end |
| 118 | src = ulong 0 |
| 119 | ng = SDMAXN |
| 120 | while gt ng 0 bound 4 |
| 121 | src = sdfind ng |
| 122 | if gt src 0 |
| 123 | put sdlast_ng 0 ng |
| 124 | break |
| 125 | end |
| 126 | ng = sub ng 1 |
| 127 | end |
| 128 | if eq src 0 |
| 129 | ret 0 |
| 130 | end |
| 131 | avail = sub n src |
| 132 | cnt = k |
| 133 | if lt avail cnt |
| 134 | cnt = avail |
| 135 | end |
| 136 | i = ulong 0 |
| 137 | while lt i cnt bound 8 |
| 138 | tok = sdget add src i |
| 139 | put sddraftbuf i tok |
| 140 | i = add i 1 |
| 141 | end |
| 142 | ret cnt |
| 143 | end |
| 144 | |
| 145 | note Verify n drafted tokens in sddraftbuf against n+1 target tokens in sdtgtbuf. |
| 146 | note Finds first mismatch m, commits m accepted draft tokens + target token at m into sdctx, |
| 147 | note updates sdtotal_draft, sdtotal_acc, sdsteps, and returns total committed tokens (m + 1). |
| 148 | fn sdverify n ulong to ulong |
| 149 | if gt n SDMAXK |
| 150 | ret 0 |
| 151 | end |
| 152 | m = ulong 0 |
| 153 | while lt m n bound 8 |
| 154 | d = get sddraftbuf m |
| 155 | t = get sdtgtbuf m |
| 156 | if ne d t |
| 157 | break |
| 158 | end |
| 159 | m = add m 1 |
| 160 | end |
| 161 | commit = add m 1 |
| 162 | i = ulong 0 |
| 163 | while lt i commit bound 9 |
| 164 | tok = get sdtgtbuf i |
| 165 | sdpush tok |
| 166 | i = add i 1 |
| 167 | end |
| 168 | td = get sdtotal_draft 0 |
| 169 | put sdtotal_draft 0 add td n |
| 170 | ta = get sdtotal_acc 0 |
| 171 | put sdtotal_acc 0 add ta m |
| 172 | st = get sdsteps 0 |
| 173 | put sdsteps 0 add st 1 |
| 174 | ret commit |
| 175 | end |