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