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 / gpu / runtime / nativeh.om

502 lines · 11784 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/runtime/nativeh.om: CUDApp src/cudapp_native.h (the C declarations of every Omega Bridge unit, written by
3note CUDApp om/units.sh) regenerated in seeded Omega (OM-2 program mode, Linux AArch64) from the Omega source in
4note this tree. Build from the repository root:
5note { printf 'om2\n'; cat seed/ng/sha256.om gpu/runtime/zsha.om gpu/runtime/nativeh.om; } | seed/out/omc > nativeh
6note Run from the repository root with no argument. Inputs:
7note gpu/runtime/cudapp-units.ident CUDApp src/cudapp_om_units.ident unchanged: one omega-ident 2 line per unit,
8note in the order units.sh declares them. Its sha256 must equal that file's row
9note in gpu/runtime/cudapp-src.sha256.txt, or nothing is written (exit 3).
10note gpu/runtime/pathmap.tsv CUDApp Omega path prefix TAB where it lives here (as the inventory reads it)
11note the Omega source parts the path= value of each line names, mapped through pathmap.tsv
12note Output on stdout: the fixed head units.sh writes, then per unit, the parts composed each followed by a newline
13note (units.sh's composition): the line nh_rv when the abi is bridge-seeded-runtime or the composition starts with
14note the line om2, then the declaration of the last fn of the composition (its root): name omega_ROOT, result
15note uint64_t *result (one space before * for a bridge-freest unit without a view or edit parameter, two otherwise),
16note then per parameter: view T EXT is const void *pK, uint64_t pK_n; edit T EXT is void *pK, uint64_t pK_n;
17note f32 is float pK; any other scalar is uint64_t pK. Then the fixed tail.
18note A unit with a part that is not in this tree is left out and named on stderr ("nativeh: absent part ..."); the
19note output is then CUDApp's header less that unit's lines.
20note Exit 0, 3 an input is unreadable or malformed or the units list is not CUDApp's, 4 the host refused memory.
21note Memory grows with the input (run-time pools); the one fixed buffer is a path of PATH_MAX (4096) bytes.
22text nh_funits "gpu/runtime/cudapp-units.ident"
23text nh_fsrc "gpu/runtime/cudapp-src.sha256.txt"
24text nh_fmap "gpu/runtime/pathmap.tsv"
25text nh_kunits "src/cudapp_om_units.ident"
26text nh_kid "omega-ident 2 "
27text nh_kabi "abi="
28text nh_kpath "path="
29text nh_kfn "fn "
30text nh_kom2 "om2\n"
31text nh_kto "to"
32text nh_kview "view"
33text nh_kedit "edit"
34text nh_kf32 "f32"
35text nh_abirt "bridge-seeded-runtime"
36text nh_abifr "bridge-freest"
37text nh_h1 "/* Generated checked portable Omega declarations. Regenerate with om/units.sh.\n"
38text nh_h2 " * Status: 0 done, 1..14 trap, 32 argument refused, 33 reentry.\n"
39text nh_h3 " * Only a successful call writes result. Fixed views use the declared length.\n"
40text nh_h4 " * Runtime-extent units pass the live count under the bridge runtime-views profile.\n"
41text nh_h5 " * Implementation is Omega lowered by omega-bridge, not the native AArch64 ABI. */\n"
42text nh_h6 "#ifndef CUDAPP_PORTABLE_OMEGA_H\n#define CUDAPP_PORTABLE_OMEGA_H\n#include <stdint.h>\n"
43text nh_h7 "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"
44text nh_h8 "#define OMEGA_OK 0u\n#define OMEGA_BAD_ARG 32u\n#define OMEGA_REENTRY 33u\n"
45text nh_rv "/* Omega Bridge runtime views: numeric extents are capacities; * is unsized. */\n"
46text nh_d0 "uint32_t omega_"
47text nh_d1 "(uint64_t "
48text nh_d2 "*result"
49text nh_pv ", const void *p"
50text nh_pe ", void *p"
51text nh_ps ", uint64_t p"
52text nh_pf ", float p"
53text nh_pn "_n"
54text nh_d3 ");\n"
55text nh_tail "#ifdef __cplusplus\n}\n#endif\n#endif\n"
56text nh_e_read "nativeh: cannot read "
57text nh_e_list "nativeh: gpu/runtime/cudapp-src.sha256.txt has no well-formed row for src/cudapp_om_units.ident\n"
58text nh_e_units "nativeh: gpu/runtime/cudapp-units.ident is not CUDApp's src/cudapp_om_units.ident (its sha256 differs from the row in gpu/runtime/cudapp-src.sha256.txt): copy it again\n"
59text nh_e_rec "nativeh: malformed line in gpu/runtime/cudapp-units.ident\n"
60text nh_e_fn "nativeh: no fn line of the expected form in the composition of "
61text nh_e_abs "nativeh: absent part "
62text nh_e_mem "nativeh: the host refused memory\n"
63text nh_e_long "nativeh: a path is longer than 4095 bytes\n"
64global nh_t uchar *
65global nh_o uchar *
66global nh_k ulong *
67global nh_pa uchar 4096
68global nh_n ulong 32
69note nh_n: 0 path length, 2 nh_t used, 3 nh_o used, 4..9 input ranges [s,e) of units, src list, pathmap;
70note 10, 11 a token [s,e); 12 a part is absent; 13 parameters in nh_k; 14 an array parameter; 15, 16 root name [s,e)
71note ---- failure
72fn die t view uchar * code int to void
73r = write 2 t 0 len t
74exit code
75end
76fn nlerr to void
77q = new uchar 1 10
78r = write 2 q 0 1
79end
80note ---- output pool
81fn oc c ulong to void
82n = get nh_n 3
83if ge n len nh_o
84r = enlarge nh_o add mul n 2 65536
85if ne r 0
86die nh_e_mem 4
87end
88end
89put nh_o n uchar c
90put nh_n 3 add n 1
91end
92fn ot t view uchar * to void
93for i ulong len t bound 4096
94oc ulong get t i
95end
96end
97fn otr a ulong b ulong to void
98for i ulong sub b a bound 9223372036854775807
99oc ulong get nh_t add a i
100end
101end
102fn onum v ulong to void
103if ge v 10
104onum div v 10
105end
106oc add 48 rem v 10
107end
108fn oflush to void
109n = get nh_n 3
110o = ulong 0
111while lt o n bound 9223372036854775807
112x = write 1 nh_o o sub n o
113if le x 0
114exit 3
115end
116o = add o ulong x
117end
118put nh_n 3 0
119end
120note ---- paths: nh_pa[0, nh_n 0)
121fn pc c ulong to void
122n = get nh_n 0
123if ge n 4095
124die nh_e_long 3
125end
126put nh_pa n uchar c
127put nh_n 0 add n 1
128end
129fn pt t view uchar * to void
130put nh_n 0 0
131for i ulong len t bound 4096
132pc ulong get t i
133end
134end
135fn ptr a ulong b ulong to void
136for i ulong sub b a bound 9223372036854775807
137pc ulong get nh_t add a i
138end
139end
140fn diepa t view uchar * to void
141r = write 2 t 0 len t
142r = write 2 nh_pa 0 get nh_n 0
143nlerr
144exit 3
145end
146note ---- input pool: append the file at nh_pa to nh_t; false when it cannot be opened
147fn tgrow n ulong to void
148if ge add n 65536 len nh_t
149r = enlarge nh_t add mul len nh_t 2 131072
150if ne r 0
151die nh_e_mem 4
152end
153end
154end
155fn tappend to bool
156fd = int fopen nh_pa 0 get nh_n 0 int 524288 int 0
157if lt fd 0
158ret false
159end
160n = get nh_n 2
161while true bound 9223372036854775807
162tgrow n
163x = read fd nh_t n sub len nh_t n
164if lt x 0
165diepa nh_e_read
166end
167if eq x 0
168break
169end
170n = add n ulong x
171end
172r = fclose fd
173put nh_n 2 n
174ret true
175end
176fn tbyte c ulong to void
177n = get nh_n 2
178tgrow n
179put nh_t n uchar c
180put nh_n 2 add n 1
181end
182note load the file named t into slots k, k+1
183fn tload t view uchar * k ulong to void
184pt t
185s = get nh_n 2
186if not tappend
187diepa nh_e_read
188end
189put nh_n k s
190put nh_n add k 1 get nh_n 2
191end
192note ---- bytes of nh_t
193fn eol p ulong e ulong to ulong
194q = p
195while lt q e bound 9223372036854775807
196if eq get nh_t q 10
197ret q
198end
199q = add q 1
200end
201ret e
202end
203fn tfind p ulong e ulong c ulong to ulong
204q = p
205while lt q e bound 9223372036854775807
206if eq ulong get nh_t q c
207ret q
208end
209q = add q 1
210end
211ret e
212end
213fn tteq a ulong n ulong t view uchar * to bool
214if ne n len t
215ret false
216end
217for i ulong n bound 4096
218if ne get nh_t add a i get t i
219ret false
220end
221end
222ret true
223end
224fn tpre a ulong e ulong t view uchar * to bool
225if lt sub e a len t
226ret false
227end
228ret tteq a len t t
229end
230note the value of the space-separated field kw= in [ls, lz) into slots 10, 11; false when there is none
231fn tokval ls ulong lz ulong kw view uchar * to bool
232a = ls
233while lt a lz bound 9223372036854775807
234b = tfind a lz 32
235if tpre a b kw
236put nh_n 10 add a len kw
237put nh_n 11 b
238ret true
239end
240a = add b 1
241end
242ret false
243end
244note ---- the units list must be CUDApp's: its sha256 against the src list row
245fn hexeq p ulong to bool
246for j ulong 32
247b = uint get sh_dig j
248if ne get nh_t add p mul j 2 sh_hexd uint shr b 4
249ret false
250end
251if ne get nh_t add add p mul j 2 1 sh_hexd uint and b 15
252ret false
253end
254end
255ret true
256end
257fn unitsok to void
258zbeg
259s = get nh_n 4
260for i ulong sub get nh_n 5 s bound 9223372036854775807
261zbyte ulong get nh_t add s i
262end
263zend
264p = get nh_n 6
265e = get nh_n 7
266while lt p e bound 9223372036854775807
267q = eol p e
268if ge sub q p 67
269if tteq add p 66 sub q add p 66 nh_kunits
270if hexeq p
271ret
272end
273die nh_e_units 3
274end
275end
276p = add q 1
277end
278die nh_e_list 3
279end
280fn tteqr a ulong b ulong n ulong to bool
281for i ulong n bound 9223372036854775807
282if ne get nh_t add a i get nh_t add b i
283ret false
284end
285end
286ret true
287end
288note ---- one part [a, b) of a path= value: mapped through pathmap.tsv into nh_pa
289fn pmap a ulong b ulong to void
290put nh_n 0 0
291p = get nh_n 8
292e = get nh_n 9
293while lt p e bound 9223372036854775807
294q = eol p e
295if and ne p q ne get nh_t p 35
296t = tfind p q 9
297if le sub t p sub b a
298if tteqr p a sub t p
299ptr add t 1 q
300ptr add a sub t p b
301ret
302end
303end
304end
305p = add q 1
306end
307ptr a b
308end
309note compose the parts of the path= value [s, e) at the end of nh_t; false (named on stderr) when one is absent
310fn ncompose s ulong e ulong to bool
311a = s
312while lt a e bound 9223372036854775807
313b = tfind a e 44
314pmap a b
315if not tappend
316r = write 2 nh_e_abs 0 len nh_e_abs
317r = write 2 nh_pa 0 get nh_n 0
318nlerr
319ret false
320end
321tbyte 10
322a = add b 1
323end
324ret true
325end
326note ---- the root: the last line of [s, e) starting with fn
327fn lastfn s ulong e ulong to ulong
328f = e
329p = s
330while lt p e bound 9223372036854775807
331q = eol p e
332if tpre p q nh_kfn
333f = p
334end
335p = add q 1
336end
337ret f
338end
339fn skipsp p ulong e ulong to ulong
340q = p
341while and lt q e eq get nh_t q 32 bound 9223372036854775807
342q = add q 1
343end
344ret q
345end
346note parameter kind into nh_k: 0 scalar, 1 view, 2 edit, 3 f32
347fn kput v ulong to void
348n = get nh_n 13
349if ge n len nh_k
350r = enlarge nh_k add mul n 2 64
351if ne r 0
352die nh_e_mem 4
353end
354end
355put nh_k n v
356put nh_n 13 add n 1
357end
358note the parameter whose name token ends at p in the fn line [., q): its kind into nh_k; the position after it
359fn nparam p ulong q ulong to ulong
360a = skipsp p q
361b = tfind a q 32
362if eq a b
363ret q
364end
365if or tteq a sub b a nh_kview tteq a sub b a nh_kedit
366k = ulong 1
367if tteq a sub b a nh_kedit
368k = 2
369end
370put nh_n 14 1
371kput k
372c = tfind skipsp b q q 32
373ret tfind skipsp c q q 32
374end
375if tteq a sub b a nh_kf32
376kput 3
377else
378kput 0
379end
380ret b
381end
382note read the fn line at f: root name into slots 15, 16, parameter kinds into nh_k; false when malformed
383fn nsig f ulong e ulong to bool
384q = eol f e
385a = skipsp add f len nh_kfn q
386b = tfind a q 32
387if eq a b
388ret false
389end
390put nh_n 15 a
391put nh_n 16 b
392put nh_n 13 0
393put nh_n 14 0
394p = b
395while lt p q bound 9223372036854775807
396a = skipsp p q
397c = tfind a q 32
398if tteq a sub c a nh_kto
399ret true
400end
401p = nparam c q
402end
403ret false
404end
405fn odecl fr bool to void
406ot nh_d0
407otr get nh_n 15 get nh_n 16
408ot nh_d1
409if not and fr eq get nh_n 14 0
410oc 32
411end
412ot nh_d2
413for k ulong get nh_n 13 bound 9223372036854775807
414v = get nh_k k
415if eq v 1
416ot nh_pv
417else
418if eq v 2
419ot nh_pe
420else
421if eq v 3
422ot nh_pf
423else
424ot nh_ps
425end
426end
427end
428onum k
429if or eq v 1 eq v 2
430ot nh_ps
431onum k
432ot nh_pn
433end
434end
435ot nh_d3
436end
437note one line [ls, lz) of the units list
438fn nunit ls ulong lz ulong to void
439if not tpre ls lz nh_kid
440die nh_e_rec 3
441end
442if not tokval ls lz nh_kabi
443die nh_e_rec 3
444end
445rt = tteq get nh_n 10 sub get nh_n 11 get nh_n 10 nh_abirt
446fr = tteq get nh_n 10 sub get nh_n 11 get nh_n 10 nh_abifr
447if not tokval ls lz nh_kpath
448die nh_e_rec 3
449end
450s = get nh_n 10
451e = get nh_n 11
452x = tfind s e 61
453if lt x e
454s = add x 1
455end
456if eq s e
457die nh_e_rec 3
458end
459c0 = get nh_n 2
460if ncompose s e
461c1 = get nh_n 2
462f = lastfn c0 c1
463if or eq f c1 not nsig f c1
464r = write 2 nh_e_fn 0 len nh_e_fn
465r = write 2 nh_t s sub e s
466nlerr
467exit 3
468end
469if or rt tpre c0 c1 nh_kom2
470ot nh_rv
471end
472odecl fr
473end
474put nh_n 2 c0
475end
476fn main to int
477tload nh_funits 4
478tload nh_fsrc 6
479tload nh_fmap 8
480unitsok
481ot nh_h1
482ot nh_h2
483ot nh_h3
484ot nh_h4
485ot nh_h5
486ot nh_h6
487ot nh_h7
488ot nh_h8
489p = get nh_n 4
490e = get nh_n 5
491while lt p e bound 9223372036854775807
492q = eol p e
493if eq q e
494die nh_e_rec 3
495end
496nunit p q
497p = add q 1
498end
499ot nh_tail
500oflush
501ret 0
502end