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 / core / rsi / om / reuse-eval / judge.om

3560 lines · 59664 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note judge.om: the REUSE-1 judge (spark-rsi-mv #73, lane EvalJudge), written from the frozen
3note contract (omega-mv d6edaad1 docs/reuse/REUSE-1.md), the evaluator formats and the drive.om
4note CLI only; no candidate source is read. Units before it: sha256 ref. Prefix jd / JD / JW / JM.
5note Entry: jdmain (argv[1] = run, tap, calib, build, recheck, controls); see docs/reuse-eval/README.md.
6note
7note String registers: JDS holds 32 byte strings of up to 4095 bytes (register r at r * 4096),
8note lengths in JDSL. Register map: 0..2 scratch, 3 split dir, 4 output dir, 5 base ELF,
9note 6 ALLOW (run), 7 cpu, 8 arm name, 9 LIBDIR (process), 10 MANSHA (process), 11 ALLOW (process),
10note 12 TAPFILE, 13 SPLIT, 14 TRAIN lib, 15 TRAIN mansha, 16 TRAINP lib, 17 TRAINP mansha,
11note 18 drive, 19 omega-mv checkout, 20 omc, 21 calibration file, 22 control dir, 23 nog3 unit path,
12note 24 c4 unit path, 25 DEV split dir, 26..29 control scratch, 30 acquisition dir, 31 jdabs only.
13note Word memory JDM: JMIX index, JMSE sessions, JMEX group .exp, JMRQ group .req, JMOF request
14note offsets, JMRT per-request results (route, r0, r1, status), JMSC scratch.
15text JDW "/usr/bin/taskset-c-echofullcachemethoddeltaselecttap/proc//stat/status/proc/loadavg/proc/self/statVmHWM:VmRSS:arm--rep--g.logproc.logacq.logacq-.manshaindexsessions.req.expCURRENTgen-.man.elf.om.calmanifest_sha256=build AUTHORIZED REVOKED mutant:c1mutant:c1bmutant:c1cunit:check=unit:delta=crashafter:controls.loglib-c0123456789abcdef.tmpctrlarm= wrong= violations=tap_sha256= tap_bytes=drive_exit= elapsed_ns=REBUILD MATCH BLOCKED rebuild pinned usage: judge run|tap|calib|build|recheck|controls (docs/reuse-eval/README.md) queries=cal_sha256=judge error unit:mutant:"
16const JWTASK ulong 0
17const JWDC ulong 16
18const JWDASH ulong 18
19const JWECHO ulong 19
20const JWFULL ulong 23
21const JWCACHE ulong 27
22const JWMETH ulong 32
23const JWDELTA ulong 38
24const JWSEL ulong 43
25const JWTAP ulong 49
26const JWPROC ulong 52
27const JWSTAT ulong 58
28const JWSTATUS ulong 63
29const JWLOADAV ulong 70
30const JWSELF ulong 83
31const JWHWM ulong 98
32const JWRSS ulong 104
33const JWARM ulong 110
34const JWREP ulong 114
35const JWG ulong 119
36const JWLOG ulong 121
37const JWPLOG ulong 125
38const JWACQ ulong 133
39const JWACQ2 ulong 140
40const JWMANS ulong 144
41const JWINDEX ulong 151
42const JWSESS ulong 156
43const JWREQ ulong 164
44const JWEXP ulong 168
45const JWCUR ulong 172
46const JWGEN ulong 179
47const JWMAN ulong 183
48const JWELF ulong 187
49const JWOM ulong 191
50const JWCAL ulong 194
51const JWMSHA ulong 198
52const JWBUILD ulong 214
53const JWAUTH ulong 219
54const JWREVK ulong 231
55const JWMC1 ulong 240
56const JWMC1B ulong 249
57const JWMC1C ulong 259
58const JWUCHK ulong 269
59const JWUDEL ulong 280
60const JWCRASH ulong 291
61const JWCLOG ulong 302
62const JWLIB ulong 314
63const JWCTL ulong 318
64const JWHEX ulong 319
65const JWTMP ulong 335
66const JWCTRL ulong 339
67const JWAEQ ulong 343
68const JWWRONG ulong 347
69const JWVIOL ulong 354
70const JWTSHA ulong 366
71const JWTBYT ulong 377
72const JWDEX ulong 388
73const JWELNS ulong 399
74const JWMATCH ulong 411
75const JWBLK ulong 425
76const JWPIN ulong 441
77const JWUSAGE ulong 449
78const JWQRY ulong 526
79const JWCSHA ulong 535
80const JWERR ulong 546
81const JWUNIT ulong 558
82const JWMUT ulong 563
83const JMIX ulong 0
84const JMSE ulong 4096
85const JMEX ulong 1048576
86const JMRQ ulong 2097152
87const JMOF ulong 8388608
88const JMPRC ulong 9437150
89const JMEND ulong 9437180
90const JMRT ulong 9437184
91const JMSC ulong 10485760
92const JDNONE ulong 18446744073709551615
93global JDS uchar 131072
94global JDSL ulong 32
95global JDM ulong 16777216
96global JDF uchar 16777216
97global JDLB uchar 8388608
98global JDIO uchar 65536
99global JDWB uchar 65536
100global JDPK uchar 4096
101global JDPKN ulong 2
102global JDPF uchar 16
103global JDWS uchar 4
104global JDST uchar 128
105global JDRS ulong 40
106global JDSM ulong 1
107global JDC ulong 64
108global JDA ulong 64
109global JDH ulong 4
110global JDT ulong 8
111global JDXA uchar 16384
112global JDXL ulong 130
113global JDQ ulong 8
114
115note ---- string registers ----
116
117fn jdsclr r ulong to void
118put JDSL r 0
119end
120
121fn jdsc r ulong c uchar to void
122n = get JDSL r
123if ge n 4095
124trap 3
125end
126put JDS add mul r 4096 n c
127put JDSL r add n 1
128end
129
130fn jdsw r ulong off ulong n ulong to void
131for i ulong n
132jdsc r get JDW add off i
133end
134end
135
136fn jdsr r ulong s ulong to void
137n = get JDSL s
138b = mul s 4096
139for i ulong n
140jdsc r get JDS add b i
141end
142end
143
144fn jdscp r ulong s ulong to void
145if eq r s
146ret
147end
148jdsclr r
149jdsr r s
150end
151
152fn jdsnum r ulong v ulong w ulong to void
153d = new uchar 24 0
154k = ulong 0
155x = v
156while true bound 24
157put d k uchar add rem x 10 48
158k = add k 1
159x = div x 10
160if and eq x 0 ge k w
161break
162end
163end
164while gt k 0 bound 24
165k = sub k 1
166jdsc r get d k
167end
168end
169
170fn jdshex r ulong v ulong to void
171for i ulong 16
172sh = mul sub 15 i 4
173jdsc r get JDW add JWHEX and shr v sh 15
174end
175end
176
177fn jdsarg r ulong i ulong to bool
178n = argread i JDS mul r 4096 4095
179if lt n 0
180put JDSL r 0
181ret false
182end
183put JDSL r ulong n
184ret true
185end
186
187fn jdseq r ulong s ulong to bool
188n = get JDSL r
189if ne n get JDSL s
190ret false
191end
192a = mul r 4096
193b = mul s 4096
194for i ulong n
195if ne get JDS add a i get JDS add b i
196ret false
197end
198end
199ret true
200end
201
202fn jdsdash r ulong to bool
203if ne get JDSL r 1
204ret false
205end
206ret eq get JDS mul r 4096 45
207end
208
209fn jdsdsh r ulong to void
210jdsclr r
211jdsc r 45
212end
213
214fn jdsval r ulong to ulong
215n = get JDSL r
216if or eq n 0 gt n 20
217ret JDNONE
218end
219b = mul r 4096
220v = ulong 0
221for i ulong n
222c = ulong get JDS add b i
223if or lt c 48 gt c 57
224ret JDNONE
225end
226v = add mul v 10 sub c 48
227end
228ret v
229end
230
231fn jdspack r ulong to ulong
232n = get JDSL r
233if gt n 8
234ret 0
235end
236b = mul r 4096
237v = ulong 0
238for i ulong n
239v = or v shl ulong get JDS add b i mul i 8
240end
241ret v
242end
243
244note byte i of register r, 256 past the end
245fn jdsb r ulong i ulong to ulong
246if ge i get JDSL r
247ret 256
248end
249ret ulong get JDS add mul r 4096 i
250end
251
252note true if register r starts with the JDW bytes off..off+n
253fn jdspre r ulong off ulong n ulong to bool
254if lt get JDSL r n
255ret false
256end
257b = mul r 4096
258for i ulong n
259if ne get JDS add b i get JDW add off i
260ret false
261end
262end
263ret true
264end
265
266fn jdhexd c ulong to ulong
267if and ge c 48 le c 57
268ret sub c 48
269end
270if and ge c 97 le c 102
271ret sub c 87
272end
273if and ge c 65 le c 70
274ret sub c 55
275end
276ret 16
277end
278
279note the byte k of a hex string in register r (2 hex digits), 256 if bad
280fn jdshexb r ulong k ulong to ulong
281hi = jdhexd jdsb r mul k 2
282lo = jdhexd jdsb r add mul k 2 1
283if or gt hi 15 gt lo 15
284ret 256
285end
286ret add mul hi 16 lo
287end
288
289fn jdsout r ulong to void
290jdsc r 10
291n = write 1 JDS mul r 4096 get JDSL r
292put JDSL r sub get JDSL r 1
293end
294
295note append the string form of an 8-word path: dir r, "/", then JDW off..off+n
296fn jdspath r ulong d ulong off ulong n ulong to void
297jdscp r d
298jdsc r 47
299jdsw r off n
300end
301
302note ---- little-endian words in byte pools ----
303
304fn jdgfw off ulong to ulong
305v = ulong 0
306i = ulong 8
307while gt i 0 bound 8
308i = sub i 1
309v = or shl v 8 ulong get JDF add off i
310end
311ret v
312end
313
314fn jdpfw off ulong v ulong to void
315x = v
316for i ulong 8
317put JDF add off i uchar and x 255
318x = shr x 8
319end
320end
321
322fn jdgiw off ulong to ulong
323v = ulong 0
324i = ulong 8
325while gt i 0 bound 8
326i = sub i 1
327v = or shl v 8 ulong get JDIO add off i
328end
329ret v
330end
331
332fn jdpiw off ulong v ulong to void
333x = v
334for i ulong 8
335put JDIO add off i uchar and x 255
336x = shr x 8
337end
338end
339
340fn jdpww off ulong v ulong to void
341x = v
342for i ulong 8
343put JDWB add off i uchar and x 255
344x = shr x 8
345end
346end
347
348fn jdplw off ulong v ulong to void
349x = v
350for i ulong 8
351put JDLB add off i uchar and x 255
352x = shr x 8
353end
354end
355
356fn jdbswap x ulong to ulong
357v = ulong 0
358y = x
359for i ulong 8
360v = or shl v 8 and y 255
361y = shr y 8
362end
363ret v
364end
365
366note ---- files ----
367
368fn jdopen r ulong flags int to long
369ret fopen JDS mul r 4096 get JDSL r flags 420
370end
371
372fn jdexists r ulong to bool
373x = faccess JDS mul r 4096 get JDSL r 0
374ret eq x 0
375end
376
377fn jdmkdir r ulong mode int to long
378ret makedir JDS mul r 4096 get JDSL r mode
379end
380
381note whole file of register r into JDF; byte count, -1 open/read error, -2 too big
382fn jdldf r ulong to long
383x = jdopen r 0
384if lt x 0
385ret -1
386end
387fd = int x
388tot = ulong 0
389while true bound 999999
390if ge tot 16777216
391c = fclose fd
392ret -2
393end
394k = read fd JDF tot sub 16777216 tot
395if lt k 0
396c = fclose fd
397ret -1
398end
399if eq k 0
400break
401end
402tot = add tot ulong k
403end
404c = fclose fd
405ret long tot
406end
407
408note JDF[0..n) to the file of register r with open flags (577 truncate, 1089 append, 705 new)
409fn jdwrf r ulong n ulong flags int to long
410x = jdopen r flags
411if lt x 0
412ret x
413end
414fd = int x
415off = ulong 0
416while lt off n bound 999999
417k = write fd JDF off sub n off
418if le k 0
419c = fclose fd
420ret -1
421end
422off = add off ulong k
423end
424c = fsync fd
425c = fclose fd
426ret 0
427end
428
429note words of file r into JDM[base..); word count, or negative
430fn jdldw r ulong base ulong maxw ulong to long
431n = jdldf r
432if lt n 0
433ret n
434end
435nb = ulong n
436if ne and nb 7 0
437ret -3
438end
439nw = shr nb 3
440if gt nw maxw
441ret -2
442end
443for i ulong nw
444put JDM add base i jdgfw shl i 3
445end
446ret long nw
447end
448
449fn jdw2wb b ulong k ulong to void
450for i ulong k
451v = get JDM add b i
452jdpww shl i 3 v
453end
454end
455
456note JDM[base..base+nw) to file r (flags as jdwrf)
457fn jdstw r ulong base ulong nw ulong flags int to long
458x = jdopen r flags
459if lt x 0
460ret x
461end
462fd = int x
463done = ulong 0
464while lt done nw bound 999999
465k = sub nw done
466if gt k 8192
467k = 8192
468end
469jdw2wb add base done k
470w = write fd JDWB 0 shl k 3
471if ne w long shl k 3
472c = fclose fd
473ret -1
474end
475done = add done k
476end
477c = fsync fd
478c = fclose fd
479ret 0
480end
481
482note small file (at most 65535 bytes) of register r into JDWB; bytes or negative
483fn jdldsm r ulong to long
484x = jdopen r 0
485if lt x 0
486ret x
487end
488fd = int x
489k = read fd JDWB 0 65535
490c = fclose fd
491ret k
492end
493
494note file size of register r, -1 if missing
495fn jdfsize r ulong to long
496x = stat JDS mul r 4096 get JDSL r JDST 0 128
497if ne x 0
498ret -1
499end
500v = ulong 0
501i = ulong 8
502while gt i 0 bound 8
503i = sub i 1
504v = or shl v 8 ulong get JDST add 48 i
505end
506ret long v
507end
508
509note mode bits of register r (st_mode), 0 if missing
510fn jdfmode r ulong to ulong
511x = stat JDS mul r 4096 get JDSL r JDST 0 128
512if ne x 0
513ret 0
514end
515v = or ulong get JDST 16 shl ulong get JDST 17 8
516v = or v shl ulong get JDST 18 16
517ret v
518end
519
520note copy file register s to register d (new file, same permission bits)
521fn jdcpf s ulong d ulong to int
522m = jdfmode s
523if ne and m 61440 32768
524ret 1
525end
526n = jdldf s
527if lt n 0
528ret 2
529end
530x = jdopen d 705
531if lt x 0
532ret 3
533end
534fd = int x
535c = fchmod fd int and m 4095
536off = ulong 0
537nb = ulong n
538while lt off nb bound 999999
539k = write fd JDF off sub nb off
540if le k 0
541c = fclose fd
542ret 4
543end
544off = add off ulong k
545end
546c = fsync fd
547c = fclose fd
548ret 0
549end
550
551fn jdu16 off ulong to ulong
552ret or ulong get JDWB off shl ulong get JDWB add off 1 8
553end
554
555note the name of the getdents64 record at pos appended to register r
556fn jddname pos ulong r ulong to void
557k = add pos 19
558while ne get JDWB k 0 bound 256
559jdsc r get JDWB k
560k = add k 1
561end
562end
563
564note one directory record: copy (mode 1, s -> d) or size (mode 0); names in registers 0 and 1
565fn jddent pos ulong s ulong d ulong mode ulong to ulong
566jdscp 0 s
567jdsc 0 47
568jddname pos 0
569m = jdfmode 0
570if ne and m 61440 32768
571ret 0
572end
573if eq mode 0
574z = jdfsize 0
575if gt z 0
576ret ulong z
577end
578ret 0
579end
580jdscp 1 d
581jdsc 1 47
582jddname pos 1
583c = jdcpf 0 1
584if ne c 0
585ret add 10 ulong c
586end
587ret 0
588end
589
590note walk directory register s: mode 1 copies regular files into d (error code back), mode 0 sums sizes
591fn jdwalk s ulong d ulong mode ulong to ulong
592x = jdopen s 0
593if lt x 0
594ret JDNONE
595end
596fd = int x
597acc = ulong 0
598while true bound 100000
599n = getdnts fd JDWB 0 65536
600if le n 0
601break
602end
603pos = ulong 0
604while lt pos ulong n bound 100000
605v = jddent pos s d mode
606if eq mode 0
607acc = add acc v
608else
609if ne v 0
610acc = v
611end
612end
613pos = add pos jdu16 add pos 16
614end
615end
616c = fclose fd
617ret acc
618end
619
620note copy every regular file of directory register s into a new directory register d (mode 0700)
621fn jdcpdir s ulong d ulong to int
622r = jdmkdir d 448
623if ne r 0
624ret 1
625end
626e = jdwalk s d 1
627if ne e 0
628ret 2
629end
630ret 0
631end
632
633note sum of st_size of the regular files of directory register s
634fn jddirb s ulong to ulong
635v = jdwalk s s 0
636if eq v JDNONE
637ret 0
638end
639ret v
640end
641
642note make register r absolute against the current directory (register 31 is scratch)
643fn jdabs r ulong to void
644if eq jdsb r 0 47
645ret
646end
647n = cwd JDWB 0 4096
648if le n 1
649ret
650end
651jdsclr 31
652for i ulong sub ulong n 1
653jdsc 31 get JDWB i
654end
655jdsc 31 47
656jdsr 31 r
657jdscp r 31
658end
659
660note ---- SHA-256 (sha256 unit, omsha) ----
661
662fn jdhput w view ulong 64 to void
663for i ulong 4
664put JDH i jdbswap get w i
665end
666end
667
668note SHA-256 of the file of register r into JDH (big-endian words); size or -1
669fn jdhfile r ulong to long
670c = new uchar 104 0
671b = new uchar 4096 0
672w = new ulong 64 0
673b8 = new ulong 512 0
674omsha c b 0 0 w b8
675x = jdopen r 0
676if lt x 0
677ret -1
678end
679fd = int x
680tot = ulong 0
681while true bound 999999
682k = read fd b 0 4096
683if lt k 0
684y = fclose fd
685ret -1
686end
687if eq k 0
688break
689end
690omsha c b ulong k 1 w b8
691tot = add tot ulong k
692end
693y = fclose fd
694omsha c b 0 2 w b8
695jdhput w
696ret long tot
697end
698
699fn jdhcpf b edit uchar 4096 off ulong k ulong to void
700for j ulong k
701put b j get JDF add off j
702end
703end
704
705note SHA-256 of JDF[off..off+n) into JDH
706fn jdhjdf off ulong n ulong to void
707c = new uchar 104 0
708b = new uchar 4096 0
709w = new ulong 64 0
710b8 = new ulong 512 0
711omsha c b 0 0 w b8
712d = ulong 0
713while lt d n bound 999999
714k = sub n d
715if gt k 4096
716k = 4096
717end
718jdhcpf b add off d k
719omsha c b k 1 w b8
720d = add d k
721end
722omsha c b 0 2 w b8
723jdhput w
724end
725
726note the 64 hex digits of JDH appended to register r
727fn jdshash r ulong to void
728for i ulong 4
729jdshex r get JDH i
730end
731end
732
733note ---- splitmix64 ----
734
735fn jdsmix to ulong
736s = add get JDSM 0 11400714819323198485
737put JDSM 0 s
738z = mul xor s shr s 30 13787848793156543929
739z = mul xor z shr z 27 10723151780598845931
740ret xor z shr z 31
741end
742
743note ---- argument packets for execprog ----
744
745fn jdpk0 to void
746put JDPKN 0 2
747put JDPKN 1 0
748end
749
750fn jdpkb c uchar to void
751n = get JDPKN 0
752if ge n 4096
753trap 3
754end
755put JDPK n c
756put JDPKN 0 add n 1
757end
758
759fn jdpkr r ulong to void
760n = get JDSL r
761jdpkb uchar and n 255
762jdpkb uchar shr n 8
763b = mul r 4096
764for i ulong n
765jdpkb get JDS add b i
766end
767put JDPKN 1 add get JDPKN 1 1
768end
769
770note extra-argument list JDXA / JDXL (0 count, 1 + 2i offset, 2 + 2i length)
771fn jdx0 to void
772put JDXL 0 0
773end
774
775fn jdxadd r ulong to void
776k = get JDXL 0
777if ge k 64
778trap 3
779end
780off = ulong 0
781if gt k 0
782off = add get JDXL sub mul k 2 1 get JDXL mul k 2
783end
784n = get JDSL r
785if gt add off n 16384
786trap 3
787end
788b = mul r 4096
789for i ulong n
790put JDXA add off i get JDS add b i
791end
792put JDXL add mul k 2 1 off
793put JDXL add mul k 2 2 n
794put JDXL 0 add k 1
795end
796
797note list item i into register r
798fn jdxget r ulong i ulong to void
799jdsclr r
800off = get JDXL add mul i 2 1
801n = get JDXL add mul i 2 2
802for j ulong n
803jdsc r get JDXA add off j
804end
805end
806
807fn jdpkfin to void
808c = get JDPKN 1
809put JDPK 0 uchar and c 255
810put JDPK 1 uchar shr c 8
811end
812
813note ---- /proc readings ----
814
815note /proc/PID/stat (or /proc/self/stat for pid 0) fields into JDT: 0 utime 1 stime 2 cutime
816note 3 cstime 4 processor; 0 ok
817fn jdprocst pid ulong to int
818jdsclr 0
819if eq pid 0
820jdsw 0 JWSELF 15
821else
822jdsw 0 JWPROC 6
823jdsnum 0 pid 1
824jdsw 0 JWSTAT 5
825end
826n = jdldsm 0
827if le n 0
828ret 1
829end
830nb = ulong n
831p = ulong 0
832for i ulong nb
833if eq get JDWB i 41
834p = i
835end
836end
837tok = ulong 0
838v = ulong 0
839i = add p 2
840while lt i nb bound 65536
841c = ulong get JDWB i
842if or eq c 32 eq c 10
843jdstok tok v
844tok = add tok 1
845v = 0
846else
847if and ge c 48 le c 57
848v = add mul v 10 sub c 48
849end
850end
851i = add i 1
852end
853ret 0
854end
855
856fn jdstok tok ulong v ulong to void
857if and ge tok 11 le tok 14
858put JDT sub tok 11 v
859end
860if eq tok 36
861put JDT 4 v
862end
863end
864
865note index of JDW[off..off+wn) in JDWB[0..n), or n
866fn jdfindw n ulong off ulong wn ulong to ulong
867if lt n wn
868ret n
869end
870for i ulong add sub n wn 1
871k = ulong 0
872while lt k wn bound 64
873if ne get JDWB add i k get JDW add off k
874break
875end
876k = add k 1
877end
878if eq k wn
879ret i
880end
881end
882ret n
883end
884
885note first decimal number in JDWB at or after p (stops at a newline after digits)
886fn jdnumat p ulong n ulong to ulong
887v = ulong 0
888seen = false
889i = p
890while lt i n bound 65536
891c = ulong get JDWB i
892if and ge c 48 le c 57
893v = add mul v 10 sub c 48
894seen = true
895else
896if seen
897break
898end
899end
900i = add i 1
901end
902ret v
903end
904
905note VmHWM and VmRSS kB of pid into JDT 5, 6
906fn jdprocmem pid ulong to void
907put JDT 5 0
908put JDT 6 0
909jdsclr 0
910jdsw 0 JWPROC 6
911jdsnum 0 pid 1
912jdsw 0 JWSTATUS 7
913n = jdldsm 0
914if le n 0
915ret
916end
917nb = ulong n
918p = jdfindw nb JWHWM 6
919if lt p nb
920put JDT 5 jdnumat p nb
921end
922p = jdfindw nb JWRSS 6
923if lt p nb
924put JDT 6 jdnumat p nb
925end
926end
927
928note first /proc/loadavg value x 100
929fn jdloadav to ulong
930jdsclr 0
931jdsw 0 JWLOADAV 13
932n = jdldsm 0
933if le n 0
934ret 0
935end
936v = ulong 0
937fr = ulong 0
938dig = ulong 0
939dot = false
940for i ulong ulong n
941c = ulong get JDWB i
942if eq c 32
943break
944end
945if eq c 46
946dot = true
947continue
948end
949if and ge c 48 le c 57
950if dot
951if lt dig 2
952fr = add mul fr 10 sub c 48
953dig = add dig 1
954end
955else
956v = add mul v 10 sub c 48
957end
958end
959end
960while lt dig 2 bound 2
961fr = mul fr 10
962dig = add dig 1
963end
964ret add mul v 100 fr
965end
966
967note ---- arm processes ----
968note JDC: 0 pid, 1 write fd, 2 read fd, 3 kept stdin read end, 4 t0, 5 start-to-ready, 6 sum rt,
969note 7 requests sent, 8 alive, 9 violation code, 10 arm id, 11 group, 12 repetition, 13 loadavg,
970note 14 log bytes in JDLB, 15 requests done by this process, 16 revoke-at request, 17 kill-at
971note request, 18 exit status, 19 log enabled, 20 utime, 21 stime, 22 cutime, 23 cstime, 24 cpu,
972note 25 hwm, 26 rss, 27 proc read done.
973note JDA counters: 0 QUERYs, 1 wrong (correctness 0), 2..7 QUERY routes 0..5, 8 other routes,
974note 10 QUERYs after revoke, 11 route 3/4 after, 12 route 5 after, 13 route 3/4 before, 14 wrong
975note QUERYs, 15 violations.
976
977fn jdfdw off ulong to int
978x = ulong 0
979for i ulong 4
980v = ulong get JDPF add off i
981x = or x shl v mul i 8
982end
983ret int x
984end
985
986fn jdspawn to long
987r = pipefds JDPF 0 8 524288
988if ne r 0
989ret -1
990end
991r = pipefds JDPF 8 8 524288
992if ne r 0
993ret -1
994end
995a0 = jdfdw 0
996a1 = jdfdw 4
997b0 = jdfdw 8
998b1 = jdfdw 12
999pid = fork
1000if lt pid 0
1001ret -1
1002end
1003if eq pid 0
1004d = dupfd a0 0 0
1005d = dupfd b1 1 0
1006e = execprog JDPK 0 get JDPKN 0
1007exit 127
1008end
1009c = fclose b1
1010put JDC 0 ulong pid
1011put JDC 1 ulong a1
1012put JDC 2 ulong b0
1013put JDC 3 ulong a0
1014ret pid
1015end
1016
1017fn jdarmname r ulong a ulong to void
1018jdsclr r
1019if eq a 0
1020jdsw r JWECHO 4
1021end
1022if eq a 1
1023jdsw r JWFULL 4
1024end
1025if eq a 2
1026jdsw r JWCACHE 5
1027end
1028if eq a 3
1029jdsw r JWMETH 6
1030end
1031if and ge a 4 le a 6
1032jdsw r JWDELTA 5
1033end
1034if eq a 7
1035jdsw r JWSEL 6
1036end
1037if eq a 8
1038jdsw r JWTAP 3
1039end
1040end
1041
1042note packet: [taskset -c CPU] BASE ARM LIBDIR MANSHA ALLOW TAPFILE SPLIT
1043fn jdarmpk to void
1044jdpk0
1045if not jdsdash 7
1046jdsclr 0
1047jdsw 0 JWTASK 16
1048jdpkr 0
1049jdsclr 0
1050jdsw 0 JWDC 2
1051jdpkr 0
1052jdpkr 7
1053end
1054jdpkr 5
1055jdpkr 8
1056jdpkr 9
1057jdpkr 10
1058jdpkr 11
1059jdpkr 12
1060jdpkr 13
1061jdpkfin
1062end
1063
1064fn jdpstart to int
1065jdarmpk
1066put JDC 13 jdloadav
1067t0 = monons
1068pid = jdspawn
1069if lt pid 0
1070ret 1
1071end
1072put JDC 4 ulong t0
1073put JDC 5 0
1074put JDC 6 0
1075put JDC 7 0
1076put JDC 8 1
1077put JDC 9 0
1078put JDC 15 0
1079put JDC 18 0
1080put JDC 27 0
1081put JDC 28 0
1082for i ulong 5
1083put JDT i 0
1084end
1085put JDT 5 0
1086put JDT 6 0
1087ret 0
1088end
1089
1090note write a frame JDM[off..off+nw) to the arm before deadline dl; 0 ok, 3 timeout, 4 write failure
1091fn jdsend off ulong nw ulong dl long to int
1092fd = int get JDC 1
1093nb = shl nw 3
1094if gt nb 65536
1095ret 4
1096end
1097for i ulong nw
1098jdpiw shl i 3 get JDM add off i
1099end
1100done = ulong 0
1101while lt done nb bound 999999
1102left = sub dl monons
1103if le left 0
1104ret 3
1105end
1106e = waitio fd 4 left
1107if eq e 0
1108ret 3
1109end
1110if or lt e 0 eq and e 4 0
1111ret 4
1112end
1113k = sub nb done
1114if gt k 4096
1115k = 4096
1116end
1117w = write fd JDIO done k
1118if le w 0
1119ret 4
1120end
1121done = add done ulong w
1122end
1123ret 0
1124end
1125
1126note read exactly n bytes into JDIO[off..) before deadline dl; 0 ok, 1 end of file, 3 timeout
1127fn jdrdn fd int off ulong n ulong dl long to int
1128got = ulong 0
1129while lt got n bound 999999
1130left = sub dl monons
1131if le left 0
1132ret 3
1133end
1134e = waitio fd 1 left
1135if lt e 0
1136ret 1
1137end
1138if eq e 0
1139ret 3
1140end
1141k = read fd JDIO add off got sub n got
1142if le k 0
1143ret 1
1144end
1145got = add got ulong k
1146end
1147ret 0
1148end
1149
1150note response into JDRS (0 status, 1 q, 2.. words); 0 ok, 1 short, 2 bad q, 3 timeout
1151fn jdrecv dl long to int
1152fd = int get JDC 2
1153e = jdrdn fd 0 16 dl
1154if ne e 0
1155ret e
1156end
1157put JDRS 0 jdgiw 0
1158q = jdgiw 8
1159put JDRS 1 q
1160if gt q 32
1161ret 2
1162end
1163e = jdrdn fd 16 shl q 3 dl
1164if ne e 0
1165ret e
1166end
1167for i ulong q
1168put JDRS add 2 i jdgiw add 16 shl i 3
1169end
1170ret 0
1171end
1172
1173note read /proc of the live arm once (before END or a kill)
1174fn jdpread to void
1175if ne get JDC 27 0
1176ret
1177end
1178pid = get JDC 0
1179r = jdprocst pid
1180put JDC 20 get JDT 0
1181put JDC 21 get JDT 1
1182put JDC 22 get JDT 2
1183put JDC 23 get JDT 3
1184put JDC 24 get JDT 4
1185jdprocmem pid
1186put JDC 25 get JDT 5
1187put JDC 26 get JDT 6
1188put JDC 27 1
1189end
1190
1191fn jdclosefd to void
1192c = fclose int get JDC 1
1193c = fclose int get JDC 2
1194c = fclose int get JDC 3
1195end
1196
1197note wait status in JDWS to the proc.log exit word
1198fn jdwstat to ulong
1199sig = and ulong get JDWS 0 127
1200if ne sig 0
1201ret add 256 sig
1202end
1203ret ulong get JDWS 1
1204end
1205
1206note reap the arm within 10 s, killing it after that
1207fn jdreap to void
1208pid = int get JDC 0
1209dl = add monons 10000000000
1210while true bound 999999
1211r = waitpid pid JDWS 0 4 1
1212if eq r long pid
1213put JDC 18 jdwstat
1214ret
1215end
1216if lt r 0
1217put JDC 18 1023
1218ret
1219end
1220if gt monons dl
1221k = killpid pid 9
1222r = waitpid pid JDWS 0 4 0
1223put JDC 18 jdwstat
1224ret
1225end
1226s = sleepns 1000000
1227end
1228end
1229
1230note kill the arm (protocol violation or a C11 kill); code 0 = deliberate kill
1231fn jdpkill code ulong to void
1232if eq get JDC 8 0
1233ret
1234end
1235jdpread
1236pid = int get JDC 0
1237k = killpid pid 9
1238r = waitpid pid JDWS 0 4 0
1239if eq code 0
1240put JDC 18 jdwstat
1241else
1242put JDC 18 add 512 code
1243end
1244put JDC 8 0
1245jdclosefd
1246end
1247
1248note send END, require status 0 and q 0, reap; K17: END round trip into JDC 28, and 1024 added to
1249note the exit word when END itself failed (bad status or q, end of file, timeout, write failure;
1250note the low bits then hold the exit status, or 512 + 4 + code when the judge had to kill the arm)
1251fn jdpfin to void
1252if eq get JDC 8 0
1253ret
1254end
1255if eq get JDC 19 1
1256jdpstats
1257end
1258jdpread
1259put JDM JMEND 10
1260put JDM add JMEND 1 0
1261t1 = monons
1262dl = add t1 10000000000
1263e = jdsend JMEND 2 dl
1264if eq e 0
1265e = jdrecv dl
1266end
1267put JDC 28 ulong sub monons t1
1268if ne e 0
1269jdpkill add 4 ulong e
1270put JDC 18 add get JDC 18 1024
1271ret
1272end
1273bad = or ne get JDRS 0 0 ne get JDRS 1 0
1274jdreap
1275if bad
1276put JDC 18 add get JDC 18 1024
1277end
1278put JDC 8 0
1279jdclosefd
1280end
1281
1282note K14: diagnostic STATS, excluded from every latency sum, padded to 32 counter words.
1283fn jdpstats to void
1284for i ulong 34
1285put JDM add 9437000 i 0
1286end
1287put JDM JMEND 9
1288put JDM add JMEND 1 0
1289dl = add monons 10000000000
1290e = jdsend JMEND 2 dl
1291if eq e 0
1292e = jdrecv dl
1293end
1294if eq e 0
1295put JDM 9437000 get JDRS 0
1296put JDM 9437001 get JDRS 1
1297for i ulong get JDRS 1
1298put JDM add 9437002 i get JDRS add i 2
1299end
1300else
1301put JDM 9437000 JDNONE
1302end
1303jdscp 0 4
1304jdsc 0 47
1305jdsc 0 115
1306jdsc 0 116
1307jdsc 0 97
1308jdsc 0 116
1309jdsc 0 115
1310jdsc 0 45
1311jdsnum 0 get JDC 10 1
1312jdsc 0 45
1313jdsnum 0 get JDC 12 1
1314jdsw 0 JWG 2
1315jdsnum 0 get JDC 11 2
1316jdsc 0 46
1317jdsc 0 99
1318jdsc 0 116
1319jdsc 0 114
1320x = jdstw 0 9437000 34 705
1321end
1322
1323note status, r0, r1, route of the response as logged, into JDQ 0..3
1324fn jdlogval op ulong code ulong to void
1325put JDQ 0 get JDRS 0
1326put JDQ 1 0
1327put JDQ 2 0
1328put JDQ 3 0
1329if and eq op 2 ge get JDRS 1 3
1330put JDQ 1 get JDRS 2
1331put JDQ 2 get JDRS 3
1332put JDQ 3 get JDRS 4
1333end
1334if ne code 0
1335put JDQ 1 0
1336put JDQ 2 0
1337put JDQ 3 0
1338end
1339if eq code 1
1340put JDQ 0 JDNONE
1341end
1342if eq code 2
1343put JDQ 0 sub JDNONE 1
1344end
1345end
1346
1347note one 16-word raw record for request j into JDLB, counters into JDA
1348fn jdlogrec j ulong code ulong rt ulong to void
1349off = get JDM add JMOF j
1350op = get JDM add JMRQ off
1351ex = add JMEX shl j 3
1352jdlogval op code
1353co = jdcorr op code get JDQ 0 get JDQ 1 get JDQ 2 ex
1354jdcount j op code co get JDQ 3
1355if eq get JDC 19 0
1356ret
1357end
1358jdlogw j op ex rt co
1359end
1360
1361fn jdlogw j ulong op ulong ex ulong rt ulong co ulong to void
1362b = get JDC 14
1363if gt add b 128 8388608
1364trap 3
1365end
1366jdplw b get JDC 11
1367jdplw add b 8 get JDC 12
1368jdplw add b 16 get JDC 10
1369jdplw add b 24 j
1370jdplw add b 32 op
1371jdplw add b 40 get JDQ 0
1372jdplw add b 48 get JDQ 1
1373jdplw add b 56 get JDQ 2
1374jdplw add b 64 get JDQ 3
1375jdplw add b 72 get JDM ex
1376jdplw add b 80 get JDM add ex 2
1377jdplw add b 88 get JDM add ex 3
1378jdplw add b 96 rt
1379jdplw add b 104 get JDM add ex 6
1380jdplw add b 112 get JDM add ex 5
1381jdplw add b 120 co
1382put JDC 14 add b 128
1383end
1384
1385note correctness word: code 0 answered, 1 violation, 2 not sent
1386fn jdcorr op ulong code ulong st ulong r0 ulong r1 ulong ex ulong to ulong
1387if ne code 0
1388ret 0
1389end
1390if eq get JDC 10 0
1391ret 2
1392end
1393if ne st get JDM ex
1394ret 0
1395end
1396if ne op 2
1397ret 2
1398end
1399if ne st 0
1400ret 1
1401end
1402e0 = get JDM add ex 2
1403if ne r0 e0
1404ret 0
1405end
1406e1 = get JDM add ex 3
1407if ne r1 e1
1408ret 0
1409end
1410ret 1
1411end
1412
1413fn jdcount j ulong op ulong code ulong co ulong ro ulong to void
1414rt = add JMRT shl j 2
1415put JDM rt ro
1416put JDM add rt 1 code
1417put JDM add rt 2 co
1418if eq co 0
1419put JDA 1 add get JDA 1 1
1420end
1421if eq code 1
1422put JDA 15 add get JDA 15 1
1423end
1424if ne op 2
1425ret
1426end
1427put JDM add rt 3 1
1428put JDA 0 add get JDA 0 1
1429if eq co 0
1430put JDA 14 add get JDA 14 1
1431end
1432if ne code 0
1433ret
1434end
1435if le ro 5
1436put JDA add 2 ro add get JDA add 2 ro 1
1437else
1438put JDA 8 add get JDA 8 1
1439end
1440m = or eq ro 3 eq ro 4
1441rv = get JDC 16
1442if and ne rv JDNONE ge j rv
1443put JDA 10 add get JDA 10 1
1444if m
1445put JDA 11 add get JDA 11 1
1446end
1447if eq ro 5
1448put JDA 12 add get JDA 12 1
1449end
1450else
1451if m
1452put JDA 13 add get JDA 13 1
1453end
1454end
1455end
1456
1457fn jdcnt0 to void
1458for i ulong 64
1459put JDA i 0
1460end
1461end
1462
1463note send request j and read its response; logs it
1464fn jdpreq j ulong to void
1465if eq get JDC 8 0
1466jdlogrec j 2 0
1467ret
1468end
1469if eq j get JDC 16
1470jdrevoke
1471end
1472off = get JDM add JMOF j
1473nw = add get JDM add add JMRQ off 1 2
1474t1 = monons
1475dl = add t1 10000000000
1476e = jdsend add JMRQ off nw dl
1477if eq e 0
1478e = jdrecv dl
1479end
1480t2 = monons
1481if eq e 0
1482eq1 = get JDM add add JMEX shl j 3 1
1483if ne get JDRS 1 eq1
1484e = 2
1485end
1486end
1487rt = ulong sub t2 t1
1488if eq get JDC 15 0
1489put JDC 5 ulong sub t2 long get JDC 4
1490end
1491put JDC 15 add get JDC 15 1
1492put JDC 6 add get JDC 6 rt
1493put JDC 7 add get JDC 7 1
1494if ne e 0
1495put JDC 9 ulong e
1496jdlogrec j 1 rt
1497jdpkill ulong e
1498ret
1499end
1500jdlogrec j 0 rt
1501end
1502
1503note C7 mid-session revocation: append the line of register 29 to the ALLOW copy of register 28
1504fn jdrevoke to void
1505if eq get JDSL 28 0
1506ret
1507end
1508x = jdopen 28 1089
1509if lt x 0
1510ret
1511end
1512fd = int x
1513w = write fd JDS 118784 get JDSL 29
1514c = fsync fd
1515c = fclose fd
1516end
1517
1518note the proc.log record (16 words at JMPRC) appended to <dir 4>/proc.log
1519fn jdproclog to int
1520p = JMPRC
1521put JDM p get JDC 10
1522put JDM add p 1 get JDC 11
1523put JDM add p 2 get JDC 12
1524put JDM add p 3 get JDC 5
1525put JDM add p 4 get JDC 20
1526put JDM add p 5 get JDC 21
1527put JDM add p 6 get JDC 22
1528put JDM add p 7 get JDC 23
1529put JDM add p 8 get JDC 25
1530put JDM add p 9 get JDC 26
1531put JDM add p 10 get JDC 18
1532put JDM add p 11 get JDC 7
1533put JDM add p 12 get JDC 6
1534put JDM add p 13 get JDC 24
1535put JDM add p 14 get JDC 13
1536put JDM add p 15 get JDC 28
1537jdspath 0 4 JWPLOG 8
1538x = jdstw 0 p 16 1089
1539if lt x 0
1540ret 1
1541end
1542ret 0
1543end
1544
1545note <dir 4>/arm-A-rep-R-gNN.log from JDLB (a new file; never overwritten)
1546fn jdrawlog to int
1547jdscp 0 4
1548jdsc 0 47
1549jdsw 0 JWARM 4
1550jdsnum 0 get JDC 10 1
1551jdsw 0 JWREP 5
1552jdsnum 0 get JDC 12 1
1553jdsw 0 JWG 2
1554jdsnum 0 get JDC 11 2
1555jdsw 0 JWLOG 4
1556x = jdopen 0 705
1557if lt x 0
1558ret 1
1559end
1560fd = int x
1561n = get JDC 14
1562off = ulong 0
1563while lt off n bound 999999
1564k = write fd JDLB off sub n off
1565if le k 0
1566c = fclose fd
1567ret 2
1568end
1569off = add off ulong k
1570end
1571c = fsync fd
1572c = fclose fd
1573ret 0
1574end
1575
1576note one arm process over requests j0..j1 of the loaded group; arm config in registers 5, 7..13,
1577note JDC 10..12; writes the raw log and proc.log when JDC 19 = 1. 0 ok, nonzero judge failure.
1578fn jdpgroup j0 ulong j1 ulong to int
1579put JDC 14 0
1580r = jdpstart
1581if ne r 0
1582ret 1
1583end
1584j = j0
1585while lt j j1 bound 999999
1586if eq j get JDC 17
1587jdpkill 0
1588end
1589jdpreq j
1590j = add j 1
1591end
1592jdpfin
1593if eq get JDC 19 0
1594ret 0
1595end
1596r = jdrawlog
1597if ne r 0
1598ret 2
1599end
1600r = jdproclog
1601if ne r 0
1602ret 3
1603end
1604ret 0
1605end
1606
1607note ---- split directories ----
1608
1609note index and sessions of the split in register 3; group count or negative
1610fn jdsload to long
1611jdspath 0 3 JWINDEX 5
1612n = jdldw 0 JMIX 4096
1613if lt n 16
1614ret -1
1615end
1616if ne get JDM JMIX 3544386032354079058
1617ret -2
1618end
1619if ne get JDM add JMIX 1 1
1620ret -2
1621end
1622g = get JDM add JMIX 3
1623if or gt g 100 ne ulong n add 16 g
1624ret -3
1625end
1626jdspath 0 3 JWSESS 8
1627s = jdldw 0 JMSE 1044480
1628if lt s 0
1629ret -4
1630end
1631if ne ulong s mul 16 get JDM add JMIX 4
1632ret -5
1633end
1634ret long g
1635end
1636
1637fn jdgpath r ulong d ulong g ulong ext ulong to void
1638jdscp r d
1639jdsc r 47
1640jdsc r 103
1641jdsnum r g 2
1642jdsw r ext 4
1643end
1644
1645note group g of the split in register 3 into JMRQ / JMOF / JMEX; request count or negative
1646fn jdgload g ulong to long
1647jdgpath 0 3 g JWREQ
1648nw = jdldw 0 JMRQ 6291456
1649if lt nw 0
1650ret -1
1651end
1652off = ulong 0
1653j = ulong 0
1654while lt off ulong nw bound 999999
1655if ge j 1048576
1656ret -2
1657end
1658put JDM add JMOF j off
1659off = add off add get JDM add add JMRQ off 1 2
1660j = add j 1
1661end
1662if ne off ulong nw
1663ret -3
1664end
1665if ne j get JDM add add JMIX 16 g
1666ret -4
1667end
1668jdgpath 0 3 g JWEXP
1669ne8 = jdldw 0 JMEX 1048576
1670if ne ulong ne8 shl j 3
1671ret -5
1672end
1673for i ulong j
1674if not jdopok i
1675ret -6
1676end
1677end
1678ret long j
1679end
1680
1681fn jdopok i ulong to bool
1682o = get JDM add JMOF i
1683op = get JDM add JMRQ o
1684eo = get JDM add add JMEX shl i 3 4
1685ret eq op eo
1686end
1687
1688fn jdusage to int
1689jdsclr 0
1690jdsw 0 JWUSAGE 77
1691jdsc 0 10
1692n = write 2 JDS 0 get JDSL 0
1693ret 2
1694end
1695
1696fn jderr code ulong to int
1697jdsclr 0
1698jdsw 0 JWERR 12
1699jdsnum 0 code 1
1700jdsc 0 10
1701n = write 2 JDS 0 get JDSL 0
1702ret 3
1703end
1704
1705note ---- run ----
1706
1707note arm-order seed: a 64-hex FINAL seed gives bytes 16..23 little endian; else a decimal value
1708fn jdseed r ulong to ulong
1709if eq get JDSL r 64
1710v = ulong 0
1711for k ulong 8
1712b = jdshexb r add 16 k
1713if gt b 255
1714ret JDNONE
1715end
1716v = or v shl b mul k 8
1717end
1718ret v
1719end
1720ret jdsval r
1721end
1722
1723note arm digits of register r into JDM JMSC..; count, 0 when invalid
1724fn jdarms r ulong to ulong
1725n = get JDSL r
1726if or eq n 0 gt n 8
1727ret 0
1728end
1729for i ulong n
1730c = jdsb r i
1731if or lt c 48 gt c 55
1732ret 0
1733end
1734a = sub c 48
1735for k ulong i
1736if eq get JDM add JMSC k a
1737ret 0
1738end
1739end
1740put JDM add JMSC i a
1741end
1742ret n
1743end
1744
1745note fresh copy of the base arm list at JMSC + 16, Fisher-Yates with splitmix64 (i = n-1 .. 1)
1746fn jdperm n ulong to void
1747b = add JMSC 16
1748for i ulong n
1749put JDM add b i get JDM add JMSC i
1750end
1751i = sub n 1
1752while gt i 0 bound 8
1753j = rem jdsmix add i 1
1754t = get JDM add b i
1755put JDM add b i get JDM add b j
1756put JDM add b j t
1757i = sub i 1
1758end
1759end
1760
1761fn jdlibdir r ulong rep ulong lib ulong to void
1762jdscp r 4
1763jdsc r 47
1764jdsw r JWLIB 4
1765jdsnum r rep 1
1766jdsc r 45
1767jdsnum r lib 1
1768end
1769
1770note process registers 8..13 and JDC 10, 12 for arm a in repetition rep of a run
1771fn jdarmcfg a ulong rep ulong to void
1772jdarmname 8 a
1773jdsdsh 9
1774jdsdsh 10
1775jdsdsh 11
1776jdsdsh 12
1777jdsdsh 13
1778if or eq a 3 or eq a 4 eq a 7
1779jdlibdir 9 rep 1
1780jdscp 10 15
1781jdscp 11 6
1782end
1783if eq a 5
1784jdscp 11 6
1785end
1786if eq a 6
1787jdlibdir 9 rep 2
1788jdscp 10 17
1789jdscp 11 6
1790end
1791put JDC 10 a
1792put JDC 12 rep
1793end
1794
1795fn jdaddm i ulong d ulong to void
1796put JDM i add get JDM i d
1797end
1798
1799fn jdneed n ulong lib ulong to bool
1800for i ulong n
1801a = get JDM add JMSC i
1802if and eq lib 1 or eq a 3 or eq a 4 eq a 7
1803ret true
1804end
1805if and eq lib 2 eq a 6
1806ret true
1807end
1808end
1809ret false
1810end
1811
1812fn jdsummary n ulong to void
1813for i ulong n
1814a = get JDM add JMSC i
1815jdsclr 0
1816jdsw 0 JWAEQ 4
1817jdsnum 0 a 1
1818jdsw 0 JWWRONG 7
1819jdsnum 0 get JDM add add JMSC 32 a 1
1820jdsw 0 JWVIOL 12
1821jdsnum 0 get JDM add add JMSC 48 a 1
1822jdsout 0
1823end
1824end
1825
1826note all arms of the base list over one loaded group g, repetition rep
1827fn jdrungrp na ulong g ulong rep ulong nreq ulong to int
1828jdperm na
1829for k ulong na
1830a = get JDM add add JMSC 16 k
1831jdarmcfg a rep
1832put JDC 11 g
1833w0 = get JDA 1
1834v0 = get JDA 15
1835e = jdpgroup 0 nreq
1836if ne e 0
1837ret add 40 e
1838end
1839dw = sub get JDA 1 w0
1840jdaddm add add JMSC 32 a dw
1841dv = sub get JDA 15 v0
1842jdaddm add add JMSC 48 a dv
1843end
1844ret 0
1845end
1846
1847note judge run SPLIT OUT REPS SEED ARMS BASE ALLOW LIB MAN LIBP MANP CPU
1848fn jdrun to int
1849if ne argcnt 14
1850ret jdusage
1851end
1852b = jdsarg 3 2
1853b = jdsarg 4 3
1854b = jdsarg 0 4
1855b = jdsarg 1 5
1856b = jdsarg 2 6
1857b = jdsarg 5 7
1858b = jdsarg 6 8
1859b = jdsarg 14 9
1860b = jdsarg 15 10
1861b = jdsarg 16 11
1862b = jdsarg 17 12
1863b = jdsarg 7 13
1864reps = jdsval 0
1865seed = jdseed 1
1866na = jdarms 2
1867if or or eq reps JDNONE or eq reps 0 gt reps 99 or eq seed JDNONE eq na 0
1868ret jdusage
1869end
1870n1 = jdneed na 1
1871n2 = jdneed na 2
1872if and n1 or jdsdash 14 jdsdash 15
1873ret jdusage
1874end
1875if and n2 or jdsdash 16 jdsdash 17
1876ret jdusage
1877end
1878g = jdsload
1879if lt g 0
1880ret jderr 10
1881end
1882r = jdmkdir 4 493
1883jdspath 0 4 JWPLOG 8
1884if jdexists 0
1885ret jderr 11
1886end
1887for i ulong 32
1888put JDM add add JMSC 32 i 0
1889end
1890put JDSM 0 seed
1891e = jdrunloop reps na n1 n2 ulong g
1892if ne e 0
1893ret jderr e
1894end
1895jdsummary na
1896ret 0
1897end
1898
1899
1900fn jdrunloop reps ulong na ulong n1 bool n2 bool g ulong to ulong
1901put JDC 16 JDNONE
1902put JDC 17 JDNONE
1903put JDC 19 1
1904jdcnt0
1905for rep ulong reps
1906if n1
1907jdlibdir 26 rep 1
1908c = jdcpdir 14 26
1909if ne c 0
1910ret 12
1911end
1912end
1913if n2
1914jdlibdir 26 rep 2
1915c = jdcpdir 16 26
1916if ne c 0
1917ret 13
1918end
1919end
1920for gi ulong g
1921nreq = jdgload gi
1922if lt nreq 0
1923ret 20
1924end
1925e = jdrungrp na gi rep ulong nreq
1926if ne e 0
1927ret ulong e
1928end
1929end
1930end
1931ret 0
1932end
1933
1934note ---- tap ----
1935
1936note judge tap SPLIT BASE TAPFILE SPLITARG CPU: one B process over every group in order
1937fn jdtap to int
1938if ne argcnt 7
1939ret jdusage
1940end
1941b = jdsarg 3 2
1942b = jdsarg 5 3
1943b = jdsarg 12 4
1944b = jdsarg 13 5
1945b = jdsarg 7 6
1946g = jdsload
1947if lt g 0
1948ret jderr 10
1949end
1950if jdexists 12
1951ret jderr 14
1952end
1953jdarmname 8 8
1954jdsdsh 9
1955jdsdsh 10
1956jdsdsh 11
1957put JDC 10 1
1958put JDC 11 0
1959put JDC 12 0
1960put JDC 16 JDNONE
1961put JDC 17 JDNONE
1962put JDC 19 0
1963jdcnt0
1964r = jdpstart
1965if ne r 0
1966ret jderr 15
1967end
1968for gi ulong ulong g
1969nreq = jdgload gi
1970if lt nreq 0
1971jdpkill 0
1972ret jderr 16
1973end
1974for j ulong ulong nreq
1975jdpreq j
1976end
1977end
1978jdpfin
1979z = jdhfile 12
1980jdsclr 0
1981jdsw 0 JWTSHA 11
1982jdshash 0
1983jdsw 0 JWTBYT 11
1984if gt z 0
1985jdsnum 0 ulong z 1
1986else
1987jdsc 0 48
1988end
1989jdsw 0 JWQRY 9
1990jdsnum 0 get JDA 0 1
1991jdsw 0 JWWRONG 7
1992jdsnum 0 get JDA 1 1
1993jdsw 0 JWVIOL 12
1994jdsnum 0 get JDA 15 1
1995jdsout 0
1996if or ne get JDA 1 0 ne get JDC 18 0
1997ret 4
1998end
1999if le z 0
2000ret 4
2001end
2002ret 0
2003end
2004
2005note ---- calib ----
2006note pairs (key, ns) at JMSC, sort area at JMSC + 2097152, logs at JMSC + 3145728; change class
2007note of QUERY j at JMRT + j, per-session change counts at JMRT + 524288 + ordinal.
2008
2009const JDPAIR ulong 10485760
2010const JDSORT ulong 12582912
2011const JDLOGW ulong 13631488
2012
2013fn jdccls c ulong to ulong
2014if eq c 0
2015ret 0
2016end
2017if eq c 1
2018ret 1
2019end
2020if le c 64
2021ret 2
2022end
2023ret 3
2024end
2025
2026fn jdcchg nreq ulong to void
2027cb = add JMRT 524288
2028for j ulong nreq
2029o = get JDM add JMOF j
2030op = get JDM add JMRQ o
2031ex = add JMEX shl j 3
2032s = get JDM add ex 5
2033ok = eq get JDM ex 0
2034si = add cb s
2035put JDM add JMRT j 9
2036if and eq op 1 ok
2037put JDM si 0
2038end
2039if and ok and ge op 3 le op 6
2040jdaddm si 1
2041end
2042if and ok eq op 8
2043jdaddm si 1
2044end
2045if and ok eq op 7
2046m = get JDM add add JMRQ o 2
2047jdaddm si m
2048end
2049if eq op 2
2050put JDM add JMRT j jdccls get JDM si
2051put JDM si 0
2052end
2053end
2054end
2055
2056fn jdpair k ulong v ulong np ulong to ulong
2057if ge np 1048576
2058ret np
2059end
2060put JDM add JDPAIR shl np 1 k
2061put JDM add add JDPAIR shl np 1 1 v
2062ret add np 1
2063end
2064
2065note pairs of one arm log (already at JDLOGW) for a loaded group of nreq requests
2066fn jdcpairs a ulong nreq ulong np ulong to ulong
2067n = np
2068path = ulong 2
2069if eq a 1
2070path = 0
2071end
2072if eq a 3
2073path = 1
2074end
2075for j ulong nreq
2076n = jdcpone a path j n
2077end
2078ret n
2079end
2080
2081fn jdsfld s ulong w ulong to ulong
2082ret get JDM add add JMSE shl s 4 w
2083end
2084
2085fn jdcpone a ulong path ulong j ulong np ulong to ulong
2086rec = add JDLOGW shl j 4
2087fam = jdsfld get JDM add rec 14 2
2088ncl = jdsfld get JDM add rec 14 5
2089if or or lt fam 1 gt fam 2 gt ncl 2
2090ret np
2091end
2092k = add mul sub fam 1 3 ncl
2093n = jdcpq path j k np
2094if jdcbind get JDM add rec 4 rec j a
2095kb = add k 100
2096if eq a 1
2097kb = add k 200
2098end
2099n = jdpair kb get JDM add rec 12 n
2100end
2101ret n
2102end
2103
2104note QUERY pair of record j; k = (family - 1) * 3 + nclass
2105fn jdcpq path ulong j ulong k ulong np ulong to ulong
2106rec = add JDLOGW shl j 4
2107if or ne get JDM add rec 4 2 ne get JDM add rec 15 1
2108ret np
2109end
2110f0 = div k 3
2111ncl = rem k 3
2112c = jdcell f0 path ncl get JDM add JMRT j
2113ret jdpair c get JDM add rec 12 np
2114end
2115
2116fn jdcell f0 ulong path ulong ncl ulong cc ulong to ulong
2117x = mul add mul f0 4 path 12
2118ret add add x mul ncl 4 cc
2119end
2120
2121fn jdcbind op ulong rec ulong j ulong a ulong to bool
2122if or ne op 1 eq j 0
2123ret false
2124end
2125if eq a 4
2126ret false
2127end
2128ret and eq get JDM add rec 5 0 eq get JDM add rec 9 0
2129end
2130
2131note values of key k gathered into JDSORT and sorted; count
2132fn jdgather k ulong np ulong to ulong
2133n = ulong 0
2134for i ulong np
2135if eq get JDM add JDPAIR shl i 1 k
2136put JDM add JDSORT n get JDM add add JDPAIR shl i 1 1
2137n = add n 1
2138end
2139end
2140jdhsort JDSORT n
2141ret n
2142end
2143
2144fn jdsift b ulong st ulong n ulong to void
2145root = st
2146while true bound 64
2147ch = add mul root 2 1
2148if ge ch n
2149break
2150end
2151sw = root
2152if gt get JDM add b ch get JDM add b sw
2153sw = ch
2154end
2155c2 = add ch 1
2156if lt c2 n
2157if gt get JDM add b c2 get JDM add b sw
2158sw = c2
2159end
2160end
2161if eq sw root
2162break
2163end
2164t = get JDM add b root
2165put JDM add b root get JDM add b sw
2166put JDM add b sw t
2167root = sw
2168end
2169end
2170
2171fn jdhsort b ulong n ulong to void
2172if lt n 2
2173ret
2174end
2175st = add div sub n 2 2 1
2176while gt st 0 bound 999999
2177st = sub st 1
2178jdsift b st n
2179end
2180e = sub n 1
2181while gt e 0 bound 999999
2182t = get JDM b
2183put JDM b get JDM add b e
2184put JDM add b e t
2185jdsift b 0 e
2186e = sub e 1
2187end
2188end
2189
2190note nearest-rank percentile p of the n sorted values at JDSORT: index ceil(p n / 100) - 1
2191fn jdpct n ulong p ulong to ulong
2192i = div add mul p n 99 100
2193if eq i 0
2194i = 1
2195end
2196ret get JDM add JDSORT sub i 1
2197end
2198
2199fn jdfloor1 a ulong b ulong to ulong
2200if le a b
2201ret 1
2202end
2203d = sub a b
2204if lt d 1
2205ret 1
2206end
2207ret d
2208end
2209
2210note the calibration words into JMEX[0..200)
2211fn jdcalout np ulong eqv ulong to void
2212for i ulong 200
2213put JDM add JMEX i 0
2214end
2215put JDM JMEX 3544386010811150674
2216put JDM add JMEX 1 1
2217put JDM add JMEX 2 eqv
2218for c ulong 96
2219if eq rem div c 12 4 3
2220continue
2221end
2222n = jdgather c np
2223if gt n 0
2224put JDM add add JMEX 8 shl c 1 jdpct n 50
2225put JDM add add JMEX 9 shl c 1 jdpct n 90
2226end
2227end
2228for f0 ulong 2
2229for ncl ulong 3
2230jdcalbind f0 ncl np
2231end
2232end
2233end
2234
2235fn jdcalbind f0 ulong ncl ulong np ulong to void
2236k = add mul f0 3 ncl
2237nf = jdgather add k 200 np
2238if eq nf 0
2239ret
2240end
2241fp = jdpct nf 50
2242nm = jdgather add k 100 np
2243if eq nm 0
2244ret
2245end
2246c = add mul add mul f0 4 3 12 mul ncl 4
2247put JDM add add JMEX 8 shl c 1 jdfloor1 jdpct nm 50 fp
2248put JDM add add JMEX 9 shl c 1 jdfloor1 jdpct nm 90 fp
2249end
2250
2251note judge calib CALIBDIR RUNDIR REPS OUTFILE
2252fn jdcalib to int
2253if ne argcnt 6
2254ret jdusage
2255end
2256b = jdsarg 3 2
2257b = jdsarg 4 3
2258b = jdsarg 0 4
2259b = jdsarg 21 5
2260reps = jdsval 0
2261if or eq reps JDNONE eq reps 0
2262ret jdusage
2263end
2264g = jdsload
2265if lt g 0
2266ret jderr 10
2267end
2268ns = get JDM add JMIX 4
2269if eq ns 0
2270ret jderr 17
2271end
2272eqv = div mul get JDM add JMIX 6 1000 ns
2273np = jdcalloop reps ulong g
2274if eq np JDNONE
2275ret jderr 18
2276end
2277jdcalout np eqv
2278x = jdstw 21 JMEX 200 705
2279if lt x 0
2280ret jderr 19
2281end
2282z = jdhfile 21
2283jdsclr 0
2284jdsw 0 JWCSHA 11
2285jdshash 0
2286jdsout 0
2287ret 0
2288end
2289
2290fn jdcalloop reps ulong g ulong to ulong
2291np = ulong 0
2292for rep ulong reps
2293for gi ulong g
2294x = jdgload gi
2295if lt x 0
2296ret JDNONE
2297end
2298nreq = ulong x
2299jdcchg nreq
2300np = jdcal3 rep gi nreq np
2301if eq np JDNONE
2302ret JDNONE
2303end
2304end
2305end
2306ret np
2307end
2308
2309fn jdcal3 rep ulong gi ulong nreq ulong np ulong to ulong
2310n = np
2311for t ulong 3
2312a = add t 2
2313if eq t 0
2314a = 1
2315end
2316if eq t 2
2317a = 4
2318end
2319x = jdcload a rep gi
2320if ne x mul nreq 16
2321ret JDNONE
2322end
2323n = jdcpairs a nreq n
2324end
2325ret n
2326end
2327
2328note raw log arm a, repetition rep, group g of the run dir in register 4 into JDLOGW; words
2329fn jdcload a ulong rep ulong g ulong to ulong
2330jdscp 0 4
2331jdsc 0 47
2332jdsw 0 JWARM 4
2333jdsnum 0 a 1
2334jdsw 0 JWREP 5
2335jdsnum 0 rep 1
2336jdsw 0 JWG 2
2337jdsnum 0 g 2
2338jdsw 0 JWLOG 4
2339x = jdldw 0 JDLOGW 3145728
2340if lt x 0
2341ret JDNONE
2342end
2343ret ulong x
2344end
2345
2346note ---- build ----
2347
2348note index of JDW[off..off+wn) in JDF[0..n), or n
2349fn jdfindf n ulong off ulong wn ulong to ulong
2350if lt n wn
2351ret n
2352end
2353for i ulong add sub n wn 1
2354k = ulong 0
2355while lt k wn bound 64
2356if ne get JDF add i k get JDW add off k
2357break
2358end
2359k = add k 1
2360end
2361if eq k wn
2362ret i
2363end
2364end
2365ret n
2366end
2367
2368note register r written to the file of register p (flags), with a final newline
2369fn jdwreg r ulong p ulong flags int to long
2370x = jdopen p flags
2371if lt x 0
2372ret x
2373end
2374fd = int x
2375jdsc r 10
2376w = write fd JDS mul r 4096 get JDSL r
2377put JDSL r sub get JDSL r 1
2378c = fsync fd
2379c = fclose fd
2380ret 0
2381end
2382
2383note drive child: chdir into register 19, stdout onto the pipe, exec the packet
2384fn jddchild wr int to void
2385c = chdir JDS 77824 get JDSL 19
2386if ne c 0
2387exit 126
2388end
2389d = dupfd wr 1 0
2390e = execprog JDPK 0 get JDPKN 0
2391exit 127
2392end
2393
2394note read the child's stdout into JDF until end of file; bytes
2395fn jddread rd int dl long to ulong
2396n = ulong 0
2397while true bound 999999
2398left = sub dl monons
2399if le left 0
2400break
2401end
2402e = waitio rd 1 left
2403if le e 0
2404break
2405end
2406if ge n 16777216
2407break
2408end
2409k = read rd JDF n sub 16777216 n
2410if le k 0
2411break
2412end
2413n = add n ulong k
2414end
2415ret n
2416end
2417
2418note run drive build: registers 18 drive, 19 checkout (cwd of drive), 20 omc, 11 ALLOW, 21 CALIB,
2419note 9 OUTLIB, 30 acquisition dir, JDXA extra arguments. acq.log record, acq-L-R.mansha; the
2420note manifest hex is left in register 10 (empty if none). Returns the drive exit word.
2421fn jdbuild lib ulong rep ulong to ulong
2422jdbpk
2423r = jdprocst 0
2424put JDC 40 get JDT 2
2425put JDC 41 get JDT 3
2426ex = jdbrun
2427r = jdprocst 0
2428el = get JDC 42
2429n = get JDC 43
2430cu = sub get JDT 2 get JDC 40
2431cs = sub get JDT 3 get JDC 41
2432jdacqrec lib rep el cu cs ex
2433jdmansha lib rep n
2434w = write 1 JDF 0 n
2435jdsclr 0
2436jdsw 0 JWDEX 11
2437jdsnum 0 ex 1
2438jdsw 0 JWELNS 12
2439jdsnum 0 el 1
2440jdsout 0
2441ret ex
2442end
2443
2444fn jdbpk to void
2445jdpk0
2446jdpkr 18
2447jdsclr 0
2448jdsw 0 JWBUILD 5
2449jdpkr 0
2450jdpkr 20
2451jdpkr 11
2452jdpkr 21
2453jdpkr 9
2454for i ulong get JDXL 0
2455jdxget 0 i
2456jdpkr 0
2457end
2458jdpkfin
2459end
2460
2461note fork and exec the drive packet; exit word; JDC 42 elapsed ns, JDC 43 output bytes in JDF
2462fn jdbrun to ulong
2463put JDC 42 0
2464put JDC 43 0
2465pr = pipefds JDPF 0 8 524288
2466if ne pr 0
2467ret 1001
2468end
2469rd = jdfdw 0
2470wr = jdfdw 4
2471t0 = monons
2472pid = fork
2473if lt pid 0
2474ret 1002
2475end
2476if eq pid 0
2477jddchild wr
2478end
2479c = fclose wr
2480dl = add t0 3600000000000
2481n = jddread rd dl
2482if gt monons dl
2483k = killpid int pid 9
2484end
2485w = waitpid int pid JDWS 0 4 0
2486t1 = monons
2487c = fclose rd
2488put JDC 42 ulong sub t1 t0
2489put JDC 43 n
2490ret jdwstat
2491end
2492
2493fn jdacqrec lib ulong rep ulong el ulong cu ulong cs ulong ex ulong to void
2494p = JMPRC
2495put JDM p lib
2496put JDM add p 1 rep
2497put JDM add p 2 el
2498put JDM add p 3 cu
2499put JDM add p 4 cs
2500put JDM add p 5 ex
2501put JDM add p 6 jddirb 9
2502put JDM add p 7 0
2503jdspath 0 30 JWACQ 7
2504x = jdstw 0 p 8 1089
2505end
2506
2507note manifest_sha256=<64 hex> of the drive output into register 10 and acq-L-R.mansha
2508fn jdmansha lib ulong rep ulong n ulong to void
2509jdsclr 10
2510p = jdfindf n JWMSHA 16
2511if ge add p 80 add n 1
2512ret
2513end
2514b = add p 16
2515for i ulong 64
2516jdsc 10 get JDF add b i
2517end
2518jdscp 0 30
2519jdsc 0 47
2520jdsw 0 JWACQ2 4
2521jdsnum 0 lib 1
2522jdsc 0 45
2523jdsnum 0 rep 1
2524jdsw 0 JWMANS 7
2525x = jdwreg 10 0 577
2526end
2527
2528fn jdxpre r ulong to bool
2529if jdspre r JWUNIT 5
2530ret true
2531end
2532if jdspre r JWMUT 7
2533ret true
2534end
2535ret jdspre r JWCRASH 11
2536end
2537
2538note judge build DRIVE OMEGADIR OMC ALLOW CALIB OUTLIB ACQDIR LIBID REP [DRIVE ARGS...]
2539fn jdbuildc to int
2540if lt argcnt 11
2541ret jdusage
2542end
2543b = jdsarg 18 2
2544b = jdsarg 19 3
2545b = jdsarg 20 4
2546b = jdsarg 11 5
2547b = jdsarg 21 6
2548b = jdsarg 9 7
2549b = jdsarg 30 8
2550b = jdsarg 0 9
2551lib = jdsval 0
2552b = jdsarg 0 10
2553rep = jdsval 0
2554if or eq lib JDNONE eq rep JDNONE
2555ret jdusage
2556end
2557jdabs 18
2558jdabs 20
2559if not jdsdash 11
2560jdabs 11
2561end
2562if not jdsdash 21
2563jdabs 21
2564end
2565jdabs 9
2566jdx0
2567i = ulong 11
2568while lt i ulong argcnt bound 64
2569b = jdsarg 0 i
2570if not jdxpre 0
2571jdabs 0
2572end
2573jdxadd 0
2574i = add i 1
2575end
2576ex = jdbuild lib rep
2577if gt ex 255
2578ret 255
2579end
2580ret int ex
2581end
2582
2583note ---- recheck (contract 7.4) ----
2584
2585note judge recheck MANSHAFILE PINHEX: 0 REBUILD MATCH, 3 BLOCKED
2586fn jdrecheck to int
2587if ne argcnt 4
2588ret jdusage
2589end
2590b = jdsarg 1 2
2591b = jdsarg 2 3
2592n = jdldsm 1
2593jdsclr 0
2594if gt n 0
2595for i ulong ulong n
2596c = get JDWB i
2597if eq c 10
2598break
2599end
2600jdsc 0 c
2601end
2602end
2603if and eq get JDSL 2 64 jdseq 0 2
2604jdsclr 1
2605jdsw 1 JWMATCH 14
2606jdsr 1 0
2607jdsout 1
2608ret 0
2609end
2610jdsclr 1
2611jdsw 1 JWBLK 16
2612jdsr 1 0
2613jdsw 1 JWPIN 8
2614jdsr 1 2
2615jdsout 1
2616ret 3
2617end
2618
2619note ---- entry ----
2620
2621fn jdmain to int
2622if lt argcnt 2
2623ret jdusage
2624end
2625b = jdsarg 0 1
2626k = jdspack 0
2627if eq k 7239026
2628ret jdrun
2629end
2630if eq k 7364980
2631ret jdtap
2632end
2633if eq k 422675505507
2634ret jdcalib
2635end
2636if eq k 431315580258
2637ret jdbuildc
2638end
2639if eq k 30227109702231410
2640ret jdrecheck
2641end
2642if eq k 8317145149216812899
2643ret jdcontrols
2644end
2645ret jdusage
2646end
2647
2648note ---- controls (contract 9; K7 outcome words, K10 mutants) ----
2649
2650note JDK: 0 synthetic request count, 1 request word cursor, 2 synthetic session ordinal,
2651note 3 cold flag, 4 outcome undetected count, 5 not-run count, 6 experience byte size,
2652note 7 last drive exit, 8 synthetic wl, 9 synthetic shape mode, 10 stored generation.
2653global JDK ulong 64
2654global JDCP ulong 64
2655
2656note Control paths: <control dir>/cID-SUFFIX, no collisions/overwrites.
2657fn jdctpath r ulong id ulong suffix ulong to void
2658jdscp r 22
2659jdsc r 47
2660jdsc r 99
2661jdsnum r id 1
2662jdsc r 45
2663jdsnum r suffix 1
2664end
2665
2666note controls.log: id, subcase, detected (1), undetected (0), reported (2) or not-run (3),
2667note served-tampered flag, four reserved zero words. Each observation also printed to stdout.
2668fn jdctl id ulong subc ulong outcome ulong served ulong to void
2669for i ulong 8
2670put JDM add JMPRC i 0
2671end
2672put JDM JMPRC id
2673put JDM add JMPRC 1 subc
2674put JDM add JMPRC 2 outcome
2675put JDM add JMPRC 3 served
2676jdspath 0 22 JWCLOG 12
2677x = jdstw 0 JMPRC 8 1089
2678if or eq outcome 0 ne served 0
2679jdaddk 4 1
2680end
2681if eq outcome 3
2682jdaddk 5 1
2683end
2684jdsclr 0
2685jdsc 0 67
2686jdsnum 0 id 1
2687jdsc 0 47
2688jdsnum 0 subc 1
2689jdsc 0 61
2690jdsnum 0 outcome 1
2691jdsw 0 JWWRONG 7
2692jdsnum 0 get JDA 1 1
2693jdsw 0 JWVIOL 12
2694jdsnum 0 get JDA 15 1
2695jdsc 0 32
2696jdsc 0 53
2697jdsc 0 61
2698jdsnum 0 get JDA 7 1
2699jdsc 0 32
2700jdsc 0 77
2701jdsc 0 61
2702jdsnum 0 add get JDA 5 get JDA 6 1
2703jdsout 0
2704end
2705
2706fn jdaddk i ulong v ulong to void
2707put JDK i add get JDK i v
2708end
2709
2710fn jdctlbool id ulong subc ulong yes bool served ulong to void
2711o = ulong 0
2712if yes
2713o = 1
2714end
2715jdctl id subc o served
2716end
2717
2718note load the first valid AGG BEGIN of DEV as the ancestor of the control programs.
2719fn jdctancestor to bool
2720jdscp 3 25
2721g = jdsload
2722if lt g 0
2723ret false
2724end
2725for gi ulong ulong g
2726nr = jdgload gi
2727if lt nr 0
2728ret false
2729end
2730if jdctfind ulong nr
2731ret true
2732end
2733end
2734ret false
2735end
2736
2737fn jdctfind nr ulong to bool
2738for j ulong nr
2739o = add JMRQ get JDM add JMOF j
2740if ne get JDM o 1
2741continue
2742end
2743if ne get JDM add o 3 1
2744continue
2745end
2746for k ulong 64
2747put JDCP k get JDM add add o 2 k
2748end
2749ret true
2750end
2751ret false
2752end
2753
2754note emit RFRQ as the next synthetic request, compare with the independent reference.
2755fn jdctemit to void
2756j = get JDK 0
2757o = get JDK 1
2758nw = add get RFRQ 1 2
2759put JDM add JMOF j o
2760for k ulong nw
2761put JDM add JMRQ add o k get RFRQ k
2762end
2763st = rfreq
2764ex = add JMEX shl j 3
2765for k ulong 8
2766put JDM add ex k 0
2767end
2768put JDM ex get RFRS 0
2769put JDM add ex 1 get RFRS 1
2770put JDM add ex 2 get RFRS 2
2771put JDM add ex 3 get RFRS 3
2772put JDM add ex 4 get RFRQ 0
2773put JDM add ex 5 get JDK 2
2774if eq get RFRQ 0 2
2775put JDM add ex 6 get JDK 3
2776put JDK 3 0
2777end
2778if or eq get RFRQ 0 1 eq get RFRQ 0 8
2779put JDK 3 1
2780end
2781put JDK 0 add j 1
2782put JDK 1 add o nw
2783end
2784
2785note derive a valid AGG program from DEV, with the same family/fold and its first constant,
2786note keeping just ADD at the selected width. These deliberate shapes isolate the mutants.
2787fn jdctprog wl ulong c ulong to void
2788for k ulong 64
2789put RFRQ add 2 k 0
2790end
2791put RFRQ 2 3544411312749556050
2792put RFRQ 3 1
2793put RFRQ 4 wl
2794put RFRQ 5 1
2795put RFRQ 6 1
2796put RFRQ 7 1
2797put RFRQ 8 c
2798end
2799
2800note build a synthetic workload: mode 0, train (8 QUERYs); 1, drift + boundary refusals;
2801note 2, MUL/SHL boundary KATs. It is independently scored by rfreq, not candidate responses.
2802fn jdctsyn wl ulong mode ulong to void
2803rfreset
2804put JDK 0 0
2805put JDK 1 0
2806put JDK 2 0
2807put JDK 3 1
2808put JDK 8 wl
2809put JDK 9 mode
2810jdctprog wl and get JDCP 6 7
2811put RFRQ 0 1
2812put RFRQ 1 69
2813put RFRQ 66 4
2814put RFRQ 67 0
2815put RFRQ 68 1
2816put RFRQ 69 sub shl ulong 1 wl 1
2817put RFRQ 70 2
2818if eq wl 16
2819put RFRQ 68 256
2820end
2821jdctemit
2822for i ulong 8
2823put RFRQ 0 2
2824put RFRQ 1 0
2825jdctemit
2826end
2827if eq mode 1
2828jdctprog wl 9
2829put RFRQ 0 8
2830put RFRQ 1 64
2831jdctemit
2832put RFRQ 0 2
2833put RFRQ 1 0
2834jdctemit
2835put RFRQ 0 3
2836put RFRQ 1 2
2837put RFRQ 2 0
2838put RFRQ 3 shl ulong 1 wl
2839jdctemit
2840put RFRQ 0 2
2841put RFRQ 1 0
2842jdctemit
2843end
2844if eq mode 2
2845jdctbound wl 3
2846jdctbound wl 7
2847end
2848end
2849
2850fn jdctbound wl ulong op ulong to void
2851jdctprog wl 1
2852put RFRQ 7 op
2853put RFRQ 8 sub wl 1
2854if eq op 3
2855put RFRQ 8 sub shl ulong 1 wl 1
2856end
2857put RFRQ 0 8
2858put RFRQ 1 64
2859jdctemit
2860put RFRQ 0 2
2861put RFRQ 1 0
2862jdctemit
2863put RFRQ 0 3
2864put RFRQ 1 2
2865put RFRQ 2 0
2866put RFRQ 3 shl ulong 1 wl
2867jdctemit
2868put RFRQ 0 2
2869put RFRQ 1 0
2870jdctemit
2871end
2872
2873note authorize the current digest JDH in ALLOW register 11 (copies of ALLOW are always private).
2874fn jdctauth to bool
2875jdsclr 0
2876jdshash 0
2877jdsw 0 JWAUTH 12
2878jdsw 0 JWCTRL 4
2879x = jdwreg 0 11 1089
2880ret eq x 0
2881end
2882
2883note tap the current synthetic workload to fresh experience register ep, then authorize it.
2884fn jdcttap ep ulong to bool
2885jdarmname 8 8
2886jdsdsh 9
2887jdsdsh 10
2888jdsdsh 11
2889jdscp 12 ep
2890jdsclr 13
2891jdsc 13 49
2892put JDC 10 1
2893put JDC 11 0
2894put JDC 12 0
2895put JDC 16 JDNONE
2896put JDC 17 JDNONE
2897put JDC 19 0
2898jdcnt0
2899e = jdpgroup 0 get JDK 0
2900if or ne e 0 ne get JDA 1 0
2901ret false
2902end
2903if ne get JDC 18 0
2904ret false
2905end
2906z = jdhfile ep
2907if le z 0
2908ret false
2909end
2910jdscp 11 6
2911ret jdctauth
2912end
2913
2914note build a library from experience ep, optional mutant kind (0 none, 1 c1, 2 c1b, 3 c1c),
2915note optional unit mutant kind (0 none, 1 nog3, 2 c4). Destination register 9.
2916fn jdctbuild ep ulong mut ulong unit ulong rep ulong to ulong
2917jdx0
2918if ne mut 0
2919jdsclr 0
2920if eq mut 1
2921jdsw 0 JWMC1 9
2922end
2923if eq mut 2
2924jdsw 0 JWMC1B 10
2925end
2926if eq mut 3
2927jdsw 0 JWMC1C 10
2928end
2929jdxadd 0
2930end
2931if ne unit 0
2932jdsclr 0
2933if eq unit 1
2934jdsw 0 JWUCHK 11
2935jdsr 0 23
2936end
2937if eq unit 2
2938jdsw 0 JWUDEL 11
2939jdsr 0 24
2940end
2941jdxadd 0
2942end
2943jdxadd ep
2944jdscp 11 6
2945jdsdsh 21
2946ex = jdbuild 9 rep
2947put JDK 7 ex
2948ret ex
2949end
2950
2951note run a synthetic workload against the current library (9/10), arm a; no raw measurement log.
2952fn jdctserve a ulong to bool
2953jdarmname 8 a
2954jdscp 11 6
2955jdsdsh 12
2956jdsdsh 13
2957put JDC 10 a
2958put JDC 11 0
2959put JDC 12 0
2960put JDC 16 JDNONE
2961put JDC 17 JDNONE
2962put JDC 19 0
2963jdcnt0
2964e = jdpgroup 0 get JDK 0
2965ret and eq e 0 eq get JDA 15 0
2966end
2967
2968note G3 refusal means every successful QUERY was route 5 with correct values, no protocol failure.
2969fn jdctrefused to bool
2970if eq get JDA 0 0
2971ret false
2972end
2973if ne get JDA 1 0
2974ret false
2975end
2976if ne get JDA 15 0
2977ret false
2978end
2979ret eq get JDA 7 get JDA 0
2980end
2981
2982note mutant library build + independently scored synthetic workload (id 1/2/3/6).
2983fn jdctmut id ulong subc ulong mut ulong unit ulong ep ulong to void
2984jdctpath 9 id subc
2985ex = jdctbuild ep mut unit add mul id 100 subc
2986if or ne ex 0 ne get JDSL 10 64
2987jdctl id subc 3 0
2988ret
2989end
2990wl = ulong 16
2991jdctsyn wl 1
2992ok = jdctserve 4
2993if not ok
2994jdctl id subc 0 0
2995ret
2996end
2997if or eq unit 1 eq unit 2
2998jdctlbool id subc gt get JDA 14 0 0
2999else
3000yes = jdctrefused
3001if eq id 1
3002yes = or yes gt get JDA 14 0
3003end
3004jdctlbool id subc yes 0
3005end
3006end
3007
3008note C2/C3 tampered experience helpers. ep -> private copy at register 2; re-authorize its new hash.
3009fn jdctexcopy ep ulong id ulong subc ulong to bool
3010jdctpath 2 id add 100 subc
3011c = jdcpf ep 2
3012if ne c 0
3013ret false
3014end
3015ret true
3016end
3017
3018note tamper variant 0 magic byte, 1 program digest, 2 sample output, 3 permute diagnostic costs.
3019note Valid admitted records are 1024 bytes, sample slots at words 16..47, costs at word 7.
3020fn jdctexmut ep ulong id ulong subc ulong kind ulong to void
3021if not jdctexcopy ep id subc
3022jdctl id subc 3 0
3023ret
3024end
3025n = jdldf 2
3026if lt n 1024
3027jdctl id subc 3 0
3028ret
3029end
3030if eq kind 0
3031put JDF 0 xor get JDF 0 1
3032end
3033if eq kind 1
3034put JDF 416 xor get JDF 416 1
3035end
3036if eq kind 2
3037x = jdgfw 136
3038y = jdgfw 152
3039jdpfw 136 y
3040jdpfw 152 x
3041end
3042if eq kind 3
3043jdctcost ulong n
3044end
3045x = jdwrf 2 ulong n 577
3046z = jdhfile 2
3047jdscp 11 6
3048if not jdctauth
3049jdctl id subc 3 0
3050ret
3051end
3052jdctpath 9 id subc
3053ex = jdctbuild 2 0 0 add mul id 100 subc
3054if eq kind 3
3055if ne ex 0
3056jdctl id subc 0 0
3057ret
3058end
3059jdctsame id subc
3060else
3061jdctlbool id subc eq ex 10 0
3062end
3063end
3064
3065fn jdctcost n ulong to void
3066nr = div n 1024
3067if lt nr 2
3068ret
3069end
3070first = jdgfw 56
3071for i ulong sub nr 1
3072next = jdgfw add mul add i 1 1024 56
3073jdpfw add mul i 1024 56 next
3074end
3075jdpfw add mul sub nr 1 1024 56 first
3076end
3077
3078note K13 C3 equality: code/ELF byte-identical, manifest count/entries identical; lineage differs.
3079fn jdctsame id ulong subc ulong to void
3080ok = jdctcmpdir 14 9
3081jdctlbool id subc ok 0
3082end
3083
3084fn jdctcmpfile to bool
3085x = jdhfile 0
3086for i ulong 4
3087put JDT i get JDH i
3088end
3089y = jdhfile 1
3090if or ne x y lt x 0
3091ret false
3092end
3093for i ulong 4
3094if ne get JDT i get JDH i
3095ret false
3096end
3097end
3098ret true
3099end
3100
3101fn jdctcmpdir a ulong b ulong to bool
3102jdspath 0 a JWCUR 7
3103x = jdldf 0
3104if ne x 40
3105ret false
3106end
3107ga = jdgfw 0
3108jdspath 0 b JWCUR 7
3109x = jdldf 0
3110if ne x 40
3111ret false
3112end
3113gb = jdgfw 0
3114for e ulong 2
3115ext = JWOM
3116if eq e 1
3117ext = JWELF
3118end
3119jdgenpath 0 a ga ext
3120jdgenpath 1 b gb ext
3121if not jdctcmpfile
3122ret false
3123end
3124end
3125jdgenpath 0 a ga JWMAN
3126x = jdldw 0 add JMSC 1024 256
3127if ne x 256
3128ret false
3129end
3130jdgenpath 0 b gb JWMAN
3131x = jdldf 0
3132if ne x 2048
3133ret false
3134end
3135if ne get JDM add JMSC 1028 jdgfw 32
3136ret false
3137end
3138for i ulong 128
3139pos = add i 56
3140if ne get JDM add add JMSC 1024 pos jdgfw mul pos 8
3141ret false
3142end
3143end
3144ret true
3145end
3146
3147fn jdgenpath r ulong d ulong g ulong ext ulong to void
3148jdspath r d JWGEN 4
3149jdsnum r g 1
3150n = ulong 4
3151if eq ext JWOM
3152n = 3
3153end
3154jdsw r ext n
3155end
3156
3157note mutate CURRENT's named file in library 9; 0 ELF byte, 1 manifest byte, 2 coherent ELF,
3158note 3 compiler digest, 4 profile version, 5 truncated manifest, 6 truncated CURRENT.
3159fn jdctart kind ulong to bool
3160jdspath 0 9 JWCUR 7
3161n = jdldf 0
3162if ne n 40
3163ret false
3164end
3165g = jdgfw 0
3166put JDK 10 g
3167if eq kind 6
3168x = truncate JDS 0 get JDSL 0 17
3169ret eq x 0
3170end
3171if or eq kind 0 eq kind 2
3172jdgenpath 0 9 g JWELF
3173n = jdldf 0
3174if le n 256
3175ret false
3176end
3177p = sub ulong n 1
3178put JDF p xor get JDF p 1
3179x = jdwrf 0 ulong n 577
3180if eq kind 0
3181ret eq x 0
3182end
3183z = jdhfile 0
3184for i ulong 4
3185put JDK add 16 i get JDH i
3186end
3187end
3188jdgenpath 0 9 g JWMAN
3189n = jdldf 0
3190if ne n 2048
3191ret false
3192end
3193if eq kind 5
3194x = truncate JDS 0 get JDSL 0 777
3195ret eq x 0
3196end
3197if eq kind 1
3198put JDF 101 xor get JDF 101 1
3199end
3200if eq kind 2
3201for i ulong 4
3202jdpfw mul add 10 i 8 get JDK add 16 i
3203end
3204end
3205if eq kind 3
3206put JDF 112 xor get JDF 112 1
3207end
3208if eq kind 4
3209jdpfw 144 2
3210end
3211if ne kind 1
3212jdctfnv
3213end
3214x = jdwrf 0 2048 577
3215z = jdhfile 0
3216jdspath 0 9 JWCUR 7
3217jdpfw 0 g
3218for i ulong 4
3219jdpfw mul add i 1 8 jdbswap get JDH i
3220end
3221x = jdwrf 0 40 577
3222note K7 C9 must pass the mutated manifest as MANSHA so the compiler/profile check itself is tested.
3223if or eq kind 3 eq kind 4
3224jdsclr 10
3225jdshash 10
3226end
3227ret eq x 0
3228end
3229
3230fn jdctfnv to void
3231h = ulong 14695981039346656037
3232for i ulong 2040
3233h = mul xor h ulong get JDF i 1099511628211
3234end
3235jdpfw 2040 h
3236end
3237
3238note artifact load-refusal controls use the private honest library 14/15.
3239fn jdctartifact id ulong subc ulong kind ulong to void
3240jdctpath 9 id subc
3241x = jdcpdir 14 9
3242if ne x 0
3243jdctl id subc 3 0
3244ret
3245end
3246jdscp 10 15
3247if not jdctart kind
3248jdctl id subc 3 0
3249ret
3250end
3251jdctsyn 16 1
3252ok = jdctserve 4
3253served = ulong 0
3254if gt add get JDA 5 get JDA 6 0
3255served = 1
3256end
3257jdctlbool id subc and ok jdctrefused served
3258end
3259
3260note create a private ALLOW and append a REVOKED line for the control experience register 27.
3261fn jdctrevprep subc ulong to bool
3262jdctpath 28 9 add 100 subc
3263x = jdcpf 6 28
3264if ne x 0
3265ret false
3266end
3267z = jdhfile 27
3268if lt z 0
3269ret false
3270end
3271jdsclr 29
3272jdshash 29
3273jdsw 29 JWREVK 9
3274jdsw 29 JWCTRL 4
3275jdsc 29 10
3276ret true
3277end
3278
3279fn jdctrevoke subc ulong to void
3280if not jdctrevprep subc
3281jdctl 9 subc 3 0
3282ret
3283end
3284jdctsyn 16 1
3285jdarmname 8 4
3286jdscp 9 14
3287jdscp 10 15
3288jdscp 11 28
3289jdsdsh 12
3290jdsdsh 13
3291put JDC 10 4
3292put JDC 11 0
3293put JDC 12 0
3294put JDC 16 JDNONE
3295if eq subc 0
3296jdrevoke
3297else
3298put JDC 16 2
3299end
3300put JDC 17 JDNONE
3301put JDC 19 0
3302jdcnt0
3303e = jdpgroup 0 get JDK 0
3304served = ulong 0
3305ok = false
3306if eq subc 0
3307if gt add get JDA 5 get JDA 6 0
3308served = 1
3309end
3310ok = jdctrefused
3311else
3312if gt get JDA 11 0
3313served = 1
3314end
3315ok = jdctrevmid
3316end
3317ok = and ok eq e 0
3318ok = and ok eq get JDA 1 0
3319jdctlbool 9 subc ok served
3320put JDC 16 JDNONE
3321jdsclr 28
3322jdsclr 29
3323end
3324
3325fn jdctrevmid to bool
3326if eq get JDA 13 0
3327ret false
3328end
3329if eq get JDA 10 0
3330ret false
3331end
3332ret eq get JDA 10 get JDA 12
3333end
3334
3335note C8 steps: seed the directory with an honest complete generation, then invoke crashafter:K;
3336note read CURRENT and check its manifest/ELF SHA-256, pin it, serve and score with the reference.
3337fn jdctcrash step ulong to void
3338jdctpath 9 10 step
3339x = jdcpdir 14 9
3340if ne x 0
3341jdctl 10 step 3 0
3342ret
3343end
3344jdx0
3345jdsclr 0
3346jdsw 0 JWCRASH 11
3347jdsnum 0 step 1
3348jdxadd 0
3349jdxadd 27
3350jdscp 11 6
3351jdsdsh 21
3352ex = jdbuild 9 add 1000 step
3353if ne ex 97
3354jdctl 10 step 0 0
3355ret
3356end
3357if not jdctcurrent
3358jdctl 10 step 0 0
3359ret
3360end
3361jdctsyn 16 1
3362ok = jdctserve 4
3363ok = and ok eq get JDA 1 0
3364m = add get JDA 5 get JDA 6
3365ok = and ok gt m 0
3366jdctlbool 10 step ok 0
3367end
3368
3369note validate complete CURRENT files independently; use its manifest digest as MANSHA (register 10).
3370fn jdctcurrent to bool
3371jdspath 0 9 JWCUR 7
3372n = jdldf 0
3373if ne n 40
3374ret false
3375end
3376g = jdgfw 0
3377for i ulong 4
3378put JDK add 16 i jdbswap jdgfw mul add i 1 8
3379end
3380jdgenpath 0 9 g JWMAN
3381n = jdhfile 0
3382if ne n 2048
3383ret false
3384end
3385for i ulong 4
3386if ne get JDH i get JDK add 16 i
3387ret false
3388end
3389end
3390jdsclr 10
3391jdshash 10
3392n = jdldf 0
3393if ne n 2048
3394ret false
3395end
3396for i ulong 4
3397put JDK add 16 i jdgfw mul add 10 i 8
3398end
3399jdgenpath 0 9 g JWELF
3400n = jdhfile 0
3401if le n 0
3402ret false
3403end
3404for i ulong 4
3405if ne get JDH i get JDK add 16 i
3406ret false
3407end
3408end
3409jdgenpath 0 9 g JWOM
3410ret gt jdfsize 0 0
3411end
3412
3413note C11: identity before/after a real SIGKILL mid-session, fresh process byte-identical responses.
3414fn jdctrestart to void
3415jdctsyn 16 1
3416jdscp 9 14
3417jdscp 10 15
3418ok = jdctserve 4
3419if or not ok ne get JDA 1 0
3420jdctl 13 0 0 0
3421ret
3422end
3423for i ulong 4
3424put JDK add 24 i get JDM add add JMRT 4 i
3425end
3426if not jdctcurrent
3427jdctl 13 0 0 0
3428ret
3429end
3430jdctsyn 16 1
3431jdarmname 8 4
3432jdscp 11 6
3433jdsdsh 12
3434jdsdsh 13
3435put JDC 17 3
3436put JDC 16 JDNONE
3437put JDC 19 0
3438jdcnt0
3439e = jdpgroup 0 get JDK 0
3440killed = eq get JDC 18 265
3441put JDC 17 JDNONE
3442jdscp 9 14
3443if not jdctcurrent
3444jdctl 13 0 0 0
3445ret
3446end
3447jdctsyn 16 1
3448ok = jdctserve 4
3449same = jdseq 10 15
3450jdctlbool 13 0 and killed and same and ok eq get JDA 1 0 0
3451end
3452
3453note C5 is scored both at widths 8 and 16, full and delta (with/without a library).
3454fn jdctkat wl ulong a ulong subc ulong to void
3455jdctsyn wl 2
3456if eq a 1
3457jdsdsh 9
3458jdsdsh 10
3459else
3460jdscp 9 14
3461jdscp 10 15
3462end
3463ok = jdctserve a
3464jdctlbool 7 subc and ok eq get JDA 1 0 0
3465end
3466
3467note controls DEV BASE DRIVE OMEGADIR OMC ALLOW NOG3 C4 OUT CPU
3468note Builds its own honest control experiences and libraries; no FINAL data or vault access.
3469fn jdcontrols to int
3470if ne argcnt 12
3471ret jdusage
3472end
3473b = jdsarg 25 2
3474b = jdsarg 5 3
3475b = jdsarg 18 4
3476b = jdsarg 19 5
3477b = jdsarg 20 6
3478b = jdsarg 1 7
3479b = jdsarg 23 8
3480b = jdsarg 24 9
3481b = jdsarg 22 10
3482b = jdsarg 7 11
3483jdabs 18
3484jdabs 20
3485jdabs 23
3486jdabs 24
3487r = jdmkdir 22 448
3488jdabs 22
3489jdscp 30 22
3490jdctpath 6 0 0
3491c = jdcpf 1 6
3492if ne c 0
3493ret jderr 70
3494end
3495jdctpath 26 0 8
3496jdctpath 27 0 16
3497if not jdctancestor
3498ret jderr 71
3499end
3500put JDK 4 0
3501put JDK 5 0
3502jdctsyn 8 0
3503if not jdcttap 26
3504ret jderr 72
3505end
3506jdctsyn 16 0
3507if not jdcttap 27
3508ret jderr 73
3509end
3510note Honest rebuild for C3 costs and all artifact/lifecycle controls.
3511jdctpath 9 0 1
3512ex = jdctbuild 27 0 0 1
3513if ne ex 0
3514ret jderr 74
3515end
3516jdscp 14 9
3517jdscp 15 10
3518jdctmut 1 0 1 0 26
3519jdctmut 1 1 1 1 26
3520jdctmut 2 0 2 0 27
3521jdctmut 2 1 2 1 27
3522jdctmut 3 0 3 0 27
3523jdctexmut 27 4 0 0
3524jdctexmut 27 4 1 1
3525jdctexmut 27 5 0 2
3526jdctexmut 27 5 1 3
3527jdctmut 6 0 0 2 27
3528for w ulong 2
3529wl = add mul w 8 8
3530jdctkat wl 1 mul w 3
3531jdctkat wl 4 add mul w 3 1
3532jdctsyn wl 2
3533jdsdsh 9
3534jdsdsh 10
3535ok = jdctserve 4
3536jdctlbool 7 add mul w 3 2 and ok eq get JDA 1 0 0
3537end
3538for k ulong 3
3539jdctartifact 8 k k
3540end
3541jdctrevoke 0
3542jdctrevoke 1
3543for k ulong 9
3544jdctcrash add k 1
3545end
3546jdctartifact 11 0 3
3547jdctartifact 11 1 4
3548jdctartifact 12 0 5
3549jdctartifact 12 1 6
3550jdctrestart
3551note C12 is an ablation report, not a guard detection; run independently via judge run with arms 56.
3552jdctl 14 0 2 0
3553if gt get JDK 4 0
3554ret 4
3555end
3556if gt get JDK 5 0
3557ret 3
3558end
3559ret 0
3560end