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 / core / rsi / om / reuse-eval / gen.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gen.om: the REUSE-1 workload generator of the evaluator (docs/reuse/REUSE-1.md v1.0 section 7, |
| 3 | note /tmp/reuse/EVAL-FORMATS.md layout, integrator clarifications K2, K6, K8). |
| 4 | note Units before it: sha256, ref. Prefix gn / GN. Holds fn main. |
| 5 | note |
| 6 | note gen SPLIT OUTDIR [SEEDHEX] |
| 7 | note SPLIT: TRAIN (id 1), CALIB (2), DEV (3), FINAL (4), TRAINP (5). SEEDHEX (64 hex characters, the |
| 8 | note 32-byte FINAL seed) is required for FINAL and refused otherwise; the FINAL generator seed is its |
| 9 | note bytes 8..15 read little endian. Public seeds: TRAIN 1001, TRAINP 1002, CALIB 1003, DEV 1004. |
| 10 | note Writes OUTDIR/index, OUTDIR/sessions, OUTDIR/gNN.req, OUTDIR/gNN.exp (OUTDIR is created when |
| 11 | note missing), prints one summary line. Exit 0 ok, 2 usage, 3 file error, 4 generation failure |
| 12 | note (a reference status other than 0, or an impossible draw such as no MIN/MAX shape for type A). |
| 13 | note |
| 14 | note Randomness: splitmix64 only. Each purpose has its own stream, seeded with |
| 15 | note sub(seed, tag) = mix(seed + tag * 0x9E3779B97F4A7C15) (mix = the splitmix64 finalizer): |
| 16 | note tag 1 shape pool, 2 TRAIN list (machines, session programs, n), 3 composition (programs and the |
| 17 | note dealing permutation of FINAL, DEV and CALIB), 4 data (states and changes, in request order). |
| 18 | note A draw below m is the next output mod m (bias below m / 2^64, at most 2^-51 here). |
| 19 | note |
| 20 | note Splits (contract 7; K8 a..h): |
| 21 | note - shape pool: 24 distinct AGG shapes (wl 8 or 16, f 1..6, k 1..6, ops 1..8) drawn from the |
| 22 | note TRAIN seed; TRAINP's 24 are drawn from 1002 and exclude TRAIN's. Pool rank r has weight |
| 23 | note L / (r + 1), L = lcm(1..24) = 5354228880, so the weights are exactly 1 / (rank + 1). |
| 24 | note - TRAIN / TRAINP: 240 sessions in generation order, session s is FSM iff s mod 6 = 5; 10 machines |
| 25 | note (0..4 general, 5..9 permutation machines), FSM session number f uses machine f mod 10; AGG |
| 26 | note session number j reuses a uniformly chosen earlier AGG program exactly iff j mod 4 = 3, else a |
| 27 | note pool shape by weight with new constants; n uniform in {64, 512, 4096}; BEGIN + 8 x (SET, QUERY). |
| 28 | note - FINAL / DEV: 2 families x 8 types x 3 n x 4 = 192 sessions, dealt into 24 groups of 8 by a |
| 29 | note seeded permutation. AGG types Z..P: 1 recall (a TRAIN AGG program), 2 transfer (a TRAIN pool |
| 30 | note shape by weight, new constants, not equal to any TRAIN program), 1 novel (a shape outside both |
| 31 | note pools); C: 4 novel; type A only uses f MIN or MAX (fails when TRAIN has none). FSM: 2 recall |
| 32 | note (TRAIN machines), 2 new; type C 4 new; type A permutation machines (recall from machines 5..9). |
| 33 | note Bodies: Z 32 QUERY; S and C 64 (SET, QUERY); D 8 (BATCH of 1024 SET, QUERY); R 64 (SWAP, |
| 34 | note QUERY); I 64 (DEL, INS alternating from DEL, QUERY); A AGG 64 (DEL of the first index whose |
| 35 | note mapped value is the current fold result, INS of a random value at a random index, QUERY); |
| 36 | note A FSM 64 (SET at index 0 to a symbol whose transition from s0 differs from the current one, |
| 37 | note QUERY); P 16 QUERY with a PROGRAM before QUERY 4, 8, 12, 16 (AGG same shape new constants, |
| 38 | note FSM same S and A new s0, lambda and rules). |
| 39 | note - CALIB: 2 families x 3 n x 4 change classes x 4 = 96 sessions, dealt into 12 groups of 8; each |
| 40 | note BEGIN + 16 x (change, QUERY), change = none (type Z), one SET (S), BATCH of 2..64 SET (D) or |
| 41 | note BATCH of 1024 SET (D); AGG programs = pool shapes by weight with new constants, FSM general. |
| 42 | note Every expected response is ref.om's (rfreq); any status other than 0 fails the run (exit 4). |
| 43 | note Permutation machines: S 4..8, A 4..16, the alphabet cut into 2 or 3 intervals; interval 0 is a |
| 44 | note rotation by 1..S-1, the others random permutations; one rule (s, lo, hi, pi(s)) per moved |
| 45 | note state, so every symbol's transition is a permutation of the states; s0 must have two |
| 46 | note different successors (redrawn otherwise), so a SET at index 0 can always change q_1. |
| 47 | |
| 48 | global GNRS ulong 4 |
| 49 | global GNTP ulong 24 |
| 50 | global GNPP ulong 24 |
| 51 | global GNLM ulong 640 |
| 52 | global GNLP ulong 15360 |
| 53 | global GNLF ulong 240 |
| 54 | global GNLN ulong 240 |
| 55 | global GNLA ulong 240 |
| 56 | global GNPG ulong 64 |
| 57 | global GNSP ulong 15360 |
| 58 | global GNSM ulong 1920 |
| 59 | global GNSO ulong 240 |
| 60 | global GNSS ulong 3840 |
| 61 | global GNOB uchar 16777216 |
| 62 | global GNEB uchar 4194304 |
| 63 | global GNWB uchar 65536 |
| 64 | global GNPA uchar 4096 |
| 65 | global GNAR uchar 4096 |
| 66 | global GNCT ulong 32 |
| 67 | global GNGR ulong 100 |
| 68 | global GNFD long 4 |
| 69 | text gntsess "/sessions" |
| 70 | text gntidx "/index" |
| 71 | text gnemm "gen: type A needs a MIN or MAX program and the TRAIN pool or list has none\n" |
| 72 | text gneus "usage: gen TRAIN|TRAINP|CALIB|DEV|FINAL OUTDIR [SEEDHEX (FINAL only)]\n" |
| 73 | text gneio "gen: file error\n" |
| 74 | text gnegen "gen: generation failure\n" |
| 75 | |
| 76 | note GNCT: 0 exit code, 1 split id, 2 session count, 3 group count, 4 OUTDIR length, 5 GNOB fill, |
| 77 | note 6 GNEB fill, 7 requests, 8 QUERYs, 9 request index in group, 10 session requests, |
| 78 | note 11 session QUERYs, 12 cold pending, 13 session ordinal, 14 seed, 15 GNWB fill, |
| 79 | note 16 TRAIN pool MIN/MAX shapes |
| 80 | |
| 81 | note ---- splitmix64 ---- |
| 82 | |
| 83 | fn gnmix z ulong to ulong |
| 84 | a = mul xor z shr z 30 13787848793156543929 |
| 85 | b = mul xor a shr a 27 10723151780598845931 |
| 86 | ret xor b shr b 31 |
| 87 | end |
| 88 | |
| 89 | fn gnsub seed ulong tag ulong to ulong |
| 90 | ret gnmix add seed mul tag 11400714819323198485 |
| 91 | end |
| 92 | |
| 93 | fn gnrnd k ulong to ulong |
| 94 | s = add get GNRS k 11400714819323198485 |
| 95 | put GNRS k s |
| 96 | ret gnmix s |
| 97 | end |
| 98 | |
| 99 | fn gnbelow k ulong m ulong to ulong |
| 100 | ret rem gnrnd k m |
| 101 | end |
| 102 | |
| 103 | fn gnfail code ulong to void |
| 104 | if eq get GNCT 0 0 |
| 105 | put GNCT 0 code |
| 106 | end |
| 107 | end |
| 108 | |
| 109 | note ---- shapes and programs ---- |
| 110 | |
| 111 | fn gnshape k ulong fsel ulong to ulong |
| 112 | wl = ulong 8 |
| 113 | if eq gnbelow k 2 1 |
| 114 | wl = 16 |
| 115 | end |
| 116 | f = ulong 0 |
| 117 | if eq fsel 1 |
| 118 | f = add 3 gnbelow k 2 |
| 119 | else |
| 120 | f = add 1 gnbelow k 6 |
| 121 | end |
| 122 | kk = add 1 gnbelow k 6 |
| 123 | s = add add wl mul 256 f mul 4096 kk |
| 124 | m = ulong 65536 |
| 125 | for j ulong kk |
| 126 | s = add s mul m add 1 gnbelow k 8 |
| 127 | m = mul m 16 |
| 128 | end |
| 129 | ret s |
| 130 | end |
| 131 | |
| 132 | fn gnfok s ulong fsel ulong to bool |
| 133 | if eq fsel 0 |
| 134 | ret true |
| 135 | end |
| 136 | f = and shr s 8 15 |
| 137 | ret or eq f 3 eq f 4 |
| 138 | end |
| 139 | |
| 140 | fn gnclrpg fam ulong to void |
| 141 | for i ulong 64 |
| 142 | put GNPG i 0 |
| 143 | end |
| 144 | put GNPG 0 3544411312749556050 |
| 145 | put GNPG 1 fam |
| 146 | end |
| 147 | |
| 148 | fn gnconst k ulong wl ulong op ulong to ulong |
| 149 | if ge op 7 |
| 150 | ret gnbelow k wl |
| 151 | end |
| 152 | ret gnbelow k shl ulong 1 wl |
| 153 | end |
| 154 | |
| 155 | note an AGG program of shape s with random constants into GNPG |
| 156 | fn gnprog s ulong k ulong to void |
| 157 | gnclrpg 1 |
| 158 | wl = and s 255 |
| 159 | put GNPG 2 wl |
| 160 | put GNPG 3 and shr s 8 15 |
| 161 | kk = and shr s 12 15 |
| 162 | put GNPG 4 kk |
| 163 | for j ulong kk |
| 164 | op = and shr s add 16 mul j 4 15 |
| 165 | c = gnconst k wl op |
| 166 | put GNPG add 5 mul j 2 op |
| 167 | put GNPG add 6 mul j 2 c |
| 168 | end |
| 169 | end |
| 170 | |
| 171 | fn gnrule k ulong s ulong a ulong to ulong |
| 172 | rs = gnbelow k s |
| 173 | x = gnbelow k a |
| 174 | y = gnbelow k a |
| 175 | t = gnbelow k s |
| 176 | if gt x y |
| 177 | z = x |
| 178 | x = y |
| 179 | y = z |
| 180 | end |
| 181 | ret add add rs shl x 8 add shl y 16 shl t 24 |
| 182 | end |
| 183 | |
| 184 | note a general FSM into GNPG; sa, aa = 0 draw S, A, otherwise keep them |
| 185 | fn gnmach k ulong sa ulong aa ulong to void |
| 186 | gnclrpg 2 |
| 187 | s = sa |
| 188 | if eq s 0 |
| 189 | s = add 2 gnbelow k 15 |
| 190 | end |
| 191 | a = aa |
| 192 | if eq a 0 |
| 193 | a = add 2 gnbelow k 15 |
| 194 | end |
| 195 | put GNPG 2 s |
| 196 | put GNPG 3 a |
| 197 | put GNPG 4 gnbelow k s |
| 198 | r = add 1 gnbelow k 24 |
| 199 | put GNPG 5 r |
| 200 | for i ulong s |
| 201 | put GNPG add 6 i gnbelow k 256 |
| 202 | end |
| 203 | for j ulong r |
| 204 | put GNPG add 22 j gnrule k s a |
| 205 | end |
| 206 | end |
| 207 | |
| 208 | fn gnaddr r ulong st ulong lo ulong hi ulong t ulong to ulong |
| 209 | w = add add st shl lo 8 add shl hi 16 shl t 24 |
| 210 | put GNPG add 22 r w |
| 211 | ret add r 1 |
| 212 | end |
| 213 | |
| 214 | note symbols lo..hi: a random permutation of the S states, one rule per moved state |
| 215 | fn gnpint k ulong s ulong lo ulong hi ulong r ulong to ulong |
| 216 | p = new ulong 16 0 |
| 217 | for i ulong s |
| 218 | put p i i |
| 219 | end |
| 220 | j = s |
| 221 | while gt j 1 bound 16 |
| 222 | u = gnbelow k j |
| 223 | j = sub j 1 |
| 224 | t = get p j |
| 225 | put p j get p u |
| 226 | put p u t |
| 227 | end |
| 228 | rr = r |
| 229 | for st ulong s |
| 230 | if ne get p st st |
| 231 | rr = gnaddr rr st lo hi get p st |
| 232 | end |
| 233 | end |
| 234 | ret rr |
| 235 | end |
| 236 | |
| 237 | note FSM transition of the machine in GNPG (the rule order of contract 1.2) |
| 238 | fn gndel s ulong a ulong to ulong |
| 239 | r = get GNPG 5 |
| 240 | for i ulong r |
| 241 | w = get GNPG add 22 i |
| 242 | if eq and w 255 s |
| 243 | lo = and shr w 8 255 |
| 244 | hi = and shr w 16 255 |
| 245 | if and le lo a le a hi |
| 246 | ret shr w 24 |
| 247 | end |
| 248 | end |
| 249 | end |
| 250 | ret s |
| 251 | end |
| 252 | |
| 253 | fn gnpermok to bool |
| 254 | s0 = get GNPG 4 |
| 255 | a = get GNPG 3 |
| 256 | i0 = gndel s0 0 |
| 257 | for x ulong a |
| 258 | if ne gndel s0 x i0 |
| 259 | ret true |
| 260 | end |
| 261 | end |
| 262 | ret false |
| 263 | end |
| 264 | |
| 265 | fn gnperm1 k ulong to void |
| 266 | gnclrpg 2 |
| 267 | s = add 4 gnbelow k 5 |
| 268 | a = add 4 gnbelow k 13 |
| 269 | put GNPG 2 s |
| 270 | put GNPG 3 a |
| 271 | put GNPG 4 gnbelow k s |
| 272 | for i ulong s |
| 273 | put GNPG add 6 i gnbelow k 256 |
| 274 | end |
| 275 | b1 = add 1 gnbelow k sub a 1 |
| 276 | b2 = a |
| 277 | if eq gnbelow k 2 1 |
| 278 | c = add 1 gnbelow k sub a 1 |
| 279 | while eq c b1 bound 999 |
| 280 | c = add 1 gnbelow k sub a 1 |
| 281 | end |
| 282 | if lt c b1 |
| 283 | b2 = b1 |
| 284 | b1 = c |
| 285 | else |
| 286 | b2 = c |
| 287 | end |
| 288 | end |
| 289 | rot = add 1 gnbelow k sub s 1 |
| 290 | r = ulong 0 |
| 291 | for st ulong s |
| 292 | r = gnaddr r st 0 sub b1 1 rem add st rot s |
| 293 | end |
| 294 | r = gnpint k s b1 sub b2 1 r |
| 295 | if lt b2 a |
| 296 | r = gnpint k s b2 sub a 1 r |
| 297 | end |
| 298 | put GNPG 5 r |
| 299 | end |
| 300 | |
| 301 | note a permutation machine into GNPG: 0 ok, 1 none found |
| 302 | fn gnperm k ulong to ulong |
| 303 | for t ulong 64 |
| 304 | gnperm1 k |
| 305 | if gnpermok |
| 306 | ret 0 |
| 307 | end |
| 308 | end |
| 309 | ret 1 |
| 310 | end |
| 311 | |
| 312 | note ---- pools and the TRAIN / TRAINP list ---- |
| 313 | |
| 314 | fn gnpget which ulong r ulong to ulong |
| 315 | if eq which 1 |
| 316 | ret get GNTP r |
| 317 | end |
| 318 | ret get GNPP r |
| 319 | end |
| 320 | |
| 321 | fn gnphas which ulong s ulong cnt ulong to bool |
| 322 | for i ulong cnt |
| 323 | if eq gnpget which i s |
| 324 | ret true |
| 325 | end |
| 326 | end |
| 327 | ret false |
| 328 | end |
| 329 | |
| 330 | fn gnpool which ulong to void |
| 331 | seed = ulong 1001 |
| 332 | if eq which 5 |
| 333 | seed = 1002 |
| 334 | end |
| 335 | put GNRS 0 gnsub seed 1 |
| 336 | i = ulong 0 |
| 337 | while lt i 24 bound 99999 |
| 338 | s = gnshape 0 0 |
| 339 | ok = not gnphas which s i |
| 340 | if eq which 5 |
| 341 | if gnphas 1 s 24 |
| 342 | ok = false |
| 343 | end |
| 344 | end |
| 345 | if ok |
| 346 | if eq which 1 |
| 347 | put GNTP i s |
| 348 | else |
| 349 | put GNPP i s |
| 350 | end |
| 351 | i = add i 1 |
| 352 | end |
| 353 | end |
| 354 | end |
| 355 | |
| 356 | note a pool shape by weight 1 / (rank + 1), restricted by fsel; 0 when none qualifies |
| 357 | fn gnpick which ulong fsel ulong k ulong to ulong |
| 358 | tot = ulong 0 |
| 359 | for r ulong 24 |
| 360 | if gnfok gnpget which r fsel |
| 361 | tot = add tot div 5354228880 add r 1 |
| 362 | end |
| 363 | end |
| 364 | if eq tot 0 |
| 365 | ret 0 |
| 366 | end |
| 367 | u = gnbelow k tot |
| 368 | for q ulong 24 |
| 369 | s = gnpget which q |
| 370 | if gnfok s fsel |
| 371 | w = div 5354228880 add q 1 |
| 372 | if lt u w |
| 373 | ret s |
| 374 | end |
| 375 | u = sub u w |
| 376 | end |
| 377 | end |
| 378 | ret 0 |
| 379 | end |
| 380 | |
| 381 | fn gncplm i ulong to void |
| 382 | for j ulong 64 |
| 383 | put GNLM add mul i 64 j get GNPG j |
| 384 | end |
| 385 | end |
| 386 | |
| 387 | fn gncplp s ulong to void |
| 388 | for j ulong 64 |
| 389 | put GNLP add mul s 64 j get GNPG j |
| 390 | end |
| 391 | end |
| 392 | |
| 393 | fn gnlpto d ulong s ulong to void |
| 394 | for j ulong 64 |
| 395 | put GNLP add mul d 64 j get GNLP add mul s 64 j |
| 396 | end |
| 397 | end |
| 398 | |
| 399 | fn gnlmto d ulong i ulong to void |
| 400 | for j ulong 64 |
| 401 | put GNLP add mul d 64 j get GNLM add mul i 64 j |
| 402 | end |
| 403 | end |
| 404 | |
| 405 | fn gnnsize k ulong to ulong |
| 406 | u = gnbelow k 3 |
| 407 | if eq u 0 |
| 408 | ret 64 |
| 409 | end |
| 410 | if eq u 1 |
| 411 | ret 512 |
| 412 | end |
| 413 | ret 4096 |
| 414 | end |
| 415 | |
| 416 | note the 240 sessions of TRAIN (which 1) or TRAINP (5) into GNLP, GNLF, GNLN; machines into GNLM |
| 417 | fn gnlist which ulong to void |
| 418 | seed = ulong 1001 |
| 419 | if eq which 5 |
| 420 | seed = 1002 |
| 421 | end |
| 422 | put GNRS 0 gnsub seed 2 |
| 423 | for i ulong 10 |
| 424 | if lt i 5 |
| 425 | gnmach 0 0 0 |
| 426 | else |
| 427 | if ne gnperm 0 0 |
| 428 | gnfail 4 |
| 429 | ret |
| 430 | end |
| 431 | end |
| 432 | gncplm i |
| 433 | end |
| 434 | na = ulong 0 |
| 435 | for s ulong 240 |
| 436 | put GNLN s gnnsize 0 |
| 437 | if eq rem s 6 5 |
| 438 | put GNLF s 2 |
| 439 | gnlmto s rem div s 6 10 |
| 440 | else |
| 441 | put GNLF s 1 |
| 442 | if eq rem na 4 3 |
| 443 | e = gnbelow 0 na |
| 444 | gnlpto s get GNLA e |
| 445 | else |
| 446 | gnprog gnpick which 0 0 0 |
| 447 | gncplp s |
| 448 | end |
| 449 | put GNLA na s |
| 450 | na = add na 1 |
| 451 | end |
| 452 | end |
| 453 | end |
| 454 | |
| 455 | note ---- FINAL / DEV composition ---- |
| 456 | |
| 457 | fn gnlpeq s ulong to bool |
| 458 | for j ulong 64 |
| 459 | if ne get GNPG j get GNLP add mul s 64 j |
| 460 | ret false |
| 461 | end |
| 462 | end |
| 463 | ret true |
| 464 | end |
| 465 | |
| 466 | fn gnlmeq i ulong to bool |
| 467 | for j ulong 64 |
| 468 | if ne get GNPG j get GNLM add mul i 64 j |
| 469 | ret false |
| 470 | end |
| 471 | end |
| 472 | ret true |
| 473 | end |
| 474 | |
| 475 | fn gnintr to bool |
| 476 | for s ulong 240 |
| 477 | if eq get GNLF s 1 |
| 478 | if gnlpeq s |
| 479 | ret true |
| 480 | end |
| 481 | end |
| 482 | end |
| 483 | ret false |
| 484 | end |
| 485 | |
| 486 | fn gninmach to bool |
| 487 | for i ulong 10 |
| 488 | if gnlmeq i |
| 489 | ret true |
| 490 | end |
| 491 | end |
| 492 | ret false |
| 493 | end |
| 494 | |
| 495 | note recall: a uniformly chosen TRAIN AGG session program (f filtered) into GNPG; 1 if none |
| 496 | fn gnrecall fsel ulong to ulong |
| 497 | cnt = ulong 0 |
| 498 | for s ulong 240 |
| 499 | if eq get GNLF s 1 |
| 500 | if gnfokf get GNLP add mul s 64 3 fsel |
| 501 | cnt = add cnt 1 |
| 502 | end |
| 503 | end |
| 504 | end |
| 505 | if eq cnt 0 |
| 506 | ret 1 |
| 507 | end |
| 508 | u = gnbelow 0 cnt |
| 509 | for t ulong 240 |
| 510 | if eq get GNLF t 1 |
| 511 | if gnfokf get GNLP add mul t 64 3 fsel |
| 512 | if eq u 0 |
| 513 | for j ulong 64 |
| 514 | put GNPG j get GNLP add mul t 64 j |
| 515 | end |
| 516 | ret 0 |
| 517 | end |
| 518 | u = sub u 1 |
| 519 | end |
| 520 | end |
| 521 | end |
| 522 | ret 1 |
| 523 | end |
| 524 | |
| 525 | note note: gnfok reads f from bits 8..11 of a shape id; for a PROG word 3 (f itself) use gnfokf |
| 526 | fn gnfokf f ulong fsel ulong to bool |
| 527 | if eq fsel 0 |
| 528 | ret true |
| 529 | end |
| 530 | ret or eq f 3 eq f 4 |
| 531 | end |
| 532 | |
| 533 | note shape id of the AGG program in GNLP row s (contract 1.1) |
| 534 | fn gnrowsh s ulong to ulong |
| 535 | b = mul s 64 |
| 536 | k = get GNLP add b 4 |
| 537 | v = add get GNLP add b 2 mul 256 get GNLP add b 3 |
| 538 | v = add v mul 4096 k |
| 539 | m = ulong 65536 |
| 540 | for j ulong k |
| 541 | v = add v mul m get GNLP add b add 5 mul j 2 |
| 542 | m = mul m 16 |
| 543 | end |
| 544 | ret v |
| 545 | end |
| 546 | |
| 547 | note a shape is seen when some TRAIN AGG session program has it |
| 548 | fn gnseen sh ulong to bool |
| 549 | for s ulong 240 |
| 550 | if eq get GNLF s 1 |
| 551 | if eq gnrowsh s sh |
| 552 | ret true |
| 553 | end |
| 554 | end |
| 555 | end |
| 556 | ret false |
| 557 | end |
| 558 | |
| 559 | note transfer: a TRAIN pool shape by weight that TRAIN sessions used, new constants that equal |
| 560 | note no TRAIN program; 1 when none is found |
| 561 | fn gntransf fsel ulong to ulong |
| 562 | for a ulong 64 |
| 563 | s = gnpick 1 fsel 0 |
| 564 | if eq s 0 |
| 565 | ret 1 |
| 566 | end |
| 567 | if gnseen s |
| 568 | for b ulong 64 |
| 569 | gnprog s 0 |
| 570 | if not gnintr |
| 571 | ret 0 |
| 572 | end |
| 573 | end |
| 574 | end |
| 575 | end |
| 576 | ret 1 |
| 577 | end |
| 578 | |
| 579 | fn gnnovel fsel ulong to ulong |
| 580 | for a ulong 99999 |
| 581 | s = gnshape 0 fsel |
| 582 | if not or gnphas 1 s 24 gnphas 5 s 24 |
| 583 | gnprog s 0 |
| 584 | ret 0 |
| 585 | end |
| 586 | end |
| 587 | ret 1 |
| 588 | end |
| 589 | |
| 590 | fn gnfsmnew adv ulong to ulong |
| 591 | for a ulong 999 |
| 592 | if eq adv 1 |
| 593 | if ne gnperm 0 0 |
| 594 | ret 1 |
| 595 | end |
| 596 | else |
| 597 | gnmach 0 0 0 |
| 598 | end |
| 599 | if not gninmach |
| 600 | ret 0 |
| 601 | end |
| 602 | end |
| 603 | ret 1 |
| 604 | end |
| 605 | |
| 606 | fn gnfsmold adv ulong to void |
| 607 | i = gnbelow 0 10 |
| 608 | if eq adv 1 |
| 609 | i = add 5 gnbelow 0 5 |
| 610 | end |
| 611 | for j ulong 64 |
| 612 | put GNPG j get GNLM add mul i 64 j |
| 613 | end |
| 614 | end |
| 615 | |
| 616 | fn gnsetsp c ulong fam ulong typ ulong nov ulong n ulong body ulong to void |
| 617 | for j ulong 64 |
| 618 | put GNSP add mul c 64 j get GNPG j |
| 619 | end |
| 620 | b = mul c 8 |
| 621 | put GNSM b fam |
| 622 | put GNSM add b 1 typ |
| 623 | put GNSM add b 2 nov |
| 624 | put GNSM add b 3 n |
| 625 | put GNSM add b 4 body |
| 626 | end |
| 627 | |
| 628 | fn gnnof i ulong to ulong |
| 629 | if eq i 0 |
| 630 | ret 64 |
| 631 | end |
| 632 | if eq i 1 |
| 633 | ret 512 |
| 634 | end |
| 635 | ret 4096 |
| 636 | end |
| 637 | |
| 638 | note one FINAL / DEV session of the composition: 0 ok, else failure |
| 639 | fn gncsess c ulong fam ulong typ ulong n ulong j ulong to ulong |
| 640 | adv = ulong 0 |
| 641 | if eq typ 6 |
| 642 | adv = 1 |
| 643 | end |
| 644 | nov = ulong 0 |
| 645 | st = ulong 0 |
| 646 | if eq fam 1 |
| 647 | nov = 2 |
| 648 | if eq j 0 |
| 649 | nov = 1 |
| 650 | end |
| 651 | if or eq j 3 eq typ 8 |
| 652 | nov = 3 |
| 653 | end |
| 654 | if eq nov 1 |
| 655 | st = gnrecall adv |
| 656 | end |
| 657 | if eq nov 2 |
| 658 | st = gntransf adv |
| 659 | end |
| 660 | if eq nov 3 |
| 661 | st = gnnovel adv |
| 662 | end |
| 663 | else |
| 664 | nov = 4 |
| 665 | if or ge j 2 eq typ 8 |
| 666 | nov = 5 |
| 667 | end |
| 668 | if eq nov 4 |
| 669 | gnfsmold adv |
| 670 | else |
| 671 | st = gnfsmnew adv |
| 672 | end |
| 673 | end |
| 674 | gnsetsp c fam typ nov n typ |
| 675 | ret st |
| 676 | end |
| 677 | |
| 678 | fn gndeal cnt ulong to void |
| 679 | for i ulong cnt |
| 680 | put GNSO i i |
| 681 | end |
| 682 | j = cnt |
| 683 | while gt j 1 bound 240 |
| 684 | u = gnbelow 0 j |
| 685 | j = sub j 1 |
| 686 | t = get GNSO j |
| 687 | put GNSO j get GNSO u |
| 688 | put GNSO u t |
| 689 | end |
| 690 | end |
| 691 | |
| 692 | fn gncomp to void |
| 693 | put GNRS 0 gnsub get GNCT 14 3 |
| 694 | for c ulong 192 |
| 695 | fam = add 1 div c 96 |
| 696 | typ = add 1 rem div c 12 8 |
| 697 | n = gnnof rem div c 4 3 |
| 698 | st = gncsess c fam typ n rem c 4 |
| 699 | if ne st 0 |
| 700 | x = write 2 gnemm 0 len gnemm |
| 701 | gnfail 4 |
| 702 | ret |
| 703 | end |
| 704 | end |
| 705 | gndeal 192 |
| 706 | put GNCT 2 192 |
| 707 | end |
| 708 | |
| 709 | fn gncalib to void |
| 710 | put GNRS 0 gnsub get GNCT 14 3 |
| 711 | for c ulong 96 |
| 712 | fam = add 1 div c 48 |
| 713 | n = gnnof rem div c 16 3 |
| 714 | cc = rem div c 4 4 |
| 715 | if eq fam 1 |
| 716 | gnprog gnpick 1 0 0 0 |
| 717 | else |
| 718 | gnmach 0 0 0 |
| 719 | end |
| 720 | typ = ulong 3 |
| 721 | if eq cc 0 |
| 722 | typ = 1 |
| 723 | end |
| 724 | if eq cc 1 |
| 725 | typ = 2 |
| 726 | end |
| 727 | gnsetsp c fam typ 0 n add 10 cc |
| 728 | end |
| 729 | gndeal 96 |
| 730 | put GNCT 2 96 |
| 731 | end |
| 732 | |
| 733 | fn gnfromls to void |
| 734 | for s ulong 240 |
| 735 | for j ulong 64 |
| 736 | put GNPG j get GNLP add mul s 64 j |
| 737 | end |
| 738 | gnsetsp s get GNLF s 2 0 get GNLN s 9 |
| 739 | put GNSO s s |
| 740 | end |
| 741 | put GNCT 2 240 |
| 742 | end |
| 743 | |
| 744 | note ---- output buffers and files ---- |
| 745 | |
| 746 | fn gnpb x ulong to void |
| 747 | o = get GNCT 5 |
| 748 | v = x |
| 749 | for i ulong 8 |
| 750 | put GNOB add o i uchar and v 255 |
| 751 | v = shr v 8 |
| 752 | end |
| 753 | put GNCT 5 add o 8 |
| 754 | end |
| 755 | |
| 756 | fn gnpe x ulong to void |
| 757 | o = get GNCT 6 |
| 758 | v = x |
| 759 | for i ulong 8 |
| 760 | put GNEB add o i uchar and v 255 |
| 761 | v = shr v 8 |
| 762 | end |
| 763 | put GNCT 6 add o 8 |
| 764 | end |
| 765 | |
| 766 | fn gnpw x ulong to void |
| 767 | o = get GNCT 15 |
| 768 | v = x |
| 769 | for i ulong 8 |
| 770 | put GNWB add o i uchar and v 255 |
| 771 | v = shr v 8 |
| 772 | end |
| 773 | put GNCT 15 add o 8 |
| 774 | end |
| 775 | |
| 776 | fn gnwrob n ulong to void |
| 777 | fd = int get GNFD 0 |
| 778 | off = ulong 0 |
| 779 | while lt off n bound 99999 |
| 780 | r = write fd GNOB off sub n off |
| 781 | if le r 0 |
| 782 | gnfail 3 |
| 783 | ret |
| 784 | end |
| 785 | off = add off ulong r |
| 786 | end |
| 787 | end |
| 788 | |
| 789 | fn gnwreb n ulong to void |
| 790 | fd = int get GNFD 1 |
| 791 | off = ulong 0 |
| 792 | while lt off n bound 99999 |
| 793 | r = write fd GNEB off sub n off |
| 794 | if le r 0 |
| 795 | gnfail 3 |
| 796 | ret |
| 797 | end |
| 798 | off = add off ulong r |
| 799 | end |
| 800 | end |
| 801 | |
| 802 | fn gnwrwb n ulong to void |
| 803 | fd = int get GNFD 2 |
| 804 | off = ulong 0 |
| 805 | while lt off n bound 99999 |
| 806 | r = write fd GNWB off sub n off |
| 807 | if le r 0 |
| 808 | gnfail 3 |
| 809 | ret |
| 810 | end |
| 811 | off = add off ulong r |
| 812 | end |
| 813 | end |
| 814 | |
| 815 | note request bytes: absorbed into the holdout digest (slot 1) in file order, then written |
| 816 | fn gnflreq to void |
| 817 | n = get GNCT 5 |
| 818 | off = ulong 0 |
| 819 | while lt off n bound 999 |
| 820 | k = sub n off |
| 821 | if gt k 65536 |
| 822 | k = 65536 |
| 823 | end |
| 824 | for i ulong k |
| 825 | put RFHB i get GNOB add off i |
| 826 | end |
| 827 | rfhabs 1 k |
| 828 | off = add off k |
| 829 | end |
| 830 | gnwrob n |
| 831 | put GNCT 5 0 |
| 832 | end |
| 833 | |
| 834 | fn gnflexp to void |
| 835 | gnwreb get GNCT 6 |
| 836 | put GNCT 6 0 |
| 837 | end |
| 838 | |
| 839 | fn gngpath g ulong ext ulong to ulong |
| 840 | l = get GNCT 4 |
| 841 | put GNPA l 47 |
| 842 | put GNPA add l 1 103 |
| 843 | put GNPA add l 2 uchar add 48 div g 10 |
| 844 | put GNPA add l 3 uchar add 48 rem g 10 |
| 845 | put GNPA add l 4 46 |
| 846 | if eq ext 0 |
| 847 | put GNPA add l 5 114 |
| 848 | put GNPA add l 6 101 |
| 849 | put GNPA add l 7 113 |
| 850 | else |
| 851 | put GNPA add l 5 101 |
| 852 | put GNPA add l 6 120 |
| 853 | put GNPA add l 7 112 |
| 854 | end |
| 855 | ret add l 8 |
| 856 | end |
| 857 | |
| 858 | fn gnopen slot ulong pl ulong to void |
| 859 | fd = fopen GNPA 0 pl 577 420 |
| 860 | if lt fd 0 |
| 861 | gnfail 3 |
| 862 | fd = -1 |
| 863 | end |
| 864 | put GNFD slot fd |
| 865 | end |
| 866 | |
| 867 | fn gnclose slot ulong to void |
| 868 | fd = int get GNFD slot |
| 869 | if ge fd 0 |
| 870 | r = fclose fd |
| 871 | if ne r 0 |
| 872 | gnfail 3 |
| 873 | end |
| 874 | end |
| 875 | put GNFD slot -1 |
| 876 | end |
| 877 | |
| 878 | note ---- requests ---- |
| 879 | |
| 880 | note send RFRQ: append the frame, run the reference, append the 8-word expected record |
| 881 | fn gnemit to void |
| 882 | op = get RFRQ 0 |
| 883 | w = add get RFRQ 1 2 |
| 884 | for i ulong w |
| 885 | gnpb get RFRQ i |
| 886 | end |
| 887 | st = rfreq |
| 888 | if ne st 0 |
| 889 | gnfail 4 |
| 890 | end |
| 891 | cold = ulong 0 |
| 892 | if eq op 2 |
| 893 | if eq get GNCT 12 1 |
| 894 | cold = 1 |
| 895 | put GNCT 12 0 |
| 896 | end |
| 897 | put GNCT 8 add get GNCT 8 1 |
| 898 | put GNCT 11 add get GNCT 11 1 |
| 899 | end |
| 900 | if or eq op 1 eq op 8 |
| 901 | put GNCT 12 1 |
| 902 | end |
| 903 | gnpe ulong st |
| 904 | gnpe get RFRS 1 |
| 905 | gnpe get RFRS 2 |
| 906 | gnpe get RFRS 3 |
| 907 | gnpe op |
| 908 | gnpe get GNCT 13 |
| 909 | gnpe cold |
| 910 | gnpe 0 |
| 911 | put GNCT 7 add get GNCT 7 1 |
| 912 | put GNCT 9 add get GNCT 9 1 |
| 913 | put GNCT 10 add get GNCT 10 1 |
| 914 | if gt get GNCT 5 16646144 |
| 915 | gnflreq |
| 916 | end |
| 917 | if gt get GNCT 6 4194240 |
| 918 | gnflexp |
| 919 | end |
| 920 | end |
| 921 | |
| 922 | fn gnq to void |
| 923 | put RFRQ 0 2 |
| 924 | put RFRQ 1 0 |
| 925 | gnemit |
| 926 | end |
| 927 | |
| 928 | fn gnc2 op ulong a ulong b ulong to void |
| 929 | put RFRQ 0 op |
| 930 | put RFRQ 1 2 |
| 931 | put RFRQ 2 a |
| 932 | put RFRQ 3 b |
| 933 | gnemit |
| 934 | end |
| 935 | |
| 936 | fn gnc1 op ulong a ulong to void |
| 937 | put RFRQ 0 op |
| 938 | put RFRQ 1 1 |
| 939 | put RFRQ 2 a |
| 940 | gnemit |
| 941 | end |
| 942 | |
| 943 | fn gnset to void |
| 944 | n = get RFN 0 |
| 945 | d = rfdom |
| 946 | i = gnbelow 1 n |
| 947 | gnc2 3 i gnbelow 1 d |
| 948 | end |
| 949 | |
| 950 | fn gnbset m ulong to void |
| 951 | put RFRQ 0 7 |
| 952 | put RFRQ 1 add 1 mul 3 m |
| 953 | put RFRQ 2 m |
| 954 | n = get RFN 0 |
| 955 | d = rfdom |
| 956 | for i ulong m |
| 957 | b = add 3 mul i 3 |
| 958 | put RFRQ b 3 |
| 959 | put RFRQ add b 1 gnbelow 1 n |
| 960 | put RFRQ add b 2 gnbelow 1 d |
| 961 | end |
| 962 | gnemit |
| 963 | end |
| 964 | |
| 965 | note BEGIN with the session's program (GNSP row c) and n random values of its domain |
| 966 | fn gnbegin c ulong n ulong to void |
| 967 | put RFRQ 0 1 |
| 968 | put RFRQ 1 add n 65 |
| 969 | for j ulong 64 |
| 970 | put RFRQ add j 2 get GNSP add mul c 64 j |
| 971 | end |
| 972 | d = get GNSP add mul c 64 3 |
| 973 | if eq get GNSP add mul c 64 1 1 |
| 974 | d = shl ulong 1 get GNSP add mul c 64 2 |
| 975 | end |
| 976 | put RFRQ 66 n |
| 977 | for i ulong n |
| 978 | put RFRQ add 67 i gnbelow 1 d |
| 979 | end |
| 980 | gnemit |
| 981 | end |
| 982 | |
| 983 | fn gnbs to void |
| 984 | for i ulong 64 |
| 985 | gnset |
| 986 | gnq |
| 987 | end |
| 988 | end |
| 989 | |
| 990 | fn gnbr to void |
| 991 | for i ulong 64 |
| 992 | n = get RFN 0 |
| 993 | a = gnbelow 1 n |
| 994 | gnc2 6 a gnbelow 1 n |
| 995 | gnq |
| 996 | end |
| 997 | end |
| 998 | |
| 999 | fn gnbi to void |
| 1000 | for i ulong 64 |
| 1001 | n = get RFN 0 |
| 1002 | if eq rem i 2 0 |
| 1003 | gnc1 5 gnbelow 1 n |
| 1004 | else |
| 1005 | a = gnbelow 1 add n 1 |
| 1006 | gnc2 4 a gnbelow 1 rfdom |
| 1007 | end |
| 1008 | gnq |
| 1009 | end |
| 1010 | end |
| 1011 | |
| 1012 | fn gnextr to ulong |
| 1013 | rffull |
| 1014 | ex = get RFR 0 |
| 1015 | n = get RFN 0 |
| 1016 | for i ulong n |
| 1017 | if eq rflane get RFX i ex |
| 1018 | ret i |
| 1019 | end |
| 1020 | end |
| 1021 | gnfail 4 |
| 1022 | ret 0 |
| 1023 | end |
| 1024 | |
| 1025 | fn gnbaagg to void |
| 1026 | for it ulong 64 |
| 1027 | gnc1 5 gnextr |
| 1028 | n = get RFN 0 |
| 1029 | a = gnbelow 1 add n 1 |
| 1030 | gnc2 4 a gnbelow 1 rfdom |
| 1031 | gnq |
| 1032 | end |
| 1033 | end |
| 1034 | |
| 1035 | fn gnbafsm to void |
| 1036 | for it ulong 64 |
| 1037 | s0 = get RFP 4 |
| 1038 | a = get RFP 3 |
| 1039 | cur = rfdelta s0 get RFX 0 |
| 1040 | cnt = ulong 0 |
| 1041 | for x ulong a |
| 1042 | if ne rfdelta s0 x cur |
| 1043 | cnt = add cnt 1 |
| 1044 | end |
| 1045 | end |
| 1046 | if eq cnt 0 |
| 1047 | gnfail 4 |
| 1048 | ret |
| 1049 | end |
| 1050 | u = gnbelow 1 cnt |
| 1051 | v = ulong 0 |
| 1052 | for y ulong a |
| 1053 | if ne rfdelta s0 y cur |
| 1054 | if eq u 0 |
| 1055 | v = y |
| 1056 | end |
| 1057 | u = sub u 1 |
| 1058 | end |
| 1059 | end |
| 1060 | gnc2 3 0 v |
| 1061 | gnq |
| 1062 | end |
| 1063 | end |
| 1064 | |
| 1065 | fn gnrfpeq to bool |
| 1066 | for j ulong 64 |
| 1067 | if ne get GNPG j get RFP j |
| 1068 | ret false |
| 1069 | end |
| 1070 | end |
| 1071 | ret true |
| 1072 | end |
| 1073 | |
| 1074 | note a PROGRAM for rule drift into RFRQ: same shape new constants, or same S and A new rules |
| 1075 | fn gnnewp to void |
| 1076 | for t ulong 64 |
| 1077 | if eq get RFP 1 1 |
| 1078 | gnprog rfshape 1 |
| 1079 | else |
| 1080 | gnmach 1 get RFP 2 get RFP 3 |
| 1081 | end |
| 1082 | if not gnrfpeq |
| 1083 | put RFRQ 0 8 |
| 1084 | put RFRQ 1 64 |
| 1085 | for j ulong 64 |
| 1086 | put RFRQ add j 2 get GNPG j |
| 1087 | end |
| 1088 | gnemit |
| 1089 | ret |
| 1090 | end |
| 1091 | end |
| 1092 | gnfail 4 |
| 1093 | end |
| 1094 | |
| 1095 | fn gnbp to void |
| 1096 | for i ulong 16 |
| 1097 | if eq rem i 4 3 |
| 1098 | gnnewp |
| 1099 | end |
| 1100 | gnq |
| 1101 | end |
| 1102 | end |
| 1103 | |
| 1104 | fn gnbody body ulong fam ulong to void |
| 1105 | if eq body 1 |
| 1106 | for i ulong 32 |
| 1107 | gnq |
| 1108 | end |
| 1109 | ret |
| 1110 | end |
| 1111 | if or eq body 2 eq body 8 |
| 1112 | gnbs |
| 1113 | ret |
| 1114 | end |
| 1115 | if eq body 3 |
| 1116 | for j ulong 8 |
| 1117 | gnbset 1024 |
| 1118 | gnq |
| 1119 | end |
| 1120 | ret |
| 1121 | end |
| 1122 | if eq body 4 |
| 1123 | gnbr |
| 1124 | ret |
| 1125 | end |
| 1126 | if eq body 5 |
| 1127 | gnbi |
| 1128 | ret |
| 1129 | end |
| 1130 | if eq body 6 |
| 1131 | if eq fam 1 |
| 1132 | gnbaagg |
| 1133 | else |
| 1134 | gnbafsm |
| 1135 | end |
| 1136 | ret |
| 1137 | end |
| 1138 | if eq body 7 |
| 1139 | gnbp |
| 1140 | ret |
| 1141 | end |
| 1142 | if eq body 9 |
| 1143 | for t ulong 8 |
| 1144 | gnset |
| 1145 | gnq |
| 1146 | end |
| 1147 | ret |
| 1148 | end |
| 1149 | for q ulong 16 |
| 1150 | if eq body 11 |
| 1151 | gnset |
| 1152 | end |
| 1153 | if eq body 12 |
| 1154 | gnbset add 2 gnbelow 1 63 |
| 1155 | end |
| 1156 | if eq body 13 |
| 1157 | gnbset 1024 |
| 1158 | end |
| 1159 | gnq |
| 1160 | end |
| 1161 | end |
| 1162 | |
| 1163 | fn gnsess pos ulong to void |
| 1164 | c = get GNSO pos |
| 1165 | b = mul c 8 |
| 1166 | fam = get GNSM b |
| 1167 | n = get GNSM add b 3 |
| 1168 | put GNCT 13 pos |
| 1169 | put GNCT 10 0 |
| 1170 | put GNCT 11 0 |
| 1171 | r = mul pos 16 |
| 1172 | put GNSS r pos |
| 1173 | put GNSS add r 14 get GNCT 9 |
| 1174 | gnbegin c n |
| 1175 | put GNSS add r 1 div pos 8 |
| 1176 | put GNSS add r 2 fam |
| 1177 | put GNSS add r 3 get GNSM add b 1 |
| 1178 | put GNSS add r 4 get GNSM add b 2 |
| 1179 | nc = ulong 2 |
| 1180 | if le n 512 |
| 1181 | nc = 1 |
| 1182 | end |
| 1183 | if le n 64 |
| 1184 | nc = 0 |
| 1185 | end |
| 1186 | put GNSS add r 5 nc |
| 1187 | put GNSS add r 6 n |
| 1188 | put GNSS add r 7 rfshape |
| 1189 | rfpdig |
| 1190 | for j ulong 4 |
| 1191 | put GNSS add r add 8 j get RFPD j |
| 1192 | end |
| 1193 | gnbody get GNSM add b 4 fam |
| 1194 | put GNSS add r 12 get GNCT 10 |
| 1195 | put GNSS add r 13 get GNCT 11 |
| 1196 | put GNSS add r 15 0 |
| 1197 | end |
| 1198 | |
| 1199 | fn gngroup g ulong to void |
| 1200 | put GNCT 9 0 |
| 1201 | gnopen 0 gngpath g 0 |
| 1202 | gnopen 1 gngpath g 1 |
| 1203 | if ne get GNCT 0 0 |
| 1204 | ret |
| 1205 | end |
| 1206 | rfreset |
| 1207 | for i ulong 8 |
| 1208 | gnsess add mul g 8 i |
| 1209 | end |
| 1210 | gnflreq |
| 1211 | gnflexp |
| 1212 | gnclose 0 |
| 1213 | gnclose 1 |
| 1214 | put GNGR g get GNCT 9 |
| 1215 | end |
| 1216 | |
| 1217 | fn gnsmall tpath ulong n ulong to void |
| 1218 | l = get GNCT 4 |
| 1219 | if eq tpath 0 |
| 1220 | for i ulong len gntsess |
| 1221 | put GNPA add l i get gntsess i |
| 1222 | end |
| 1223 | gnopen 2 add l len gntsess |
| 1224 | else |
| 1225 | for j ulong len gntidx |
| 1226 | put GNPA add l j get gntidx j |
| 1227 | end |
| 1228 | gnopen 2 add l len gntidx |
| 1229 | end |
| 1230 | if eq get GNCT 0 0 |
| 1231 | gnwrwb n |
| 1232 | end |
| 1233 | gnclose 2 |
| 1234 | end |
| 1235 | |
| 1236 | fn gnwrite to void |
| 1237 | put GNRS 1 gnsub get GNCT 14 4 |
| 1238 | rfhini 1 |
| 1239 | cnt = get GNCT 2 |
| 1240 | g = div cnt 8 |
| 1241 | put GNCT 3 g |
| 1242 | for i ulong g |
| 1243 | gngroup i |
| 1244 | if ne get GNCT 0 0 |
| 1245 | ret |
| 1246 | end |
| 1247 | end |
| 1248 | rfhfin 1 |
| 1249 | put GNCT 15 0 |
| 1250 | for w ulong mul cnt 16 |
| 1251 | gnpw get GNSS w |
| 1252 | end |
| 1253 | gnsmall 0 get GNCT 15 |
| 1254 | put GNCT 15 0 |
| 1255 | gnpw 3544386032354079058 |
| 1256 | gnpw 1 |
| 1257 | gnpw get GNCT 1 |
| 1258 | gnpw g |
| 1259 | gnpw cnt |
| 1260 | gnpw get GNCT 7 |
| 1261 | gnpw get GNCT 8 |
| 1262 | for d ulong 4 |
| 1263 | gnpw get RFHD d |
| 1264 | end |
| 1265 | for z ulong 5 |
| 1266 | gnpw 0 |
| 1267 | end |
| 1268 | for k ulong g |
| 1269 | gnpw get GNGR k |
| 1270 | end |
| 1271 | gnsmall 1 get GNCT 15 |
| 1272 | end |
| 1273 | |
| 1274 | note ---- arguments and the summary line ---- |
| 1275 | |
| 1276 | fn gnhexv c ulong to ulong |
| 1277 | if and ge c 48 le c 57 |
| 1278 | ret sub c 48 |
| 1279 | end |
| 1280 | if and ge c 97 le c 102 |
| 1281 | ret sub c 87 |
| 1282 | end |
| 1283 | if and ge c 65 le c 70 |
| 1284 | ret sub c 55 |
| 1285 | end |
| 1286 | ret 16 |
| 1287 | end |
| 1288 | |
| 1289 | note FINAL generator seed: bytes 8..15 (LE) of the 64-hex-character seed in GNAR; 16 = bad hex |
| 1290 | fn gnseedhex n ulong to ulong |
| 1291 | if ne n 64 |
| 1292 | put GNCT 20 1 |
| 1293 | ret 0 |
| 1294 | end |
| 1295 | for i ulong 64 |
| 1296 | if gt gnhexv ulong get GNAR i 15 |
| 1297 | put GNCT 20 1 |
| 1298 | end |
| 1299 | end |
| 1300 | v = ulong 0 |
| 1301 | for b ulong 8 |
| 1302 | hi = gnhexv ulong get GNAR add 16 mul b 2 |
| 1303 | lo = gnhexv ulong get GNAR add 17 mul b 2 |
| 1304 | v = or v shl add mul hi 16 lo mul b 8 |
| 1305 | end |
| 1306 | ret v |
| 1307 | end |
| 1308 | |
| 1309 | fn gnsplit n ulong to ulong |
| 1310 | if or eq n 0 gt n 8 |
| 1311 | ret 0 |
| 1312 | end |
| 1313 | v = ulong 0 |
| 1314 | for i ulong n |
| 1315 | v = or v shl ulong get GNAR i mul i 8 |
| 1316 | end |
| 1317 | if eq v 336236466772 |
| 1318 | ret 1 |
| 1319 | end |
| 1320 | if eq v 284697575747 |
| 1321 | ret 2 |
| 1322 | end |
| 1323 | if eq v 5653828 |
| 1324 | ret 3 |
| 1325 | end |
| 1326 | if eq v 327513164102 |
| 1327 | ret 4 |
| 1328 | end |
| 1329 | if eq v 88297166688852 |
| 1330 | ret 5 |
| 1331 | end |
| 1332 | ret 0 |
| 1333 | end |
| 1334 | |
| 1335 | fn gntxt t ulong to void |
| 1336 | o = get GNCT 15 |
| 1337 | put GNWB o uchar t |
| 1338 | put GNCT 15 add o 1 |
| 1339 | end |
| 1340 | |
| 1341 | fn gntnum v ulong to void |
| 1342 | d = new uchar 24 0 |
| 1343 | k = ulong 0 |
| 1344 | x = v |
| 1345 | while true bound 21 |
| 1346 | put d k uchar add 48 rem x 10 |
| 1347 | k = add k 1 |
| 1348 | x = div x 10 |
| 1349 | if eq x 0 |
| 1350 | break |
| 1351 | end |
| 1352 | end |
| 1353 | while gt k 0 bound 21 |
| 1354 | k = sub k 1 |
| 1355 | gntxt ulong get d k |
| 1356 | end |
| 1357 | end |
| 1358 | |
| 1359 | fn gntkey a ulong b ulong c ulong to void |
| 1360 | if gt get GNCT 15 0 |
| 1361 | gntxt 32 |
| 1362 | end |
| 1363 | gntxt a |
| 1364 | gntxt b |
| 1365 | gntxt c |
| 1366 | gntxt 61 |
| 1367 | end |
| 1368 | |
| 1369 | fn gnthex w ulong to void |
| 1370 | for i ulong 16 |
| 1371 | nib = and shr w mul sub 15 i 4 15 |
| 1372 | if lt nib 10 |
| 1373 | gntxt add 48 nib |
| 1374 | else |
| 1375 | gntxt add 87 nib |
| 1376 | end |
| 1377 | end |
| 1378 | end |
| 1379 | |
| 1380 | note "spl=ID grp=G ses=S req=R qry=Q mnx=M dgs=HEX": split id, groups, sessions, requests, QUERYs, |
| 1381 | note MIN/MAX shapes in the TRAIN pool, holdout digest (SHA-256 of the .req files in group order) |
| 1382 | fn gnsummary to void |
| 1383 | put GNCT 15 0 |
| 1384 | gntkey 115 112 108 |
| 1385 | gntnum get GNCT 1 |
| 1386 | gntkey 103 114 112 |
| 1387 | gntnum get GNCT 3 |
| 1388 | gntkey 115 101 115 |
| 1389 | gntnum get GNCT 2 |
| 1390 | gntkey 114 101 113 |
| 1391 | gntnum get GNCT 7 |
| 1392 | gntkey 113 114 121 |
| 1393 | gntnum get GNCT 8 |
| 1394 | gntkey 109 110 120 |
| 1395 | gntnum get GNCT 16 |
| 1396 | gntkey 100 103 115 |
| 1397 | for i ulong 4 |
| 1398 | gnthex get RFHD i |
| 1399 | end |
| 1400 | gntxt 10 |
| 1401 | x = write 1 GNWB 0 get GNCT 15 |
| 1402 | end |
| 1403 | |
| 1404 | fn gnminmax to ulong |
| 1405 | m = ulong 0 |
| 1406 | for r ulong 24 |
| 1407 | if gnfok get GNTP r 1 |
| 1408 | m = add m 1 |
| 1409 | end |
| 1410 | end |
| 1411 | ret m |
| 1412 | end |
| 1413 | |
| 1414 | fn main to int |
| 1415 | ac = argcnt |
| 1416 | if or lt ac 3 gt ac 4 |
| 1417 | x = write 2 gneus 0 len gneus |
| 1418 | ret 2 |
| 1419 | end |
| 1420 | l1 = argread 1 GNAR 0 4096 |
| 1421 | if lt l1 0 |
| 1422 | ret 2 |
| 1423 | end |
| 1424 | sid = gnsplit ulong l1 |
| 1425 | if eq sid 0 |
| 1426 | x = write 2 gneus 0 len gneus |
| 1427 | ret 2 |
| 1428 | end |
| 1429 | put GNCT 1 sid |
| 1430 | seed = ulong 1001 |
| 1431 | if eq sid 2 |
| 1432 | seed = 1003 |
| 1433 | end |
| 1434 | if eq sid 3 |
| 1435 | seed = 1004 |
| 1436 | end |
| 1437 | if eq sid 5 |
| 1438 | seed = 1002 |
| 1439 | end |
| 1440 | if eq sid 4 |
| 1441 | if ne ac 4 |
| 1442 | x = write 2 gneus 0 len gneus |
| 1443 | ret 2 |
| 1444 | end |
| 1445 | l3 = argread 3 GNAR 0 4096 |
| 1446 | if lt l3 0 |
| 1447 | ret 2 |
| 1448 | end |
| 1449 | seed = gnseedhex ulong l3 |
| 1450 | if ne get GNCT 20 0 |
| 1451 | x = write 2 gneus 0 len gneus |
| 1452 | ret 2 |
| 1453 | end |
| 1454 | else |
| 1455 | if ne ac 3 |
| 1456 | x = write 2 gneus 0 len gneus |
| 1457 | ret 2 |
| 1458 | end |
| 1459 | end |
| 1460 | put GNCT 14 seed |
| 1461 | l2 = argread 2 GNPA 0 3900 |
| 1462 | if le l2 0 |
| 1463 | ret 2 |
| 1464 | end |
| 1465 | put GNCT 4 ulong l2 |
| 1466 | md = makedir GNPA 0 ulong l2 493 |
| 1467 | if and lt md 0 ne md -17 |
| 1468 | x = write 2 gneio 0 len gneio |
| 1469 | ret 3 |
| 1470 | end |
| 1471 | gnpool 1 |
| 1472 | gnpool 5 |
| 1473 | put GNCT 16 gnminmax |
| 1474 | if eq sid 1 |
| 1475 | gnlist 1 |
| 1476 | gnfromls |
| 1477 | end |
| 1478 | if eq sid 5 |
| 1479 | gnlist 5 |
| 1480 | gnfromls |
| 1481 | end |
| 1482 | if eq sid 2 |
| 1483 | gncalib |
| 1484 | end |
| 1485 | if or eq sid 3 eq sid 4 |
| 1486 | gnlist 1 |
| 1487 | gncomp |
| 1488 | end |
| 1489 | if eq get GNCT 0 0 |
| 1490 | gnwrite |
| 1491 | end |
| 1492 | e = get GNCT 0 |
| 1493 | if eq e 3 |
| 1494 | x = write 2 gneio 0 len gneio |
| 1495 | end |
| 1496 | if eq e 4 |
| 1497 | x = write 2 gnegen 0 len gnegen |
| 1498 | end |
| 1499 | if eq e 0 |
| 1500 | gnsummary |
| 1501 | end |
| 1502 | ret int e |
| 1503 | end |