interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / helix / ollm_factory / rlvr_factory.om

2161 lines · 35961 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: Apache-2.0
3note seed/helix/ollm_factory/rlvr_factory.om:
4note Pure seeded OM-2 Mechanical RLVR Data & Error-to-Fix Repair Factory for Omega LLM.
5note
6note Generates a rich, compositional, multi-phrasing corpus of OM-2 functions covering ALL 10
7note coding skill families (`arith, branch, loop, bits, digits, fold, select, count, scan, rewrite`)
8note across all 5 signature shapes (`u1`, `u2`, `u3`, `ar`, `aw`) PLUS verified error-to-fix repair
9note and Helix SM121/EGP2 proof records. Every emitted function has a corresponding exact ground-truth
10note assertion in `oracle` mode so BOTH Strand A and Strand B compile & execute 100% of records!
11note
12note Modes (argv[1]):
13note corpus [round] -> emits mechanically verified OM-2 training corpus (`round=1` default,
14note `round=2` shifts constants + Arboris-boosted failure-family focus)
15note oracle [round] -> emits self-checking `om2` oracle compiling & executing 100% of functions
16note repair -> emits verified error-to-fix repair + Helix SM121/EGP2 proof specialist records
17note teacher -> live native Omega TCP request to 35B `q36-serve` on `127.0.0.1:18099`
18
19text rfOm2 "om2\n"
20text rfNote "note "
21text rfFnU1 "\nfn solve a ulong to ulong\n"
22text rfFnU2 "\nfn solve a ulong b ulong to ulong\n"
23text rfFnU3 "\nfn solve a ulong b ulong c ulong to ulong\n"
24text rfFnAr "\nfn solve a view ulong 8 n ulong to ulong\n"
25text rfFnAw "\nfn solve a edit ulong 8 n ulong to void\n"
26text rfEnd "\nend\n\n"
27text rfNl "\n"
28
29text rfV0 "return "
30text rfV1 "compute "
31text rfV2 "find "
32text rfV3 "give "
33
34text rfOrFnPfx "fn f_"
35text rfOrSigU1 " a ulong to ulong\n"
36text rfOrSigU2 " a ulong b ulong to ulong\n"
37text rfOrSigU3 " a ulong b ulong c ulong to ulong\n"
38text rfOrSigAr " a view ulong 8 n ulong to ulong\n"
39text rfOrSigAw " a edit ulong 8 n ulong to void\n"
40text rfOrMainH "fn main to int\narr = new ulong 8 0\nput arr 0 3\nput arr 1 11\nput arr 2 0\nput arr 3 7\nput arr 4 19\nput arr 5 4\nput arr 6 2\nput arr 7 15\nok = ulong 0\n"
41text rfOrChkA "if ne f_"
42text rfOrChkB " "
43text rfOrChkC "\nexit "
44text rfOrChkD "\nend\nok = add ok 1\n"
45text rfOrAwRst "put arr 0 3\nput arr 1 11\nput arr 2 0\nput arr 3 7\nput arr 4 19\nput arr 5 4\nput arr 6 2\nput arr 7 15\nf_"
46text rfOrAwCall " arr 8\nif ne add get arr 0 add get arr 1 get arr 7 "
47text rfOrMainT "ret 0\nend\n"
48text rfOrArrArg "arr 8"
49
50text rfTcpReq "POST /v1/chat/completions HTTP/1.1\nHost: 127.0.0.1\nContent-Type: application/json\nContent-Length: 318\nConnection: close\n\n{\"model\":\"qwen3.6-35b-a3b\",\"max_tokens\":96,\"temperature\":0,\"messages\":[{\"role\":\"user\",\"content\":\"Omega OM-2 syntax uses prefix ops (add, sub, mul, div, rem, and, or, xor, shl, shr, eq, lt, gt) and blocks closed by end. Example:\\nfn solve a ulong to ulong\\nret add mul a 3 1\\nend\\nNow write ONLY:\\nfn solve a ulong to ulong returning a*17+5.\"}]}"
51text rfTeaOff "RLVR_TEACHER connected=0 mode=deterministic_curriculum\n"
52text rfTeaOn "RLVR_TEACHER connected=1 bytes="
53
54global rfMode ulong 1
55global rfRound ulong 1
56
57fn rfWrt s view uchar * to void
58r = write 1 s 0 len s
59end
60
61fn rfNum v ulong to void
62b = new uchar 24 0
63p = ulong 24
64x = v
65while true bound 24
66p = sub p 1
67put b p uchar add 48 rem x 10
68x = div x 10
69if eq x 0
70break
71end
72end
73r = write 1 b p sub 24 p
74end
75
76fn rfVerb v ulong to void
77m = rem v 4
78if eq m 0
79rfWrt rfV0
80end
81if eq m 1
82rfWrt rfV1
83end
84if eq m 2
85rfWrt rfV2
86end
87if eq m 3
88rfWrt rfV3
89end
90end
91
92fn rfEqArg a view uchar * al ulong b view uchar * to bool
93if ne al len b
94ret false
95end
96for i ulong al bound 64
97if ne get a i get b i
98ret false
99end
100end
101ret true
102end
103
104note ==================== FAMILY 1: U1 (arith, branch, bits, digits, loops) ====================
105text u1d_aff0 "a multiplied by "
106text u1d_aff1 " plus "
107text u1d_sq0 "a squared plus "
108text u1d_sq1 " times a plus "
109text u1d_xor0 "a XORed with "
110text u1d_clp0 "a clamped to the range ["
111text u1d_clp1 ", "
112text u1d_clp2 "]"
113text u1d_mod0 "the remainder when (a plus "
114text u1d_mod1 ") is divided by "
115text u1d_sh0 "(a shifted right by "
116text u1d_sh1 ") plus (a masked with "
117text u1d_sh2 ")"
118text u1d_div0 "1 if a is divisible by "
119text u1d_div1 " else 0"
120text u1d_cdiv0 "ceiling of (a divided by "
121text u1d_cdiv1 ")"
122text u1d_rnd0 "a rounded down to a multiple of "
123text u1d_bit0 "1 if bit "
124text u1d_bit1 " of a is set else 0"
125text u1d_tbit0 "a with bit "
126text u1d_tbit1 " toggled"
127text u1d_sbit0 "a with bit "
128text u1d_sbit1 " set"
129text u1d_dig0 "the sum of digits of a in base "
130text u1d_dig1 "the count of digits of a in base "
131text u1d_dig2 "the largest digit of a in base "
132text u1d_loop0 "the sum of squares of 0..((a mod "
133text u1d_loop1 ") - 1)"
134text u1d_loop2 "the count of 1-bits in (a XOR "
135text u1d_loop3 ")"
136text u1d_loop4 "the integer square root of (a plus "
137text u1d_loop5 ")"
138
139text u1b_aff0 "ret add mul a "
140text u1b_spc " "
141text u1b_sq0 "ret add add mul a a mul a "
142text u1b_xor0 "ret xor a "
143text u1b_clp0 "if lt a "
144text u1b_ret "\nret "
145text u1b_clp1 "\nend\nif gt a "
146text u1b_clp2 "\nend\nret a"
147text u1b_mod0 "ret rem add a "
148text u1b_sh0 "ret add shr a "
149text u1b_sh1 " and a "
150text u1b_div0 "if eq rem a "
151text u1b_div1 " 0\nret 1\nend\nret 0"
152text u1b_cdiv0 "ret div add a "
153text u1b_rnd0 "ret sub a rem a "
154text u1b_bit0 "ret and shr a "
155text u1b_bit1 " 1"
156text u1b_tbit0 "ret xor a shl ulong 1 "
157text u1b_sbit0 "ret or a shl ulong 1 "
158text u1b_digs0 "x = a\ns = ulong 0\nwhile gt x 0 bound 64\ns = add s rem x "
159text u1b_digs1 "\nx = div x "
160text u1b_digs2 "\nend\nret s"
161text u1b_digc0 "if eq a 0\nret 1\nend\nx = a\nc = ulong 0\nwhile gt x 0 bound 64\nc = add c 1\nx = div x "
162text u1b_digc1 "\nend\nret c"
163text u1b_digm0 "x = a\nm = ulong 0\nwhile gt x 0 bound 64\nd = rem x "
164text u1b_digm1 "\nif gt d m\nm = d\nend\nx = div x "
165text u1b_digm2 "\nend\nret m"
166text u1b_lsq0 "k = rem a "
167text u1b_lsq1 "\ns = ulong 0\nfor i ulong k bound 64\ns = add s mul i i\nend\nret s"
168text u1b_pop0 "x = xor a "
169text u1b_pop1 "\nc = ulong 0\nwhile gt x 0 bound 64\nc = add c and x 1\nx = shr x 1\nend\nret c"
170text u1b_isq0 "t = add a "
171text u1b_isq1 "\nr = ulong 0\nwhile le mul add r 1 add r 1 t bound 1024\nr = add r 1\nend\nret r"
172
173fn rfEmitU1All isMain bool to void
174id = ulong 1
175ro = mul sub get rfRound 0 1 2
176note 1a. 24 affine transforms a*k + c
177for ki ulong 6
178k = add add 7 mul ki 4 ro
179for ci ulong 4
180c = add add 5 mul ci 6 ro
181if not isMain
182if eq get rfMode 0 0
183rfWrt rfNote
184rfVerb id
185rfWrt u1d_aff0
186rfNum k
187rfWrt u1d_aff1
188rfNum c
189rfWrt rfFnU1
190else
191rfWrt rfOrFnPfx
192rfNum id
193rfWrt rfOrSigU1
194end
195rfWrt u1b_aff0
196rfNum k
197rfWrt u1b_spc
198rfNum c
199rfWrt rfEnd
200else
201exp = add mul ulong 37 k c
202rfWrt rfOrChkA
203rfNum id
204rfWrt rfOrChkB
205rfNum 37
206rfWrt rfOrChkB
207rfNum exp
208rfWrt rfOrChkC
209rfNum add 10 rem id 80
210rfWrt rfOrChkD
211end
212id = add id 1
213end
214end
215
216note 1b. 12 quadratics: a*a + k*a + c
217for i ulong 12
218k = add add 3 mul i 2 ro
219c = add add 7 mul i 3 ro
220if not isMain
221if eq get rfMode 0 0
222rfWrt rfNote
223rfVerb id
224rfWrt u1d_sq0
225rfNum k
226rfWrt u1d_sq1
227rfNum c
228rfWrt rfFnU1
229else
230rfWrt rfOrFnPfx
231rfNum id
232rfWrt rfOrSigU1
233end
234rfWrt u1b_sq0
235rfNum k
236rfWrt u1b_spc
237rfNum c
238rfWrt rfEnd
239else
240exp = add add mul ulong 37 37 mul ulong 37 k c
241rfWrt rfOrChkA
242rfNum id
243rfWrt rfOrChkB
244rfNum 37
245rfWrt rfOrChkB
246rfNum exp
247rfWrt rfOrChkC
248rfNum add 10 rem id 80
249rfWrt rfOrChkD
250end
251id = add id 1
252end
253
254note 1c. 12 XOR masks
255for mi ulong 12
256msk = add add 85 mul mi 37 mul ro 11
257if not isMain
258if eq get rfMode 0 0
259rfWrt rfNote
260rfVerb id
261rfWrt u1d_xor0
262rfNum msk
263rfWrt rfFnU1
264else
265rfWrt rfOrFnPfx
266rfNum id
267rfWrt rfOrSigU1
268end
269rfWrt u1b_xor0
270rfNum msk
271rfWrt rfEnd
272else
273exp = xor ulong 37 msk
274rfWrt rfOrChkA
275rfNum id
276rfWrt rfOrChkB
277rfNum 37
278rfWrt rfOrChkB
279rfNum exp
280rfWrt rfOrChkC
281rfNum add 10 rem id 80
282rfWrt rfOrChkD
283end
284id = add id 1
285end
286
287note 1d. 16 range clamps [lo, hi]
288for ri ulong 16
289lo = add add 13 mul ri 7 ro
290hi = add lo add 41 mul ri 11
291if not isMain
292if eq get rfMode 0 0
293rfWrt rfNote
294rfVerb id
295rfWrt u1d_clp0
296rfNum lo
297rfWrt u1d_clp1
298rfNum hi
299rfWrt u1d_clp2
300rfWrt rfFnU1
301else
302rfWrt rfOrFnPfx
303rfNum id
304rfWrt rfOrSigU1
305end
306rfWrt u1b_clp0
307rfNum lo
308rfWrt u1b_ret
309rfNum lo
310rfWrt u1b_clp1
311rfNum hi
312rfWrt u1b_ret
313rfNum hi
314rfWrt u1b_clp2
315rfWrt rfEnd
316else
317exp = ulong 37
318if lt exp lo
319exp = lo
320end
321if gt exp hi
322exp = hi
323end
324rfWrt rfOrChkA
325rfNum id
326rfWrt rfOrChkB
327rfNum 37
328rfWrt rfOrChkB
329rfNum exp
330rfWrt rfOrChkC
331rfNum add 10 rem id 80
332rfWrt rfOrChkD
333end
334id = add id 1
335end
336
337note 1e. 12 modular offsets: (a + off) % md
338for mi ulong 12
339off = add add 17 mul mi 5 ro
340md = add add 19 mul mi 6 ro
341if not isMain
342if eq get rfMode 0 0
343rfWrt rfNote
344rfVerb id
345rfWrt u1d_mod0
346rfNum off
347rfWrt u1d_mod1
348rfNum md
349rfWrt rfFnU1
350else
351rfWrt rfOrFnPfx
352rfNum id
353rfWrt rfOrSigU1
354end
355rfWrt u1b_mod0
356rfNum off
357rfWrt u1b_spc
358rfNum md
359rfWrt rfEnd
360else
361exp = rem add ulong 37 off md
362rfWrt rfOrChkA
363rfNum id
364rfWrt rfOrChkB
365rfNum 37
366rfWrt rfOrChkB
367rfNum exp
368rfWrt rfOrChkC
369rfNum add 10 rem id 80
370rfWrt rfOrChkD
371end
372id = add id 1
373end
374
375note 1f. 12 shift+mask splits
376for si ulong 12
377sh = add 2 rem si 5
378mk = add add 31 mul si 17 ro
379if not isMain
380if eq get rfMode 0 0
381rfWrt rfNote
382rfVerb id
383rfWrt u1d_sh0
384rfNum sh
385rfWrt u1d_sh1
386rfNum mk
387rfWrt u1d_sh2
388rfWrt rfFnU1
389else
390rfWrt rfOrFnPfx
391rfNum id
392rfWrt rfOrSigU1
393end
394rfWrt u1b_sh0
395rfNum sh
396rfWrt u1b_sh1
397rfNum mk
398rfWrt rfEnd
399else
400exp = add shr ulong 37 sh and ulong 37 mk
401rfWrt rfOrChkA
402rfNum id
403rfWrt rfOrChkB
404rfNum 37
405rfWrt rfOrChkB
406rfNum exp
407rfWrt rfOrChkC
408rfNum add 10 rem id 80
409rfWrt rfOrChkD
410end
411id = add id 1
412end
413
414note 1g. 12 divisibility checks (a % d == 0) + 12 ceil-div + 12 round-down to multiple of d
415for i ulong 12
416d = add add 7 mul i 4 ro
417if not isMain
418if eq get rfMode 0 0
419rfWrt rfNote
420rfVerb id
421rfWrt u1d_div0
422rfNum d
423rfWrt u1d_div1
424rfWrt rfFnU1
425else
426rfWrt rfOrFnPfx
427rfNum id
428rfWrt rfOrSigU1
429end
430rfWrt u1b_div0
431rfNum d
432rfWrt u1b_div1
433rfWrt rfEnd
434else
435exp = ulong 0
436if eq rem ulong 37 d 0
437exp = 1
438end
439rfWrt rfOrChkA
440rfNum id
441rfWrt rfOrChkB
442rfNum 37
443rfWrt rfOrChkB
444rfNum exp
445rfWrt rfOrChkC
446rfNum add 10 rem id 80
447rfWrt rfOrChkD
448end
449id = add id 1
450end
451
452for i ulong 12
453d = add add 5 mul i 3 ro
454if not isMain
455if eq get rfMode 0 0
456rfWrt rfNote
457rfVerb id
458rfWrt u1d_cdiv0
459rfNum d
460rfWrt u1d_cdiv1
461rfWrt rfFnU1
462else
463rfWrt rfOrFnPfx
464rfNum id
465rfWrt rfOrSigU1
466end
467rfWrt u1b_cdiv0
468rfNum sub d 1
469rfWrt u1b_spc
470rfNum d
471rfWrt rfEnd
472else
473exp = div add ulong 37 sub d 1 d
474rfWrt rfOrChkA
475rfNum id
476rfWrt rfOrChkB
477rfNum 37
478rfWrt rfOrChkB
479rfNum exp
480rfWrt rfOrChkC
481rfNum add 10 rem id 80
482rfWrt rfOrChkD
483end
484id = add id 1
485end
486
487for i ulong 12
488d = add add 6 mul i 5 ro
489if not isMain
490if eq get rfMode 0 0
491rfWrt rfNote
492rfVerb id
493rfWrt u1d_rnd0
494rfNum d
495rfWrt rfFnU1
496else
497rfWrt rfOrFnPfx
498rfNum id
499rfWrt rfOrSigU1
500end
501rfWrt u1b_rnd0
502rfNum d
503rfWrt rfEnd
504else
505exp = sub ulong 37 rem ulong 37 d
506rfWrt rfOrChkA
507rfNum id
508rfWrt rfOrChkB
509rfNum 37
510rfWrt rfOrChkB
511rfNum exp
512rfWrt rfOrChkC
513rfNum add 10 rem id 80
514rfWrt rfOrChkD
515end
516id = add id 1
517end
518
519note 1h. 24 bit test / toggle / set ops (bits 2..9)
520for i ulong 8
521bt = add 2 i
522if not isMain
523if eq get rfMode 0 0
524rfWrt rfNote
525rfVerb id
526rfWrt u1d_bit0
527rfNum bt
528rfWrt u1d_bit1
529rfWrt rfFnU1
530else
531rfWrt rfOrFnPfx
532rfNum id
533rfWrt rfOrSigU1
534end
535rfWrt u1b_bit0
536rfNum bt
537rfWrt u1b_bit1
538rfWrt rfEnd
539else
540exp = and shr ulong 37 bt 1
541rfWrt rfOrChkA
542rfNum id
543rfWrt rfOrChkB
544rfNum 37
545rfWrt rfOrChkB
546rfNum exp
547rfWrt rfOrChkC
548rfNum add 10 rem id 80
549rfWrt rfOrChkD
550end
551id = add id 1
552end
553
554for i ulong 8
555bt = add 2 i
556if not isMain
557if eq get rfMode 0 0
558rfWrt rfNote
559rfVerb id
560rfWrt u1d_tbit0
561rfNum bt
562rfWrt u1d_tbit1
563rfWrt rfFnU1
564else
565rfWrt rfOrFnPfx
566rfNum id
567rfWrt rfOrSigU1
568end
569rfWrt u1b_tbit0
570rfNum bt
571rfWrt rfEnd
572else
573exp = xor ulong 37 shl ulong 1 bt
574rfWrt rfOrChkA
575rfNum id
576rfWrt rfOrChkB
577rfNum 37
578rfWrt rfOrChkB
579rfNum exp
580rfWrt rfOrChkC
581rfNum add 10 rem id 80
582rfWrt rfOrChkD
583end
584id = add id 1
585end
586
587for i ulong 8
588bt = add 2 i
589if not isMain
590if eq get rfMode 0 0
591rfWrt rfNote
592rfVerb id
593rfWrt u1d_sbit0
594rfNum bt
595rfWrt u1d_sbit1
596rfWrt rfFnU1
597else
598rfWrt rfOrFnPfx
599rfNum id
600rfWrt rfOrSigU1
601end
602rfWrt u1b_sbit0
603rfNum bt
604rfWrt rfEnd
605else
606exp = or ulong 37 shl ulong 1 bt
607rfWrt rfOrChkA
608rfNum id
609rfWrt rfOrChkB
610rfNum 37
611rfWrt rfOrChkB
612rfNum exp
613rfWrt rfOrChkC
614rfNum add 10 rem id 80
615rfWrt rfOrChkD
616end
617id = add id 1
618end
619
620note 1i. 24 base-B digit sum / count / max (bases 3,4,5,6,7,8,9,12 -- deliberately non-10 so zero overlap with bench!)
621for i ulong 8
622bs = add 3 i
623if eq bs 10
624bs = 12
625end
626if not isMain
627if eq get rfMode 0 0
628rfWrt rfNote
629rfVerb id
630rfWrt u1d_dig0
631rfNum bs
632rfWrt rfFnU1
633else
634rfWrt rfOrFnPfx
635rfNum id
636rfWrt rfOrSigU1
637end
638rfWrt u1b_digs0
639rfNum bs
640rfWrt u1b_digs1
641rfNum bs
642rfWrt u1b_digs2
643rfWrt rfEnd
644else
645x = ulong 37
646s = ulong 0
647while gt x 0 bound 64
648s = add s rem x bs
649x = div x bs
650end
651rfWrt rfOrChkA
652rfNum id
653rfWrt rfOrChkB
654rfNum 37
655rfWrt rfOrChkB
656rfNum s
657rfWrt rfOrChkC
658rfNum add 10 rem id 80
659rfWrt rfOrChkD
660end
661id = add id 1
662end
663
664for i ulong 8
665bs = add 3 i
666if eq bs 10
667bs = 12
668end
669if not isMain
670if eq get rfMode 0 0
671rfWrt rfNote
672rfVerb id
673rfWrt u1d_dig1
674rfNum bs
675rfWrt rfFnU1
676else
677rfWrt rfOrFnPfx
678rfNum id
679rfWrt rfOrSigU1
680end
681rfWrt u1b_digc0
682rfNum bs
683rfWrt u1b_digc1
684rfWrt rfEnd
685else
686x = ulong 37
687c = ulong 0
688while gt x 0 bound 64
689c = add c 1
690x = div x bs
691end
692rfWrt rfOrChkA
693rfNum id
694rfWrt rfOrChkB
695rfNum 37
696rfWrt rfOrChkB
697rfNum c
698rfWrt rfOrChkC
699rfNum add 10 rem id 80
700rfWrt rfOrChkD
701end
702id = add id 1
703end
704
705for i ulong 8
706bs = add 3 i
707if eq bs 10
708bs = 12
709end
710if not isMain
711if eq get rfMode 0 0
712rfWrt rfNote
713rfVerb id
714rfWrt u1d_dig2
715rfNum bs
716rfWrt rfFnU1
717else
718rfWrt rfOrFnPfx
719rfNum id
720rfWrt rfOrSigU1
721end
722rfWrt u1b_digm0
723rfNum bs
724rfWrt u1b_digm1
725rfNum bs
726rfWrt u1b_digm2
727rfWrt rfEnd
728else
729x = ulong 37
730m = ulong 0
731while gt x 0 bound 64
732dg = rem x bs
733if gt dg m
734m = dg
735end
736x = div x bs
737end
738rfWrt rfOrChkA
739rfNum id
740rfWrt rfOrChkB
741rfNum 37
742rfWrt rfOrChkB
743rfNum m
744rfWrt rfOrChkC
745rfNum add 10 rem id 80
746rfWrt rfOrChkD
747end
748id = add id 1
749end
750
751note 1j. 24 iterative loops: sum-of-squares, popcount(a^k), isqrt(a+k)
752for i ulong 8
753md = add add 7 mul i 3 ro
754if not isMain
755if eq get rfMode 0 0
756rfWrt rfNote
757rfVerb id
758rfWrt u1d_loop0
759rfNum md
760rfWrt u1d_loop1
761rfWrt rfFnU1
762else
763rfWrt rfOrFnPfx
764rfNum id
765rfWrt rfOrSigU1
766end
767rfWrt u1b_lsq0
768rfNum md
769rfWrt u1b_lsq1
770rfWrt rfEnd
771else
772k = rem ulong 37 md
773s = ulong 0
774for j ulong k bound 64
775s = add s mul j j
776end
777rfWrt rfOrChkA
778rfNum id
779rfWrt rfOrChkB
780rfNum 37
781rfWrt rfOrChkB
782rfNum s
783rfWrt rfOrChkC
784rfNum add 10 rem id 80
785rfWrt rfOrChkD
786end
787id = add id 1
788end
789
790for i ulong 8
791mk = add add 45 mul i 23 ro
792if not isMain
793if eq get rfMode 0 0
794rfWrt rfNote
795rfVerb id
796rfWrt u1d_loop2
797rfNum mk
798rfWrt u1d_loop3
799rfWrt rfFnU1
800else
801rfWrt rfOrFnPfx
802rfNum id
803rfWrt rfOrSigU1
804end
805rfWrt u1b_pop0
806rfNum mk
807rfWrt u1b_pop1
808rfWrt rfEnd
809else
810x = xor ulong 37 mk
811c = ulong 0
812while gt x 0 bound 64
813c = add c and x 1
814x = shr x 1
815end
816rfWrt rfOrChkA
817rfNum id
818rfWrt rfOrChkB
819rfNum 37
820rfWrt rfOrChkB
821rfNum c
822rfWrt rfOrChkC
823rfNum add 10 rem id 80
824rfWrt rfOrChkD
825end
826id = add id 1
827end
828
829for i ulong 8
830off = add add 11 mul i 17 ro
831if not isMain
832if eq get rfMode 0 0
833rfWrt rfNote
834rfVerb id
835rfWrt u1d_loop4
836rfNum off
837rfWrt u1d_loop5
838rfWrt rfFnU1
839else
840rfWrt rfOrFnPfx
841rfNum id
842rfWrt rfOrSigU1
843end
844rfWrt u1b_isq0
845rfNum off
846rfWrt u1b_isq1
847rfWrt rfEnd
848else
849t = add ulong 37 off
850r = ulong 0
851while le mul add r 1 add r 1 t bound 1024
852r = add r 1
853end
854rfWrt rfOrChkA
855rfNum id
856rfWrt rfOrChkB
857rfNum 37
858rfWrt rfOrChkB
859rfNum r
860rfWrt rfOrChkC
861rfNum add 10 rem id 80
862rfWrt rfOrChkD
863end
864id = add id 1
865end
866end
867
868note ==================== FAMILY 2: U2 (a ulong b ulong -> ulong) ====================
869text u2d0 " times a plus "
870text u2d1 " times b"
871text u2d2 "the larger of (a plus "
872text u2d3 ") and (b multiplied by "
873text u2d4 ")"
874text u2d5 "the smaller of (a multiplied by "
875text u2d6 ") and (b plus "
876text u2d7 "(a XOR b) masked with "
877text u2d8 "the sum of integers from a to a plus (b mod "
878text u2d9 ") exclusive"
879text u2d10 "the saturating difference max(0, a minus b minus "
880text u2d11 "the GCD of (a plus "
881text u2d12 ") and (b plus "
882text u2d13 "the Hamming distance between a and (b XOR "
883text u2b0 "ret add mul a "
884text u2b1 " mul b "
885text u2b2 "x = add a "
886text u2b3 "\ny = mul b "
887text u2b4 "\nif gt x y\nret x\nend\nret y"
888text u2b5 "x = mul a "
889text u2b6 "\ny = add b "
890text u2b7 "\nif lt x y\nret x\nend\nret y"
891text u2b8 "ret and xor a b "
892text u2b9 "k = rem b "
893text u2b10 "\ns = ulong 0\nfor i ulong k bound 64\ns = add s add a i\nend\nret s"
894text u2b11 "t = add b "
895text u2b12 "\nif gt a t\nret sub a t\nend\nret 0"
896text u2b13 "x = add a "
897text u2b14 "\ny = add b "
898text u2b15 "\nwhile gt y 0 bound 128\nt = rem x y\nx = y\ny = t\nend\nret x"
899text u2b16 "x = xor a xor b "
900text u2b17 "\nc = ulong 0\nwhile gt x 0 bound 64\nc = add c and x 1\nx = shr x 1\nend\nret c"
901
902fn rfEmitU2All isMain bool to void
903id = ulong 301
904ro = mul sub get rfRound 0 1 2
905for i ulong 6
906wa = add add 3 mul i 2 ro
907for j ulong 4
908wb = add add 5 mul j 3 ro
909if not isMain
910if eq get rfMode 0 0
911rfWrt rfNote
912rfVerb id
913rfNum wa
914rfWrt u2d0
915rfNum wb
916rfWrt u2d1
917rfWrt rfFnU2
918else
919rfWrt rfOrFnPfx
920rfNum id
921rfWrt rfOrSigU2
922end
923rfWrt u2b0
924rfNum wa
925rfWrt u2b1
926rfNum wb
927rfWrt rfEnd
928else
929exp = add mul ulong 19 wa mul ulong 11 wb
930rfWrt rfOrChkA
931rfNum id
932rfWrt rfOrChkB
933rfNum 19
934rfWrt rfOrChkB
935rfNum 11
936rfWrt rfOrChkB
937rfNum exp
938rfWrt rfOrChkC
939rfNum add 10 rem id 80
940rfWrt rfOrChkD
941end
942id = add id 1
943end
944end
945
946for i ulong 12
947off = add add 11 mul i 5 ro
948ml = add 3 rem i 5
949if not isMain
950if eq get rfMode 0 0
951rfWrt rfNote
952rfVerb id
953rfWrt u2d2
954rfNum off
955rfWrt u2d3
956rfNum ml
957rfWrt u2d4
958rfWrt rfFnU2
959else
960rfWrt rfOrFnPfx
961rfNum id
962rfWrt rfOrSigU2
963end
964rfWrt u2b2
965rfNum off
966rfWrt u2b3
967rfNum ml
968rfWrt u2b4
969rfWrt rfEnd
970else
971x = add ulong 19 off
972y = mul ulong 11 ml
973exp = y
974if gt x y
975exp = x
976end
977rfWrt rfOrChkA
978rfNum id
979rfWrt rfOrChkB
980rfNum 19
981rfWrt rfOrChkB
982rfNum 11
983rfWrt rfOrChkB
984rfNum exp
985rfWrt rfOrChkC
986rfNum add 10 rem id 80
987rfWrt rfOrChkD
988end
989id = add id 1
990end
991
992for i ulong 12
993ml = add 2 rem i 5
994off = add add 15 mul i 4 ro
995if not isMain
996if eq get rfMode 0 0
997rfWrt rfNote
998rfVerb id
999rfWrt u2d5
1000rfNum ml
1001rfWrt u2d6
1002rfNum off
1003rfWrt u2d4
1004rfWrt rfFnU2
1005else
1006rfWrt rfOrFnPfx
1007rfNum id
1008rfWrt rfOrSigU2
1009end
1010rfWrt u2b5
1011rfNum ml
1012rfWrt u2b6
1013rfNum off
1014rfWrt u2b7
1015rfWrt rfEnd
1016else
1017x = mul ulong 19 ml
1018y = add ulong 11 off
1019exp = y
1020if lt x y
1021exp = x
1022end
1023rfWrt rfOrChkA
1024rfNum id
1025rfWrt rfOrChkB
1026rfNum 19
1027rfWrt rfOrChkB
1028rfNum 11
1029rfWrt rfOrChkB
1030rfNum exp
1031rfWrt rfOrChkC
1032rfNum add 10 rem id 80
1033rfWrt rfOrChkD
1034end
1035id = add id 1
1036end
1037
1038for i ulong 12
1039msk = add add 127 mul i 29 ro
1040if not isMain
1041if eq get rfMode 0 0
1042rfWrt rfNote
1043rfVerb id
1044rfWrt u2d7
1045rfNum msk
1046rfWrt rfFnU2
1047else
1048rfWrt rfOrFnPfx
1049rfNum id
1050rfWrt rfOrSigU2
1051end
1052rfWrt u2b8
1053rfNum msk
1054rfWrt rfEnd
1055else
1056exp = and xor ulong 19 11 msk
1057rfWrt rfOrChkA
1058rfNum id
1059rfWrt rfOrChkB
1060rfNum 19
1061rfWrt rfOrChkB
1062rfNum 11
1063rfWrt rfOrChkB
1064rfNum exp
1065rfWrt rfOrChkC
1066rfNum add 10 rem id 80
1067rfWrt rfOrChkD
1068end
1069id = add id 1
1070end
1071
1072for i ulong 12
1073cap = add add 7 mul i 3 ro
1074if not isMain
1075if eq get rfMode 0 0
1076rfWrt rfNote
1077rfVerb id
1078rfWrt u2d8
1079rfNum cap
1080rfWrt u2d9
1081rfWrt rfFnU2
1082else
1083rfWrt rfOrFnPfx
1084rfNum id
1085rfWrt rfOrSigU2
1086end
1087rfWrt u2b9
1088rfNum cap
1089rfWrt u2b10
1090rfWrt rfEnd
1091else
1092k = rem ulong 11 cap
1093s = ulong 0
1094for t ulong k bound 64
1095s = add s add ulong 19 t
1096end
1097rfWrt rfOrChkA
1098rfNum id
1099rfWrt rfOrChkB
1100rfNum 19
1101rfWrt rfOrChkB
1102rfNum 11
1103rfWrt rfOrChkB
1104rfNum s
1105rfWrt rfOrChkC
1106rfNum add 10 rem id 80
1107rfWrt rfOrChkD
1108end
1109id = add id 1
1110end
1111
1112for i ulong 12
1113off = add add 2 mul i 3 ro
1114if not isMain
1115if eq get rfMode 0 0
1116rfWrt rfNote
1117rfVerb id
1118rfWrt u2d10
1119rfNum off
1120rfWrt u2d4
1121rfWrt rfFnU2
1122else
1123rfWrt rfOrFnPfx
1124rfNum id
1125rfWrt rfOrSigU2
1126end
1127rfWrt u2b11
1128rfNum off
1129rfWrt u2b12
1130rfWrt rfEnd
1131else
1132t = add ulong 11 off
1133exp = ulong 0
1134if gt ulong 19 t
1135exp = sub ulong 19 t
1136end
1137rfWrt rfOrChkA
1138rfNum id
1139rfWrt rfOrChkB
1140rfNum 19
1141rfWrt rfOrChkB
1142rfNum 11
1143rfWrt rfOrChkB
1144rfNum exp
1145rfWrt rfOrChkC
1146rfNum add 10 rem id 80
1147rfWrt rfOrChkD
1148end
1149id = add id 1
1150end
1151
1152for i ulong 12
1153ca = add add 3 mul i 4 ro
1154cb = add add 5 mul i 3 ro
1155if not isMain
1156if eq get rfMode 0 0
1157rfWrt rfNote
1158rfVerb id
1159rfWrt u2d11
1160rfNum ca
1161rfWrt u2d12
1162rfNum cb
1163rfWrt u2d4
1164rfWrt rfFnU2
1165else
1166rfWrt rfOrFnPfx
1167rfNum id
1168rfWrt rfOrSigU2
1169end
1170rfWrt u2b13
1171rfNum ca
1172rfWrt u2b14
1173rfNum cb
1174rfWrt u2b15
1175rfWrt rfEnd
1176else
1177x = add ulong 19 ca
1178y = add ulong 11 cb
1179while gt y 0 bound 128
1180t = rem x y
1181x = y
1182y = t
1183end
1184rfWrt rfOrChkA
1185rfNum id
1186rfWrt rfOrChkB
1187rfNum 19
1188rfWrt rfOrChkB
1189rfNum 11
1190rfWrt rfOrChkB
1191rfNum x
1192rfWrt rfOrChkC
1193rfNum add 10 rem id 80
1194rfWrt rfOrChkD
1195end
1196id = add id 1
1197end
1198
1199for i ulong 12
1200mk = add add 17 mul i 19 ro
1201if not isMain
1202if eq get rfMode 0 0
1203rfWrt rfNote
1204rfVerb id
1205rfWrt u2d13
1206rfNum mk
1207rfWrt u2d4
1208rfWrt rfFnU2
1209else
1210rfWrt rfOrFnPfx
1211rfNum id
1212rfWrt rfOrSigU2
1213end
1214rfWrt u2b16
1215rfNum mk
1216rfWrt u2b17
1217rfWrt rfEnd
1218else
1219x = xor ulong 19 xor ulong 11 mk
1220c = ulong 0
1221while gt x 0 bound 64
1222c = add c and x 1
1223x = shr x 1
1224end
1225rfWrt rfOrChkA
1226rfNum id
1227rfWrt rfOrChkB
1228rfNum 19
1229rfWrt rfOrChkB
1230rfNum 11
1231rfWrt rfOrChkB
1232rfNum c
1233rfWrt rfOrChkC
1234rfNum add 10 rem id 80
1235rfWrt rfOrChkD
1236end
1237id = add id 1
1238end
1239end
1240
1241note ==================== FAMILY 3: U3 (a ulong b ulong c ulong -> ulong) ====================
1242text u3d0 "a multiplied by b plus c plus "
1243text u3d1 "the smaller of (a plus b) and (c plus "
1244text u3d2 ")"
1245text u3d3 "(a XOR b XOR c) plus "
1246text u3d4 "the median of (a plus "
1247text u3d5 "), b, and c"
1248text u3d6 "a clamped between b and add b add c "
1249text u3b0 "ret add add mul a b c "
1250text u3b1 "x = add a b\ny = add c "
1251text u3b2 "\nif lt x y\nret x\nend\nret y"
1252text u3b3 "ret add xor xor a b c "
1253text u3b4 "x = add a "
1254text u3b5 "\ny = b\nz = c\nif gt x y\nt = x\nx = y\ny = t\nend\nif gt y z\nt = y\ny = z\nz = t\nend\nif gt x y\nt = x\nx = y\ny = t\nend\nret y"
1255text u3b6 "hi = add b add c "
1256text u3b7 "\nif lt a b\nret b\nend\nif gt a hi\nret hi\nend\nret a"
1257
1258fn rfEmitU3All isMain bool to void
1259id = ulong 501
1260ro = mul sub get rfRound 0 1 2
1261for i ulong 12
1262k = add add 7 mul i 6 ro
1263if not isMain
1264if eq get rfMode 0 0
1265rfWrt rfNote
1266rfVerb id
1267rfWrt u3d0
1268rfNum k
1269rfWrt rfFnU3
1270else
1271rfWrt rfOrFnPfx
1272rfNum id
1273rfWrt rfOrSigU3
1274end
1275rfWrt u3b0
1276rfNum k
1277rfWrt rfEnd
1278else
1279exp = add add mul ulong 5 9 13 k
1280rfWrt rfOrChkA
1281rfNum id
1282rfWrt rfOrChkB
1283rfNum 5
1284rfWrt rfOrChkB
1285rfNum 9
1286rfWrt rfOrChkB
1287rfNum 13
1288rfWrt rfOrChkB
1289rfNum exp
1290rfWrt rfOrChkC
1291rfNum add 10 rem id 80
1292rfWrt rfOrChkD
1293end
1294id = add id 1
1295end
1296
1297for i ulong 12
1298k = add add 9 mul i 4 ro
1299if not isMain
1300if eq get rfMode 0 0
1301rfWrt rfNote
1302rfVerb id
1303rfWrt u3d1
1304rfNum k
1305rfWrt u3d2
1306rfWrt rfFnU3
1307else
1308rfWrt rfOrFnPfx
1309rfNum id
1310rfWrt rfOrSigU3
1311end
1312rfWrt u3b1
1313rfNum k
1314rfWrt u3b2
1315rfWrt rfEnd
1316else
1317x = add ulong 5 9
1318y = add ulong 13 k
1319exp = y
1320if lt x y
1321exp = x
1322end
1323rfWrt rfOrChkA
1324rfNum id
1325rfWrt rfOrChkB
1326rfNum 5
1327rfWrt rfOrChkB
1328rfNum 9
1329rfWrt rfOrChkB
1330rfNum 13
1331rfWrt rfOrChkB
1332rfNum exp
1333rfWrt rfOrChkC
1334rfNum add 10 rem id 80
1335rfWrt rfOrChkD
1336end
1337id = add id 1
1338end
1339
1340for i ulong 12
1341k = add add 11 mul i 5 ro
1342if not isMain
1343if eq get rfMode 0 0
1344rfWrt rfNote
1345rfVerb id
1346rfWrt u3d3
1347rfNum k
1348rfWrt rfFnU3
1349else
1350rfWrt rfOrFnPfx
1351rfNum id
1352rfWrt rfOrSigU3
1353end
1354rfWrt u3b3
1355rfNum k
1356rfWrt rfEnd
1357else
1358exp = add xor xor ulong 5 9 13 k
1359rfWrt rfOrChkA
1360rfNum id
1361rfWrt rfOrChkB
1362rfNum 5
1363rfWrt rfOrChkB
1364rfNum 9
1365rfWrt rfOrChkB
1366rfNum 13
1367rfWrt rfOrChkB
1368rfNum exp
1369rfWrt rfOrChkC
1370rfNum add 10 rem id 80
1371rfWrt rfOrChkD
1372end
1373id = add id 1
1374end
1375
1376for i ulong 12
1377k = add add 3 mul i 2 ro
1378if not isMain
1379if eq get rfMode 0 0
1380rfWrt rfNote
1381rfVerb id
1382rfWrt u3d4
1383rfNum k
1384rfWrt u3d5
1385rfWrt rfFnU3
1386else
1387rfWrt rfOrFnPfx
1388rfNum id
1389rfWrt rfOrSigU3
1390end
1391rfWrt u3b4
1392rfNum k
1393rfWrt u3b5
1394rfWrt rfEnd
1395else
1396x = add ulong 5 k
1397y = ulong 9
1398z = ulong 13
1399if gt x y
1400t = x
1401x = y
1402y = t
1403end
1404if gt y z
1405t = y
1406y = z
1407z = t
1408end
1409if gt x y
1410t = x
1411x = y
1412y = t
1413end
1414rfWrt rfOrChkA
1415rfNum id
1416rfWrt rfOrChkB
1417rfNum 5
1418rfWrt rfOrChkB
1419rfNum 9
1420rfWrt rfOrChkB
1421rfNum 13
1422rfWrt rfOrChkB
1423rfNum y
1424rfWrt rfOrChkC
1425rfNum add 10 rem id 80
1426rfWrt rfOrChkD
1427end
1428id = add id 1
1429end
1430
1431for i ulong 12
1432k = add add 4 mul i 3 ro
1433if not isMain
1434if eq get rfMode 0 0
1435rfWrt rfNote
1436rfVerb id
1437rfWrt u3d6
1438rfNum k
1439rfWrt rfFnU3
1440else
1441rfWrt rfOrFnPfx
1442rfNum id
1443rfWrt rfOrSigU3
1444end
1445rfWrt u3b6
1446rfNum k
1447rfWrt u3b7
1448rfWrt rfEnd
1449else
1450hi = add ulong 9 add ulong 13 k
1451exp = ulong 5
1452if lt exp 9
1453exp = 9
1454end
1455if gt exp hi
1456exp = hi
1457end
1458rfWrt rfOrChkA
1459rfNum id
1460rfWrt rfOrChkB
1461rfNum 5
1462rfWrt rfOrChkB
1463rfNum 9
1464rfWrt rfOrChkB
1465rfNum 13
1466rfWrt rfOrChkB
1467rfNum exp
1468rfWrt rfOrChkC
1469rfNum add 10 rem id 80
1470rfWrt rfOrChkD
1471end
1472id = add id 1
1473end
1474end
1475
1476note ==================== FAMILY 4: AR (fold, count, select, scan) ====================
1477text ard0 "the count of elements in a[0..n) strictly greater than "
1478text ard1 "the sum of elements in a[0..n) that are at least "
1479text ard2 "the XOR of (a[i] plus "
1480text ard3 ") for i in 0..n"
1481text ard4 "the index of the first element in a[0..n) greater than "
1482text ard5 ", or n if none"
1483text ard6 "the maximum of (a[i] XOR "
1484text ard7 ") over a[0..n)"
1485text ard8 "the weighted sum of (i + "
1486text ard9 ") * a[i] for i in 0..n"
1487text arb0 "c = ulong 0\nfor i ulong n bound 8\nif gt get a i "
1488text arb1 "\nc = add c 1\nend\nend\nret c"
1489text arb2 "s = ulong 0\nfor i ulong n bound 8\nv = get a i\nif ge v "
1490text arb3 "\ns = add s v\nend\nend\nret s"
1491text arb4 "x = ulong 0\nfor i ulong n bound 8\nx = xor x add get a i "
1492text arb5 "\nend\nret x"
1493text arb6 "for i ulong n bound 8\nif gt get a i "
1494text arb7 "\nret i\nend\nend\nret n"
1495text arb8 "m = ulong 0\nfor i ulong n bound 8\nv = xor get a i "
1496text arb9 "\nif gt v m\nm = v\nend\nend\nret m"
1497text arb10 "s = ulong 0\nfor i ulong n bound 8\ns = add s mul add i "
1498text arb11 " get a i\nend\nret s"
1499
1500fn rfArVal i ulong to ulong
1501if eq i 0
1502ret 3
1503end
1504if eq i 1
1505ret 11
1506end
1507if eq i 2
1508ret 0
1509end
1510if eq i 3
1511ret 7
1512end
1513if eq i 4
1514ret 19
1515end
1516if eq i 5
1517ret 4
1518end
1519if eq i 6
1520ret 2
1521end
1522ret 15
1523end
1524
1525fn rfEmitArAll isMain bool to void
1526id = ulong 701
1527ro = mul sub get rfRound 0 1 2
1528for i ulong 12
1529thr = add add 2 i ro
1530if not isMain
1531if eq get rfMode 0 0
1532rfWrt rfNote
1533rfVerb id
1534rfWrt ard0
1535rfNum thr
1536rfWrt rfFnAr
1537else
1538rfWrt rfOrFnPfx
1539rfNum id
1540rfWrt rfOrSigAr
1541end
1542rfWrt arb0
1543rfNum thr
1544rfWrt arb1
1545rfWrt rfEnd
1546else
1547c = ulong 0
1548for j ulong 8
1549if gt rfArVal j thr
1550c = add c 1
1551end
1552end
1553rfWrt rfOrChkA
1554rfNum id
1555rfWrt rfOrChkB
1556rfWrt rfOrArrArg
1557rfWrt rfOrChkB
1558rfNum c
1559rfWrt rfOrChkC
1560rfNum add 10 rem id 80
1561rfWrt rfOrChkD
1562end
1563id = add id 1
1564end
1565
1566for i ulong 12
1567thr = add add 3 i ro
1568if not isMain
1569if eq get rfMode 0 0
1570rfWrt rfNote
1571rfVerb id
1572rfWrt ard1
1573rfNum thr
1574rfWrt rfFnAr
1575else
1576rfWrt rfOrFnPfx
1577rfNum id
1578rfWrt rfOrSigAr
1579end
1580rfWrt arb2
1581rfNum thr
1582rfWrt arb3
1583rfWrt rfEnd
1584else
1585s = ulong 0
1586for j ulong 8
1587v = rfArVal j
1588if ge v thr
1589s = add s v
1590end
1591end
1592rfWrt rfOrChkA
1593rfNum id
1594rfWrt rfOrChkB
1595rfWrt rfOrArrArg
1596rfWrt rfOrChkB
1597rfNum s
1598rfWrt rfOrChkC
1599rfNum add 10 rem id 80
1600rfWrt rfOrChkD
1601end
1602id = add id 1
1603end
1604
1605for i ulong 12
1606off = add add 5 mul i 3 ro
1607if not isMain
1608if eq get rfMode 0 0
1609rfWrt rfNote
1610rfVerb id
1611rfWrt ard2
1612rfNum off
1613rfWrt ard3
1614rfWrt rfFnAr
1615else
1616rfWrt rfOrFnPfx
1617rfNum id
1618rfWrt rfOrSigAr
1619end
1620rfWrt arb4
1621rfNum off
1622rfWrt arb5
1623rfWrt rfEnd
1624else
1625x = ulong 0
1626for j ulong 8
1627x = xor x add rfArVal j off
1628end
1629rfWrt rfOrChkA
1630rfNum id
1631rfWrt rfOrChkB
1632rfWrt rfOrArrArg
1633rfWrt rfOrChkB
1634rfNum x
1635rfWrt rfOrChkC
1636rfNum add 10 rem id 80
1637rfWrt rfOrChkD
1638end
1639id = add id 1
1640end
1641
1642for i ulong 12
1643thr = add add 1 mul i 2 ro
1644if not isMain
1645if eq get rfMode 0 0
1646rfWrt rfNote
1647rfVerb id
1648rfWrt ard4
1649rfNum thr
1650rfWrt ard5
1651rfWrt rfFnAr
1652else
1653rfWrt rfOrFnPfx
1654rfNum id
1655rfWrt rfOrSigAr
1656end
1657rfWrt arb6
1658rfNum thr
1659rfWrt arb7
1660rfWrt rfEnd
1661else
1662res = ulong 8
1663for j ulong 8
1664if gt rfArVal j thr
1665res = j
1666break
1667end
1668end
1669rfWrt rfOrChkA
1670rfNum id
1671rfWrt rfOrChkB
1672rfWrt rfOrArrArg
1673rfWrt rfOrChkB
1674rfNum res
1675rfWrt rfOrChkC
1676rfNum add 10 rem id 80
1677rfWrt rfOrChkD
1678end
1679id = add id 1
1680end
1681
1682for i ulong 12
1683mk = add add 13 mul i 7 ro
1684if not isMain
1685if eq get rfMode 0 0
1686rfWrt rfNote
1687rfVerb id
1688rfWrt ard6
1689rfNum mk
1690rfWrt ard7
1691rfWrt rfFnAr
1692else
1693rfWrt rfOrFnPfx
1694rfNum id
1695rfWrt rfOrSigAr
1696end
1697rfWrt arb8
1698rfNum mk
1699rfWrt arb9
1700rfWrt rfEnd
1701else
1702m = ulong 0
1703for j ulong 8
1704v = xor rfArVal j mk
1705if gt v m
1706m = v
1707end
1708end
1709rfWrt rfOrChkA
1710rfNum id
1711rfWrt rfOrChkB
1712rfWrt rfOrArrArg
1713rfWrt rfOrChkB
1714rfNum m
1715rfWrt rfOrChkC
1716rfNum add 10 rem id 80
1717rfWrt rfOrChkD
1718end
1719id = add id 1
1720end
1721
1722for i ulong 12
1723w = add add 2 i ro
1724if not isMain
1725if eq get rfMode 0 0
1726rfWrt rfNote
1727rfVerb id
1728rfWrt ard8
1729rfNum w
1730rfWrt ard9
1731rfWrt rfFnAr
1732else
1733rfWrt rfOrFnPfx
1734rfNum id
1735rfWrt rfOrSigAr
1736end
1737rfWrt arb10
1738rfNum w
1739rfWrt arb11
1740rfWrt rfEnd
1741else
1742s = ulong 0
1743for j ulong 8
1744s = add s mul add j w rfArVal j
1745end
1746rfWrt rfOrChkA
1747rfNum id
1748rfWrt rfOrChkB
1749rfWrt rfOrArrArg
1750rfWrt rfOrChkB
1751rfNum s
1752rfWrt rfOrChkC
1753rfNum add 10 rem id 80
1754rfWrt rfOrChkD
1755end
1756id = add id 1
1757end
1758end
1759
1760note ==================== FAMILY 5: AW (in-place array rewrites) ====================
1761text awd0 "add "
1762text awd1 " to every element of a[0..n) in place"
1763text awd2 "multiply every element of a[0..n) by "
1764text awd3 " and add "
1765text awd4 " in place"
1766text awd5 "replace every element of a[0..n) greater than "
1767text awd6 " with "
1768text awd7 "XOR every element of a[0..n) with "
1769text awd8 "replace every element of a[0..n) less than "
1770text awd9 "add index times "
1771text awd10 " to each element of a[0..n) in place"
1772text awb0 "for i ulong n bound 8\nput a i add get a i "
1773text awb1 "\nend"
1774text awb2 "for i ulong n bound 8\nput a i add mul get a i "
1775text awb3 " "
1776text awb4 "for i ulong n bound 8\nif gt get a i "
1777text awb5 "\nput a i "
1778text awb6 "\nend\nend"
1779text awb7 "for i ulong n bound 8\nput a i xor get a i "
1780text awb8 "for i ulong n bound 8\nif lt get a i "
1781text awb9 "for i ulong n bound 8\nput a i add get a i mul i "
1782
1783fn rfEmitAwAll isMain bool to void
1784id = ulong 901
1785ro = mul sub get rfRound 0 1 2
1786for i ulong 16
1787k = add add 5 mul i 4 ro
1788if not isMain
1789if eq get rfMode 0 0
1790rfWrt rfNote
1791rfWrt awd0
1792rfNum k
1793rfWrt awd1
1794rfWrt rfFnAw
1795else
1796rfWrt rfOrFnPfx
1797rfNum id
1798rfWrt rfOrSigAw
1799end
1800rfWrt awb0
1801rfNum k
1802rfWrt awb1
1803rfWrt rfEnd
1804else
1805exp = add add add ulong 3 k add ulong 11 k add ulong 15 k
1806rfWrt rfOrAwRst
1807rfNum id
1808rfWrt rfOrAwCall
1809rfNum exp
1810rfWrt rfOrChkC
1811rfNum add 10 rem id 80
1812rfWrt rfOrChkD
1813end
1814id = add id 1
1815end
1816
1817for i ulong 16
1818m = add 3 rem i 5
1819c = add add 4 mul i 3 ro
1820if not isMain
1821if eq get rfMode 0 0
1822rfWrt rfNote
1823rfWrt awd2
1824rfNum m
1825rfWrt awd3
1826rfNum c
1827rfWrt awd4
1828rfWrt rfFnAw
1829else
1830rfWrt rfOrFnPfx
1831rfNum id
1832rfWrt rfOrSigAw
1833end
1834rfWrt awb2
1835rfNum m
1836rfWrt awb3
1837rfNum c
1838rfWrt awb1
1839rfWrt rfEnd
1840else
1841v0 = add mul ulong 3 m c
1842v1 = add mul ulong 11 m c
1843v7 = add mul ulong 15 m c
1844exp = add v0 add v1 v7
1845rfWrt rfOrAwRst
1846rfNum id
1847rfWrt rfOrAwCall
1848rfNum exp
1849rfWrt rfOrChkC
1850rfNum add 10 rem id 80
1851rfWrt rfOrChkD
1852end
1853id = add id 1
1854end
1855
1856for i ulong 16
1857cap = add add 4 i ro
1858if not isMain
1859if eq get rfMode 0 0
1860rfWrt rfNote
1861rfWrt awd5
1862rfNum cap
1863rfWrt awd6
1864rfNum cap
1865rfWrt rfFnAw
1866else
1867rfWrt rfOrFnPfx
1868rfNum id
1869rfWrt rfOrSigAw
1870end
1871rfWrt awb4
1872rfNum cap
1873rfWrt awb5
1874rfNum cap
1875rfWrt awb6
1876rfWrt rfEnd
1877else
1878v0 = ulong 3
1879if gt v0 cap
1880v0 = cap
1881end
1882v1 = ulong 11
1883if gt v1 cap
1884v1 = cap
1885end
1886v7 = ulong 15
1887if gt v7 cap
1888v7 = cap
1889end
1890exp = add v0 add v1 v7
1891rfWrt rfOrAwRst
1892rfNum id
1893rfWrt rfOrAwCall
1894rfNum exp
1895rfWrt rfOrChkC
1896rfNum add 10 rem id 80
1897rfWrt rfOrChkD
1898end
1899id = add id 1
1900end
1901
1902for i ulong 16
1903flr = add add 3 i ro
1904if not isMain
1905if eq get rfMode 0 0
1906rfWrt rfNote
1907rfWrt awd8
1908rfNum flr
1909rfWrt awd6
1910rfNum flr
1911rfWrt rfFnAw
1912else
1913rfWrt rfOrFnPfx
1914rfNum id
1915rfWrt rfOrSigAw
1916end
1917rfWrt awb8
1918rfNum flr
1919rfWrt awb5
1920rfNum flr
1921rfWrt awb6
1922rfWrt rfEnd
1923else
1924v0 = ulong 3
1925if lt v0 flr
1926v0 = flr
1927end
1928v1 = ulong 11
1929if lt v1 flr
1930v1 = flr
1931end
1932v7 = ulong 15
1933if lt v7 flr
1934v7 = flr
1935end
1936exp = add v0 add v1 v7
1937rfWrt rfOrAwRst
1938rfNum id
1939rfWrt rfOrAwCall
1940rfNum exp
1941rfWrt rfOrChkC
1942rfNum add 10 rem id 80
1943rfWrt rfOrChkD
1944end
1945id = add id 1
1946end
1947
1948for i ulong 16
1949msk = add add 19 mul i 13 ro
1950if not isMain
1951if eq get rfMode 0 0
1952rfWrt rfNote
1953rfWrt awd7
1954rfNum msk
1955rfWrt rfFnAw
1956else
1957rfWrt rfOrFnPfx
1958rfNum id
1959rfWrt rfOrSigAw
1960end
1961rfWrt awb7
1962rfNum msk
1963rfWrt awb1
1964rfWrt rfEnd
1965else
1966exp = add xor ulong 3 msk add xor ulong 11 msk xor ulong 15 msk
1967rfWrt rfOrAwRst
1968rfNum id
1969rfWrt rfOrAwCall
1970rfNum exp
1971rfWrt rfOrChkC
1972rfNum add 10 rem id 80
1973rfWrt rfOrChkD
1974end
1975id = add id 1
1976end
1977
1978for i ulong 16
1979st = add add 2 mul i 3 ro
1980if not isMain
1981if eq get rfMode 0 0
1982rfWrt rfNote
1983rfWrt awd9
1984rfNum st
1985rfWrt awd10
1986rfWrt rfFnAw
1987else
1988rfWrt rfOrFnPfx
1989rfNum id
1990rfWrt rfOrSigAw
1991end
1992rfWrt awb9
1993rfNum st
1994rfWrt awb1
1995rfWrt rfEnd
1996else
1997v0 = add ulong 3 mul ulong 0 st
1998v1 = add ulong 11 mul ulong 1 st
1999v7 = add ulong 15 mul ulong 7 st
2000exp = add v0 add v1 v7
2001rfWrt rfOrAwRst
2002rfNum id
2003rfWrt rfOrAwCall
2004rfNum exp
2005rfWrt rfOrChkC
2006rfNum add 10 rem id 80
2007rfWrt rfOrChkD
2008end
2009id = add id 1
2010end
2011end
2012
2013note ==================== REPAIR & HELIX PROOF SPECIALIST CORPUS ====================
2014text repRec1 "note repair omc-error-12 split chained boolean guards and return clamped sum\nfn solve a ulong b ulong to ulong\ns = add a b\nif lt s 10\nret 10\nend\nif gt s 500\nret 500\nend\nret s\nend\n\n"
2015text repRec2 "note repair omc-error-22 explicit bound on dynamic while loop returning bit length\nfn solve a ulong to ulong\nx = a\nc = ulong 0\nwhile gt x 0 bound 64\nx = shr x 1\nc = add c 1\nend\nret c\nend\n\n"
2016text repRec3 "note repair antibody-13 pin branch target basic block leaders before swapping SM121 instructions\nfn solve a ulong b ulong to ulong\nif eq and a 1 0\nret add mul a 3 b\nend\nret add mul a 5 b\nend\n\n"
2017text repRec4 "note repair antibody-14 enforce SM121 6-cycle fixed-latency ALU RAW floor before VRAM upload\nfn solve a ulong b ulong to ulong\nif lt a 6\nret 6\nend\nif lt a b\nret a\nend\nret b\nend\n\n"
2018text repRec5 "note repair antibody-15 never compact fixed-latency I2F stalls below rawFloor 6\nfn solve a ulong to ulong\nif eq a 31\nret 6\nend\nif lt a 6\nret 6\nend\nret a\nend\n\n"
2019text repRec6 "note repair egp2-fma-fuse fold mul a b plus c with constant zero identity\nfn solve a ulong b ulong c ulong to ulong\np = mul a b\nif eq c 0\nret p\nend\nret add p c\nend\n\n"
2020text repRec7 "note repair omc-noend always close every if and for block with matching end before ret\nfn solve a view ulong 8 n ulong to ulong\ns = ulong 0\nfor i ulong n bound 8\nv = get a i\nif ne and v 1 0\ns = add s v\nend\nend\nret s\nend\n\n"
2021text repRec8 "note repair array-inplace-rewrite reverse elements of a[0..n) without out-of-bounds index\nfn solve a edit ulong 8 n ulong to void\ni = ulong 0\nwhile lt add mul i 2 1 n bound 8\nj = sub sub n 1 i\nt = get a i\nput a i get a j\nput a j t\ni = add i 1\nend\nend\n\n"
2022
2023fn rfEmitRepairCorpus to void
2024rfWrt repRec1
2025rfWrt repRec2
2026rfWrt repRec3
2027rfWrt repRec4
2028rfWrt repRec5
2029rfWrt repRec6
2030rfWrt repRec7
2031rfWrt repRec8
2032end
2033
2034fn rfProbeLiveTeacher to void
2035sa = new uchar 16 0
2036req = new uchar 1024 0
2037buf = new uchar 2048 0
2038fd = socknew 2 1 0
2039if lt fd 0
2040rfWrt rfTeaOff
2041ret
2042end
2043put sa 0 2
2044put sa 1 0
2045put sa 2 70
2046put sa 3 179
2047put sa 4 127
2048put sa 5 0
2049put sa 6 0
2050put sa 7 1
2051cr = connect int fd sa 0 16
2052if lt cr 0
2053z = fclose int fd
2054rfWrt rfTeaOff
2055ret
2056end
2057p = ulong 0
2058for i ulong len rfTcpReq bound 1024
2059c = get rfTcpReq i
2060if and eq c 10 lt p 1020
2061put req p 13
2062p = add p 1
2063end
2064if lt p 1022
2065put req p c
2066p = add p 1
2067end
2068end
2069wr = write int fd req 0 p
2070tot = ulong 0
2071for it ulong 16
2072r = read int fd buf tot sub 2048 tot
2073if le r 0
2074break
2075end
2076tot = add tot ulong r
2077if ge tot 2048
2078break
2079end
2080end
2081cl = fclose int fd
2082rfWrt rfTeaOn
2083rfNum tot
2084rfWrt rfNl
2085if gt tot 0
2086w = write 1 buf 0 tot
2087rfWrt rfNl
2088end
2089end
2090
2091text argCorpus "corpus"
2092text argOracle "oracle"
2093text argRepair "repair"
2094text argTeacher "teacher"
2095
2096fn main to int
2097ab = new uchar 32 0
2098rb = new uchar 16 0
2099mode = ulong 0
2100rnd = ulong 1
2101if ge argcnt 2
2102alr = argread 1 ab 0 32
2103al = ulong 0
2104if gt alr 0
2105al = ulong alr
2106end
2107if rfEqArg ab al argOracle
2108mode = 1
2109else
2110if rfEqArg ab al argRepair
2111mode = 2
2112else
2113if rfEqArg ab al argTeacher
2114mode = 3
2115end
2116end
2117end
2118end
2119if ge argcnt 3
2120rlr = argread 2 rb 0 16
2121if gt rlr 0
2122ch = ulong get rb 0
2123if and ge ch 49 le ch 57
2124rnd = sub ch 48
2125end
2126end
2127end
2128put rfMode 0 mode
2129put rfRound 0 rnd
2130if eq mode 3
2131rfProbeLiveTeacher
2132ret 0
2133end
2134if eq mode 2
2135rfEmitRepairCorpus
2136ret 0
2137end
2138if eq mode 1
2139rfWrt rfOm2
2140rfEmitU1All false
2141rfEmitU2All false
2142rfEmitU3All false
2143rfEmitArAll false
2144rfEmitAwAll false
2145rfWrt rfOrMainH
2146rfEmitU1All true
2147rfEmitU2All true
2148rfEmitU3All true
2149rfEmitArAll true
2150rfEmitAwAll true
2151rfWrt rfOrMainT
2152ret 0
2153end
2154rfEmitU1All false
2155rfEmitU2All false
2156rfEmitU3All false
2157rfEmitArAll false
2158rfEmitAwAll false
2159rfEmitRepairCorpus
2160ret 0
2161end