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 / helix_jit.om

1057 lines · 20283 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note seed/helix/helix_jit.om: In-Process Proof-Carrying SM121 Evolutionary JIT + Strand A Monk Proof Gate.
3note Pure seeded OM-2 (zero C, zero Python, zero CUDA).
4note Compose after:
5note gpu/nvidia/om/codegen/bw_hazard.om (with local `rb` non-colliding when composed with bw_enc_sm121.om)
6note om/gpu/q36/emit_fast.om
7note
8note Intercepts every SM121 kernel emitted into q36Buf[0..cnt*4) (and optionally qhBuf[0..cnt*4))
9note BEFORE upload to GB10 VRAM:
10note 1. Runs a 3-mutant negative self-test against Strand A's in-process Monk verifier (hxMonkVerify)
11note on first init (opcode smuggle, wait-barrier strip, illegal RAW stall shave -> 3/3 MUST be KILLED).
12note 2. Reads active Arboris genome (0..6) from `/tmp/helix_genome.cfg` (default 0 = Monk Reference):
13note G0: Monk Reference (untouched baseline)
14note G1: Predator (Antibody #13 basic-block leaders + Antibody #14 rawFloor=6 swaps + ALU/wait-NOP compaction)
15note G2: Mitosis Hybrid Champion (G1 + G6 warp-yield hiding + Antibody #15 never shave I2F fixed-latency stalls)
16note G3: Mitosis 2-Pass Champion (2-pass RAW-safe interleaving + G2)
17note G5: Strand 3 Trickster (reverse-order chaos swaps + hostile yield/stall jitter, rawFloor=6)
18note G6: Strand 4 Ascetic (zero-swap minimal footprint + rawFloor=6 compaction + yield=1 power/warp pacing)
19note 3. Mechanically proves EVERY evolved kernel in-memory via Strand A Monk BEFORE VRAM upload:
20note - 128-bit functional equality outside 17-bit SM121 control word w3[9..25]
21note - Exact bijection permutation (Antibodies 2 & 7)
22note - Full anchor pinning: flow!=0, guard!=7, nm<=8, ISETP(16), FSETP(25), nm>=33 (Antibody 4)
23note - Full RAW/WAR/WAW dependency preservation (Antibody 5)
24note - Full CFG worklist fixed-point dataflow scoreboard check: hazards == 0 (Antibody 6a)
25note - Fixed-latency ALU RAW cycle floor >= min(ref_cycles, rawFloor) including anchor
26note consumers AND live writes reaching a BRA/EXIT boundary (Antibody 6b / Attack 8)
27note If ANY check fails by a single bit, the candidate dies on the spot and original q36Buf is kept!
28
29global hxInitDone ulong 1
30global hxActive ulong 1
31global hxGenome ulong 1
32global hxRawFloor ulong 1
33global hxStats ulong 8
34note hxStats: 0=kernels_seen, 1=proved, 2=rejected, 3=skipped, 4=stalls_ref, 5=stalls_cand, 6=swaps, 7=yields_tuned
35
36global hxRef ulong 8192
37global hxCand ulong 8192
38global hxRefRec ulong 49152
39global hxCndRec ulong 49152
40global hxPerm ulong 2048
41global hxInv ulong 2048
42global hxSeen ulong 2048
43global hxTarget uchar 2048
44global hxWbar uchar 512
45global hxRbar uchar 512
46global hxInW uchar 1048576
47global hxInR uchar 1048576
48global hxHzSeen ulong 2048
49global hxHzQu ulong 2048
50global hxHzWk ulong 2048
51
52text hxCfgPath "/tmp/helix_genome.cfg"
53text hxLogA "HELIX_JIT_SUMMARY genome="
54text hxLogB " kernels="
55text hxLogC " proved="
56text hxLogD " rejected="
57text hxLogE " skipped="
58text hxLogF " swaps="
59text hxLogG " stalls_ref="
60text hxLogH " stalls_evolved="
61text hxLogI " yields_tuned="
62text hxLogJ " mutants_killed=3/3\n"
63text hxMutFail "HELIX_JIT FATAL: Monk self-test mutant survived!\n"
64
65fn hxWrt s view uchar * to void
66r = write 1 s 0 len s
67end
68
69fn hxNum v ulong to void
70b = new uchar 24 0
71p = ulong 24
72x = v
73while true bound 24
74p = sub p 1
75put b p uchar add 48 rem x 10
76x = div x 10
77if eq x 0
78break
79end
80end
81r = write 1 b p sub 24 p
82end
83
84fn hxLoadGenomeCfg to ulong
85fd = fopen hxCfgPath 0 len hxCfgPath 0 0
86if lt fd 0
87ret 0
88end
89buf = new uchar 16 0
90r = read int fd buf 0 15
91z = fclose int fd
92if lt r 1
93ret 0
94end
95c = ulong get buf 0
96if and ge c 48 le c 54
97ret sub c 48
98end
99ret 0
100end
101
102fn hxDecodeBuf isCand bool cnt ulong to bool
103ins = new uchar 16 0
104rec = new ulong 24 0
105for pc ulong cnt bound 2048
106base = mul pc 4
107for k ulong 4
108w = ulong 0
109if isCand
110w = get hxCand add base k
111else
112w = get hxRef add base k
113end
114put ins mul k 4 uchar and w 255
115put ins add mul k 4 1 uchar and shr w 8 255
116put ins add mul k 4 2 uchar and shr w 16 255
117put ins add mul k 4 3 uchar and shr w 24 255
118end
119if ne hz_dec1 ins rec 0
120ret false
121end
122db = mul pc 24
123for j ulong 24
124if isCand
125put hxCndRec add db j get rec j
126else
127put hxRefRec add db j get rec j
128end
129end
130end
131ret true
132end
133
134fn hxMarkTargets cnt ulong to void
135for i ulong cnt bound 2048
136put hxTarget i 0
137end
138if gt cnt 0
139put hxTarget 0 1
140end
141for pc ulong cnt bound 2048
142db = mul pc 24
143fl = get hxRefRec add db 17
144if eq fl 2
145tg = hz_u2l get hxRefRec add db 18
146dst = add long pc tg
147if and ge dst 0 lt dst long cnt
148put hxTarget ulong dst 1
149end
150if lt add pc 1 cnt
151put hxTarget add pc 1 1
152end
153end
154end
155end
156
157fn hxIsMonkAnchor pc ulong to bool
158if ne get hxTarget pc 0
159ret true
160end
161db = mul pc 24
162if ne get hxRefRec add db 17 0
163ret true
164end
165if ne get hxRefRec add db 1 7
166ret true
167end
168nm = get hxRefRec add db 19
169if or le nm 8 ge nm 33
170ret true
171end
172if or eq nm 16 eq nm 25
173ret true
174end
175ret false
176end
177
178fn hxIsSwapAnchor pc ulong to bool
179if hxIsMonkAnchor pc
180ret true
181end
182db = mul pc 24
183if ne get hxRefRec add db 6 0
184ret true
185end
186if ne get hxRefRec add db 4 7
187ret true
188end
189ret ne get hxRefRec add db 5 7
190end
191
192fn hxRegOverlap a ulong b ulong to bool
193if or eq a 0 eq b 0
194ret false
195end
196ra = and a 255
197na = and shr a 8 255
198ua = and shr a 16 1
199rb2 = and b 255
200nb = and shr b 8 255
201ub = and shr b 16 1
202if ne ua ub
203ret false
204end
205if or eq ra 255 eq rb2 255
206ret false
207end
208if or le add ra na rb2 le add rb2 nb ra
209ret false
210end
211ret true
212end
213
214fn hxHasRaw u ulong v ulong to bool
215du = mul u 24
216dv = mul v 24
217if eq get hxRefRec add du 10 0
218ret false
219end
220wu = get hxRefRec add du 16
221for j ulong get hxRefRec add dv 9 bound 5
222if hxRegOverlap wu get hxRefRec add add dv 11 j
223ret true
224end
225end
226ret false
227end
228
229fn hxHasWaw u ulong v ulong to bool
230du = mul u 24
231dv = mul v 24
232if or eq get hxRefRec add du 10 0 eq get hxRefRec add dv 10 0
233ret false
234end
235ret hxRegOverlap get hxRefRec add du 16 get hxRefRec add dv 16
236end
237
238fn hxHasDep u ulong v ulong to bool
239if hxHasWaw u v
240ret true
241end
242if hxHasRaw u v
243ret true
244end
245du = mul u 24
246dv = mul v 24
247if ne get hxRefRec add dv 10 0
248wv = get hxRefRec add dv 16
249for j ulong get hxRefRec add du 9 bound 5
250if hxRegOverlap get hxRefRec add add du 11 j wv
251ret true
252end
253end
254end
255ret false
256end
257
258fn hxCndStall pc ulong to ulong
259w3 = get hxCand add mul pc 4 3
260ret and shr w3 9 15
261end
262
263fn hxSetCndStall pc ulong nst ulong to void
264idx = add mul pc 4 3
265w3 = get hxCand idx
266nw3 = or and w3 not shl ulong 15 9 shl nst 9
267put hxCand idx nw3
268end
269
270fn hxSumRefStall lo ulong hi ulong to ulong
271tot = ulong 0
272k = lo
273while lt k hi bound 2048
274tot = add tot get hxRefRec add mul k 24 2
275k = add k 1
276end
277ret tot
278end
279
280fn hxSumCndStall lo ulong hi ulong to ulong
281tot = ulong 0
282k = lo
283while lt k hi bound 2048
284tot = add tot hxCndStall k
285k = add k 1
286end
287ret tot
288end
289
290note ==================== STRAND A IN-PROCESS MONK PROOF VERIFIER ====================
291fn hxChkOpnd opnd ulong chkR bool to bool
292reg = and opnd 255
293cnt = and shr opnd 8 255
294uni = and shr opnd 16 1
295base = add mul uni 256 reg
296for k ulong cnt bound 4
297idx = add base k
298if lt idx 512
299if ne get hxWbar idx 0
300ret false
301end
302if chkR
303if ne get hxRbar idx 0
304ret false
305end
306end
307end
308end
309ret true
310end
311
312fn hxMarkOpnd opnd ulong bit ulong isR bool to void
313reg = and opnd 255
314cnt = and shr opnd 8 255
315uni = and shr opnd 16 1
316base = add mul uni 256 reg
317b8 = uchar bit
318for k ulong cnt bound 4
319idx = add base k
320if lt idx 512
321if isR
322put hxRbar idx or get hxRbar idx b8
323else
324put hxWbar idx or get hxWbar idx b8
325end
326end
327end
328end
329
330fn hxStepHazard pc ulong check bool to bool
331db = mul pc 24
332wt = get hxCndRec add db 6
333if ne wt 0
334clr = uchar and not wt 255
335w8 = uchar and wt 255
336for i ulong 512
337put hxWbar i and get hxWbar i clr
338if ne and get hxRbar i w8 0
339put hxRbar i 0
340end
341end
342end
343nr = get hxCndRec add db 9
344nw = get hxCndRec add db 10
345if check
346for j ulong nr bound 5
347if not hxChkOpnd get hxCndRec add add db 11 j false
348ret false
349end
350end
351if ne nw 0
352if not hxChkOpnd get hxCndRec add db 16 true
353ret false
354end
355end
356end
357if and ne get hxCndRec add db 7 0 ne nw 0
358wb = get hxCndRec add db 4
359if lt wb 6
360hxMarkOpnd get hxCndRec add db 16 shl ulong 1 wb false
361end
362end
363if ne get hxCndRec add db 8 0
364rb2 = get hxCndRec add db 5
365wb2 = get hxCndRec add db 4
366lm = ulong 0
367if lt rb2 6
368lm = or lm shl ulong 1 rb2
369end
370if lt wb2 6
371lm = or lm shl ulong 1 wb2
372end
373if ne lm 0
374for j ulong nr bound 5
375hxMarkOpnd get hxCndRec add add db 11 j lm true
376end
377end
378end
379ret true
380end
381
382fn hxLoadIn pc ulong to void
383off = mul pc 512
384for i ulong 512
385put hxWbar i get hxInW add off i
386put hxRbar i get hxInR add off i
387end
388end
389
390fn hxJoinTo tgt ulong to bool
391off = mul tgt 512
392ch = false
393for i ulong 512
394ow = get hxInW add off i
395nw = or ow get hxWbar i
396if ne nw ow
397put hxInW add off i nw
398ch = true
399end
400orv = get hxInR add off i
401nrv = or orv get hxRbar i
402if ne nrv orv
403put hxInR add off i nrv
404ch = true
405end
406end
407ret ch
408end
409
410fn hxReachPush n ulong tgt long top ulong to ulong
411if or lt tgt 0 ge tgt long n
412ret top
413end
414u = ulong tgt
415if eq get hxHzSeen u 0
416put hxHzSeen u 1
417put hxHzWk top u
418ret add top 1
419end
420ret top
421end
422
423fn hxEdge n ulong tgt long top ulong to ulong
424if or lt tgt 0 ge tgt long n
425ret top
426end
427u = ulong tgt
428ch = hxJoinTo u
429sv = get hxHzSeen u
430qv = get hxHzQu u
431if and or ch eq sv 1 eq qv 0
432put hxHzQu u 1
433put hxHzWk top u
434ret add top 1
435end
436ret top
437end
438
439fn hxZeroHz n ulong to void
440for i ulong n bound 2048
441put hxHzSeen i 0
442put hxHzQu i 0
443off = mul i 512
444for r ulong 512
445put hxInW add off r 0
446put hxInR add off r 0
447end
448end
449end
450
451fn hxDoReach n ulong to void
452put hxHzSeen 0 1
453put hxHzWk 0 0
454top = ulong 1
455while gt top 0 bound 4096
456top = sub top 1
457pc = get hxHzWk top
458db = mul pc 24
459fl = get hxCndRec add db 17
460gd = get hxCndRec add db 1
461if or eq fl 0 ne gd 7
462top = hxReachPush n add long pc 1 top
463end
464if eq fl 2
465tg = hz_u2l get hxCndRec add db 18
466top = hxReachPush n add long pc tg top
467end
468end
469end
470
471fn hxCheckCfgHazards n ulong to bool
472hxZeroHz n
473hxDoReach n
474put hxHzWk 0 0
475put hxHzQu 0 1
476top = ulong 1
477while gt top 0 bound 65536
478top = sub top 1
479pc = get hxHzWk top
480put hxHzQu pc 0
481put hxHzSeen pc 2
482hxLoadIn pc
483z = hxStepHazard pc false
484db = mul pc 24
485fl = get hxCndRec add db 17
486gd = get hxCndRec add db 1
487if or eq fl 0 ne gd 7
488top = hxEdge n add long pc 1 top
489end
490if eq fl 2
491tg = hz_u2l get hxCndRec add db 18
492top = hxEdge n add long pc tg top
493end
494end
495for pc ulong n bound 2048
496if ne get hxHzSeen pc 0
497hxLoadIn pc
498if not hxStepHazard pc true
499ret false
500end
501end
502end
503ret true
504end
505
506fn hxRawSpanOk u ulong v ulong inclV bool flr ulong to bool
507hiRef = v
508hiCnd = get hxInv v
509if inclV
510hiRef = add v 1
511hiCnd = add hiCnd 1
512end
513rcyc = hxSumRefStall u hiRef
514eff = flr
515note SM121 IMAD.WIDE (nm==14) and I2FP/I2F (nm==29) are 6-cycle pipes; never drop below 6!
516nm = get hxRefRec add mul u 24 19
517if or eq nm 14 eq nm 29
518if lt eff 6
519eff = ulong 6
520end
521end
522req = rcyc
523if gt req eff
524req = eff
525end
526ret ge hxSumCndStall get hxInv u hiCnd req
527end
528
529note Fixed-latency RAW stall verification (up to distance 16, including anchor consumers & BRA/EXIT!)
530fn hxCheckRawOne u ulong n ulong flr ulong to bool
531du = mul u 24
532if or eq get hxRefRec add du 10 0 ne get hxRefRec add du 7 0
533ret true
534end
535note Antibody #15: I2FP/I2F (op 581, nm==29, var=0) stall must never be shaved below min(ref_stall, flr)!
536if eq get hxRefRec add du 19 29
537rst = get hxRefRec add du 2
538if gt rst flr
539rst = flr
540end
541if lt hxCndStall get hxInv u rst
542ret false
543end
544end
545lim = add u 16
546if gt lim n
547lim = n
548end
549v = add u 1
550while lt v lim bound 16
551if hxHasRaw u v
552ret hxRawSpanOk u v false flr
553end
554if hxHasWaw u v
555ret true
556end
557dbv = mul v 24
558flv = get hxRefRec add dbv 17
559if ne flv 0
560ret hxRawSpanOk u v true flr
561end
562if hxIsMonkAnchor v
563ret hxRawSpanOk u v true flr
564end
565v = add v 1
566end
567ret true
568end
569
570fn hxCheckRawStalls n ulong flr ulong to bool
571for u ulong n bound 2048
572if not hxCheckRawOne u n flr
573ret false
574end
575end
576ret true
577end
578
579fn hxCheckFunc n ulong to bool
580for i ulong n bound 2048
581ri = get hxPerm i
582cb = mul i 4
583rb3 = mul ri 4
584if ne get hxCand cb get hxRef rb3
585ret false
586end
587if ne get hxCand add cb 1 get hxRef add rb3 1
588ret false
589end
590if ne get hxCand add cb 2 get hxRef add rb3 2
591ret false
592end
593cw = and get hxCand add cb 3 ulong 4227858943
594rw = and get hxRef add rb3 3 ulong 4227858943
595if ne cw rw
596ret false
597end
598end
599ret true
600end
601
602fn hxCheckPermAnchors n ulong to bool
603for i ulong n bound 2048
604put hxSeen i 0
605end
606for i ulong n bound 2048
607r = get hxPerm i
608if ge r n
609ret false
610end
611if ne get hxSeen r 0
612ret false
613end
614put hxSeen r 1
615put hxInv r i
616if hxIsMonkAnchor i
617if ne r i
618ret false
619end
620end
621end
622ret true
623end
624
625fn hxCheckDeps n ulong to bool
626for u ulong n bound 2048
627pu = get hxInv u
628v = add u 1
629while lt v n bound 2048
630if hxHasDep u v
631if ge pu get hxInv v
632ret false
633end
634end
635v = add v 1
636end
637end
638ret true
639end
640
641note Complete Strand A Monk Proof Gate: returns 0 PASS, or antibody error code (13/14/15/16/17).
642fn hxMonkVerify n ulong flr ulong to ulong
643if not hxCheckPermAnchors n
644ret 13
645end
646if not hxCheckFunc n
647ret 14
648end
649if not hxDecodeBuf true n
650ret 17
651end
652if not hxCheckDeps n
653ret 16
654end
655if not hxCheckCfgHazards n
656ret 17
657end
658if not hxCheckRawStalls n flr
659ret 17
660end
661ret 0
662end
663
664note ==================== STRAND B PREDATOR EVOLUTION PASSES ====================
665fn hxSwapCand i ulong j ulong to void
666bi = mul i 4
667bj = mul j 4
668for k ulong 4
669t = get hxCand add bi k
670put hxCand add bi k get hxCand add bj k
671put hxCand add bj k t
672end
673tp = get hxPerm i
674put hxPerm i get hxPerm j
675put hxPerm j tp
676put hxInv get hxPerm i i
677put hxInv get hxPerm j j
678end
679
680fn hxWindowRawOk lo ulong hi ulong n ulong flr ulong to bool
681k = lo
682while lt k hi bound 24
683u = get hxPerm k
684if not hxCheckRawOne u n flr
685ret false
686end
687k = add k 1
688end
689ret true
690end
691
692fn hxDoSwapsRevPass n ulong flr ulong to ulong
693note Trickster (G5): reverse-order adversarial interleaving from back to front!
694sw = ulong 0
695if lt n 2
696ret 0
697end
698i = sub n 2
699while true bound 2048
700j = add i 1
701if and not hxIsSwapAnchor i not hxIsSwapAnchor j
702if not hxHasDep get hxPerm i get hxPerm j
703hxSwapCand i j
704lo = ulong 0
705if gt i 16
706lo = sub i 16
707end
708hi = add i 2
709if gt hi n
710hi = n
711end
712if hxWindowRawOk lo hi n flr
713sw = add sw 1
714if lt i 2
715break
716end
717i = sub i 2
718continue
719end
720hxSwapCand i j
721end
722end
723if eq i 0
724break
725end
726i = sub i 1
727end
728ret sw
729end
730
731fn hxTricksterChaos n ulong flr ulong to ulong
732note Trickster (G5): inject adversarial yield=1 jitter + asymmetric non-RAW stall perturbations!
733cnt = ulong 0
734for pc ulong n bound 2048
735orig = get hxPerm pc
736if not hxIsSwapAnchor orig
737idx = add mul pc 4 3
738w3 = get hxCand idx
739if eq rem pc 2 0
740put hxCand idx or w3 ulong 8192
741cnt = add cnt 1
742end
743st = hxCndStall pc
744if and eq rem pc 3 1 lt st 8
745hxSetCndStall pc add st 1
746end
747end
748end
749ret cnt
750end
751
752fn hxAsceticPace n ulong to ulong
753note Ascetic (G6): energy & thermal pacing -- enable yield=1 on FFMA(24)/I2FP(29)/F2I(30)/MUFU(31) transitions
754note to maximize warp power-gating and minimize peak thermal bursts while keeping exact semantics!
755cnt = ulong 0
756for pc ulong n bound 2048
757orig = get hxPerm pc
758db = mul orig 24
759nm = get hxRefRec add db 19
760if or eq nm 24 or eq nm 29 or eq nm 30 eq nm 31
761idx = add mul pc 4 3
762w3 = get hxCand idx
763if eq and w3 8192 0
764put hxCand idx or w3 ulong 8192
765cnt = add cnt 1
766end
767end
768end
769ret cnt
770end
771
772fn hxDoSwapsPass n ulong flr ulong to ulong
773sw = ulong 0
774i = ulong 0
775while lt add i 1 n bound 2048
776j = add i 1
777if and not hxIsSwapAnchor i not hxIsSwapAnchor j
778if not hxHasDep get hxPerm i get hxPerm j
779hxSwapCand i j
780lo = ulong 0
781if gt i 16
782lo = sub i 16
783end
784hi = add i 2
785if gt hi n
786hi = n
787end
788if hxWindowRawOk lo hi n flr
789sw = add sw 1
790i = add i 2
791continue
792end
793hxSwapCand i j
794end
795end
796i = add i 1
797end
798ret sw
799end
800
801note Can we compact stall on candidate pc?
802note Safe targets (Antibodies #13, #14, #15 crystallized from live GB10 silicon):
803note 1. Non-anchor fixed-latency ALU (rawFloor >= 6)
804note 2. Wait-barrier NOP (nm==1 && wait!=0, e.g. qW0/qW1/qWall: hardware wait already stalls!)
805note NEVER compact I2FP/I2F (nm==29) / LDC / ULDC / S2R / LDG / LDS / F2I (nm==30) / MUFU (nm==31)!
806fn hxCanCompactPc pc ulong gen ulong to bool
807orig = get hxPerm pc
808db = mul orig 24
809nm = get hxRefRec add db 19
810if eq nm 1
811wt = get hxRefRec add db 6
812if ne wt 0
813ret ge gen 1
814end
815ret false
816end
817if eq nm 29
818ret false
819end
820if hxIsSwapAnchor orig
821ret false
822end
823if ne get hxRefRec add db 7 0
824ret false
825end
826ret eq get hxRefRec add db 8 0
827end
828
829fn hxShaveSafe pc ulong n ulong flr ulong to bool
830lo = ulong 0
831if gt pc 17
832lo = sub pc 17
833end
834hi = add pc 1
835ret hxWindowRawOk lo hi n flr
836end
837
838fn hxCompactStalls n ulong gen ulong flr ulong to void
839for pc ulong n bound 2048
840if hxCanCompactPc pc gen
841for s ulong 15
842st = hxCndStall pc
843if le st 1
844break
845end
846hxSetCndStall pc sub st 1
847if not hxShaveSafe pc n flr
848hxSetCndStall pc st
849break
850end
851end
852end
853end
854end
855
856note SM121 yield-hint burst tuning (G3/G4): clear redundant yield=1 on non-memory I2FP(29)/F2I(30)/MUFU(31) issue bursts
857fn hxTuneYields n ulong to ulong
858cnt = ulong 0
859for pc ulong n bound 2048
860orig = get hxPerm pc
861db = mul orig 24
862nm = get hxRefRec add db 19
863if or eq nm 29 or eq nm 30 eq nm 31
864idx = add mul pc 4 3
865w3 = get hxCand idx
866if ne and w3 8192 0
867put hxCand idx and w3 not ulong 8192
868cnt = add cnt 1
869end
870end
871end
872ret cnt
873end
874
875note ==================== 3-MUTANT MONK SELF-TEST ====================
876fn hxMut1 n ulong flr ulong to bool
877w0 = get hxCand 0
878put hxCand 0 xor w0 1
879rc1 = hxMonkVerify n flr
880put hxCand 0 w0
881ret eq rc1 14
882end
883
884fn hxMut2 n ulong flr ulong to bool
885hasWt = false
886clr = not shl ulong 63 20
887for pc ulong n bound 2048
888if ne get hxRefRec add mul pc 24 6 0
889hasWt = true
890idx = add mul pc 4 3
891w = get hxCand idx
892put hxCand idx and w clr
893end
894end
895if not hasWt
896ret true
897end
898rc2 = hxMonkVerify n flr
899for pc ulong n bound 2048
900idx = add mul pc 4 3
901put hxCand idx get hxRef idx
902end
903ret eq rc2 17
904end
905
906fn hxFindRawMut n ulong to ulong
907for u ulong n bound 2048
908du = mul u 24
909if ne get hxRefRec add du 10 0
910if eq get hxRefRec add du 7 0
911if lt add u 1 n
912if gt get hxRefRec add du 2 0
913if hxHasRaw u add u 1
914ret u
915end
916end
917end
918end
919end
920end
921ret 99999
922end
923
924fn hxMut3 n ulong flr ulong to bool
925sPc = hxFindRawMut n
926if eq sPc 99999
927ret true
928end
929hxSetCndStall sPc 0
930rc3 = hxMonkVerify n flr
931put hxCand add mul sPc 4 3 get hxRef add mul sPc 4 3
932ret eq rc3 17
933end
934
935fn hxTest3Mutants n ulong flr ulong to bool
936if not hxMut1 n flr
937ret false
938end
939if not hxMut2 n flr
940ret false
941end
942ret hxMut3 n flr
943end
944
945fn hxPrintSummary to void
946hxWrt hxLogA
947hxNum get hxGenome 0
948hxWrt hxLogB
949hxNum get hxStats 0
950hxWrt hxLogC
951hxNum get hxStats 1
952hxWrt hxLogD
953hxNum get hxStats 2
954hxWrt hxLogE
955hxNum get hxStats 3
956hxWrt hxLogF
957hxNum get hxStats 6
958hxWrt hxLogG
959hxNum get hxStats 4
960hxWrt hxLogH
961hxNum get hxStats 5
962hxWrt hxLogI
963hxNum get hxStats 7
964hxWrt hxLogJ
965end
966
967fn hxEnsureInit to void
968if eq get hxInitDone 0 0
969g = hxLoadGenomeCfg
970put hxGenome 0 g
971note Antibody #14 (crystallized from live GB10 silicon): SM121 fixed-latency ALU pipe floor is ALWAYS 6 cycles!
972put hxRawFloor 0 6
973for i ulong 8
974put hxStats i 0
975end
976put hxInitDone 0 1
977end
978end
979
980fn hxRunCore cnt ulong to bool
981for i ulong cnt bound 2048
982put hxPerm i i
983put hxInv i i
984end
985if not hxDecodeBuf false cnt
986put hxStats 3 add get hxStats 3 1
987ret false
988end
989hxMarkTargets cnt
990flr = get hxRawFloor 0
991if eq get hxInitDone 0 1
992if not hxTest3Mutants cnt flr
993hxWrt hxMutFail
994exit 88
995end
996put hxInitDone 0 2
997end
998gen = get hxGenome 0
999sRef = hxSumRefStall 0 cnt
1000sw = ulong 0
1001yt = ulong 0
1002if eq gen 5
1003sw = hxDoSwapsRevPass cnt flr
1004yt = hxTricksterChaos cnt flr
1005else
1006if eq gen 6
1007hxCompactStalls cnt 1 flr
1008yt = hxAsceticPace cnt
1009else
1010sw = hxDoSwapsPass cnt flr
1011if eq gen 3
1012sw = add sw hxDoSwapsPass cnt flr
1013end
1014hxCompactStalls cnt gen flr
1015if or eq gen 2 eq gen 3
1016yt = hxAsceticPace cnt
1017end
1018end
1019end
1020mrc = hxMonkVerify cnt flr
1021if ne mrc 0
1022put hxStats 2 add get hxStats 2 1
1023ret false
1024end
1025sCnd = hxSumCndStall 0 cnt
1026put hxStats 1 add get hxStats 1 1
1027put hxStats 4 add get hxStats 4 sRef
1028put hxStats 5 add get hxStats 5 sCnd
1029put hxStats 6 add get hxStats 6 sw
1030put hxStats 7 add get hxStats 7 yt
1031ret true
1032end
1033
1034fn hxEvolveQ36Buf cnt ulong to void
1035if eq get hxActive 0 0
1036ret
1037end
1038hxEnsureInit
1039if eq get hxGenome 0 0
1040ret
1041end
1042if or eq cnt 0 gt cnt 2048
1043put hxStats 3 add get hxStats 3 1
1044ret
1045end
1046put hxStats 0 add get hxStats 0 1
1047for i ulong mul cnt 4 bound 8192
1048v = get q36Buf i
1049put hxRef i v
1050put hxCand i v
1051end
1052if hxRunCore cnt
1053for i ulong mul cnt 4 bound 8192
1054put q36Buf i get hxCand i
1055end
1056end
1057end