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 / ng / a64 / tests / frand.om

2123 lines · 32947 bytes Raw Blame History
1note frand.om: scalar float programs for the ng-a64 back-end gate (rgate.om, D-float in seed/ng/a64/DESIGN.md
2note section 9). Build: seed/out/omc < seed/ng/a64/tests/frand.om > frand
3note frand SEED a random canonical ΩIR text unit (IR.md s10) for SEED (decimal, 1..2^64-1) on stdout
4note frand edge K the deterministic edge program K (1..66, below)
5note A unit: @f0 writes its u64 argument as 8 little-endian bytes to stdout (write, host 54); @f1 and @f2 print an
6note f64 or f32 arithmetic result: a NaN (it compares unequal to itself) is printed with its sign and payload
7note dropped but its exponent and quiet bit kept (IR.md s7.3: an arithmetic NaN is any quiet NaN; a signaling
8note result would print differently), every other value bit for bit; @f3 has a random signature of up to 20
9note parameters mixing f64, f32 and integers (more than eight of either register bank: stack arguments) and folds
10note them into its f64 or f32 result after printing each of them (its float parameters live across calls); @f6
11note takes the same arguments and is a leaf returning a u64 checksum of every argument bit (parameters stay in their
12note argument registers); @f5 recurses (depth 0..19) with an f64 and an f32 of each frame live across its call
13note (callee-saved V registers at every depth). The export @f4 holds a pool of f32/f64 values from an edge table (signed
14note zeros, infinities, quiet and signaling NaNs with payloads, largest/smallest normals and subnormals, conversion
15note boundaries and halfway cases) and random bits, then random operations, each result printed: add sub mul div
16note min max (canonical print), neg fabs (bit for bit), fsqrt, fma, the six compares (as 0/1), select, bitcast
17note both ways, conv int -> float (nearest even and toward zero), f64 -> f32 (imm 0, 1, 4, 5), f32 -> f64, float ->
18note every integer type, stores and loads of f32/f64 array elements, calls of @f3, and a two-way branch whose join
19note block takes float parameters in either order (parallel-move cycles). The pool stays live to the end, where
20note every value is printed again (more live floats across calls than d8..d15 hold: spills). One seed in four
21note ends with a chk.conv of a pool value into a random integer type (trap 5 when it is NaN or out of range).
22note Edge programs: 1 f64 and 2 f32 binary ops and compares over every pair of the edge table; 3 f64 and 4 f32
23note unary ops, conversions to every integer type and to the other float width in every mode, bitcasts; 5 integer
24note edge values to f32/f64 in both modes; 6 f64 and 7 f32 chk.conv of every passing edge value; 8 + j (j 0..47)
25note for integer type 2 + j mod 8, source f32 (j / 8 even) or f64, case j / 16: the values just inside both ends of
26note the chk.conv range pass and are converted, then the upper bound (case 0), the lower one (case 1) or a NaN (case
27note 2) traps 5; 56 register pressure, stack arguments of both banks and recursion (epress); 57..66 `fill` (op 51)
28note of u8, i8, u16, i16, u32, i32, u64, i64, f32 and f64 elements (efill: lengths, offsets, nested slices, sentinels,
29note NaN and -0 bit patterns). ngrun is the oracle: rgate compares status, stdout and stderr byte for byte.
30om2
31
32global ob uchar 8388608
33global on ulong 1
34global rs ulong 1
35global vn ulong 1
36global tk ulong 1
37global bn ulong 1
38global pv ulong 4096
39global pt ulong 4096
40global pc ulong 4096
41global pn ulong 1
42global iv ulong 4096
43global it ulong 4096
44global inn ulong 1
45global bv ulong 4096
46global bnn ulong 1
47global fp ulong 64
48global fpn ulong 1
49note fr[0] = 1 (epress): each float argument of @f3 is a fresh finite constant in [1, 2) (held in a register at the
50note call, and no NaN or infinity hides a misplaced argument in @f3's result)
51global fr ulong 1
52note fw[0]: the element type of an efill program (types %t38..%t40 in its header), 0 otherwise
53global fw ulong 1
54text y_true "true"
55text y_false "false"
56note y_ft: the element type of fill program 57 + j, one hex digit each: u8 i8 u16 i16 u32 i32 u64 i64 f32 f64
57text y_ft "26374859de"
58global ra ulong 2
59global y_pa uchar 4096
60
61text y_use "usage: frand SEED | frand edge K\n"
62text y_io "frand: io error\n"
63text y_edge "edge"
64text y_hd "omegair 1\ntype %t32 = array u8 8\ntype %t33 = ref edit host %t32\ntype %t34 = array f64 8\ntype %t35 = ref edit host %t34\ntype %t36 = array f32 8\ntype %t37 = ref edit host %t36\n"
65text y_hd2 "global @g0 %t32 zero\n"
66text y_ty38 "type %t38 = array "
67text y_ty39 " 300\ntype %t39 = ref edit host %t38\ntype %t40 = slice edit host "
68text y_t39 "%t39 "
69text y_fill "fill "
70text y_chks "chk.slice 3 "
71text y_slice "slice %t40 "
72text y_u64t ":u64"
73text y_f0 "fn @f0 flags 0 %1:u64 -> void\nblock ^0\n%2 = gaddr %t33 @g0\n%3 = const u64 0\nbr ^1 %0 %3 %1\nblock ^1 %4:tok %5:u64 %6:u64\n%7 = const u64 8\n%8 = lt bool %5 %7\ncbr %4 %8 ^2 ^3\nblock ^2 %9:tok\n%10 = const u64 1\n%11 = chk.bounds 3 %9 %2 %5 %10\n%12 = conv u8 0 %6\n%13 = store %11 %2 %5 %12\n%14 = const u64 8\n%15 = shr u64 %6 %14\n%16 = add u64 %5 %10\nbr ^1 %13 %16 %15\nblock ^3 %17:tok\n%18 = const i32 1\n%19 = const u64 0\n%20 = chk.slice 3 %17 %2 %19 %7\n%21 %22 = host i64 54 %20 %18 %2 %19 %7\nret %21\nend\n"
74text y_f1 "fn @f1 flags 0 %1:f64 -> void\nblock ^0\n%2 = ne bool %1 %1\n%3 = bitcast u64 %1\n%4 = const u64 9221120237041090560\n%5 = and u64 %3 %4\n%6 = select u64 %2 %5 %3\n%7 = call void %0 @f0 %6\nret %7\nend\n"
75text y_f2 "fn @f2 flags 0 %1:f32 -> void\nblock ^0\n%2 = ne bool %1 %1\n%3 = bitcast u32 %1\n%4 = const u32 2143289344\n%5 = and u32 %3 %4\n%6 = select u32 %2 %5 %3\n%7 = conv u64 0 %6\n%8 = call void %0 @f0 %7\nret %8\nend\n"
76text y_eq " = "
77text y_call "call "
78text y_void "void "
79text y_f0c " @f0 "
80text y_f1c " @f1 "
81text y_f2c " @f2 "
82text y_f3c " @f3"
83text y_f6c " @f6"
84text y_fn6 "fn @f6 flags 0"
85text y_rotl "rotl u64 "
86text y_xor "xor u64 "
87text y_const "const "
88text y_conv "conv "
89text y_bcast "bitcast "
90text y_sel "select "
91text y_fma "fma "
92text y_bool "bool "
93text y_load "load "
94text y_store "store "
95text y_chkb "chk.bounds 3 "
96text y_chkc "chk.conv "
97text y_alloca "alloca "
98text y_cbr "cbr "
99text y_br "br ^"
100text y_block "block ^"
101text y_tok ":tok"
102text y_retv "retv "
103text y_end "end\n"
104text y_fn3 "fn @f3 flags 0"
105text y_arrow " -> "
106text y_ex4 "export @f4 flags 0 -> i32\nblock ^0\n"
107text y_f5 "fn @f5 flags 0 %1:f64 %2:u64 %3:f32 -> f64\nblock ^0\n%4 = const u64 0\n%5 = eq bool %2 %4\ncbr %0 %5 ^1 ^2\nblock ^1 %6:tok\nretv %6 %1\nblock ^2 %7:tok\n%8 = const f64 0x3ff8000000000000\n%9 = mul f64 %1 %8\n%10 = conv f64 0 %3\n%11 = add f64 %9 %10\n%12 = const u64 1\n%13 = sub u64 %2 %12\n%14 = neg f32 %3\n%15 %16 = call f64 %7 @f5 %11 %13 %14\n%17 = sub f64 %16 %9\n%18 = conv f64 0 %14\n%19 = add f64 %17 %18\nretv %15 %19\nend\n"
108text y_x "0x"
109text y_t35 "%t35 "
110text y_t37 "%t37 "
111text y_bop "add sub mul div min max "
112text y_cop "eq ne lt le gt ge "
113text y_uop "neg fabs fsqrt "
114text y_tn "bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 "
115
116note f64 edge table: +-0, +-1, 0.5, 1.5, 3, largest finite, smallest normal, largest and smallest subnormal, +-inf,
117note quiet NaNs (with payload, negative), signaling NaNs, 2^31 - 1, +-2^31, +-2^63, 2^64, 255.5, 65535.75, -128.9,
118note the largest f32 as f64, the f64 just below and at the f32 overflow halfway point, 2^-149, 2^-150, 1 + 2^-24
119note (f32 halfway), 1 + 3 * 2^-24, 2^53 + 2, -2^53
120global e64 ulong 40
121global e32 ulong 32
122global ein ulong 24
123
124fn ini to void
125put e64 0 0
126put e64 1 0x8000000000000000
127put e64 2 0x3ff0000000000000
128put e64 3 0xbff0000000000000
129put e64 4 0x3fe0000000000000
130put e64 5 0x3ff8000000000000
131put e64 6 0x4008000000000000
132put e64 7 0x7fefffffffffffff
133put e64 8 0x0010000000000000
134put e64 9 0x000fffffffffffff
135put e64 10 0x0000000000000001
136put e64 11 0x7ff0000000000000
137put e64 12 0xfff0000000000000
138put e64 13 0x7ff8000000000000
139put e64 14 0x7ff8000000000123
140put e64 15 0xfff8000000000000
141put e64 16 0x7ff0000000000001
142put e64 17 0xfff4000000000005
143put e64 18 0x41dfffffffc00000
144put e64 19 0x41e0000000000000
145put e64 20 0xc1e0000000000000
146put e64 21 0x43e0000000000000
147put e64 22 0xc3e0000000000000
148put e64 23 0x43f0000000000000
149put e64 24 0x406ff00000000000
150put e64 25 0x40effff800000000
151put e64 26 0xc06011cccccccccd
152put e64 27 0x47efffffe0000000
153put e64 28 0x47efffffefffffff
154put e64 29 0x47effffff0000000
155put e64 30 0x36a0000000000000
156put e64 31 0x3690000000000000
157put e64 32 0x3ff0000010000000
158put e64 33 0x3ff0000030000000
159put e64 34 0x4340000000000001
160put e64 35 0xc340000000000000
161put e64 36 0x41efffffffe00000
162put e64 37 0xc1e0000000200000
163put e64 38 0x3fefffffffffffff
164put e64 39 0xc3dfffffffffffff
165put e32 0 0
166put e32 1 0x80000000
167put e32 2 0x3f800000
168put e32 3 0xbf800000
169put e32 4 0x3f000000
170put e32 5 0x3fc00000
171put e32 6 0x7f7fffff
172put e32 7 0x00800000
173put e32 8 0x007fffff
174put e32 9 0x00000001
175put e32 10 0x7f800000
176put e32 11 0xff800000
177put e32 12 0x7fc00000
178put e32 13 0x7fc00123
179put e32 14 0xffc00000
180put e32 15 0x7f800001
181put e32 16 0xffa00005
182put e32 17 0x4f000000
183put e32 18 0xcf000000
184put e32 19 0x5f000000
185put e32 20 0xdf000000
186put e32 21 0x5f800000
187put e32 22 0x437f8000
188put e32 23 0x437f0000
189put e32 24 0xc3010000
190put e32 25 0x477fffc0
191put e32 26 0x4b800001
192put e32 27 0xcb800000
193put e32 28 0x3f7fffff
194put e32 29 0x4effffff
195put e32 30 0xc2fe0000
196put e32 31 0x46fffe00
197put ein 0 0
198put ein 1 1
199put ein 2 0xffffffffffffffff
200put ein 3 0x7fffffffffffffff
201put ein 4 0x8000000000000000
202put ein 5 0x20000000000001
203put ein 6 0x20000000000003
204put ein 7 0x1000001
205put ein 8 0x1000003
206put ein 9 0x7fffffff
207put ein 10 0x80000000
208put ein 11 0xffffffff
209put ein 12 0xffffffff80000000
210put ein 13 0xfffffffffeffffff
211put ein 14 0x7fffff8000000001
212put ein 15 0xffffff7fffffffff
213put ein 16 255
214put ein 17 0xffffffffffffff80
215put ein 18 65535
216put ein 19 0xffffffffffff8000
217put ein 20 0x8000000000000401
218put ein 21 0xfffffffffffff801
219put ein 22 3
220put ein 23 0x10000000000000ff
221end
222
223note ---- output ----
224fn oc c ulong to void
225n = get on 0
226if lt n len ob
227put ob n uchar c
228put on 0 add n 1
229end
230end
231
232fn ws t view uchar * to void
233for j ulong len t bound 4096
234oc ulong get t j
235end
236end
237
238note wk t k: the k-th space-separated word of t
239fn wk t view uchar * k ulong to void
240i = ulong 0
241w = ulong 0
242while lt i len t bound 4096
243c = ulong get t i
244if eq c 32
245w = add w 1
246else
247if eq w k
248oc c
249end
250end
251i = add i 1
252end
253end
254
255fn wd v ulong to void
256d = ulong 1
257while ge div v d 10 bound 20
258d = mul d 10
259end
260x = v
261while gt d 0 bound 20
262oc add 48 div x d
263x = rem x d
264d = div d 10
265end
266end
267
268note wsd v w: v as a signed decimal of width w bits (canonical form: sign-extended)
269fn wsd v ulong to void
270if ne shr v 63 0
271oc 45
272wd sub ulong 0 v
273else
274wd v
275end
276end
277
278fn wh v ulong n ulong to void
279ws y_x
280k = n
281while gt k 0 bound 16
282k = sub k 1
283c = and shr v mul k 4 15
284if lt c 10
285oc add 48 c
286else
287oc add 87 c
288end
289end
290end
291
292fn nl to void
293oc 10
294end
295
296fn sp to void
297oc 32
298end
299
300note type ids (IR.md s4.1): 1 bool, 2 u8, 3 u16, 4 u32, 5 u64, 6 i8, 7 i16, 8 i32, 9 i64, 13 f32, 14 f64
301fn wty t ulong to void
302if le t 9
303wk y_tn sub t 1
304ret
305end
306wk y_tn sub t 4
307end
308
309fn wv v ulong to void
310oc 37
311wd v
312end
313
314note nv: a new value id, its line started (`%N = `)
315fn nv to ulong
316v = get vn 0
317put vn 0 add v 1
318wv v
319ws y_eq
320ret v
321end
322
323fn flush to bool
324n = get on 0
325p = ulong 0
326while lt p n bound 65536
327k = write 1 ob p sub n p
328if le k 0
329ret false
330end
331p = add p ulong k
332end
333ret true
334end
335
336note ---- splitmix64 ----
337fn rnd to ulong
338s = add get rs 0 0x9e3779b97f4a7c15
339put rs 0 s
340z = mul xor s shr s 30 0xbf58476d1ce4e5b9
341z = mul xor z shr z 27 0x94d049bb133111eb
342ret xor z shr z 31
343end
344
345fn rn n ulong to ulong
346ret rem rnd n
347end
348
349note ---- values ----
350fn isf t ulong to bool
351ret or eq t 13 eq t 14
352end
353
354fn sgn t ulong to bool
355ret and ge t 6 le t 9
356end
357
358fn wid t ulong to ulong
359if or eq t 2 eq t 6
360ret 8
361end
362if or eq t 3 eq t 7
363ret 16
364end
365if or or eq t 4 eq t 8 eq t 13
366ret 32
367end
368ret 64
369end
370
371note canon t v: integer bits v as the canonical const imm of int type t
372fn canon t ulong v ulong to ulong
373w = wid t
374if eq w 64
375ret v
376end
377m = sub shl ulong 1 w 1
378x = and v m
379if sgn t
380s = shl ulong 1 sub w 1
381ret sub xor x s s
382end
383ret x
384end
385
386note kconst t v: a const of type t with bits v (floats: low 32 bits for f32), a new value
387fn kconst t ulong v ulong to ulong
388r = nv
389ws y_const
390wty t
391sp
392if eq t 14
393wh v 16
394end
395if eq t 13
396wh and v 0xffffffff 8
397end
398if not isf t
399c = canon t v
400if sgn t
401wsd c
402else
403wd c
404end
405end
406nl
407ret r
408end
409
410fn addf v ulong t ulong c ulong to void
411n = get pn 0
412if lt n len pv
413put pv n v
414put pt n t
415put pc n c
416put pn 0 add n 1
417end
418end
419
420fn addi v ulong t ulong to void
421n = get inn 0
422if lt n len iv
423put iv n v
424put it n t
425put inn 0 add n 1
426end
427end
428
429fn addb v ulong to void
430n = get bnn 0
431if lt n len bv
432put bv n v
433put bnn 0 add n 1
434end
435end
436
437note pick t: a pool value of float type t (a new constant when there is none)
438fn pick t ulong to ulong
439n = get pn 0
440k = ulong 0
441while lt k 8 bound 8
442if gt n 0
443i = rn n
444if eq get pt i t
445ret get pv i
446end
447end
448k = add k 1
449end
450i = ulong 0
451while lt i n bound 4096
452if eq get pt i t
453ret get pv i
454end
455i = add i 1
456end
457v = fconst t
458ret v
459end
460
461note fconst t: a new f32/f64 constant (half edge table, half random bits), added to the pool
462fn fconst t ulong to ulong
463b = rnd
464if eq rn 2 0
465if eq t 14
466b = get e64 rn len e64
467else
468b = get e32 rn len e32
469end
470end
471v = kconst t b
472addf v t 0
473ret v
474end
475
476fn rint to ulong
477k = rn 8
478if eq k 0
479ret 2
480end
481if eq k 1
482ret 3
483end
484if eq k 2
485ret 4
486end
487if eq k 3
488ret 5
489end
490if eq k 4
491ret 6
492end
493if eq k 5
494ret 7
495end
496if eq k 6
497ret 8
498end
499ret 9
500end
501
502note iconst t: a new integer constant of type t (half edge table, half random bits), added to the pool
503fn iconst t ulong to ulong
504b = rnd
505if eq rn 2 0
506b = get ein rn len ein
507end
508v = kconst t b
509addi v t
510ret v
511end
512
513note pinty t: an integer pool value of type t (a new constant when there is none in eight tries)
514fn pinty t ulong to ulong
515n = get inn 0
516k = ulong 0
517while lt k 8 bound 8
518if gt n 0
519i = rn n
520if eq get it i t
521ret get iv i
522end
523end
524k = add k 1
525end
526ret iconst t
527end
528
529note pint: an integer pool value (a new constant now and then)
530fn pint to ulong
531n = get inn 0
532if or eq n 0 eq rn 4 0
533v = iconst rint
534ret sub get inn 0 1
535end
536ret rn n
537end
538
539fn ft to ulong
540if eq rn 2 0
541ret 13
542end
543ret 14
544end
545
546note ---- printing (each a call: the token moves on) ----
547fn pr v ulong t ulong c ulong to void
548if isf t
549if eq c 0
550x = v
551if eq t 14
552x = nv
553ws y_bcast
554wty 5
555sp
556wv v
557nl
558else
559y = nv
560ws y_bcast
561wty 4
562sp
563wv v
564nl
565x = nv
566ws y_conv
567wty 5
568sp
569oc 48
570sp
571wv y
572nl
573end
574pcall 0 x
575ret
576end
577if eq t 14
578pcall 1 v
579else
580pcall 2 v
581end
582ret
583end
584x = v
585if ne t 5
586x = nv
587ws y_conv
588wty 5
589oc 32
590oc 48
591sp
592wv v
593nl
594end
595pcall 0 x
596end
597
598note pcall f v: call void @f0/@f1/@f2 with v
599fn pcall f ulong v ulong to void
600r = nv
601ws y_call
602ws y_void
603wv get tk 0
604if eq f 0
605ws y_f0c
606end
607if eq f 1
608ws y_f1c
609end
610if eq f 2
611ws y_f2c
612end
613wv v
614nl
615put tk 0 r
616end
617
618note ---- random operations ----
619fn obin to void
620t = ft
621a = pick t
622b = pick t
623k = rn 6
624r = nv
625wk y_bop k
626sp
627wty t
628sp
629wv a
630sp
631wv b
632nl
633addf r t 1
634pr r t 1
635end
636
637fn ocmp t ulong a ulong b ulong k ulong to void
638r = nv
639wk y_cop k
640sp
641ws y_bool
642wv a
643sp
644wv b
645nl
646addb r
647z = nv
648ws y_sel
649wty 5
650sp
651wv r
652sp
653wv get ra 0
654sp
655wv get ra 1
656nl
657pcall 0 z
658end
659
660fn oun to void
661t = ft
662a = pick t
663k = rn 3
664r = nv
665wk y_uop k
666sp
667wty t
668sp
669wv a
670nl
671c = ulong 0
672if eq k 2
673c = 1
674end
675addf r t c
676pr r t c
677end
678
679fn ofma to void
680t = ft
681a = pick t
682b = pick t
683c = pick t
684r = nv
685ws y_fma
686wty t
687sp
688wv a
689sp
690wv b
691sp
692wv c
693nl
694addf r t 1
695pr r t 1
696end
697
698fn osel to void
699t = ft
700if eq get bnn 0 0
701ocmp t pick t pick t rn 6
702end
703c = get bv rn get bnn 0
704a = pick t
705b = pick t
706r = nv
707ws y_sel
708wty t
709sp
710wv c
711sp
712wv a
713sp
714wv b
715nl
716addf r t 0
717pr r t 0
718end
719
720note conv to float type t from integer pool value i, imm m (0 nearest even, 1 toward zero)
721fn oi2f t ulong i ulong m ulong to void
722r = nv
723ws y_conv
724wty t
725sp
726wd m
727sp
728wv get iv i
729nl
730addf r t 0
731pr r t 0
732end
733
734fn of2f a ulong s ulong m ulong to void
735t = ulong 13
736if eq s 13
737t = 14
738end
739r = nv
740ws y_conv
741wty t
742sp
743wd m
744sp
745wv a
746nl
747addf r t 1
748pr r t 1
749end
750
751fn of2i a ulong t ulong to void
752r = nv
753ws y_conv
754wty t
755sp
756oc 48
757sp
758wv a
759nl
760addi r t
761pr r t 0
762end
763
764fn obc to void
765t = ft
766if eq rn 2 0
767a = pick t
768d = ulong 5
769if eq t 13
770d = 4
771end
772if eq rn 2 0
773d = add d 4
774end
775r = nv
776ws y_bcast
777wty d
778sp
779wv a
780nl
781addi r d
782pr r d 0
783ret
784end
785d = ulong 9
786if eq t 13
787d = 8
788end
789a = kconst d rnd
790r = nv
791ws y_bcast
792wty t
793sp
794wv a
795nl
796addf r t 0
797pr r t 0
798end
799
800note store then load an element of the f64 or f32 array (refs in fr 0 / ra), each access under its chk.bounds
801fn omem to void
802t = ft
803a = pick t
804x = kconst 5 rn 8
805o = kconst 5 1
806f = get fp 0
807if eq t 13
808f = get fp 1
809end
810c = nv
811ws y_chkb
812wv get tk 0
813sp
814wv f
815sp
816wv x
817sp
818wv o
819nl
820s = nv
821ws y_store
822wv c
823sp
824wv f
825sp
826wv x
827sp
828wv a
829nl
830put tk 0 s
831c = nv
832ws y_chkb
833wv get tk 0
834sp
835wv f
836sp
837wv x
838sp
839wv o
840nl
841put tk 0 c
842r = nv
843ws y_load
844wty t
845sp
846wv c
847sp
848wv f
849sp
850wv x
851nl
852addf r t 0
853pr r t 0
854end
855
856note the signature of @f3: fpn parameter types in fp 2.., result type in fp 60; ocall puts arguments in fp 32..
857fn sig to void
858n = rn 21
859put fpn 0 n
860k = ulong 0
861while lt k n bound 21
862u = rn 3
863t = ulong 14
864if eq u 1
865t = 13
866end
867if eq u 2
868t = rint
869end
870put fp add k 2 t
871k = add k 1
872end
873put fp 60 ft
874end
875
876fn ocall to void
877n = get fpn 0
878k = ulong 0
879while lt k n bound 21
880t = get fp add k 2
881a = ulong 0
882if isf t
883if eq get fr 0 1
884if eq t 14
885a = kconst t or 0x3ff0000000000000 shl rn 1048576 32
886else
887a = kconst t or 0x3f800000 rn 1048576
888end
889else
890a = pick t
891end
892else
893a = pinty t
894end
895put fp add k 32 a
896k = add k 1
897end
898t = get fp 60
899r = get vn 0
900put vn 0 add r 2
901wv r
902sp
903wv add r 1
904ws y_eq
905ws y_call
906wty t
907sp
908wv get tk 0
909ws y_f3c
910k = ulong 0
911while lt k n bound 21
912sp
913wv get fp add k 32
914k = add k 1
915end
916nl
917put tk 0 r
918addf add r 1 t 1
919pr add r 1 t 1
920r = get vn 0
921put vn 0 add r 2
922wv r
923sp
924wv add r 1
925ws y_eq
926ws y_call
927wty 5
928sp
929wv get tk 0
930ws y_f6c
931k = ulong 0
932while lt k n bound 21
933sp
934wv get fp add k 32
935k = add k 1
936end
937nl
938put tk 0 r
939pr add r 1 5 0
940end
941
942note two-way branch: cbr on a compare; one side passes (a, b), the other (b, a) to the join block's parameters
943fn odia to void
944t = ft
945a = pick t
946b = pick t
947b2 = pick t
948k = rn 6
949c = nv
950wk y_cop k
951sp
952ws y_bool
953wv a
954sp
955wv b2
956nl
957x = get bn 0
958put bn 0 add x 3
959ws y_cbr
960wv get tk 0
961sp
962wv c
963oc 32
964oc 94
965wd x
966oc 32
967oc 94
968wd add x 1
969nl
970k = ulong 0
971while lt k 2 bound 2
972ws y_block
973wd add x k
974sp
975q = get vn 0
976put vn 0 add q 1
977wv q
978ws y_tok
979nl
980ws y_br
981wd add x 2
982sp
983wv q
984sp
985if eq k 0
986wv a
987sp
988wv b
989else
990wv b
991sp
992wv a
993end
994nl
995k = add k 1
996end
997ws y_block
998wd add x 2
999sp
1000q = get vn 0
1001put vn 0 add q 3
1002wv q
1003ws y_tok
1004sp
1005wv add q 1
1006oc 58
1007wty t
1008sp
1009wv add q 2
1010oc 58
1011wty t
1012nl
1013put tk 0 q
1014addf add q 1 t 0
1015addf add q 2 t 0
1016pr add q 1 t 0
1017pr add q 2 t 0
1018end
1019
1020fn oconv to void
1021k = rn 4
1022if eq k 0
1023oi2f ft pint rn 2
1024ret
1025end
1026if eq k 1
1027t = ft
1028m = rn 2
1029if eq t 14
1030m = rn 6
1031if ge m 2
1032m = add m 2
1033end
1034if ge m 6
1035m = 0
1036end
1037end
1038of2f pick t t m
1039ret
1040end
1041of2i pick ft rint
1042end
1043
1044note chk.conv of pool value a (type s) into t: trap 5 when NaN or out of range, else nothing
1045fn ochk a ulong t ulong to void
1046c = nv
1047ws y_chkc
1048wty t
1049oc 32
1050oc 53
1051sp
1052wv get tk 0
1053sp
1054wv a
1055nl
1056put tk 0 c
1057end
1058
1059note @f3 (random signature in fp): prints every parameter bit for bit (integers as u64), so each argument's bank,
1060note register and stack slot is checked; then acc = 0; acc = acc * 3 - p for each parameter (f32 and integers through
1061note conv to f64 first, nearest even); result acc or its f32. Its float parameters live across those calls
1062fn wf3 to void
1063ws y_fn3
1064n = get fpn 0
1065k = ulong 0
1066while lt k n bound 21
1067sp
1068wv add k 1
1069oc 58
1070wty get fp add k 2
1071k = add k 1
1072end
1073ws y_arrow
1074wty get fp 60
1075nl
1076ws y_block
1077oc 48
1078nl
1079put vn 0 add n 1
1080put tk 0 0
1081k = ulong 0
1082while lt k n bound 21
1083pr add k 1 get fp add k 2 0
1084k = add k 1
1085end
1086a = kconst 14 0
1087c = kconst 14 0x4008000000000000
1088k = ulong 0
1089while lt k n bound 21
1090t = get fp add k 2
1091p = add k 1
1092if ne t 14
1093p = nv
1094ws y_conv
1095wty 14
1096sp
1097oc 48
1098sp
1099wv add k 1
1100nl
1101end
1102m = nv
1103wk y_bop 2
1104sp
1105wty 14
1106sp
1107wv a
1108sp
1109wv c
1110nl
1111a = nv
1112wk y_bop 1
1113sp
1114wty 14
1115sp
1116wv m
1117sp
1118wv p
1119nl
1120k = add k 1
1121end
1122if eq get fp 60 13
1123r = nv
1124ws y_conv
1125wty 13
1126sp
1127oc 48
1128sp
1129wv a
1130nl
1131a = r
1132end
1133ws y_retv
1134wv get tk 0
1135sp
1136wv a
1137nl
1138ws y_end
1139end
1140
1141fn hdr to void
1142ws y_hd
1143t = get fw 0
1144if ne t 0
1145ws y_ty38
1146wty t
1147ws y_ty39
1148wty t
1149nl
1150end
1151ws y_hd2
1152ws y_f0
1153ws y_f1
1154ws y_f2
1155wf3
1156ws y_ex4
1157put vn 0 1
1158put tk 0 0
1159put bn 0 1
1160r = get vn 0
1161oc 37
1162wd r
1163sp
1164wv add r 1
1165ws y_eq
1166ws y_alloca
1167ws y_t35
1168wv 0
1169nl
1170oc 37
1171wd add r 2
1172sp
1173wv add r 3
1174ws y_eq
1175ws y_alloca
1176ws y_t37
1177wv r
1178nl
1179put fp 0 add r 1
1180put fp 1 add r 3
1181put tk 0 add r 2
1182put vn 0 add r 4
1183put ra 0 kconst 5 1
1184put ra 1 kconst 5 0
1185end
1186
1187note tail all: (all: print every pool value again, the random programs) then retv 0
1188fn tail all bool to void
1189n = get pn 0
1190if not all
1191n = 0
1192end
1193i = ulong 0
1194while lt i n bound 4096
1195pr get pv i get pt i get pc i
1196i = add i 1
1197end
1198r = kconst 8 0
1199ws y_retv
1200wv get tk 0
1201sp
1202wv r
1203nl
1204ws y_end
1205ws y_f5
1206wf6
1207end
1208
1209note @f6: @f3's signature, a leaf returning u64: h = rotl(h, 7) xor the bits of each parameter in order (f64 and
1210note integers as u64, f32 through u32), so every argument bit reaches the result while the parameters stay in their
1211note argument registers (no call: caller-saved V registers, the LDR D path for stack parameters)
1212fn wf6 to void
1213ws y_fn6
1214n = get fpn 0
1215k = ulong 0
1216while lt k n bound 21
1217sp
1218wv add k 1
1219oc 58
1220wty get fp add k 2
1221k = add k 1
1222end
1223ws y_arrow
1224wty 5
1225nl
1226ws y_block
1227oc 48
1228nl
1229put vn 0 add n 1
1230h = kconst 5 0
1231s = kconst 5 7
1232k = ulong 0
1233while lt k n bound 21
1234t = get fp add k 2
1235b = add k 1
1236if eq t 14
1237b = nv
1238ws y_bcast
1239wty 5
1240sp
1241wv add k 1
1242nl
1243end
1244if eq t 13
1245y = nv
1246ws y_bcast
1247wty 4
1248sp
1249wv add k 1
1250nl
1251b = nv
1252ws y_conv
1253wty 5
1254sp
1255oc 48
1256sp
1257wv y
1258nl
1259end
1260if not isf t
1261if ne t 5
1262b = nv
1263ws y_conv
1264wty 5
1265sp
1266oc 48
1267sp
1268wv add k 1
1269nl
1270end
1271end
1272g = nv
1273ws y_rotl
1274wv h
1275sp
1276wv s
1277nl
1278h = nv
1279ws y_xor
1280wv g
1281sp
1282wv b
1283nl
1284k = add k 1
1285end
1286ws y_retv
1287oc 37
1288oc 48
1289sp
1290wv h
1291nl
1292ws y_end
1293end
1294
1295fn gen to void
1296sig
1297hdr
1298c = add 4 rn 12
1299k = ulong 0
1300while lt k c bound 16
1301v = fconst ft
1302k = add k 1
1303end
1304n = add 20 rn 50
1305k = ulong 0
1306while lt k n bound 70
1307u = rn 15
1308if le u 2
1309obin
1310end
1311if eq u 3
1312oun
1313end
1314if eq u 4
1315ofma
1316end
1317if eq u 5
1318t = ft
1319ocmp t pick t pick t rn 6
1320end
1321if eq u 6
1322osel
1323end
1324if or eq u 7 eq u 8
1325oconv
1326end
1327if eq u 9
1328obc
1329end
1330if eq u 10
1331omem
1332end
1333if eq u 11
1334ocall
1335end
1336if eq u 12
1337odia
1338end
1339if eq u 13
1340v = iconst rint
1341oi2f ft sub get inn 0 1 rn 2
1342end
1343if eq u 14
1344orec
1345end
1346k = add k 1
1347end
1348if eq rn 4 0
1349ochk pick ft rint
1350end
1351tail true
1352end
1353
1354note y_pt: the parameter types of @f3 in epress, one hex digit each (e f64, d f32, 2..9 the integers)
1355text y_pt "e5e8ed2e9e3ed6e4e5e7"
1356text y_f5c " @f5"
1357
1358note orec: a call of @f5 (fixed text y_f5: recursive, depth 0..19, an f64 and an f32 of each frame live across its
1359note call: callee-saved V registers saved and restored at every depth) on pool values; its result printed canonical
1360fn orec to void
1361a = pick 14
1362b = pick 13
1363d = kconst 5 rn 20
1364r = get vn 0
1365put vn 0 add r 2
1366wv r
1367sp
1368wv add r 1
1369ws y_eq
1370ws y_call
1371wty 14
1372sp
1373wv get tk 0
1374ws y_f5c
1375sp
1376wv a
1377sp
1378wv d
1379sp
1380wv b
1381nl
1382put tk 0 r
1383addf add r 1 14 1
1384pr add r 1 14 1
1385end
1386
1387note epress: edge 56, register pressure: @f3 takes 9 f64, 2 f32 and 9 integers (v0..v7 and x0..x7 full, three float
1388note and one integer stack argument) and returns f32; the 72 f32/f64 edge values stay live across 8 calls of @f3
1389note and 8 recursive calls of @f5, and are printed again at the end
1390fn epress to void
1391put fpn 0 20
1392put fr 0 1
1393k = ulong 0
1394while lt k 20 bound 20
1395c = ulong get y_pt k
1396t = sub c 48
1397if ge c 97
1398t = sub c 87
1399end
1400put fp add k 2 t
1401k = add k 1
1402end
1403put fp 60 13
1404hdr
1405epush 14
1406epush 13
1407k = ulong 0
1408while lt k 8 bound 8
1409ocall
1410orec
1411k = add k 1
1412end
1413tail true
1414end
1415
1416note ---- edge programs ----
1417fn epush t ulong to void
1418n = len e64
1419if eq t 13
1420n = len e32
1421end
1422i = ulong 0
1423while lt i n bound 64
1424b = get e64 i
1425if eq t 13
1426b = get e32 i
1427end
1428v = kconst t b
1429addf v t 0
1430i = add i 1
1431end
1432end
1433
1434note eb t: every binary op and compare over every ordered pair of the edge values of t
1435fn eb t ulong to void
1436epush t
1437n = get pn 0
1438i = ulong 0
1439while lt i n bound 64
1440j = ulong 0
1441while lt j n bound 64
1442a = get pv i
1443b = get pv j
1444k = ulong 0
1445while lt k 6 bound 6
1446r = nv
1447wk y_bop k
1448sp
1449wty t
1450sp
1451wv a
1452sp
1453wv b
1454nl
1455pr r t 1
1456k = add k 1
1457end
1458k = ulong 0
1459while lt k 6 bound 6
1460ocmp t a b k
1461k = add k 1
1462end
1463r = nv
1464ws y_fma
1465wty t
1466sp
1467wv a
1468sp
1469wv b
1470sp
1471wv get pv rem add i j n
1472nl
1473pr r t 1
1474j = add j 1
1475end
1476i = add i 1
1477end
1478end
1479
1480note eu t: unary ops, conversions to every integer type and the other width in every mode, bitcasts
1481fn eu t ulong to void
1482epush t
1483n = get pn 0
1484i = ulong 0
1485while lt i n bound 64
1486a = get pv i
1487k = ulong 0
1488while lt k 3 bound 3
1489r = nv
1490wk y_uop k
1491sp
1492wty t
1493sp
1494wv a
1495nl
1496c = ulong 0
1497if eq k 2
1498c = 1
1499end
1500pr r t c
1501k = add k 1
1502end
1503k = ulong 2
1504while le k 9 bound 8
1505of2i a k
1506k = add k 1
1507end
1508if eq t 14
1509of2f a t 0
1510of2f a t 1
1511of2f a t 4
1512of2f a t 5
1513else
1514of2f a t 0
1515end
1516d = ulong 5
1517if eq t 13
1518d = 4
1519end
1520r = nv
1521ws y_bcast
1522wty d
1523sp
1524wv a
1525nl
1526pr r d 0
1527i = add i 1
1528end
1529end
1530
1531note ei: integer edge values of every integer type to f32 and f64, nearest even and toward zero
1532fn ei to void
1533i = ulong 0
1534while lt i len ein bound 64
1535t = ulong 2
1536while le t 9 bound 8
1537v = kconst t get ein i
1538addi v t
1539x = sub get inn 0 1
1540oi2f 14 x 0
1541oi2f 14 x 1
1542oi2f 13 x 0
1543oi2f 13 x 1
1544t = add t 1
1545end
1546i = add i 1
1547end
1548end
1549
1550note ec t: chk.conv of the edge values of t that pass into each integer type (ngrun decides the trap: only the
1551note passing ones are emitted, by the rule of IR.md s7.9 computed here on the bits)
1552fn ec t ulong to void
1553epush t
1554n = get pn 0
1555i = ulong 0
1556while lt i n bound 64
1557k = ulong 2
1558while le k 9 bound 8
1559if cpass t get e64 i k
1560if eq t 14
1561ochk get pv i k
1562of2i get pv i k
1563end
1564end
1565if eq t 13
1566if cpass32 get e32 i k
1567ochk get pv i k
1568of2i get pv i k
1569end
1570end
1571k = add k 1
1572end
1573i = add i 1
1574end
1575end
1576
1577note cpass t b k: f64 bits b (t 14) pass chk.conv into integer type k: not NaN and the truncated value inside;
1578note decided from the exponent, conservatively (a value whose integer part needs the type's width plus one bit,
1579note or any NaN or infinity, is treated as failing and skipped)
1580fn cpass t ulong b ulong k ulong to bool
1581e = and shr b 52 2047
1582s = ne shr b 63 0
1583if eq e 2047
1584ret false
1585end
1586if lt e 1023
1587ret true
1588end
1589p = sub e 1023
1590w = wid k
1591if sgn k
1592ret lt p sub w 1
1593end
1594if s
1595ret false
1596end
1597ret lt p w
1598end
1599
1600fn cpass32 b ulong k ulong to bool
1601e = and shr b 23 255
1602s = ne shr b 31 0
1603if eq e 255
1604ret false
1605end
1606if lt e 127
1607ret true
1608end
1609p = sub e 127
1610w = wid k
1611if sgn k
1612ret lt p sub w 1
1613end
1614if s
1615ret false
1616end
1617ret lt p w
1618end
1619
1620fn edge k ulong to void
1621if ge k 57
1622c = ulong get y_ft sub k 57
1623efill hexd c
1624ret
1625end
1626if eq k 56
1627epress
1628ret
1629end
1630put fpn 0 0
1631put fp 60 14
1632hdr
1633if eq k 1
1634eb 14
1635end
1636if eq k 2
1637eb 13
1638end
1639if eq k 3
1640eu 14
1641end
1642if eq k 4
1643eu 13
1644end
1645if eq k 5
1646ei
1647end
1648if eq k 6
1649ec 14
1650end
1651if eq k 7
1652ec 13
1653end
1654if ge k 8
1655eb8 sub k 8
1656end
1657tail false
1658end
1659
1660note eb8 j: the chk.conv boundary program j (edge 8 + j): integer type 2 + j mod 8, source f32 (j / 8 even) or f64,
1661note case j / 16; the value just inside the upper bound and the one just inside the lower bound pass and convert,
1662note then the upper bound (case 0), the lower trap value (1) or a quiet NaN (2) traps 5
1663fn eb8 j ulong to void
1664k = add 2 rem j 8
1665t = ulong 14
1666if eq rem div j 8 2 0
1667t = 13
1668end
1669c = div j 16
1670a = kconst t sub ebd t k 0 1
1671ochk a k
1672of2i a k
1673a = kconst t ebd t k 2
1674ochk a k
1675of2i a k
1676x = ebd t k 0
1677if eq c 1
1678x = ebd t k 1
1679end
1680if eq c 2
1681x = 0x7ff8000000000000
1682if eq t 13
1683x = 0x7fc00000
1684end
1685end
1686a = kconst t x
1687ochk a k
1688end
1689
1690note ebd t k q: bits of float type t (p fraction bits, exponent bias b) for chk.conv into integer type k: q 0 the
1691note upper bound 2^w (unsigned) or 2^(w-1); q 1 the low trap value -1 (unsigned), -(2^(w-1) + 1) when representable,
1692note else the next value below -2^(w-1); q 2 its neighbour toward zero, which passes
1693fn ebd t ulong k ulong q ulong to ulong
1694p = ulong 52
1695b = ulong 1023
1696sg = ulong 0x8000000000000000
1697if eq t 13
1698p = 23
1699b = 127
1700sg = 0x80000000
1701end
1702m = wid k
1703if sgn k
1704m = sub m 1
1705end
1706if eq q 0
1707ret shl add b m p
1708end
1709lo = or sg shl b p
1710if sgn k
1711if le m p
1712lo = or or sg shl add b m p shl ulong 1 sub p m
1713else
1714lo = add or sg shl add b m p 1
1715if eq q 2
1716ret sub lo 1
1717end
1718ret lo
1719end
1720end
1721if eq q 1
1722ret lo
1723end
1724ret sub lo 1
1725end
1726
1727note ---- fill programs (edges 57..66, op 51; ΩIR arrays and slices hold numbers, so bool is not among them) ----
1728
1729fn hexd c ulong to ulong
1730if ge c 97
1731ret sub c 87
1732end
1733ret sub c 48
1734end
1735
1736fn one1 t ulong to bool
1737ret or eq t 1 eq wid t 8
1738end
1739
1740note efill t: fill program for element type t over a 300-element local array A (alloca, %t39): per case A is filled
1741note whole with a sentinel (fill of the REF), a slice of A at offset O and length L (one case in three a slice of a
1742note slice: offsets O1 then O2, O = O1 + O2) is filled with a value, then all 300 elements are folded, h = 31 h + bits,
1743note and h is printed (sentinels before and after the span, every filled element, each at its own place). Lengths
1744note 0..257 for 1-byte elements (u8, i8), else 0..40 and 63..65, 127..129, 255..257 (the 16-byte block and
1745note tail boundaries of every width); offsets 7 (c + 3) mod 32 cover 0..31. Values and sentinels: random bits, for
1746note f32/f64 half of them from the edge tables (signed zeros, NaN payloads, signaling NaNs), stored bit for bit
1747fn efill t ulong to void
1748put fw 0 t
1749put fpn 0 0
1750put fp 60 14
1751hdr
1752r = get vn 0
1753put vn 0 add r 2
1754wv r
1755sp
1756wv add r 1
1757ws y_eq
1758ws y_alloca
1759ws y_t39
1760wv get tk 0
1761nl
1762put tk 0 r
1763eloop t add r 1
1764tail false
1765end
1766
1767note eloop t a: the cases of efill over the array REF a
1768fn eloop t ulong a ulong to void
1769nc = ulong 50
1770if one1 t
1771nc = 258
1772end
1773c = ulong 0
1774while lt c nc bound 300
1775l = c
1776if and not one1 t ge c 41
1777l = elen sub c 41
1778end
1779o = rem mul add c 3 7 32
1780ecase t a l o eq rem c 3 0
1781c = add c 1
1782end
1783end
1784
1785note elen i: the long lengths 63..65, 127..129, 255..257 (i 0..8)
1786fn elen i ulong to ulong
1787ret add sub shl ulong 1 add 6 div i 3 1 rem i 3
1788end
1789
1790note evalue t: a new constant of element type t for a fill (bool: true or false)
1791fn evalue t ulong to ulong
1792if eq t 1
1793r = nv
1794ws y_const
1795wty 1
1796sp
1797if eq rn 2 0
1798ws y_true
1799else
1800ws y_false
1801end
1802nl
1803ret r
1804end
1805b = rnd
1806if isf t
1807if eq rn 2 0
1808if eq t 14
1809b = get e64 rn len e64
1810else
1811b = get e32 rn len e32
1812end
1813end
1814end
1815ret kconst t b
1816end
1817
1818fn ecase t ulong a ulong l ulong o ulong ns bool to void
1819s = evalue t
1820v = evalue t
1821q = nv
1822ws y_fill
1823wv get tk 0
1824sp
1825wv a
1826sp
1827wv s
1828nl
1829put tk 0 q
1830r = a
1831if ns
1832o1 = div o 2
1833r = eslice a o1 add add l sub o o1 rem l 5
1834r = eslice r sub o o1 l
1835else
1836r = eslice a o l
1837end
1838q = nv
1839ws y_fill
1840wv get tk 0
1841sp
1842wv r
1843sp
1844wv v
1845nl
1846put tk 0 q
1847echk t a
1848end
1849
1850note eslice r o l: chk.slice 3 then slice %t40 of r at offset o, length l; the slice value
1851fn eslice r ulong o ulong l ulong to ulong
1852x = kconst 5 o
1853y = kconst 5 l
1854c = nv
1855ws y_chks
1856wv get tk 0
1857sp
1858wv r
1859sp
1860wv x
1861sp
1862wv y
1863nl
1864put tk 0 c
1865s = nv
1866ws y_slice
1867wv c
1868sp
1869wv r
1870sp
1871wv x
1872sp
1873wv y
1874nl
1875ret s
1876end
1877
1878note echk t a: the fold of the 300 elements of a: a loop (head, body, exit blocks), h = 31 h + bits(a[i]); h printed
1879fn echk t ulong a ulong to void
1880h0 = kconst 5 0
1881i0 = kconst 5 0
1882x = get bn 0
1883put bn 0 add x 3
1884ws y_br
1885wd x
1886sp
1887wv get tk 0
1888sp
1889wv h0
1890sp
1891wv i0
1892nl
1893q = get vn 0
1894put vn 0 add q 3
1895ws y_block
1896wd x
1897sp
1898wv q
1899ws y_tok
1900sp
1901wv add q 1
1902ws y_u64t
1903sp
1904wv add q 2
1905ws y_u64t
1906nl
1907n = kconst 5 300
1908cc = nv
1909wk y_cop 2
1910sp
1911ws y_bool
1912wv add q 2
1913sp
1914wv n
1915nl
1916ws y_cbr
1917wv q
1918sp
1919wv cc
1920oc 32
1921oc 94
1922wd add x 1
1923oc 32
1924oc 94
1925wd add x 2
1926nl
1927ebody t a x q
1928end
1929
1930note ebody t a x q: the loop body (block x + 1) and exit (block x + 2) of echk; q, q + 1, q + 2 the head's parameters
1931fn ebody t ulong a ulong x ulong q ulong to void
1932ws y_block
1933wd add x 1
1934sp
1935q2 = get vn 0
1936put vn 0 add q2 1
1937wv q2
1938ws y_tok
1939nl
1940one = kconst 5 1
1941cb = nv
1942ws y_chkb
1943wv q2
1944sp
1945wv a
1946sp
1947wv add q 2
1948sp
1949wv one
1950nl
1951e = nv
1952ws y_load
1953wty t
1954sp
1955wv cb
1956sp
1957wv a
1958sp
1959wv add q 2
1960nl
1961bb = ebits t e
1962k = kconst 5 31
1963m = nv
1964wk y_bop 2
1965sp
1966wty 5
1967sp
1968wv add q 1
1969sp
1970wv k
1971nl
1972h2 = nv
1973wk y_bop 0
1974sp
1975wty 5
1976sp
1977wv m
1978sp
1979wv bb
1980nl
1981i2 = nv
1982wk y_bop 0
1983sp
1984wty 5
1985sp
1986wv add q 2
1987sp
1988wv one
1989nl
1990ws y_br
1991wd x
1992sp
1993wv cb
1994sp
1995wv h2
1996sp
1997wv i2
1998nl
1999ws y_block
2000wd add x 2
2001sp
2002q3 = get vn 0
2003put vn 0 add q3 1
2004wv q3
2005ws y_tok
2006nl
2007put tk 0 q3
2008pcall 0 add q 1
2009end
2010
2011note ebits t e: element value e of type t as u64 bits (floats bit for bit, integers by conv, bool 1 or 0)
2012fn ebits t ulong e ulong to ulong
2013if eq t 14
2014r = nv
2015ws y_bcast
2016wty 5
2017sp
2018wv e
2019nl
2020ret r
2021end
2022if eq t 13
2023y = nv
2024ws y_bcast
2025wty 4
2026sp
2027wv e
2028nl
2029r = nv
2030ws y_conv
2031wty 5
2032sp
2033oc 48
2034sp
2035wv y
2036nl
2037ret r
2038end
2039if eq t 1
2040r = nv
2041ws y_sel
2042wty 5
2043sp
2044wv e
2045sp
2046wv get ra 0
2047sp
2048wv get ra 1
2049nl
2050ret r
2051end
2052if eq t 5
2053ret e
2054end
2055r = nv
2056ws y_conv
2057wty 5
2058sp
2059oc 48
2060sp
2061wv e
2062nl
2063ret r
2064end
2065
2066fn arg a ulong to ulong
2067m = argread a y_pa 0 4096
2068if or le m 0 ge m 4096
2069r = write 2 y_use 0 len y_use
2070exit 2
2071end
2072ret ulong m
2073end
2074
2075fn dec m ulong to ulong
2076v = ulong 0
2077for j ulong m bound 4096
2078c = ulong get y_pa j
2079if or lt c 48 gt c 57
2080r = write 2 y_use 0 len y_use
2081exit 2
2082end
2083v = add mul v 10 sub c 48
2084end
2085ret v
2086end
2087
2088fn main to int
2089ini
2090if eq argcnt 3
2091m = arg 1
2092if ne m len y_edge
2093r = write 2 y_use 0 len y_use
2094ret 2
2095end
2096for j ulong m bound 8
2097if ne get y_pa j get y_edge j
2098r = write 2 y_use 0 len y_use
2099ret 2
2100end
2101end
2102k = dec arg 2
2103if or lt k 1 gt k 66
2104r = write 2 y_use 0 len y_use
2105ret 2
2106end
2107put rs 0 k
2108edge k
2109else
2110if ne argcnt 2
2111r = write 2 y_use 0 len y_use
2112ret 2
2113end
2114s = dec arg 1
2115put rs 0 s
2116gen
2117end
2118if not flush
2119r = write 2 y_io 0 len y_io
2120ret 1
2121end
2122ret 0
2123end