interplane.Get Omega
Read in your language

babel

aien-dev/babel

Brought by drakestapleton

branch main Branches Tags History

babel / src / 50-diff.om

886 lines · 12765 bytes Raw Blame History
1note babel 50-diff: toolchains, target builds and the differential test.
2note For every exported unit babel runs the same vectors through three legs: the ORIGINAL C function
3note (cc, verbatim text), the lowered Omega unit (pinned omc) and the generated target. A unit is
4note TRANSLATED only when all three outputs are byte-identical on every vector.
5global Bv ulong 9
6global Sm ulong 1
7global Tok ulong 8
8global Brc ulong 1
9global Trc ulong 1
10global Tsr ulong 1
11global Ubd ulong 1024
12note leg results of unit u at Ulg[3u + k], k 0 original C, 1 Omega, 2 target:
13note 0 not required (the unit never reached the differential), 1 PASS, 2 FAIL, 3 NOT_RUN
14global Ulg ulong 3072
15text TnCc "cc"
16text TnCargo "cargo"
17text TnPy "python3"
18text TnCpp "g++"
19text TnCpp2 "c++"
20text TnZig "zig"
21text TnGo "go"
22text EvZig "ZIG="
23text EvGo "GO="
24text AVer "--version"
25text AVer2 "version"
26text ABuild "build"
27text ATest "test"
28text AOff "--offline"
29text AQuiet "--quiet"
30text AMan "--manifest-path"
31text AStd17 "-std=c17"
32text AStdx "-std=c++17"
33text AO0 "-O0"
34text Aw "-w"
35text Ao "-o"
36text AB "-B"
37text AExe "build-exe"
38text AOd "-O"
39text ADbg "Debug"
40text Alc "-lc"
41text AEmit "-femit-bin="
42text ADot "."
43text EvZg1 "ZIG_GLOBAL_CACHE_DIR="
44text EvZg2 "ZIG_LOCAL_CACHE_DIR="
45text EvGoc "GOCACHE="
46text WZg1 "zig-global"
47text WZg2 "zig-local"
48text WGoc "go-build"
49text WOrc "oracle"
50text WOmd "omega-driver"
51text PRsMan "rust/Cargo.toml"
52text PRsExe "rust/target/debug/babel_diff"
53text PCExe "c/.build/babel_diff"
54text PCBld "c/.build"
55text PCpBld "cpp/.build/"
56text PZExe "zig/.build/babel_diff"
57text PZBld "zig/.build"
58text PGoBld "go/.build/"
59text PVec "/vectors.txt"
60text POut1 "/c-original.out"
61text POut2 "/omega.out"
62text POut3 "/target.out"
63text PBlog "diff/build.log"
64text PBlogU "/build.log"
65text PTlog "diff/test.log"
66text RsOrc "differential oracle failed: the original C function did not build or run with cc (see diff/"
67text RsOrc2 "/oracle.c): "
68text RsOmd "Omega leg failed: the lowered unit plus the babel driver did not compile or run with the pinned omc (see diff/"
69text RsOmd2 "/driver.om): "
70text RsPrep "could not write the differential files under diff/"
71text RsTbd "target build failed (see diff/build.log): "
72text RsTbdU "target build failed (see diff/"
73text RsTbdU2 "/build.log): "
74text RsTrn "target driver failed on the vectors (see diff/"
75text RsTrn2 "/target.out): "
76text RsMo "Omega leg differs from the original C on "
77text RsMt "target output differs from the original C on "
78text RsOf " of "
79text RsVec " vectors (see diff/"
80text RsVe "/)"
81text RsNoCc "no C compiler (cc) on PATH: the differential oracle cannot run, so nothing can be called TRANSLATED"
82
83fn vinit to void
84put Bv 0 0
85put Bv 1 1
86put Bv 2 2
87put Bv 3 sub shl ulong 1 32 1
88put Bv 4 shl ulong 1 32
89put Bv 5 sub shl ulong 1 63 1
90put Bv 6 shl ulong 1 63
91put Bv 7 sub ulong 0 2
92put Bv 8 sub ulong 0 1
93end
94
95fn hilo h ulong l ulong to ulong
96ret or shl h 32 l
97end
98
99note splitmix64; seed fixed so every run uses the same vectors
100fn smx to ulong
101s = add get Sm 0 hilo 2654435769 2135587861
102put Sm 0 s
103z = mul xor s shr s 30 hilo 3210233709 484763065
104z = mul xor z shr z 27 hilo 2496678331 321982955
105ret xor z shr z 31
106end
107
108note systematic vector count for arity k: product of the 9 boundary values up to k = 3, 81 rows after
109fn nsys k ulong to ulong
110if eq k 0
111ret 1
112end
113if eq k 1
114ret 9
115end
116if eq k 2
117ret 81
118end
119if eq k 3
120ret 729
121end
122ret 81
123end
124
125fn sysval k ulong j ulong i ulong to ulong
126if le k 3
127d = ulong 1
128for t ulong sub sub k 1 i
129d = mul d 9
130end
131ret get Bv rem div j d 9
132end
133ret get Bv rem add j mul i add 1 div j 9 9
134end
135
136note vectors.txt for unit u: "id n" then one vector per line; stored in the pool (Uv0/Uvn, Unv)
137fn genvec u ulong to void
138k = get Uar u
139ns = nsys k
140nr = ulong 64
141if eq k 0
142nr = 0
143end
144put Sm 0 20261026
145m = mark
146bu get Uid u
147bc 32
148bu add ns nr
149bc 10
150for j ulong ns
151for i ulong k
152if gt i 0
153bc 32
154end
155bu sysval k j i
156end
157bc 10
158end
159for j ulong nr
160for i ulong k
161if gt i 0
162bc 32
163end
164bu smx
165end
166bc 10
167end
168n = sub mark m
169put Uv0 u psave m n
170put Uvn u n
171put Unv u add ns nr
172reset m
173end
174
175note tool slot s: 0 cc, 1 cargo, 2 python3, 3 g++, 4 zig, 5 go (env ZIG / GO override PATH)
176fn tfind s ulong nm view uchar * to void
177if which nm
178put Tok s 1
179put Tl0 s get Gv0 0
180put Tln s get Gvn 0
181end
182end
183
184fn tools to void
185tfind 0 TnCc
186tfind 1 TnCargo
187tfind 2 TnPy
188tfind 3 TnCpp
189if eq get Tok 3 0
190tfind 3 TnCpp2
191end
192if getenv EvZig
193tenv 4
194else
195tfind 4 TnZig
196end
197if getenv EvGo
198tenv 5
199else
200tfind 5 TnGo
201end
202for s ulong 6
203if eq get Tok s 1
204tver s
205end
206end
207end
208
209note tool slot s from an environment override (Gv0/Gvn): found only when the path is executable
210fn tenv s ulong to void
211m = mark
212bpl get Gv0 0 get Gvn 0
213r = faccess Ob m sub mark m 1
214reset m
215if ne r 0
216ret
217end
218put Tok s 1
219put Tl0 s get Gv0 0
220put Tln s get Gvn 0
221end
222
223note first line of "<tool> --version" (zig/go: "version") into Tv0/Tvn
224fn tver s ulong to void
225m = mark
226rclr
227kenv
228kpl get Tl0 s get Tln s
229if ge s 4
230ktx AVer2
231else
232ktx AVer
233end
234a = mark
235bwk WkOut
236b = mark
237rset 2 a b
238put Rmg 0 1
239r = spawn
240reset m
241if ne r 0
242ret
243end
244a = mark
245bwk WkOut
246b = mark
247q = rfile a b
248reset m
249if le q 0
250ret
251end
252j = ulong 0
253while lt j ulong q bound 999999
254if eq get Fb j 10
255break
256end
257j = add j 1
258end
259if gt j 200
260j = 200
261end
262bfb 0 j
263put Tv0 s psave m j
264put Tvn s j
265reset m
266end
267
268note tool slot of the selected target
269fn tslot to ulong
270g = get Lg 0
271if eq g 1
272ret 0
273end
274if eq g 2
275ret 1
276end
277if eq g 3
278ret 2
279end
280if eq g 6
281ret 3
282end
283if eq g 5
284ret 4
285end
286ret 5
287end
288
289note argv helpers: <out>/<s>, <out>/<s><name><t>
290fn kout s view uchar * to void
291m = mark
292bouts s
293kob m sub mark m
294reset m
295end
296
297note <out>/<s><name> onto argv
298fn kouto s view uchar * u ulong to void
299m = mark
300bouts s
301bname u
302kob m sub mark m
303reset m
304end
305
306fn koutn s view uchar * u ulong t view uchar * to void
307m = mark
308bouts s
309bname u
310bs t
311kob m sub mark m
312reset m
313end
314
315fn ktool s ulong to void
316kpl get Tl0 s get Tln s
317end
318
319note stdin /dev/null, stdout and stderr merged into <out>/<s>
320fn rlog s view uchar * to void
321a = mark
322bouts s
323b = mark
324rset 2 a b
325put Rmg 0 1
326end
327
328note env-style NAME=<out>/.work/<s> argument
329fn kenvwk e view uchar * s view uchar * to void
330m = mark
331bs e
332bwk s
333kob m sub mark m
334reset m
335end
336
337fn mkout s view uchar * to void
338m = mark
339bouts s
340e = mark
341q = mkdirs m e
342reset m
343end
344
345note build the selected target project once (per unit for cpp and go, into Ubd); log diff/build.log
346fn tbuild to void
347g = get Lg 0
348s = tslot
349put Brc 0 0
350if eq get Tok s 0
351put Brc 0 255
352ret
353end
354m = mark
355rclr
356kenv
357if eq g 2
358ktool 1
359ktx ABuild
360ktx AOff
361ktx AQuiet
362ktx AMan
363kout PRsMan
364end
365if eq g 3
366ktool 2
367ktx AB
368kout PPyMain
369end
370if eq g 1
371mkout PCBld
372cbuild
373end
374if eq g 5
375mkout PZBld
376zbuild
377end
378if eq g 6
379reset m
380ubuild
381ret
382end
383if eq g 4
384reset m
385ubuild
386ret
387end
388rlog PBlog
389put Brc 0 spawn
390reset m
391end
392
393fn cbuild to void
394ktool 0
395ktx AStd17
396ktx AO0
397ktx Aw
398ktx Ao
399kout PCExe
400kout PCMain
401for u ulong get Nu 0
402if exported u
403koutn UCc u Ext_c
404end
405end
406end
407
408fn zbuild to void
409kenvwk EvZg1 WZg1
410kenvwk EvZg2 WZg2
411ktool 4
412ktx AExe
413ktx AOd
414ktx ADbg
415ktx Alc
416m = mark
417bs AEmit
418bouts PZExe
419kob m sub mark m
420reset m
421kout PZMain
422end
423
424note per-unit builds: cpp/diff/<name>.cpp with g++, go/<name> with go build
425fn ubuild to void
426g = get Lg 0
427if eq g 6
428mkout PCpBld
429else
430mkout PGoBld
431end
432for u ulong get Nu 0
433if exported u
434put Ubd u ubuild1 u
435end
436end
437end
438
439fn ubuild1 u ulong to ulong
440m = mark
441rclr
442kenv
443if eq get Lg 0 6
444ktool 3
445ktx AStdx
446ktx AO0
447ktx Aw
448ktx Ao
449kouto PCpBld u
450koutn PCpD u Ext_cp
451else
452kenvwk EvGoc WGoc
453ktool 5
454ktx ABuild
455ktx Ao
456kouto PGoBld u
457ktx ADot
458a = mark
459bouts UGo
460bname u
461b = mark
462rset 6 a b
463end
464a = mark
465bouts PDiff
466bname u
467b = mark
468q = mkdirs a b
469bs PBlogU
470b = mark
471rset 2 a b
472put Rmg 0 1
473r = spawn
474reset m
475ret r
476end
477
478note the target executable (and interpreter) for unit u onto argv
479fn ktarget u ulong to void
480g = get Lg 0
481if eq g 2
482kout PRsExe
483end
484if eq g 3
485kenv
486ktool 2
487ktx AB
488kout PPyMain
489end
490if eq g 1
491kout PCExe
492end
493if eq g 5
494kout PZExe
495end
496if eq g 6
497kouto PCpBld u
498end
499if eq g 4
500kouto PGoBld u
501end
502end
503
504note run argv with stdin diff/<name>/vectors.txt and stdout diff/<name><t>
505fn runvec u ulong t view uchar * to ulong
506a = mark
507bouts PDiff
508bname u
509bs PVec
510b = mark
511bouts PDiff
512bname u
513bs t
514c = mark
515bwk WkErr
516d = mark
517rset 0 a b
518rset 2 b c
519rset 4 c d
520r = spawn
521reset a
522ret r
523end
524
525note diff/<name>/ with vectors.txt, oracle.c and driver.om
526fn dprep u ulong to bool
527m = mark
528bouts PDiff
529bname u
530e = mark
531q = mkdirs m e
532reset m
533genvec u
534m = mark
535bpl get Uv0 u get Uvn u
536c = mark
537bouts PDiff
538bname u
539bs PVec
540p = mark
541w = wfile m c c p
542reset m
543genoracle u
544ret genomdrv u
545end
546
547note the original C leg; on success the oracle output is kept in the pool (Uo0/Uon)
548fn leg1 u ulong to ulong
549m = mark
550rclr
551kenv
552ktool 0
553ktx AStd17
554ktx AO0
555ktx Aw
556ktx Ao
557a = mark
558bwk WOrc
559kob a sub mark a
560reset a
561koutn PDiff u POrc
562put Rmg 0 1
563a = mark
564bwk WkErr
565b = mark
566rset 2 a b
567r = spawn
568reset m
569if ne r 0
570ret r
571end
572rclr
573krst
574a = mark
575bwk WOrc
576kob a sub mark a
577reset a
578r = runvec u POut1
579reset m
580if ne r 0
581ret r
582end
583a = mark
584bouts PDiff
585bname u
586bs POut1
587b = mark
588q = rfile a b
589reset m
590if lt q 0
591ret 254
592end
593if ne nlines ulong q get Unv u
594ret 253
595end
596bfb 0 ulong q
597put Uo0 u psave m ulong q
598put Uon u ulong q
599reset m
600ret 0
601end
602
603fn nlines n ulong to ulong
604c = ulong 0
605for i ulong n
606if eq get Fb i 10
607c = add c 1
608end
609end
610ret c
611end
612
613note the Omega leg: driver.om through the pinned omc, then run
614fn leg2 u ulong to ulong
615m = mark
616rclr
617krst
618k = mark
619bomc
620kob k sub mark k
621reset k
622a = mark
623bouts PDiff
624bname u
625bs POmd
626b = mark
627bwk WOmd
628c = mark
629bwk WkErr
630d = mark
631rset 0 a b
632rset 2 b c
633rset 4 c d
634r = spawn
635if ne r 0
636reset m
637ret r
638end
639q = chmod Ob b sub c b 493
640rclr
641krst
642kob b sub c b
643reset m
644r = runvec u POut2
645reset m
646ret r
647end
648
649note lines of the file <out>/diff/<name><t> that differ from the oracle output
650fn mism u ulong t view uchar * to ulong
651m = mark
652bouts PDiff
653bname u
654bs t
655b = mark
656q = rfile m b
657reset m
658n = get Unv u
659if lt q 0
660ret n
661end
662ret mcount u ulong q
663end
664
665note compare Fb[0, fe) line by line with the oracle output of unit u
666fn mcount u ulong fe ulong to ulong
667put Cv 0 get Uo0 u
668oe = add get Uo0 u get Uon u
669f = ulong 0
670nb = ulong 0
671for j ulong get Unv u
672o = get Cv 0
673e = lnend o oe
674g = fend f fe
675if not fbpl f sub g f o sub e o
676nb = add nb 1
677end
678put Cv 0 add e 1
679f = add g 1
680if gt f fe
681f = fe
682end
683end
684if lt f fe
685nb = add nb 1
686end
687ret nb
688end
689
690fn fend f ulong e ulong to ulong
691i = f
692while lt i e bound 999999
693if eq get Fb i 10
694ret i
695end
696i = add i 1
697end
698ret e
699end
700
701fn fbpl a ulong an ulong b ulong bn ulong to bool
702if ne an bn
703ret false
704end
705for i ulong an
706if ne get Fb add a i get Pl add b i
707ret false
708end
709end
710ret true
711end
712
713note "<s><k> of <n> vectors (see diff/<name>/)" as the unit reason
714fn whymis u ulong s view uchar * k ulong to void
715m = mark
716bs s
717bu k
718bs RsOf
719bu get Unv u
720bs RsVec
721bname u
722bs RsVe
723ureasob u m
724end
725
726fn whyrc u ulong s view uchar * rc ulong to void
727m = mark
728bs s
729bs RsExit
730bu rc
731ureasob u m
732end
733
734note s <name> t "exit rc"
735fn whyrcn u ulong s view uchar * t view uchar * rc ulong to void
736m = mark
737bs s
738bname u
739bs t
740bs RsExit
741bu rc
742ureasob u m
743end
744
745fn legset u ulong k ulong v ulong to void
746put Ulg add mul u 3 k v
747end
748
749note one exported unit through all three legs
750fn diffunit u ulong to void
751progress u
752if not dprep u
753setst u 4 7 0
754ureason u RsPrep
755ret
756end
757r = leg1 u
758if ne r 0
759legset u 0 2
760setst u 4 8 r
761whyrcn u RsOrc RsOrc2 r
762ret
763end
764legset u 0 1
765r = leg2 u
766if ne r 0
767legset u 1 2
768setst u 4 7 r
769whyrcn u RsOmd RsOmd2 r
770ret
771end
772k = mism u POut2
773put Umo u k
774if gt k 0
775legset u 1 2
776setst u 4 7 0
777whymis u RsMo k
778ret
779end
780legset u 1 1
781legt u
782end
783
784fn legt u ulong to void
785if eq get Tok tslot 0
786setst u 5 6 0
787ureason u RsNoTl
788ret
789end
790b = get Brc 0
791if ne b 0
792legset u 2 2
793setst u 4 6 b
794whyrc u RsTbd b
795ret
796end
797b = get Ubd u
798if ne b 0
799legset u 2 2
800setst u 4 6 b
801whyrcn u RsTbdU RsTbdU2 b
802ret
803end
804rclr
805kenv
806ktarget u
807r = runvec u POut3
808if ne r 0
809legset u 2 2
810setst u 4 7 r
811whyrcn u RsTrn RsTrn2 r
812ret
813end
814k = mism u POut3
815put Umt u k
816if gt k 0
817legset u 2 2
818setst u 4 7 0
819whymis u RsMt k
820ret
821end
822legset u 2 1
823setst u 1 7 0
824end
825
826note generated tests (rust, python): cargo test / unittest over the oracle outputs; Tsr 999 = not run
827fn ttests to void
828put Tsr 0 999
829g = get Lg 0
830if eq get Tok tslot 0
831ret
832end
833if not anycase
834ret
835end
836m = mark
837rclr
838kenv
839if eq g 2
840genrstest
841ktool 1
842ktx ATest
843ktx AOff
844ktx AQuiet
845ktx AMan
846kout PRsMan
847end
848if eq g 3
849genpytest
850ktool 2
851ktx AB
852kout PPyTst
853end
854if lt g 2
855reset m
856ret
857end
858if gt g 3
859reset m
860ret
861end
862rlog PTlog
863put Tsr 0 spawn
864reset m
865end
866
867note whole differential stage: units still EXPORTED become TRANSLATED, FAIL or NOT_RUN
868fn difftest to void
869vinit
870tbuild
871for u ulong get Nu 0
872if not exported u
873continue
874end
875legset u 0 3
876legset u 1 3
877legset u 2 3
878if eq get Tok 0 0
879setst u 5 8 0
880ureason u RsNoCc
881continue
882end
883diffunit u
884end
885ttests
886end