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 / bridge / cuda / gate.om

1898 lines · 34651 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note bridge/cuda/gate.om: BRIDGE-CUDA, the gate of the CUDA compatibility profile slice (one slice of CUDApp compat/),
3note in seeded Omega (Linux AArch64). Build from the repository root (OM-2 program mode; seed/ng/sha256.om supplies
4note sh_dat, sh_all, sh_dig, sh_hexd):
5note { printf 'om2\n'; cat seed/ng/sha256.om bridge/cuda/gate.om; } | seed/out/omc > gate
6note Run from the repository root:
7note gate SCRATCH C0CHECK FIXTURE [CUDAPP OLDOMC CC_AARCH64 CC_X86_64]
8note SCRATCH a new directory (made 0700); an existing one is refused (exit 2). It must be absolute (start with /)
9note when the oracle tier runs: build.sh builds in absolute directories.
10note C0CHECK bridge/cuda/c0_check.om built after gpu/nvidia/om/cache/digest.om
11note FIXTURE bridge/cuda/fixture.om built
12note Tier A (always): the work of CUDApp compat/cuda/test.sh at 84b524ca, with the executables and the PTX made by
13note FIXTURE instead of by gcc and build.sh. FIXTURE writes the PTX, and synthesizes both executables twice from
14note bridge/cuda/fixture-ISA.tsv (the profile reader's own view of the gcc executables): the two builds must hold
15note the same bytes, and C0CHECK emit on the synthetic executable must give the table again, line for line after
16note the first (the first line is the artifact row, which names the executable's own digest). The v3 profiles
17note are then re-pinned to the synthetic digests, and the checks of test.sh run with the same mutations. Their
18note transcript, without the two "built ISA" lines whose digests name gcc's executables, must equal lines 3 to the
19note end of bridge/cuda/test-sh-84b524ca.txt, the output of test.sh at CUDApp 84b524ca.
20note Tier B (oracle, only with the four optional arguments, all absolute paths): runs CUDAPP/compat/cuda/test.sh
21note with OMEGA_OMC=OLDOMC (the compiler that test pins) and PATH=/usr/bin:/bin; its output must equal the whole
22note transcript file. Then builds vadd_drv for each ISA as build.sh does, but links it against the libcuda.so.1
23note stub made by FIXTURE: the executable must have the digest pinned in the v3 profile. Then C0CHECK emit of the
24note test's own executables must equal the fixture tables, and of its no-libcuda executable the synthetic one.
25note Then (tier A, outside the transcript) the limit check: three profile versions totalling one byte under 16 MiB
26note are read and compared, 16 MiB refused, and 16 MiB over the shortest indexed row is under the name table's size;
27note and every file named in bridge/cuda/copied.tsv must have its digest
28note (tier B checks CUDAPP/compat/cuda's files against the same table). Transcript lines 1-2 (gcc's hashes) are
29note compared only by tier B.
30note Output: one line per check, then BRIDGE-CUDA PASS|FAIL checks=N failed=F oracle=PASS|FAIL|NOT_RUN
31note hardware=NOT_RUN. The device run of vadd_drv (VADD_U32 PASS on a GPU) is never made here.
32note Exit 0 PASS, 1 FAIL, 2 bad usage or setup. Buffers: files up to 16 MiB, captured outputs up to 1 MiB, paths
33note up to 4096 bytes; anything larger is a FAIL or exit 2, never truncated.
34text t_usage "usage: gate SCRATCH C0CHECK FIXTURE [CUDAPP OLDOMC CC_AARCH64 CC_X86_64] (run from the omega-mv root)\n"
35text t_noscr "BRIDGE-CUDA INVALID: SCRATCH exists or cannot be made\n"
36text t_nogold "BRIDGE-CUDA INVALID: cannot read bridge/cuda/test-sh-84b524ca.txt\n"
37text t_check "check"
38text t_emit "emit"
39text t_ptx "ptx"
40text t_exe "exe"
41text t_stub "stub"
42text t_full "full"
43text t_nolib "nolib"
44text t_aarch64 "aarch64"
45text t_x86 "x86_64"
46text t_static "static"
47text t_x86s "x86_64-static"
48text f_pfx "bridge/cuda/profile-c0-"
49text f_v "-v"
50text f_tsv ".tsv"
51text f_tab "bridge/cuda/fixture-"
52text f_gold "bridge/cuda/test-sh-84b524ca.txt"
53text f_null "/dev/null"
54text f_sh "/bin/sh"
55text f_test "/compat/cuda/test.sh"
56text f_drv "/compat/cuda/fixture/vadd_drv.c"
57text f_orc "/src/cudapp_om_standalone_oracles.c"
58text f_cudainc "-I/usr/local/cuda/include"
59text e_path "PATH=/usr/bin:/bin"
60text e_omc "OMEGA_OMC="
61text s_ptx "v.ptx"
62text s_ea "ea"
63text s_ea2 "ea2"
64text s_ex "ex"
65text s_ex2 "ex2"
66text s_en "en"
67text s_pa "pa.tsv"
68text s_px "px.tsv"
69text s_out ".out"
70text s_err ".err"
71text s_slash "/"
72text s_old "old"
73text s_oldout "old.out"
74text s_olda "old/a/"
75text s_oldptx "old/a/vadd_u32.ptx"
76text s_oldnl "old/nolib/vadd_drv"
77text s_vdrv "/vadd_drv"
78text s_b "b-"
79text s_lib "/libcuda.so.1"
80text s_se "se-"
81text s_re "re-"
82text s_bar "bar.ptx"
83text s_multi "multi.ptx"
84text c_std "-std=c11"
85text c_o2 "-O2"
86text c_noid "-fno-ident"
87text c_fpm "-ffile-prefix-map="
88text c_eqdot "=."
89text c_c "-c"
90text c_fpc "-ffp-contract=off"
91text c_o "-o"
92text c_vd "vadd_drv"
93text c_vdo "vadd_drv.o"
94text c_so "standalone_oracles.o"
95text c_l "-L."
96text c_lc "-l:libcuda.so.1"
97text m_hostexe "artifact\thost-exe\t"
98text m_ptx "artifact\tptx\t"
99text m_import "import\t"
100text m_cuda "cuda"
101text m_cuinit "import\tcuInit\t"
102text m_add "import\tcuMemAllocManaged\tcuda\tsupported\tcuMemAllocManaged\n"
103text m_sup "import\tcuInit\tcuda\tsupported"
104text m_unsup "import\tcuInit\tcuda\tunsupported"
105text m_s1 "schema\tAIEN_CUDA_COMPAT_PROFILE\t1"
106text m_s2 "schema\tAIEN_CUDA_COMPAT_PROFILE\t2"
107text m_host "host\t"
108text m_g34 "\tGLIBC_2.34"
109text m_g17 "\tGLIBC_2.17"
110text m_lookup "lookup\tabsent\tcuMod\n"
111text m_libc "needed\tlibc.so.6\t"
112text m_ret "\tret;"
113text m_bar "\tbar.sync 0;"
114text m_rr "\tret; ret;"
115text m_tcuda "\tcuda\t"
116text m_libcuda "libcuda.so.1"
117text m_refused "REFUSED "
118text r_hostisa "host-isa"
119text r_hash "artifact-hash"
120text r_unlisted "unlisted import cuInit"
121text r_missing "missing import cuMemAllocManaged"
122text r_status "unsupported-status"
123text r_schema "schema-mismatch"
124text r_floor "libc-floor"
125text r_lookup "dynamic-lookup"
126text r_needed "unlisted needed libc.so.6"
127text r_nolib "missing needed libcuda.so.1"
128text r_bar "unsupported-op ptxop bar.sync"
129text r_multi "multi-statement"
130text n_isaax "isa-a-on-x86"
131text n_isaxa "isa-x86-on-a"
132text n_xa "x86-exe-as-a"
133text n_hash "edited-hash"
134text n_drop "dropped-import"
135text n_add "added-import"
136text n_unsup "unsupported-status"
137text n_schema "schema-2"
138text n_floor "libc-floor"
139text n_lookup "lookup-prefix"
140text n_needed "profile-missing-needed"
141text n_nolib "exe-missing-libcuda"
142text n_bar "ptx-barrier"
143text n_multi "ptx-multi"
144text p_hash "p-hash.tsv"
145text p_drop "p-drop.tsv"
146text p_add "p-add.tsv"
147text p_unsup "p-unsup.tsv"
148text p_schema "p-schema.tsv"
149text p_floor "p-floor.tsv"
150text p_lookup "p-lookup.tsv"
151text p_needed "p-noneed.tsv"
152text p_nolib "p-nolib.tsv"
153text p_bar "p-bar.tsv"
154text p_multi "p-multi.tsv"
155text o_builtptx "built ptx "
156text o_synth "synthesized "
157text o_built "built "
158text o_pass "PASS "
159text o_fail "FAIL "
160text o_imports " v1/v2/v3 CUDA imports: empty diff"
161text o_impfail " v1/v2/v3 CUDA imports differ"
162text o_admit "admit "
163text o_refuse "refuse "
164text o_rc " rc="
165text o_want " want "
166text o_colon ": "
167text o_testpass "CUDA-C0-PROFILE-TEST PASS"
168text o_testfail "CUDA-C0-PROFILE-TEST FAIL"
169text o_twice ": two syntheses hold the same bytes"
170text o_twicef ": two syntheses differ"
171text o_ptxf "ptx: FIXTURE ptx failed"
172text o_exef ": FIXTURE exe failed"
173text o_emit "emit "
174text o_emitok ": C0CHECK reads the synthetic executable as bridge/cuda/fixture table (after line 1)"
175text o_emitf ": C0CHECK reading of the synthetic executable differs from the fixture table"
176text o_nlok "emit nolib: synthetic no-libcuda executable carries no CUDA import and no libcuda.so.1"
177text o_nlf "emit nolib: synthetic no-libcuda executable still names CUDA"
178text o_gold "transcript: equals bridge/cuda/test-sh-84b524ca.txt lines 3 to end"
179text o_goldf "transcript: differs from bridge/cuda/test-sh-84b524ca.txt lines 3 to end"
180text o_otest "oracle test.sh: output equals bridge/cuda/test-sh-84b524ca.txt"
181text o_otestf "oracle test.sh: output differs from bridge/cuda/test-sh-84b524ca.txt, exit "
182text o_obuild "oracle build "
183text o_ostub ": gcc linked against the Omega libcuda.so.1 stub gives the v3 profile's digest"
184text o_ostubf ": gcc linked against the Omega libcuda.so.1 stub does not give the v3 profile's digest"
185text o_oemit "oracle emit "
186text o_oemitok ": C0CHECK reads test.sh's gcc executable as bridge/cuda/fixture table"
187text o_oemitf ": C0CHECK reading of test.sh's gcc executable differs from the fixture table"
188text o_onlok "oracle emit nolib: test.sh's no-libcuda executable reads as the synthetic one (after line 1)"
189text o_onlf "oracle emit nolib: test.sh's no-libcuda executable differs from the synthetic one"
190text o_sum "BRIDGE-CUDA "
191text o_spass "PASS"
192text o_sfail "FAIL"
193text o_checks " checks="
194text o_failed " failed="
195text o_oracle " oracle="
196text o_notrun "NOT_RUN"
197text o_repin "repin: the v3 profiles pinned to the synthetic digests"
198text o_hw " hardware=NOT_RUN\n"
199text o_lim "limit: profile versions one byte under 16 MiB together are read and compared, 16 MiB refused; the name table cannot fill"
200text o_limf "limit: the 16 MiB bound on the three profile versions does not hold at its edge, or the name table could fill under it"
201text o_copies "copies: digests equal bridge/cuda/copied.tsv, files "
202text o_copiesf "copies: digest differs from bridge/cuda/copied.tsv (or the table is malformed): "
203text o_oracle1 "oracle "
204text f_copied "bridge/cuda/copied.tsv"
205text f_bc "bridge/cuda/"
206text f_cc "/compat/cuda/"
207text s_lim "lim"
208text m_row "import\tcuInit\tcuda\n"
209text m_minrow "import\t\tcuda"
210const BIG ulong 16777216
211const CAP ulong 1048576
212global g_pa uchar 4096
213global g_ap uchar 32768
214global g_av uchar 65536
215global g_ev uchar 8192
216global g_cw uchar 4096
217global g_b uchar 16777216
218global g_c uchar 16777216
219global g_r uchar 1048576
220global g_g uchar 1048576
221global g_t uchar 1048576
222global g_o uchar 1048576
223global g_pt uchar 16384
224global g_h uchar 512
225global g_stb uchar 4
226global g_io ulong 2097152
227global g_il ulong 2097152
228global g_iv ulong 4
229global g_n ulong 64
230note g_n: 0 path length, 8 argv bytes, 9 argc, 10 env bytes, 11 g_b length, 12 g_c length, 13 g_r length,
231note 14 g_g length, 15 g_t length, 16 g_o length, 17 failures, 18 checks, 40..43 pattern lengths, 22 cwd length,
232note 23 tier-A failures, 24 transcript on, 25 names indexed, 27 import paths under SCRATCH/lim (ilimit),
233note 30..36 argument path lengths
234note g_ap: argument k at 4096*k (0 SCRATCH with '/', 1 C0CHECK, 2 FIXTURE, 3 CUDAPP, 4 OLDOMC, 5 CC_AARCH64,
235note 6 CC_X86_64). g_h: digest k as 64 hex at 64*k (0 synthetic aarch64, 1 synthetic x86_64, 2 synthetic nolib,
236note 3 ptx, 4 mutated ptx, 5 a digest read from a profile, 6 scratch).
237note ---- output: a line in g_o, flushed to stdout and, while g_n 24 is 1, kept in the transcript g_t
238fn oc c ulong to void
239n = get g_n 16
240if lt n CAP
241put g_o n uchar c
242put g_n 16 add n 1
243end
244end
245fn ot t view uchar * to void
246for i ulong len t bound 4096
247oc ulong get t i
248end
249end
250fn onum v ulong to void
251if ge v 10
252onum div v 10
253end
254oc add 48 rem v 10
255end
256fn ohx k ulong to void
257for j ulong 64
258oc ulong get g_h add mul k 64 j
259end
260end
261fn onl to void
262oc 10
263n = get g_n 16
264r = write 1 g_o 0 n
265if eq get g_n 24 1
266t = get g_n 15
267for j ulong n bound 1048576
268if lt add t j CAP
269put g_t add t j get g_o j
270end
271end
272put g_n 15 add t n
273end
274put g_n 16 0
275end
276fn ook ok bool to void
277put g_n 18 add get g_n 18 1
278if ok
279ot o_pass
280else
281ot o_fail
282put g_n 17 add get g_n 17 1
283end
284end
285note ---- paths
286fn pclr to void
287put g_n 0 0
288end
289fn pc c ulong to void
290n = get g_n 0
291if lt n 4096
292put g_pa n uchar c
293end
294put g_n 0 add n 1
295end
296fn pt t view uchar * to void
297for i ulong len t bound 4096
298pc ulong get t i
299end
300end
301fn pak k ulong to void
302for j ulong get g_n add 30 k bound 4096
303pc ulong get g_ap add mul k 4096 j
304end
305end
306fn psc t view uchar * to void
307pclr
308pak 0
309pt t
310end
311fn pss t view uchar * u view uchar * to void
312psc t
313pt u
314end
315fn fopn fl ulong mode ulong to int
316if gt get g_n 0 4095
317ret -1
318end
319r = fopen g_pa 0 get g_n 0 int fl int mode
320if lt r 0
321ret -1
322end
323ret int r
324end
325fn frd to int
326ret fopn 524288 0
327end
328fn fwr to int
329ret fopn 524865 420
330end
331fn fclo fd int to void
332if ge fd 0
333r = fclose fd
334end
335end
336note ---- g_b: load the file g_pa (true when whole and under 16 MiB), save it to g_pa
337fn bload to bool
338put g_n 11 0
339fd = frd
340if lt fd 0
341ret false
342end
343n = ulong 0
344ok = true
345while true bound 16777218
346x = read fd g_b n sub BIG n
347if lt x 0
348ok = false
349break
350end
351if eq x 0
352break
353end
354n = add n ulong x
355if ge n BIG
356ok = false
357break
358end
359end
360fclo fd
361put g_n 11 n
362ret ok
363end
364fn bsave to bool
365fd = fwr
366if lt fd 0
367ret false
368end
369n = get g_n 11
370o = ulong 0
371ok = true
372while lt o n bound 16777217
373x = write fd g_b o sub n o
374if le x 0
375ok = false
376break
377end
378o = add o ulong x
379end
380fclo fd
381ret ok
382end
383note g_b into g_r, g_g (false when over 1 MiB)
384fn b2r to bool
385n = get g_n 11
386if ge n CAP
387ret false
388end
389for j ulong n bound 1048576
390put g_r j get g_b j
391end
392put g_n 13 n
393ret true
394end
395fn b2g to bool
396n = get g_n 11
397if ge n CAP
398ret false
399end
400for j ulong n bound 1048576
401put g_g j get g_b j
402end
403put g_n 14 n
404ret true
405end
406note digest of the file g_pa into slot k; false when unreadable
407fn hfile k ulong to bool
408if not bload
409ret false
410end
411n = get g_n 11
412for j ulong n bound 16777216
413put sh_dat j get g_b j
414end
415sh_all n
416for j ulong 32
417b = get sh_dig j
418put g_h add mul k 64 mul j 2 sh_hexd uint shr b 4
419put g_h add add mul k 64 mul j 2 1 sh_hexd uint and b 15
420end
421ret true
422end
423fn heq a ulong b ulong to bool
424for j ulong 64
425if ne get g_h add mul a 64 j get g_h add mul b 64 j
426ret false
427end
428end
429ret true
430end
431note ---- edits of g_b
432note does g_b hold digest slot a at offset i
433fn hmat i ulong a ulong to bool
434o = mul a 64
435for j ulong 64
436if ne get g_b add i j get g_h add o j
437ret false
438end
439end
440ret true
441end
442note replace every occurrence of digest slot a by digest slot b (same length, in place)
443fn hsub a ulong b ulong to void
444n = get g_n 11
445if lt n 64
446ret
447end
448o = mul b 64
449for i ulong add sub n 64 1 bound 16777216
450if hmat i a
451for j ulong 64
452put g_b add i j get g_h add o j
453end
454end
455end
456end
457note digest in the field after the line prefix t (first such line) into slot 5; false when absent
458fn hfind t view uchar * to bool
459n = get g_n 11
460s = ulong 0
461while lt s n bound 16777216
462m = le add add s len t 64 n
463for j ulong len t bound 4096
464if m
465if ne get g_b add s j get t j
466m = false
467end
468end
469end
470if m
471for j ulong 64
472put g_h add 320 j get g_b add add s len t j
473end
474ret true
475end
476while lt s n bound 16777216
477c = get g_b s
478s = add s 1
479if eq c 10
480break
481end
482end
483end
484ret false
485end
486fn bapp t view uchar * to bool
487n = get g_n 11
488if ge add n len t BIG
489ret false
490end
491for j ulong len t bound 4096
492put g_b add n j get t j
493end
494put g_n 11 add n len t
495ret true
496end
497note patterns 0..3 at 4096*k, lengths in g_n 40..43
498fn setp k ulong t view uchar * to void
499for j ulong len t bound 4096
500put g_pt add mul k 4096 j get t j
501end
502put g_n add 40 k len t
503end
504fn cput c uchar to void
505n = get g_n 12
506if lt n BIG
507put g_c n c
508end
509put g_n 12 add n 1
510end
511fn cpat k ulong to void
512for j ulong get g_n add 40 k bound 4096
513cput get g_pt add mul k 4096 j
514end
515end
516fn crng s ulong e ulong to void
517j = s
518while lt j e bound 16777216
519cput get g_b j
520j = add j 1
521end
522end
523note does g_b[s,e) start with (w 0), equal (w 1) or end with (w 2) pattern k
524fn lmat s ulong e ulong k ulong w ulong to bool
525p = get g_n add 40 k
526if gt p sub e s
527ret false
528end
529if eq w 1
530if ne p sub e s
531ret false
532end
533end
534b = s
535if eq w 2
536b = sub e p
537end
538ret pmat b k
539end
540note does g_b at b hold pattern k
541fn pmat b ulong k ulong to bool
542q = mul k 4096
543for j ulong get g_n add 40 k bound 4096
544x = get g_b add b j
545if ne x get g_pt add q j
546ret false
547end
548end
549ret true
550end
551note rewrite g_b line by line through g_c, as sed or grep -v would:
552note md 1 drop lines starting with pattern 0; md 2 lines starting with 0 get 1 in its place; md 3 a line equal to
553note 0 becomes 1; md 4 the line 1 goes before each line equal to 0; md 5 a line starting with 0 and ending with 2
554note (the two not overlapping) ends with 1 instead of 2. False when the result passes 16 MiB.
555fn xl md ulong to bool
556n = get g_n 11
557put g_n 12 0
558s = ulong 0
559while lt s n bound 16777216
560e = s
561while lt e n bound 16777216
562if eq get g_b e 10
563break
564end
565e = add e 1
566end
567k = true
568if eq md 1
569k = not lmat s e 0 0
570end
571if eq md 2
572if lmat s e 0 0
573cpat 1
574s = add s get g_n 40
575end
576end
577if eq md 3
578if lmat s e 0 1
579cpat 1
580s = e
581end
582end
583if eq md 4
584if lmat s e 0 1
585cpat 1
586cput 10
587end
588end
589if eq md 5
590if lmat s e 0 0
591if lmat s e 2 2
592if le add get g_n 40 get g_n 42 sub e s
593crng s sub e get g_n 42
594cpat 1
595s = e
596end
597end
598end
599end
600if k
601crng s e
602if lt e n
603cput 10
604end
605end
606s = add e 1
607end
608m = get g_n 12
609if gt m BIG
610ret false
611end
612for j ulong m bound 16777216
613put g_b j get g_c j
614end
615put g_n 11 m
616ret true
617end
618note ---- processes
619fn aclr to void
620put g_n 8 2
621put g_n 9 0
622end
623fn apa to void
624p = get g_n 8
625n = get g_n 0
626if gt add add p n 2 65536
627exit 2
628end
629for j ulong n bound 4096
630put g_av add add p 2 j get g_pa j
631end
632put g_av p uchar and n 255
633put g_av add p 1 uchar shr n 8
634put g_n 8 add p add n 2
635c = add get g_n 9 1
636put g_n 9 c
637put g_av 0 uchar and c 255
638put g_av 1 uchar shr c 8
639end
640fn atx t view uchar * to void
641pclr
642pt t
643apa
644end
645fn ask k ulong to void
646pclr
647pak k
648apa
649end
650fn ast t view uchar * to void
651psc t
652apa
653end
654note the environment: PATH, and OMEGA_OMC when the oracle runs
655fn envset omc bool to void
656put g_ev 0 1
657put g_ev 1 0
658p = ulong 2
659put g_ev p uchar len e_path
660put g_ev add p 1 0
661for j ulong len e_path bound 64
662put g_ev add add p 2 j get e_path j
663end
664p = add add p 2 len e_path
665if omc
666put g_ev 0 2
667n = add len e_omc get g_n 34
668put g_ev p uchar and n 255
669put g_ev add p 1 uchar shr n 8
670p = add p 2
671for j ulong len e_omc bound 64
672put g_ev add p j get e_omc j
673end
674p = add p len e_omc
675for j ulong get g_n 34 bound 4096
676put g_ev add p j get g_ap add 16384 j
677end
678p = add p get g_n 34
679end
680put g_n 10 p
681end
682fn redir s int d int to void
683if ne dupfd s d 0 long d
684exit 127
685end
686end
687note run the argument list (in g_cw when g_n 22 is not 0), stdin /dev/null, stdout and stderr to SCRATCH/o.out
688note and SCRATCH/o.err: the exit code, 256 + the signal, 512 when a file could not be opened, 1000 when killed at
689note the 600 s deadline
690fn runo o view uchar * to ulong
691pclr
692pt f_null
693fi = frd
694pss o s_out
695fo = fwr
696pss o s_err
697fe = fwr
698if or lt fi 0 or lt fo 0 lt fe 0
699fclo fi
700fclo fo
701fclo fe
702ret 512
703end
704pid = fork
705if lt pid 0
706exit 2
707end
708if eq pid 0
709redir fi 0
710redir fo 1
711redir fe 2
712if ne get g_n 22 0
713if ne chdir g_cw 0 get g_n 22 0
714exit 127
715end
716end
717r = execenv g_av 0 get g_n 8 g_ev 0 get g_n 10
718exit 127
719end
720fclo fi
721fclo fo
722fclo fe
723t0 = monons
724while true bound 1000000000
725r = waitpid int pid g_stb 0 len g_stb 1
726if eq r pid
727x = ulong get g_stb 0
728if ne x 0
729ret add 256 x
730end
731ret ulong get g_stb 1
732end
733if lt r 0
734exit 2
735end
736if gt sub monons t0 600000000000
737r = killpid int pid 9
738r = waitpid int pid g_stb 0 len g_stb 0
739ret 1000
740end
741q = sleepns 200000
742end
743exit 2
744end
745note SCRATCH/o.out into g_r; false when unreadable or over 1 MiB
746fn rout o view uchar * to bool
747pss o s_out
748if not bload
749ret false
750end
751ret b2r
752end
753note ---- C0CHECK
754fn ck0 w view uchar * to void
755aclr
756ask 1
757atx w
758end
759note is "REFUSED " + why inside g_r
760fn rhas why view uchar * to bool
761n = get g_n 13
762w = add len m_refused len why
763if lt n w
764ret false
765end
766for i ulong add sub n w 1 bound 1048576
767m = true
768for j ulong w bound 8192
769if m
770c = get m_refused 0
771if lt j len m_refused
772c = get m_refused j
773else
774c = get why sub j len m_refused
775end
776if ne get g_r add i j c
777m = false
778end
779end
780end
781if m
782ret true
783end
784end
785ret false
786end
787note g_r as the shell's $(cat file) (trailing newlines dropped) or tr '\n' ';' (sem true)
788fn orr sem bool to void
789n = get g_n 13
790if not sem
791while gt n 0 bound 1048576
792if ne get g_r sub n 1 10
793break
794end
795n = sub n 1
796end
797end
798for j ulong n bound 1048576
799c = get g_r j
800if and sem eq c 10
801oc 59
802else
803oc ulong c
804end
805end
806end
807fn admit nm view uchar * to void
808rc = runo nm
809ok = rout nm
810ok = and ok eq rc 0
811ook ok
812ot o_admit
813ot nm
814if not ok
815ot o_rc
816onum rc
817end
818ot o_colon
819orr false
820onl
821end
822fn refuse nm view uchar * why view uchar * to void
823rc = runo nm
824ok = rout nm
825if ok
826ok = and eq rc 1 rhas why
827end
828ook ok
829ot o_refuse
830ot nm
831ot o_rc
832onum rc
833if not ok
834ot o_want
835ot why
836end
837ot o_colon
838orr true
839onl
840end
841note check P E X R with SCRATCH names and a run ISA
842fn ckargs p view uchar * e view uchar * x view uchar * to void
843ck0 t_check
844ast p
845ast e
846ast x
847end
848note ---- profile copies
849fn ploadv isa view uchar * v ulong to bool
850pclr
851pt f_pfx
852pt isa
853pt f_v
854pc add 48 v
855pt f_tsv
856ret bload
857end
858note load a profile copy, keep slot 5 as its pinned host-exe digest
859fn pload p view uchar * to bool
860psc p
861ret bload
862end
863fn psave p view uchar * to bool
864psc p
865ret bsave
866end
867note ---- the import lists of v1, v2, v3 as multisets of names. The binding limit is g_b: the three versions of one
868note ISA are read into it together and must hold under 16 MiB (checked by ilimit). The name table g_io/g_il cannot
869note overflow under that limit: an indexed row is at least as long as m_minrow (import TAB, an empty name, TAB,
870note cuda), and ilimit checks that 16 MiB divided by that length is under len g_io. A put past the table would
871note trap (exit 103), never overrun.
872fn idx v ulong o ulong to void
873n = get g_n 11
874s = o
875while lt s n bound 16777216
876e = s
877while lt e n bound 16777216
878if eq get g_b e 10
879break
880end
881e = add e 1
882end
883if lmat s e 3 0
884f = add s len m_import
885g = f
886while lt g e bound 16777216
887if eq get g_b g 9
888break
889end
890g = add g 1
891end
892c = false
893if lt g e
894c = iscuda add g 1 e
895end
896if c
897k = get g_n 25
898put g_io k f
899put g_il k sub g f
900put g_n 25 add k 1
901end
902end
903s = add e 1
904end
905put g_iv v get g_n 25
906end
907note is g_b[h, e) the field cuda (ending at e or at a tab)
908fn iscuda h ulong e ulong to bool
909if gt add h 4 e
910ret false
911end
912if ne get g_b h 99
913ret false
914end
915if ne get g_b add h 1 117
916ret false
917end
918if ne get g_b add h 2 100
919ret false
920end
921if ne get g_b add h 3 97
922ret false
923end
924if lt add h 4 e
925ret eq get g_b add h 4 9
926end
927ret true
928end
929fn ieq a ulong b ulong to bool
930la = get g_il a
931if ne la get g_il b
932ret false
933end
934oa = get g_io a
935ob = get g_io b
936for j ulong la bound 16777216
937x = get g_b add oa j
938if ne x get g_b add ob j
939ret false
940end
941end
942ret true
943end
944note occurrences of name i among the names of version v
945fn icnt i ulong v ulong to ulong
946lo = ulong 0
947if gt v 0
948lo = get g_iv sub v 1
949end
950c = ulong 0
951k = lo
952while lt k get g_iv v bound 2097152
953if ieq i k
954c = add c 1
955end
956k = add k 1
957end
958ret c
959end
960fn isame a ulong b ulong to bool
961la = ulong 0
962if gt a 0
963la = get g_iv sub a 1
964end
965lb = ulong 0
966if gt b 0
967lb = get g_iv sub b 1
968end
969if ne sub get g_iv a la sub get g_iv b lb
970ret false
971end
972i = la
973while lt i get g_iv a bound 2097152
974if ne icnt i a icnt i b
975ret false
976end
977i = add i 1
978end
979ret true
980end
981note load and compare the three versions; the path is bridge/cuda/profile-c0-ISA-vN.tsv, or SCRATCH/lim-vN.tsv
982note while g_n 27 is 1 (ilimit)
983fn iload isa view uchar * to bool
984put g_n 25 0
985setp 3 m_import
986put g_n 11 0
987ok = true
988for v ulong 3
989o = get g_n 11
990if eq get g_n 27 1
991psc s_lim
992else
993pclr
994pt f_pfx
995pt isa
996end
997pt f_v
998pc add 49 v
999pt f_tsv
1000fd = frd
1001if lt fd 0
1002ok = false
1003end
1004n = o
1005while ge fd 0 bound 16777218
1006x = read fd g_b n sub BIG n
1007if le x 0
1008if lt x 0
1009ok = false
1010end
1011break
1012end
1013n = add n ulong x
1014if ge n BIG
1015ok = false
1016break
1017end
1018end
1019fclo fd
1020put g_n 11 n
1021idx v o
1022end
1023if ok
1024ok = and isame 0 1 isame 1 2
1025end
1026ret ok
1027end
1028fn imports isa view uchar * to void
1029ok = iload isa
1030ook ok
1031ot isa
1032if ok
1033ot o_imports
1034else
1035ot o_impfail
1036end
1037onl
1038end
1039note ---- the limit: SCRATCH/lim-v1.tsv is one cuInit row and pad bytes x, v2 and v3 the cuInit row alone
1040fn lfile v ulong pad ulong to bool
1041n = len m_row
1042for j ulong n bound 4096
1043put g_b j get m_row j
1044end
1045for j ulong pad bound 16777216
1046put g_b add n j 120
1047end
1048put g_n 11 add n pad
1049psc s_lim
1050pt f_v
1051pc add 49 v
1052pt f_tsv
1053ret bsave
1054end
1055fn lset pad ulong to bool
1056ok = lfile 0 pad
1057if ok
1058ok = lfile 1 0
1059end
1060if ok
1061ok = lfile 2 0
1062end
1063ret ok
1064end
1065note three versions one byte under BIG together must be read and compared, of BIG refused; and BIG divided by the
1066note shortest indexed row's length must be under the name table's size
1067fn ilimit to void
1068put g_n 27 1
1069r = len m_row
1070ok = lset sub sub BIG 1 mul 3 r
1071if ok
1072ok = iload t_aarch64
1073end
1074if ok
1075ok = lset sub BIG mul 3 r
1076end
1077if ok
1078ok = not iload t_aarch64
1079end
1080if ok
1081ok = lt div BIG len m_minrow len g_io
1082end
1083put g_n 27 0
1084ook ok
1085if ok
1086ot o_lim
1087else
1088ot o_limf
1089end
1090onl
1091end
1092note ---- copies: each row of bridge/cuda/copied.tsv is a sha256, a tab and a file name; the file under
1093note bridge/cuda/ (src 0) or CUDAPP/compat/cuda/ (src 1, the oracle) must have that digest
1094fn copies src ulong to void
1095pclr
1096pt f_copied
1097ok = bload
1098n = get g_n 11
1099if ok
1100for j ulong n bound 16777216
1101put g_c j get g_b j
1102end
1103end
1104rows = ulong 0
1105bad = n
1106s = ulong 0
1107while and ok lt s n bound 16777216
1108e = s
1109while lt e n bound 16777216
1110if eq get g_c e 10
1111break
1112end
1113e = add e 1
1114end
1115if lt sub e s 66
1116ok = false
1117bad = s
1118break
1119end
1120if ne get g_c add s 64 9
1121ok = false
1122bad = s
1123break
1124end
1125pclr
1126if eq src 0
1127pt f_bc
1128else
1129pak 3
1130pt f_cc
1131end
1132j = add s 65
1133while lt j e bound 16777216
1134pc ulong get g_c j
1135j = add j 1
1136end
1137if hfile 6
1138for q ulong 64
1139hx = get g_h add 384 q
1140if ne hx get g_c add s q
1141ok = false
1142end
1143end
1144else
1145ok = false
1146end
1147if not ok
1148bad = s
1149break
1150end
1151rows = add rows 1
1152s = add e 1
1153end
1154if eq rows 0
1155ok = false
1156end
1157ook ok
1158if eq src 1
1159ot o_oracle1
1160end
1161if ok
1162ot o_copies
1163onum rows
1164else
1165ot o_copiesf
1166j = add bad 65
1167while lt j n bound 16777216
1168c = get g_c j
1169if eq c 10
1170break
1171end
1172oc ulong c
1173j = add j 1
1174end
1175end
1176onl
1177end
1178note ---- FIXTURE
1179fn fx0 w view uchar * to void
1180aclr
1181ask 2
1182atx w
1183end
1184note g_r against g_b, after the first line of each (sk true) or whole (sk false)
1185fn sameb sk bool to bool
1186i = ulong 0
1187j = ulong 0
1188n = get g_n 13
1189m = get g_n 11
1190if sk
1191while lt i n bound 1048576
1192c = get g_r i
1193i = add i 1
1194if eq c 10
1195break
1196end
1197end
1198while lt j m bound 16777216
1199c = get g_b j
1200j = add j 1
1201if eq c 10
1202break
1203end
1204end
1205end
1206if ne sub n i sub m j
1207ret false
1208end
1209for k ulong sub n i bound 1048576
1210if ne get g_r add i k get g_b add j k
1211ret false
1212end
1213end
1214ret true
1215end
1216note synthesize SCRATCH/o from the fixture table of isa with flavour fl
1217fn synth isa view uchar * fl view uchar * o view uchar * to ulong
1218fx0 t_exe
1219pclr
1220pt f_tab
1221pt isa
1222pt f_tsv
1223apa
1224pclr
1225pt f_pfx
1226pt isa
1227pt f_v
1228pc 51
1229pt f_tsv
1230apa
1231atx fl
1232ast o
1233ret runo o
1234end
1235note synthesize isa into SCRATCH/a, its digest into slot k
1236fn sone isa view uchar * a view uchar * k ulong to bool
1237if ne synth isa t_full a 0
1238ret false
1239end
1240psc a
1241ret hfile k
1242end
1243note synthesize isa twice into slots k and 6, report
1244fn synth2 isa view uchar * k ulong to void
1245ok = false
1246if eq k 0
1247ok = sone isa s_ea k
1248if ok
1249ok = sone isa s_ea2 6
1250end
1251else
1252ok = sone isa s_ex k
1253if ok
1254ok = sone isa s_ex2 6
1255end
1256end
1257if ok
1258ok = heq k 6
1259end
1260ook ok
1261ot o_synth
1262ot isa
1263oc 32
1264ohx k
1265if ok
1266ot o_twice
1267else
1268ot o_twicef
1269end
1270onl
1271end
1272note C0CHECK emit of the synthetic executable o against the v3 profile and v.ptx into SCRATCH/se-isa, compared
1273fn emitchk isa view uchar * o view uchar * to void
1274ck0 t_emit
1275pclr
1276pt f_pfx
1277pt isa
1278pt f_v
1279pc 51
1280pt f_tsv
1281apa
1282ast o
1283ast s_ptx
1284pclr
1285pt s_se
1286pt isa
1287rc = runo isa
1288ok = eq rc 0
1289if ok
1290ok = rout isa
1291end
1292if ok
1293pclr
1294pt f_tab
1295pt isa
1296pt f_tsv
1297ok = bload
1298end
1299if ok
1300ok = sameb true
1301end
1302ook ok
1303ot o_emit
1304ot isa
1305if ok
1306ot o_emitok
1307else
1308ot o_emitf
1309end
1310onl
1311end
1312note the profile v3 of isa re-pinned to digest slot k, saved as p
1313fn repin isa view uchar * k ulong p view uchar * to bool
1314if not ploadv isa 3
1315ret false
1316end
1317if not hfind m_hostexe
1318ret false
1319end
1320hsub 5 k
1321ret psave p
1322end
1323note ---- tier A
1324fn tiera to void
1325fx0 t_ptx
1326ast s_ptx
1327rc = runo s_ptx
1328ok = eq rc 0
1329if ok
1330psc s_ptx
1331ok = hfile 3
1332end
1333if ok
1334put g_n 24 1
1335ot o_builtptx
1336ohx 3
1337onl
1338put g_n 24 0
1339else
1340ook false
1341ot o_ptxf
1342onl
1343end
1344synth2 t_aarch64 0
1345synth2 t_x86 1
1346emitchk t_aarch64 s_ea
1347emitchk t_x86 s_ex
1348nolib
1349ok = and repin t_aarch64 0 s_pa repin t_x86 1 s_px
1350ook ok
1351ot o_repin
1352onl
1353put g_n 24 1
1354imports t_aarch64
1355imports t_x86
1356put g_n 23 get g_n 17
1357c0tests
1358put g_n 24 0
1359end
1360note the no-libcuda executable: synthesized into SCRATCH/en, digest slot 2; its emit must carry no cuda row
1361fn nolib to void
1362fx0 t_exe
1363pclr
1364pt f_tab
1365pt t_aarch64
1366pt f_tsv
1367apa
1368pclr
1369pt f_pfx
1370pt t_aarch64
1371pt f_v
1372pc 51
1373pt f_tsv
1374apa
1375atx t_nolib
1376ast s_en
1377ok = eq runo s_en 0
1378if ok
1379psc s_en
1380ok = hfile 2
1381end
1382if ok
1383ck0 t_emit
1384pclr
1385pt f_pfx
1386pt t_aarch64
1387pt f_v
1388pc 51
1389pt f_tsv
1390apa
1391ast s_en
1392ast s_ptx
1393ok = eq runo t_nolib 0
1394end
1395if ok
1396ok = rout t_nolib
1397end
1398if ok
1399ok = not nmcuda
1400end
1401ook ok
1402if ok
1403ot o_nlok
1404else
1405ot o_nlf
1406end
1407onl
1408end
1409note does g_r hold the field cuda or the text libcuda.so.1 (after its first line)
1410fn nmcuda to bool
1411n = get g_n 13
1412s = ulong 0
1413while lt s n bound 1048576
1414if eq get g_r s 10
1415break
1416end
1417s = add s 1
1418end
1419while lt s n bound 1048576
1420if rat s m_tcuda
1421ret true
1422end
1423if rat s m_libcuda
1424ret true
1425end
1426s = add s 1
1427end
1428ret false
1429end
1430note does g_r hold t at i
1431fn rat i ulong t view uchar * to bool
1432if gt add i len t get g_n 13
1433ret false
1434end
1435for j ulong len t bound 4096
1436x = get g_r add i j
1437if ne x get t j
1438ret false
1439end
1440end
1441ret true
1442end
1443note a profile variant of pa.tsv: md 0 none, else xl md; then optionally appended text
1444fn pvar p view uchar * md ulong to bool
1445if not pload s_pa
1446ret false
1447end
1448if gt md 0
1449if not xl md
1450ret false
1451end
1452end
1453ret psave p
1454end
1455fn c0tests to void
1456ckargs s_pa s_ea s_ptx
1457atx t_aarch64
1458admit t_aarch64
1459ckargs s_px s_ex s_ptx
1460atx t_static
1461admit t_x86s
1462ckargs s_pa s_ea s_ptx
1463atx t_x86
1464refuse n_isaax r_hostisa
1465ckargs s_px s_ex s_ptx
1466atx t_aarch64
1467refuse n_isaxa r_hostisa
1468ckargs s_pa s_ex s_ptx
1469atx t_static
1470refuse n_xa r_hash
1471ok = pload s_pa
1472hsub 0 1
1473ok = psave p_hash
1474ckargs p_hash s_ea s_ptx
1475atx t_aarch64
1476refuse n_hash r_hash
1477setp 0 m_cuinit
1478ok = pvar p_drop 1
1479ckargs p_drop s_ea s_ptx
1480atx t_aarch64
1481refuse n_drop r_unlisted
1482ok = pload s_pa
1483ok = bapp m_add
1484ok = psave p_add
1485ckargs p_add s_ea s_ptx
1486atx t_aarch64
1487refuse n_add r_missing
1488setp 0 m_sup
1489setp 1 m_unsup
1490ok = pvar p_unsup 2
1491ckargs p_unsup s_ea s_ptx
1492atx t_aarch64
1493refuse n_unsup r_status
1494setp 0 m_s1
1495setp 1 m_s2
1496ok = pvar p_schema 3
1497ckargs p_schema s_ea s_ptx
1498atx t_aarch64
1499refuse n_schema r_schema
1500setp 0 m_host
1501setp 1 m_g17
1502setp 2 m_g34
1503ok = pvar p_floor 5
1504ckargs p_floor s_ea s_ptx
1505atx t_aarch64
1506refuse n_floor r_floor
1507ok = pload s_pa
1508ok = bapp m_lookup
1509ok = psave p_lookup
1510ckargs p_lookup s_ea s_ptx
1511atx t_aarch64
1512refuse n_lookup r_lookup
1513setp 0 m_libc
1514ok = pvar p_needed 1
1515ckargs p_needed s_ea s_ptx
1516atx t_aarch64
1517refuse n_needed r_needed
1518ok = pload s_pa
1519hsub 0 2
1520ok = psave p_nolib
1521ckargs p_nolib s_en s_ptx
1522atx t_aarch64
1523refuse n_nolib r_nolib
1524setp 0 m_ret
1525setp 1 m_bar
1526ok = ptxvar s_bar 4
1527ok = pload s_pa
1528hsub 3 4
1529ok = psave p_bar
1530ckargs p_bar s_ea s_bar
1531atx t_aarch64
1532refuse n_bar r_bar
1533setp 1 m_rr
1534ok = ptxvar s_multi 3
1535ok = pload s_pa
1536hsub 3 4
1537ok = psave p_multi
1538ckargs p_multi s_ea s_multi
1539atx t_aarch64
1540refuse n_multi r_multi
1541if eq get g_n 17 get g_n 23
1542ot o_testpass
1543else
1544ot o_testfail
1545end
1546onl
1547end
1548note v.ptx through xl md into SCRATCH/o, digest slot 4
1549fn ptxvar o view uchar * md ulong to bool
1550psc s_ptx
1551if not bload
1552ret false
1553end
1554if not xl md
1555ret false
1556end
1557psc o
1558if not bsave
1559ret false
1560end
1561ret hfile 4
1562end
1563note ---- tier B
1564fn tierb to void
1565envset true
1566aclr
1567pclr
1568pt f_sh
1569apa
1570pclr
1571pak 3
1572pt f_test
1573apa
1574ast s_old
1575rc = runo s_old
1576ok = rout s_old
1577if ok
1578ok = and eq rc 0 gsame 0
1579end
1580ook ok
1581if ok
1582ot o_otest
1583else
1584ot o_otestf
1585onum rc
1586end
1587onl
1588envset false
1589obuild t_aarch64 5
1590obuild t_x86 6
1591oemit t_aarch64
1592oemit t_x86
1593ck0 t_emit
1594pclr
1595pt f_pfx
1596pt t_aarch64
1597pt f_v
1598pc 51
1599pt f_tsv
1600apa
1601ast s_oldnl
1602ast s_oldptx
1603ok = eq runo s_oldnl 0
1604if ok
1605ok = rout s_oldnl
1606end
1607if ok
1608psc t_nolib
1609pt s_out
1610ok = bload
1611end
1612if ok
1613ok = sameb true
1614end
1615ook ok
1616if ok
1617ot o_onlok
1618else
1619ot o_onlf
1620end
1621onl
1622end
1623note g_r against the golden from line k+1
1624fn gsame k ulong to bool
1625i = ulong 0
1626n = get g_n 14
1627for q ulong k bound 1048576
1628while lt i n bound 1048576
1629c = get g_g i
1630i = add i 1
1631if eq c 10
1632break
1633end
1634end
1635end
1636m = get g_n 13
1637if ne m sub n i
1638ret false
1639end
1640for j ulong m bound 1048576
1641if ne get g_r j get g_g add i j
1642ret false
1643end
1644end
1645ret true
1646end
1647note the gcc of argument slot c, as build.sh, in SCRATCH/b-isa (made here; it is the working directory)
1648fn obuild isa view uchar * c ulong to void
1649psc s_b
1650pt isa
1651r = makedir g_pa 0 get g_n 0 448
1652n = get g_n 0
1653for j ulong n bound 4096
1654put g_cw j get g_pa j
1655end
1656ok = and eq r 0 lt n 4096
1657if ok
1658put g_n 22 n
1659aclr
1660ask c
1661atx c_std
1662atx c_o2
1663atx c_noid
1664pclr
1665pt c_fpm
1666for j ulong n bound 4096
1667pc ulong get g_cw j
1668end
1669pt c_eqdot
1670apa
1671atx f_cudainc
1672atx c_c
1673pclr
1674pak 3
1675pt f_drv
1676apa
1677atx c_o
1678atx c_vdo
1679ok = eq runo isa 0
1680end
1681if ok
1682aclr
1683ask c
1684atx c_std
1685atx c_o2
1686atx c_fpc
1687atx c_noid
1688atx c_c
1689pclr
1690pak 3
1691pt f_orc
1692apa
1693atx c_o
1694atx c_so
1695ok = eq runo isa 0
1696end
1697put g_n 22 0
1698if ok
1699fx0 t_stub
1700pclr
1701pt f_pfx
1702pt isa
1703pt f_v
1704pc 51
1705pt f_tsv
1706apa
1707psc s_b
1708pt isa
1709pt s_lib
1710apa
1711ok = eq runo isa 0
1712end
1713if ok
1714put g_n 22 n
1715aclr
1716ask c
1717atx c_o
1718atx c_vd
1719atx c_vdo
1720atx c_so
1721atx c_l
1722atx c_lc
1723ok = eq runo isa 0
1724put g_n 22 0
1725end
1726if ok
1727psc s_b
1728pt isa
1729pt s_vdrv
1730ok = hfile 6
1731end
1732if ok
1733ok = and ploadv isa 3 hfind m_hostexe
1734end
1735if ok
1736ok = heq 5 6
1737end
1738ook ok
1739ot o_obuild
1740ot isa
1741oc 32
1742ohx 6
1743if ok
1744ot o_ostub
1745else
1746ot o_ostubf
1747end
1748onl
1749end
1750note C0CHECK emit of test.sh's gcc executable must equal the fixture table byte for byte
1751fn oemit isa view uchar * to void
1752ck0 t_emit
1753pclr
1754pt f_pfx
1755pt isa
1756pt f_v
1757pc 51
1758pt f_tsv
1759apa
1760psc s_olda
1761pt isa
1762pt s_vdrv
1763apa
1764ast s_oldptx
1765pclr
1766pt s_re
1767pt isa
1768ok = eq runo isa 0
1769if ok
1770ok = rout isa
1771end
1772if ok
1773pclr
1774pt f_tab
1775pt isa
1776pt f_tsv
1777ok = bload
1778end
1779if ok
1780ok = sameb false
1781end
1782ook ok
1783ot o_oemit
1784ot isa
1785if ok
1786ot o_oemitok
1787else
1788ot o_oemitf
1789end
1790onl
1791end
1792fn usage to void
1793r = write 2 t_usage 0 len t_usage
1794exit 2
1795end
1796fn main to int
1797argc = ulong argcnt
1798if and ne argc 4 ne argc 8
1799usage
1800end
1801for k ulong 7
1802if lt k sub argc 1
1803n = argread add k 1 g_ap mul k 4096 4095
1804if or lt n 1 ge n 4095
1805usage
1806end
1807put g_n add 30 k ulong n
1808end
1809end
1810if and eq argc 8 ne get g_ap 0 47
1811usage
1812end
1813n = get g_n 30
1814if ne get g_ap sub n 1 47
1815put g_ap n 47
1816put g_n 30 add n 1
1817end
1818pclr
1819pak 0
1820r = makedir g_pa 0 sub get g_n 0 1 448
1821if ne r 0
1822r = write 2 t_noscr 0 len t_noscr
1823exit 2
1824end
1825pclr
1826pt f_gold
1827if not bload
1828r = write 2 t_nogold 0 len t_nogold
1829exit 2
1830end
1831if not b2g
1832r = write 2 t_nogold 0 len t_nogold
1833exit 2
1834end
1835envset false
1836tiera
1837note the transcript is complete; compare it
1838ok = tgold
1839ook ok
1840if ok
1841ot o_gold
1842else
1843ot o_goldf
1844end
1845onl
1846ilimit
1847copies 0
1848oracle = ulong 0
1849if eq argc 8
1850f0 = get g_n 17
1851tierb
1852copies 1
1853oracle = 1
1854if ne get g_n 17 f0
1855oracle = 2
1856end
1857end
1858ot o_sum
1859fl = get g_n 17
1860if eq fl 0
1861ot o_spass
1862else
1863ot o_sfail
1864end
1865ot o_checks
1866onum get g_n 18
1867ot o_failed
1868onum fl
1869ot o_oracle
1870if eq oracle 0
1871ot o_notrun
1872end
1873if eq oracle 1
1874ot o_spass
1875end
1876if eq oracle 2
1877ot o_sfail
1878end
1879ot o_hw
1880r = write 1 g_o 0 get g_n 16
1881put g_n 16 0
1882if eq fl 0
1883ret 0
1884end
1885ret 1
1886end
1887note the transcript g_t against the golden from line 3
1888fn tgold to bool
1889n = get g_n 15
1890if gt n 1048575
1891ret false
1892end
1893for j ulong n bound 1048576
1894put g_r j get g_t j
1895end
1896put g_n 13 n
1897ret gsame 2
1898end