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 / turing.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note turing.om (lane EvalStats, spark-rsi-mv #73): Turing accounting of REUSE-1 section 8 under |
| 3 | note calibration/profiles/Turing-profile-REUSE-v1.0.toml. Needs the units sha256 and stats (st* |
| 4 | note helpers: paths, files, output, split readers). Names: functions tu*, globals TU*. |
| 5 | note |
| 6 | note CLI (argv[1] is the dispatcher's subcommand): |
| 7 | note turing SPLITDIR PROFILE TRAINLIB TRAINPLIB BASEOM CODER OUTDIR |
| 8 | note SPLITDIR = the FINAL split (index, sessions, gNN.exp); PROFILE = the profile TOML file; |
| 9 | note TRAINLIB, TRAINPLIB = the evaluator's rebuilt LIBDIRs (CURRENT, gen-G.man, gen-G.om); |
| 10 | note BASEOM = base.om written by drive base; CODER = the external turing-coder referee |
| 11 | note (omega-mv a647b6a9 src/turing), or - (T_real is then NOT_RUN); OUTDIR receives B.tps, |
| 12 | note M1.tps (TRAIN library), M2.tps (TRAINP library), D.tsy, the coded files X.tps.rans and |
| 13 | note X.tps.range, and turing.txt (the report, also on stdout). |
| 14 | note Exit 0 = report written; 2 = inputs refused (status=REFUSED code=N); 15 = output failure. |
| 15 | note |
| 16 | note D: the low 4 bits of r0 of every QUERY record of gNN.exp, groups in order, records in order |
| 17 | note (the evaluator's reference = repetition 1 of every arm). One TPS1 record per symbol t: |
| 18 | note observation_index t, context_key 0, crumb ordinal t, norm_sum 65536, q = 65521 on the symbol |
| 19 | note and 1 on each of the 15 others (CODER_SPEC sections 2 and 3; K 16, qbits 16). |
| 20 | note profile_digest = SHA-256 of the profile file bytes; dataset_digest = the FINAL holdout digest |
| 21 | note (index words 7..10, each word's 8 bytes big endian); model_digest = SHA-256( |
| 22 | note "turing.reuse.model.v1" 0x00 || the 2048 manifest bytes of the arm's library), and for B the |
| 23 | note hashed bytes are 32 zero bytes (the profile's "or 32 zero bytes for B", read as the payload). |
| 24 | note Trailers: SHA-256("turing.tc.pstream.v1" 0x00 || header || records) and |
| 25 | note SHA-256("turing.tc.symbols.v1" 0x00 || header || symbols). |
| 26 | note |
| 27 | note Charges (profile model_code): P1 = 64 bits x 8 manifest words per template (manifest word 4 |
| 28 | note = K) plus, for select, 64 bits x 193 calibration values (192 cell words + E_q) when the |
| 29 | note manifest names a calibration file (words 52..55 not all 0). P2 = 8 bits x (bytes of gen-G.om |
| 30 | note - bytes of base.om + 2048 manifest bytes). Models: method, delta, select = M1; deltap = M2; |
| 31 | note idelta, cache = B (no charge). |
| 32 | note L_ideal(D|X) = n ub(65521) micro-bits for every model (CODER_SPEC section 8 rule). The data |
| 33 | note terms are equal, so T_ideal(arm) = -charge. T_real(arm, coder) = -charge + 8 (coded bytes |
| 34 | note of B - coded bytes of M), each coded file run through `CODER encode` then `CODER verify`. |
| 35 | note H1 per coded file: |coded bits x 10^6 - ideal ub - 448 x 10^6| <= 64 x 10^6 + 1000 n. |
| 36 | note No Turing verdict word is issued (profile verdict_rule). |
| 37 | note |
| 38 | note Refusal codes: 1 usage, 2 split (detail = the stats refusal code), 3 profile unreadable, |
| 39 | note 4 library CURRENT or manifest invalid (detail 1 TRAIN, 2 TRAINP), 5 base.om unreadable, |
| 40 | note 7 too many symbols for the TPS1 buffer, 15 output write failed. |
| 41 | |
| 42 | text TUK "turing.reuse.model.v1\nturing.tc.pstream.v1\nturing.tc.symbols.v1\nCURRENT\ngen-\n.man\n.om\nB.tps\nD.tsy\nM1.tps\nM2.tps\nencode\nverify\nrans\nrange\n.\nturing.txt\nreport=reuse1-turing version=1 profile=Turing-profile-REUSE-v1.0\nprofile_sha256=\n dataset_sha256=\n n=\n k=16\nmodel name=\n model_sha256=\n tps1_trailer=\n generation=\n k_templates=\n calibration=\n gen_om_bytes=\n base_om_bytes=\ndata ideal_ub=\n ub_per_symbol=\ncoded model=\n coder=\n bytes=\n overhead_ub=\n h1=\nPASS\nFAIL\nNOT_RUN\ncharge arm=\n p1_bits=\n p2_bits=\nturing arm=\n t_ideal_p1_bits=\n t_real_p1_bits_rans=\n t_real_p1_bits_range=\n t_ideal_p2_bits=\n t_real_p2_bits_rans=\n t_real_p2_bits_range=\nB\nM1\nM2\ndelta_t=NOT_APPLICABLE reason=one_library_generation_per_arm verdict=none\nstatus=REFUSED code=\n exit=\nyes\nno\nh1_all=\n tsy1_trailer=\n detail=\n" |
| 43 | |
| 44 | const TKMOD ulong 0 |
| 45 | const TKPST ulong 1 |
| 46 | const TKSYM ulong 2 |
| 47 | const TKCUR ulong 3 |
| 48 | const TKGEN ulong 4 |
| 49 | const TKMAN ulong 5 |
| 50 | const TKOM ulong 6 |
| 51 | const TKBTPS ulong 7 |
| 52 | const TKDTSY ulong 8 |
| 53 | const TKM1 ulong 9 |
| 54 | const TKM2 ulong 10 |
| 55 | const TKENC ulong 11 |
| 56 | const TKVER ulong 12 |
| 57 | const TKRANS ulong 13 |
| 58 | const TKRANGE ulong 14 |
| 59 | const TKDOT ulong 15 |
| 60 | const TKTXT ulong 16 |
| 61 | const TKHEAD ulong 17 |
| 62 | const TKPROF ulong 18 |
| 63 | const TKDATA ulong 19 |
| 64 | const TKN ulong 20 |
| 65 | const TKK ulong 21 |
| 66 | const TKMODEL ulong 22 |
| 67 | const TKMSHA ulong 23 |
| 68 | const TKTRAIL ulong 24 |
| 69 | const TKGENER ulong 25 |
| 70 | const TKKT ulong 26 |
| 71 | const TKCAL ulong 27 |
| 72 | const TKGOMB ulong 28 |
| 73 | const TKBOMB ulong 29 |
| 74 | const TKIDEAL ulong 30 |
| 75 | const TKUBPS ulong 31 |
| 76 | const TKCODED ulong 32 |
| 77 | const TKCODER ulong 33 |
| 78 | const TKBYTES ulong 34 |
| 79 | const TKOVH ulong 35 |
| 80 | const TKH1 ulong 36 |
| 81 | const TKPASS ulong 37 |
| 82 | const TKFAIL ulong 38 |
| 83 | const TKNRUN ulong 39 |
| 84 | const TKCHG ulong 40 |
| 85 | const TKP1 ulong 41 |
| 86 | const TKP2 ulong 42 |
| 87 | const TKTUR ulong 43 |
| 88 | const TKTI1 ulong 44 |
| 89 | const TKTR1R ulong 45 |
| 90 | const TKTR1G ulong 46 |
| 91 | const TKTI2 ulong 47 |
| 92 | const TKTR2R ulong 48 |
| 93 | const TKTR2G ulong 49 |
| 94 | const TKMB ulong 50 |
| 95 | const TKDELT ulong 53 |
| 96 | const TKREFU ulong 54 |
| 97 | const TKEXIT ulong 55 |
| 98 | const TKYES ulong 56 |
| 99 | const TKNO ulong 57 |
| 100 | const TKH1ALL ulong 58 |
| 101 | const TKTSYT ulong 59 |
| 102 | const TKDETL ulong 60 |
| 103 | |
| 104 | global TUFB uchar 8388608 |
| 105 | global TUFL ulong 1 |
| 106 | global TUD ulong 4 |
| 107 | global TUPD ulong 4 |
| 108 | global TUMD ulong 12 |
| 109 | global TUTR ulong 12 |
| 110 | global TUSYT ulong 4 |
| 111 | global TUSY uchar 1048576 |
| 112 | global TUN ulong 1 |
| 113 | global TUKT ulong 3 |
| 114 | global TUCAL ulong 3 |
| 115 | global TUGEN ulong 3 |
| 116 | global TUGOM ulong 3 |
| 117 | global TUBOM ulong 1 |
| 118 | global TUCS ulong 6 |
| 119 | global TUCX ulong 6 |
| 120 | global TUPK uchar 4096 |
| 121 | global TUPKL ulong 1 |
| 122 | global TUWS uchar 4 |
| 123 | global TURF ulong 2 |
| 124 | |
| 125 | note ---------- text table ---------- |
| 126 | fn tukoff k ulong to ulong |
| 127 | i = ulong 0 |
| 128 | c = ulong 0 |
| 129 | while lt c k bound 999999 |
| 130 | if eq get TUK i 10 |
| 131 | c = add c 1 |
| 132 | end |
| 133 | i = add i 1 |
| 134 | end |
| 135 | ret i |
| 136 | end |
| 137 | |
| 138 | fn tuks k ulong to void |
| 139 | i = tukoff k |
| 140 | while ne get TUK i 10 bound 4096 |
| 141 | stoc get TUK i |
| 142 | i = add i 1 |
| 143 | end |
| 144 | end |
| 145 | |
| 146 | fn tukp k ulong to void |
| 147 | i = tukoff k |
| 148 | while ne get TUK i 10 bound 4096 |
| 149 | stpc get TUK i |
| 150 | i = add i 1 |
| 151 | end |
| 152 | end |
| 153 | |
| 154 | note length of string k |
| 155 | fn tuklen k ulong to ulong |
| 156 | i = tukoff k |
| 157 | s = i |
| 158 | while ne get TUK i 10 bound 4096 |
| 159 | i = add i 1 |
| 160 | end |
| 161 | ret sub i s |
| 162 | end |
| 163 | |
| 164 | note ---------- SHA-256 over global bytes ---------- |
| 165 | note copies n bytes of source src (0 TUFB, 1 STFB, 2 TUSY) from byte off into b |
| 166 | fn tucopy b edit uchar 4096 src ulong off ulong n ulong to void |
| 167 | for i ulong n |
| 168 | if eq src 0 |
| 169 | put b i get TUFB add off i |
| 170 | else |
| 171 | if eq src 1 |
| 172 | put b i get STFB add off i |
| 173 | else |
| 174 | put b i get TUSY add off i |
| 175 | end |
| 176 | end |
| 177 | end |
| 178 | end |
| 179 | |
| 180 | note string k then a zero byte into b; returns the length |
| 181 | fn tutag b edit uchar 4096 k ulong to ulong |
| 182 | i = tukoff k |
| 183 | n = ulong 0 |
| 184 | while ne get TUK i 10 bound 4096 |
| 185 | put b n get TUK i |
| 186 | n = add n 1 |
| 187 | i = add i 1 |
| 188 | end |
| 189 | put b n 0 |
| 190 | ret add n 1 |
| 191 | end |
| 192 | |
| 193 | note SHA-256 of (domain string tag and 0x00, unless tag >= 1000) || src[off .. off + n) into TUD |
| 194 | note (TUD word j = digest bytes 8j..8j+7 read little endian) |
| 195 | fn tusha tag ulong src ulong off ulong n ulong to void |
| 196 | c = new uchar 104 0 |
| 197 | b = new uchar 4096 0 |
| 198 | w = new ulong 64 0 |
| 199 | b8 = new ulong 512 0 |
| 200 | omsha c b 0 0 w b8 |
| 201 | if lt tag 1000 |
| 202 | m = tutag b tag |
| 203 | omsha c b m 1 w b8 |
| 204 | end |
| 205 | o = ulong 0 |
| 206 | while lt o n bound 999999 |
| 207 | m = sub n o |
| 208 | if gt m 4096 |
| 209 | m = 4096 |
| 210 | end |
| 211 | tucopy b src add off o m |
| 212 | omsha c b m 1 w b8 |
| 213 | o = add o m |
| 214 | end |
| 215 | omsha c b 0 2 w b8 |
| 216 | for j ulong 4 |
| 217 | put TUD j get w j |
| 218 | end |
| 219 | end |
| 220 | |
| 221 | note the 32 digest bytes of TUD as hex |
| 222 | fn tuohd to void |
| 223 | for j ulong 4 |
| 224 | v = get TUD j |
| 225 | for k ulong 8 |
| 226 | stohb and shr v mul k 8 255 |
| 227 | end |
| 228 | end |
| 229 | end |
| 230 | |
| 231 | note ---------- TPS1 / TSY1 byte building in TUFB ---------- |
| 232 | fn tub v ulong to void |
| 233 | p = get TUFL 0 |
| 234 | put TUFB p uchar and v 255 |
| 235 | put TUFL 0 add p 1 |
| 236 | end |
| 237 | |
| 238 | note little-endian integer of nb bytes |
| 239 | fn tule v ulong nb ulong to void |
| 240 | for k ulong nb |
| 241 | tub shr v mul k 8 |
| 242 | end |
| 243 | end |
| 244 | |
| 245 | note 32 bytes of digest words (word j little-endian bytes) |
| 246 | fn tudig4 a ulong b ulong c ulong d ulong to void |
| 247 | tule a 8 |
| 248 | tule b 8 |
| 249 | tule c 8 |
| 250 | tule d 8 |
| 251 | end |
| 252 | |
| 253 | note the dataset digest: index words 7..10, each word's bytes big endian |
| 254 | fn tudata to void |
| 255 | for j ulong 4 |
| 256 | v = get STHD j |
| 257 | for k ulong 8 |
| 258 | tub shr v mul sub 7 k 8 |
| 259 | end |
| 260 | end |
| 261 | end |
| 262 | |
| 263 | note TPS1 for model m (0 B, 1 M1, 2 M2) into TUFB; trailer digest stored in TUTR |
| 264 | fn tutps m ulong to void |
| 265 | put TUFL 0 0 |
| 266 | tule 827543636 4 |
| 267 | tule 1 2 |
| 268 | tule 16 1 |
| 269 | tule 16 1 |
| 270 | tule 0 4 |
| 271 | n = get TUN 0 |
| 272 | tule n 8 |
| 273 | tule 56 4 |
| 274 | tule 0 4 |
| 275 | tudig4 get TUPD 0 get TUPD 1 get TUPD 2 get TUPD 3 |
| 276 | b = mul m 4 |
| 277 | tudig4 get TUMD b get TUMD add b 1 get TUMD add b 2 get TUMD add b 3 |
| 278 | tudata |
| 279 | tule 0 4 |
| 280 | for t ulong n |
| 281 | tule t 8 |
| 282 | tule 0 8 |
| 283 | tule t 4 |
| 284 | tule 65536 4 |
| 285 | s = ulong get TUSY t |
| 286 | for x ulong 16 |
| 287 | if eq x s |
| 288 | tule 65521 2 |
| 289 | else |
| 290 | tule 1 2 |
| 291 | end |
| 292 | end |
| 293 | end |
| 294 | tusha TKPST 0 0 get TUFL 0 |
| 295 | for j ulong 4 |
| 296 | put TUTR add b j get TUD j |
| 297 | tule get TUD j 8 |
| 298 | end |
| 299 | end |
| 300 | |
| 301 | note TSY1 into TUFB |
| 302 | fn tutsy to void |
| 303 | put TUFL 0 0 |
| 304 | tule 827937620 4 |
| 305 | tule 1 2 |
| 306 | tule 16 1 |
| 307 | tule 0 1 |
| 308 | n = get TUN 0 |
| 309 | tule n 8 |
| 310 | tule 0 8 |
| 311 | tudata |
| 312 | for t ulong n |
| 313 | tub ulong get TUSY t |
| 314 | end |
| 315 | tusha TKSYM 0 0 get TUFL 0 |
| 316 | for j ulong 4 |
| 317 | put TUSYT j get TUD j |
| 318 | tule get TUD j 8 |
| 319 | end |
| 320 | end |
| 321 | |
| 322 | note TUFB[0..TUFL) to the path in STPB; 0 ok |
| 323 | fn tuwfile to int |
| 324 | fd = fopen STPB 0 get STPL 0 577 420 |
| 325 | if lt fd 0 |
| 326 | ret 1 |
| 327 | end |
| 328 | n = get TUFL 0 |
| 329 | o = ulong 0 |
| 330 | while lt o n bound 999999 |
| 331 | w = write int fd TUFB o sub n o |
| 332 | if le w 0 |
| 333 | c = fclose int fd |
| 334 | ret 1 |
| 335 | end |
| 336 | o = add o ulong w |
| 337 | end |
| 338 | s = fsync int fd |
| 339 | c = fclose int fd |
| 340 | if or ne s 0 ne c 0 |
| 341 | ret 1 |
| 342 | end |
| 343 | ret 0 |
| 344 | end |
| 345 | |
| 346 | note output file name of model m (k = TKBTPS, TKM1, TKM2) in OUTDIR (slot 6) |
| 347 | fn tutpsname m ulong to void |
| 348 | stpbase 6 |
| 349 | if eq m 0 |
| 350 | tukp TKBTPS |
| 351 | end |
| 352 | if eq m 1 |
| 353 | tukp TKM1 |
| 354 | end |
| 355 | if eq m 2 |
| 356 | tukp TKM2 |
| 357 | end |
| 358 | end |
| 359 | |
| 360 | note ---------- D ---------- |
| 361 | fn tusyms to int |
| 362 | n = ulong 0 |
| 363 | for i ulong get STNR 0 |
| 364 | if eq get STRO i 2 |
| 365 | if ge n len TUSY |
| 366 | ret 7 |
| 367 | end |
| 368 | put TUSY n uchar and get STR0 i 15 |
| 369 | n = add n 1 |
| 370 | end |
| 371 | end |
| 372 | put TUN 0 n |
| 373 | ret 0 |
| 374 | end |
| 375 | |
| 376 | note ---------- libraries ---------- |
| 377 | note checks library l (1 TRAIN in slot 2, 2 TRAINP in slot 3): CURRENT, gen-G.man (magic, SHA-256 |
| 378 | note equal to CURRENT's), K, calibration presence, model digest, gen-G.om size. 0 ok. |
| 379 | fn tulib l ulong to int |
| 380 | s = add l 1 |
| 381 | stpbase s |
| 382 | tukp TKCUR |
| 383 | n = stload |
| 384 | if ne n 40 |
| 385 | ret 1 |
| 386 | end |
| 387 | g = stw 0 |
| 388 | cd = new ulong 4 0 |
| 389 | for j ulong 4 |
| 390 | put cd j stw add 8 mul j 8 |
| 391 | end |
| 392 | put TUGEN l g |
| 393 | stpbase s |
| 394 | tukp TKGEN |
| 395 | stpu g |
| 396 | tukp TKMAN |
| 397 | n = stload |
| 398 | if ne n 2048 |
| 399 | ret 2 |
| 400 | end |
| 401 | if ne stw 0 3544386019401740626 |
| 402 | ret 3 |
| 403 | end |
| 404 | tusha 1000 1 0 2048 |
| 405 | for j ulong 4 |
| 406 | if ne get TUD j get cd j |
| 407 | ret 4 |
| 408 | end |
| 409 | end |
| 410 | put TUKT l stw 32 |
| 411 | cal = or or stw 416 stw 424 or stw 432 stw 440 |
| 412 | put TUCAL l 0 |
| 413 | if ne cal 0 |
| 414 | put TUCAL l 1 |
| 415 | end |
| 416 | tusha TKMOD 1 0 2048 |
| 417 | for j ulong 4 |
| 418 | put TUMD add mul l 4 j get TUD j |
| 419 | end |
| 420 | stpbase s |
| 421 | tukp TKGEN |
| 422 | stpu g |
| 423 | tukp TKOM |
| 424 | n = stload |
| 425 | if lt n 0 |
| 426 | ret 5 |
| 427 | end |
| 428 | put TUGOM l ulong n |
| 429 | ret 0 |
| 430 | end |
| 431 | |
| 432 | note B's model digest over 32 zero bytes |
| 433 | fn tubmodel to void |
| 434 | for i ulong 32 |
| 435 | put STFB i 0 |
| 436 | end |
| 437 | tusha TKMOD 1 0 32 |
| 438 | for j ulong 4 |
| 439 | put TUMD j get TUD j |
| 440 | end |
| 441 | end |
| 442 | |
| 443 | note ---------- the external coder ---------- |
| 444 | fn tupkc c uchar to void |
| 445 | p = get TUPKL 0 |
| 446 | put TUPK p c |
| 447 | put TUPKL 0 add p 1 |
| 448 | end |
| 449 | |
| 450 | note appends the path in STPB as one packed record |
| 451 | fn tupkpath to void |
| 452 | n = get STPL 0 |
| 453 | tupkc uchar and n 255 |
| 454 | tupkc uchar shr n 8 |
| 455 | for i ulong n |
| 456 | tupkc get STPB i |
| 457 | end |
| 458 | end |
| 459 | |
| 460 | fn tupkk k ulong to void |
| 461 | n = tuklen k |
| 462 | tupkc uchar n |
| 463 | tupkc 0 |
| 464 | i = tukoff k |
| 465 | for j ulong n |
| 466 | tupkc get TUK add i j |
| 467 | end |
| 468 | end |
| 469 | |
| 470 | note runs the packed list; returns the exit code, 256 + signal, or 512 when fork or exec failed |
| 471 | fn turun to ulong |
| 472 | put TUPK 0 6 |
| 473 | put TUPK 1 0 |
| 474 | pid = fork |
| 475 | if lt pid 0 |
| 476 | ret 512 |
| 477 | end |
| 478 | if eq pid 0 |
| 479 | d = dupfd 2 1 0 |
| 480 | r = execprog TUPK 0 get TUPKL 0 |
| 481 | exit 127 |
| 482 | end |
| 483 | r = waitpid int pid TUWS 0 4 0 |
| 484 | if ne r pid |
| 485 | ret 512 |
| 486 | end |
| 487 | sg = and ulong get TUWS 0 127 |
| 488 | if ne sg 0 |
| 489 | ret add 256 sg |
| 490 | end |
| 491 | ret ulong get TUWS 1 |
| 492 | end |
| 493 | |
| 494 | note the coded file name of model m, coder c (0 rans, 1 range) as the path |
| 495 | fn tucodedname m ulong c ulong to void |
| 496 | tutpsname m |
| 497 | tukp TKDOT |
| 498 | if eq c 0 |
| 499 | tukp TKRANS |
| 500 | else |
| 501 | tukp TKRANGE |
| 502 | end |
| 503 | end |
| 504 | |
| 505 | note CODER op coder model: op TKENC or TKVER |
| 506 | fn tucoder op ulong m ulong c ulong to ulong |
| 507 | put TUPKL 0 2 |
| 508 | stpexact 5 |
| 509 | tupkpath |
| 510 | tupkk op |
| 511 | if eq c 0 |
| 512 | tupkk TKRANS |
| 513 | else |
| 514 | tupkk TKRANGE |
| 515 | end |
| 516 | tutpsname m |
| 517 | tupkpath |
| 518 | stpbase 6 |
| 519 | tukp TKDTSY |
| 520 | tupkpath |
| 521 | tucodedname m c |
| 522 | tupkpath |
| 523 | ret turun |
| 524 | end |
| 525 | |
| 526 | note encode, verify and size one coded file; TUCX = exit (0 ok), TUCS = bytes |
| 527 | fn tucode m ulong c ulong to void |
| 528 | x = add mul m 2 c |
| 529 | e = tucoder TKENC m c |
| 530 | if eq e 0 |
| 531 | e = tucoder TKVER m c |
| 532 | end |
| 533 | put TUCX x e |
| 534 | put TUCS x 0 |
| 535 | if ne e 0 |
| 536 | ret |
| 537 | end |
| 538 | tucodedname m c |
| 539 | n = stload |
| 540 | if lt n 56 |
| 541 | put TUCX x 600 |
| 542 | ret |
| 543 | end |
| 544 | if ne stw 48 sub ulong n 56 |
| 545 | put TUCX x 601 |
| 546 | ret |
| 547 | end |
| 548 | put TUCS x ulong n |
| 549 | end |
| 550 | |
| 551 | note ---------- CODER_SPEC section 8 ideal length ---------- |
| 552 | fn tuub q ulong to ulong |
| 553 | ip = ulong 0 |
| 554 | for i ulong 64 |
| 555 | if ne and shr q i 1 0 |
| 556 | ip = i |
| 557 | end |
| 558 | end |
| 559 | m = shl q sub 62 ip |
| 560 | frac = ulong 0 |
| 561 | for i ulong 32 |
| 562 | stmul m m |
| 563 | m = or shl get STHL 0 2 shr get STHL 1 62 |
| 564 | if ge m 9223372036854775808 |
| 565 | frac = or frac shl ulong 1 sub 31 i |
| 566 | m = shr m 1 |
| 567 | end |
| 568 | end |
| 569 | lg = or shl ip 32 frac |
| 570 | x = sub 68719476736 lg |
| 571 | ret shr add mul x 1000000 2147483648 32 |
| 572 | end |
| 573 | |
| 574 | note ---------- report ---------- |
| 575 | note model of arm a: 0 B, 1 M1, 2 M2 |
| 576 | fn tumodel a ulong to ulong |
| 577 | if or or eq a 3 eq a 4 eq a 7 |
| 578 | ret 1 |
| 579 | end |
| 580 | if eq a 6 |
| 581 | ret 2 |
| 582 | end |
| 583 | ret 0 |
| 584 | end |
| 585 | |
| 586 | fn tup1 a ulong to ulong |
| 587 | m = tumodel a |
| 588 | if eq m 0 |
| 589 | ret 0 |
| 590 | end |
| 591 | v = mul 512 get TUKT m |
| 592 | if and eq a 7 eq get TUCAL m 1 |
| 593 | v = add v 12352 |
| 594 | end |
| 595 | ret v |
| 596 | end |
| 597 | |
| 598 | fn tup2 a ulong to long |
| 599 | m = tumodel a |
| 600 | if eq m 0 |
| 601 | ret 0 |
| 602 | end |
| 603 | d = sub long get TUGOM m long get TUBOM 0 |
| 604 | ret mul 8 add d 2048 |
| 605 | end |
| 606 | |
| 607 | note T_real for charge ch (bits) and coder c: -ch + 8 (bytes of B - bytes of M); 0 = NOT_RUN flag in TURF |
| 608 | fn tureal ch long m ulong c ulong to long |
| 609 | put TURF 0 0 |
| 610 | if or ne get TUCX c 0 ne get TUCX add mul m 2 c 0 |
| 611 | put TURF 0 1 |
| 612 | ret 0 |
| 613 | end |
| 614 | d = sub long get TUCS c long get TUCS add mul m 2 c |
| 615 | ret add neg ch mul 8 d |
| 616 | end |
| 617 | |
| 618 | fn tuoreal ch long m ulong c ulong to void |
| 619 | v = tureal ch m c |
| 620 | if eq get TURF 0 1 |
| 621 | tuks TKNRUN |
| 622 | else |
| 623 | stol v |
| 624 | end |
| 625 | end |
| 626 | |
| 627 | fn tuarmline a ulong to void |
| 628 | p1 = long tup1 a |
| 629 | p2 = tup2 a |
| 630 | m = tumodel a |
| 631 | tuks TKCHG |
| 632 | stks add SKARM0 a |
| 633 | tuks TKP1 |
| 634 | stol p1 |
| 635 | tuks TKP2 |
| 636 | stol p2 |
| 637 | stnl |
| 638 | tuks TKTUR |
| 639 | stks add SKARM0 a |
| 640 | tuks TKTI1 |
| 641 | stol neg p1 |
| 642 | tuks TKTR1R |
| 643 | tuoreal p1 m 0 |
| 644 | tuks TKTR1G |
| 645 | tuoreal p1 m 1 |
| 646 | tuks TKTI2 |
| 647 | stol neg p2 |
| 648 | tuks TKTR2R |
| 649 | tuoreal p2 m 0 |
| 650 | tuks TKTR2G |
| 651 | tuoreal p2 m 1 |
| 652 | stnl |
| 653 | end |
| 654 | |
| 655 | note H1 for coded file x: returns 1 PASS, 0 FAIL, 2 NOT_RUN |
| 656 | fn tuh1 x ulong to ulong |
| 657 | if ne get TUCX x 0 |
| 658 | ret 2 |
| 659 | end |
| 660 | n = get TUN 0 |
| 661 | id = mul n tuub 65521 |
| 662 | cb = mul get TUCS x 8000000 |
| 663 | ov = sub long sub long cb long id 448000000 |
| 664 | if lt ov 0 |
| 665 | ov = neg ov |
| 666 | end |
| 667 | if le ov long add 64000000 mul 1000 n |
| 668 | ret 1 |
| 669 | end |
| 670 | ret 0 |
| 671 | end |
| 672 | |
| 673 | fn tucodedline m ulong c ulong to ulong |
| 674 | x = add mul m 2 c |
| 675 | tuks TKCODED |
| 676 | tuks add TKMB m |
| 677 | tuks TKCODER |
| 678 | if eq c 0 |
| 679 | tuks TKRANS |
| 680 | else |
| 681 | tuks TKRANGE |
| 682 | end |
| 683 | h = tuh1 x |
| 684 | if eq h 2 |
| 685 | if ne get TUCX x 1000 |
| 686 | tuks TKEXIT |
| 687 | stou get TUCX x |
| 688 | end |
| 689 | tuks TKH1 |
| 690 | tuks TKNRUN |
| 691 | stnl |
| 692 | ret h |
| 693 | end |
| 694 | tuks TKBYTES |
| 695 | stou get TUCS x |
| 696 | n = get TUN 0 |
| 697 | tuks TKOVH |
| 698 | stol sub long mul get TUCS x 8000000 long mul n tuub 65521 |
| 699 | tuks TKH1 |
| 700 | if eq h 1 |
| 701 | tuks TKPASS |
| 702 | else |
| 703 | tuks TKFAIL |
| 704 | end |
| 705 | stnl |
| 706 | ret h |
| 707 | end |
| 708 | |
| 709 | fn tumodelline m ulong to void |
| 710 | tuks TKMODEL |
| 711 | tuks add TKMB m |
| 712 | tuks TKMSHA |
| 713 | b = mul m 4 |
| 714 | for j ulong 4 |
| 715 | v = get TUMD add b j |
| 716 | for k ulong 8 |
| 717 | stohb and shr v mul k 8 255 |
| 718 | end |
| 719 | end |
| 720 | tuks TKTRAIL |
| 721 | for j ulong 4 |
| 722 | v = get TUTR add b j |
| 723 | for k ulong 8 |
| 724 | stohb and shr v mul k 8 255 |
| 725 | end |
| 726 | end |
| 727 | if gt m 0 |
| 728 | tuks TKGENER |
| 729 | stou get TUGEN m |
| 730 | tuks TKKT |
| 731 | stou get TUKT m |
| 732 | tuks TKCAL |
| 733 | if eq get TUCAL m 1 |
| 734 | tuks TKYES |
| 735 | else |
| 736 | tuks TKNO |
| 737 | end |
| 738 | tuks TKGOMB |
| 739 | stou get TUGOM m |
| 740 | tuks TKBOMB |
| 741 | stou get TUBOM 0 |
| 742 | end |
| 743 | stnl |
| 744 | end |
| 745 | |
| 746 | fn tureport to void |
| 747 | tuks TKHEAD |
| 748 | stnl |
| 749 | tuks TKPROF |
| 750 | for j ulong 4 |
| 751 | put TUD j get TUPD j |
| 752 | end |
| 753 | tuohd |
| 754 | tuks TKDATA |
| 755 | for j ulong 4 |
| 756 | stohw get STHD j |
| 757 | end |
| 758 | tuks TKN |
| 759 | stou get TUN 0 |
| 760 | tuks TKK |
| 761 | tuks TKTSYT |
| 762 | for j ulong 4 |
| 763 | put TUD j get TUSYT j |
| 764 | end |
| 765 | tuohd |
| 766 | stnl |
| 767 | for m ulong 3 |
| 768 | tumodelline m |
| 769 | end |
| 770 | n = get TUN 0 |
| 771 | tuks TKIDEAL |
| 772 | stou mul n tuub 65521 |
| 773 | tuks TKUBPS |
| 774 | stou tuub 65521 |
| 775 | stnl |
| 776 | all = ulong 1 |
| 777 | for m ulong 3 |
| 778 | for c ulong 2 |
| 779 | h = tucodedline m c |
| 780 | if ne h 1 |
| 781 | all = 0 |
| 782 | end |
| 783 | end |
| 784 | end |
| 785 | tuks TKH1ALL |
| 786 | if eq all 1 |
| 787 | tuks TKPASS |
| 788 | else |
| 789 | if eq get TUCX 0 1000 |
| 790 | tuks TKNRUN |
| 791 | else |
| 792 | tuks TKFAIL |
| 793 | end |
| 794 | end |
| 795 | stnl |
| 796 | tuarmline 3 |
| 797 | tuarmline 4 |
| 798 | tuarmline 7 |
| 799 | tuarmline 6 |
| 800 | tuarmline 5 |
| 801 | tuarmline 2 |
| 802 | tuks TKDELT |
| 803 | stnl |
| 804 | end |
| 805 | |
| 806 | fn tufail code ulong d ulong to int |
| 807 | put STOP 0 0 |
| 808 | tuks TKREFU |
| 809 | stou code |
| 810 | tuks TKDETL |
| 811 | stou d |
| 812 | stnl |
| 813 | if ne get STQT 0 1 |
| 814 | r = stflush 1 |
| 815 | end |
| 816 | ret 2 |
| 817 | end |
| 818 | |
| 819 | note the evaluation on slots 0 split, 1 profile, 2 TRAIN lib, 3 TRAINP lib, 4 base.om, |
| 820 | note 5 coder (- = NOT_RUN), 6 out; report to stdout unless STQT is 1 |
| 821 | fn turun2 to int |
| 822 | streset |
| 823 | e = stidx |
| 824 | if eq e 0 |
| 825 | e = stsess |
| 826 | end |
| 827 | if eq e 0 |
| 828 | e = stexps |
| 829 | end |
| 830 | if ne e 0 |
| 831 | ret tufail 2 ulong e |
| 832 | end |
| 833 | if ne tusyms 0 |
| 834 | ret tufail 7 0 |
| 835 | end |
| 836 | stpexact 1 |
| 837 | n = stload |
| 838 | if lt n 0 |
| 839 | ret tufail 3 0 |
| 840 | end |
| 841 | tusha 1000 1 0 ulong n |
| 842 | for j ulong 4 |
| 843 | put TUPD j get TUD j |
| 844 | end |
| 845 | tubmodel |
| 846 | for l ulong 2 |
| 847 | e = tulib add l 1 |
| 848 | if ne e 0 |
| 849 | ret tufail 4 add mul add l 1 10 ulong e |
| 850 | end |
| 851 | end |
| 852 | stpexact 4 |
| 853 | n = stload |
| 854 | if lt n 0 |
| 855 | ret tufail 5 0 |
| 856 | end |
| 857 | put TUBOM 0 ulong n |
| 858 | for m ulong 3 |
| 859 | tutps m |
| 860 | tutpsname m |
| 861 | if ne tuwfile 0 |
| 862 | ret tufail 15 m |
| 863 | end |
| 864 | end |
| 865 | tutsy |
| 866 | stpbase 6 |
| 867 | tukp TKDTSY |
| 868 | if ne tuwfile 0 |
| 869 | ret tufail 15 3 |
| 870 | end |
| 871 | nocoder = and eq get STBL 5 1 eq get STBD 20480 45 |
| 872 | for x ulong 6 |
| 873 | put TUCX x 1000 |
| 874 | put TUCS x 0 |
| 875 | end |
| 876 | if not nocoder |
| 877 | for m ulong 3 |
| 878 | tucode m 0 |
| 879 | tucode m 1 |
| 880 | end |
| 881 | end |
| 882 | put STOP 0 0 |
| 883 | tureport |
| 884 | if ne get STQT 0 1 |
| 885 | r = stflush 1 |
| 886 | end |
| 887 | stpbase 6 |
| 888 | tukp TKTXT |
| 889 | if ne stwfile 0 |
| 890 | ret 15 |
| 891 | end |
| 892 | ret 0 |
| 893 | end |
| 894 | |
| 895 | fn tumain to int |
| 896 | if lt argcnt 9 |
| 897 | ret tufail 1 0 |
| 898 | end |
| 899 | for k ulong 7 |
| 900 | if eq stargb add k 2 k 0 |
| 901 | ret tufail 1 add k 1 |
| 902 | end |
| 903 | end |
| 904 | ret turun2 |
| 905 | end |