interplane.Get Omega
Read in your language

omega-mv

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

Brought by drakestapleton

branch main Branches Tags History

omega-mv / core / rsi / om / reuse-eval / stats.om

2204 lines · 44337 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note stats.om (lane EvalStats, spark-rsi-mv #73): the REUSE-1 statistics and decision unit.
3note Contract: omega-mv d6edaad1 docs/reuse/REUSE-1.md (sections 6, 9, 10); evaluator formats:
4note docs EVAL-FORMATS (split directory, raw run log, proc.log, acq.log, controls.log K7, seeds K6).
5note No fn main here: the evaluator dispatcher calls stmain. Names: functions st*, globals ST*,
6note constants SK*. turing.om and receipt.om reuse the st* output, path and file helpers.
7note
8note CLI (argv[1] is the dispatcher's subcommand and is not read):
9note stats SPLITDIR RUNDIR CTRLDIR SEEDHEX OUTDIR
10note SPLITDIR = the FINAL split directory (index, sessions, gNN.exp); RUNDIR = arm-A-rep-R-gNN.log,
11note proc.log, acq.log; CTRLDIR = the directory holding controls.log, or - when no control run
12note exists (every control then counts as not run); SEEDHEX = the 32-byte FINAL seed as 64 hex;
13note OUTDIR receives stats.txt (the report, also written to stdout) and stats.sum (words below).
14note Exit 0 = report written (the decision is inside it), 2 = inputs refused (status=REFUSED line
15note with a code, nothing else decided), other = output write failure.
16note
17note Definitions (all integer, no floating point):
18note - reps R = 3 (0-based in names and logs), arms 0 echo 1 full 2 cache 3 method 4 delta
19note 5 idelta 6 deltap 7 select. Library charged per arm: method, delta, select = acq lib 1
20note (TRAIN), deltap = lib 2 (TRAINP), every other arm none (idelta runs with LIBDIR -).
21note - cost of one arm process (arm a, rep r, group g) = start-to-ready (proc word 3, which
22note includes request 0's round trip) + sum of round trips of requests 1.. of the group + the END
23note round trip (proc word 15, K17; raw logs and proc word 12 exclude END). This charges
24note start-to-ready to the first request (contract 5.4).
25note - process exit (proc word 10, K17): 0 ok; any nonzero value (exit code, 256 + signal,
26note 512 + judge kill code, 1023 reap failure, + 1024 when END itself failed) is a failed process
27note and counts as one wrong refusal of its arm (so STOP for arms 1..7); reported per arm as
28note proc_failed (correct line), exit_nonzero and end_failed (memory line).
29note - V(a, g) = sum over the 3 reps of the process cost; acq(a) = sum over the 3 reps of the
30note elapsed ns of the arm's library build. T(a) = sum over groups of V(a, g) + acq(a). Sums over
31note reps stand for the per-group means of contract 10 (the factor 3 cancels in every ratio).
32note - rho(a) = T(a) / T(full); ratio rho(x)/rho(y) = T(x) / T(y) (full cancels, same resample).
33note Statistic s: 0..7 rho(arm s); 8 delta/cache; 9 delta/idelta; 10 select/delta;
34note 11 delta/method; 12 idelta/full.
35note - ppm = floor(num * 1000000 / den), exact 128-bit product and division. Floor makes the
36note decision comparisons exact: ppm < 1000000 iff ratio < 1; ppm >= 1000000 iff ratio >= 1.
37note - bootstrap: B = 10000 resamples; resample b draws G group indices, each = splitmix64() mod G
38note (bias below G / 2^64); one draw serves every arm (paired); splitmix64 state starts at the
39note FINAL seed bytes 0..7 read little endian (contract 10, K6) and is advanced once per draw.
40note The 10000 values of each statistic are sorted ascending; interval = (v[k_lo], v[k_hi]) with
41note nearest rank k = ceil(p * B) - 1 (0-based): p = 0.025 gives k_lo = 249, p = 0.975 gives 9749.
42note The point value is the statistic on the sample itself (every group once).
43note - quantiles: nearest rank on ascending values, index ceil(p * m / 100) - 1 for p = 50, 95, 99,
44note over the QUERY round trips (all 3 reps) of one arm, cold (exp cold flag 1) or warm (0),
45note per category: all, session type, novelty class, family, n class. m = 0 prints na.
46note - cat_rho: request round trips only (no start-to-ready, no acquisition), per session category,
47note arm over full; regime lines are the cat_rho ratios delta/method and idelta/full per type.
48note - correctness: the log's word 15 is recomputed from words 5..11 (QUERY 1 iff status, r0, r1
49note equal; other requests 2 iff status equal; echo 2); a record is wrong when either the log or
50note the recomputation says 0; disagreements are counted as log_inconsistent. Echo is never scored.
51note - transfer coverage: delta-arm QUERYs (all reps) in sessions of novelty class 2 with route 3
52note or 4, over all such QUERYs. Fallback = route 5 among an arm's QUERYs.
53note - payback(a): FINAL request order (group 0.., request 0..), per request the rep-summed
54note (full - arm) cost (request 0 = start-to-ready only), then after each group's last request
55note the rep-summed (full - arm) END round trip; the number of QUERYs seen when the cumulative
56note sum first exceeds acq(a) (tested after every request and after every END term); none if
57note it never does. rho totals include END as before.
58note - Cbar (contract 6, #744), per arm, ppm of one full QUERY: F = floor(full QUERY round-trip
59note sum / count); r = echo mean QUERY / F; q = QUERYs not served by routes 2..4 / QUERYs;
60note e = mean of the route 2..4 QUERYs / F - r; K = acq(a) / F (full-QUERY units); N = the arm's
61note QUERYs over 3 reps; cbar = r + (1 - q) e + q + K / N (signed, truncating toward zero);
62note observed = (QUERY round-trip sum + acq) / N / F. Reported, never in the decision.
63note - echo_sub(a) = (T(a) - T(echo)) / (T(full) - T(echo)), signed ppm (secondary figure).
64note - decision (contract 10, K7): STOP on any wrong answer or wrong refusal of arms 1..7, a control
65note with outcome 0 or the served-tampered flag, or lower bound of rho(delta) >= 1; else GO when
66note upper bounds of rho(delta), delta/cache and delta/idelta are < 1, transfer coverage >= 1/2
67note (with at least one transfer QUERY) and every control C1..C12 has all its required
68note (control, sub-case) pairs (stcreq) and none not run; a missing pair counts as not run;
69note else INVESTIGATE. Every failing condition is listed as a reason line.
70note
71note stats.sum: 256 words LE. 0 magic 3544386041195737426 (R1STS001), 1 version 1, 2 decision
72note (1 GO, 2 INVESTIGATE, 3 STOP), 3 reason bits (0 wrong_answer, 1 wrong_refusal,
73note 2 control_undetected, 3 tampered_served, 4 rho_delta_lower_ge_1, 5 rho_delta_upper_ge_1,
74note 6 delta_over_cache_upper_ge_1, 7 delta_over_idelta_upper_ge_1, 8 transfer_coverage_below_half,
75note 9 control_not_run), 4 groups, 5 sessions, 6 requests, 7 queries (per rep), 8 reps, 9 split id,
76note 10 bootstrap seed, 11 resamples, 12 scored QUERY responses (arms 1..7, all reps), 13 correct
77note ones, 14 wrong ones, 15 wrong refusals, 16 transfer QUERYs, 17 covered, 18..21 holdout digest
78note (index words 7..10 as stored), 22 log inconsistencies, 24 + 3 s .. 26 + 3 s point, lo, hi ppm
79note of statistic s (s 0..12), 64 + a T(a), 72 + a acq(a), 80 + a route-5 QUERYs of arm a,
80note 88 + a payback QUERYs (18446744073709551615 = none or not applicable), 96 + a failed
81note processes of arm a (K17 nonzero exit), 104 + a processes of arm a whose END failed; the rest 0.
82note
83note Refusal codes: 1 usage, 2 index unreadable, 3 index invalid, 4 sessions invalid, 5 exp invalid,
84note 6 log missing, 7 log size, 8 log identity words, 9 log expectation words differ from exp,
85note 10 proc.log invalid, 11 proc record missing or duplicate, 12 acq.log invalid or a needed build
86note missing, 13 controls.log invalid (detail k.0 field range, k.1 reported outside C12, k.2
87note sub-case not required, k.3 repeated pair; k = record), 14 capacity, 15 output write failed.
88
89const SKINDEX ulong 0
90const SKSESS ulong 1
91const SKEXP ulong 2
92const SKARMP ulong 3
93const SKREPP ulong 4
94const SKGP ulong 5
95const SKLOG ulong 6
96const SKPROC ulong 7
97const SKACQ ulong 8
98const SKCTL ulong 9
99const SKTXT ulong 10
100const SKSUM ulong 11
101const SKHEAD ulong 12
102const SKREFU ulong 13
103const SKDETL ulong 14
104const SKINPUT ulong 15
105const SKGROUP ulong 16
106const SKSESN ulong 17
107const SKREQS ulong 18
108const SKQRYS ulong 19
109const SKREPS ulong 20
110const SKARM ulong 21
111const SKTOTAL ulong 22
112const SKRTNS ulong 23
113const SKREADY ulong 24
114const SKACQNS ulong 25
115const SKTOTNS ulong 26
116const SKRHO ulong 27
117const SKPOINT ulong 28
118const SKLO ulong 29
119const SKHI ulong 30
120const SKRATIO ulong 31
121const SKCORR ulong 32
122const SKQOK ulong 33
123const SKQBAD ulong 34
124const SKCOK ulong 35
125const SKCBAD ulong 36
126const SKUNSC ulong 37
127const SKINCON ulong 38
128const SKROUTE ulong 39
129const SKRN ulong 40
130const SKEQ ulong 41
131const SKROTH ulong 42
132const SKFALL ulong 43
133const SKCOVER ulong 44
134const SKCOVD ulong 45
135const SKCOVP ulong 46
136const SKMEM ulong 47
137const SKPROCS ulong 48
138const SKHWMX ulong 49
139const SKHWMM ulong 50
140const SKRSSX ulong 51
141const SKCPU ulong 52
142const SKEXITN ulong 53
143const SKACQL ulong 54
144const SKBUILD ulong 55
145const SKELAP ulong 56
146const SKLIBB ulong 57
147const SKDRIVN ulong 58
148const SKPAYB ulong 59
149const SKPAYQ ulong 60
150const SKNONE ulong 61
151const SKCBAR ulong 62
152const SKCR ulong 63
153const SKCQ ulong 64
154const SKCE ulong 65
155const SKCK ulong 66
156const SKCN ulong 67
157const SKCBV ulong 68
158const SKCOBS ulong 69
159const SKECHO ulong 70
160const SKPPM ulong 71
161const SKNA ulong 72
162const SKQUANT ulong 73
163const SKTEMP ulong 74
164const SKCOLD ulong 75
165const SKWARM ulong 76
166const SKCAT ulong 77
167const SKCOUNT ulong 78
168const SKP50 ulong 79
169const SKP95 ulong 80
170const SKP99 ulong 81
171const SKCATR ulong 82
172const SKREGT ulong 83
173const SKDOM ulong 84
174const SKIOF ulong 85
175const SKCTLID ulong 86
176const SKRECS ulong 87
177const SKDET ulong 88
178const SKUNDET ulong 89
179const SKREPD ulong 90
180const SKNRUN ulong 91
181const SKTAMP ulong 92
182const SKDECI ulong 93
183const SKREAS ulong 94
184const SKI742 ulong 95
185const SKI743 ulong 96
186const SKI744 ulong 97
187const SKVERD ulong 98
188const SKHELPS ulong 99
189const SKNHELP ulong 100
190const SKINCO ulong 101
191const SKVERDS ulong 102
192const SKSIMNR ulong 103
193const SKSTEP ulong 104
194const SKBOOT ulong 105
195const SKSEED ulong 106
196const SKRKLO ulong 107
197const SKRKHI ulong 108
198const SKGO ulong 109
199const SKINV ulong 110
200const SKSTOP ulong 111
201const SKRWA ulong 112
202const SKRWR ulong 113
203const SKRCU ulong 114
204const SKRTS ulong 115
205const SKRLO ulong 116
206const SKRUP ulong 117
207const SKRDC ulong 118
208const SKRDI ulong 119
209const SKRCOV ulong 120
210const SKRNR ulong 121
211const SKMATCH ulong 122
212const SKYES ulong 123
213const SKNO ulong 124
214const SKARM0 ulong 125
215const SKCAT0 ulong 133
216const SKRAT0 ulong 153
217const SKCID0 ulong 157
218const SKOC0 ulong 172
219const SKBINDF ulong 177
220const SKRESTA ulong 178
221const SKDOMR ulong 179
222const SKIOFR ulong 180
223const SKR5 ulong 181
224const SKSPACE ulong 182
225const SKDIG ulong 183
226const SKR5D ulong 184
227const SKMISSP ulong 185
228const SKENDNS ulong 186
229const SKENDF ulong 187
230const SKPROCF ulong 188
231
232text STK "index\nsessions\n.exp\narm-\n-rep-\n-g\n.log\nproc.log\nacq.log\ncontrols.log\nstats.txt\nstats.sum\nreport=reuse1-stats version=1 contract=REUSE-1 v1.0\nstatus=REFUSED code=\n detail=\ninput split=\n groups=\n sessions=\n requests=\n queries=\n reps=\n arm=\ntotal\n rt_ns=\n ready_ns=\n acq_ns=\n total_ns=\nrho\n point_ppm=\n lo_ppm=\n hi_ppm=\nratio name=\ncorrect\n query_ok=\n query_wrong=\n change_ok=\n change_wrong=\n unscored=\n log_inconsistent=\nroutes\n r\n=\n other=\n fallback_ppm=\ncoverage arm=delta class=transfer queries=\n method_served=\n coverage_ppm=\nmemory\n procs=\n hwm_max_kb=\n hwm_mean_kb=\n rss_max_kb=\n cpu_ticks=\n exit_nonzero=\nacq lib=\n builds=\n elapsed_ns=\n libdir_bytes_max=\n drive_nonzero=\npayback\n queries=\nnone\ncbar\n r_ppm=\n q_ppm=\n e_ppm=\n k_units_ppm=\n n=\n cbar_ppm=\n observed_ppm=\necho_sub\n ppm=\nna\nquant\n temp=\ncold\nwarm\n cat=\n count=\n p50_ns=\n p95_ns=\n p99_ns=\ncat_rho\nregime cat=\n delta_over_method_ppm=\n idelta_over_full_ppm=\ncontrol id=\n records=\n detected=\n undetected=\n reported=\n not_run=\n served_tampered=\ndecision=\nreason=\nissue742 transfer_coverage_ppm=\nissue743\nissue744 select_over_delta\n verdict=\nhelps\ndoes_not_help\ninconclusive\nverdicts source=REVIEW_REQUIRED host=\n simulator=NOT_RUN physical=NOT_RUN\nfull_ns_per_step=NOT_RECORDED reason=raw_logs_carry_no_reference_timing\nbootstrap resamples=\n seed=\n rank_lo=\n rank_hi=\nGO\nINVESTIGATE\nSTOP\nwrong_answer\nwrong_refusal\ncontrol_undetected\ntampered_served\nrho_delta_lower_ge_1\nrho_delta_upper_ge_1\ndelta_over_cache_upper_ge_1\ndelta_over_idelta_upper_ge_1\ntransfer_coverage_below_half\ncontrol_not_run\n matched_correctness=\nyes\nno\necho\nfull\ncache\nmethod\ndelta\nidelta\ndeltap\nselect\nall\ntype:Z\ntype:S\ntype:D\ntype:R\ntype:I\ntype:A\ntype:P\ntype:C\nnov:none\nnov:recall\nnov:transfer\nnov:novel\nnov:fsm_recall\nnov:fsm_new\nfam:AGG\nfam:FSM\nn:64\nn:512\nn:4096\ndelta/cache\ndelta/idelta\nselect/delta\ndelta/method\nidelta/full\nC1\nC1b\nC1c\nC2\nC3\nC4\nC5\nC6\nC7\nC8\nC9\nC10\nC11\nC12\ndetected\nundetected\nreported\nnot_run\nmissing\n bind_failures=NOT_RECORDED\n restart_identity=\n delta_over_method\n idelta_over_full\n route5_method=\n \n0123456789abcdef\n route5_delta=\n missing_pairs=\n end_ns=\n end_failed=\n proc_failed=\n"
233
234global STOB uchar 4194304
235global STOP ulong 1
236global STPB uchar 4096
237global STPL ulong 1
238global STBD uchar 32768
239global STBL ulong 8
240global STFB uchar 8388608
241global STRNG ulong 1
242global STRF ulong 4
243global STNG ulong 1
244global STNS ulong 1
245global STNR ulong 1
246global STNQ ulong 1
247global STSPL ulong 1
248global STHD ulong 4
249global STSEED ulong 1
250global STGO ulong 128
251global STGN ulong 128
252global STSG ulong 1024
253global STSF ulong 1024
254global STST ulong 1024
255global STSN ulong 1024
256global STSC ulong 1024
257global STRO ulong 65536
258global STRC ulong 65536
259global STRS ulong 65536
260global STRX ulong 65536
261global STR0 ulong 65536
262global STR1 ulong 65536
263global STRT ulong 1572864
264global STAG ulong 3072
265global STA0 ulong 3072
266global STPR ulong 3072
267global STPF ulong 3072
268global STPE ulong 3072
269global STCNT ulong 256
270global STSS ulong 8192
271global STAQ ulong 32
272global STAQC ulong 32
273global STAQX ulong 32
274global STAQB ulong 32
275global STAQF ulong 32
276global STCT ulong 128
277global STV ulong 1024
278global STAA ulong 8
279global STT ulong 8
280global STBS ulong 130000
281global STPT ulong 13
282global STLO ulong 13
283global STHI ulong 13
284global STQV ulong 262144
285global STQI ulong 262144
286global STHL ulong 2
287global STDEC ulong 2
288global STSUM ulong 256
289global STPYC long 1
290global STPYQ ulong 1
291global STQT ulong 1
292
293note ---------- output buffer ----------
294fn stoc c uchar to void
295p = get STOP 0
296put STOB p c
297put STOP 0 add p 1
298end
299
300fn stkoff k ulong to ulong
301i = ulong 0
302c = ulong 0
303while lt c k bound 999999
304if eq get STK i 10
305c = add c 1
306end
307i = add i 1
308end
309ret i
310end
311
312fn stks k ulong to void
313i = stkoff k
314while ne get STK i 10 bound 4096
315stoc get STK i
316i = add i 1
317end
318end
319
320fn stnl to void
321stoc 10
322end
323
324fn stou v ulong to void
325d = new uchar 24 0
326n = ulong 0
327x = v
328while true bound 30
329put d n uchar add rem x 10 48
330n = add n 1
331x = div x 10
332if eq x 0
333break
334end
335end
336for i ulong n
337stoc get d sub sub n i 1
338end
339end
340
341fn stol v long to void
342if lt v 0
343stoc 45
344stou ulong neg v
345ret
346end
347stou ulong v
348end
349
350note one lowercase hex digit pair of byte b
351fn stohb b ulong to void
352h = add stkoff SKDIG shr b 4
353l = add stkoff SKDIG and b 15
354stoc get STK h
355stoc get STK l
356end
357
358note a digest word as stored in the split files (bytes 8j..8j+7 read big endian) as 16 hex digits
359fn stohw w ulong to void
360for k ulong 8
361stohb and shr w mul sub 7 k 8 255
362end
363end
364
365note key k, then value v
366fn stkv k ulong v ulong to void
367stks k
368stou v
369end
370
371fn stkvl k ulong v long to void
372stks k
373stol v
374end
375
376note write the output buffer to fd; 0 ok
377fn stflush fd int to int
378n = get STOP 0
379o = ulong 0
380while lt o n bound 999999
381w = write fd STOB o sub n o
382if le w 0
383ret 1
384end
385o = add o ulong w
386end
387ret 0
388end
389
390note ---------- paths and files ----------
391fn stpc c uchar to void
392p = get STPL 0
393put STPB p c
394put STPL 0 add p 1
395end
396
397fn stpk k ulong to void
398i = stkoff k
399while ne get STK i 10 bound 4096
400stpc get STK i
401i = add i 1
402end
403end
404
405fn stpu v ulong to void
406d = new uchar 24 0
407n = ulong 0
408x = v
409while true bound 30
410put d n uchar add rem x 10 48
411n = add n 1
412x = div x 10
413if eq x 0
414break
415end
416end
417for i ulong n
418stpc get d sub sub n i 1
419end
420end
421
422fn stpu2 v ulong to void
423stpc uchar add div v 10 48
424stpc uchar add rem v 10 48
425end
426
427note base slot b (an argv copy) exactly as the path
428fn stpexact b ulong to void
429put STPL 0 0
430o = mul b 4096
431for i ulong get STBL b
432stpc get STBD add o i
433end
434end
435
436note base slot b as the path, then a slash
437fn stpbase b ulong to void
438stpexact b
439stpc 47
440end
441
442note argv[ix] into base slot b; returns its length (0 = missing)
443fn stargb ix ulong b ulong to ulong
444o = mul b 4096
445n = argread ix STBD o 4095
446if le n 0
447put STBL b 0
448ret 0
449end
450put STBL b ulong n
451ret ulong n
452end
453
454note the whole file at STPB into STFB; bytes read, or -errno, or -27 when it does not fit
455fn stload to long
456fd = fopen STPB 0 get STPL 0 0 0
457if lt fd 0
458ret fd
459end
460tot = ulong 0
461cap = len STFB
462r = long 0
463while lt tot cap bound 999999
464m = sub cap tot
465if gt m 1048576
466m = 1048576
467end
468n = read int fd STFB tot m
469if lt n 0
470r = n
471break
472end
473if eq n 0
474break
475end
476tot = add tot ulong n
477end
478c = fclose int fd
479if lt r 0
480ret r
481end
482if lt c 0
483ret c
484end
485if eq tot cap
486ret -27
487end
488ret long tot
489end
490
491note little-endian word at byte o of STFB
492fn stw o ulong to ulong
493v = ulong 0
494for k ulong 8
495b = ulong get STFB add o k
496v = or v shl b mul k 8
497end
498ret v
499end
500
501note word k of record rec (rb bytes per record)
502fn strw rec ulong rb ulong k ulong to ulong
503ret stw add mul rec rb mul k 8
504end
505
506note write STOB[0..n) to the path in STPB (create or truncate, mode 0644, fsync); 0 ok
507fn stwfile to int
508fd = fopen STPB 0 get STPL 0 577 420
509if lt fd 0
510ret 1
511end
512r = stflush int fd
513s = fsync int fd
514c = fclose int fd
515if or ne r 0 or ne s 0 ne c 0
516ret 1
517end
518ret 0
519end
520
521note ---------- 128-bit exact arithmetic ----------
522note a * b into STHL (0 high, 1 low)
523fn stmul a ulong b ulong to void
524m = ulong 4294967295
525al = and a m
526bl = and b m
527p0 = mul al bl
528p1 = mul al shr b 32
529p2 = mul shr a 32 bl
530mid = add add shr p0 32 and p1 m and p2 m
531put STHL 1 or and p0 m shl mid 32
532hi = mul shr a 32 shr b 32
533hi = add add hi shr p1 32 add shr p2 32 shr mid 32
534put STHL 0 hi
535end
536
537note floor(a * b / c), saturated at 2^64 - 1; c = 0 gives 2^64 - 1
538fn stmd a ulong b ulong c ulong to ulong
539if eq c 0
540ret 18446744073709551615
541end
542stmul a b
543hi = get STHL 0
544lo = get STHL 1
545r = ulong 0
546q = ulong 0
547ov = false
548bit = ulong 0
549for i ulong 128
550if lt i 64
551bit = and shr hi sub 63 i 1
552else
553bit = and shr lo sub 127 i 1
554end
555cy = shr r 63
556r = or shl r 1 bit
557qb = ulong 0
558if or eq cy 1 ge r c
559r = sub r c
560qb = 1
561end
562if and lt i 64 eq qb 1
563ov = true
564end
565q = or shl q 1 qb
566end
567if ov
568ret 18446744073709551615
569end
570ret q
571end
572
573note ppm of num over den (floor)
574fn stppm num ulong den ulong to ulong
575ret stmd num 1000000 den
576end
577
578note signed ppm (truncation toward zero); den must be > 0
579fn stppms num long den long to long
580if lt num 0
581ret neg long stmd ulong neg num 1000000 ulong den
582end
583ret long stmd ulong num 1000000 ulong den
584end
585
586note ---------- splitmix64 ----------
587fn stsm to ulong
588s = add get STRNG 0 11400714819323198485
589put STRNG 0 s
590z = mul xor s shr s 30 13787848793156543929
591z = mul xor z shr z 27 10723151780598845931
592ret xor z shr z 31
593end
594
595note hex digit value, 16 = not a hex digit
596fn sthexv c uchar to ulong
597if and ge c 48 le c 57
598ret ulong sub c 48
599end
600if and ge c 97 le c 102
601ret ulong sub c 87
602end
603if and ge c 65 le c 70
604ret ulong sub c 55
605end
606ret 16
607end
608
609note byte i (0..31) of the 64-hex text held in base slot b; 256 = bad
610fn sthexb b ulong i ulong to ulong
611o = add mul b 4096 mul i 2
612h = sthexv get STBD o
613l = sthexv get STBD add o 1
614if or gt h 15 gt l 15
615ret 256
616end
617ret or shl h 4 l
618end
619
620note little-endian word from hex bytes s..s+7 of base slot b; STRF 3 = 1 on a bad digit
621fn sthexw b ulong s ulong to ulong
622v = ulong 0
623for k ulong 8
624x = sthexb b add s k
625if gt x 255
626put STRF 3 1
627x = 0
628end
629v = or v shl x mul k 8
630end
631ret v
632end
633
634note ---------- refusal ----------
635fn stref code ulong a ulong r ulong g ulong to int
636put STRF 0 code
637put STRF 1 a
638put STRF 2 r
639put STRF 3 g
640ret int code
641end
642
643fn stprref to void
644stks SKREFU
645stou get STRF 0
646stks SKDETL
647stou get STRF 1
648stoc 46
649stou get STRF 2
650stoc 46
651stou get STRF 3
652stnl
653end
654
655note ---------- split directory ----------
656fn stidx to int
657stpbase 0
658stpk SKINDEX
659n = stload
660if lt n 128
661ret stref 2 0 0 0
662end
663if or ne stw 0 3544386032354079058 ne stw 8 1
664ret stref 3 0 0 0
665end
666g = stw 24
667if or eq g 0 gt g 99
668ret stref 3 1 0 0
669end
670if ne ulong n add 128 mul g 8
671ret stref 3 2 0 0
672end
673put STNG 0 g
674put STSPL 0 stw 16
675put STNS 0 stw 32
676put STNR 0 stw 40
677put STNQ 0 stw 48
678for j ulong 4
679put STHD j stw add 56 mul j 8
680end
681off = ulong 0
682for i ulong g
683c = stw add 128 mul i 8
684put STGN i c
685put STGO i off
686off = add off c
687end
688if ne off get STNR 0
689ret stref 3 3 0 0
690end
691if gt off len STRO
692ret stref 14 0 0 0
693end
694ret 0
695end
696
697note checks one sessions record i; 0 ok
698fn stsone i ulong to int
699g = strw i 128 1
700f = strw i 128 2
701t = strw i 128 3
702v = strw i 128 4
703c = strw i 128 5
704if or ne strw i 128 0 i ge g get STNG 0
705ret 1
706end
707if or or lt f 1 gt f 2 or lt t 1 gt t 8
708ret 1
709end
710if or gt v 5 gt c 2
711ret 1
712end
713put STSG i g
714put STSF i f
715put STST i t
716put STSN i v
717put STSC i c
718ret 0
719end
720
721fn stsess to int
722stpbase 0
723stpk SKSESS
724n = stload
725s = get STNS 0
726if or eq s 0 gt s len STSG
727ret stref 4 0 0 0
728end
729if ne n long mul s 128
730ret stref 4 1 0 0
731end
732for i ulong s
733if ne stsone i 0
734ret stref 4 2 i 0
735end
736end
737ret 0
738end
739
740fn stexpg g ulong to int
741stpbase 0
742stpc 103
743stpu2 g
744stpk SKEXP
745n = stload
746c = get STGN g
747if ne n long mul c 64
748ret stref 5 0 0 g
749end
750o = get STGO g
751for j ulong c
752i = add o j
753s = strw j 64 5
754if or ge s get STNS 0 ne get STSG s g
755ret stref 5 1 j g
756end
757put STRX i strw j 64 0
758put STR0 i strw j 64 2
759put STR1 i strw j 64 3
760put STRO i strw j 64 4
761put STRS i s
762put STRC i strw j 64 6
763end
764ret 0
765end
766
767fn stexps to int
768q = ulong 0
769for g ulong get STNG 0
770r = stexpg g
771if ne r 0
772ret r
773end
774o = get STGO g
775for j ulong get STGN g
776if eq get STRO add o j 2
777q = add q 1
778end
779end
780end
781if ne q get STNQ 0
782ret stref 5 2 q 0
783end
784ret 0
785end
786
787note ---------- raw run logs ----------
788fn stcadd a ulong k ulong v ulong to void
789x = add mul a 32 k
790put STCNT x add get STCNT x v
791end
792
793fn stcmax a ulong k ulong v ulong to void
794x = add mul a 32 k
795if gt v get STCNT x
796put STCNT x v
797end
798end
799
800note the correctness the log should carry for record j (byte base o) of request i
801fn stwant a ulong i ulong o ulong to ulong
802if eq a 0
803ret 2
804end
805sg = stw add o 40
806if ne sg get STRX i
807ret 0
808end
809if ne get STRO i 2
810ret 2
811end
812if and eq stw add o 48 get STR0 i eq stw add o 56 get STR1 i
813ret 1
814end
815ret 0
816end
817
818note correctness counters for one record
819fn stcorr a ulong i ulong o ulong to void
820corr = stw add o 120
821want = stwant a i o
822if ne corr want
823stcadd a 5 1
824end
825if eq a 0
826stcadd a 4 1
827ret
828end
829bad = or eq want 0 eq corr 0
830if eq get STRO i 2
831if bad
832stcadd a 1 1
833else
834stcadd a 0 1
835end
836ret
837end
838if bad
839stcadd a 3 1
840else
841stcadd a 2 1
842end
843end
844
845note QUERY route, round-trip, hit and transfer counters
846fn stquery a ulong i ulong o ulong rt ulong to void
847rte = stw add o 64
848if le rte 5
849stcadd a add 6 rte 1
850else
851stcadd a 12 1
852end
853stcadd a 13 rt
854stcadd a 14 1
855hit = and ge rte 2 le rte 4
856if hit
857stcadd a 15 rt
858stcadd a 16 1
859end
860s = get STRS i
861if and eq a 4 eq get STSN s 2
862stcadd a 17 1
863if and ge rte 3 le rte 4
864stcadd a 18 1
865end
866end
867end
868
869note word k of the record at byte o differs from v
870fn stwne o ulong k ulong v ulong to bool
871ret ne stw add o mul k 8 v
872end
873
874note identity and expectation words of record j at byte o; 0 ok, else refusal code
875fn stchk a ulong r ulong g ulong j ulong o ulong to int
876i = add get STGO g j
877if or stwne o 0 g stwne o 1 r
878ret 8
879end
880if or stwne o 2 a stwne o 3 j
881ret 8
882end
883if stwne o 4 get STRO i
884ret 8
885end
886if or stwne o 9 get STRX i stwne o 10 get STR0 i
887ret 9
888end
889if or stwne o 11 get STR1 i stwne o 13 get STRC i
890ret 9
891end
892if stwne o 14 get STRS i
893ret 9
894end
895ret 0
896end
897
898note one raw log record j of (a, r, g), already in STFB; 0 ok, else a refusal code
899fn strec a ulong r ulong g ulong j ulong to int
900o = mul j 128
901e = stchk a r g j o
902if ne e 0
903ret e
904end
905i = add get STGO g j
906rt = stw add o 96
907put STRT add mul add mul a 3 r 65536 i rt
908slot = add mul add mul a 3 r 128 g
909put STAG slot add get STAG slot rt
910if eq j 0
911put STA0 slot rt
912end
913s = add mul a 1024 get STRS i
914put STSS s add get STSS s rt
915stcorr a i o
916if eq get STRO i 2
917stquery a i o rt
918end
919ret 0
920end
921
922fn stlog a ulong r ulong g ulong to int
923stpbase 1
924stpk SKARMP
925stpc uchar add a 48
926stpk SKREPP
927stpc uchar add r 48
928stpk SKGP
929stpu2 g
930stpk SKLOG
931n = stload
932if lt n 0
933ret stref 6 a r g
934end
935c = get STGN g
936if ne n long mul c 128
937ret stref 7 a r g
938end
939for j ulong c
940e = strec a r g j
941if ne e 0
942ret stref ulong e a r add mul g 100000 j
943end
944end
945ret 0
946end
947
948fn stlogs to int
949for a ulong 8
950for r ulong 3
951for g ulong get STNG 0
952e = stlog a r g
953if ne e 0
954ret e
955end
956end
957end
958end
959ret 0
960end
961
962note ---------- proc.log, acq.log, controls.log ----------
963fn stproc1 k ulong to int
964a = strw k 128 0
965g = strw k 128 1
966r = strw k 128 2
967if or or ge a 8 ge g get STNG 0 ge r 3
968ret stref 10 k 0 0
969end
970slot = add mul add mul a 3 r 128 g
971if ne get STPF slot 0
972ret stref 11 a r g
973end
974put STPF slot 1
975put STPR slot strw k 128 3
976put STPE slot strw k 128 15
977stcadd a 26 strw k 128 15
978stcadd a 19 1
979stcmax a 20 strw k 128 8
980stcadd a 21 strw k 128 8
981stcmax a 22 strw k 128 9
982cpu = add add strw k 128 4 strw k 128 5 add strw k 128 6 strw k 128 7
983stcadd a 23 cpu
984stpexit a strw k 128 10
985stcadd a 25 strw k 128 3
986ret 0
987end
988
989note K17 exit word x of one arm process: nonzero = a failed process, counted as one wrong
990note refusal of the arm (counter 3, so STOP for arms 1..7) and in counters 24 (exit nonzero) and
991note 28 (failed processes); x >= 1024 = END itself failed (counter 27)
992fn stpexit a ulong x ulong to void
993if eq x 0
994ret
995end
996stcadd a 24 1
997stcadd a 28 1
998stcadd a 3 1
999if ge x 1024
1000stcadd a 27 1
1001end
1002end
1003
1004fn stprocs to int
1005stpbase 1
1006stpk SKPROC
1007n = stload
1008if or lt n 0 ne rem ulong n 128 0
1009ret stref 10 0 0 0
1010end
1011for k ulong div ulong n 128
1012e = stproc1 k
1013if ne e 0
1014ret e
1015end
1016end
1017for a ulong 8
1018for r ulong 3
1019for g ulong get STNG 0
1020if eq get STPF add mul add mul a 3 r 128 g 0
1021ret stref 11 a r g
1022end
1023end
1024end
1025end
1026ret 0
1027end
1028
1029fn stacq1 k ulong to int
1030l = strw k 64 0
1031r = strw k 64 1
1032if or gt l 9 ge r 3
1033ret stref 12 k 0 0
1034end
1035x = add mul l 3 r
1036if ne get STAQF x 0
1037ret stref 12 k 1 0
1038end
1039put STAQF x 1
1040put STAQ x strw k 64 2
1041put STAQC x add strw k 64 3 strw k 64 4
1042put STAQX x strw k 64 5
1043put STAQB x strw k 64 6
1044ret 0
1045end
1046
1047fn stacqs to int
1048stpbase 1
1049stpk SKACQ
1050n = stload
1051if or lt n 0 ne rem ulong n 64 0
1052ret stref 12 0 0 0
1053end
1054for k ulong div ulong n 64
1055e = stacq1 k
1056if ne e 0
1057ret e
1058end
1059end
1060for l ulong 2
1061for r ulong 3
1062if eq get STAQF add mul add l 1 3 r 0
1063ret stref 12 add l 1 r 2
1064end
1065end
1066end
1067ret 0
1068end
1069
1070note required sub-cases of control c as a bit mask (bit s = sub-case s), the 36 pairs EvalJudge's
1071note controls run writes (confirmed with EvalJudge 2026-10-25): C1 0,1; C1b 0,1; C1c 0; C2 0,1;
1072note C3 0,1; C4 0; C5 0..5; C6 0,1,2; C7 0,1; C8 1..9 (crashafter K); C9 0,1; C10 0,1; C11 0;
1073note C12 0
1074fn stcreq c ulong to ulong
1075if or or eq c 3 eq c 6 or eq c 13 eq c 14
1076ret 1
1077end
1078if eq c 7
1079ret 63
1080end
1081if eq c 8
1082ret 7
1083end
1084if eq c 10
1085ret 1022
1086end
1087ret 3
1088end
1089
1090note required pairs of control c with no record
1091fn stcmiss c ulong to ulong
1092m = and stcreq c not get STCT add mul c 8 6
1093n = ulong 0
1094for s ulong 10
1095n = add n and shr m s 1
1096end
1097ret n
1098end
1099
1100note STCT per control id c (1..14), 8 slots: 0 records, 1 detected, 2 undetected, 3 reported,
1101note 4 not run, 5 served tampered, 6 bit mask of the sub-cases seen. A sub-case outside the
1102note required list or a repeated (control, sub-case) pair is refused (13).
1103fn stctl1 k ulong to int
1104c = strw k 64 0
1105o = strw k 64 2
1106f = strw k 64 3
1107if or or lt c 1 gt c 14 or gt o 3 gt f 1
1108ret stref 13 k 0 0
1109end
1110if and eq o 2 ne c 14
1111ret stref 13 k 1 0
1112end
1113s = strw k 64 1
1114if ge s 10
1115ret stref 13 k 2 0
1116end
1117if eq and shr stcreq c s 1 0
1118ret stref 13 k 2 0
1119end
1120b = mul c 8
1121bit = shl ulong 1 s
1122if ne and get STCT add b 6 bit 0
1123ret stref 13 k 3 0
1124end
1125put STCT add b 6 or get STCT add b 6 bit
1126put STCT b add get STCT b 1
1127if eq o 1
1128put STCT add b 1 add get STCT add b 1 1
1129end
1130if eq o 0
1131put STCT add b 2 add get STCT add b 2 1
1132end
1133if eq o 2
1134put STCT add b 3 add get STCT add b 3 1
1135end
1136if eq o 3
1137put STCT add b 4 add get STCT add b 4 1
1138end
1139if eq f 1
1140put STCT add b 5 add get STCT add b 5 1
1141end
1142ret 0
1143end
1144
1145fn stctls to int
1146if and eq get STBL 2 1 eq get STBD 8192 45
1147ret 0
1148end
1149stpbase 2
1150stpk SKCTL
1151n = stload
1152if or lt n 0 ne rem ulong n 64 0
1153ret stref 13 0 0 0
1154end
1155for k ulong div ulong n 64
1156e = stctl1 k
1157if ne e 0
1158ret e
1159end
1160end
1161ret 0
1162end
1163
1164note ---------- totals and bootstrap ----------
1165fn stlib a ulong to ulong
1166if or or eq a 3 eq a 4 eq a 7
1167ret 1
1168end
1169if eq a 6
1170ret 2
1171end
1172ret 0
1173end
1174
1175note process cost of (a, r, g)
1176fn stpcost a ulong r ulong g ulong to ulong
1177slot = add mul add mul a 3 r 128 g
1178v = add get STPR slot get STPE slot
1179ret sub add v get STAG slot get STA0 slot
1180end
1181
1182fn sttotals to void
1183for a ulong 8
1184t = ulong 0
1185for g ulong get STNG 0
1186v = ulong 0
1187for r ulong 3
1188v = add v stpcost a r g
1189end
1190put STV add mul a 128 g v
1191t = add t v
1192end
1193l = stlib a
1194q = ulong 0
1195if gt l 0
1196for r ulong 3
1197q = add q get STAQ add mul l 3 r
1198end
1199end
1200put STAA a q
1201put STT a add t q
1202end
1203end
1204
1205fn stnum s ulong to ulong
1206if lt s 8
1207ret s
1208end
1209if eq s 11
1210ret 4
1211end
1212if eq s 12
1213ret 5
1214end
1215if eq s 10
1216ret 7
1217end
1218ret 4
1219end
1220
1221fn stden s ulong to ulong
1222if lt s 8
1223ret 1
1224end
1225if eq s 8
1226ret 2
1227end
1228if eq s 9
1229ret 5
1230end
1231if eq s 10
1232ret 4
1233end
1234if eq s 11
1235ret 3
1236end
1237ret 1
1238end
1239
1240note one resample b: acc holds the 8 resampled totals
1241fn stres b ulong acc edit ulong 8 to void
1242for a ulong 8
1243put acc a get STAA a
1244end
1245g = get STNG 0
1246for i ulong g
1247x = rem stsm g
1248for a ulong 8
1249put acc a add get acc a get STV add mul a 128 x
1250end
1251end
1252for s ulong 13
1253v = stppm get acc stnum s get acc stden s
1254put STBS add mul s 10000 b v
1255end
1256end
1257
1258note ---------- heap sort of STQV[0..n) ascending, STQI moved along ----------
1259fn stswap i ulong j ulong to void
1260v = get STQV i
1261put STQV i get STQV j
1262put STQV j v
1263w = get STQI i
1264put STQI i get STQI j
1265put STQI j w
1266end
1267
1268fn stsift s ulong n ulong to void
1269r = s
1270while true bound 64
1271c = add mul r 2 1
1272if ge c n
1273break
1274end
1275if lt add c 1 n
1276if gt get STQV add c 1 get STQV c
1277c = add c 1
1278end
1279end
1280if le get STQV c get STQV r
1281break
1282end
1283stswap r c
1284r = c
1285end
1286end
1287
1288fn stsort n ulong to void
1289if lt n 2
1290ret
1291end
1292i = div n 2
1293while gt i 0 bound 999999
1294i = sub i 1
1295stsift i n
1296end
1297e = n
1298while gt e 1 bound 999999
1299e = sub e 1
1300stswap 0 e
1301stsift 0 e
1302end
1303end
1304
1305note nearest rank index for p per mille of n (n > 0): ceil(p n / 1000) - 1
1306fn strank p ulong n ulong to ulong
1307ret sub div add mul p n 999 1000 1
1308end
1309
1310fn stboot to void
1311put STRNG 0 get STSEED 0
1312acc = new ulong 8 0
1313for b ulong 10000
1314stres b acc
1315end
1316for s ulong 13
1317put STPT s stppm get STT stnum s get STT stden s
1318for b ulong 10000
1319put STQV b get STBS add mul s 10000 b
1320put STQI b 0
1321end
1322stsort 10000
1323put STLO s get STQV strank 25 10000
1324put STHI s get STQV strank 975 10000
1325end
1326end
1327
1328note ---------- categories and quantiles ----------
1329fn stcatm cat ulong s ulong to bool
1330if eq cat 0
1331ret true
1332end
1333if le cat 8
1334ret eq get STST s cat
1335end
1336if le cat 14
1337ret eq get STSN s sub cat 9
1338end
1339if le cat 16
1340ret eq get STSF s sub cat 14
1341end
1342ret eq get STSC s sub cat 17
1343end
1344
1345note request i is a QUERY with cold flag t
1346fn stisq i ulong t ulong to bool
1347if ne get STRO i 2
1348ret false
1349end
1350ret eq get STRC i t
1351end
1352
1353note fill STQV/STQI with the QUERY round trips of arm a with cold flag t; returns the count
1354fn stqfill a ulong t ulong to ulong
1355m = ulong 0
1356n = get STNR 0
1357for r ulong 3
1358base = mul add mul a 3 r 65536
1359for i ulong n
1360if stisq i t
1361put STQV m get STRT add base i
1362put STQI m get STRS i
1363m = add m 1
1364end
1365end
1366end
1367ret m
1368end
1369
1370note the value at rank k (0-based) among the sorted entries of category cat
1371fn stqpick m ulong cat ulong k ulong to ulong
1372c = ulong 0
1373for j ulong m
1374if stcatm cat get STQI j
1375if eq c k
1376ret get STQV j
1377end
1378c = add c 1
1379end
1380end
1381ret 0
1382end
1383
1384fn stqline a ulong t ulong cat ulong m ulong to void
1385c = ulong 0
1386for j ulong m
1387if stcatm cat get STQI j
1388c = add c 1
1389end
1390end
1391stks SKQUANT
1392stks SKARM
1393stks add SKARM0 a
1394stks SKTEMP
1395if eq t 1
1396stks SKCOLD
1397else
1398stks SKWARM
1399end
1400stks SKCAT
1401stks add SKCAT0 cat
1402stkv SKCOUNT c
1403if eq c 0
1404stks SKP50
1405stks SKNA
1406stks SKP95
1407stks SKNA
1408stks SKP99
1409stks SKNA
1410stnl
1411ret
1412end
1413stkv SKP50 stqpick m cat strank 500 c
1414stkv SKP95 stqpick m cat strank 950 c
1415stkv SKP99 stqpick m cat strank 990 c
1416stnl
1417end
1418
1419fn stquants to void
1420for a ulong 8
1421for t ulong 2
1422tt = sub 1 t
1423m = stqfill a tt
1424stsort m
1425for cat ulong 20
1426stqline a tt cat m
1427end
1428end
1429end
1430end
1431
1432note request round-trip sum of arm a over sessions of category cat (all reps)
1433fn stcsum a ulong cat ulong to ulong
1434v = ulong 0
1435for s ulong get STNS 0
1436if stcatm cat s
1437v = add v get STSS add mul a 1024 s
1438end
1439end
1440ret v
1441end
1442
1443fn stcatline a ulong cat ulong to void
1444d = stcsum 1 cat
1445if eq d 0
1446ret
1447end
1448stks SKCATR
1449stks SKARM
1450stks add SKARM0 a
1451stks SKCAT
1452stks add SKCAT0 cat
1453stkv SKPPM stppm stcsum a cat d
1454stnl
1455end
1456
1457fn stregime t ulong to void
1458m = stcsum 3 t
1459f = stcsum 1 t
1460if or eq m 0 eq f 0
1461ret
1462end
1463stks SKREGT
1464stks add SKCAT0 t
1465stkv SKDOM stppm stcsum 4 t m
1466stkv SKIOF stppm stcsum 5 t f
1467stnl
1468end
1469
1470note ---------- payback ----------
1471note rep-summed cost of request j of group g for arm a (request 0 = start-to-ready)
1472fn streqc a ulong g ulong j ulong to ulong
1473v = ulong 0
1474i = add get STGO g j
1475for r ulong 3
1476k = add mul a 3 r
1477if eq j 0
1478v = add v get STPR add mul k 128 g
1479else
1480v = add v get STRT add mul k 65536 i
1481end
1482end
1483ret v
1484end
1485
1486note rep-summed END round trip of arm a's processes for group g
1487fn stendc a ulong g ulong to ulong
1488v = ulong 0
1489for r ulong 3
1490v = add v get STPE add mul add mul a 3 r 128 g
1491end
1492ret v
1493end
1494
1495note one group of the payback walk; state in STPYC (cumulative) and STPYQ (QUERYs seen);
1496note true when the cumulative sum exceeds lim. The END difference is added after the group's
1497note last request, so END savings never count before that group's QUERYs.
1498fn stpayg a ulong g ulong lim long to bool
1499o = get STGO g
1500for j ulong get STGN g
1501d = sub long streqc 1 g j long streqc a g j
1502cum = add get STPYC 0 d
1503put STPYC 0 cum
1504if eq get STRO add o j 2
1505put STPYQ 0 add get STPYQ 0 1
1506end
1507if gt cum lim
1508ret true
1509end
1510end
1511d = sub long stendc 1 g long stendc a g
1512cum = add get STPYC 0 d
1513put STPYC 0 cum
1514ret gt cum lim
1515end
1516
1517note QUERYs until the cumulative (full - arm) cost exceeds acq(a); 2^64 - 1 = never
1518fn stpay a ulong to ulong
1519put STPYC 0 0
1520put STPYQ 0 0
1521lim = long get STAA a
1522for g ulong get STNG 0
1523if stpayg a g lim
1524ret get STPYQ 0
1525end
1526end
1527ret 18446744073709551615
1528end
1529
1530note ---------- report sections ----------
1531fn starmk k ulong a ulong to void
1532stks k
1533stks SKARM
1534stks add SKARM0 a
1535end
1536
1537fn sttotline a ulong to void
1538starmk SKTOTAL a
1539rt = ulong 0
1540rd = ulong 0
1541for r ulong 3
1542for g ulong get STNG 0
1543slot = add mul add mul a 3 r 128 g
1544rt = add rt get STAG slot
1545rd = add rd get STPR slot
1546end
1547end
1548stkv SKRTNS rt
1549stkv SKREADY rd
1550stkv SKENDNS stc a 26
1551stkv SKACQNS get STAA a
1552stkv SKTOTNS get STT a
1553stnl
1554end
1555
1556fn ststatline s ulong to void
1557if lt s 8
1558starmk SKRHO s
1559else
1560stks SKRATIO
1561stks add SKRAT0 sub s 8
1562end
1563stkv SKPOINT get STPT s
1564stkv SKLO get STLO s
1565stkv SKHI get STHI s
1566stnl
1567end
1568
1569fn stc a ulong k ulong to ulong
1570ret get STCNT add mul a 32 k
1571end
1572
1573fn stcorrline a ulong to void
1574starmk SKCORR a
1575stkv SKQOK stc a 0
1576stkv SKQBAD stc a 1
1577stkv SKCOK stc a 2
1578stkv SKCBAD stc a 3
1579stkv SKUNSC stc a 4
1580stkv SKINCON stc a 5
1581stkv SKPROCF stc a 28
1582stnl
1583end
1584
1585fn strouteline a ulong to void
1586starmk SKROUTE a
1587for k ulong 6
1588stks SKRN
1589stou k
1590stks SKEQ
1591stou stc a add 6 k
1592end
1593stkv SKROTH stc a 12
1594stkv SKFALL stppm stc a 11 stc a 14
1595stnl
1596end
1597
1598fn stmemline a ulong to void
1599starmk SKMEM a
1600n = stc a 19
1601stkv SKPROCS n
1602stkv SKHWMX stc a 20
1603if gt n 0
1604stkv SKHWMM div stc a 21 n
1605end
1606stkv SKRSSX stc a 22
1607stkv SKCPU stc a 23
1608stkv SKEXITN stc a 24
1609stkv SKENDF stc a 27
1610stnl
1611end
1612
1613fn stacqline l ulong to void
1614stks SKACQL
1615stou l
1616e = ulong 0
1617c = ulong 0
1618b = ulong 0
1619x = ulong 0
1620for r ulong 3
1621k = add mul l 3 r
1622e = add e get STAQ k
1623c = add c get STAQC k
1624if gt get STAQB k b
1625b = get STAQB k
1626end
1627if ne get STAQX k 0
1628x = add x 1
1629end
1630end
1631stkv SKBUILD 3
1632stkv SKELAP e
1633stkv SKCPU c
1634stkv SKLIBB b
1635stkv SKDRIVN x
1636stnl
1637end
1638
1639fn stpayline a ulong to void
1640starmk SKPAYB a
1641p = stpay a
1642put STSUM add 88 a p
1643stks SKPAYQ
1644if eq p 18446744073709551615
1645stks SKNONE
1646else
1647stou p
1648end
1649stnl
1650end
1651
1652note r + (1 - q) e + q + kn, every term in ppm (division truncates toward zero)
1653fn stcbarv r long q long e long kn long to long
1654t = div mul sub 1000000 q e 1000000
1655ret add add r t add q kn
1656end
1657
1658note the Cbar line of arm a, f = mean full QUERY round trip (ns, > 0)
1659fn stcbar2 a ulong f ulong to void
1660n = stc a 14
1661r = long stppm div stc 0 13 stc 0 14 f
1662h = stc a 16
1663e = sub long 0 r
1664if gt h 0
1665e = sub long stppm div stc a 15 h f r
1666end
1667q = long stppm sub n h n
1668k = stppm get STAA a f
1669starmk SKCBAR a
1670stkvl SKCR r
1671stkvl SKCQ q
1672stkvl SKCE e
1673stkv SKCK k
1674stkv SKCN n
1675stkvl SKCBV stcbarv r q e long div k n
1676stkv SKCOBS stppm div add stc a 13 get STAA a n f
1677stnl
1678end
1679
1680fn stcbarline a ulong to void
1681fc = stc 1 14
1682if or or eq fc 0 eq stc a 14 0 eq stc 0 14 0
1683ret
1684end
1685f = div stc 1 13 fc
1686if gt f 0
1687stcbar2 a f
1688end
1689end
1690
1691fn stecholine a ulong to void
1692num = sub long get STT a long get STT 0
1693den = sub long get STT 1 long get STT 0
1694starmk SKECHO a
1695stks SKPPM
1696if le den 0
1697stks SKNA
1698else
1699stol stppms num den
1700end
1701stnl
1702end
1703
1704note outcome word of control c: 1 detected, 0 undetected, 2 reported, 3 not run, 4 missing
1705fn stcout c ulong to ulong
1706b = mul c 8
1707if eq get STCT b 0
1708ret 4
1709end
1710if or gt get STCT add b 2 0 gt get STCT add b 5 0
1711ret 0
1712end
1713if or gt get STCT add b 4 0 gt stcmiss c 0
1714ret 3
1715end
1716if gt get STCT add b 3 0
1717ret 2
1718end
1719ret 1
1720end
1721
1722fn stctlline c ulong to void
1723b = mul c 8
1724stks SKCTLID
1725stks add SKCID0 c
1726stkv SKRECS get STCT b
1727stkv SKDET get STCT add b 1
1728stkv SKUNDET get STCT add b 2
1729stkv SKREPD get STCT add b 3
1730stkv SKNRUN get STCT add b 4
1731stkv SKTAMP get STCT add b 5
1732stkv SKMISSP stcmiss c
1733stnl
1734end
1735
1736note the outcome word of stcout value o
1737fn stocw o ulong to void
1738if eq o 1
1739stks SKOC0
1740ret
1741end
1742if eq o 0
1743stks add SKOC0 1
1744ret
1745end
1746stks add SKOC0 o
1747end
1748
1749note " Cx=<outcome word>"
1750fn stctlw c ulong to void
1751stks SKSPACE
1752stks add SKCID0 c
1753stks SKEQ
1754stocw stcout c
1755end
1756
1757note ---------- decision ----------
1758fn streason k ulong bit ulong to void
1759stks SKREAS
1760stks k
1761stnl
1762put STDEC 1 or get STDEC 1 shl ulong 1 bit
1763end
1764
1765fn streasa k ulong bit ulong a ulong to void
1766stks SKREAS
1767stks k
1768stks SKARM
1769stks add SKARM0 a
1770stnl
1771put STDEC 1 or get STDEC 1 shl ulong 1 bit
1772end
1773
1774fn streasc k ulong bit ulong c ulong to void
1775stks SKREAS
1776stks k
1777stks SKSPACE
1778stks add SKCID0 c
1779stnl
1780put STDEC 1 or get STDEC 1 shl ulong 1 bit
1781end
1782
1783note writes the reason lines; returns 3 STOP, 1 GO, 2 INVESTIGATE
1784fn stdecide to ulong
1785put STDEC 1 0
1786for a ulong 8
1787if gt a 0
1788if gt stc a 1 0
1789streasa SKRWA 0 a
1790end
1791if gt stc a 3 0
1792streasa SKRWR 1 a
1793end
1794end
1795end
1796for c ulong 15
1797if gt c 0
1798if gt get STCT add mul c 8 2 0
1799streasc SKRCU 2 c
1800end
1801if gt get STCT add mul c 8 5 0
1802streasc SKRTS 3 c
1803end
1804end
1805end
1806if ge get STLO 4 1000000
1807streason SKRLO 4
1808end
1809stop = gt get STDEC 1 0
1810if ge get STHI 4 1000000
1811streason SKRUP 5
1812end
1813if ge get STHI 8 1000000
1814streason SKRDC 6
1815end
1816if ge get STHI 9 1000000
1817streason SKRDI 7
1818end
1819tq = stc 4 17
1820if or eq tq 0 lt mul stc 4 18 2 tq
1821streason SKRCOV 8
1822end
1823for c ulong 15
1824if gt c 0
1825o = stcout c
1826if or eq o 3 eq o 4
1827streasc SKRNR 9 c
1828end
1829end
1830end
1831if stop
1832ret 3
1833end
1834if eq get STDEC 1 0
1835ret 1
1836end
1837ret 2
1838end
1839
1840fn stiss to void
1841tq = stc 4 17
1842stks SKI742
1843stou stppm stc 4 18 tq
1844stks SKBINDF
1845stks SKR5
1846stou stc 3 11
1847stks SKR5D
1848stou stc 4 11
1849stks SKRESTA
1850stocw stcout 13
1851stctlw 1
1852stctlw 2
1853stctlw 3
1854stctlw 4
1855stctlw 5
1856for c ulong 6
1857stctlw add c 8
1858end
1859stnl
1860stks SKI743
1861stks SKDOMR
1862stkv SKPOINT get STPT 11
1863stkv SKLO get STLO 11
1864stkv SKHI get STHI 11
1865stks SKIOFR
1866stkv SKPOINT get STPT 12
1867stkv SKLO get STLO 12
1868stkv SKHI get STHI 12
1869stctlw 6
1870stctlw 10
1871stnl
1872stks SKI744
1873stkv SKPOINT get STPT 10
1874stkv SKLO get STLO 10
1875stkv SKHI get STHI 10
1876m = and and eq stc 4 1 0 eq stc 4 3 0 and eq stc 7 1 0 eq stc 7 3 0
1877stks SKMATCH
1878if m
1879stks SKYES
1880else
1881stks SKNO
1882end
1883stks SKVERD
1884if lt get STHI 10 1000000
1885stks SKHELPS
1886else
1887if ge get STLO 10 1000000
1888stks SKNHELP
1889else
1890stks SKINCO
1891end
1892end
1893stnl
1894end
1895
1896note ---------- report and summary ----------
1897fn stsumw k ulong v ulong to void
1898put STSUM k v
1899end
1900
1901fn stfillsum d ulong to void
1902stsumw 0 3544386041195737426
1903stsumw 1 1
1904stsumw 2 d
1905stsumw 3 get STDEC 1
1906stsumw 4 get STNG 0
1907stsumw 5 get STNS 0
1908stsumw 6 get STNR 0
1909stsumw 7 get STNQ 0
1910stsumw 8 3
1911stsumw 9 get STSPL 0
1912stsumw 10 get STSEED 0
1913stsumw 11 10000
1914sc = ulong 0
1915ok = ulong 0
1916bad = ulong 0
1917cw = ulong 0
1918for a ulong 8
1919if gt a 0
1920ok = add ok stc a 0
1921bad = add bad stc a 1
1922cw = add cw stc a 3
1923end
1924end
1925stsumw 12 add ok bad
1926stsumw 13 ok
1927stsumw 14 bad
1928stsumw 15 cw
1929stsumw 16 stc 4 17
1930stsumw 17 stc 4 18
1931for j ulong 4
1932stsumw add 18 j get STHD j
1933end
1934ic = ulong 0
1935for a ulong 8
1936ic = add ic stc a 5
1937end
1938stsumw 22 ic
1939for s ulong 13
1940stsumw add 24 mul s 3 get STPT s
1941stsumw add 25 mul s 3 get STLO s
1942stsumw add 26 mul s 3 get STHI s
1943end
1944for a ulong 8
1945stsumw add 64 a get STT a
1946stsumw add 72 a get STAA a
1947stsumw add 80 a stc a 11
1948stsumw add 96 a stc a 28
1949stsumw add 104 a stc a 27
1950end
1951end
1952
1953fn streport to ulong
1954stks SKHEAD
1955stnl
1956stks SKINPUT
1957stou get STSPL 0
1958stkv SKGROUP get STNG 0
1959stkv SKSESN get STNS 0
1960stkv SKREQS get STNR 0
1961stkv SKQRYS get STNQ 0
1962stkv SKREPS 3
1963stnl
1964stks SKBOOT
1965stou 10000
1966stkv SKSEED get STSEED 0
1967stkv SKRKLO strank 25 10000
1968stkv SKRKHI strank 975 10000
1969stnl
1970for a ulong 8
1971sttotline a
1972end
1973for s ulong 13
1974ststatline s
1975end
1976for a ulong 8
1977stcorrline a
1978end
1979for a ulong 8
1980strouteline a
1981end
1982stks SKCOVER
1983stou stc 4 17
1984stkv SKCOVD stc 4 18
1985stkv SKCOVP stppm stc 4 18 stc 4 17
1986stnl
1987for a ulong 8
1988stmemline a
1989end
1990stacqline 1
1991stacqline 2
1992for a ulong 8
1993put STSUM add 88 a 18446744073709551615
1994if gt a 1
1995stpayline a
1996end
1997end
1998for a ulong 8
1999if gt a 1
2000stcbarline a
2001end
2002end
2003for a ulong 8
2004if ne a 1
2005stecholine a
2006end
2007end
2008for a ulong 8
2009for cat ulong 20
2010if gt cat 0
2011stcatline a cat
2012end
2013end
2014end
2015for t ulong 8
2016stregime add t 1
2017end
2018stquants
2019stks SKSTEP
2020stnl
2021for c ulong 14
2022stctlline add c 1
2023end
2024stiss
2025d = stdecide
2026stks SKDECI
2027if eq d 1
2028stks SKGO
2029end
2030if eq d 2
2031stks SKINV
2032end
2033if eq d 3
2034stks SKSTOP
2035end
2036stnl
2037stks SKVERDS
2038if eq d 1
2039stks SKGO
2040end
2041if eq d 2
2042stks SKINV
2043end
2044if eq d 3
2045stks SKSTOP
2046end
2047stks SKSIMNR
2048stnl
2049ret d
2050end
2051
2052note one little-endian word appended to STOB
2053fn stow v ulong to void
2054for b ulong 8
2055stoc uchar and shr v mul b 8 255
2056end
2057end
2058
2059note STSUM as 2048 bytes into STOB (replacing its contents)
2060fn stsumbytes to void
2061put STOP 0 0
2062for k ulong 256
2063stow get STSUM k
2064end
2065end
2066
2067note the path now in STPB becomes base slot b
2068fn stbfromp b ulong to void
2069o = mul b 4096
2070n = get STPL 0
2071for i ulong n
2072put STBD add o i get STPB i
2073end
2074put STBL b n
2075end
2076
2077note zero every accumulator, so one process can run several evaluations (tests)
2078fn streset to void
2079for i ulong len STCNT
2080put STCNT i 0
2081end
2082for i ulong len STAG
2083put STAG i 0
2084put STA0 i 0
2085put STPR i 0
2086put STPE i 0
2087put STPF i 0
2088end
2089for i ulong len STSS
2090put STSS i 0
2091end
2092for i ulong len STAQ
2093put STAQ i 0
2094put STAQC i 0
2095put STAQX i 0
2096put STAQB i 0
2097put STAQF i 0
2098end
2099for i ulong len STCT
2100put STCT i 0
2101end
2102for i ulong len STSUM
2103put STSUM i 0
2104end
2105put STDEC 0 0
2106put STDEC 1 0
2107put STOP 0 0
2108end
2109
2110note runs every reading step; 0 ok, else refusal code
2111fn stread to int
2112e = stidx
2113if ne e 0
2114ret e
2115end
2116e = stsess
2117if ne e 0
2118ret e
2119end
2120e = stexps
2121if ne e 0
2122ret e
2123end
2124e = stlogs
2125if ne e 0
2126ret e
2127end
2128e = stprocs
2129if ne e 0
2130ret e
2131end
2132e = stacqs
2133if ne e 0
2134ret e
2135end
2136ret stctls
2137end
2138
2139note prints the refusal line to stdout; returns the exit code 2
2140fn stfail code ulong d ulong to int
2141r = stref code d 0 0
2142stprref
2143w = stflush 1
2144ret 2
2145end
2146
2147note the evaluation on base slots 0 split, 1 run, 2 ctrl (- = none), 3 out and the seed in
2148note STSEED; the report goes to stdout unless STQT is 1. Returns the exit code.
2149fn strun to int
2150streset
2151e = stread
2152if ne e 0
2153stprref
2154if ne get STQT 0 1
2155r = stflush 1
2156end
2157ret 2
2158end
2159sttotals
2160stboot
2161d = streport
2162stfillsum d
2163if ne get STQT 0 1
2164r = stflush 1
2165end
2166stpbase 3
2167stpk SKTXT
2168w = stwfile
2169if ne w 0
2170ret 15
2171end
2172stsumbytes
2173stpbase 3
2174stpk SKSUM
2175w = stwfile
2176if ne w 0
2177ret 15
2178end
2179ret 0
2180end
2181
2182fn stmain to int
2183put STOP 0 0
2184if lt argcnt 7
2185ret stfail 1 0
2186end
2187l0 = stargb 2 0
2188l1 = stargb 3 1
2189l2 = stargb 4 2
2190l3 = stargb 5 3
2191if ne l3 64
2192ret stfail 1 1
2193end
2194put STRF 3 0
2195put STSEED 0 sthexw 3 0
2196if ne get STRF 3 0
2197ret stfail 1 2
2198end
2199l4 = stargb 6 3
2200if or or eq l0 0 eq l1 0 or eq l2 0 eq l4 0
2201ret stfail 1 3
2202end
2203ret strun
2204end