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 / tools / pi-drive-27b / specdraft.om

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