interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / tools / omegallm / wpatch / wpcheck.om

2176 lines · 37637 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note wpcheck: the Omega test driver for wpatch (replaces check.py). CPU only. Built by wpbuild as
3note wpcheck-all.om = om2, the vendored SHA-256 layout and functions, this file.
4note Usage: wpcheck small BUILD WORK ORACLE own-model fixtures made here with BUILD/ollm
5note wpcheck real BUILD WORK ORACLE CK the read-only round40 checkpoint CK
6note wpcheck sum FILE print the Omega SHA-256 of FILE (used by wpbuild)
7note BUILD holds wpatch and ollm. WORK must not exist; it is created 0700 and holds every fixture.
8note ORACLE is wporacle.py, run as /usr/bin/python3 ORACLE REQUEST. It only computes hashlib
9note SHA-256 and IEEE f32 cast digests of files named in REQUEST; every comparison, exit code, fixture,
10note refusal and the PASS/FAIL verdict is decided here. Fixture rehashes (FNV, manifest and binding
11note digests) use the vendored Omega SHA-256, not the oracle.
12note Output is plain text: RUN argv, the child's stdout as `| ` lines (its stderr passes through),
13note EXIT got want elapsed_ns, then PASS or FAIL lines. The last line is
14note `WPCHECK PASS checks=N commands=M` (exit 0) or `WPCHECK FAIL ...` (exit 1); 2 is usage.
15
16global sb uchar 131072
17global sl ulong 256
18global pb uchar 4096
19global pn ulong 1
20global av uchar 8192
21global ap ulong 2
22global stb uchar 4
23global ob uchar 4194304
24global obn ulong 1
25global oo uchar 65536
26global ol ulong 1024
27global oln ulong 1
28global rq uchar 65536
29global rqn ulong 2
30global dig uchar 32
31global dg uchar 32
32global cnt ulong 4
33global tt ulong 1536
34global tn ulong 2
35global rix ulong 64
36global rbt ulong 64
37global rcn ulong 1
38global hh ulong 8
39global mf ulong 16
40global ca uchar 65536
41global cb uchar 65536
42const SWP ulong 0
43const SOLLM ulong 1
44const SWORK ulong 2
45const SORC ulong 3
46const SBASE ulong 4
47const SEDIT ulong 5
48const SPF ulong 6
49const SRF ulong 7
50const STRAIN ulong 8
51const SP0 ulong 9
52const SREQ ulong 12
53const SMEX ulong 13
54const SOUT ulong 14
55const SREV ulong 15
56const SBIND ulong 16
57const SRT ulong 17
58const SBADB ulong 18
59const SOD ulong 19
60const SX0 ulong 20
61const SX1 ulong 21
62const SX2 ulong 22
63const SX3 ulong 23
64const SX4 ulong 24
65const SX5 ulong 25
66const SSNAP ulong 30
67const SBUILD ulong 31
68const SRQ ulong 32
69const SMODE ulong 33
70const ALL ulong 18446744073709551615
71const DLT f64 0.001
72const QTR f64 0.25
73const BIGM f64 1000001.0
74const OVER ulong 16777217
75const BASEOFF ulong 8162304
76text PY "/usr/bin/python3"
77text SUMT "/usr/bin/sha256sum"
78text BSHA "7c7b5b5260f2d9453b6076b64e7f23e88341d96498584f2dfaa229c31ad2e346"
79text HEXD "0123456789abcdef"
80text CK02 "OLLMCK02"
81text WP01 "OLLMWP01"
82text WB01 "OLLMWB01"
83text PARS "{\"delta\":0.001,\"name\":\"Ω patch\"}\n"
84text RATS "Own-model fixture. Preserve exact rollback.\n"
85text PARR "{\"kind\":\"w2\",\"layer\":3,\"entries\":10,\"delta\":0.001}\n"
86text RATR "Read-only round40 baseline. Checked patch integration fixture, not a quality claim.\n"
87text SHOWA "{\"patch_sha256\":\""
88text SHOWZ "\"params\":\"{\\\"delta\\\":0.001,\\\"name\\\":\\\"Ω patch\\\"}\\u000a\",\"rationale\":\"Own-model fixture. Preserve exact rollback.\\u000a\"}\n"
89text TRAINW "abc abcd abcde"
90text INITA "256 8 16 2 32 2 2 1 10 3000 1"
91text MUTN "wrong-base-sha geometry shape oob nan inf magnitude unsorted duplicate old-bits old-moment entries-hash tensor-count tensor-base-sha tensor-out-sha output-sha output-f32-sha "
92text CINSP "inspect"
93text CDIFF "diff"
94text CSHOW "show"
95text CVAL "validate"
96text CAPP "apply"
97text CVER "verify"
98text CREV "revert"
99text CBIND "bind"
100text CCB "checkbind"
101text CINIT "init"
102text CTRAIN "train"
103text WTE "wte"
104text SLICEA "0 0 1 0 2"
105text OOBA "0 0 99999 0 1"
106text MSMALL "small"
107text MREAL "real"
108text MSUM "sum"
109text FTRAIN "train.bin"
110text FBASE "base.ck"
111text FSNAP "base-snapshot.ck"
112text FEDIT "edited.ck"
113text FPF "params.txt"
114text FRF "rationale.txt"
115text FPAT "patches-"
116text FPATS "patches"
117text FEXP "expected-"
118text FMEX "manifest-expected-"
119text FAPP "applied-"
120text FREV "reverted-"
121text FBND "binding-"
122text FRT "runtime-"
123text FBADB "wrong-f32-binding-"
124text FCK ".ck"
125text FWP ".wp"
126text FREQ ".req"
127text FORQ "oracle-"
128text FMUTE "oracle-mutant-edited.ck"
129text FMUTD "oracle-mutant-patches"
130text FMUTO "oracle-mutant.ck"
131text FMUTR "oracle-mutant-requested.ck"
132text FOVP "oversized-params"
133text FOVR "oversized-rationale"
134text FUTF "invalid-utf8.wp"
135text FFLIP "flipped"
136text FBAPP "bad-apply.ck"
137text FBREV "bad-revert.ck"
138text FBBND "bad-bind"
139text FTRUNC "truncated.wp"
140text FWRM "wrong-m.ck"
141text FEXO "exotic.ck"
142text FEXE "exotic-edited.ck"
143text FEXD "exotic-patches"
144text FR40E "round40-edited.ck"
145text FR40X "round40-expected.ck"
146text FR40A "round40-applied.ck"
147text FR40R "round40-reverted.ck"
148text SLWP "/wpatch"
149text SLOLLM "/ollm"
150text QSHA "sha "
151text QF32 "f32 "
152text QNE "f32ne "
153text SURV "f32_surviving="
154text CHGD " changed="
155text RMSK "rms="
156text NONF3 "nonfinite=3"
157text WTEL "wte "
158text PASST "PASS "
159text FAILT "FAIL "
160text RUNT "RUN"
161text BART "| "
162text EXITT "EXIT got="
163text WANTT " want="
164text ELAPT " elapsed_ns="
165text HEADT "WPCHECK "
166text WPSHT " wpatch_sha256="
167text WPPT "WPCHECK PASS checks="
168text WPFT "WPCHECK FAIL checks="
169text CMDT " commands="
170text USAGE "usage: wpcheck small BUILD WORK ORACLE | wpcheck real BUILD WORK ORACLE CK | wpcheck sum FILE\n"
171text SP " "
172text NL "\n"
173text LIO ": I/O failure"
174text LCAP "driver capacity"
175text LCHILD "could not start a child process"
176text LEXIT "exit"
177text LORL "oracle answered every request"
178text LMAG "oracle CK02 magic"
179text LCKL "oracle checkpoint length"
180text LFNV "oracle checkpoint FNV"
181text LGEOP "oracle checkpoint geometry P"
182text LWMAG "oracle manifest magic"
183text LNAME "oracle canonical manifest name"
184text LMLEN "oracle manifest length"
185text LPOL "oracle policy"
186text LEID "oracle edit identity"
187text LMETA "oracle metadata lengths"
188text LPROV "oracle UTF8 provenance"
189text LORD "oracle strict order"
190text LBND "oracle indices in bounds"
191text LHDR "oracle preserved base header"
192text LMGEO "oracle manifest geometry"
193text LMP "oracle manifest P"
194text LBSHA "oracle base SHA"
195text LEBIT "oracle entry bits"
196text LEFIN "oracle entry changed finite"
197text LEMAG "oracle entry magnitude"
198text LEMOM "oracle saved moments"
199text LOSHA "oracle expected output SHA"
200text LOF32 "oracle expected f32 SHA"
201text LTALL "oracle all tensors present"
202text LTGEO "oracle tensor record geometry"
203text LTCNT "oracle tensor changed count"
204text LTBS "oracle tensor base SHA"
205text LTOS "oracle tensor output SHA"
206text LAGREE "manifest oracle agrees with independent request"
207text LSHOW "show UTF8 provenance"
208text LAPPX "apply exact oracle bytes"
209text LAPPR "apply equals independent requested bytes"
210text LSURV "verify f32 survival count"
211text LREVB "revert byte-identical base"
212text LBFMT "oracle binding format"
213text LBCK "oracle binding CK and f32"
214text LBRT "oracle binding runtime and patch"
215text LBSELF "oracle binding self digest"
216text LOUTP "OUT exists preserved"
217text LSLICE "inspect exact slice bits"
218text LBASEW "BASE never written"
219text LMUTP "mutant patch policy"
220text LMUTS "mutant apply equals its own independent request"
221text LMUTR "independent oracle rejects rehashed finite-value mutant accepted by verify"
222text LOVER "oversized metadata creates no output"
223text LREF ": refusal creates no output"
224text LEXO "f32 cast boundary vectors"
225text LRMS "scaled RMS survives maximum finite f64, counts nonfinite separately"
226text LFBASE "final base identity"
227text LRPIN "real base pinned SHA"
228text LROFF "Wolfram layer3 w2 offset"
229text LRTEN "real ten entry identity"
230text LRAPP "real apply equals independently requested bytes"
231text LRREV "real byte-identical revert SHA"
232text LRBASE "real base unchanged"
233text LROUT "real output SHA matches independent expected bytes"
234text LRMOUT "real manifest output SHA matches independent expected bytes"
235text LRF32 "real f32 SHA matches independent expected bytes"
236text LRMF32 "real manifest f32 SHA matches independent expected bytes"
237
238note ---- output and verdicts ----------------------------------------------------------------------
239fn say s view uchar * to void
240r = write 1 s 0 len s
241end
242fn saynum v ulong to void
243x = v
244n = ulong 0
245while ge x 10
246put dig n uchar add 48 rem x 10
247x = div x 10
248n = add n 1
249end
250put dig n uchar add 48 x
251for i ulong add n 1
252r = write 1 dig sub n i 1
253end
254end
255fn saypb to void
256r = write 1 pb 0 get pn 0
257end
258fn tally to void
259saynum get cnt 0
260say CMDT
261saynum get cnt 1
262say NL
263end
264note FAIL with label pb + m (pb may be empty), then the summary; exit 1.
265fn failpm m view uchar * to void
266say FAILT
267saypb
268say m
269say NL
270say WPFT
271tally
272exit 1
273end
274fn pclear to void
275put pn 0 0
276end
277fn fail m view uchar * to void
278pclear
279failpm m
280end
281fn need c bool m view uchar * to void
282if not c
283fail m
284end
285put cnt 0 add get cnt 0 1
286say PASST
287say m
288say NL
289end
290note need with label pb + m
291fn needpm c bool m view uchar * to void
292if not c
293failpm m
294end
295put cnt 0 add get cnt 0 1
296say PASST
297saypb
298say m
299say NL
300end
301
302note ---- path builder, slots, argument packets ---------------------------------------------------
303fn pbyte b uchar to void
304n = get pn 0
305if ge n 4095
306fail LCAP
307end
308put pb n b
309put pn 0 add n 1
310end
311fn ptext s view uchar * to void
312for i ulong len s
313pbyte get s i
314end
315end
316fn pnum v ulong to void
317x = v
318n = ulong 0
319while ge x 10
320put dig n uchar add 48 rem x 10
321x = div x 10
322n = add n 1
323end
324put dig n uchar add 48 x
325for i ulong add n 1
326pbyte get dig sub n i
327end
328end
329fn phex v ulong to void
330for i ulong 16
331pbyte get HEXD and shr v mul sub 15 i 4 15
332end
333end
334note append word k (0-based, space separated) of s
335fn pword s view uchar * k ulong to void
336w = ulong 0
337for i ulong len s
338c = get s i
339if eq c 32
340w = add w 1
341else
342if eq w k
343pbyte c
344end
345end
346end
347end
348note Slot k is 512 bytes of sb at k * 512, its length in sl.
349fn pslot k ulong to void
350o = mul k 512
351for i ulong get sl k
352pbyte get sb add o i
353end
354end
355fn keepat k ulong to void
356n = get pn 0
357if gt n 512
358fail LCAP
359end
360o = mul k 512
361for i ulong n
362put sb add o i get pb i
363end
364put sl k n
365end
366fn under k ulong base ulong s view uchar * to void
367pclear
368pslot base
369ptext s
370keepat k
371end
372note slot k = WORK/s
373fn wname k ulong s view uchar * to void
374pclear
375pslot SWORK
376pbyte 47
377ptext s
378keepat k
379end
380note slot k = WORK/a N
381fn wnamep k ulong a view uchar * v ulong to void
382pclear
383pslot SWORK
384pbyte 47
385ptext a
386pnum v
387keepat k
388end
389note slot k = WORK/a N b
390fn wnamen k ulong a view uchar * v ulong b view uchar * to void
391pclear
392pslot SWORK
393pbyte 47
394ptext a
395pnum v
396ptext b
397keepat k
398end
399fn slotis k ulong s view uchar * to bool
400if ne get sl k len s
401ret false
402end
403o = mul k 512
404for i ulong len s
405if ne get sb add o i get s i
406ret false
407end
408end
409ret true
410end
411fn argslot i ulong k ulong to void
412r = argread i pb 0 512
413if le r 0
414say USAGE
415exit 2
416end
417put pn 0 ulong r
418keepat k
419end
420fn aclear to void
421put ap 0 2
422put ap 1 0
423end
424fn apb to void
425p = get ap 0
426n = get pn 0
427if or gt add add p n 2 len av ge get ap 1 64
428fail LCAP
429end
430put av p uchar and n 255
431put av add p 1 uchar shr n 8
432for i ulong n
433put av add add p 2 i get pb i
434end
435put ap 0 add add p 2 n
436put ap 1 add get ap 1 1
437end
438fn atext s view uchar * to void
439pclear
440ptext s
441apb
442end
443fn aslot k ulong to void
444pclear
445pslot k
446apb
447end
448fn anum v ulong to void
449pclear
450pnum v
451apb
452end
453note one argument per space-separated word of s
454fn awords s view uchar * to void
455pclear
456for i ulong len s
457if eq get s i 32
458apb
459pclear
460else
461pbyte get s i
462end
463end
464apb
465end
466note packet: wpatch CMD
467fn acmd s view uchar * to void
468aclear
469aslot SWP
470atext s
471end
472
473note ---- child processes ---------------------------------------------------------------------------
474fn showcmd to void
475say RUNT
476p = ulong 2
477for i ulong get ap 1
478n = or ulong get av p shl ulong get av add p 1 8
479say SP
480r = write 1 av add p 2 n
481p = add add p 2 n
482end
483say NL
484end
485fn redir s int d int to void
486if ne s d
487if ne dupfd s d 0 long d
488exit 127
489end
490end
491end
492fn drain rd int to void
493n = ulong 0
494k = long 1
495while gt k 0 bound 999999
496if eq n len ob
497fail LCAP
498end
499k = read rd ob n sub len ob n
500if gt k 0
501n = add n ulong k
502end
503end
504r = fclose rd
505put obn 0 n
506end
507fn reap pid long to ulong
508w = waitpid int pid stb 0 4 0
509if ne w pid
510fail LCHILD
511end
512if ne get stb 0 0
513ret add 256 ulong and get stb 0 127
514end
515ret ulong get stb 1
516end
517fn echoob to void
518n = get obn 0
519s = ulong 0
520for i ulong n
521if eq get ob i 10
522say BART
523r = write 1 ob s add sub i s 1
524s = add i 1
525end
526end
527if lt s n
528say BART
529r = write 1 ob s sub n s
530say NL
531end
532end
533note Run the packet in av: stdout is captured into ob, stderr passes through. Checks the exit.
534fn go want ulong to void
535put av 0 uchar and get ap 1 255
536put av 1 uchar shr get ap 1 8
537showcmd
538pf = new uchar 8 0
539if ne pipefds pf 0 8 0 0
540fail LCHILD
541end
542rd = int or ulong get pf 0 shl ulong get pf 1 8
543wr = int or ulong get pf 4 shl ulong get pf 5 8
544t0 = monons
545pid = fork
546if lt pid 0
547fail LCHILD
548end
549if eq pid 0
550r = fclose rd
551redir wr 1
552r = execprog av 0 get ap 0
553exit 127
554end
555r = fclose wr
556drain rd
557x = reap pid
558t = sub monons t0
559put cnt 1 add get cnt 1 1
560echoob
561say EXITT
562saynum x
563say WANTT
564saynum want
565say ELAPT
566saynum ulong t
567say NL
568need eq x want LEXIT
569end
570note Slot k = child stdout without trailing white space.
571fn keepout k ulong to void
572n = get obn 0
573going = true
574while going
575if eq n 0
576going = false
577else
578if le get ob sub n 1 32
579n = sub n 1
580else
581going = false
582end
583end
584end
585pclear
586for i ulong n
587pbyte get ob i
588end
589keepat k
590end
591note true when the bytes now in pb occur in ob
592fn obhaspb to bool
593n = get obn 0
594m = get pn 0
595if gt m n
596ret false
597end
598for i ulong add sub n m 1
599hit = true
600for j ulong m
601if ne get ob add i j get pb j
602hit = false
603end
604end
605if hit
606ret true
607end
608end
609ret false
610end
611
612note ---- files and maps -----------------------------------------------------------------------------
613fn failio k ulong to void
614pclear
615pslot k
616failpm LIO
617end
618fn fsize k ulong to ulong
619pclear
620pslot k
621fd = int fopen pb 0 get pn 0 0 0
622if lt fd 0
623failio k
624end
625sz = fseek fd 0 2
626r = fclose fd
627if lt sz 0
628failio k
629end
630ret ulong sz
631end
632fn mopen k ulong to long
633pclear
634pslot k
635fd = int fopen pb 0 get pn 0 0 0
636if lt fd 0
637failio k
638end
639sz = fseek fd 0 2
640h = mapnew fd 0 ulong sz 1 2
641r = fclose fd
642if lt h 0
643failio k
644end
645ret h
646end
647note Create slot k (must not exist) with n zero bytes; return a shared read/write map.
648fn mcreate k ulong n ulong to long
649pclear
650pslot k
651fd = int fopen pb 0 get pn 0 194 420
652if lt fd 0
653failio k
654end
655if ne ftrunc fd long n 0
656failio k
657end
658h = mapnew fd 0 n 3 1
659r = fclose fd
660if lt h 0
661failio k
662end
663ret h
664end
665fn mdrop h long to void
666r = mapdrop h
667end
668fn cpy src long so ulong dst long doff ulong n ulong to void
669b = new uchar 65536 0
670p = ulong 0
671while lt p n bound 999999
672k = sub n p
673if gt k 65536
674k = 65536
675end
676r = mapread src add so p b 0 k
677r = mapwrite dst add doff p b 0 k
678p = add p k
679end
680end
681fn mcopy src long n ulong k ulong to long
682h = mcreate k n
683cpy src 0 h 0 n
684ret h
685end
686fn exists k ulong to bool
687pclear
688pslot k
689ret eq faccess pb 0 get pn 0 0 0
690end
691fn mkd k ulong to void
692pclear
693pslot k
694if ne makedir pb 0 get pn 0 493 0
695failio k
696end
697end
698fn wtext k ulong s view uchar * to void
699pclear
700pslot k
701fd = int fopen pb 0 get pn 0 193 420
702if lt fd 0
703failio k
704end
705r = write fd s 0 len s
706c = fclose fd
707if or ne r long len s ne c 0
708failio k
709end
710end
711fn g8 h long o ulong to ulong
712ret mapget h o 8
713end
714fn s8 h long o ulong v ulong to void
715r = mapset h o 8 v
716end
717fn gb h long o ulong to ulong
718b = new uchar 1 0
719r = mapread h o b 0 1
720ret ulong get b 0
721end
722fn sbt h long o ulong v ulong to void
723b = new uchar 1 0
724put b 0 uchar v
725r = mapwrite h o b 0 1
726end
727fn flip h long o ulong to void
728sbt h o xor gb h o 1
729end
730fn fnvh h long n ulong to ulong
731b = new uchar 65536 0
732v = ulong 14695981039346656037
733p = ulong 120
734while lt p n bound 999999
735k = sub n p
736if gt k 65536
737k = 65536
738end
739r = mapread h p b 0 k
740for i ulong k
741v = mul xor v ulong get b i 1099511628211
742end
743p = add p k
744end
745ret v
746end
747fn reseal h long n ulong to void
748s8 h 112 fnvh h n
749end
750fn mreq h1 long o1 ulong h2 long n ulong to bool
751p = ulong 0
752while lt p n bound 999999
753k = sub n p
754if gt k 65536
755k = 65536
756end
757r = mapread h1 add o1 p ca 0 k
758r = mapread h2 p cb 0 k
759for i ulong k
760if ne get ca i get cb i
761ret false
762end
763end
764p = add p k
765end
766ret true
767end
768fn fsame k1 ulong k2 ulong to bool
769n = fsize k1
770if ne n fsize k2
771ret false
772end
773if eq n 0
774ret true
775end
776h1 = mopen k1
777h2 = mopen k2
778same = mreq h1 0 h2 n
779mdrop h1
780mdrop h2
781ret same
782end
783fn mtext h long o ulong s view uchar * to bool
784b = new uchar 4096 0
785if gt len s 4096
786fail LCAP
787end
788r = mapread h o b 0 len s
789if ne r long len s
790ret false
791end
792for i ulong len s
793if ne get b i get s i
794ret false
795end
796end
797ret true
798end
799note Omega SHA-256 of n bytes at o into dg.
800fn shah h long o ulong n ulong to void
801b = new uchar 65536 0
802c = new uchar 104 0
803d = new uchar 32 0
804sha256_init c
805p = ulong 0
806while lt p n bound 999999
807k = sub n p
808if gt k 65536
809k = 65536
810end
811r = mapread h add o p b 0 k
812sha256_update c part b 0 k
813p = add p k
814end
815sha256_final c d
816for i ulong 32
817put dg i get d i
818end
819end
820fn hb to long
821ret long get hh 0
822end
823fn he to long
824ret long get hh 1
825end
826fn hm to long
827ret long get hh 2
828end
829fn mfg i ulong to ulong
830ret get mf i
831end
832
833note ---- oracle requests --------------------------------------------------------------------------
834fn rqb b uchar to void
835n = get rqn 0
836if ge n len rq
837fail LCAP
838end
839put rq n b
840put rqn 0 add n 1
841end
842fn rqt s view uchar * to void
843for i ulong len s
844rqb get s i
845end
846end
847fn rqnum v ulong to void
848pclear
849pnum v
850for i ulong get pn 0
851rqb get pb i
852end
853end
854fn rqslot k ulong to void
855o = mul k 512
856for i ulong get sl k
857rqb get sb add o i
858end
859end
860fn rqnl to void
861rqb 10
862put rqn 1 add get rqn 1 1
863end
864fn qsha k ulong o ulong n ulong to void
865rqt QSHA
866rqnum o
867rqb 32
868if eq n ALL
869rqb 45
870else
871rqnum n
872end
873rqb 32
874rqslot k
875rqnl
876end
877fn qf32 k ulong to void
878rqt QF32
879rqslot k
880rqnl
881end
882fn qne a ulong b ulong s ulong c ulong k ulong to void
883rqt QNE
884rqnum a
885rqb 32
886rqnum b
887rqb 32
888rqnum s
889rqb 32
890rqnum c
891rqb 32
892rqslot k
893rqnl
894end
895note Run the oracle on the pending request; its answer lines go to oo, starts in ol.
896fn orun to void
897put cnt 2 add get cnt 2 1
898wnamen SRQ FORQ get cnt 2 FREQ
899pclear
900pslot SRQ
901fd = int fopen pb 0 get pn 0 193 420
902if lt fd 0
903failio SRQ
904end
905r = write fd rq 0 get rqn 0
906c = fclose fd
907if or ne r long get rqn 0 ne c 0
908failio SRQ
909end
910aclear
911atext PY
912aslot SORC
913aslot SRQ
914go 0
915n = get obn 0
916if gt n len oo
917fail LCAP
918end
919k = ulong 0
920put ol 0 0
921for i ulong n
922put oo i get ob i
923if eq get ob i 10
924k = add k 1
925if ge k len ol
926fail LCAP
927end
928put ol k add i 1
929end
930end
931put oln 0 k
932need and eq k get rqn 1 eq get ol k n LORL
933put rqn 0 0
934put rqn 1 0
935end
936note line i holds exactly 64 lower-case hex digits equal to the 32 bytes b
937fn hexis i ulong b view uchar 32 to bool
938s = get ol i
939if ne sub get ol add i 1 s 65
940ret false
941end
942for j ulong 32
943x = get b j
944o = add s mul j 2
945if ne get oo o get HEXD shr x 4
946ret false
947end
948if ne get oo add o 1 get HEXD and x 15
949ret false
950end
951end
952ret true
953end
954fn ohexm i ulong h long o ulong to bool
955b = new uchar 32 0
956r = mapread h o b 0 32
957ret hexis i b
958end
959fn ohexd i ulong to bool
960b = new uchar 32 0
961for j ulong 32
962put b j get dg j
963end
964ret hexis i b
965end
966fn ohext i ulong s view uchar * to bool
967o = get ol i
968if ne sub get ol add i 1 o add len s 1
969ret false
970end
971for j ulong len s
972if ne get oo add o j get s j
973ret false
974end
975end
976ret true
977end
978fn oeq i ulong j ulong to bool
979a = get ol i
980b = get ol j
981n = sub get ol add i 1 a
982if ne n sub get ol add j 1 b
983ret false
984end
985for k ulong n
986if ne get oo add a k get oo add b k
987ret false
988end
989end
990ret true
991end
992fn onum i ulong to ulong
993v = ulong 0
994s = get ol i
995n = sub sub get ol add i 1 s 1
996for k ulong n
997d = sub ulong get oo add s k 48
998v = add mul v 10 d
999end
1000ret v
1001end
1002note slot k ends in / + the 64 hex digits of line i + .wp
1003fn namechk k ulong i ulong to bool
1004n = get sl k
1005if lt n 68
1006ret false
1007end
1008o = add mul k 512 sub n 68
1009if ne get sb o 47
1010ret false
1011end
1012s = get ol i
1013for j ulong 64
1014if ne get sb add add o 1 j get oo add s j
1015ret false
1016end
1017end
1018a = eq get sb add o 65 46
1019b = eq get sb add o 66 119
1020c = eq get sb add o 67 112
1021ret and and a b c
1022end
1023
1024note ---- checkpoint geometry -----------------------------------------------------------------------
1025fn tadd kd ulong ly ulong r ulong c ulong to void
1026n = get tn 0
1027if ge n 256
1028fail LCAP
1029end
1030o = mul n 6
1031put tt o kd
1032put tt add o 1 ly
1033put tt add o 2 r
1034put tt add o 3 c
1035put tt add o 4 get tn 1
1036put tt add o 5 mul r c
1037put tn 0 add n 1
1038put tn 1 add get tn 1 mul r c
1039end
1040fn tlayer y ulong d ulong f ulong to void
1041tadd 2 y 1 d
1042tadd 3 y d d
1043tadd 4 y d d
1044tadd 5 y d d
1045tadd 6 y d d
1046tadd 7 y 1 d
1047tadd 8 y d f
1048tadd 9 y f d
1049end
1050fn tensors h long to void
1051put tn 0 0
1052put tn 1 0
1053d = g8 h 24
1054f = g8 h 40
1055tadd 0 0 g8 h 8 d
1056tadd 1 0 g8 h 16 d
1057for y ulong g8 h 48
1058tlayer y d f
1059end
1060tadd 10 0 1 d
1061end
1062fn tget i ulong j ulong to ulong
1063ret get tt add mul i 6 j
1064end
1065fn ckcheck h long n ulong to void
1066need mtext h 0 CK02 LMAG
1067pp = g8 h 96
1068need eq n add 120 mul 24 pp LCKL
1069need eq fnvh h n g8 h 112 LFNV
1070tensors h
1071k = sub get tn 0 1
1072need eq add tget k 4 tget k 5 pp LGEOP
1073end
1074
1075note ---- manifest ---------------------------------------------------------------------------------
1076note mf: 0 size, 1 policy, 2 tensors, 3 entries, 4 P, 5 entry offset, 6 entry size, 7 end of
1077note entries, 8 params length, 9 rationale length. The map handle is hh 2.
1078fn manfields k ulong to void
1079h = mopen k
1080put hh 2 ulong h
1081put mf 0 fsize k
1082put mf 1 g8 h 16
1083put mf 2 g8 h 24
1084put mf 3 g8 h 32
1085put mf 4 g8 h 40
1086es = ulong 40
1087if eq g8 h 16 0
1088es = 24
1089end
1090eo = add 376 mul 128 g8 h 24
1091put mf 5 eo
1092put mf 6 es
1093put mf 7 add eo mul es g8 h 32
1094put mf 8 g8 h 224
1095put mf 9 g8 h 232
1096end
1097fn entix i ulong to ulong
1098ret g8 hm add mfg 5 mul mfg 6 i
1099end
1100fn provok to bool
1101h = hm
1102e = mfg 7
1103if eq get cnt 3 0
1104a = and eq mfg 8 len PARS mtext h e PARS
1105b = and eq mfg 9 len RATS mtext h add e mfg 8 RATS
1106ret and a b
1107end
1108a = and eq mfg 8 len PARR mtext h e PARR
1109b = and eq mfg 9 len RATR mtext h add e mfg 8 RATR
1110ret and a b
1111end
1112fn ordered to bool
1113m = mfg 3
1114if eq m 0
1115ret true
1116end
1117for i ulong sub m 1
1118if ge entix i entix add i 1
1119ret false
1120end
1121end
1122ret true
1123end
1124fn inbounds to bool
1125for i ulong mfg 3
1126if ge entix i mfg 4
1127ret false
1128end
1129end
1130ret true
1131end
1132note Manifest structure. Oracle lines 0 and 1 are the manifest SHA and the entry-range SHA.
1133fn mancheck k ulong to void
1134h = hm
1135need mtext h 0 WP01 LWMAG
1136need namechk k 0 LNAME
1137need eq g8 h 8 mfg 0 LMLEN
1138need le mfg 1 2 LPOL
1139need ohexm 1 h 192 LEID
1140need eq add add mfg 7 mfg 8 mfg 9 mfg 0 LMETA
1141need provok LPROV
1142need ordered LORD
1143need inbounds LBND
1144end
1145note Queue the manifest SHA and entry-range SHA requests (lines 0 and 1).
1146fn qman k ulong to void
1147qsha k 0 ALL
1148qsha k mfg 5 mul mfg 6 mfg 3
1149end
1150fn entchk i ulong to void
1151h = hm
1152o = add mfg 5 mul mfg 6 i
1153old = g8 h add o 8
1154nw = g8 h add o 16
1155wo = add 120 mul 8 g8 h o
1156need and eq g8 hb wo old eq g8 he wo nw LEBIT
1157need and ne old nw ne and shr nw 52 2047 2047 LEFIN
1158need le bitcast f64 and nw 0x7fffffffffffffff 1000000.0 LEMAG
1159if gt mfg 1 0
1160pp = mfg 4
1161a = eq g8 h add o 24 g8 hb add wo mul 8 pp
1162b = eq g8 h add o 32 g8 hb add wo mul 16 pp
1163need and a b LEMOM
1164end
1165end
1166note Expected output derived from the manifest: edited, saved moments zeroed, resealed.
1167fn mexpect k ulong to void
1168n = fsize SEDIT
1169x = mcopy he n k
1170pp = mfg 4
1171for i ulong mfg 3
1172wo = add 120 mul 8 entix i
1173if ge mfg 1 1
1174s8 x add wo mul 8 pp 0
1175end
1176if eq mfg 1 2
1177s8 x add wo mul 16 pp 0
1178end
1179end
1180reseal x n
1181mdrop x
1182end
1183fn tchanged i ulong to ulong
1184lo = tget i 4
1185hi = add lo tget i 5
1186c = ulong 0
1187for j ulong mfg 3
1188x = entix j
1189if and ge x lo lt x hi
1190c = add c 1
1191end
1192end
1193ret c
1194end
1195fn trec i ulong to bool
1196h = hm
1197r = add 376 mul 128 i
1198a = and eq g8 h r tget i 0 eq g8 h add r 8 tget i 1
1199b = and eq g8 h add r 16 tget i 2 eq g8 h add r 24 tget i 3
1200c = and eq g8 h add r 32 64 eq g8 h add r 40 tget i 4
1201ret and and a b c
1202end
1203note Per-tensor checks; oracle lines from first: nt base-range SHAs, then nt output-range SHAs.
1204fn tchk first ulong to void
1205nt = mfg 2
1206need eq nt get tn 0 LTALL
1207for i ulong nt
1208r = add 376 mul 128 i
1209need trec i LTGEO
1210need eq g8 hm add r 48 tchanged i LTCNT
1211need ohexm add first i hm add r 64 LTBS
1212need ohexm add add first nt i hm add r 96 LTOS
1213end
1214end
1215note Zero the saved moments of word offset wo as policy p clears them.
1216fn zmom x long wo ulong p ulong to void
1217pp = g8 x 96
1218if ge p 1
1219s8 x add wo mul 8 pp 0
1220end
1221if eq p 2
1222s8 x add wo mul 16 pp 0
1223end
1224end
1225fn rqword x long i ulong p ulong to void
1226wo = add 120 mul 8 get rix i
1227s8 x wo get rbt i
1228zmom x wo p
1229end
1230note Requested output from intent: copy of slot src with rix/rbt bits, moments zeroed per policy.
1231fn reqout src ulong k ulong p ulong to void
1232hs = mopen src
1233n = fsize src
1234x = mcopy hs n k
1235mdrop hs
1236for i ulong get rcn 0
1237rqword x i p
1238end
1239reseal x n
1240mdrop x
1241end
1242
1243note ---- small: one policy --------------------------------------------------------------------------
1244fn pdiff p ulong to void
1245wnamep SOD FPAT p
1246mkd SOD
1247acmd CDIFF
1248aslot SBASE
1249aslot SEDIT
1250anum p
1251aslot SPF
1252aslot SRF
1253aslot SOD
1254go 0
1255keepout add SP0 p
1256end
1257fn porc p ulong to void
1258k = add SP0 p
1259manfields k
1260wnamen SMEX FMEX p FCK
1261mexpect SMEX
1262nt = mfg 2
1263qman k
1264qsha SBASE 0 ALL
1265qsha SMEX 0 ALL
1266qf32 SMEX
1267qne add mfg 5 8 add mfg 5 16 mfg 6 mfg 3 k
1268for i ulong nt
1269qsha SBASE add 120 mul 8 tget i 4 mul 8 tget i 5
1270end
1271for i ulong nt
1272qsha SMEX add 120 mul 8 tget i 4 mul 8 tget i 5
1273end
1274orun
1275mancheck k
1276need eq mfg 1 p LPOL
1277ckcheck hb fsize SBASE
1278need mreq hm 256 hb 120 LHDR
1279geo = true
1280for i ulong 6
1281if ne g8 hm add 48 mul 8 i g8 hb add 8 mul 8 i
1282geo = false
1283end
1284end
1285need geo LMGEO
1286need eq mfg 4 g8 hb 96 LMP
1287need ohexm 2 hm 96 LBSHA
1288for i ulong mfg 3
1289entchk i
1290end
1291need ohexm 3 hm 128 LOSHA
1292need ohexm 4 hm 160 LOF32
1293tchk 6
1294end
1295fn pshow p ulong to void
1296acmd CSHOW
1297aslot add SP0 p
1298go 0
1299n = get obn 0
1300a = len SHOWA
1301z = len SHOWZ
1302ok = gt n add add a z 64
1303if ok
1304for i ulong a
1305if ne get ob i get SHOWA i
1306ok = false
1307end
1308end
1309s = get ol 0
1310for j ulong 64
1311if ne get ob add a j get oo add s j
1312ok = false
1313end
1314end
1315for i ulong z
1316if ne get ob add sub n z i get SHOWZ i
1317ok = false
1318end
1319end
1320end
1321need ok LSHOW
1322end
1323fn papply p ulong to void
1324acmd CVAL
1325aslot add SP0 p
1326aslot SBASE
1327go 0
1328wnamen SOUT FAPP p FCK
1329wnamen SREV FREV p FCK
1330acmd CAPP
1331aslot add SP0 p
1332aslot SBASE
1333aslot SOUT
1334go 0
1335need fsame SOUT SMEX LAPPX
1336need fsame SREQ SOUT LAPPR
1337acmd CVER
1338aslot add SP0 p
1339aslot SOUT
1340go 0
1341pclear
1342ptext SURV
1343pnum onum 5
1344ptext CHGD
1345pnum mfg 3
1346need obhaspb LSURV
1347acmd CREV
1348aslot add SP0 p
1349aslot SOUT
1350aslot SREV
1351go 0
1352need fsame SREV SSNAP LREVB
1353end
1354fn pbind p ulong to void
1355k = add SP0 p
1356wnamep SBIND FBND p
1357acmd CBIND
1358aslot k
1359aslot SOUT
1360aslot SWP
1361aslot SBIND
1362go 0
1363qsha SMEX 0 ALL
1364qf32 SMEX
1365qsha SWP 0 ALL
1366qsha k 0 ALL
1367qsha SBIND 0 136
1368orun
1369h = mopen SBIND
1370need and eq fsize SBIND 168 mtext h 0 WB01 LBFMT
1371need and ohexm 0 h 8 ohexm 1 h 40 LBCK
1372need and ohexm 2 h 72 ohexm 3 h 104 LBRT
1373need ohexm 4 h 136 LBSELF
1374mdrop h
1375end
1376fn pcheckb p ulong to void
1377acmd CCB
1378aslot SBIND
1379aslot SOUT
1380aslot SWP
1381go 0
1382acmd CCB
1383aslot SBIND
1384aslot SBASE
1385aslot SWP
1386go 60
1387wnamep SRT FRT p
1388n = fsize SWP
1389h = mopen SWP
1390x = mcreate SRT add n 1
1391cpy h 0 x 0 n
1392mdrop x
1393mdrop h
1394acmd CCB
1395aslot SBIND
1396aslot SOUT
1397aslot SRT
1398go 62
1399wnamep SBADB FBADB p
1400h = mopen SBIND
1401x = mcopy h 168 SBADB
1402mdrop h
1403flip x 40
1404shah x 0 136
1405r = mapwrite x 136 dg 0 32
1406acmd CCB
1407aslot SBADB
1408aslot SOUT
1409aslot SWP
1410go 61
1411flip x 104
1412acmd CCB
1413aslot SBADB
1414aslot SOUT
1415aslot SWP
1416go 59
1417mdrop x
1418end
1419fn prefuse p ulong to void
1420acmd CAPP
1421aslot add SP0 p
1422aslot SBASE
1423aslot SOUT
1424go 52
1425need fsame SOUT SMEX LOUTP
1426acmd CAPP
1427aslot add SP0 p
1428aslot SBASE
1429aslot SBASE
1430go 52
1431acmd CREV
1432aslot add SP0 p
1433aslot SOUT
1434aslot SBASE
1435go 52
1436acmd CDIFF
1437aslot SBASE
1438aslot SEDIT
1439anum p
1440aslot SPF
1441aslot SRF
1442aslot SOD
1443go 52
1444end
1445fn policy p ulong to void
1446pdiff p
1447porc p
1448wnamen SREQ FEXP p FCK
1449reqout SBASE SREQ p
1450need fsame SREQ SMEX LAGREE
1451pshow p
1452papply p
1453pbind p
1454pcheckb p
1455prefuse p
1456mdrop hm
1457end
1458
1459note ---- small: fixtures and adversarial manifests --------------------------------------------------
1460fn train to void
1461wname STRAIN FTRAIN
1462h = mcreate STRAIN 3000
1463b = new uchar 15 0
1464for i ulong len TRAINW
1465put b i get TRAINW i
1466end
1467for i ulong 200
1468r = mapwrite h mul i 15 b 0 15
1469end
1470mdrop h
1471wname SBASE FBASE
1472aclear
1473aslot SOLLM
1474atext CINIT
1475aslot SBASE
1476awords INITA
1477go 0
1478aclear
1479aslot SOLLM
1480atext CTRAIN
1481aslot SBASE
1482aslot STRAIN
1483anum 2
1484anum 1
1485go 0
1486end
1487note edited = base + 0.001 at every tensor start, index 1 low bit flipped; requested = those bits.
1488fn mkedit to void
1489n = fsize SBASE
1490h = mopen SBASE
1491put hh 0 ulong h
1492ckcheck h n
1493wname SSNAP FSNAP
1494x = mcopy h n SSNAP
1495mdrop x
1496wname SEDIT FEDIT
1497x = mcopy h n SEDIT
1498put hh 1 ulong x
1499k = get tn 0
1500for i ulong k
1501wo = add 120 mul 8 tget i 4
1502s8 x wo bitcast ulong add bitcast f64 g8 x wo DLT
1503put rix i tget i 4
1504put rbt i g8 x wo
1505end
1506s8 x 128 xor g8 x 128 1
1507put rix k 1
1508put rbt k g8 x 128
1509put rcn 0 add k 1
1510reseal x n
1511wname SPF FPF
1512wtext SPF PARS
1513wname SRF FRF
1514wtext SRF RATS
1515end
1516fn inspect to void
1517acmd CINSP
1518aslot SBASE
1519go 0
1520acmd CINSP
1521aslot SBASE
1522atext WTE
1523awords SLICEA
1524go 0
1525pclear
1526phex g8 hb 120
1527a = obhaspb
1528pclear
1529phex g8 hb 128
1530need and a obhaspb LSLICE
1531acmd CINSP
1532aslot SBASE
1533atext WTE
1534awords OOBA
1535go 27
1536end
1537note Policy-2 patch for an edit whose index-0 value is 0.25: verify accepts it, yet its applied
1538note bytes must differ from expected-2.ck (the in-run negative control of the byte oracle).
1539fn mutant to void
1540n = fsize SEDIT
1541wname SX0 FMUTE
1542x = mcopy he n SX0
1543s8 x 120 bitcast ulong QTR
1544reseal x n
1545mdrop x
1546wname SX1 FMUTD
1547mkd SX1
1548acmd CDIFF
1549aslot SBASE
1550aslot SX0
1551anum 2
1552aslot SPF
1553aslot SRF
1554aslot SX1
1555go 0
1556keepout SX2
1557wname SX3 FMUTO
1558acmd CAPP
1559aslot SX2
1560aslot SBASE
1561aslot SX3
1562go 0
1563acmd CVER
1564aslot SX2
1565aslot SX3
1566go 0
1567old = get rbt 0
1568put rbt 0 bitcast ulong QTR
1569wname SX4 FMUTR
1570reqout SBASE SX4 2
1571put rbt 0 old
1572need fsame SX4 SX3 LMUTS
1573wnamen SREQ FEXP 2 FCK
1574need not fsame SREQ SX3 LMUTR
1575end
1576fn fill h long o ulong n ulong to void
1577b = new uchar 65536 97
1578p = ulong 0
1579while lt p n bound 999999
1580k = sub n p
1581if gt k 65536
1582k = 65536
1583end
1584r = mapwrite h add o p b 0 k
1585p = add p k
1586end
1587end
1588note Oversized params (f 0) or rationale (f 1): 16777217 bytes of a, length fields updated.
1589fn oversize f ulong to void
1590manfields add SP0 2
1591n0 = mfg 0
1592e = add mfg 7 mfg 8
1593if eq f 0
1594e = mfg 7
1595end
1596dropn = mfg 9
1597if eq f 0
1598dropn = mfg 8
1599end
1600nn = sub add n0 OVER dropn
1601if eq f 0
1602pclear
1603pslot SWORK
1604pbyte 47
1605ptext FOVP
1606else
1607pclear
1608pslot SWORK
1609pbyte 47
1610ptext FOVR
1611end
1612ptext FWP
1613keepat SX0
1614pn0 = get pn 0
1615put pn 0 sub pn0 3
1616ptext FCK
1617keepat SX1
1618x = mcreate SX0 nn
1619cpy hm 0 x 0 e
1620fill x e OVER
1621if eq f 0
1622cpy hm add e mfg 8 x add e OVER mfg 9
1623s8 x 224 OVER
1624else
1625s8 x 232 OVER
1626end
1627s8 x 8 nn
1628mdrop x
1629mdrop hm
1630acmd CVAL
1631aslot SX0
1632aslot SBASE
1633go 57
1634acmd CSHOW
1635aslot SX0
1636go 57
1637acmd CAPP
1638aslot SX0
1639aslot SBASE
1640aslot SX1
1641go 57
1642need not exists SX1 LOVER
1643end
1644fn badutf to void
1645manfields add SP0 2
1646n = mfg 0
1647wname SX0 FUTF
1648x = mcopy hm n SX0
1649sbt x sub n 1 255
1650mdrop x
1651mdrop hm
1652acmd CVAL
1653aslot SX0
1654aslot SBASE
1655go 31
1656end
1657note Apply mutation c (0..16, named by word c of MUTN) to x; return the expected refusal code.
1658fn mutate x long c ulong to ulong
1659eo = mfg 5
1660if eq c 0
1661flip x 96
1662ret 50
1663end
1664if eq c 1
1665s8 x 48 add g8 x 48 1
1666ret 36
1667end
1668if eq c 2
1669s8 x 392 add g8 x 392 1
1670ret 37
1671end
1672if eq c 3
1673s8 x eo mfg 4
1674ret 38
1675end
1676if eq c 4
1677s8 x add eo 16 0x7ff8000000000000
1678ret 40
1679end
1680if eq c 5
1681s8 x add eo 16 0x7ff0000000000000
1682ret 41
1683end
1684if eq c 6
1685s8 x add eo 16 bitcast ulong BIGM
1686ret 42
1687end
1688if eq c 7
1689for j ulong 5
1690a = g8 x add eo mul 8 j
1691s8 x add eo mul 8 j g8 x add add eo 40 mul 8 j
1692s8 x add add eo 40 mul 8 j a
1693end
1694ret 39
1695end
1696if eq c 8
1697s8 x add eo 40 g8 x eo
1698ret 43
1699end
1700ret mutate2 x c
1701end
1702fn mutate2 x long c ulong to ulong
1703eo = mfg 5
1704if eq c 9
1705s8 x add eo 8 xor g8 x add eo 8 1
1706ret 47
1707end
1708if eq c 10
1709s8 x add eo 24 xor g8 x add eo 24 1
1710ret 48
1711end
1712if eq c 11
1713flip x 192
1714ret 46
1715end
1716if eq c 12
1717s8 x 424 add g8 x 424 1
1718ret 45
1719end
1720if eq c 13
1721flip x 440
1722ret 49
1723end
1724if eq c 14
1725flip x 472
1726ret 49
1727end
1728if eq c 15
1729flip x 128
1730ret 53
1731end
1732flip x 160
1733ret 54
1734end
1735fn mutcase c ulong to void
1736n = mfg 0
1737pclear
1738pslot SWORK
1739pbyte 47
1740pword MUTN c
1741ptext FWP
1742keepat SX0
1743put pn 0 sub get pn 0 3
1744ptext FCK
1745keepat SX1
1746x = mcopy hm n SX0
1747code = mutate x c
1748if ne c 11
1749shah x mfg 5 mul mfg 6 mfg 3
1750r = mapwrite x 192 dg 0 32
1751end
1752mdrop x
1753acmd CVAL
1754aslot SX0
1755aslot SBASE
1756go code
1757acmd CAPP
1758aslot SX0
1759aslot SBASE
1760aslot SX1
1761go code
1762gone = not exists SX1
1763pclear
1764pword MUTN c
1765needpm gone LREF
1766end
1767fn flipped to void
1768n = mfg 0
1769wname SX0 FFLIP
1770mkd SX0
1771k = add SP0 1
1772pclear
1773pslot SX0
1774o = add mul k 512 sub get sl k 68
1775for i ulong 68
1776pbyte get sb add o i
1777end
1778keepat SX0
1779x = mcopy hm n SX0
1780flip x sub n 1
1781mdrop x
1782wnamen SX1 FAPP 1 FCK
1783acmd CSHOW
1784aslot SX0
1785go 30
1786acmd CVAL
1787aslot SX0
1788aslot SBASE
1789go 30
1790acmd CVER
1791aslot SX0
1792aslot SX1
1793go 30
1794wname SX2 FBAPP
1795acmd CAPP
1796aslot SX0
1797aslot SBASE
1798aslot SX2
1799go 30
1800wname SX2 FBREV
1801acmd CREV
1802aslot SX0
1803aslot SX1
1804aslot SX2
1805go 30
1806wname SX2 FBBND
1807acmd CBIND
1808aslot SX0
1809aslot SX1
1810aslot SWP
1811aslot SX2
1812go 30
1813end
1814fn truncs to void
1815n = mfg 0
1816wname SX0 FTRUNC
1817x = mcopy hm sub n 1 SX0
1818mdrop x
1819acmd CVAL
1820aslot SX0
1821aslot SBASE
1822go 32
1823pclear
1824pslot SX0
1825r = unlink pb 0 get pn 0
1826x = mcopy hm 100 SX0
1827mdrop x
1828acmd CSHOW
1829aslot SX0
1830go 32
1831end
1832fn diffbad to void
1833acmd CDIFF
1834aslot SBASE
1835aslot SBASE
1836anum 0
1837aslot SPF
1838aslot SRF
1839aslot SWORK
1840go 55
1841n = fsize SEDIT
1842wname SX0 FWRM
1843x = mcopy he n SX0
1844o = add 120 mul 8 g8 x 96
1845s8 x o xor g8 x o 1
1846reseal x n
1847mdrop x
1848acmd CDIFF
1849aslot SBASE
1850aslot SX0
1851anum 0
1852aslot SPF
1853aslot SRF
1854aslot SWORK
1855go 56
1856end
1857fn exval i ulong to ulong
1858if eq i 0
1859ret 0
1860end
1861if eq i 1
1862ret 0x8000000000000000
1863end
1864if eq i 2
1865ret 1
1866end
1867if eq i 3
1868ret 0x3690000000000000
1869end
1870if eq i 4
1871ret 0x3ff0000010000000
1872end
1873if eq i 5
1874ret 0x3ff0000030000000
1875end
1876if eq i 6
1877ret 0x47f0000000000000
1878end
1879if eq i 7
1880ret 0x7ff0000000000000
1881end
1882if eq i 8
1883ret 0xfff0000000000000
1884end
1885if eq i 9
1886ret 0x7ff8000000000000
1887end
1888ret 0x7fefffffffffffff
1889end
1890note true when the bytes of s occur in ob at o, before e
1891fn obat o ulong e ulong s view uchar * to bool
1892if gt add o len s e
1893ret false
1894end
1895for j ulong len s
1896if ne get ob add o j get s j
1897ret false
1898end
1899end
1900ret true
1901end
1902note true when the inspect line starting `wte ` has rms= with a leading digit 1-9 and nonfinite=3
1903fn rmsok to bool
1904n = get obn 0
1905s = ulong 0
1906for i ulong n
1907if eq get ob i 10
1908if obat s i WTEL
1909ret lineok s i
1910end
1911s = add i 1
1912end
1913end
1914ret false
1915end
1916fn lineok s ulong e ulong to bool
1917r = false
1918f = false
1919for i ulong sub e s
1920o = add s i
1921if obat o e RMSK
1922if lt add o 4 e
1923c = get ob add o 4
1924r = and ge c 49 le c 57
1925end
1926end
1927if obat o e NONF3
1928f = true
1929end
1930end
1931ret and r f
1932end
1933fn exotic to void
1934n = fsize SBASE
1935wname SX0 FEXO
1936x = mcopy hb n SX0
1937for i ulong 11
1938s8 x add 120 mul 8 i exval i
1939end
1940reseal x n
1941wname SX1 FEXE
1942y = mcopy x n SX1
1943mdrop x
1944s8 y 216 bitcast ulong QTR
1945reseal y n
1946mdrop y
1947wname SX2 FEXD
1948mkd SX2
1949acmd CDIFF
1950aslot SX0
1951aslot SX1
1952anum 0
1953aslot SPF
1954aslot SRF
1955aslot SX2
1956go 0
1957keepout SX3
1958qf32 SX1
1959orun
1960h = mopen SX3
1961need ohexm 0 h 160 LEXO
1962mdrop h
1963acmd CVAL
1964aslot SX3
1965aslot SX0
1966go 0
1967acmd CINSP
1968aslot SX0
1969go 0
1970need rmsok LRMS
1971end
1972fn small to void
1973train
1974mkedit
1975inspect
1976for p ulong 3
1977policy p
1978end
1979need fsame SBASE SSNAP LBASEW
1980mutant
1981oversize 0
1982oversize 1
1983badutf
1984manfields add SP0 1
1985for c ulong 17
1986mutcase c
1987end
1988flipped
1989truncs
1990mdrop hm
1991diffbad
1992exotic
1993need fsame SBASE SSNAP LFBASE
1994end
1995
1996note ---- real ---------------------------------------------------------------------------------------
1997fn redit to void
1998n = fsize SBASE
1999h = mopen SBASE
2000put hh 0 ulong h
2001wname SEDIT FR40E
2002x = mcopy h n SEDIT
2003put hh 1 ulong x
2004tensors x
2005off = ulong 0
2006for i ulong get tn 0
2007if and eq tget i 0 9 eq tget i 1 3
2008off = tget i 4
2009end
2010end
2011need eq off BASEOFF LROFF
2012for i ulong 10
2013wo = add 120 mul 8 add off i
2014s8 x wo bitcast ulong add bitcast f64 g8 x wo DLT
2015put rix i add off i
2016put rbt i g8 x wo
2017end
2018put rcn 0 10
2019reseal x n
2020end
2021fn rten to bool
2022if ne mfg 3 10
2023ret false
2024end
2025for i ulong 10
2026if ne entix i add get rix 0 i
2027ret false
2028end
2029end
2030ret true
2031end
2032fn real to void
2033qsha SBASE 0 ALL
2034orun
2035need ohext 0 BSHA LRPIN
2036redit
2037wname SREQ FR40X
2038reqout SBASE SREQ 2
2039wname SPF FPF
2040wtext SPF PARR
2041wname SRF FRF
2042wtext SRF RATR
2043wname SOD FPATS
2044mkd SOD
2045acmd CDIFF
2046aslot SBASE
2047aslot SEDIT
2048anum 2
2049aslot SPF
2050aslot SRF
2051aslot SOD
2052go 0
2053keepout SP0
2054manfields SP0
2055qman SP0
2056orun
2057mancheck SP0
2058need rten LRTEN
2059acmd CVAL
2060aslot SP0
2061aslot SBASE
2062go 0
2063wname SOUT FR40A
2064wname SREV FR40R
2065acmd CAPP
2066aslot SP0
2067aslot SBASE
2068aslot SOUT
2069go 0
2070need fsame SREQ SOUT LRAPP
2071acmd CVER
2072aslot SP0
2073aslot SOUT
2074go 0
2075acmd CREV
2076aslot SP0
2077aslot SOUT
2078aslot SREV
2079go 0
2080aclear
2081atext SUMT
2082aslot SBASE
2083aslot SREV
2084aslot SOUT
2085go 0
2086qsha SREV 0 ALL
2087qsha SBASE 0 ALL
2088qsha SOUT 0 ALL
2089qsha SREQ 0 ALL
2090qf32 SREQ
2091qf32 SOUT
2092orun
2093need ohext 0 BSHA LRREV
2094need ohext 1 BSHA LRBASE
2095need oeq 2 3 LROUT
2096need ohexm 3 hm 128 LRMOUT
2097need oeq 5 4 LRF32
2098need ohexm 4 hm 160 LRMF32
2099end
2100
2101note Print dg as 64 lowercase hex digits.
2102fn sayhex to void
2103pclear
2104for i ulong 32
2105pbyte get HEXD shr get dg i 4
2106pbyte get HEXD and get dg i 15
2107end
2108saypb
2109end
2110note `wpcheck sum FILE`: the Omega SHA-256 of FILE as hex and a newline (wpbuild uses it to check
2111note the vendored net sources). An unreadable FILE is a FAIL with exit 1. An empty FILE is not
2112note mapped (a zero-length map traps); its digest is the SHA-256 of no bytes.
2113fn sumone to int
2114argslot 2 SBASE
2115n = fsize SBASE
2116c = new uchar 104 0
2117d = new uchar 32 0
2118if eq n 0
2119sha256_init c
2120sha256_final c d
2121for i ulong 32
2122put dg i get d i
2123end
2124else
2125h = mopen SBASE
2126shah h 0 n
2127mdrop h
2128end
2129sayhex
2130say NL
2131ret 0
2132end
2133fn main to int
2134c = argcnt
2135if and and ne c 3 ne c 5 ne c 6
2136say USAGE
2137ret 2
2138end
2139argslot 1 SMODE
2140if and eq c 3 slotis SMODE MSUM
2141ret sumone
2142end
2143ok = or and eq c 5 slotis SMODE MSMALL and eq c 6 slotis SMODE MREAL
2144if not ok
2145say USAGE
2146ret 2
2147end
2148argslot 2 SBUILD
2149argslot 3 SWORK
2150argslot 4 SORC
2151if eq c 6
2152argslot 5 SBASE
2153put cnt 3 1
2154end
2155under SWP SBUILD SLWP
2156under SOLLM SBUILD SLOLLM
2157mkd SWORK
2158h = mopen SWP
2159shah h 0 fsize SWP
2160mdrop h
2161say HEADT
2162pclear
2163pslot SMODE
2164saypb
2165say WPSHT
2166sayhex
2167say NL
2168if eq c 5
2169small
2170else
2171real
2172end
2173say WPPT
2174tally
2175ret 0
2176end