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 / nvidia / checks / lib.om

278 lines · 5840 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/nvidia/checks/lib.om: the table reader every check of gpu/nvidia/checks shares. A check is the gpu/
3note units it tests, then this part, then the check's own part, concatenated (gpu/nvidia/checks/checks.tsv) and
4note compiled by seed/out/omc. Run: CHECK TABLE. The table holds one case per line, fields split by tabs; an
5note empty line or one starting with # is skipped. For each case main calls the check's `fn crow to bool` with
6note the fields of the case; false is a failed case. The check prints its own name in `fn cname to void` (a
7note text must be declared before its first use, so lib.om cannot name the check's text).
8note Output: one FAIL line per failed case (its line number and text), then NAME PASS rows=N (exit 0), or
9note NAME FAIL rows=N failed=F (exit 1). A table with no case fails. Exit 2: bad usage, a table that cannot be
10note read or held (enlarge refused), or a field the check cannot read (ckbad). The table and the field list
11note are run-time pools sized from the input; the path is at most 4095 bytes (Linux PATH_MAX less the 0).
12text t_ckusage "usage: CHECK TABLE\n"
13text t_ckread "check: cannot read the table, or the host refused memory to hold it\n"
14text t_ckbadf "check: unreadable field on line "
15text t_ckfail "FAIL line "
16text t_ckpass " PASS rows="
17text t_ckfl " FAIL rows="
18text t_ckfd " failed="
19global ck_t uchar *
20global ck_fs ulong *
21global ck_fe ulong *
22global ck_p uchar 4096
23global ck_o uchar 65536
24global ck_n ulong 16
25note ck_n: 0 table length, 1 output length, 2 fields in the row, 3 line number, 4 rows, 5 failed
26fn ckflush to void
27o = ulong 0
28n = get ck_n 1
29while lt o n bound 65537
30x = write 1 ck_o o sub n o
31if le x 0
32exit 2
33end
34o = add o ulong x
35end
36put ck_n 1 0
37end
38fn ckoc c ulong to void
39n = get ck_n 1
40if ge n len ck_o
41ckflush
42n = 0
43end
44put ck_o n uchar c
45put ck_n 1 add n 1
46end
47note lib.om is OM-1 so that it composes with units of either profile (an OM-1 unit may use words OM-2 reserves,
48note such as layout); OM-1 has no unsized view, so a text is never passed: ckout k prints lib's own text k (0 FAIL
49note line, 1 PASS rows=, 2 FAIL rows=, 3 failed=), and a check prints its name with ckoc in its own cname
50fn ckout k ulong to void
51if eq k 0
52for i ulong len t_ckfail bound 64
53ckoc ulong get t_ckfail i
54end
55end
56if eq k 1
57for i ulong len t_ckpass bound 64
58ckoc ulong get t_ckpass i
59end
60end
61if eq k 2
62for i ulong len t_ckfl bound 64
63ckoc ulong get t_ckfl i
64end
65end
66if eq k 3
67for i ulong len t_ckfd bound 64
68ckoc ulong get t_ckfd i
69end
70end
71end
72fn cknumo v ulong to void
73if ge v 10
74cknumo div v 10
75end
76ckoc add 48 rem v 10
77end
78note exit 2 with lib's own message k: 0 usage, 1 the table cannot be read or held
79fn ckrefuse k ulong to void
80ckflush
81if eq k 0
82r = write 2 t_ckusage 0 len t_ckusage
83end
84if eq k 1
85r = write 2 t_ckread 0 len t_ckread
86end
87exit 2
88end
89note a field the check cannot read: exit 2 naming the line (a broken table is not a failed case)
90fn ckbad to void
91ckflush
92r = write 2 t_ckbadf 0 len t_ckbadf
93cknumo get ck_n 3
94ckoc 10
95r = write 2 ck_o 0 get ck_n 1
96exit 2
97end
98fn ckcnt to ulong
99ret get ck_n 2
100end
101fn cklen i ulong to ulong
102if ge i get ck_n 2
103ckbad
104end
105ret sub get ck_fe i get ck_fs i
106end
107note byte j of field i
108fn ckch i ulong j ulong to ulong
109if ge j cklen i
110ckbad
111end
112ret ulong get ck_t add get ck_fs i j
113end
114note field i as an unsigned decimal below 2^64; anything else is ckbad
115fn cknum i ulong to ulong
116n = cklen i
117if or eq n 0 gt n 20
118ckbad
119end
120v = ulong 0
121for j ulong n bound 20
122c = ckch i j
123if or lt c 48 gt c 57
124ckbad
125end
126d = sub c 48
127if gt v div sub 18446744073709551615 d 10
128ckbad
129end
130v = add mul v 10 d
131end
132ret v
133end
134fn cknib c ulong to ulong
135if and ge c 48 le c 57
136ret sub c 48
137end
138if and ge c 97 le c 102
139ret sub c 87
140end
141ckbad
142ret 0
143end
144note field i as lowercase hex bytes: their count (0 for "-"); ckhex i j is byte j
145fn ckhexn i ulong to ulong
146n = cklen i
147if and eq n 1 eq ckch i 0 45
148ret 0
149end
150if or eq n 0 ne rem n 2 0
151ckbad
152end
153ret div n 2
154end
155fn ckhex i ulong j ulong to ulong
156hi = cknib ckch i mul j 2
157lo = cknib ckch i add mul j 2 1
158ret or shl hi 4 lo
159end
160note field slot k exists in ck_fs and ck_fe
161fn ckslot k ulong to void
162if lt k len ck_fs
163ret
164end
165n = mul add k 1 2
166r = enlarge ck_fs n
167q = enlarge ck_fe n
168if or lt r 0 lt q 0
169ckrefuse 1
170end
171end
172note split ck_t[s, e) at tabs into ck_fs/ck_fe
173fn cksplit s ulong e ulong to void
174k = ulong 0
175ckslot 0
176put ck_fs 0 s
177i = s
178while lt i e bound 1099511627776
179if eq get ck_t i 9
180put ck_fe k i
181k = add k 1
182ckslot k
183put ck_fs k add i 1
184end
185i = add i 1
186end
187put ck_fe k e
188put ck_n 2 add k 1
189end
190fn ckline s ulong e ulong to void
191if or eq s e eq get ck_t s 35
192ret
193end
194cksplit s e
195put ck_n 4 add get ck_n 4 1
196if not crow
197put ck_n 5 add get ck_n 5 1
198ckout 0
199cknumo get ck_n 3
200ckoc 58
201ckoc 32
202for j ulong sub e s bound 1099511627776
203c = ulong get ck_t add s j
204if eq c 9
205c = 32
206end
207ckoc c
208end
209ckoc 10
210end
211end
212note read the file named by argument 1 into ck_t, growing it as the file needs; its length
213fn ckload to ulong
214p = argread 1 ck_p 0 4095
215if lt p 1
216ckrefuse 0
217end
218fd = fopen ck_p 0 ulong p int 524288 int 0
219if lt fd 0
220ckrefuse 1
221end
222n = ulong 0
223while true bound 1099511627776
224if eq n len ck_t
225g = add mul n 2 65536
226r = enlarge ck_t g
227if lt r 0
228ckrefuse 1
229end
230end
231x = read int fd ck_t n sub len ck_t n
232if lt x 0
233ckrefuse 1
234end
235if eq x 0
236break
237end
238n = add n ulong x
239end
240r = fclose int fd
241ret n
242end
243fn main to int
244if ne argcnt 2
245ckrefuse 0
246end
247n = ckload
248put ck_n 0 n
249s = ulong 0
250line = ulong 1
251while lt s n bound 1099511627776
252e = s
253while and lt e n ne get ck_t e 10 bound 1099511627776
254e = add e 1
255end
256put ck_n 3 line
257ckline s e
258s = add e 1
259line = add line 1
260end
261f = get ck_n 5
262ckrows = get ck_n 4
263cname
264if and eq f 0 gt ckrows 0
265ckout 1
266cknumo ckrows
267ckoc 10
268ckflush
269ret 0
270end
271ckout 2
272cknumo ckrows
273ckout 3
274cknumo f
275ckoc 10
276ckflush
277ret 1
278end