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 / seed / ng / ngcheck.om

2373 lines · 46991 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note seed/ng/ngcheck.om: the ΩIR witness (seed/ng/IR.md s9, s11). Owner: ng-ir lane (Hive NG M0).
3note It has its own reader: no code is shared with seed/ng/src/ir.om or opt.om (D1b). Build:
4note cat seed/ng/sha256.om seed/ng/ngcheck.om | seed/out/omc > ngcheck
5note ngcheck < unit.ir exit 0 and "ACCEPT <sha256> fns=N blocks=N ops=N" on stdout, or exit with
6note the refusal class (10..29) and "ngcheck: CLASS at OFFSET" on stderr
7note ngcheck --table print the host word table compiled in (equal to seed/ng/hostwords.tsv)
8note Order (IR.md s11): phase 1 reads the module front to back and checks every rule that needs only
9note the bytes of one record (header, type table, globals, function and block headers, op rows and
10note counts); phase 2 checks each function in order: terminators, branch targets, reachability,
11note then each op in block and op order (ids and dominance, token, result type, placement, codes,
12note typing, coverage, facts). The first fault ends the run.
13text c_cls "MAGIC\nVERSION\nTRUNCATED\nNONCANONICAL\nTRAILING\nUNKNOWN_OP\nTYPE\nUSE_BEFORE_DEF\nDOMINANCE\nBLOCK_ARITY\nUNTERMINATED\nCHECK_CODE\nEFFECT\nLIMIT\nREF\nUNCHECKED\nUNREACHABLE\nIO\nTOKEN\nFACT\nENTRY\n"
14const c_hxn ulong 52
15text c_tx "ngcheck: \n at \nACCEPT \n fns=\n blocks=\n ops=\n--table\nngcheck: usage: ngcheck [--table] < unit.ir\nOSC1IR\nomega.ng.ir.v1\n"
16note the op rows of IR.md s7.12: op tk imm fix var ty (tk 0 P 1 E 2 R 3 T; ty 0 none 1 r 2 o 3 p)
17text c_rows "1 0 1 0 0 1 2 0 0 3 0 1 10 0 0 2 0 1 11 0 0 2 0 1 12 0 0 2 0 1 13 0 0 2 0 1 14 0 0 2 0 1 15 0 0 1 0 1 16 0 0 2 0 1 17 0 0 2 0 1 18 0 0 2 0 1 19 0 0 1 0 1 20 0 0 2 0 1 21 0 0 2 0 1 22 0 0 2 0 1 23 0 0 2 0 1 24 0 0 2 0 1 25 0 0 2 0 1 26 0 0 1 0 1 27 0 0 1 0 1 28 0 1 1 0 1 30 0 0 2 0 1 31 0 0 2 0 1 32 0 0 2 0 1 33 0 0 2 0 1 34 0 0 2 0 1 35 0 0 2 0 1 36 0 1 1 0 1 37 0 0 1 0 1 40 0 1 0 0 1 41 0 0 0 0 1 42 2 0 2 0 1 43 1 0 3 0 0 44 1 0 0 0 0 45 0 1 2 0 1 46 0 0 3 0 1 47 1 1 3 0 1 48 1 1 4 0 1 50 1 0 0 0 1 51 1 0 2 0 0 52 0 1 0 0 1 53 0 0 1 0 1 54 2 0 3 0 1 55 2 1 1 0 1 56 1 1 2 0 0 57 0 1 1 0 1 58 2 0 2 0 1 59 1 0 3 0 0 60 3 0 1 1 0 61 3 0 3 0 0 62 3 0 0 0 0 63 3 0 1 0 0 64 1 0 1 1 2 65 3 1 0 0 0 66 3 0 1 0 0 67 1 0 4 1 0 70 1 1 2 0 0 71 1 1 2 0 0 72 1 1 2 0 0 73 1 1 1 0 0 74 1 1 1 0 0 75 1 1 2 0 0 76 1 1 2 0 0 77 1 1 1 0 0 78 1 1 1 0 3 79 1 1 3 0 0 80 1 1 3 0 0 81 1 1 2 0 0 82 1 1 1 0 0 90 0 1 1 0 0 91 0 1 3 0 0 92 0 1 3 0 0 93 0 1 3 0 0 100 0 0 1 0 1 101 0 1 1 0 1 102 0 1 2 0 1 103 0 1 1 0 1 104 2 1 4 0 1 105 1 1 5 0 0 106 0 1 3 0 1 110 1 1 0 1 2 111 1 1 1 0 1 112 2 1 0 0 1 113 2 1 1 0 1 114 1 1 2 0 0 115 1 1 3 0 1 116 1 1 3 0 1"
18note seed/ng/hostwords.tsv, byte for byte (the gate compares ngcheck --table with the file), then the rows of
19note seed/ng/hostwords-ng.tsv: ng's own words, which omc does not have (IR.md s7.11). --table prints the first only:
20note c_hxn is the length of the second, 52 bytes
21text c_hwt "id\tword\targs\tclass\n53\tread\tiw\tio\n54\twrite\tir\tio\n100\tfclose\ti\tfs\n101\tfsync\ti\tfs\n102\tfchmod\tii\tfs\n103\tfseek\tili\tfs\n104\tsocknew\tiii\tnet\n105\tlisten\tii\tnet\n106\taccept\tii\tnet\n107\tfork\t-\tproc\n108\tdupfd\tiii\tproc\n109\tmonons\t-\ttime\n110\tfopen\trii\tfs\n111\tunlink\tr\tfs\n112\tmakedir\tri\tfs\n113\tgetdnts\tiw\tfs\n114\tconnect\tir\tnet\n115\tbind\tir\tnet\n116\twaitpid\tiwi\tproc\n117\tfstat\tiw\tfs\n118\trecv\tiwi\tio\n119\tsend\tiri\tio\n120\tsleepns\tl\ttime\n121\targcnt\t-\tenv\n122\targread\tLw\tenv\n123\twaitio\tiil\tio\n124\texecprog\tr\tproc\n125\trenames\tri\tfs\n126\trmdir\tr\tfs\n127\tkillpid\tii\tproc\n128\tpipefds\twi\tproc\n129\tgetpid\t-\tproc\n130\trealns\t-\ttime\n131\tsockname\tiw\tnet\n132\tcwd\tw\tfs\n133\treadlnk\trw\tfs\n134\tsockopt\tiiir\tnet\n135\trandom\twi\tenv\n136\tenvcnt\t-\tenv\n137\tenvread\tLw\tenv\n138\tchdir\tr\tfs\n139\tftrunc\til\tfs\n140\tstat\trw\tfs\n141\tlink\tr\tfs\n142\tsymlnk\tr\tfs\n143\tchmod\tri\tfs\n144\tfaccess\tri\tfs\n145\tgetuid\t-\tproc\n146\tgeteuid\t-\tproc\n147\tgetgid\t-\tproc\n148\tgetegid\t-\tproc\n149\tlstat\trw\tfs\n150\ttruncate\trl\tfs\n151\tchown\trii\tfs\n153\tfchdir\ti\tfs\n154\tgetppid\t-\tproc\n155\tumask\ti\tfs\n156\tfdsync\ti\tfs\n157\tmemfd\tri\tfs\n158\tsetsid\t-\tproc\n159\tgetpgid\ti\tproc\n160\tsetpgid\tii\tproc\n161\tpread\tiwl\tio\n162\tpwrite\tirl\tio\n163\tgetsid\ti\tproc\n164\tsyncfs\ti\tfs\n165\tshutdown\tii\tnet\n166\tdevctl\tiuw\tdev\n167\tmapnew\tiLLii\tdev\n168\tmapdrop\tl\tdev\n169\tmapread\tlLw\tdev\n170\tmapwrite\tlLr\tdev\n171\tdevcall\tiuww\tdev\n172\tuvmctl\tiuw\tdev\n173\tmapaddr\tl\tdev\n174\tmapget\tlLi\tdev\n175\tmapset\tlLiL\tdev\n176\tmaphold\tLL\tdev\n177\tmapbind\tliLi\tdev\n197\tflock\tii\tfs\n198\texecpure\tr\tproc\n199\tcpufence\t-\tcpu\n200\tcpurelax\t-\tcpu\n220\tpeercred\tiw\tnet\n221\tpollfds\twl\tio\n222\tsendmsg\tiri\tnet\n224\tpeername\tiw\tnet\n228\tvfioctl\tiuS\tdev\n229\tvfiomap\tir\tdev\n230\tvfiomapw\tir\tdev\n231\teventfd\tu\tdev\n232\tvfioirq\tiuw\tdev\n233\texecenv\trr\tproc\n235\tprlimit\tiiw\tlimit\n236\tcpuset\tir\tsched\n237\tcpuget\tiw\tsched\n238\tcpunow\t-\tsched\n239\tsetprio\tiii\tsched\n240\tgetprio\tii\tsched\n241\tlibfn\ti\tlib\n242\tlibptr\tw\tlib\n243\tlibcall\tLw\tlib\n"
22global c_s ulong 4
23global c_n ulong 16
24global c_f ulong 16
25global c_q ulong 16
26global c_ob uchar 32
27global c_ab uchar 256
28global c_rok uchar 256
29global c_rtk uchar 256
30global c_rim uchar 256
31global c_rfx uchar 256
32global c_rva uchar 256
33global c_rty uchar 256
34global c_hok uchar 256
35global c_hcp uchar 256
36global c_has uint 256
37global c_hal uint 256
38global c_tk uchar 65568
39global c_t1 uint 65568
40global c_t2 uint 65568
41global c_t3 uint 65568
42global c_t4 uint 65568
43global c_t5 uint 65568
44global c_tsz ulong 65568
45global c_xty uint 65536
46global c_xof uint 65536
47global c_xor uchar 65536
48global c_th uint 131072
49global c_gty uint 65536
50global c_gcl uchar 65536
51global c_fk uchar 65536
52global c_ffl uchar 65536
53global c_fnp uint 65536
54global c_fp0 uint 65536
55global c_frs uint 65536
56global c_fsg uchar 65536
57global c_fb0 uint 65536
58global c_fnb uint 65536
59global c_fof uint 65536
60global c_fpt uint 4194304
61global c_bnp uint 1048576
62global c_bp0 uint 1048576
63global c_bo0 uint 1048576
64global c_bno uint 1048576
65global c_bof uint 1048576
66global c_bpt uint 4194304
67global c_oop uchar 4194304
68global c_oty uint 4194304
69global c_oim ulong 4194304
70global c_ona uint 4194304
71global c_oa0 uint 4194304
72global c_oof uint 4194304
73global c_ov uint 4194304
74global c_opb uint 4194304
75global c_opp uint 4194304
76global c_cvn uint 4194304
77global c_arg uint 4194304
78global c_vty uint 2097152
79global c_vb uint 2097152
80global c_vp uint 2097152
81global c_vo uint 2097152
82global c_cvh uint 2097152
83global c_s1 uint 65536
84global c_s2 uint 65536
85global c_bv0 uint 65536
86global c_vis uchar 65536
87global c_stk uint 65536
88global c_sti uchar 65536
89global c_rpo uint 65536
90global c_ord uint 65536
91global c_pc uint 65537
92global c_pst uint 65537
93global c_pfl uint 65537
94global c_pl uint 131072
95global c_idm uint 65536
96global c_dch uint 65536
97global c_dsb uint 65536
98global c_dnx uint 65536
99global c_pre uint 65536
100global c_pos uint 65536
101note ---- output ----------------------------------------------------------------------------------
102fn ck_txt k ulong fd int to void
103s = ulong 0
104c = ulong 1
105for i ulong len c_tx
106if eq get c_tx i 10
107if eq c k
108r = write fd c_tx s sub i s
109ret
110end
111c = add c 1
112s = add i 1
113end
114end
115end
116fn ck_cname k ulong to void
117s = ulong 0
118c = ulong 1
119for i ulong len c_cls
120if eq get c_cls i 10
121if eq c k
122r = write 2 c_cls s sub i s
123ret
124end
125c = add c 1
126s = add i 1
127end
128end
129end
130fn ck_num v ulong fd int to void
131x = v
132i = ulong 32
133for j ulong 21
134i = sub i 1
135put c_ob i uchar add 48 rem x 10
136x = div x 10
137if eq x 0
138r = write fd c_ob i sub 32 i
139ret
140end
141end
142end
143fn ck_nl fd int to void
144put c_ob 0 10
145r = write fd c_ob 0 1
146end
147fn ck_bad c ulong off ulong to void
148ck_txt 1 2
149ck_cname sub c 9
150ck_txt 2 2
151ck_num off 2
152ck_nl 2
153exit int c
154end
155note refuse with class c at the offset of the op being checked (c_q 12)
156fn ck_fail c ulong to void
157ck_bad c ulong get c_oof get c_q 12
158end
159fn ck_want b bool c ulong to void
160if not b
161ck_fail c
162end
163end
164note ---- reading primitives (cursor c_s 0, end c_s 1) ---------------------------------------------
165fn ck_at to ulong
166ret get c_s 0
167end
168fn ck_need k ulong to ulong
169p = get c_s 0
170if gt add p k get c_s 1
171ck_bad 12 p
172end
173put c_s 0 add p k
174ret p
175end
176fn ck_u8 to ulong
177p = ck_need 1
178ret ulong get sh_dat p
179end
180fn ck_u16 to ulong
181p = ck_need 2
182v = ulong get sh_dat p
183ret or v shl ulong get sh_dat add p 1 8
184end
185fn ck_un k ulong to ulong
186p = ck_need k
187v = ulong 0
188for j ulong k bound 8
189x = ulong get sh_dat add p j
190v = or v shl x mul j 8
191end
192ret v
193end
194fn ck_u32 to ulong
195ret ck_un 4
196end
197fn ck_u64 to ulong
198ret ck_un 8
199end
200note ---- init: op rows and host words ----------------------------------------------------------
201fn ck_rows to void
202p = ulong 0
203for r ulong 256
204if ge p len c_rows
205ret
206end
207op = ck_dec p
208p = get c_q 15
209put c_rok op 1
210put c_rtk op uchar ck_dec p
211p = get c_q 15
212put c_rim op uchar ck_dec p
213p = get c_q 15
214put c_rfx op uchar ck_dec p
215p = get c_q 15
216put c_rva op uchar ck_dec p
217p = get c_q 15
218put c_rty op uchar ck_dec p
219p = get c_q 15
220end
221end
222note decimal number in c_rows at p (skipping separators); the next position goes to c_q 15
223fn ck_dec p ulong to ulong
224i = p
225while lt get c_rows i 48 bound 8
226i = add i 1
227end
228v = ulong 0
229while lt i len c_rows bound 12
230c = get c_rows i
231if or lt c 48 gt c 57
232break
233end
234v = add mul v 10 ulong sub c 48
235i = add i 1
236end
237put c_q 15 i
238ret v
239end
240note host words: skip the header line, then "id\tword\targs\tclass\n" rows
241fn ck_hosts to void
242p = ck_hnext 0
243while lt p len c_hwt bound 256
244p = ck_hrow p
245end
246end
247fn ck_hnext p ulong to ulong
248i = p
249while lt i len c_hwt bound 4096
250if eq get c_hwt i 10
251ret add i 1
252end
253i = add i 1
254end
255ret i
256end
257fn ck_hfld p ulong to ulong
258i = p
259while lt i len c_hwt bound 4096
260if eq get c_hwt i 9
261ret i
262end
263i = add i 1
264end
265ret i
266end
267fn ck_hrow p ulong to ulong
268v = ulong 0
269i = p
270while ne get c_hwt i 9 bound 4
271v = add mul v 10 ulong sub get c_hwt i 48
272i = add i 1
273end
274i = ck_hfld add i 1
275a = add i 1
276e = ck_hfld a
277put c_hok v 1
278put c_has v uint a
279if ne get c_hwt a 45
280put c_hal v uint sub e a
281end
282if and eq get c_hwt add e 1 99 eq get c_hwt add e 2 112
283put c_hcp v 1
284end
285ret ck_hnext e
286end
287note ---- header ------------------------------------------------------------------------------------
288fn ck_head to void
289n = get c_s 1
290for j ulong 7
291if ge j n
292ck_bad 12 0
293end
294if lt j 6
295if ne get sh_dat j get c_tx add 96 j
296ck_bad 10 0
297end
298else
299if ne get sh_dat j 0
300ck_bad 10 0
301end
302end
303end
304put c_s 0 7
305if ne ck_u8 9
306ck_bad 11 7
307end
308p = ck_need 16
309for j ulong 16
310c = get sh_dat add 8 j
311if lt j 14
312if ne c get c_tx add 103 j
313ck_bad 11 8
314end
315else
316if ne c 0
317ck_bad 11 8
318end
319end
320end
321end
322note ---- type predicates (ids are validated before these are used) -----------------------------
323fn ck_sb t ulong to ulong
324if or eq t 1 eq t 2
325ret 1
326end
327if or eq t 6 or eq t 18 eq t 19
328ret 1
329end
330if or eq t 3 or eq t 7 or eq t 16 eq t 17
331ret 2
332end
333if or eq t 4 or eq t 8 eq t 13
334ret 4
335end
336if or eq t 5 or eq t 9 eq t 14
337ret 8
338end
339ret 0
340end
341fn ck_kd t ulong to ulong
342if lt t 32
343ret 0
344end
345if ge t add 32 get c_n 0
346ret 255
347end
348ret ulong get c_tk t
349end
350fn ck_g1 t ulong to ulong
351if lt t 32
352ret 0
353end
354ret ulong get c_t1 t
355end
356fn ck_g2 t ulong to ulong
357if lt t 32
358ret 0
359end
360ret ulong get c_t2 t
361end
362fn ck_g3 t ulong to ulong
363if lt t 32
364ret 0
365end
366ret ulong get c_t3 t
367end
368fn ck_g4 t ulong to ulong
369if lt t 32
370ret 0
371end
372ret ulong get c_t4 t
373end
374fn ck_g5 t ulong to ulong
375if lt t 32
376ret 0
377end
378ret ulong get c_t5 t
379end
380fn ck_isint t ulong to bool
381ret and ge t 2 le t 9
382end
383fn ck_issgn t ulong to bool
384ret and ge t 6 le t 9
385end
386fn ck_isuns t ulong to bool
387ret and ge t 2 le t 5
388end
389fn ck_isflt t ulong to bool
390ret or or eq t 13 eq t 14 or eq t 16 eq t 17
391end
392fn ck_isar t ulong to bool
393ret or ck_isint t ck_isflt t
394end
395fn ck_isnum t ulong to bool
396ret or ck_isar t or eq t 18 eq t 19
397end
398note the lane element of a scalar or VEC type
399fn ck_el t ulong to ulong
400if eq ck_kd t 1
401ret ck_g1 t
402end
403ret t
404end
405fn ck_lanes t ulong to ulong
406if eq ck_kd t 1
407ret ck_g2 t
408end
409ret 1
410end
411note byte size of a memory element type (scalar, VEC, ARRAY, STRUCT)
412fn ck_size t ulong to ulong
413if lt t 32
414ret ck_sb t
415end
416ret get c_tsz t
417end
418note the element type of a REF to an ARRAY or of a SLICE, else 0
419fn ck_relt r ulong to ulong
420k = ck_kd r
421if eq k 5
422ret ck_g1 r
423end
424if eq k 4
425a = ck_g1 r
426if eq ck_kd a 2
427ret ck_g1 a
428end
429end
430ret 0
431end
432note a type id usable as a value type: scalar, VEC, REF, SLICE, FRAG (never tok, void, ARRAY, STRUCT)
433note returns 0 when it is, else the class (24 an absent table id, 16 otherwise)
434fn ck_vtc t ulong to ulong
435if lt t 32
436if eq ck_sb t 0
437ret 16
438end
439ret 0
440end
441k = ck_kd t
442if eq k 255
443ret 24
444end
445if or eq k 2 eq k 3
446ret 16
447end
448ret 0
449end
450note ---- type table (phase 1); every fault is reported at the entry's offset ---------------------
451fn ck_types to void
452o = ck_at
453n = ck_u32
454if gt n 65536
455ck_bad 23 o
456end
457for k ulong n bound 65536
458ck_type add k 32
459end
460end
461fn ck_type t ulong to void
462o = ck_at
463kd = ck_u8
464put c_tk t uchar kd
465if or eq kd 0 gt kd 6
466ck_bad 13 o
467end
468if eq kd 1
469ck_tvec t o
470end
471if eq kd 2
472ck_tarr t o
473end
474if eq kd 3
475ck_tstr t o
476end
477if or eq kd 4 eq kd 5
478ck_tref t o kd
479end
480if eq kd 6
481ck_tfrg t o
482end
483put c_n 0 sub t 31
484ck_tdup t o
485end
486note a type id referenced from entry t: a scalar id or an earlier entry
487fn ck_tid x ulong t ulong o ulong to void
488if ge x 32
489if ge x t
490ck_bad 24 o
491end
492ret
493end
494if eq ck_sb x 0
495ck_bad 16 o
496end
497end
498fn ck_tvec t ulong o ulong to void
499e = ck_u32
500l = ck_u32
501ck_tid e t o
502if not or eq e 1 or ck_isint e ck_isflt e
503ck_bad 16 o
504end
505if or or lt l 2 gt l 64 ne and l sub l 1 0
506ck_bad 16 o
507end
508if gt mul l ck_sb e 64
509ck_bad 16 o
510end
511put c_t1 t uint e
512put c_t2 t uint l
513put c_tsz t mul l ck_sb e
514end
515fn ck_tarr t ulong o ulong to void
516e = ck_u32
517c = ck_u32
518ck_tid e t o
519k = ck_kd e
520if not or ck_isnum e or eq k 1 eq k 3
521ck_bad 16 o
522end
523if or eq c 0 gt c 16777216
524ck_bad 16 o
525end
526put c_t1 t uint e
527put c_t2 t uint c
528put c_tsz t mul c ck_size e
529end
530fn ck_tstr t ulong o ulong to void
531sz = ck_u32
532no = ck_at
533nf = ck_u32
534if or eq sz 0 gt sz 1073741824
535ck_bad 16 o
536end
537if eq nf 0
538ck_bad 16 o
539end
540if gt nf 64
541ck_bad 23 no
542end
543f0 = get c_n 1
544if gt add f0 nf 65536
545ck_bad 23 no
546end
547put c_t1 t uint sz
548put c_t2 t uint nf
549put c_t3 t uint f0
550put c_tsz t sz
551put c_q 14 0
552for j ulong nf bound 64
553ck_tfld t o add f0 j
554end
555put c_n 1 add f0 nf
556if gt get c_q 14 sz
557ck_bad 16 o
558end
559end
560note field x of struct t; c_q 14 is the end of the previous field
561fn ck_tfld t ulong o ulong x ulong to void
562ft = ck_u32
563of = ck_u32
564od = ck_u8
565ck_tid ft t o
566k = ck_kd ft
567if not or ck_isnum ft or eq k 2 eq k 3
568ck_bad 16 o
569end
570if gt od 1
571ck_bad 13 o
572end
573if and eq od 1 ge ft 32
574ck_bad 13 o
575end
576if lt of get c_q 14
577ck_bad 16 o
578end
579put c_q 14 add of ck_size ft
580put c_xty x uint ft
581put c_xof x uint of
582put c_xor x uchar od
583end
584fn ck_tref t ulong o ulong kd ulong to void
585x = ck_u32
586ac = ck_u8
587sp = ck_u8
588ck_tid x t o
589k = ck_kd x
590if eq kd 4
591if not or eq k 2 eq k 3
592ck_bad 16 o
593end
594else
595if not or ck_isnum x or eq k 1 eq k 3
596ck_bad 16 o
597end
598end
599if or gt ac 1 gt sp 4
600ck_bad 13 o
601end
602if and eq sp 3 eq ac 1
603ck_bad 16 o
604end
605put c_t1 t uint x
606put c_t2 t uint ac
607put c_t3 t uint sp
608end
609fn ck_tfrg t ulong o ulong to void
610ro = ck_u8
611m = ck_u16
612n = ck_u16
613k = ck_u16
614e = ck_u32
615if gt ro 2
616ck_bad 13 o
617end
618if or or eq m 0 gt m 256 or eq n 0 gt n 256
619ck_bad 16 o
620end
621if or eq k 0 gt k 256
622ck_bad 16 o
623end
624ck_tid e t o
625if not ck_isnum e
626ck_bad 16 o
627end
628put c_t1 t uint ro
629put c_t2 t uint m
630put c_t3 t uint n
631put c_t4 t uint k
632put c_t5 t uint e
633end
634note duplicate entries (NONCANONICAL): open hash over the entry's contents
635fn ck_thash t ulong to ulong
636h = ulong get c_tk t
637h = add mul h 1000003 ulong get c_t1 t
638h = add mul h 1000003 ulong get c_t2 t
639if eq get c_tk t 3
640f0 = ulong get c_t3 t
641for j ulong ulong get c_t2 t bound 64
642x = add f0 j
643h = add mul h 1000003 ulong get c_xty x
644h = add mul h 1000003 ulong get c_xof x
645h = add mul h 1000003 ulong get c_xor x
646end
647ret h
648end
649h = add mul h 1000003 ulong get c_t3 t
650h = add mul h 1000003 ulong get c_t4 t
651ret add mul h 1000003 ulong get c_t5 t
652end
653fn ck_teq a ulong b ulong to bool
654if ne get c_tk a get c_tk b
655ret false
656end
657if ne get c_t1 a get c_t1 b
658ret false
659end
660if ne get c_t2 a get c_t2 b
661ret false
662end
663if eq get c_tk a 3
664ret ck_feq ulong get c_t3 a ulong get c_t3 b ulong get c_t2 a
665end
666if ne get c_t3 a get c_t3 b
667ret false
668end
669if ne get c_t4 a get c_t4 b
670ret false
671end
672ret eq get c_t5 a get c_t5 b
673end
674fn ck_feq a ulong b ulong n ulong to bool
675for j ulong n bound 64
676x = add a j
677y = add b j
678if ne get c_xty x get c_xty y
679ret false
680end
681if ne get c_xof x get c_xof y
682ret false
683end
684if ne get c_xor x get c_xor y
685ret false
686end
687end
688ret true
689end
690fn ck_tdup t ulong o ulong to void
691s = and ck_thash t 131071
692for i ulong 131072
693u = ulong get c_th s
694if eq u 0
695put c_th s uint t
696ret
697end
698if ck_teq u t
699ck_bad 13 o
700end
701s = and add s 1 131071
702end
703end
704note ---- globals (phase 1) ---------------------------------------------------------------------
705fn ck_globs to void
706o = ck_at
707n = ck_u32
708if gt n 65536
709ck_bad 23 o
710end
711put c_n 2 n
712for g ulong n bound 65536
713ck_glob g
714end
715end
716fn ck_glob g ulong to void
717o = ck_at
718t = ck_u32
719c = ck_u8
720k = ck_kd t
721if eq k 255
722ck_bad 24 o
723end
724if gt c 2
725ck_bad 13 o
726end
727if eq c 2
728if not or and ge t 2 le t 9 or eq t 13 eq t 14
729ck_bad 16 o
730end
731else
732if ne k 2
733ck_bad 16 o
734end
735end
736put c_gty g uint t
737put c_gcl g uchar c
738if eq c 1
739p = ck_need get c_tsz t
740end
741end
742note ---- functions (phase 1): headers, blocks, op rows --------------------------------------------
743fn ck_funcs to void
744o = ck_at
745n = ck_u32
746if gt n 65536
747ck_bad 23 o
748end
749put c_n 3 n
750for f ulong n bound 65536
751ck_fread f
752end
753p = ck_at
754if lt p get c_s 1
755ck_bad 14 p
756end
757ck_entry o
758ck_back
759end
760note at most one callback function (flags bit 1); a second one is FIELD at its record
761fn ck_back to void
762c = ulong 0
763for f ulong get c_n 3 bound 65536
764if ge ulong get c_ffl f 2
765c = add c 1
766if eq c 2
767ck_bad 13 ulong get c_fof f
768end
769end
770end
771end
772note D11, IR.md s6.1: exactly one program entry, an export with no parameters and result i32;
773note none is ENTRY at the function count, a second one is ENTRY at its record
774fn ck_entry o ulong to void
775c = ulong 0
776for f ulong get c_n 3 bound 65536
777if and eq get c_fk f 2 eq get c_fnp f 0
778if eq get c_frs f 8
779c = add c 1
780if eq c 2
781ck_bad 30 ulong get c_fof f
782end
783end
784end
785end
786if eq c 0
787ck_bad 30 o
788end
789end
790note a parameter count (function or block): LIMIT above 64 at its own offset
791fn ck_pcount to ulong
792o = ck_at
793n = ck_u32
794if gt n 64
795ck_bad 23 o
796end
797ret n
798end
799fn ck_fread f ulong to void
800o = ck_at
801put c_fof f uint o
802k = ck_u8
803fl = ck_u8
804if or gt k 2 gt fl 3
805ck_bad 13 o
806end
807put c_fk f uchar k
808put c_ffl f uchar fl
809np = ck_pcount
810put c_fnp f uint np
811put c_fp0 f uint get c_n 8
812for j ulong np bound 64
813ck_fparam f o
814end
815r = ck_u32
816if ne r 0
817ck_ptype r f o
818if eq k 1
819ck_bad 22 o
820end
821end
822put c_frs f uint r
823note flags bit 1 (IR.md s6.1): the callback function, kind 0 with six u64 parameters and a u64 result
824if ge fl 2
825if or or ne k 0 ne np 6 ne r 5
826ck_bad 13 o
827end
828for j ulong 6
829if ne ulong get c_fpt add ulong get c_fp0 f j 5
830ck_bad 13 o
831end
832end
833end
834if eq k 1
835ck_kern f o
836end
837ck_blocks f
838end
839note a parameter or result type of function f: a value type, FRAG only in kernels
840fn ck_ptype t ulong f ulong o ulong to void
841c = ck_vtc t
842if ne c 0
843ck_bad c o
844end
845if and eq ck_kd t 6 ne get c_fk f 1
846ck_bad 22 o
847end
848end
849fn ck_fparam f ulong o ulong to void
850t = ck_u32
851ck_ptype t f o
852x = get c_n 8
853put c_fpt x uint t
854put c_n 8 add x 1
855end
856fn ck_kern f ulong o ulong to void
857x = ck_u32
858y = ck_u32
859z = ck_u32
860s = ck_u8
861if or or eq x 0 eq y 0 eq z 0
862ck_bad 13 o
863end
864if or or gt x 4096 gt y 4096 gt z 4096
865ck_bad 13 o
866end
867if gt mul mul x y z 4096
868ck_bad 13 o
869end
870if not or eq s 0 and and ge s 4 le s 128 eq and s sub s 1 0
871ck_bad 13 o
872end
873put c_fsg f uchar s
874end
875fn ck_blocks f ulong to void
876o = ck_at
877nb = ck_u32
878if eq nb 0
879ck_bad 13 o
880end
881if gt nb 65536
882ck_bad 23 o
883end
884if gt add get c_n 4 nb 1048576
885ck_bad 23 o
886end
887put c_fb0 f uint get c_n 4
888put c_fnb f uint nb
889put c_q 9 0
890for j ulong nb bound 65536
891ck_bread f j
892end
893end
894fn ck_bread f ulong j ulong to void
895b = get c_n 4
896put c_n 4 add b 1
897o = ck_at
898put c_bof b uint o
899np = ck_pcount
900put c_bnp b uint np
901put c_bp0 b uint get c_n 7
902if and eq j 0 gt np 0
903ck_bad 19 o
904end
905if and ne j 0 eq np 0
906ck_bad 19 o
907end
908for k ulong np bound 64
909ck_bparam f k o
910end
911ck_bops b
912end
913fn ck_bparam f ulong k ulong o ulong to void
914t = ck_u32
915if eq k 0
916if ne t 20
917ck_bad 19 o
918end
919else
920ck_ptype t f o
921end
922x = get c_n 7
923put c_bpt x uint t
924put c_n 7 add x 1
925end
926fn ck_bops b ulong to void
927on = ck_at
928n = ck_u32
929if eq n 0
930ck_bad 20 ulong get c_bof b
931end
932if gt add get c_q 9 n 1048576
933ck_bad 23 on
934end
935if gt add get c_n 5 n 4194304
936ck_bad 23 on
937end
938put c_q 9 add get c_q 9 n
939put c_bo0 b uint get c_n 5
940put c_bno b uint n
941for k ulong n bound 1048576
942ck_oread
943end
944end
945fn ck_oread to void
946o = ck_at
947op = ck_u8
948x = get c_n 5
949put c_n 5 add x 1
950put c_oof x uint o
951put c_oop x uchar op
952if eq get c_rok op 0
953ck_bad 15 o
954end
955put c_oty x uint ck_u32
956if ne get c_rim op 0
957put c_oim x ck_u64
958end
959n = ulong 0
960if ne get c_rva op 0
961no = ck_at
962n = ck_u32
963if gt n 64
964ck_bad 23 no
965end
966end
967m = add ck_ntok op add ulong get c_rfx op n
968put c_ona x uint m
969a0 = get c_n 6
970put c_oa0 x uint a0
971for k ulong m bound 128
972put c_arg add a0 k uint ck_u32
973end
974put c_n 6 add a0 m
975end
976note 1 when op carries a token operand at slot 0 (E, R and T ops other than br)
977fn ck_ntok op ulong to ulong
978if or eq get c_rtk op 0 eq op 60
979ret 0
980end
981ret 1
982end
983note ---- op field accessors ----------------------------------------------------------------------
984fn ck_op o ulong to ulong
985ret ulong get c_oop o
986end
987fn ck_ty o ulong to ulong
988ret ulong get c_oty o
989end
990fn ck_im o ulong to ulong
991ret get c_oim o
992end
993fn ck_na o ulong to ulong
994ret ulong get c_ona o
995end
996fn ck_a o ulong k ulong to ulong
997s = add ulong get c_oa0 o k
998ret ulong get c_arg s
999end
1000note the type of value operand k of op o
1001fn ck_ta o ulong k ulong to ulong
1002v = ck_a o k
1003ret ulong get c_vty v
1004end
1005fn ck_isterm o ulong to bool
1006op = ck_op o
1007ret or and ge op 60 le op 63 or eq op 65 eq op 66
1008end
1009note ---- phase 2: one function ---------------------------------------------------------------------
1010fn ck_fn f ulong to void
1011put c_f 0 f
1012put c_f 1 ulong get c_fb0 f
1013put c_f 2 ulong get c_fnb f
1014put c_f 5 ulong get c_fk f
1015put c_f 6 ulong get c_frs f
1016put c_f 7 ulong get c_fsg f
1017ck_term
1018ck_cfg
1019ck_reach
1020ck_doms
1021ck_dtree
1022ck_vnum f
1023ck_covidx
1024ck_walk
1025end
1026note every block ends with its one terminator (UNTERMINATED)
1027fn ck_term to void
1028for j ulong get c_f 2 bound 65536
1029b = add get c_f 1 j
1030o0 = ulong get c_bo0 b
1031n = ulong get c_bno b
1032for k ulong sub n 1 bound 1048576
1033if ck_isterm add o0 k
1034ck_bad 20 ulong get c_oof add o0 k
1035end
1036end
1037x = add o0 sub n 1
1038if not ck_isterm x
1039ck_bad 20 ulong get c_oof x
1040end
1041end
1042end
1043fn ck_last j ulong to ulong
1044b = add get c_f 1 j
1045ret sub add ulong get c_bo0 b ulong get c_bno b 1
1046end
1047note successors from each block's terminator: branch targets exist, are not block 0, arity (s7.6)
1048fn ck_cfg to void
1049for j ulong get c_f 2 bound 65536
1050put c_s1 j 0
1051put c_s2 j 0
1052o = ck_last j
1053op = ck_op o
1054put c_q 12 o
1055if eq op 60
1056put c_s1 j uint ck_tgt o 0
1057end
1058if eq op 61
1059put c_s1 j uint ck_tgt o 2
1060put c_s2 j uint ck_tgt o 3
1061end
1062end
1063end
1064note block operand k of op o (a br or cbr): 1 + its local index
1065fn ck_tgt o ulong k ulong to ulong
1066t = ck_a o k
1067if or eq t 0 ge t get c_f 2
1068ck_fail 24
1069end
1070b = add get c_f 1 t
1071np = ulong get c_bnp b
1072if eq ck_op o 61
1073ck_want eq np 1 19
1074else
1075ck_want eq np sub ck_na o 1 19
1076end
1077ret add t 1
1078end
1079note depth-first search from block 0: postorder into c_rpo, then reverse; UNREACHABLE
1080fn ck_reach to void
1081nb = get c_f 2
1082for j ulong nb bound 65536
1083put c_vis j 0
1084end
1085put c_vis 0 1
1086put c_stk 0 0
1087put c_sti 0 0
1088sp = ulong 1
1089pc = ulong 0
1090while gt sp 0 bound 262144
1091top = ulong get c_stk sub sp 1
1092i = ulong get c_sti sub sp 1
1093if lt i 2
1094put c_sti sub sp 1 uchar add i 1
1095s = ck_succ top i
1096if ne s 0
1097if eq get c_vis sub s 1 0
1098put c_vis sub s 1 1
1099put c_stk sp uint sub s 1
1100put c_sti sp 0
1101sp = add sp 1
1102end
1103end
1104else
1105put c_pfl pc uint top
1106pc = add pc 1
1107sp = sub sp 1
1108end
1109end
1110for j ulong nb bound 65536
1111if eq get c_vis j 0
1112ck_bad 26 ulong get c_bof add get c_f 1 j
1113end
1114end
1115for i ulong nb bound 65536
1116x = ulong get c_pfl sub sub nb 1 i
1117put c_rpo i uint x
1118put c_ord x uint i
1119end
1120end
1121fn ck_succ j ulong i ulong to ulong
1122if eq i 0
1123ret ulong get c_s1 j
1124end
1125ret ulong get c_s2 j
1126end
1127note immediate dominators (Cooper, Harvey, Kennedy) over predecessor lists
1128fn ck_doms to void
1129nb = get c_f 2
1130for j ulong add nb 1 bound 65537
1131put c_pc j 0
1132end
1133for j ulong nb bound 65536
1134ck_pcnt ulong get c_s1 j
1135ck_pcnt ulong get c_s2 j
1136end
1137s = ulong 0
1138for j ulong nb bound 65536
1139put c_pst j uint s
1140put c_pfl j uint s
1141s = add s ulong get c_pc j
1142end
1143for j ulong nb bound 65536
1144ck_padd j ulong get c_s1 j
1145ck_padd j ulong get c_s2 j
1146put c_idm j 4294967295
1147end
1148put c_idm 0 0
1149ch = true
1150while ch bound 65537
1151ch = false
1152for i ulong sub nb 1 bound 65536
1153b = ulong get c_rpo add i 1
1154ni = ck_newidom b
1155if ne ni ulong get c_idm b
1156put c_idm b uint ni
1157ch = true
1158end
1159end
1160end
1161end
1162fn ck_pcnt s ulong to void
1163if ne s 0
1164put c_pc sub s 1 add get c_pc sub s 1 1
1165end
1166end
1167fn ck_padd j ulong s ulong to void
1168if ne s 0
1169x = ulong get c_pfl sub s 1
1170put c_pl x uint j
1171put c_pfl sub s 1 uint add x 1
1172end
1173end
1174fn ck_newidom b ulong to ulong
1175ni = ulong 4294967295
1176s = ulong get c_pst b
1177for k ulong ulong get c_pc b bound 131072
1178p = ulong get c_pl add s k
1179if ne get c_idm p 4294967295
1180if eq ni 4294967295
1181ni = p
1182else
1183ni = ck_isect p ni
1184end
1185end
1186end
1187ret ni
1188end
1189fn ck_isect a ulong b ulong to ulong
1190x = a
1191y = b
1192while ne x y bound 65537
1193while gt get c_ord x get c_ord y bound 65537
1194x = ulong get c_idm x
1195end
1196while gt get c_ord y get c_ord x bound 65537
1197y = ulong get c_idm y
1198end
1199end
1200ret x
1201end
1202note dominator tree: preorder and postorder numbers make dominance an O(1) query
1203fn ck_dtree to void
1204nb = get c_f 2
1205for j ulong nb bound 65536
1206put c_dch j 0
1207put c_dsb j 0
1208end
1209for i ulong sub nb 1 bound 65536
1210b = sub sub nb 1 i
1211p = ulong get c_idm b
1212put c_dsb b get c_dch p
1213put c_dch p uint add b 1
1214end
1215put c_stk 0 0
1216put c_dnx 0 get c_dch 0
1217put c_pre 0 0
1218sp = ulong 1
1219pr = ulong 1
1220po = ulong 0
1221while gt sp 0 bound 262144
1222top = ulong get c_stk sub sp 1
1223c = ulong get c_dnx top
1224if ne c 0
1225x = sub c 1
1226put c_dnx top get c_dsb x
1227put c_stk sp uint x
1228put c_pre x uint pr
1229put c_dnx x get c_dch x
1230pr = add pr 1
1231sp = add sp 1
1232else
1233put c_pos top uint po
1234po = add po 1
1235sp = sub sp 1
1236end
1237end
1238end
1239note a dominates b (blocks, local indices; a dominates itself)
1240fn ck_dom a ulong b ulong to bool
1241if gt get c_pre a get c_pre b
1242ret false
1243end
1244ret le get c_pos b get c_pos a
1245end
1246note ---- value numbering (IR.md s6.2) -------------------------------------------------------------
1247fn ck_vnum f ulong to void
1248put c_f 3 0
1249ck_vdef 20 0 0 0
1250np = ulong get c_fnp f
1251p0 = ulong get c_fp0 f
1252for k ulong np bound 64
1253ck_vdef ulong get c_fpt add p0 k 0 0 0
1254end
1255for j ulong get c_f 2 bound 65536
1256ck_vblk j
1257end
1258end
1259fn ck_vdef t ulong b ulong p ulong o ulong to void
1260v = get c_f 3
1261if ge v 2097152
1262ck_bad 23 ulong get c_fof get c_f 0
1263end
1264put c_vty v uint t
1265put c_vb v uint b
1266put c_vp v uint p
1267put c_vo v uint o
1268put c_f 3 add v 1
1269end
1270fn ck_vblk j ulong to void
1271b = add get c_f 1 j
1272put c_bv0 j uint get c_f 3
1273p0 = ulong get c_bp0 b
1274for k ulong ulong get c_bnp b bound 64
1275ck_vdef ulong get c_bpt add p0 k j 0 0
1276end
1277o0 = ulong get c_bo0 b
1278for k ulong ulong get c_bno b bound 1048576
1279ck_vop add o0 k j k
1280end
1281end
1282fn ck_vop o ulong j ulong k ulong to void
1283op = ck_op o
1284put c_opb o uint j
1285put c_opp o uint k
1286put c_ov o uint get c_f 3
1287if eq get c_rtk op 1
1288ck_vdef 20 j add k 1 add o 1
1289end
1290c = ulong get c_rty op
1291t = ck_ty o
1292if and ne t 0 or eq c 1 eq c 2
1293ck_vdef t j add k 1 add o 1
1294end
1295end
1296note the result value of op o (after its token for an E op)
1297fn ck_res o ulong to ulong
1298v = ulong get c_ov o
1299if eq get c_rtk ck_op o 1
1300ret add v 1
1301end
1302ret v
1303end
1304note ---- coverage index: checks and facts keyed by their first value operand ----------------------
1305fn ck_covidx to void
1306nv = get c_f 3
1307for v ulong nv bound 2097152
1308put c_cvh v 0
1309end
1310for j ulong get c_f 2 bound 65536
1311b = add get c_f 1 j
1312o0 = ulong get c_bo0 b
1313for k ulong ulong get c_bno b bound 1048576
1314ck_covadd add o0 k
1315end
1316end
1317end
1318fn ck_covadd o ulong to void
1319op = ck_op o
1320s = ulong 2
1321if or eq op 79 or eq op 80 eq op 82
1322s = 1
1323end
1324if or eq op 90 or eq op 92 eq op 93
1325s = 0
1326end
1327if eq s 2
1328ret
1329end
1330if le ck_na o s
1331ret
1332end
1333r = ck_a o s
1334if ge r get c_f 3
1335ret
1336end
1337put c_cvn o get c_cvh r
1338put c_cvh r uint add o 1
1339end
1340note ---- the op walk ---------------------------------------------------------------------------------
1341fn ck_walk to void
1342for j ulong get c_f 2 bound 65536
1343b = add get c_f 1 j
1344put c_f 4 0
1345if ne j 0
1346put c_f 4 ulong get c_bv0 j
1347end
1348o0 = ulong get c_bo0 b
1349for k ulong ulong get c_bno b bound 1048576
1350ck_ochk add o0 k j k
1351end
1352end
1353end
1354fn ck_ochk o ulong j ulong k ulong to void
1355put c_q 10 j
1356put c_q 11 k
1357put c_q 12 o
1358op = ck_op o
1359for s ulong ck_na o bound 128
1360ck_opnd o op s
1361end
1362ck_tycol o op
1363ck_place o op j
1364ck_code o op
1365ck_typing o op
1366ck_cover o op
1367if eq get c_rtk op 1
1368put c_f 4 ulong get c_ov o
1369end
1370end
1371note slot kind: 0 value, 1 block, 2 function, 3 the token
1372fn ck_slot op ulong s ulong to ulong
1373if eq op 60
1374if eq s 0
1375ret 1
1376end
1377if eq s 1
1378ret 3
1379end
1380ret 0
1381end
1382if and eq s 0 ne get c_rtk op 0
1383ret 3
1384end
1385if and eq op 61 or eq s 2 eq s 3
1386ret 1
1387end
1388if and eq s 1 or eq op 64 eq op 67
1389ret 2
1390end
1391ret 0
1392end
1393fn ck_opnd o ulong op ulong s ulong to void
1394kd = ck_slot op s
1395x = ck_a o s
1396if eq kd 1
1397ret
1398end
1399if eq kd 2
1400ck_want lt x get c_n 3 24
1401ret
1402end
1403ck_want lt x get c_f 3 17
1404ck_usedef x
1405t = ulong get c_vty x
1406if eq kd 0
1407ck_want ne t 20 28
1408ret
1409end
1410ck_want eq t 20 28
1411if ne get c_rtk op 2
1412ck_want eq x get c_f 4 28
1413end
1414end
1415note value v is defined before the use point (c_q 10 block, c_q 11 op position)
1416fn ck_usedef v ulong to void
1417vb = ulong get c_vb v
1418b = get c_q 10
1419if eq vb b
1420ck_want le ulong get c_vp v get c_q 11 17
1421ret
1422end
1423ck_want ck_dom vb b 18
1424end
1425note the ty field against the row's ty column
1426fn ck_tycol o ulong op ulong to void
1427c = ulong get c_rty op
1428t = ck_ty o
1429if eq c 0
1430ck_want eq t 0 13
1431ret
1432end
1433if and eq c 2 eq t 0
1434ret
1435end
1436ck_want ne t 0 16
1437x = ck_vtc t
1438if ne x 0
1439ck_fail x
1440end
1441if eq c 3
1442ck_want ck_isint t 16
1443end
1444if and eq ck_kd t 6 ne get c_f 5 1
1445ck_fail 22
1446end
1447end
1448note kernel-only ops, ops kernels may not use, entry-block-only ops (EFFECT)
1449fn ck_place o ulong op ulong j ulong to void
1450k = get c_f 5
1451if and ge op 111 le op 116
1452ck_want ne k 1 22
1453end
1454if or or eq op 40 eq op 41 or eq op 44 eq op 45
1455ck_want eq k 1 22
1456end
1457if or eq op 104 or eq op 105 eq op 106
1458ck_want eq k 1 22
1459end
1460if or or eq op 64 eq op 66 or eq op 67 eq op 110
1461ck_want ne k 1 22
1462end
1463if or eq op 41 eq op 50
1464ck_want eq j 0 22
1465end
1466end
1467note trap codes of checks and trap (CHECK_CODE), fact origins (NONCANONICAL)
1468fn ck_code o ulong op ulong to void
1469m = ck_im o
1470if or eq op 65 eq op 82
1471ck_want and ge m 1 le m 14 21
1472ret
1473end
1474if and ge op 70 le op 81
1475ck_want eq m ck_ccode op 21
1476ret
1477end
1478if and ge op 90 le op 93
1479ck_want le m 255 13
1480end
1481end
1482fn ck_ccode op ulong to ulong
1483if eq op 74
1484ret 2
1485end
1486if eq op 77
1487ret 7
1488end
1489if eq op 78
1490ret 5
1491end
1492if or eq op 79 eq op 80
1493ret 3
1494end
1495if eq op 81
1496ret 4
1497end
1498ret 1
1499end
1500note ---- typing per row group (IR.md s7) -----------------------------------------------------------
1501fn ck_typing o ulong op ulong to void
1502if le op 2
1503ck_tconst o op
1504ret
1505end
1506if and ge op 10 le op 28
1507ck_tarith o op
1508ret
1509end
1510if and ge op 30 le op 37
1511ck_tcmp o op
1512ret
1513end
1514if or eq op 42 eq op 43
1515ck_tmem o op
1516ret
1517end
1518if or and ge op 40 le op 45 eq op 46
1519ck_tgpu o op
1520ret
1521end
1522if and ge op 47 le op 59
1523ck_tmem o op
1524ret
1525end
1526if and ge op 60 le op 67
1527ck_tctl o op
1528ret
1529end
1530if and ge op 70 le op 82
1531ck_tchk o op
1532ret
1533end
1534if and ge op 90 le op 93
1535ck_tfact o op
1536ret
1537end
1538if and ge op 100 le op 106
1539ck_tvops o op
1540ret
1541end
1542if eq op 110
1543ck_thost o
1544end
1545if and ge op 111 le op 116
1546ck_tpool o op
1547end
1548end
1549note canonical const bits for scalar type t (IR.md s7.2)
1550fn ck_canon t ulong v ulong to bool
1551w = mul ck_sb t 8
1552if eq t 1
1553ret le v 1
1554end
1555if eq w 64
1556ret true
1557end
1558if ck_issgn t
1559h = shl ulong 1 sub w 1
1560ret lt add v h shl ulong 1 w
1561end
1562ret lt v shl ulong 1 w
1563end
1564fn ck_tconst o ulong op ulong to void
1565t = ck_ty o
1566if eq op 1
1567ck_want or eq t 1 ck_isnum t 16
1568ck_want ck_canon t ck_im o 13
1569ret
1570end
1571ck_want eq ck_ta o 0 1 16
1572ck_want eq ck_ta o 1 t 16
1573ck_want eq ck_ta o 2 t 16
1574end
1575note every operand of op o from slot s0 on has type t
1576fn ck_alltype o ulong s0 ulong t ulong to void
1577for k ulong sub ck_na o s0 bound 128
1578ck_want eq ck_ta o add s0 k t 16
1579end
1580end
1581fn ck_tarith o ulong op ulong to void
1582t = ck_ty o
1583e = ck_el t
1584ok = ck_isar e
1585if eq op 14
1586ok = ck_isint e
1587end
1588if and ge op 16 le op 19
1589ok = or eq e 1 ck_isint e
1590end
1591if or eq op 20 eq op 21
1592ok = ck_isint e
1593end
1594if or eq op 22 eq op 23
1595ok = ck_isuns e
1596end
1597if and ge op 26 le op 28
1598ok = ck_isflt e
1599end
1600ck_want ok 16
1601ck_alltype o 0 t
1602if eq op 28
1603ck_fmathimm ck_im o
1604end
1605end
1606fn ck_fmathimm m ulong to void
1607fu = and m 255
1608cl = and shr m 8 255
1609n = and shr m 16 255
1610ck_want le fu 7 13
1611ck_want le cl 2 13
1612ck_want eq shr m 25 0 13
1613if eq cl 1
1614ck_want ge n 1 13
1615else
1616ck_want eq n 0 13
1617end
1618end
1619fn ck_tcmp o ulong op ulong to void
1620t = ck_ty o
1621if eq op 36
1622ck_tconv o t
1623ret
1624end
1625if eq op 37
1626ck_tbits o t
1627ret
1628end
1629s = ck_ta o 0
1630ck_want eq ck_ta o 1 s 16
1631e = ck_el s
1632if or eq op 30 eq op 31
1633ck_want or eq e 1 ck_isar e 16
1634else
1635ck_want ck_isar e 16
1636end
1637if eq ck_kd s 1
1638ck_want eq ck_kd t 1 16
1639ck_want eq ck_g1 t 1 16
1640ck_want eq ck_g2 t ck_g2 s 16
1641else
1642ck_want eq t 1 16
1643end
1644end
1645fn ck_tconv o ulong t ulong to void
1646s = ck_ta o 0
1647et = ck_el t
1648es = ck_el s
1649ck_want ck_isnum et 16
1650ck_want ck_isnum es 16
1651ck_want ne et es 16
1652ck_want eq ck_kd s ck_kd t 16
1653ck_want eq ck_lanes s ck_lanes t 16
1654m = ck_im o
1655if ck_isint et
1656ck_want eq m 0 13
1657else
1658ck_want and le and m 3 1 eq shr m 3 0 13
1659end
1660end
1661fn ck_tbits o ulong t ulong to void
1662s = ck_ta o 0
1663et = ck_el t
1664es = ck_el s
1665ck_want ck_isnum et 16
1666ck_want ck_isnum es 16
1667ck_want eq mul ck_sb et ck_lanes t mul ck_sb es ck_lanes s 16
1668end
1669fn ck_tgpu o ulong op ulong to void
1670t = ck_ty o
1671if eq op 40
1672ck_want eq t 4 16
1673ck_want le ck_im o 10 13
1674end
1675if eq op 41
1676ck_want eq ck_kd t 4 16
1677ck_want eq ck_g2 t 1 16
1678ck_want eq ck_g3 t 2 16
1679ck_want eq ck_kd ck_g1 t 2 16
1680end
1681if eq op 45
1682ck_tshfl o t
1683end
1684if eq op 46
1685ck_want ck_isflt ck_el t 16
1686ck_alltype o 0 t
1687end
1688end
1689note shfl v types (IR.md s7.7): u32, i32, f32 and u64, i64, f64 (ids 4, 8, 13 and 5, 9, 14)
1690fn ck_shfty t ulong to bool
1691if or eq t 4 eq t 8
1692ret true
1693end
1694if or eq t 13 eq t 5
1695ret true
1696end
1697ret or eq t 9 eq t 14
1698end
1699fn ck_tshfl o ulong t ulong to void
1700ck_want ck_shfty t 16
1701m = ck_im o
1702ck_want and ge m 1 le m 4 13
1703ck_want eq ck_ta o 0 t 16
1704ck_want eq ck_ta o 1 4 16
1705d = ck_cval ck_a o 1
1706ck_want ne get c_q 15 0 16
1707if le m 2
1708ck_want ge d 1 16
1709end
1710ck_want le d 127 16
1711sg = get c_f 7
1712if ne sg 0
1713ck_want lt d sg 16
1714end
1715end
1716note the imm of the const defining value v into the result, c_q 15 = 1 when v is defined by a const
1717fn ck_cval v ulong to ulong
1718put c_q 15 0
1719x = ulong get c_vo v
1720if eq x 0
1721ret 0
1722end
1723if ne ck_op sub x 1 1
1724ret 0
1725end
1726put c_q 15 1
1727ret ck_im sub x 1
1728end
1729note memory ops; r is slot 1 for token ops, slot 0 for len and fref
1730fn ck_tmem o ulong op ulong to void
1731t = ck_ty o
1732if eq op 50
1733ck_want eq ck_kd t 4 16
1734ck_want eq ck_g2 t 1 16
1735ck_want or eq ck_g3 t 0 eq ck_g3 t 4 16
1736ret
1737end
1738if eq op 52
1739ck_tgaddr o t
1740ret
1741end
1742if eq op 53
1743ck_want eq t 5 16
1744ck_want ne ck_relt ck_ta o 0 0 16
1745ret
1746end
1747if or eq op 55 or eq op 56 eq op 57
1748ck_tfield o op t
1749ret
1750end
1751r = ck_ta o 1
1752e = ck_relt r
1753ck_want ne e 0 16
1754if or or eq op 43 eq op 47 or eq op 48 or eq op 51 eq op 59
1755ck_want eq ck_g2 r 1 16
1756end
1757if eq op 51
1758ck_want eq ck_ta o 2 e 16
1759ret
1760end
1761if eq op 54
1762ck_tslice o r e t
1763ret
1764end
1765ck_want or eq ck_ta o 2 4 eq ck_ta o 2 5 16
1766ck_tacc o op e t
1767end
1768fn ck_tacc o ulong op ulong e ulong t ulong to void
1769if eq op 42
1770ck_want eq t e 16
1771ck_want or ne ck_sb e 0 eq ck_kd e 1 16
1772end
1773if eq op 43
1774ck_want or ne ck_sb e 0 eq ck_kd e 1 16
1775ck_want eq ck_ta o 3 e 16
1776end
1777if or eq op 47 eq op 48
1778ck_tatom o op e t
1779end
1780if eq op 58
1781ck_want ne ck_sb e 0 16
1782ck_want eq ck_kd t 1 16
1783ck_want eq ck_g1 t e 16
1784end
1785if eq op 59
1786s = ck_ta o 3
1787ck_want ne ck_sb e 0 16
1788ck_want eq ck_kd s 1 16
1789ck_want eq ck_g1 s e 16
1790end
1791end
1792fn ck_tatom o ulong op ulong e ulong t ulong to void
1793ck_want eq t e 16
1794ck_want or or eq e 4 eq e 8 or or eq e 5 eq e 9 eq e 13 16
1795m = ck_im o
1796ck_want le and shr m 8 255 3 13
1797ck_want le and shr m 16 255 1 13
1798ck_want eq shr m 24 0 13
1799ck_want eq ck_ta o 3 e 16
1800if eq op 47
1801ck_want le and m 255 6 13
1802if eq e 13
1803a = and m 255
1804ck_want or or eq a 0 eq a 1 or eq a 2 eq a 6 16
1805end
1806else
1807ck_want eq and m 255 0 13
1808ck_want eq ck_ta o 4 e 16
1809end
1810end
1811fn ck_tslice o ulong r ulong e ulong t ulong to void
1812ck_want eq ck_ta o 2 5 16
1813ck_want eq ck_ta o 3 5 16
1814ck_want eq ck_kd t 5 16
1815ck_want eq ck_g1 t e 16
1816ck_want eq ck_g3 t ck_g3 r 16
1817ck_want le ck_g2 t ck_g2 r 16
1818end
1819fn ck_tgaddr o ulong t ulong to void
1820g = ck_im o
1821ck_want lt g get c_n 2 24
1822ck_want eq ck_kd t 4 16
1823ck_want ne get c_gcl g 2 16
1824ck_want eq ck_g1 t ulong get c_gty g 16
1825ck_want eq ck_g3 t 0 16
1826if eq get c_gcl g 1
1827ck_want eq ck_g2 t 0 16
1828end
1829end
1830note fload, fstore (r slot 1) and fref (r slot 0): REF to STRUCT, field index in imm
1831fn ck_tfield o ulong op ulong t ulong to void
1832s = ulong 1
1833if eq op 57
1834s = 0
1835end
1836r = ck_ta o s
1837ck_want eq ck_kd r 4 16
1838st = ck_g1 r
1839ck_want eq ck_kd st 3 16
1840x = ck_im o
1841ck_want lt x ck_g2 st 16
1842ft = ulong get c_xty add ck_g3 st x
1843if eq op 55
1844ck_want ne ck_sb ft 0 16
1845ck_want eq t ft 16
1846end
1847if eq op 56
1848ck_want ne ck_sb ft 0 16
1849ck_want eq ck_g2 r 1 16
1850ck_want eq ck_ta o 2 ft 16
1851end
1852if eq op 57
1853ck_want eq ck_kd t 4 16
1854ck_want eq ck_g1 t ft 16
1855ck_want eq ck_g2 t ck_g2 r 16
1856ck_want eq ck_g3 t ck_g3 r 16
1857end
1858end
1859fn ck_tctl o ulong op ulong to void
1860rs = get c_f 6
1861if eq op 60
1862ck_tbr o
1863end
1864if eq op 61
1865ck_want eq ck_ta o 1 1 16
1866end
1867if eq op 62
1868ck_want eq rs 0 16
1869end
1870if eq op 63
1871ck_want ne rs 0 16
1872ck_want eq ck_ta o 1 rs 16
1873end
1874if eq op 64
1875ck_tcall o 2
1876end
1877if eq op 66
1878ck_want eq ck_ta o 1 8 16
1879end
1880if eq op 67
1881ck_want eq ck_ta o 2 4 16
1882ck_want eq ck_ta o 3 4 16
1883ck_want eq ck_ta o 4 4 16
1884ck_tcall o 5
1885end
1886end
1887note br: argument types equal the target's parameter types (BLOCK_ARITY)
1888fn ck_tbr o ulong to void
1889b = add get c_f 1 ck_a o 0
1890p0 = ulong get c_bp0 b
1891for k ulong sub ck_na o 1 bound 128
1892ck_want eq ck_ta o add k 1 ulong get c_bpt add p0 k 19
1893end
1894end
1895note call (arguments from slot 2) and launch (from slot 5): callee kind, count, types, result
1896fn ck_tcall o ulong s0 ulong to void
1897f = ck_a o 1
1898k = ulong get c_fk f
1899if eq s0 2
1900ck_want ne k 1 22
1901ck_want eq ck_ty o ulong get c_frs f 16
1902else
1903ck_want eq k 1 22
1904end
1905np = ulong get c_fnp f
1906ck_want eq sub ck_na o s0 np 16
1907p0 = ulong get c_fp0 f
1908for j ulong np bound 64
1909ck_want eq ck_ta o add s0 j ulong get c_fpt add p0 j 16
1910end
1911end
1912fn ck_tchk o ulong op ulong to void
1913a = ck_ta o 1
1914if or eq op 70 or eq op 71 eq op 72
1915ck_want ck_isint a 16
1916ck_want eq ck_ta o 2 a 16
1917end
1918if or eq op 73 or eq op 74 eq op 77
1919ck_want ck_isint a 16
1920end
1921if or eq op 75 eq op 76
1922ck_want ck_issgn a 16
1923ck_want eq ck_ta o 2 a 16
1924end
1925if eq op 78
1926ck_want ck_isar a 16
1927end
1928if eq op 79
1929ck_want ne ck_relt a 0 16
1930ck_want or eq ck_ta o 2 4 eq ck_ta o 2 5 16
1931ck_want eq ck_ta o 3 5 16
1932end
1933if eq op 80
1934ck_want ne ck_relt a 0 16
1935ck_want eq ck_ta o 2 5 16
1936ck_want eq ck_ta o 3 5 16
1937end
1938if eq op 81
1939ck_want eq a 5 16
1940ck_want eq ck_ta o 2 5 16
1941end
1942if eq op 82
1943ck_want eq a 1 16
1944end
1945end
1946fn ck_tfact o ulong op ulong to void
1947a = ck_ta o 0
1948if eq op 90
1949ck_want eq a 1 16
1950ret
1951end
1952if eq op 91
1953ck_trange o a
1954ret
1955end
1956ck_want ne ck_relt a 0 16
1957if eq op 92
1958ck_want or eq ck_ta o 1 4 eq ck_ta o 1 5 16
1959else
1960ck_want eq ck_ta o 1 5 16
1961end
1962ck_want eq ck_ta o 2 5 16
1963end
1964fn ck_trange o ulong a ulong to void
1965ck_want ck_isint a 16
1966ck_want eq ck_ta o 1 a 16
1967ck_want eq ck_ta o 2 a 16
1968lo = ck_cval ck_a o 1
1969ck_want ne get c_q 15 0 16
1970hi = ck_cval ck_a o 2
1971ck_want ne get c_q 15 0 16
1972if ck_issgn a
1973ck_want le long lo long hi 16
1974else
1975ck_want le lo hi 16
1976end
1977end
1978fn ck_tvops o ulong op ulong to void
1979t = ck_ty o
1980if eq op 104
1981ck_tmmald o t
1982ret
1983end
1984if eq op 105
1985ck_tmmast o
1986ret
1987end
1988if eq op 106
1989ck_tmma o t
1990ret
1991end
1992if eq op 100
1993ck_want eq ck_kd t 1 16
1994ck_want eq ck_ta o 0 ck_g1 t 16
1995ret
1996end
1997v = ck_ta o 0
1998ck_want eq ck_kd v 1 16
1999if eq op 101
2000ck_want eq t ck_g1 v 16
2001ck_want lt ck_im o ck_g2 v 16
2002end
2003if eq op 102
2004ck_want eq v t 16
2005ck_want eq ck_ta o 1 ck_g1 t 16
2006ck_want lt ck_im o ck_g2 v 16
2007end
2008if eq op 103
2009e = ck_g1 v
2010ck_want eq t e 16
2011m = ck_im o
2012ck_want le m 5 13
2013if ge m 3
2014ck_want or eq e 1 ck_isint e 16
2015else
2016ck_want ck_isar e 16
2017end
2018end
2019end
2020fn ck_tmmald o ulong t ulong to void
2021ck_want eq ck_kd t 6 16
2022ck_want le ck_im o 1 13
2023ck_want eq ck_relt ck_ta o 1 ck_g5 t 16
2024ck_tmmidx o
2025end
2026fn ck_tmmidx o ulong to void
2027ck_want or eq ck_ta o 2 4 eq ck_ta o 2 5 16
2028ck_want eq ck_ta o 3 5 16
2029ck_want eq ck_ta o 4 5 16
2030end
2031fn ck_tmmast o ulong to void
2032r = ck_ta o 1
2033d = ck_ta o 5
2034ck_want le ck_im o 1 13
2035ck_want eq ck_g2 r 1 16
2036ck_want eq ck_kd d 6 16
2037ck_want eq ck_g1 d 2 16
2038ck_want eq ck_relt r ck_g5 d 16
2039ck_tmmidx o
2040end
2041fn ck_tmma o ulong t ulong to void
2042a = ck_ta o 0
2043b = ck_ta o 1
2044m = ck_im o
2045ck_want or eq m 0 eq m 2 13
2046ck_want and eq ck_kd t 6 eq ck_g1 t 2 16
2047ck_want and eq ck_kd a 6 eq ck_g1 a 0 16
2048ck_want and eq ck_kd b 6 eq ck_g1 b 1 16
2049ck_want eq ck_ta o 2 t 16
2050ck_want eq ck_g5 a ck_g5 b 16
2051ck_tmmdim a t
2052ck_tmmdim b t
2053end
2054fn ck_tmmdim a ulong t ulong to void
2055ck_want eq ck_g2 a ck_g2 t 16
2056ck_want eq ck_g3 a ck_g3 t 16
2057ck_want eq ck_g4 a ck_g4 t 16
2058end
2059note host words (IR.md s7.11): word known, operand count and types per letter, slices covered
2060fn ck_thost o ulong to void
2061w = ck_im o
2062ck_want lt w 256 22
2063ck_want ne get c_hok w 0 22
2064if eq get c_hcp w 1
2065ck_want eq ck_ty o 0 16
2066else
2067ck_want eq ck_ty o 9 16
2068end
2069a = ulong get c_has w
2070l = ulong get c_hal w
2071c = ulong 0
2072for i ulong l bound 16
2073x = get c_hwt add a i
2074c = add c 1
2075if or eq x 114 or eq x 119 eq x 83
2076c = add c 2
2077end
2078end
2079ck_want eq sub ck_na o 1 c 16
2080put c_q 13 0
2081k = ulong 1
2082for i ulong l bound 16
2083k = ck_hlet o k ulong get c_hwt add a i
2084end
2085end
2086fn ck_hlet o ulong k ulong x ulong to ulong
2087t = ck_ta o k
2088if eq x 105
2089ck_want eq t 8 16
2090end
2091if eq x 108
2092ck_want eq t 9 16
2093end
2094if eq x 76
2095ck_want eq t 5 16
2096end
2097if eq x 117
2098ck_want eq t 4 16
2099put c_q 13 ck_cval ck_a o k
2100ck_want ne get c_q 15 0 16
2101end
2102if or eq x 114 or eq x 119 eq x 83
2103ck_hslice o k x
2104ret add k 3
2105end
2106ret add k 1
2107end
2108fn ck_hslice o ulong k ulong x ulong to void
2109r = ck_ta o k
2110ck_want eq ck_relt r 2 16
2111w = or eq x 119 and eq x 83 ne get c_q 13 15210
2112if w
2113ck_want eq ck_g2 r 1 16
2114end
2115ck_want eq ck_ta o add k 1 5 16
2116ck_want eq ck_ta o add k 2 5 16
2117ck_covq ck_a o k ck_a o add k 1 ck_a o add k 2 0
2118put c_q 4 80
2119put c_q 5 93
2120put c_q 6 ck_a o 0
2121ck_want ck_find 25
2122end
2123note ---- coverage and facts (IR.md s8, s7.10) -------------------------------------------------------
2124fn ck_covq r ulong x ulong y ulong m ulong to void
2125put c_q 0 r
2126put c_q 1 x
2127put c_q 2 y
2128put c_q 3 m
2129end
2130fn ck_cover o ulong op ulong to void
2131if or or eq op 42 eq op 43 or eq op 47 eq op 48
2132ck_covq ck_a o 1 ck_a o 2 1 1
2133ck_covb o
2134end
2135if eq op 58
2136ck_covq ck_a o 1 ck_a o 2 ck_lanes ck_ty o 1
2137ck_covb o
2138end
2139if eq op 59
2140ck_covq ck_a o 1 ck_a o 2 ck_lanes ck_ta o 3 1
2141ck_covb o
2142end
2143if or eq op 104 eq op 105
2144ck_covq ck_a o 1 ck_a o 2 ck_a o 4 0
2145ck_covb o
2146end
2147if eq op 54
2148ck_covq ck_a o 1 ck_a o 2 ck_a o 3 0
2149put c_q 4 80
2150put c_q 5 93
2151put c_q 6 ck_a o 0
2152ck_want ck_find 25
2153end
2154if and ge op 90 le op 93
2155if eq ck_im o 0
2156ck_facto o op
2157end
2158end
2159end
2160fn ck_covb o ulong to void
2161put c_q 4 79
2162put c_q 5 92
2163put c_q 6 ck_a o 0
2164ck_want ck_find 25
2165end
2166note origin 0 facts: dominated by the check with the same operands (no token rule; s7.10)
2167fn ck_facto o ulong op ulong to void
2168ck_want ne op 91 29
2169put c_q 5 0
2170put c_q 6 4294967295
2171if eq op 90
2172ck_covq ck_a o 0 0 0 2
2173put c_q 4 82
2174end
2175if eq op 92
2176ck_covq ck_a o 0 ck_a o 1 ck_a o 2 0
2177put c_q 4 79
2178end
2179if eq op 93
2180ck_covq ck_a o 0 ck_a o 1 ck_a o 2 0
2181put c_q 4 80
2182end
2183ck_want ck_find 29
2184end
2185note search the list of r = c_q 0 for a covering op (c_q 4 check op, c_q 5 fact op or 0)
2186fn ck_find to bool
2187c = ulong get c_cvh get c_q 0
2188while ne c 0 bound 4194305
2189if ck_cand sub c 1
2190ret true
2191end
2192c = ulong get c_cvn sub c 1
2193end
2194ret false
2195end
2196fn ck_cand c ulong to bool
2197op = ck_op c
2198s = ulong 0
2199if eq op get c_q 4
2200s = 1
2201else
2202if or eq get c_q 5 0 ne op get c_q 5
2203ret false
2204end
2205end
2206if not ck_cmatch c s
2207ret false
2208end
2209if not ck_cdom c
2210ret false
2211end
2212if eq s 0
2213ret true
2214end
2215ret ck_ctok c
2216end
2217note operands of candidate c (value operands from slot s) against c_q 1, 2 and mode c_q 3
2218fn ck_cmatch c ulong s ulong to bool
2219m = get c_q 3
2220if eq m 2
2221ret true
2222end
2223if le ck_na c add s 2
2224ret false
2225end
2226if ne ck_a c add s 1 get c_q 1
2227ret false
2228end
2229y = ck_a c add s 2
2230if eq m 0
2231ret eq y get c_q 2
2232end
2233if ge y get c_f 3
2234ret false
2235end
2236e = ck_cval y
2237if eq get c_q 15 0
2238ret false
2239end
2240ret ge e get c_q 2
2241end
2242note rule 2: c dominates the use point
2243fn ck_cdom c ulong to bool
2244cb = ulong get c_opb c
2245b = get c_q 10
2246if eq cb b
2247ret lt ulong get c_opp c get c_q 11
2248end
2249ret ck_dom cb b
2250end
2251note rule 3: the check's token is the access's token (c_q 6) or dominates its definition
2252fn ck_ctok c ulong to bool
2253t = get c_q 6
2254if eq t 4294967295
2255ret true
2256end
2257tc = ulong get c_ov c
2258if eq t tc
2259ret true
2260end
2261cb = ulong get c_opb c
2262tb = ulong get c_vb t
2263if eq tb cb
2264ret gt ulong get c_vp t ulong get c_opp c
2265end
2266ret ck_dom cb tb
2267end
2268note ---- main --------------------------------------------------------------------------------------
2269fn ck_slurp to ulong
2270n = ulong 0
2271while lt n len sh_dat bound 16777217
2272k = read 0 sh_dat n sub len sh_dat n
2273if lt k 0
2274ck_bad 27 n
2275end
2276if eq k 0
2277ret n
2278end
2279n = add n ulong k
2280end
2281k = read 0 c_ob 0 1
2282if gt k 0
2283ck_bad 23 n
2284end
2285ret n
2286end
2287fn ck_istable to bool
2288k = argread 1 c_ab 0 len c_ab
2289if ne k 7
2290ret false
2291end
2292for i ulong 7
2293if ne get c_ab i get c_tx add 44 i
2294ret false
2295end
2296end
2297ret true
2298end
2299fn ck_accept n ulong to void
2300sh_all n
2301for j ulong 32
2302b = uint get sh_dig j
2303put c_ab mul j 2 sh_hexd shr b 4
2304put c_ab add mul j 2 1 sh_hexd and b 15
2305end
2306ck_txt 3 1
2307r = write 1 c_ab 0 64
2308ck_txt 4 1
2309ck_num get c_n 3 1
2310ck_txt 5 1
2311ck_num get c_n 4 1
2312ck_txt 6 1
2313ck_num get c_n 5 1
2314ck_nl 1
2315end
2316fn main to int
2317c = argcnt
2318if gt c 1
2319if and eq c 2 ck_istable
2320r = write 1 c_hwt 0 sub len c_hwt c_hxn
2321ret 0
2322end
2323ck_txt 8 2
2324ck_nl 2
2325ret 2
2326end
2327ck_rows
2328ck_hosts
2329n = ck_slurp
2330put c_s 1 n
2331ck_head
2332ck_types
2333ck_globs
2334ck_funcs
2335for f ulong get c_n 3 bound 65536
2336ck_fn f
2337end
2338ck_accept n
2339ret 0
2340end
2341
2342
2343note Class-2 pool globals never expose an address. Each access names the current storage.
2344fn ck_tpool o ulong op ulong to void
2345g = ck_im o
2346ck_want lt g get c_n 2 24
2347ck_want eq get c_gcl g 2 16
2348t = ulong get c_gty g
2349if eq op 112
2350ck_want eq ck_ty o 5 16
2351ret
2352end
2353if eq op 111
2354ck_want eq ck_ty o 9 16
2355ck_want eq ck_ta o 1 5 16
2356ret
2357end
2358if eq op 113
2359ck_want eq ck_ty o t 16
2360ck_want eq ck_ta o 1 5 16
2361ret
2362end
2363if eq op 114
2364ck_want eq ck_ta o 1 5 16
2365ck_want eq ck_ta o 2 t 16
2366ret
2367end
2368ck_want eq ck_ty o 9 16
2369ck_want eq ck_ta o 1 8 16
2370ck_want eq ck_ta o 2 5 16
2371ck_want eq ck_ta o 3 5 16
2372ck_want eq t 2 16
2373end