omega-helix
This project has not described itself yet.
Brought by drakestapleton
omega-helix / native / spec.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note omegallm spec.om: Frozen-Core Specialist Training (trainf), Test-Time Fast-Weights |
| 3 | note (ttteval, tttsamp), and Layer-Contrastive Decoding (dolaeval). Pure seeded Omega. |
| 4 | |
| 5 | global odl1 f64 4096 |
| 6 | global odl2 f64 4096 |
| 7 | global ottt_st ulong 8 |
| 8 | global oens ulong 8 |
| 9 | global ocl_st ulong 18 |
| 10 | global ocl_k ulong 4 |
| 11 | global ocl_a0 ulong 4 |
| 12 | global ocl_sl ulong 4 |
| 13 | global ocl_wo ulong 4 |
| 14 | global ocl_wn ulong 4 |
| 15 | global ocl_w f64 4 |
| 16 | global ocl_ent f64 4 |
| 17 | global ocl_al f64 4 |
| 18 | global ocl_ph ulong 4 |
| 19 | global ocl_wm long 4 |
| 20 | note Dynamic editable spclip recipe, splice, SHA-256, eval, tune & lineage state |
| 21 | const OSP_SP_AUTO ulong 65535 |
| 22 | global ocl_cfg ulong 16 |
| 23 | global ocl_link ulong 32 |
| 24 | global ocl_sp_s ulong 4 |
| 25 | global ocl_sp_e ulong 4 |
| 26 | global ocl_sp_g ulong 4 |
| 27 | global ocl_raw_sl ulong 4 |
| 28 | global ocl_bsha uchar 32 |
| 29 | global ocl_lsha uchar 1024 |
| 30 | global ocl_lph ulong 32 |
| 31 | global ocl_rsha uchar 32 |
| 32 | global ocl_csha uchar 32 |
| 33 | global ocl_dsha uchar 32 |
| 34 | global ocl_tsha uchar 32 |
| 35 | global ocl_rec uchar 65536 |
| 36 | global ocl_rlen ulong 1 |
| 37 | global ocl_rcur ulong 1 |
| 38 | global ocl_exp ulong 16 |
| 39 | global ocl_tun_ls f64 4 |
| 40 | global ocl_tun_al f64 4 |
| 41 | global osha_k uint 64 |
| 42 | global osha_h uint 8 |
| 43 | global osha_v uint 8 |
| 44 | global osha_w uint 64 |
| 45 | global osha_b uchar 64 |
| 46 | global osha_d uchar 32 |
| 47 | global osha_n ulong 1 |
| 48 | global osha_ready ulong 1 |
| 49 | |
| 50 | text ot_sub_cr "create" |
| 51 | text ot_sub_ed "edit" |
| 52 | text ot_sub_vr "verify" |
| 53 | text ot_sub_in "inspect" |
| 54 | text ot_sub_rn "run" |
| 55 | text ot_sub_ev "eval" |
| 56 | text ot_sub_tn "tune" |
| 57 | text ot_sub_vl "verify-lineage" |
| 58 | text ot_fl_str "--strand" |
| 59 | text ot_fl_wts "--weights" |
| 60 | text ot_fl_sw "--set-weight" |
| 61 | text ot_fl_mod "--mode" |
| 62 | text ot_fl_tau "--tau" |
| 63 | text ot_fl_spl "--splice" |
| 64 | text ot_fl_ss "--set-splice" |
| 65 | text ot_fl_out "--out" |
| 66 | text ot_fl_bat "--batch" |
| 67 | text ot_fl_add "--add-layers" |
| 68 | text ot_fl_trl "--trunk-link" |
| 69 | text ot_fl_lin "--lineage" |
| 70 | text ot_fl_nln "--no-lineage" |
| 71 | text ot_kw_all "all" |
| 72 | text ot_rec_mag "OLLMSPCLIP01\n" |
| 73 | text ot_lin_mag "OLLMSPLIN01\n" |
| 74 | text ot_k_base "base " |
| 75 | text ot_k_bsha "base_sha256 " |
| 76 | text ot_k_bl "base_L " |
| 77 | text ot_k_bh "base_hash " |
| 78 | text ot_k_mode "mode " |
| 79 | text ot_k_tau "tau " |
| 80 | text ot_k_strs "strands " |
| 81 | text ot_k_str "strand " |
| 82 | text ot_k_wt "weight " |
| 83 | text ot_k_alm "alpha_micro " |
| 84 | text ot_k_spl "splice " |
| 85 | text ot_k_lnks "links " |
| 86 | text ot_k_lnk "link " |
| 87 | text ot_k_rsha "recipe_sha256 " |
| 88 | text ot_k_chld "child " |
| 89 | text ot_k_csha "child_sha256 " |
| 90 | text ot_k_cbl "child_base_L " |
| 91 | text ot_k_csl "child_spec_L " |
| 92 | text ot_k_cbh "child_base_hash " |
| 93 | text ot_k_cph "child_pack_hash " |
| 94 | text ot_k_cns "child_nspec " |
| 95 | text ot_k_tl "trunk_L " |
| 96 | text ot_k_prsh "parent_recipe_sha256 " |
| 97 | text ot_k_dsha "data_sha256 " |
| 98 | text ot_k_stp "steps " |
| 99 | text ot_k_lrm "lr_micro " |
| 100 | text ot_k_bat "batch " |
| 101 | text ot_k_ls0 "loss_start_micro " |
| 102 | text ot_k_ls1 "loss_end_micro " |
| 103 | text ot_k_lsha "lineage_sha256 " |
| 104 | |
| 105 | note ---- 1. Frozen-Core Residual Specialist Training ---- |
| 106 | note trainf CK TOKS UNTIL EVERY FREEZE_LAYERS [BATCH] |
| 107 | note Freezes embeddings + layers 0..FREEZE_LAYERS-1 bit-identically while training newer layers. |
| 108 | fn cmdtrainf to void |
| 109 | na = oargc |
| 110 | if and ne na 7 ne na 8 |
| 111 | exit 2 |
| 112 | end |
| 113 | ockload 2 |
| 114 | odopen 3 |
| 115 | until = oargu 4 |
| 116 | every = oargu 5 |
| 117 | flay = oargu 6 |
| 118 | if or eq every 0 gt flay get og 5 |
| 119 | exit 2 |
| 120 | end |
| 121 | if lt get odn 0 add get og 1 1 |
| 122 | exit 23 |
| 123 | end |
| 124 | put ottt_st 0 get og 6 |
| 125 | put ottt_st 1 get og 44 |
| 126 | if eq na 8 |
| 127 | nb = oargu 7 |
| 128 | if or eq nb 0 gt nb 64 |
| 129 | exit 2 |
| 130 | end |
| 131 | put og 6 nb |
| 132 | put og 44 1 |
| 133 | end |
| 134 | fz = add get og 31 mul flay get og 32 |
| 135 | put ofreeze 0 fz |
| 136 | put ofzlay 0 flay |
| 137 | put og 45 1 |
| 138 | st = get og 41 |
| 139 | while lt st until bound 999999 |
| 140 | ls = ostep |
| 141 | st = get og 41 |
| 142 | if or eq rem st every 0 eq st until |
| 143 | put og 6 get ottt_st 0 |
| 144 | put og 44 get ottt_st 1 |
| 145 | ocksave 2 |
| 146 | if eq na 8 |
| 147 | put og 6 oargu 7 |
| 148 | put og 44 1 |
| 149 | end |
| 150 | oputc 70 |
| 151 | oputc 32 |
| 152 | oputu st |
| 153 | oputc 32 |
| 154 | oputu flay |
| 155 | oputc 32 |
| 156 | oputl rmic ls |
| 157 | oputc 10 |
| 158 | oflush |
| 159 | end |
| 160 | end |
| 161 | put og 6 get ottt_st 0 |
| 162 | put og 44 get ottt_st 1 |
| 163 | put ofreeze 0 0 |
| 164 | put ofzlay 0 0 |
| 165 | end |
| 166 | |
| 167 | note ---- 2. Test-Time Fast-Weights (TTT-Omega) ---- |
| 168 | note Loops over parameters carry the largest bound the language takes: their pass count is P or a |
| 169 | note pack size, which ogeom and cmdspmerge have already held to the cold store, not a constant here. |
| 170 | note Snapshot ow[fz..P) into cold store ocs[P + i] |
| 171 | fn ottt_snap fz ulong to void |
| 172 | c = ocsinit |
| 173 | p = get og 8 |
| 174 | i = fz |
| 175 | while lt i p bound 9223372036854775807 |
| 176 | ocsp add p i owg i |
| 177 | i = add i 1 |
| 178 | end |
| 179 | end |
| 180 | |
| 181 | note Restore ow[fz..P) from cold store ocs[P + i] |
| 182 | fn ottt_rest fz ulong to void |
| 183 | p = get og 8 |
| 184 | i = fz |
| 185 | while lt i p bound 9223372036854775807 |
| 186 | owp i ocsg add p i |
| 187 | i = add i 1 |
| 188 | end |
| 189 | end |
| 190 | |
| 191 | note Zero cold-store gradients ocs[0..P) |
| 192 | fn ottt_zg to void |
| 193 | p = get og 8 |
| 194 | i = ulong 0 |
| 195 | while lt i p bound 9223372036854775807 |
| 196 | ocsp i 0.0f64 |
| 197 | i = add i 1 |
| 198 | end |
| 199 | end |
| 200 | |
| 201 | note One clipped SGD fast-weight step on ow[fz..P) using ocs[0..P) |
| 202 | fn ottt_sgd fz ulong lr f64 to void |
| 203 | p = get og 8 |
| 204 | ss = 0.0f64 |
| 205 | i = fz |
| 206 | while lt i p bound 9223372036854775807 |
| 207 | g = ocsg i |
| 208 | ss = add ss mul g g |
| 209 | i = add i 1 |
| 210 | end |
| 211 | nr = fsqrt ss |
| 212 | sc = lr |
| 213 | if gt nr 1.0 |
| 214 | sc = div lr nr |
| 215 | end |
| 216 | i = fz |
| 217 | while lt i p bound 9223372036854775807 |
| 218 | w = owg i |
| 219 | owp i sub w mul sc ocsg i |
| 220 | i = add i 1 |
| 221 | end |
| 222 | end |
| 223 | |
| 224 | note Evaluate suffix loss on sequence 0 over positions [pref..tt) after ofwd 0 |
| 225 | fn ottt_suf pref ulong tt ulong to f64 |
| 226 | ls = 0.0f64 |
| 227 | t = pref |
| 228 | while lt t tt bound 1024 |
| 229 | ls = add ls oheadr 0 t |
| 230 | t = add t 1 |
| 231 | end |
| 232 | ret div ls f64 sub tt pref |
| 233 | end |
| 234 | |
| 235 | note Run `steps` strictly-causal online gradient steps on prefix [0..pref) |
| 236 | fn ottt_adapt pref ulong steps ulong lr f64 fz ulong to void |
| 237 | put og 9 pref |
| 238 | put og 10 0 |
| 239 | sc = div 1.0f64 f64 pref |
| 240 | s = ulong 0 |
| 241 | while lt s steps bound 9223372036854775807 |
| 242 | ottt_zg |
| 243 | l0 = ofwd 0 |
| 244 | obwd 0 sc |
| 245 | ottt_sgd fz lr |
| 246 | s = add s 1 |
| 247 | end |
| 248 | end |
| 249 | |
| 250 | note ttteval CK HELD W PREFIX STEPS LRMICRO LAYER_FROM |
| 251 | fn cmdttteval to void |
| 252 | if ne oargc 9 |
| 253 | exit 2 |
| 254 | end |
| 255 | ockload 2 |
| 256 | odopen 3 |
| 257 | ww = oargu 4 |
| 258 | pref = oargu 5 |
| 259 | steps = oargu 6 |
| 260 | lrm = oargu 7 |
| 261 | lfrom = oargu 8 |
| 262 | tt = get og 1 |
| 263 | if or eq ww 0 or eq pref 0 ge pref tt |
| 264 | exit 2 |
| 265 | end |
| 266 | if gt lfrom get og 5 |
| 267 | exit 2 |
| 268 | end |
| 269 | if gt ww div sub get odn 0 1 tt |
| 270 | exit 23 |
| 271 | end |
| 272 | fz = add get og 31 mul lfrom get og 32 |
| 273 | lr = div f64 lrm 1000000.0 |
| 274 | b_sum = 0.0f64 |
| 275 | t_sum = 0.0f64 |
| 276 | for w ulong ww |
| 277 | obrow 0 mul w tt |
| 278 | put og 9 tt |
| 279 | l0 = ofwd 0 |
| 280 | b_sum = add b_sum ottt_suf pref tt |
| 281 | ottt_snap fz |
| 282 | ottt_adapt pref steps lr fz |
| 283 | put og 9 tt |
| 284 | l1 = ofwd 0 |
| 285 | t_sum = add t_sum ottt_suf pref tt |
| 286 | ottt_rest fz |
| 287 | end |
| 288 | put og 9 tt |
| 289 | b_lo = div b_sum f64 ww |
| 290 | t_lo = div t_sum f64 ww |
| 291 | oputc 84 |
| 292 | oputc 84 |
| 293 | oputc 84 |
| 294 | oputc 32 |
| 295 | oputu ww |
| 296 | oputc 32 |
| 297 | oputu pref |
| 298 | oputc 32 |
| 299 | oputu steps |
| 300 | oputc 32 |
| 301 | oputu lrm |
| 302 | oputc 32 |
| 303 | oputu lfrom |
| 304 | oputc 32 |
| 305 | oputl rmic b_lo |
| 306 | oputc 32 |
| 307 | oputl rmic t_lo |
| 308 | oputc 32 |
| 309 | oputl rmic sub t_lo b_lo |
| 310 | oputc 10 |
| 311 | oflush |
| 312 | end |
| 313 | |
| 314 | fn ottt_prompt v ulong to void |
| 315 | put og 9 0 |
| 316 | ocpush 0 |
| 317 | if gt v 256 |
| 318 | np = obprompt 6 |
| 319 | for i ulong np |
| 320 | ocpush get obtk i |
| 321 | end |
| 322 | else |
| 323 | pl = oargr 6 |
| 324 | if lt pl 0 |
| 325 | exit 2 |
| 326 | end |
| 327 | for i ulong ulong pl |
| 328 | ocpush ulong get oarg i |
| 329 | end |
| 330 | end |
| 331 | end |
| 332 | |
| 333 | note tttsamp CK SEED N TEMPMILLI PROMPT MERGES STEPS LRMICRO LAYER_FROM |
| 334 | fn cmdtttsamp to void |
| 335 | if ne oargc 11 |
| 336 | exit 2 |
| 337 | end |
| 338 | ockload 2 |
| 339 | v = get og 0 |
| 340 | if gt v 256 |
| 341 | obload 7 v |
| 342 | end |
| 343 | ottt_prompt v |
| 344 | nc = get og 9 |
| 345 | fz = add get og 31 mul oargu 10 get og 32 |
| 346 | lr = div f64 oargu 9 1000000.0 |
| 347 | steps = oargu 8 |
| 348 | ottt_snap fz |
| 349 | if and gt steps 0 gt nc 1 |
| 350 | pref = sub nc 1 |
| 351 | for j ulong pref |
| 352 | put oby j get obx add j 1 |
| 353 | end |
| 354 | ottt_adapt pref steps lr fz |
| 355 | end |
| 356 | osampleloaded oargu 3 oargu 4 oargu 5 |
| 357 | ottt_rest fz |
| 358 | end |
| 359 | |
| 360 | note ---- 3. Layer-Contrastive Decoding (DoLa in pure Omega) ---- |
| 361 | note Compute log_softmax of oa[pr..pr+v) into odl1 (which=1) or odl2 (which=2) |
| 362 | note Note: osoft overwrites oa[pr..pr+v) with exp(x - m), so save raw logits first. |
| 363 | fn odl_lsm pr ulong v ulong which ulong to void |
| 364 | m = bitcast f64 ulong 18442240474082181120 |
| 365 | for j ulong v |
| 366 | x = get oa add pr j |
| 367 | m = fmax m x |
| 368 | if eq which 1 |
| 369 | put odl1 j x |
| 370 | else |
| 371 | put odl2 j x |
| 372 | end |
| 373 | end |
| 374 | sm = osoft pr v m |
| 375 | lsm = flog sm |
| 376 | for j ulong v |
| 377 | if eq which 1 |
| 378 | put odl1 j sub sub get odl1 j m lsm |
| 379 | else |
| 380 | put odl2 j sub sub get odl2 j m lsm |
| 381 | end |
| 382 | end |
| 383 | end |
| 384 | |
| 385 | fn odl_mix pr ulong v ulong beta f64 to void |
| 386 | for j ulong v |
| 387 | put oa add pr j sub get odl1 j mul beta get odl2 j |
| 388 | end |
| 389 | end |
| 390 | |
| 391 | fn odl_proj h ulong t ulong z ulong pr ulong which ulong to void |
| 392 | frms h get og 33 z add get og 16 t |
| 393 | klogit z pr get og 0 get og 2 |
| 394 | odl_lsm pr get og 0 which |
| 395 | end |
| 396 | |
| 397 | note Evaluate one row t with both baseline and DoLa (early layer el, contrast beta) |
| 398 | fn odl_row t ulong el ulong beta f64 to void |
| 399 | r = mul t get og 2 |
| 400 | z = add get og 17 r |
| 401 | pr = add get og 18 mul t get og 0 |
| 402 | odl_proj add get og 15 r t z pr 1 |
| 403 | odl_proj add oahin el r t z pr 2 |
| 404 | odl_mix pr get og 0 beta |
| 405 | y = get oby t |
| 406 | put odl1 0 sub 0.0f64 get odl1 y |
| 407 | put odl2 0 olossrow pr get og 0 y |
| 408 | end |
| 409 | |
| 410 | fn odl_print ww ulong el ulong bm ulong b_lo f64 d_lo f64 to void |
| 411 | oputc 68 |
| 412 | oputc 79 |
| 413 | oputc 76 |
| 414 | oputc 65 |
| 415 | oputc 32 |
| 416 | oputu ww |
| 417 | oputc 32 |
| 418 | oputu el |
| 419 | oputc 32 |
| 420 | oputu bm |
| 421 | oputc 32 |
| 422 | oputl rmic b_lo |
| 423 | oputc 32 |
| 424 | oputl rmic d_lo |
| 425 | oputc 32 |
| 426 | oputl rmic sub d_lo b_lo |
| 427 | oputc 10 |
| 428 | oflush |
| 429 | end |
| 430 | |
| 431 | note dolaeval CK HELD W EARLY_LAYER BETA_MILLI |
| 432 | fn cmddolaeval to void |
| 433 | if ne oargc 7 |
| 434 | exit 2 |
| 435 | end |
| 436 | ockload 2 |
| 437 | odopen 3 |
| 438 | ww = oargu 4 |
| 439 | el = oargu 5 |
| 440 | bm = oargu 6 |
| 441 | tt = get og 1 |
| 442 | if or eq ww 0 or eq el 0 ge el get og 5 |
| 443 | exit 2 |
| 444 | end |
| 445 | if gt ww div sub get odn 0 1 tt |
| 446 | exit 23 |
| 447 | end |
| 448 | beta = div f64 bm 1000.0 |
| 449 | b_sum = 0.0f64 |
| 450 | d_sum = 0.0f64 |
| 451 | for w ulong ww |
| 452 | obrow 0 mul w tt |
| 453 | put og 9 tt |
| 454 | l0 = ofwd 0 |
| 455 | for t ulong tt |
| 456 | odl_row t el beta |
| 457 | b_sum = add b_sum get odl1 0 |
| 458 | d_sum = add d_sum get odl2 0 |
| 459 | end |
| 460 | end |
| 461 | tot = f64 mul ww tt |
| 462 | odl_print ww el bm div b_sum tot div d_sum tot |
| 463 | end |
| 464 | |
| 465 | |
| 466 | note ---- 4. Swappable Specialist Layer Packs (OLLMSP01) ---- |
| 467 | const OSPMAG ulong 3544421225449933903 |
| 468 | |
| 469 | note FNV-1a 64 over shapes (V,T,D,H,F,base_L) + frozen base weights ow[0..fz) |
| 470 | fn osp_fnvu h ulong v ulong to ulong |
| 471 | x = h |
| 472 | for k ulong 8 |
| 473 | b = and shr v mul k 8 255 |
| 474 | x = mul xor x b 1099511628211 |
| 475 | end |
| 476 | ret x |
| 477 | end |
| 478 | |
| 479 | fn osp_app l ulong to ulong |
| 480 | if gt get og 59 1 |
| 481 | ret add l mul get og 58 sub get og 59 1 |
| 482 | end |
| 483 | ret l |
| 484 | end |
| 485 | |
| 486 | fn osp_basehash bl ulong fz ulong to ulong |
| 487 | h = ulong 14695981039346656037 |
| 488 | h = osp_fnvu h get og 0 |
| 489 | h = osp_fnvu h get og 1 |
| 490 | h = osp_fnvu h get og 2 |
| 491 | h = osp_fnvu h get og 3 |
| 492 | h = osp_fnvu h get og 4 |
| 493 | h = osp_fnvu h bl |
| 494 | if gt get og 59 1 |
| 495 | h = osp_fnvu h get og 57 |
| 496 | h = osp_fnvu h get og 58 |
| 497 | h = osp_fnvu h get og 59 |
| 498 | end |
| 499 | i = ulong 0 |
| 500 | while lt i fz bound 9223372036854775807 |
| 501 | h = osp_fnvu h bitcast ulong owg i |
| 502 | i = add i 1 |
| 503 | end |
| 504 | ret h |
| 505 | end |
| 506 | |
| 507 | note Stream ow[fz..fz+nspec) to open pack file starting at offset 48; returns payload FNV-1a 64 |
| 508 | fn osp_wrpay fz ulong nspec ulong to ulong |
| 509 | h = ulong 14695981039346656037 |
| 510 | pos = ulong 48 |
| 511 | done = ulong 0 |
| 512 | while lt done nspec bound 65536 |
| 513 | cnt = sub nspec done |
| 514 | if gt cnt OCKC |
| 515 | cnt = OCKC |
| 516 | end |
| 517 | for j ulong cnt |
| 518 | ocput8 mul j 8 bitcast ulong owg add fz add done j |
| 519 | end |
| 520 | nb = mul cnt 8 |
| 521 | h = ocfnvk h nb |
| 522 | ocwput pos nb |
| 523 | pos = add pos nb |
| 524 | done = add done cnt |
| 525 | end |
| 526 | ret h |
| 527 | end |
| 528 | |
| 529 | note Stream nspec f64s from arg ai at offset 48 into ow[fz..fz+nspec); returns payload FNV-1a 64 |
| 530 | fn osp_rdpay ai ulong fz ulong nspec ulong to ulong |
| 531 | h = ulong 14695981039346656037 |
| 532 | pos = ulong 48 |
| 533 | done = ulong 0 |
| 534 | while lt done nspec bound 65536 |
| 535 | cnt = sub nspec done |
| 536 | if gt cnt OCKC |
| 537 | cnt = OCKC |
| 538 | end |
| 539 | nb = mul cnt 8 |
| 540 | if ne oprd ai pos 0 nb nb |
| 541 | exit 60 |
| 542 | end |
| 543 | h = ocfnvw h nb |
| 544 | for j ulong cnt |
| 545 | owp add fz add done j bitcast f64 opw8 mul j 8 |
| 546 | end |
| 547 | pos = add pos nb |
| 548 | done = add done cnt |
| 549 | end |
| 550 | ret h |
| 551 | end |
| 552 | |
| 553 | note spext BASE.ck SPEC.ck PACK.sp: verify frozen base bit-identical, write OLLMSP01 specialist pack |
| 554 | fn cmdspext to void |
| 555 | if ne oargc 5 |
| 556 | exit 2 |
| 557 | end |
| 558 | ockloop 2 |
| 559 | bl = get og 5 |
| 560 | fz = get og 33 |
| 561 | bh = osp_basehash bl fz |
| 562 | put ottt_st 0 get og 0 |
| 563 | put ottt_st 1 get og 1 |
| 564 | put ottt_st 2 get og 2 |
| 565 | put ottt_st 3 get og 3 |
| 566 | put ottt_st 4 get og 4 |
| 567 | put ottt_st 5 bl |
| 568 | put ottt_st 6 fz |
| 569 | put ottt_st 7 bh |
| 570 | ockloop 3 |
| 571 | for k ulong 5 |
| 572 | if ne get og k get ottt_st k |
| 573 | exit 62 |
| 574 | end |
| 575 | end |
| 576 | if le get og 5 get ottt_st 5 |
| 577 | exit 62 |
| 578 | end |
| 579 | if ne osp_basehash get ottt_st 5 get ottt_st 6 get ottt_st 7 |
| 580 | exit 62 |
| 581 | end |
| 582 | nspec = sub get og 8 get ottt_st 6 |
| 583 | ocwopen 4 |
| 584 | ph = osp_wrpay get ottt_st 6 nspec |
| 585 | ocput8 0 OSPMAG |
| 586 | ocput8 8 get ottt_st 5 |
| 587 | ocput8 16 get og 5 |
| 588 | ocput8 24 get ottt_st 7 |
| 589 | ocput8 32 nspec |
| 590 | ocput8 40 ph |
| 591 | ocwput 0 48 |
| 592 | ocwend 4 |
| 593 | oputc 83 |
| 594 | oputc 80 |
| 595 | oputc 69 |
| 596 | oputc 88 |
| 597 | oputc 84 |
| 598 | oputc 32 |
| 599 | oputu get ottt_st 5 |
| 600 | oputc 32 |
| 601 | oputu get og 5 |
| 602 | oputc 32 |
| 603 | oputu nspec |
| 604 | oputc 10 |
| 605 | oflush |
| 606 | end |
| 607 | |
| 608 | fn osp_rdhdr ai ulong bl ulong bh ulong to void |
| 609 | sz = ofsz ai |
| 610 | if lt sz 48 |
| 611 | exit 60 |
| 612 | end |
| 613 | if ne oprd ai 0 0 48 48 |
| 614 | exit 60 |
| 615 | end |
| 616 | if ne opw8 0 OSPMAG |
| 617 | exit 60 |
| 618 | end |
| 619 | if ne opw8 8 bl |
| 620 | exit 62 |
| 621 | end |
| 622 | if le opw8 16 bl |
| 623 | exit 62 |
| 624 | end |
| 625 | if ne opw8 24 bh |
| 626 | exit 62 |
| 627 | end |
| 628 | nspec = opw8 32 |
| 629 | if ne sz add 48 mul nspec 8 |
| 630 | exit 60 |
| 631 | end |
| 632 | put ottt_st 1 opw8 16 |
| 633 | put ottt_st 3 nspec |
| 634 | put ottt_st 4 opw8 40 |
| 635 | end |
| 636 | |
| 637 | note Shared helper: verify base & pack hashes, attach specialist layers onto base in memory |
| 638 | fn osp_attach bkai ulong pkai ulong to void |
| 639 | ockloop bkai |
| 640 | put ottt_st 0 get og 5 |
| 641 | put ottt_st 2 get og 33 |
| 642 | osp_rdhdr pkai get ottt_st 0 osp_basehash get ottt_st 0 get ottt_st 2 |
| 643 | ogrowsnap get og 8 |
| 644 | put og 5 get ottt_st 1 |
| 645 | if not ogeom |
| 646 | exit 12 |
| 647 | end |
| 648 | if ne sub get og 8 get ottt_st 2 get ottt_st 3 |
| 649 | exit 62 |
| 650 | end |
| 651 | ozerom mul 2 get og 8 |
| 652 | ogrowcopy get ottt_st 2 |
| 653 | if ne osp_rdpay pkai get ottt_st 2 get ottt_st 3 get ottt_st 4 |
| 654 | exit 61 |
| 655 | end |
| 656 | end |
| 657 | |
| 658 | note spapp BASE.ck PACK.sp OUT.ck: verify base & pack hashes, attach specialist layers onto base |
| 659 | fn cmdspapp to void |
| 660 | if ne oargc 5 |
| 661 | exit 2 |
| 662 | end |
| 663 | osp_attach 2 3 |
| 664 | ocksave 4 |
| 665 | oputc 83 |
| 666 | oputc 80 |
| 667 | oputc 65 |
| 668 | oputc 80 |
| 669 | oputc 80 |
| 670 | oputc 32 |
| 671 | oputu get ottt_st 0 |
| 672 | oputc 32 |
| 673 | oputu get ottt_st 1 |
| 674 | oputc 32 |
| 675 | oputu get ottt_st 3 |
| 676 | oputc 10 |
| 677 | oflush |
| 678 | end |
| 679 | |
| 680 | note spsamp BASE.ck PACK.sp N TEMPMILLI PROMPT SEED [MERGES] |
| 681 | note Attach specialist pack in memory (no 403 MB temp checkpoint) and sample from PROMPT (argv[6]) |
| 682 | fn cmdspsamp to void |
| 683 | na = oargc |
| 684 | if and ne na 8 ne na 9 |
| 685 | exit 2 |
| 686 | end |
| 687 | osp_attach 2 3 |
| 688 | nn = oargu 4 |
| 689 | if gt nn 999999 |
| 690 | exit 2 |
| 691 | end |
| 692 | tm = oargu 5 |
| 693 | st = oargu 7 |
| 694 | v = get og 0 |
| 695 | if gt v 256 |
| 696 | if eq na 8 |
| 697 | exit 2 |
| 698 | end |
| 699 | obload 8 v |
| 700 | end |
| 701 | ochipup |
| 702 | osampleloaded st nn tm |
| 703 | end |
| 704 | |
| 705 | note speval BASE.ck PACK.sp HELD W [MERGES] |
| 706 | note Attach specialist pack in memory and evaluate W windows on HELD |
| 707 | fn cmdspeval to void |
| 708 | na = oargc |
| 709 | if and ne na 6 ne na 7 |
| 710 | exit 2 |
| 711 | end |
| 712 | osp_attach 2 3 |
| 713 | ww = oargu 5 |
| 714 | v = get og 0 |
| 715 | if gt v 256 |
| 716 | if eq na 6 |
| 717 | exit 2 |
| 718 | end |
| 719 | obload 6 v |
| 720 | end |
| 721 | odopen 4 |
| 722 | tt = get og 1 |
| 723 | m = get odn 0 |
| 724 | if eq ww 0 |
| 725 | exit 23 |
| 726 | end |
| 727 | if gt ww div sub m 1 tt |
| 728 | exit 23 |
| 729 | end |
| 730 | ls = 0.0f64 |
| 731 | nb = ulong 0 |
| 732 | for w ulong ww |
| 733 | obrow 0 mul w tt |
| 734 | ls = add ls ofwd 0 |
| 735 | if gt v 256 |
| 736 | nb = add nb oevnb tt |
| 737 | end |
| 738 | end |
| 739 | lo = div ls f64 ww |
| 740 | bp = div lo 0.6931471805599453 |
| 741 | if gt v 256 |
| 742 | bp = div mul bp f64 mul ww tt f64 nb |
| 743 | end |
| 744 | oputc 69 |
| 745 | oputc 32 |
| 746 | oputu get og 41 |
| 747 | oputc 32 |
| 748 | oputu ww |
| 749 | oputc 32 |
| 750 | oputl rmic lo |
| 751 | oputc 32 |
| 752 | oputl rmic bp |
| 753 | oputc 10 |
| 754 | oflush |
| 755 | end |
| 756 | |
| 757 | note ---- 5. Frozen-Base Hidden-State Cache (OLLMFH01: fcache, trainfc) ---- |
| 758 | const OFHMAG ulong 3544412373522336847 |
| 759 | |
| 760 | note Write oa[src .. src + n) as little-endian f64s starting at file offset pos; returns new pos |
| 761 | fn ofh_wroa pos ulong src ulong n ulong to ulong |
| 762 | done = ulong 0 |
| 763 | while lt done n bound 65536 |
| 764 | cnt = sub n done |
| 765 | if gt cnt OCKC |
| 766 | cnt = OCKC |
| 767 | end |
| 768 | for j ulong cnt |
| 769 | ocput8 mul j 8 bitcast ulong get oa add src add done j |
| 770 | end |
| 771 | nb = mul cnt 8 |
| 772 | ocwput pos nb |
| 773 | pos = add pos nb |
| 774 | done = add done cnt |
| 775 | end |
| 776 | ret pos |
| 777 | end |
| 778 | |
| 779 | note Run frozen base on window starting at token offset o, apply optional mask mkai, write to cache |
| 780 | fn ofh_win mkai ulong o ulong pos ulong to ulong |
| 781 | tt = get og 1 |
| 782 | bl = get og 5 |
| 783 | obrow 0 o |
| 784 | if ne mkai 0 |
| 785 | if ne oprd mkai add o 1 0 tt tt |
| 786 | exit 70 |
| 787 | end |
| 788 | for tm ulong tt |
| 789 | if eq get opw tm 0 |
| 790 | put oby tm or get oby tm 65536 |
| 791 | end |
| 792 | end |
| 793 | end |
| 794 | put okv 0 0 |
| 795 | put ogkm 1 0 |
| 796 | oemb 0 |
| 797 | for l ulong get og 56 |
| 798 | olayf l |
| 799 | end |
| 800 | for t ulong tt |
| 801 | ocput8 mul t 8 get oby t |
| 802 | end |
| 803 | ocwput pos mul tt 8 |
| 804 | pos = add pos mul tt 8 |
| 805 | ret ofh_wroa pos get og 15 mul tt get og 2 |
| 806 | end |
| 807 | |
| 808 | note fcache / fcachem shared driver |
| 809 | fn ofh_run bkai ulong tkai ulong mkai ulong ww ulong outai ulong to void |
| 810 | ockloop bkai |
| 811 | odopen tkai |
| 812 | tt = get og 1 |
| 813 | bl = get og 5 |
| 814 | if or eq ww 0 gt ww div sub get odn 0 1 tt |
| 815 | exit 23 |
| 816 | end |
| 817 | if gt add tt mul tt get og 2 262144 |
| 818 | exit 12 |
| 819 | end |
| 820 | if ne mkai 0 |
| 821 | if ne ofsz mkai get odn 0 |
| 822 | exit 21 |
| 823 | end |
| 824 | end |
| 825 | bh = osp_basehash bl get og 33 |
| 826 | ocwopen outai |
| 827 | ocput8 0 OFHMAG |
| 828 | ocput8 8 ww |
| 829 | ocput8 16 tt |
| 830 | ocput8 24 get og 2 |
| 831 | ocput8 32 bl |
| 832 | ocput8 40 bh |
| 833 | ocwput 0 48 |
| 834 | pos = ulong 48 |
| 835 | put og 9 tt |
| 836 | for w ulong ww |
| 837 | pos = ofh_win mkai mul w tt pos |
| 838 | end |
| 839 | ocwend outai |
| 840 | oputc 70 |
| 841 | oputc 67 |
| 842 | oputc 65 |
| 843 | oputc 67 |
| 844 | oputc 72 |
| 845 | oputc 69 |
| 846 | oputc 32 |
| 847 | oputu ww |
| 848 | oputc 32 |
| 849 | oputu tt |
| 850 | oputc 32 |
| 851 | oputu get og 2 |
| 852 | oputc 32 |
| 853 | oputu bl |
| 854 | oputc 10 |
| 855 | oflush |
| 856 | end |
| 857 | |
| 858 | fn cmdfcache to void |
| 859 | if ne oargc 6 |
| 860 | exit 2 |
| 861 | end |
| 862 | ofh_run 2 3 0 oargu 4 5 |
| 863 | end |
| 864 | |
| 865 | note fcachem BASE.ck TOKS MASK W OUT.hc (MASK: 1 byte per token; 0 masks loss at target y[t]) |
| 866 | fn cmdfcachem to void |
| 867 | if ne oargc 7 |
| 868 | exit 2 |
| 869 | end |
| 870 | ofh_run 2 3 4 oargu 5 6 |
| 871 | end |
| 872 | |
| 873 | note Read and verify OLLMFH01 header at arg ai; stores W in ottt_st[2], rec_bytes in ottt_st[3] |
| 874 | fn ofh_rdhdr ai ulong flay ulong bh ulong to void |
| 875 | sz = ofsz ai |
| 876 | if lt sz 48 |
| 877 | exit 60 |
| 878 | end |
| 879 | if ne oprd ai 0 0 48 48 |
| 880 | exit 60 |
| 881 | end |
| 882 | if ne opw8 0 OFHMAG |
| 883 | exit 60 |
| 884 | end |
| 885 | ww = opw8 8 |
| 886 | if eq ww 0 |
| 887 | exit 60 |
| 888 | end |
| 889 | tt = get og 1 |
| 890 | dd = get og 2 |
| 891 | if ne opw8 16 tt |
| 892 | exit 62 |
| 893 | end |
| 894 | if ne opw8 24 dd |
| 895 | exit 62 |
| 896 | end |
| 897 | if ne opw8 32 flay |
| 898 | exit 62 |
| 899 | end |
| 900 | if ne opw8 40 bh |
| 901 | exit 62 |
| 902 | end |
| 903 | rec = mul add tt mul tt dd 8 |
| 904 | if gt rec 2097152 |
| 905 | exit 12 |
| 906 | end |
| 907 | if ne sz add 48 mul ww rec |
| 908 | exit 60 |
| 909 | end |
| 910 | put ottt_st 2 ww |
| 911 | put ottt_st 3 rec |
| 912 | end |
| 913 | |
| 914 | note Load cached window w from arg ai into oby[0..T) and oa[oahin(flay)..+T*D) |
| 915 | fn ofh_load ai ulong w ulong flay ulong to void |
| 916 | tt = get og 1 |
| 917 | td = mul tt get og 2 |
| 918 | rec = get ottt_st 3 |
| 919 | pos = add 48 mul w rec |
| 920 | if ne oprd ai pos 0 rec rec |
| 921 | exit 60 |
| 922 | end |
| 923 | for t ulong tt |
| 924 | put oby t opw8 mul t 8 |
| 925 | end |
| 926 | dst = oahin osp_app flay |
| 927 | off = mul tt 8 |
| 928 | for i ulong td |
| 929 | put oa add dst i bitcast f64 opw8 add off mul i 8 |
| 930 | end |
| 931 | end |
| 932 | |
| 933 | note Masked head forward + backward over unmasked positions (oby[t] < 65536). |
| 934 | note When all T positions are unmasked, matches ohead 0 + obwd 0 sc bit-for-bit. |
| 935 | fn ofh_hb flay ulong b ulong bb ulong to void |
| 936 | ct = get og 9 |
| 937 | mc = ulong 0 |
| 938 | ls = 0.0f64 |
| 939 | for t ulong ct |
| 940 | if lt get oby t 65536 |
| 941 | ls = add ls oheadr 0 t |
| 942 | mc = add mc 1 |
| 943 | end |
| 944 | end |
| 945 | if eq mc 0 |
| 946 | put olos b 0.0f64 |
| 947 | ret |
| 948 | end |
| 949 | put olos b div ls f64 mc |
| 950 | sc = div 1.0f64 f64 mul mc bb |
| 951 | ozero get og 19 mul ct get og 2 |
| 952 | for t2 ulong ct |
| 953 | if lt get oby t2 65536 |
| 954 | ohbwd 0 t2 sc |
| 955 | end |
| 956 | end |
| 957 | la = get og 56 |
| 958 | nl = sub get og 5 flay |
| 959 | for i ulong nl |
| 960 | olayb sub sub la 1 i |
| 961 | end |
| 962 | end |
| 963 | |
| 964 | note Forward+backward of one cached window w for batch slot b |
| 965 | fn ofh_one ai ulong w ulong flay ulong b ulong bb ulong to void |
| 966 | ofh_load ai w flay |
| 967 | put okv 0 0 |
| 968 | put ogkm 1 0 |
| 969 | fa = osp_app flay |
| 970 | nl = sub get og 5 flay |
| 971 | for j ulong nl |
| 972 | olayf add fa j |
| 973 | end |
| 974 | ofh_hb flay b bb |
| 975 | end |
| 976 | |
| 977 | note One cached frozen-core step: skips embeddings + layers 0..flay-1 completely |
| 978 | fn ofh_step ai ulong flay ulong to f64 |
| 979 | s = get og 41 |
| 980 | bb = get og 6 |
| 981 | p = get og 8 |
| 982 | put og 9 get og 1 |
| 983 | put og 10 p |
| 984 | ozerog p p |
| 985 | for b ulong bb |
| 986 | idx = add mul s bb b |
| 987 | w = rem smx xor get og 40 mul idx 11400714819323198485 get ottt_st 2 |
| 988 | ofh_one ai w flay b bb |
| 989 | end |
| 990 | put og 10 0 |
| 991 | ogfold true |
| 992 | ls = olsum |
| 993 | oadam |
| 994 | put og 41 add s 1 |
| 995 | ret ls |
| 996 | end |
| 997 | |
| 998 | note trainfc CK CACHE.hc UNTIL EVERY FREEZE_LAYERS [BATCH] |
| 999 | fn cmdtrainfc to void |
| 1000 | na = oargc |
| 1001 | if and ne na 7 ne na 8 |
| 1002 | exit 2 |
| 1003 | end |
| 1004 | ockloop 2 |
| 1005 | until = oargu 4 |
| 1006 | every = oargu 5 |
| 1007 | flay = oargu 6 |
| 1008 | if or eq every 0 ge flay get og 5 |
| 1009 | exit 2 |
| 1010 | end |
| 1011 | if gt get og 59 1 |
| 1012 | if lt flay add get og 57 get og 58 |
| 1013 | exit 2 |
| 1014 | end |
| 1015 | end |
| 1016 | fz = add get og 31 mul flay get og 32 |
| 1017 | ofh_rdhdr 3 flay osp_basehash flay fz |
| 1018 | put ottt_st 0 get og 6 |
| 1019 | put ottt_st 1 get og 44 |
| 1020 | if eq na 8 |
| 1021 | nb = oargu 7 |
| 1022 | if or eq nb 0 gt nb 64 |
| 1023 | exit 2 |
| 1024 | end |
| 1025 | put og 6 nb |
| 1026 | put og 44 1 |
| 1027 | end |
| 1028 | put ofreeze 0 fz |
| 1029 | put ofzlay 0 flay |
| 1030 | put og 45 1 |
| 1031 | st = get og 41 |
| 1032 | while lt st until bound 999999 |
| 1033 | ls = ofh_step 3 flay |
| 1034 | st = get og 41 |
| 1035 | if or eq rem st every 0 eq st until |
| 1036 | put og 6 get ottt_st 0 |
| 1037 | put og 44 get ottt_st 1 |
| 1038 | ocksave 2 |
| 1039 | if eq na 8 |
| 1040 | put og 6 oargu 7 |
| 1041 | put og 44 1 |
| 1042 | end |
| 1043 | oputc 70 |
| 1044 | oputc 67 |
| 1045 | oputc 32 |
| 1046 | oputu st |
| 1047 | oputc 32 |
| 1048 | oputu flay |
| 1049 | oputc 32 |
| 1050 | oputl rmic ls |
| 1051 | oputc 10 |
| 1052 | oflush |
| 1053 | end |
| 1054 | end |
| 1055 | put og 6 get ottt_st 0 |
| 1056 | put og 44 get ottt_st 1 |
| 1057 | put ofreeze 0 0 |
| 1058 | put ofzlay 0 0 |
| 1059 | end |
| 1060 | |
| 1061 | note ---- 6. Pure-Omega Specialist Fusion (spmerge, spstack) ---- |
| 1062 | |
| 1063 | note Stream ns f64s from arg ai at offset 48 into ocs[dst .. dst + ns); returns payload FNV-1a 64 |
| 1064 | fn osp_rd2c ai ulong dst ulong ns ulong to ulong |
| 1065 | h = ulong 14695981039346656037 |
| 1066 | pos = ulong 48 |
| 1067 | done = ulong 0 |
| 1068 | while lt done ns bound 65536 |
| 1069 | cnt = sub ns done |
| 1070 | if gt cnt OCKC |
| 1071 | cnt = OCKC |
| 1072 | end |
| 1073 | nb = mul cnt 8 |
| 1074 | if ne oprd ai pos 0 nb nb |
| 1075 | exit 60 |
| 1076 | end |
| 1077 | h = ocfnvw h nb |
| 1078 | for j ulong cnt |
| 1079 | ocsp add dst add done j bitcast f64 opw8 mul j 8 |
| 1080 | end |
| 1081 | pos = add pos nb |
| 1082 | done = add done cnt |
| 1083 | end |
| 1084 | ret h |
| 1085 | end |
| 1086 | |
| 1087 | note Load and verify pack payload from arg ai into ocs[dst .. dst + nspec); exits 60/61/62 on error |
| 1088 | fn osp_rd2ocs ai ulong dst ulong bl ulong bh ulong wantl ulong to ulong |
| 1089 | osp_rdhdr ai bl bh |
| 1090 | sl = get ottt_st 1 |
| 1091 | if and ne wantl 0 ne sl wantl |
| 1092 | exit 62 |
| 1093 | end |
| 1094 | if ne osp_rd2c ai dst get ottt_st 3 get ottt_st 4 |
| 1095 | exit 61 |
| 1096 | end |
| 1097 | ret sl |
| 1098 | end |
| 1099 | |
| 1100 | note Write OLLMSP01 pack at arg outai from ow[fz .. fz + ns) with header (bl, sl, bh, ns) |
| 1101 | fn osp_wrpack outai ulong bl ulong sl ulong bh ulong fz ulong ns ulong to void |
| 1102 | ocwopen outai |
| 1103 | ph = osp_wrpay fz ns |
| 1104 | ocput8 0 OSPMAG |
| 1105 | ocput8 8 bl |
| 1106 | ocput8 16 sl |
| 1107 | ocput8 24 bh |
| 1108 | ocput8 32 ns |
| 1109 | ocput8 40 ph |
| 1110 | ocwput 0 48 |
| 1111 | ocwend outai |
| 1112 | end |
| 1113 | |
| 1114 | note Compute exact grow initial weights W_0 for L=sl into ocs[0 .. ns) |
| 1115 | fn osp_init0 bl ulong sl ulong fz ulong ns ulong to void |
| 1116 | c = ocsinit |
| 1117 | ogrowsnap get og 8 |
| 1118 | put og 5 sl |
| 1119 | if not ogeom |
| 1120 | exit 12 |
| 1121 | end |
| 1122 | oinit |
| 1123 | ogrowcopy fz |
| 1124 | for j ulong get og 2 |
| 1125 | owp add get og 33 j ocsg add fz j |
| 1126 | end |
| 1127 | ogrowsilent bl |
| 1128 | i = ulong 0 |
| 1129 | while lt i ns bound 9223372036854775807 |
| 1130 | ocsp i owg add fz i |
| 1131 | i = add i 1 |
| 1132 | end |
| 1133 | end |
| 1134 | |
| 1135 | note Mode 0: weighted linear soup |
| 1136 | fn osp_m0 kk ulong fz ulong ns ulong to void |
| 1137 | sw = 0.0f64 |
| 1138 | for k ulong kk |
| 1139 | sw = add sw get odl1 k |
| 1140 | end |
| 1141 | if le sw 0.0 |
| 1142 | exit 2 |
| 1143 | end |
| 1144 | i = ulong 0 |
| 1145 | while lt i ns bound 9223372036854775807 |
| 1146 | acc = 0.0f64 |
| 1147 | for k2 ulong kk |
| 1148 | acc = add acc mul get odl1 k2 ocsg add mul add k2 1 ns i |
| 1149 | end |
| 1150 | owp add fz i div acc sw |
| 1151 | i = add i 1 |
| 1152 | end |
| 1153 | end |
| 1154 | |
| 1155 | note Mode 1: task-arithmetic sum over exact grow init W_0 |
| 1156 | fn osp_m1 kk ulong fz ulong ns ulong to void |
| 1157 | i = ulong 0 |
| 1158 | while lt i ns bound 9223372036854775807 |
| 1159 | w0 = ocsg i |
| 1160 | acc = w0 |
| 1161 | for k ulong kk |
| 1162 | d = sub ocsg add mul add k 1 ns i w0 |
| 1163 | acc = add acc mul get odl1 k d |
| 1164 | end |
| 1165 | owp add fz i acc |
| 1166 | i = add i 1 |
| 1167 | end |
| 1168 | end |
| 1169 | |
| 1170 | note Compute TIES RMS threshold 0.5*rms(W_k - W_0) into odl2[k] |
| 1171 | fn osp_ties_tau kk ulong ns ulong to void |
| 1172 | for k ulong kk |
| 1173 | ss = 0.0f64 |
| 1174 | off = mul add k 1 ns |
| 1175 | i = ulong 0 |
| 1176 | while lt i ns bound 9223372036854775807 |
| 1177 | d = sub ocsg add off i ocsg i |
| 1178 | ss = add ss mul d d |
| 1179 | i = add i 1 |
| 1180 | end |
| 1181 | put odl2 k mul 0.5 fsqrt div ss f64 ns |
| 1182 | end |
| 1183 | end |
| 1184 | |
| 1185 | note Elect TIES sign at i: 0=none, 1=pos, 2=neg |
| 1186 | fn osp_m2_sg kk ulong ns ulong i ulong to ulong |
| 1187 | w0 = ocsg i |
| 1188 | ps = 0.0f64 |
| 1189 | ng = 0.0f64 |
| 1190 | for k ulong kk |
| 1191 | d = sub ocsg add mul add k 1 ns i w0 |
| 1192 | if ge fabs d get odl2 k |
| 1193 | if gt d 0.0 |
| 1194 | ps = add ps mul get odl1 k d |
| 1195 | else |
| 1196 | ng = add ng mul get odl1 k sub 0.0f64 d |
| 1197 | end |
| 1198 | end |
| 1199 | end |
| 1200 | if and eq ps 0.0 eq ng 0.0 |
| 1201 | ret 0 |
| 1202 | end |
| 1203 | if ge ps ng |
| 1204 | ret 1 |
| 1205 | end |
| 1206 | ret 2 |
| 1207 | end |
| 1208 | |
| 1209 | note Mode 2: TIES trimmed sign-consensus merge at parameter index i |
| 1210 | fn osp_m2_i kk ulong ns ulong i ulong to f64 |
| 1211 | sg = osp_m2_sg kk ns i |
| 1212 | w0 = ocsg i |
| 1213 | if eq sg 0 |
| 1214 | ret w0 |
| 1215 | end |
| 1216 | num = 0.0f64 |
| 1217 | den = 0.0f64 |
| 1218 | for k ulong kk |
| 1219 | d = sub ocsg add mul add k 1 ns i w0 |
| 1220 | if ge fabs d get odl2 k |
| 1221 | ag = false |
| 1222 | if and eq sg 1 gt d 0.0 |
| 1223 | ag = true |
| 1224 | end |
| 1225 | if and eq sg 2 lt d 0.0 |
| 1226 | ag = true |
| 1227 | end |
| 1228 | if ag |
| 1229 | wk = get odl1 k |
| 1230 | num = add num mul wk d |
| 1231 | den = add den wk |
| 1232 | end |
| 1233 | end |
| 1234 | end |
| 1235 | if eq den 0.0 |
| 1236 | ret w0 |
| 1237 | end |
| 1238 | ret add w0 div num den |
| 1239 | end |
| 1240 | |
| 1241 | fn osp_m2 kk ulong fz ulong ns ulong to void |
| 1242 | osp_ties_tau kk ns |
| 1243 | i = ulong 0 |
| 1244 | while lt i ns bound 9223372036854775807 |
| 1245 | owp add fz i osp_m2_i kk ns i |
| 1246 | i = add i 1 |
| 1247 | end |
| 1248 | end |
| 1249 | |
| 1250 | fn osp_mgrun mode ulong kk ulong fz ulong ns ulong to void |
| 1251 | if eq mode 0 |
| 1252 | osp_m0 kk fz ns |
| 1253 | ret |
| 1254 | end |
| 1255 | if eq mode 1 |
| 1256 | osp_m1 kk fz ns |
| 1257 | ret |
| 1258 | end |
| 1259 | osp_m2 kk fz ns |
| 1260 | end |
| 1261 | |
| 1262 | note spmerge BASE.ck MODE OUT.sp W1 P1.sp W2 P2.sp [W3 P3.sp [W4 P4.sp]] |
| 1263 | fn cmdspmerge to void |
| 1264 | na = oargc |
| 1265 | if or lt na 9 or gt na 13 ne rem sub na 5 2 0 |
| 1266 | exit 2 |
| 1267 | end |
| 1268 | kk = div sub na 5 2 |
| 1269 | if gt oargu 3 2 |
| 1270 | exit 2 |
| 1271 | end |
| 1272 | ockload 2 |
| 1273 | bl = get og 5 |
| 1274 | fz = get og 33 |
| 1275 | bh = osp_basehash bl fz |
| 1276 | osp_rdhdr 6 bl bh |
| 1277 | sl = get ottt_st 1 |
| 1278 | ns = get ottt_st 3 |
| 1279 | note W_0 and the kk pack blocks fill ocs[0 .. (kk + 1) ns): past the cold store is exit 12, as |
| 1280 | note ogeom refuses a shape whose 3 P pass it |
| 1281 | if gt mul add kk 1 ns ocsinit |
| 1282 | exit 12 |
| 1283 | end |
| 1284 | osp_init0 bl sl fz ns |
| 1285 | for k ulong kk |
| 1286 | put odl1 k div f64 oargu add 5 mul k 2 1000.0 |
| 1287 | z = osp_rd2ocs add 6 mul k 2 mul add k 1 ns bl bh sl |
| 1288 | end |
| 1289 | osp_mgrun oargu 3 kk fz ns |
| 1290 | osp_wrpack 4 bl sl bh fz ns |
| 1291 | oputc 83 |
| 1292 | oputc 80 |
| 1293 | oputc 77 |
| 1294 | oputc 82 |
| 1295 | oputc 71 |
| 1296 | oputc 32 |
| 1297 | oputu oargu 3 |
| 1298 | oputc 32 |
| 1299 | oputu kk |
| 1300 | oputc 32 |
| 1301 | oputu sl |
| 1302 | oputc 32 |
| 1303 | oputu ns |
| 1304 | oputc 10 |
| 1305 | oflush |
| 1306 | end |
| 1307 | |
| 1308 | note Copy n f64s from ocs[src..) into ow[dst..) |
| 1309 | fn osp_c2w dst ulong src ulong n ulong to void |
| 1310 | i = ulong 0 |
| 1311 | while lt i n bound 9223372036854775807 |
| 1312 | owp add dst i ocsg add src i |
| 1313 | i = add i 1 |
| 1314 | end |
| 1315 | end |
| 1316 | |
| 1317 | note Scale Wo and W2 of layers [l0 .. l0+cnt) in ow by sc |
| 1318 | fn osp_sclays l0 ulong cnt ulong sc f64 to void |
| 1319 | d = get og 2 |
| 1320 | for k ulong cnt |
| 1321 | l = add l0 k |
| 1322 | oiscale opwo l mul d d sc |
| 1323 | oiscale opw2 l mul d get og 4 sc |
| 1324 | end |
| 1325 | end |
| 1326 | |
| 1327 | fn osp_stkgf dst ulong o1 ulong o2 ulong to void |
| 1328 | for g ulong get og 2 |
| 1329 | v = mul 0.5 add ocsg add o1 g ocsg add o2 g |
| 1330 | owp add dst g v |
| 1331 | end |
| 1332 | end |
| 1333 | |
| 1334 | note Finish vertical stack copy + scaling + gf average + pack write; ottt_st[5..7] = bl, fz, bh |
| 1335 | fn osp_stkfin d1 ulong n1 ulong d2 ulong to void |
| 1336 | bl = get ottt_st 5 |
| 1337 | fz = get ottt_st 6 |
| 1338 | b1 = mul d1 get og 32 |
| 1339 | b2 = mul d2 get og 32 |
| 1340 | osp_c2w fz 0 b1 |
| 1341 | osp_c2w add fz b1 n1 b2 |
| 1342 | osp_sclays bl d1 div f64 oargu 5 1000.0 |
| 1343 | osp_sclays add bl d1 d2 div f64 oargu 6 1000.0 |
| 1344 | osp_stkgf add fz add b1 b2 b1 add n1 b2 |
| 1345 | ns = add add b1 b2 get og 2 |
| 1346 | osp_wrpack 7 bl get og 5 get ottt_st 7 fz ns |
| 1347 | oputc 83 |
| 1348 | oputc 80 |
| 1349 | oputc 83 |
| 1350 | oputc 84 |
| 1351 | oputc 75 |
| 1352 | oputc 32 |
| 1353 | oputu bl |
| 1354 | oputc 32 |
| 1355 | oputu get og 5 |
| 1356 | oputc 32 |
| 1357 | oputu ns |
| 1358 | oputc 10 |
| 1359 | oflush |
| 1360 | end |
| 1361 | |
| 1362 | note spstack BASE.ck P1.sp P2.sp S1_MILLI S2_MILLI OUT.sp |
| 1363 | note Vertically stack P1 layers then P2 layers on top of frozen BASE.ck |
| 1364 | fn cmdspstack to void |
| 1365 | if ne oargc 8 |
| 1366 | exit 2 |
| 1367 | end |
| 1368 | c = ocsinit |
| 1369 | ockload 2 |
| 1370 | bl = get og 5 |
| 1371 | fz = get og 33 |
| 1372 | bh = osp_basehash bl fz |
| 1373 | put ottt_st 5 bl |
| 1374 | put ottt_st 6 fz |
| 1375 | put ottt_st 7 bh |
| 1376 | d1 = sub osp_rd2ocs 3 0 bl bh 0 bl |
| 1377 | n1 = get ottt_st 3 |
| 1378 | d2 = sub osp_rd2ocs 4 n1 bl bh 0 bl |
| 1379 | put og 5 add bl add d1 d2 |
| 1380 | if not ogeom |
| 1381 | exit 12 |
| 1382 | end |
| 1383 | osp_stkfin d1 n1 d2 |
| 1384 | end |
| 1385 | |
| 1386 | note ---- 7. LLaMA-Pro Block-Expansion Growth (growpro) ---- |
| 1387 | note Clones the last base layer's trained (g1, Wq, Wk, Wv, g2, W1) into each added layer |
| 1388 | note and zeroes only (Wo, W2) so step-0 output is bit-identical to base while starting at |
| 1389 | note the base layer's exact weight scale (44x sharper Q*K logits than random oinit). |
| 1390 | fn osp_clone oldl ulong ll ulong to void |
| 1391 | lstr = get og 32 |
| 1392 | src = add get og 31 mul sub oldl 1 lstr |
| 1393 | for k ulong sub ll oldl |
| 1394 | dst = add get og 31 mul add oldl k lstr |
| 1395 | osp_c2w dst src lstr |
| 1396 | end |
| 1397 | end |
| 1398 | |
| 1399 | fn cmdgrowpro to void |
| 1400 | if ne oargc 7 |
| 1401 | exit 2 |
| 1402 | end |
| 1403 | ockloop 2 |
| 1404 | ll = oargu 4 |
| 1405 | tt = oargu 5 |
| 1406 | lr = oargu 6 |
| 1407 | if or le ll get og 5 or eq tt 0 gt tt 999999 |
| 1408 | exit 12 |
| 1409 | end |
| 1410 | if eq lr 0 |
| 1411 | exit 12 |
| 1412 | end |
| 1413 | oldl = get og 5 |
| 1414 | oldg = get og 33 |
| 1415 | ogrowsnap get og 8 |
| 1416 | put og 5 ll |
| 1417 | if not ogeom |
| 1418 | exit 12 |
| 1419 | end |
| 1420 | put og 41 0 |
| 1421 | put og 42 tt |
| 1422 | put og 43 bitcast ulong div f64 lr 1000000.0 |
| 1423 | ozerom mul 2 get og 8 |
| 1424 | ogrowcopy oldg |
| 1425 | for j ulong get og 2 |
| 1426 | owp add get og 33 j ocsg add oldg j |
| 1427 | end |
| 1428 | osp_clone oldl ll |
| 1429 | ogrowsilent oldl |
| 1430 | ocksave 3 |
| 1431 | oputc 71 |
| 1432 | oputc 80 |
| 1433 | oputc 32 |
| 1434 | oputu oldl |
| 1435 | oputc 32 |
| 1436 | oputu ll |
| 1437 | oputc 32 |
| 1438 | oputu get og 8 |
| 1439 | oputc 10 |
| 1440 | oflush |
| 1441 | end |
| 1442 | |
| 1443 | note ---- 8. Shared-Base Product-of-Experts Parallel Ensemble (spens) ---- |
| 1444 | note spens BASE.ck P1.sp P2.sp W1_MILLI N PROMPT TEMPMILLI SEED [MERGES] |
| 1445 | note Runs frozen base layers 0..bl-1 ONCE per token, then runs P1 and P2 specialist layers |
| 1446 | note in parallel over the shared H_base and fuses log_softmax(z1) & log_softmax(z2). |
| 1447 | note Works across DIFFERENT init basins (grow + growpro) with zero weight-averaging interference! |
| 1448 | |
| 1449 | fn osp_hsnap dst ulong src ulong n ulong to void |
| 1450 | i = ulong 0 |
| 1451 | while lt i n bound 9223372036854775807 |
| 1452 | ocsp add dst i get oa add src i |
| 1453 | i = add i 1 |
| 1454 | end |
| 1455 | end |
| 1456 | |
| 1457 | fn osp_hrest dst ulong src ulong n ulong to void |
| 1458 | i = ulong 0 |
| 1459 | while lt i n bound 9223372036854775807 |
| 1460 | put oa add dst i ocsg add src i |
| 1461 | i = add i 1 |
| 1462 | end |
| 1463 | end |
| 1464 | |
| 1465 | note Run final norm + klogit + log_softmax on row nc-1 into odl1 (which=1) or odl2 (which=2) |
| 1466 | fn osp_ens_head which ulong nc ulong to void |
| 1467 | d = get og 2 |
| 1468 | nc1 = sub nc 1 |
| 1469 | r = mul nc1 d |
| 1470 | z = add get og 17 r |
| 1471 | hf = add get og 15 r |
| 1472 | s0 = add get og 16 nc1 |
| 1473 | frms hf get og 33 z s0 |
| 1474 | klogit z get og 27 get og 0 d |
| 1475 | odl_lsm get og 27 get og 0 which |
| 1476 | end |
| 1477 | |
| 1478 | note Run one specialist branch (P1 if which=1 else P2) from cached H_base -> log_softmax in odl1/odl2 |
| 1479 | fn osp_ens_br which ulong nc ulong to void |
| 1480 | bl = get oens 0 |
| 1481 | sl = get oens 2 |
| 1482 | if eq which 1 |
| 1483 | osp_c2w get oens 1 get oens 3 get oens 4 |
| 1484 | else |
| 1485 | sl = get oens 5 |
| 1486 | osp_c2w get oens 1 get oens 6 get oens 7 |
| 1487 | end |
| 1488 | ho = oahin bl |
| 1489 | hs = add get oens 6 get oens 7 |
| 1490 | osp_hrest ho hs mul nc get og 2 |
| 1491 | put og 9 nc |
| 1492 | put okv 0 0 |
| 1493 | put ogkm 1 0 |
| 1494 | for k ulong sub sl bl |
| 1495 | olayf add bl k |
| 1496 | end |
| 1497 | osp_ens_head which nc |
| 1498 | end |
| 1499 | |
| 1500 | fn osp_ens_fuse w1 f64 to void |
| 1501 | pr = get og 27 |
| 1502 | w2 = sub 1.0f64 w1 |
| 1503 | for j ulong get og 0 |
| 1504 | a = mul w1 get odl1 j |
| 1505 | b = mul w2 get odl2 j |
| 1506 | put oa add pr j add a b |
| 1507 | end |
| 1508 | end |
| 1509 | |
| 1510 | note One PoE decode step: shared base 0..bl-1 once, then P1 + P2 branches, fused into TMP (og[27]) |
| 1511 | fn osp_ens_step w1 f64 st ulong tm ulong to ulong |
| 1512 | nc = get og 9 |
| 1513 | bl = get oens 0 |
| 1514 | put okv 0 0 |
| 1515 | put ogkm 1 0 |
| 1516 | oemb 0 |
| 1517 | for l ulong bl |
| 1518 | olayf l |
| 1519 | end |
| 1520 | hs = add get oens 6 get oens 7 |
| 1521 | ho = oahin bl |
| 1522 | osp_hsnap hs ho mul nc get og 2 |
| 1523 | osp_ens_br 1 nc |
| 1524 | osp_ens_br 2 nc |
| 1525 | osp_ens_fuse w1 |
| 1526 | if eq tm 0 |
| 1527 | ret oargmax |
| 1528 | end |
| 1529 | ret odraw st div f64 tm 1000.0 |
| 1530 | end |
| 1531 | |
| 1532 | fn osp_ens_loop nn ulong w1 f64 st ulong tm ulong to void |
| 1533 | v = get og 0 |
| 1534 | for g ulong nn |
| 1535 | c = osp_ens_step w1 st tm |
| 1536 | if ne tm 0 |
| 1537 | st = add st 11400714819323198485 |
| 1538 | end |
| 1539 | if eq c 0 |
| 1540 | break |
| 1541 | end |
| 1542 | if gt v 256 |
| 1543 | obtput c |
| 1544 | else |
| 1545 | oputc c |
| 1546 | end |
| 1547 | oflush |
| 1548 | ocpush c |
| 1549 | end |
| 1550 | oflush |
| 1551 | end |
| 1552 | |
| 1553 | fn osp_ens_init to void |
| 1554 | c = ocsinit |
| 1555 | ockload 2 |
| 1556 | bl = get og 5 |
| 1557 | fz = get og 33 |
| 1558 | p0 = get og 8 |
| 1559 | bh = osp_basehash bl fz |
| 1560 | ogrowsnap p0 |
| 1561 | l1 = osp_rd2ocs 3 p0 bl bh 0 |
| 1562 | n1 = get ottt_st 3 |
| 1563 | l2 = osp_rd2ocs 4 add p0 n1 bl bh l1 |
| 1564 | put oens 0 bl |
| 1565 | put oens 1 fz |
| 1566 | put oens 2 l1 |
| 1567 | put oens 3 p0 |
| 1568 | put oens 4 n1 |
| 1569 | put oens 5 l2 |
| 1570 | put oens 6 add p0 n1 |
| 1571 | put oens 7 get ottt_st 3 |
| 1572 | put og 5 l1 |
| 1573 | if not ogeom |
| 1574 | exit 12 |
| 1575 | end |
| 1576 | ogrowcopy fz |
| 1577 | end |
| 1578 | |
| 1579 | note spens BASE.ck P1.sp P2.sp W1_MILLI PROMPT N TEMPMILLI SEED [MERGES] |
| 1580 | fn cmdspens to void |
| 1581 | na = oargc |
| 1582 | if and ne na 10 ne na 11 |
| 1583 | exit 2 |
| 1584 | end |
| 1585 | osp_ens_init |
| 1586 | v = get og 0 |
| 1587 | if gt v 256 |
| 1588 | if eq na 10 |
| 1589 | exit 2 |
| 1590 | end |
| 1591 | obload 10 v |
| 1592 | end |
| 1593 | ottt_prompt v |
| 1594 | osp_ens_loop oargu 7 div f64 oargu 5 1000.0 oargu 9 oargu 8 |
| 1595 | end |
| 1596 | |
| 1597 | note ---- 9. Multi-Link Merkle Specialist Chains (spchainapp, spchaineval, spchainsamp) ---- |
| 1598 | |
| 1599 | note Chunked copy: ocs[dst..dst+n) = ow[src..src+n) |
| 1600 | fn osp_w2c dst ulong src ulong n ulong to void |
| 1601 | for q ulong ocn n |
| 1602 | i = mul q OCH |
| 1603 | ie = oce q n |
| 1604 | while lt i ie bound 999999 |
| 1605 | ocsp add dst i owg add src i |
| 1606 | i = add i 1 |
| 1607 | end |
| 1608 | end |
| 1609 | end |
| 1610 | |
| 1611 | note Chunked copy: ow[dst..dst+n) = ocs[src..src+n) |
| 1612 | fn osp_c2wb dst ulong src ulong n ulong to void |
| 1613 | for q ulong ocn n |
| 1614 | i = mul q OCH |
| 1615 | ie = oce q n |
| 1616 | while lt i ie bound 999999 |
| 1617 | owp add dst i ocsg add src i |
| 1618 | i = add i 1 |
| 1619 | end |
| 1620 | end |
| 1621 | end |
| 1622 | |
| 1623 | note Verify payload FNV-1a 64 of pack at argv[ai] without writing ow (exits 60/61 on error) |
| 1624 | fn osp_chkpay ai ulong ns ulong wantph ulong to void |
| 1625 | h = ulong 14695981039346656037 |
| 1626 | pos = ulong 48 |
| 1627 | done = ulong 0 |
| 1628 | while lt done ns bound 65536 |
| 1629 | cnt = sub ns done |
| 1630 | if gt cnt OCKC |
| 1631 | cnt = OCKC |
| 1632 | end |
| 1633 | nb = mul cnt 8 |
| 1634 | if ne oprd ai pos 0 nb nb |
| 1635 | exit 60 |
| 1636 | end |
| 1637 | h = ocfnvw h nb |
| 1638 | pos = add pos nb |
| 1639 | done = add done cnt |
| 1640 | end |
| 1641 | if ne h wantph |
| 1642 | exit 61 |
| 1643 | end |
| 1644 | end |
| 1645 | |
| 1646 | note Verify and attach one OLLMSP01 pack at argv[ai] onto the running model in ow |
| 1647 | fn osp_chain_link ai ulong to void |
| 1648 | cur_l = get og 5 |
| 1649 | cur_fz = get og 33 |
| 1650 | osp_rdhdr ai cur_l osp_basehash cur_l cur_fz |
| 1651 | ogrowsnap get og 8 |
| 1652 | put og 5 get ottt_st 1 |
| 1653 | if not ogeom |
| 1654 | exit 12 |
| 1655 | end |
| 1656 | if ne sub get og 8 cur_fz get ottt_st 3 |
| 1657 | exit 62 |
| 1658 | end |
| 1659 | ozerom mul 2 get og 8 |
| 1660 | ogrowcopy cur_fz |
| 1661 | if ne osp_rdpay ai cur_fz get ottt_st 3 get ottt_st 4 |
| 1662 | exit 61 |
| 1663 | end |
| 1664 | end |
| 1665 | |
| 1666 | note Load BASE.ck at argv[bkai] and sequentially attach K (1..8) Merkle-chained packs at argv[p0ai..] |
| 1667 | fn ospchainload bkai ulong k ulong p0ai ulong to void |
| 1668 | if or eq k 0 gt k 8 |
| 1669 | exit 2 |
| 1670 | end |
| 1671 | ockloop bkai |
| 1672 | put ottt_st 0 get og 5 |
| 1673 | for j ulong k |
| 1674 | osp_chain_link add p0ai j |
| 1675 | end |
| 1676 | end |
| 1677 | |
| 1678 | note Load prompt from argv[pai] into obx with leading token 0 |
| 1679 | fn osp_prompt pai ulong v ulong to void |
| 1680 | put og 9 0 |
| 1681 | ocpush 0 |
| 1682 | if gt v 256 |
| 1683 | r = oargr pai |
| 1684 | if or lt r 0 gt r 4000 |
| 1685 | exit 2 |
| 1686 | end |
| 1687 | np = obprompt pai |
| 1688 | for i ulong np |
| 1689 | ocpush get obtk i |
| 1690 | end |
| 1691 | else |
| 1692 | r = oargr pai |
| 1693 | if or lt r 0 gt r 4096 |
| 1694 | exit 2 |
| 1695 | end |
| 1696 | for i ulong ulong r |
| 1697 | ocpush ulong get oarg i |
| 1698 | end |
| 1699 | end |
| 1700 | end |
| 1701 | |
| 1702 | note Sample nn tokens from the currently loaded model + context |
| 1703 | fn osp_samploop seed ulong nn ulong tm ulong to void |
| 1704 | if gt nn 999999 |
| 1705 | exit 2 |
| 1706 | end |
| 1707 | st = seed |
| 1708 | v = get og 0 |
| 1709 | for g ulong nn |
| 1710 | c = osstep st tm |
| 1711 | if ne tm 0 |
| 1712 | st = add st 11400714819323198485 |
| 1713 | end |
| 1714 | if eq c 0 |
| 1715 | break |
| 1716 | end |
| 1717 | if gt v 256 |
| 1718 | obtput c |
| 1719 | else |
| 1720 | oputc c |
| 1721 | end |
| 1722 | oflush |
| 1723 | ocpush c |
| 1724 | end |
| 1725 | oflush |
| 1726 | end |
| 1727 | |
| 1728 | note spchainapp BASE.ck OUT.ck K P1.sp ... PK.sp |
| 1729 | fn cmdspchainapp to void |
| 1730 | na = oargc |
| 1731 | if lt na 6 |
| 1732 | exit 2 |
| 1733 | end |
| 1734 | k = oargu 4 |
| 1735 | if or eq k 0 or gt k 8 ne na add 5 k |
| 1736 | exit 2 |
| 1737 | end |
| 1738 | ospchainload 2 k 5 |
| 1739 | ocksave 3 |
| 1740 | oputc 83 |
| 1741 | oputc 80 |
| 1742 | oputc 67 |
| 1743 | oputc 72 |
| 1744 | oputc 65 |
| 1745 | oputc 80 |
| 1746 | oputc 80 |
| 1747 | oputc 32 |
| 1748 | oputu get ottt_st 0 |
| 1749 | oputc 32 |
| 1750 | oputu get og 5 |
| 1751 | oputc 32 |
| 1752 | oputu k |
| 1753 | oputc 32 |
| 1754 | oputu get og 8 |
| 1755 | oputc 10 |
| 1756 | oflush |
| 1757 | end |
| 1758 | |
| 1759 | note spchaineval BASE.ck HELD W MERGES K P1.sp ... PK.sp |
| 1760 | fn cmdspchaineval to void |
| 1761 | na = oargc |
| 1762 | if lt na 8 |
| 1763 | exit 2 |
| 1764 | end |
| 1765 | k = oargu 6 |
| 1766 | if or eq k 0 or gt k 8 ne na add 7 k |
| 1767 | exit 2 |
| 1768 | end |
| 1769 | ospchainload 2 k 7 |
| 1770 | ww = oargu 4 |
| 1771 | v = get og 0 |
| 1772 | if gt v 256 |
| 1773 | obload 5 v |
| 1774 | end |
| 1775 | odopen 3 |
| 1776 | tt = get og 1 |
| 1777 | m = get odn 0 |
| 1778 | if eq ww 0 |
| 1779 | exit 23 |
| 1780 | end |
| 1781 | if gt ww div sub m 1 tt |
| 1782 | exit 23 |
| 1783 | end |
| 1784 | ls = 0.0f64 |
| 1785 | nb = ulong 0 |
| 1786 | for w ulong ww |
| 1787 | obrow 0 mul w tt |
| 1788 | ls = add ls ofwd 0 |
| 1789 | if gt v 256 |
| 1790 | nb = add nb oevnb tt |
| 1791 | end |
| 1792 | end |
| 1793 | lo = div ls f64 ww |
| 1794 | bp = div lo 0.6931471805599453 |
| 1795 | if gt v 256 |
| 1796 | bp = div mul bp f64 mul ww tt f64 nb |
| 1797 | end |
| 1798 | oputc 69 |
| 1799 | oputc 32 |
| 1800 | oputu get og 41 |
| 1801 | oputc 32 |
| 1802 | oputu ww |
| 1803 | oputc 32 |
| 1804 | oputl rmic lo |
| 1805 | oputc 32 |
| 1806 | oputl rmic bp |
| 1807 | oputc 10 |
| 1808 | oflush |
| 1809 | end |
| 1810 | |
| 1811 | note spchainsamp BASE.ck N TEMPMILLI PROMPT SEED MERGES K P1.sp ... PK.sp |
| 1812 | fn cmdspchainsamp to void |
| 1813 | na = oargc |
| 1814 | if lt na 10 |
| 1815 | exit 2 |
| 1816 | end |
| 1817 | k = oargu 8 |
| 1818 | if or eq k 0 or gt k 8 ne na add 9 k |
| 1819 | exit 2 |
| 1820 | end |
| 1821 | ospchainload 2 k 9 |
| 1822 | nn = oargu 3 |
| 1823 | if gt nn 999999 |
| 1824 | exit 2 |
| 1825 | end |
| 1826 | tm = oargu 4 |
| 1827 | st = oargu 6 |
| 1828 | v = get og 0 |
| 1829 | if gt v 256 |
| 1830 | obload 7 v |
| 1831 | end |
| 1832 | ochipup |
| 1833 | osp_prompt 5 v |
| 1834 | osp_samploop st nn tm |
| 1835 | end |
| 1836 | |
| 1837 | note ---- 10. DNA-Style Multi-Helix Chain Clipping (spclip, S = 2..4 strands) ---- |
| 1838 | note spclip BASE.ck MODE PROMPT N TEMPMILLI SEED MERGES S W1 K1 A1..AK1 W2 K2 B1..BK2 [W3 K3 C1..CK3 [W4 K4 D1..DK4]] |
| 1839 | note MODE=0: normalized prior PoE (w_s / sum(w)); MODE=1: entropy-gated multi-helix (u_s = w_s / (H_s + 0.001)). |
| 1840 | |
| 1841 | note Hidden-state output offset in oa after running layers 0..l-1 (l >= 1) |
| 1842 | fn osp_hout l ulong to ulong |
| 1843 | a = osp_app l |
| 1844 | if lt a get og 56 |
| 1845 | ret oahin a |
| 1846 | end |
| 1847 | ret get og 15 |
| 1848 | end |
| 1849 | |
| 1850 | note Reset dynamic spclip config defaults (called before legacy spclip, spguard, and subcommands) |
| 1851 | fn osp_clip_defaults to void |
| 1852 | for i ulong 16 |
| 1853 | put ocl_cfg i 0 |
| 1854 | end |
| 1855 | put ocl_cfg 0 1000 |
| 1856 | put ocl_cfg 1 2 |
| 1857 | for s ulong 4 |
| 1858 | put ocl_sp_s s 0 |
| 1859 | put ocl_sp_e s 0 |
| 1860 | put ocl_sp_g s 1000 |
| 1861 | put ocl_raw_sl s 0 |
| 1862 | put ocl_wm s 1000 |
| 1863 | put ocl_w s 1.0f64 |
| 1864 | end |
| 1865 | end |
| 1866 | |
| 1867 | fn osp_link_ai s ulong j ulong to ulong |
| 1868 | if ne get ocl_cfg 2 0 |
| 1869 | ret get ocl_link add mul s 8 j |
| 1870 | end |
| 1871 | ret add get ocl_a0 s j |
| 1872 | end |
| 1873 | |
| 1874 | fn osp_clip_validate_knobs to void |
| 1875 | md = get ocl_st 0 |
| 1876 | ss = get ocl_st 1 |
| 1877 | tm = get ocl_cfg 0 |
| 1878 | if or gt md 1 or lt ss 2 gt ss 4 |
| 1879 | exit 2 |
| 1880 | end |
| 1881 | if or eq tm 0 gt tm 100000 |
| 1882 | exit 2 |
| 1883 | end |
| 1884 | sw = 0.0f64 |
| 1885 | ac = ulong 0 |
| 1886 | for s ulong ss |
| 1887 | wi = get ocl_wm s |
| 1888 | if or lt wi -5000 gt wi 5000 |
| 1889 | exit 2 |
| 1890 | end |
| 1891 | if and eq md 1 lt wi 0 |
| 1892 | exit 2 |
| 1893 | end |
| 1894 | if gt get ocl_sp_g s 2000 |
| 1895 | exit 2 |
| 1896 | end |
| 1897 | ws = div f64 wi 1000.0 |
| 1898 | put ocl_w s ws |
| 1899 | if gt ws 0.0 |
| 1900 | sw = add sw ws |
| 1901 | end |
| 1902 | if lt wi 0 |
| 1903 | ac = add ac 1 |
| 1904 | end |
| 1905 | end |
| 1906 | if le sw 0.0 |
| 1907 | exit 2 |
| 1908 | end |
| 1909 | put ocl_st 13 ac |
| 1910 | end |
| 1911 | |
| 1912 | note ---- 10A. FIPS 180-4 SHA-256 (OM-1 compatible, low register pressure) ---- |
| 1913 | fn osha_rotr x uint n uint to uint |
| 1914 | ret or shr x n shl x sub 32 n |
| 1915 | end |
| 1916 | |
| 1917 | fn osha_initk to void |
| 1918 | if ne get osha_ready 0 0 |
| 1919 | ret |
| 1920 | end |
| 1921 | put osha_k 0 1116352408 |
| 1922 | put osha_k 1 1899447441 |
| 1923 | put osha_k 2 3049323471 |
| 1924 | put osha_k 3 3921009573 |
| 1925 | put osha_k 4 961987163 |
| 1926 | put osha_k 5 1508970993 |
| 1927 | put osha_k 6 2453635748 |
| 1928 | put osha_k 7 2870763221 |
| 1929 | put osha_k 8 3624381080 |
| 1930 | put osha_k 9 310598401 |
| 1931 | put osha_k 10 607225278 |
| 1932 | put osha_k 11 1426881987 |
| 1933 | put osha_k 12 1925078388 |
| 1934 | put osha_k 13 2162078206 |
| 1935 | put osha_k 14 2614888103 |
| 1936 | put osha_k 15 3248222580 |
| 1937 | put osha_k 16 3835390401 |
| 1938 | put osha_k 17 4022224774 |
| 1939 | put osha_k 18 264347078 |
| 1940 | put osha_k 19 604807628 |
| 1941 | put osha_k 20 770255983 |
| 1942 | put osha_k 21 1249150122 |
| 1943 | put osha_k 22 1555081692 |
| 1944 | put osha_k 23 1996064986 |
| 1945 | put osha_k 24 2554220882 |
| 1946 | put osha_k 25 2821834349 |
| 1947 | put osha_k 26 2952996808 |
| 1948 | put osha_k 27 3210313671 |
| 1949 | put osha_k 28 3336571891 |
| 1950 | put osha_k 29 3584528711 |
| 1951 | put osha_k 30 113926993 |
| 1952 | put osha_k 31 338241895 |
| 1953 | put osha_k 32 666307205 |
| 1954 | put osha_k 33 773529912 |
| 1955 | put osha_k 34 1294757372 |
| 1956 | put osha_k 35 1396182291 |
| 1957 | put osha_k 36 1695183700 |
| 1958 | put osha_k 37 1986661051 |
| 1959 | put osha_k 38 2177026350 |
| 1960 | put osha_k 39 2456956037 |
| 1961 | put osha_k 40 2730485921 |
| 1962 | put osha_k 41 2820302411 |
| 1963 | put osha_k 42 3259730800 |
| 1964 | put osha_k 43 3345764771 |
| 1965 | put osha_k 44 3516065817 |
| 1966 | put osha_k 45 3600352804 |
| 1967 | put osha_k 46 4094571909 |
| 1968 | put osha_k 47 275423344 |
| 1969 | put osha_k 48 430227734 |
| 1970 | put osha_k 49 506948616 |
| 1971 | put osha_k 50 659060556 |
| 1972 | put osha_k 51 883997877 |
| 1973 | put osha_k 52 958139571 |
| 1974 | put osha_k 53 1322822218 |
| 1975 | put osha_k 54 1537002063 |
| 1976 | put osha_k 55 1747873779 |
| 1977 | put osha_k 56 1955562222 |
| 1978 | put osha_k 57 2024104815 |
| 1979 | put osha_k 58 2227730452 |
| 1980 | put osha_k 59 2361852424 |
| 1981 | put osha_k 60 2428436474 |
| 1982 | put osha_k 61 2756734187 |
| 1983 | put osha_k 62 3204031479 |
| 1984 | put osha_k 63 3329325298 |
| 1985 | put osha_ready 0 1 |
| 1986 | end |
| 1987 | |
| 1988 | fn osha_init to void |
| 1989 | osha_initk |
| 1990 | put osha_h 0 1779033703 |
| 1991 | put osha_h 1 3144134277 |
| 1992 | put osha_h 2 1013904242 |
| 1993 | put osha_h 3 2773480762 |
| 1994 | put osha_h 4 1359893119 |
| 1995 | put osha_h 5 2600822924 |
| 1996 | put osha_h 6 528734635 |
| 1997 | put osha_h 7 1541459225 |
| 1998 | put osha_n 0 0 |
| 1999 | end |
| 2000 | |
| 2001 | fn osha_sched to void |
| 2002 | for i ulong 16 |
| 2003 | q = mul i 4 |
| 2004 | x = uint get osha_b q |
| 2005 | x = or shl x 8 uint get osha_b add q 1 |
| 2006 | x = or shl x 8 uint get osha_b add q 2 |
| 2007 | put osha_w i or shl x 8 uint get osha_b add q 3 |
| 2008 | end |
| 2009 | for j ulong 48 |
| 2010 | x = get osha_w add j 1 |
| 2011 | s0 = xor xor osha_rotr x 7 osha_rotr x 18 shr x 3 |
| 2012 | y = get osha_w add j 14 |
| 2013 | s1 = xor xor osha_rotr y 17 osha_rotr y 19 shr y 10 |
| 2014 | put osha_w add j 16 add add add get osha_w j s0 get osha_w add j 9 s1 |
| 2015 | end |
| 2016 | end |
| 2017 | |
| 2018 | fn osha_t1 i ulong to uint |
| 2019 | e = get osha_v 4 |
| 2020 | s1 = xor xor osha_rotr e 6 osha_rotr e 11 osha_rotr e 25 |
| 2021 | ch = xor get osha_v 6 and e xor get osha_v 5 get osha_v 6 |
| 2022 | t1 = add add get osha_v 7 s1 ch |
| 2023 | ret add add t1 get osha_k i get osha_w i |
| 2024 | end |
| 2025 | |
| 2026 | fn osha_t2 to uint |
| 2027 | a = get osha_v 0 |
| 2028 | b = get osha_v 1 |
| 2029 | c = get osha_v 2 |
| 2030 | s0 = xor xor osha_rotr a 2 osha_rotr a 13 osha_rotr a 22 |
| 2031 | mj = or and a b and c or a b |
| 2032 | ret add s0 mj |
| 2033 | end |
| 2034 | |
| 2035 | fn osha_round i ulong to void |
| 2036 | t1 = osha_t1 i |
| 2037 | t2 = osha_t2 |
| 2038 | put osha_v 7 get osha_v 6 |
| 2039 | put osha_v 6 get osha_v 5 |
| 2040 | put osha_v 5 get osha_v 4 |
| 2041 | put osha_v 4 add get osha_v 3 t1 |
| 2042 | put osha_v 3 get osha_v 2 |
| 2043 | put osha_v 2 get osha_v 1 |
| 2044 | put osha_v 1 get osha_v 0 |
| 2045 | put osha_v 0 add t1 t2 |
| 2046 | end |
| 2047 | |
| 2048 | fn osha_comp to void |
| 2049 | osha_sched |
| 2050 | for i ulong 8 |
| 2051 | put osha_v i get osha_h i |
| 2052 | end |
| 2053 | for r ulong 64 |
| 2054 | osha_round r |
| 2055 | end |
| 2056 | for j ulong 8 |
| 2057 | put osha_h j add get osha_h j get osha_v j |
| 2058 | end |
| 2059 | end |
| 2060 | |
| 2061 | fn osha_byte c uchar to void |
| 2062 | n = get osha_n 0 |
| 2063 | put osha_b and n 63 c |
| 2064 | n = add n 1 |
| 2065 | put osha_n 0 n |
| 2066 | if eq and n 63 0 |
| 2067 | osha_comp |
| 2068 | end |
| 2069 | end |
| 2070 | |
| 2071 | fn osha_fin to void |
| 2072 | nb = get osha_n 0 |
| 2073 | bits = shl nb 3 |
| 2074 | osha_byte uchar 128 |
| 2075 | while ne and get osha_n 0 63 56 bound 64 |
| 2076 | osha_byte uchar 0 |
| 2077 | end |
| 2078 | for k ulong 8 |
| 2079 | b = and shr bits mul sub 7 k 8 255 |
| 2080 | osha_byte uchar b |
| 2081 | end |
| 2082 | for i ulong 8 |
| 2083 | w = get osha_h i |
| 2084 | q = mul i 4 |
| 2085 | put osha_d q uchar and shr w 24 255 |
| 2086 | put osha_d add q 1 uchar and shr w 16 255 |
| 2087 | put osha_d add q 2 uchar and shr w 8 255 |
| 2088 | put osha_d add q 3 uchar and w 255 |
| 2089 | end |
| 2090 | end |
| 2091 | |
| 2092 | fn osha_file ai ulong to void |
| 2093 | osha_init |
| 2094 | sz = ofsz ai |
| 2095 | pos = ulong 0 |
| 2096 | while lt pos sz bound 9223372036854775807 |
| 2097 | cnt = sub sz pos |
| 2098 | if gt cnt 524288 |
| 2099 | cnt = ulong 524288 |
| 2100 | end |
| 2101 | if ne oprd ai pos 0 cnt cnt |
| 2102 | exit 60 |
| 2103 | end |
| 2104 | j = ulong 0 |
| 2105 | while lt j cnt bound 524288 |
| 2106 | osha_byte get opw j |
| 2107 | j = add j 1 |
| 2108 | end |
| 2109 | pos = add pos cnt |
| 2110 | end |
| 2111 | osha_fin |
| 2112 | end |
| 2113 | |
| 2114 | fn osha_buf_ocl n ulong to void |
| 2115 | osha_init |
| 2116 | i = ulong 0 |
| 2117 | while lt i n bound 65536 |
| 2118 | osha_byte get ocl_rec i |
| 2119 | i = add i 1 |
| 2120 | end |
| 2121 | osha_fin |
| 2122 | end |
| 2123 | |
| 2124 | fn osha_save_bsha to void |
| 2125 | for i ulong 32 |
| 2126 | put ocl_bsha i get osha_d i |
| 2127 | end |
| 2128 | end |
| 2129 | |
| 2130 | fn osha_eq_bsha to bool |
| 2131 | for i ulong 32 |
| 2132 | if ne get ocl_bsha i get osha_d i |
| 2133 | ret false |
| 2134 | end |
| 2135 | end |
| 2136 | ret true |
| 2137 | end |
| 2138 | |
| 2139 | fn osha_save_lsha idx ulong to void |
| 2140 | bo = mul idx 32 |
| 2141 | for i ulong 32 |
| 2142 | put ocl_lsha add bo i get osha_d i |
| 2143 | end |
| 2144 | end |
| 2145 | |
| 2146 | fn osha_eq_lsha idx ulong to bool |
| 2147 | bo = mul idx 32 |
| 2148 | for i ulong 32 |
| 2149 | if ne get ocl_lsha add bo i get osha_d i |
| 2150 | ret false |
| 2151 | end |
| 2152 | end |
| 2153 | ret true |
| 2154 | end |
| 2155 | |
| 2156 | fn osha_save_rsha to void |
| 2157 | for i ulong 32 |
| 2158 | put ocl_rsha i get osha_d i |
| 2159 | end |
| 2160 | end |
| 2161 | |
| 2162 | fn osha_eq_rsha to bool |
| 2163 | for i ulong 32 |
| 2164 | if ne get ocl_rsha i get osha_d i |
| 2165 | ret false |
| 2166 | end |
| 2167 | end |
| 2168 | ret true |
| 2169 | end |
| 2170 | |
| 2171 | fn osha_save_csha to void |
| 2172 | for i ulong 32 |
| 2173 | put ocl_csha i get osha_d i |
| 2174 | end |
| 2175 | end |
| 2176 | |
| 2177 | fn osha_eq_csha to bool |
| 2178 | for i ulong 32 |
| 2179 | if ne get ocl_csha i get osha_d i |
| 2180 | ret false |
| 2181 | end |
| 2182 | end |
| 2183 | ret true |
| 2184 | end |
| 2185 | |
| 2186 | fn osha_save_dsha to void |
| 2187 | for i ulong 32 |
| 2188 | put ocl_dsha i get osha_d i |
| 2189 | end |
| 2190 | end |
| 2191 | |
| 2192 | fn osha_save_tsha to void |
| 2193 | for i ulong 32 |
| 2194 | put ocl_tsha i get osha_d i |
| 2195 | end |
| 2196 | end |
| 2197 | |
| 2198 | fn osha_eq_tsha to bool |
| 2199 | for i ulong 32 |
| 2200 | if ne get ocl_tsha i get osha_d i |
| 2201 | ret false |
| 2202 | end |
| 2203 | end |
| 2204 | ret true |
| 2205 | end |
| 2206 | |
| 2207 | fn oput_sha_d to void |
| 2208 | for i ulong 32 |
| 2209 | b = ulong get osha_d i |
| 2210 | hi = shr b 4 |
| 2211 | lo = and b 15 |
| 2212 | if lt hi 10 |
| 2213 | oputc add hi 48 |
| 2214 | else |
| 2215 | oputc add hi 87 |
| 2216 | end |
| 2217 | if lt lo 10 |
| 2218 | oputc add lo 48 |
| 2219 | else |
| 2220 | oputc add lo 87 |
| 2221 | end |
| 2222 | end |
| 2223 | end |
| 2224 | |
| 2225 | fn oput_sha_rsha to void |
| 2226 | for i ulong 32 |
| 2227 | put osha_d i get ocl_rsha i |
| 2228 | end |
| 2229 | oput_sha_d |
| 2230 | end |
| 2231 | |
| 2232 | fn oput_sha_csha to void |
| 2233 | for i ulong 32 |
| 2234 | put osha_d i get ocl_csha i |
| 2235 | end |
| 2236 | oput_sha_d |
| 2237 | end |
| 2238 | |
| 2239 | fn oput_sha_tsha to void |
| 2240 | for i ulong 32 |
| 2241 | put osha_d i get ocl_tsha i |
| 2242 | end |
| 2243 | oput_sha_d |
| 2244 | end |
| 2245 | |
| 2246 | fn oput_sha_bsha to void |
| 2247 | for i ulong 32 |
| 2248 | put osha_d i get ocl_bsha i |
| 2249 | end |
| 2250 | oput_sha_d |
| 2251 | end |
| 2252 | |
| 2253 | fn oput_sha_lsha idx ulong to void |
| 2254 | bo = mul idx 32 |
| 2255 | for i ulong 32 |
| 2256 | put osha_d i get ocl_lsha add bo i |
| 2257 | end |
| 2258 | oput_sha_d |
| 2259 | end |
| 2260 | |
| 2261 | note Verify or capture base + all link SHA-256 digests according to ocl_cfg[3] (0=skip, 1=verify, 2=capture) |
| 2262 | fn osp_clip_hash_pass to void |
| 2263 | hm = get ocl_cfg 3 |
| 2264 | if eq hm 0 |
| 2265 | ret |
| 2266 | end |
| 2267 | bai = get ocl_cfg 1 |
| 2268 | osha_file bai |
| 2269 | if eq hm 1 |
| 2270 | if not osha_eq_bsha |
| 2271 | exit 62 |
| 2272 | end |
| 2273 | else |
| 2274 | osha_save_bsha |
| 2275 | end |
| 2276 | ss = get ocl_st 1 |
| 2277 | for s ulong ss |
| 2278 | ks = get ocl_k s |
| 2279 | for j ulong ks |
| 2280 | idx = add mul s 8 j |
| 2281 | ai = osp_link_ai s j |
| 2282 | osha_file ai |
| 2283 | if eq hm 1 |
| 2284 | if not osha_eq_lsha idx |
| 2285 | exit 61 |
| 2286 | end |
| 2287 | else |
| 2288 | osha_save_lsha idx |
| 2289 | end |
| 2290 | if lt ofsz ai 48 |
| 2291 | exit 60 |
| 2292 | end |
| 2293 | if ne oprd ai 0 0 48 48 |
| 2294 | exit 60 |
| 2295 | end |
| 2296 | if ne opw8 0 OSPMAG |
| 2297 | exit 60 |
| 2298 | end |
| 2299 | ph = opw8 40 |
| 2300 | if eq hm 1 |
| 2301 | if ne ph get ocl_lph idx |
| 2302 | exit 61 |
| 2303 | end |
| 2304 | else |
| 2305 | put ocl_lph idx ph |
| 2306 | end |
| 2307 | end |
| 2308 | end |
| 2309 | end |
| 2310 | |
| 2311 | note Parse spclip or spguard CLI strand arguments starting at ss_arg |
| 2312 | fn osp_clip_parse_at md ulong ss_arg ulong to void |
| 2313 | na = oargc |
| 2314 | if lt na add ss_arg 7 |
| 2315 | exit 2 |
| 2316 | end |
| 2317 | ss = oargu ss_arg |
| 2318 | if or lt ss 2 gt ss 4 |
| 2319 | exit 2 |
| 2320 | end |
| 2321 | put ocl_st 0 md |
| 2322 | put ocl_st 1 ss |
| 2323 | idx = add ss_arg 1 |
| 2324 | sw = 0.0f64 |
| 2325 | ac = ulong 0 |
| 2326 | for s ulong ss |
| 2327 | if gt add idx 2 na |
| 2328 | exit 2 |
| 2329 | end |
| 2330 | wi = oargs idx |
| 2331 | if and eq md 1 lt wi 0 |
| 2332 | exit 2 |
| 2333 | end |
| 2334 | if or lt wi -5000 gt wi 5000 |
| 2335 | exit 2 |
| 2336 | end |
| 2337 | put ocl_wm s wi |
| 2338 | ws = div f64 wi 1000.0 |
| 2339 | if lt wi 0 |
| 2340 | ac = add ac 1 |
| 2341 | end |
| 2342 | ks = oargu add idx 1 |
| 2343 | if or eq ks 0 gt ks 8 |
| 2344 | exit 2 |
| 2345 | end |
| 2346 | if gt add add idx 2 ks na |
| 2347 | exit 2 |
| 2348 | end |
| 2349 | put ocl_w s ws |
| 2350 | if gt ws 0.0 |
| 2351 | sw = add sw ws |
| 2352 | end |
| 2353 | put ocl_k s ks |
| 2354 | put ocl_a0 s add idx 2 |
| 2355 | idx = add add idx 2 ks |
| 2356 | end |
| 2357 | if or ne idx na le sw 0.0 |
| 2358 | exit 2 |
| 2359 | end |
| 2360 | put ocl_st 13 ac |
| 2361 | end |
| 2362 | |
| 2363 | note Parse spclip CLI arguments into ocl_st, ocl_w, ocl_k, ocl_a0 |
| 2364 | fn osp_clip_parse to void |
| 2365 | na = oargc |
| 2366 | if lt na 16 |
| 2367 | exit 2 |
| 2368 | end |
| 2369 | md = oargu 3 |
| 2370 | if gt md 1 |
| 2371 | exit 2 |
| 2372 | end |
| 2373 | osp_clip_parse_at md 9 |
| 2374 | end |
| 2375 | |
| 2376 | note Mix 64-bit little-endian integer x into running FNV-1a-64 digest h |
| 2377 | fn osp_mix64 h ulong x ulong to ulong |
| 2378 | z = h |
| 2379 | for k ulong 8 |
| 2380 | b = and shr x mul k 8 255 |
| 2381 | z = mul xor z b 1099511628211 |
| 2382 | end |
| 2383 | ret z |
| 2384 | end |
| 2385 | |
| 2386 | note True iff all ss strands share an identical valid pack at link index j on top of current ow |
| 2387 | fn osp_clip_same j ulong ss ulong to bool |
| 2388 | bh = osp_basehash get og 5 get og 33 |
| 2389 | osp_rdhdr osp_link_ai 0 j get og 5 bh |
| 2390 | sl0 = get ottt_st 1 |
| 2391 | ns0 = get ottt_st 3 |
| 2392 | ph0 = get ottt_st 4 |
| 2393 | s = ulong 1 |
| 2394 | while lt s ss bound 4 |
| 2395 | osp_rdhdr osp_link_ai s j get og 5 bh |
| 2396 | if ne get ottt_st 1 sl0 |
| 2397 | ret false |
| 2398 | end |
| 2399 | if ne get ottt_st 3 ns0 |
| 2400 | ret false |
| 2401 | end |
| 2402 | if ne get ottt_st 4 ph0 |
| 2403 | ret false |
| 2404 | end |
| 2405 | s = add s 1 |
| 2406 | end |
| 2407 | s = ulong 1 |
| 2408 | while lt s ss bound 4 |
| 2409 | osp_chkpay osp_link_ai s j ns0 ph0 |
| 2410 | s = add s 1 |
| 2411 | end |
| 2412 | ret true |
| 2413 | end |
| 2414 | |
| 2415 | note Load longest common prefix of packs across all S strands into ow; save trunk_gf in odl2 |
| 2416 | fn osp_clip_trunk to void |
| 2417 | ss = get ocl_st 1 |
| 2418 | mink = get ocl_k 0 |
| 2419 | for s ulong ss |
| 2420 | if lt get ocl_k s mink |
| 2421 | mink = get ocl_k s |
| 2422 | end |
| 2423 | end |
| 2424 | comm = ulong 0 |
| 2425 | phc = ulong 14695981039346656037 |
| 2426 | for j ulong mink |
| 2427 | if not osp_clip_same j ss |
| 2428 | break |
| 2429 | end |
| 2430 | osp_chain_link osp_link_ai 0 j |
| 2431 | phc = osp_mix64 phc get ottt_st 4 |
| 2432 | comm = add comm 1 |
| 2433 | end |
| 2434 | put ocl_st 3 get og 5 |
| 2435 | put ocl_st 4 get og 33 |
| 2436 | put ocl_st 6 comm |
| 2437 | put ocl_exp 14 osp_basehash get og 5 get og 33 |
| 2438 | for s2 ulong ss |
| 2439 | put ocl_ph s2 phc |
| 2440 | end |
| 2441 | for g ulong get og 2 |
| 2442 | put odl2 g owg add get og 33 g |
| 2443 | end |
| 2444 | end |
| 2445 | |
| 2446 | note Peek final spec_L of each strand's last pack to find max_L across all S strands |
| 2447 | fn osp_clip_maxl to ulong |
| 2448 | ss = get ocl_st 1 |
| 2449 | comm = get ocl_st 6 |
| 2450 | ml = get ocl_st 3 |
| 2451 | for s ulong ss |
| 2452 | ks = get ocl_k s |
| 2453 | if gt ks comm |
| 2454 | ai = osp_link_ai s sub ks 1 |
| 2455 | if lt ofsz ai 48 |
| 2456 | exit 60 |
| 2457 | end |
| 2458 | if ne oprd ai 0 0 48 48 |
| 2459 | exit 60 |
| 2460 | end |
| 2461 | if ne opw8 0 OSPMAG |
| 2462 | exit 60 |
| 2463 | end |
| 2464 | sl = opw8 16 |
| 2465 | if gt sl ml |
| 2466 | ml = sl |
| 2467 | end |
| 2468 | end |
| 2469 | end |
| 2470 | if gt ml 24 |
| 2471 | exit 12 |
| 2472 | end |
| 2473 | ret ml |
| 2474 | end |
| 2475 | |
| 2476 | note Load one non-shared link ai onto (cur_l, cur_fz); returns new spec_L |
| 2477 | fn osp_clip_1link ai ulong cur_l ulong cur_fz ulong to ulong |
| 2478 | osp_rdhdr ai cur_l osp_basehash cur_l cur_fz |
| 2479 | sl = get ottt_st 1 |
| 2480 | ns = get ottt_st 3 |
| 2481 | if gt sl get og 5 |
| 2482 | exit 62 |
| 2483 | end |
| 2484 | wn = mul sub sl cur_l get og 32 |
| 2485 | if ne ns add wn get og 2 |
| 2486 | exit 62 |
| 2487 | end |
| 2488 | if ne osp_rdpay ai cur_fz ns get ottt_st 4 |
| 2489 | exit 61 |
| 2490 | end |
| 2491 | ret sl |
| 2492 | end |
| 2493 | |
| 2494 | note Load remaining links comm..ks-1 of strand s into ow[fzt..); returns final depth cur_l |
| 2495 | fn osp_clip_slinks s ulong to ulong |
| 2496 | cur_l = get ocl_st 3 |
| 2497 | cur_fz = get ocl_st 4 |
| 2498 | j = get ocl_st 6 |
| 2499 | ks = get ocl_k s |
| 2500 | ph = get ocl_ph s |
| 2501 | while lt j ks bound 16 |
| 2502 | sl = osp_clip_1link osp_link_ai s j cur_l cur_fz |
| 2503 | ph = osp_mix64 ph get ottt_st 4 |
| 2504 | cur_l = sl |
| 2505 | cur_fz = add get og 31 mul sl get og 32 |
| 2506 | j = add j 1 |
| 2507 | end |
| 2508 | put ocl_ph s ph |
| 2509 | ret cur_l |
| 2510 | end |
| 2511 | |
| 2512 | note Shift active spliced layers down in ow when eff_s > tl |
| 2513 | fn osp_clip_shift dst ulong src ulong n ulong to void |
| 2514 | i = ulong 0 |
| 2515 | while lt i n bound 9223372036854775807 |
| 2516 | owp add dst i owg add src i |
| 2517 | i = add i 1 |
| 2518 | end |
| 2519 | end |
| 2520 | |
| 2521 | note Load strand s raw unspliced layers into ow[fzt..) and save gf_s into odl1[0..d); returns raw depth cl |
| 2522 | fn osp_clip_load_raw s ulong to ulong |
| 2523 | tl = get ocl_st 3 |
| 2524 | d = get og 2 |
| 2525 | if eq get ocl_k s get ocl_st 6 |
| 2526 | for g ulong d |
| 2527 | put odl1 g get odl2 g |
| 2528 | end |
| 2529 | ret tl |
| 2530 | end |
| 2531 | cl = osp_clip_slinks s |
| 2532 | gf_off = add get ocl_st 4 mul sub cl tl get og 32 |
| 2533 | for g2 ulong d |
| 2534 | put odl1 g2 owg add gf_off g2 |
| 2535 | end |
| 2536 | ret cl |
| 2537 | end |
| 2538 | |
| 2539 | fn osp_clip_chk_sp tl ulong cl ulong es ulong ee ulong gn ulong to void |
| 2540 | if lt es tl |
| 2541 | exit 2 |
| 2542 | end |
| 2543 | if gt es cl |
| 2544 | exit 2 |
| 2545 | end |
| 2546 | if lt ee tl |
| 2547 | exit 2 |
| 2548 | end |
| 2549 | if gt ee cl |
| 2550 | exit 2 |
| 2551 | end |
| 2552 | if gt es ee |
| 2553 | exit 2 |
| 2554 | end |
| 2555 | if gt gn 2000 |
| 2556 | exit 2 |
| 2557 | end |
| 2558 | end |
| 2559 | |
| 2560 | fn osp_clip_store_br s ulong es ulong nact ulong gn ulong to void |
| 2561 | tl = get ocl_st 3 |
| 2562 | wn = mul nact get og 32 |
| 2563 | oc = get ocl_st 8 |
| 2564 | d = get og 2 |
| 2565 | if gt add oc add wn d ocsinit |
| 2566 | exit 12 |
| 2567 | end |
| 2568 | if gt nact 0 |
| 2569 | fzt = get ocl_st 4 |
| 2570 | if gt es tl |
| 2571 | osp_clip_shift fzt add fzt mul sub es tl get og 32 wn |
| 2572 | end |
| 2573 | if ne gn 1000 |
| 2574 | osp_sclays tl nact div f64 gn 1000.0 |
| 2575 | end |
| 2576 | osp_w2c oc fzt wn |
| 2577 | end |
| 2578 | for g3 ulong d |
| 2579 | ocsp add add oc wn g3 get odl1 g3 |
| 2580 | end |
| 2581 | put ocl_sl s add tl nact |
| 2582 | put ocl_wo s oc |
| 2583 | put ocl_wn s wn |
| 2584 | put ocl_st 8 add oc add wn d |
| 2585 | end |
| 2586 | |
| 2587 | note Verify & store strand s's spliced active layer weights + gf into ocs |
| 2588 | fn osp_clip_strand s ulong to void |
| 2589 | tl = get ocl_st 3 |
| 2590 | cl = osp_clip_load_raw s |
| 2591 | put ocl_raw_sl s cl |
| 2592 | es = get ocl_sp_s s |
| 2593 | ee = get ocl_sp_e s |
| 2594 | if and eq es 0 eq ee 0 |
| 2595 | es = tl |
| 2596 | ee = cl |
| 2597 | else |
| 2598 | if eq es OSP_SP_AUTO |
| 2599 | es = tl |
| 2600 | put ocl_sp_s s tl |
| 2601 | end |
| 2602 | if or eq es 0 eq ee 0 |
| 2603 | exit 2 |
| 2604 | end |
| 2605 | end |
| 2606 | gn = get ocl_sp_g s |
| 2607 | osp_clip_chk_sp tl cl es ee gn |
| 2608 | osp_clip_store_br s es sub ee es gn |
| 2609 | end |
| 2610 | |
| 2611 | note Initialize spclip: verify/capture hashes, load BASE.ck, common trunk, grow to max_L, store all S strand suffixes in ocs |
| 2612 | fn osp_clip_init to void |
| 2613 | c = ocsinit |
| 2614 | osp_clip_hash_pass |
| 2615 | ockloop get ocl_cfg 1 |
| 2616 | bh = osp_basehash get og 5 get og 33 |
| 2617 | put ocl_st 2 get og 5 |
| 2618 | put ocl_st 11 bh |
| 2619 | put ocl_exp 12 get og 33 |
| 2620 | if eq get ocl_cfg 3 1 |
| 2621 | if or ne get og 5 get ocl_exp 0 ne bh get ocl_exp 1 |
| 2622 | exit 62 |
| 2623 | end |
| 2624 | end |
| 2625 | osp_clip_trunk |
| 2626 | ml = osp_clip_maxl |
| 2627 | addl = get ocl_cfg 5 |
| 2628 | ml_alloc = add ml addl |
| 2629 | if gt ml_alloc 24 |
| 2630 | exit 12 |
| 2631 | end |
| 2632 | put ocl_st 5 ml |
| 2633 | if gt ml_alloc get ocl_st 3 |
| 2634 | ogrowsnap get og 8 |
| 2635 | put og 5 ml_alloc |
| 2636 | if not ogeom |
| 2637 | exit 12 |
| 2638 | end |
| 2639 | ogrowcopy get ocl_st 4 |
| 2640 | end |
| 2641 | td = mul get og 1 get og 2 |
| 2642 | put ocl_st 7 0 |
| 2643 | put ocl_st 9 td |
| 2644 | put ocl_st 8 add td mul get ocl_st 1 get og 0 |
| 2645 | for s ulong get ocl_st 1 |
| 2646 | osp_clip_strand s |
| 2647 | end |
| 2648 | end |
| 2649 | |
| 2650 | note Compute log_softmax of TMP[0..V) into ocs[logp_off + s*V .. +V) and Shannon entropy into ocl_ent[s] |
| 2651 | fn osp_clip_lsm s ulong to void |
| 2652 | pr = get og 27 |
| 2653 | v = get og 0 |
| 2654 | m = bitcast f64 ulong 18442240474082181120 |
| 2655 | for j ulong v |
| 2656 | x = get oa add pr j |
| 2657 | m = fmax m x |
| 2658 | put odl1 j x |
| 2659 | end |
| 2660 | sm = osoft pr v m |
| 2661 | lsm = flog sm |
| 2662 | dst = add get ocl_st 9 mul s v |
| 2663 | ent = 0.0f64 |
| 2664 | for j2 ulong v |
| 2665 | lp = sub sub get odl1 j2 m lsm |
| 2666 | ocsp add dst j2 lp |
| 2667 | pj = get oa add pr j2 |
| 2668 | if gt pj 0.0 |
| 2669 | ent = sub ent mul pj lp |
| 2670 | end |
| 2671 | end |
| 2672 | if lt ent 0.0 |
| 2673 | ent = 0.0f64 |
| 2674 | end |
| 2675 | put ocl_ent s ent |
| 2676 | end |
| 2677 | |
| 2678 | note Final norm + klogit on row nc-1 of osp_hout(ocl_sl[s]), then log_softmax + entropy |
| 2679 | fn osp_clip_head s ulong nc ulong to void |
| 2680 | d = get og 2 |
| 2681 | nc1 = sub nc 1 |
| 2682 | r = mul nc1 d |
| 2683 | z = add get og 17 r |
| 2684 | hf = add osp_hout get ocl_sl s r |
| 2685 | s0 = add get og 16 nc1 |
| 2686 | frms hf get og 33 z s0 |
| 2687 | klogit z get og 27 get og 0 d |
| 2688 | osp_clip_lsm s |
| 2689 | end |
| 2690 | |
| 2691 | note Run strand s from cached H_trunk through layers trunk_L..L_s-1 and head |
| 2692 | fn osp_clip_br s ulong nc ulong to void |
| 2693 | tl = get ocl_st 3 |
| 2694 | sl = get ocl_sl s |
| 2695 | wo = get ocl_wo s |
| 2696 | wn = get ocl_wn s |
| 2697 | if gt wn 0 |
| 2698 | osp_c2wb get ocl_st 4 wo wn |
| 2699 | end |
| 2700 | osp_c2wb get og 33 add wo wn get og 2 |
| 2701 | osp_hrest osp_hout tl get ocl_st 7 mul nc get og 2 |
| 2702 | put og 9 nc |
| 2703 | put okv 0 0 |
| 2704 | put ogkm 1 0 |
| 2705 | ta = osp_app tl |
| 2706 | for k ulong sub sl tl |
| 2707 | olayf add ta k |
| 2708 | end |
| 2709 | osp_clip_head s nc |
| 2710 | end |
| 2711 | |
| 2712 | note Compute stabilized entropy-gated unnormalized weights for MODE=1 with tau != 1.0 |
| 2713 | fn osp_clip_wt_tau ss ulong tau f64 to f64 |
| 2714 | lmin = bitcast f64 ulong 9218868437227405312 |
| 2715 | for s0 ulong ss |
| 2716 | if gt get ocl_w s0 0.0 |
| 2717 | ls0 = flog add get ocl_ent s0 0.001 |
| 2718 | if lt ls0 lmin |
| 2719 | lmin = ls0 |
| 2720 | end |
| 2721 | end |
| 2722 | end |
| 2723 | su = 0.0f64 |
| 2724 | for s ulong ss |
| 2725 | u = get ocl_w s |
| 2726 | if gt u 0.0 |
| 2727 | ls = flog add get ocl_ent s 0.001 |
| 2728 | u = mul u fexp div sub lmin ls tau |
| 2729 | end |
| 2730 | put ocl_al s u |
| 2731 | if gt u 0.0 |
| 2732 | su = add su u |
| 2733 | end |
| 2734 | end |
| 2735 | ret su |
| 2736 | end |
| 2737 | |
| 2738 | note Compute normalized fusion weights ocl_al[0..S) using MODE=0/1 and tau_milli |
| 2739 | fn osp_clip_calc_al to void |
| 2740 | md = get ocl_st 0 |
| 2741 | ss = get ocl_st 1 |
| 2742 | tm = get ocl_cfg 0 |
| 2743 | if eq tm 0 |
| 2744 | tm = ulong 1000 |
| 2745 | end |
| 2746 | su = 0.0f64 |
| 2747 | if and eq md 1 ne tm 1000 |
| 2748 | su = osp_clip_wt_tau ss div f64 tm 1000.0 |
| 2749 | else |
| 2750 | for s ulong ss |
| 2751 | u = get ocl_w s |
| 2752 | if and eq md 1 gt u 0.0 |
| 2753 | u = div u add get ocl_ent s 0.001 |
| 2754 | end |
| 2755 | put ocl_al s u |
| 2756 | if gt u 0.0 |
| 2757 | su = add su u |
| 2758 | end |
| 2759 | end |
| 2760 | end |
| 2761 | for s2 ulong ss |
| 2762 | put ocl_al s2 div get ocl_al s2 su |
| 2763 | end |
| 2764 | end |
| 2765 | |
| 2766 | fn osp_clip_fuse_v j ulong ss ulong v ulong lo ulong to f64 |
| 2767 | acc = 0.0f64 |
| 2768 | for s3 ulong ss |
| 2769 | acc = add acc mul get ocl_al s3 ocsg add lo add mul s3 v j |
| 2770 | end |
| 2771 | ret acc |
| 2772 | end |
| 2773 | |
| 2774 | note Fuse S strands' log-probs in ocs into TMP[0..V) using MODE=0 (signed PoE) or MODE=1 (entropy-gated) + tau |
| 2775 | fn osp_clip_fuse to void |
| 2776 | osp_clip_calc_al |
| 2777 | sc_on = and eq get ocl_st 0 0 and ne get ocl_cfg 0 0 ne get ocl_cfg 0 1000 |
| 2778 | tau = div f64 get ocl_cfg 0 1000.0 |
| 2779 | pr = get og 27 |
| 2780 | v = get og 0 |
| 2781 | for j ulong v |
| 2782 | acc = osp_clip_fuse_v j get ocl_st 1 v get ocl_st 9 |
| 2783 | if sc_on |
| 2784 | acc = div acc tau |
| 2785 | end |
| 2786 | put oa add pr j acc |
| 2787 | end |
| 2788 | end |
| 2789 | |
| 2790 | note Jensen-Shannon Disagreement H(pbar) - mean(H(ps)) across positive-weight strands (ocl_w[s] > 0) |
| 2791 | fn osp_jsd_pbar j ulong np ulong lo ulong v ulong to f64 |
| 2792 | sm = 0.0f64 |
| 2793 | for s ulong get ocl_st 1 |
| 2794 | if gt get ocl_w s 0.0 |
| 2795 | sm = add sm fexp ocsg add lo add mul s v j |
| 2796 | end |
| 2797 | end |
| 2798 | ret div sm f64 np |
| 2799 | end |
| 2800 | |
| 2801 | fn osp_clip_jsd to f64 |
| 2802 | ss = get ocl_st 1 |
| 2803 | np = ulong 0 |
| 2804 | hmean = 0.0f64 |
| 2805 | for s ulong ss |
| 2806 | if gt get ocl_w s 0.0 |
| 2807 | np = add np 1 |
| 2808 | hmean = add hmean get ocl_ent s |
| 2809 | end |
| 2810 | end |
| 2811 | if lt np 2 |
| 2812 | put ocl_st 10 0 |
| 2813 | ret 0.0f64 |
| 2814 | end |
| 2815 | hmean = div hmean f64 np |
| 2816 | lo = get ocl_st 9 |
| 2817 | v = get og 0 |
| 2818 | hbar = 0.0f64 |
| 2819 | for j ulong v |
| 2820 | pb = osp_jsd_pbar j np lo v |
| 2821 | if gt pb 1.0e-15f64 |
| 2822 | hbar = sub hbar mul pb flog pb |
| 2823 | end |
| 2824 | end |
| 2825 | jsd = sub hbar hmean |
| 2826 | if lt jsd 0.0 |
| 2827 | jsd = 0.0f64 |
| 2828 | end |
| 2829 | jm = ulong add mul jsd 1000.0 0.5 |
| 2830 | put ocl_st 10 jm |
| 2831 | ret jsd |
| 2832 | end |
| 2833 | |
| 2834 | note Run one extra refinement pass over trunk layers [c0 .. ta-1] on row nc-1 when strands disagree |
| 2835 | fn osp_guard_c0 ta ulong tl ulong to ulong |
| 2836 | np = get og 59 |
| 2837 | lc = add get og 57 get og 58 |
| 2838 | if and gt np 1 le lc tl |
| 2839 | ret get og 57 |
| 2840 | end |
| 2841 | ret sub ta 1 |
| 2842 | end |
| 2843 | |
| 2844 | fn osp_guard_pass nc ulong tl ulong to void |
| 2845 | d = get og 2 |
| 2846 | r = mul sub nc 1 d |
| 2847 | ta = osp_app tl |
| 2848 | last_a = sub ta 1 |
| 2849 | c0 = osp_guard_c0 ta tl |
| 2850 | onlcopy_oa add oahin c0 r add oaout last_a r d |
| 2851 | for k ulong sub ta c0 |
| 2852 | l = add c0 k |
| 2853 | okvlay l sub nc 1 1 |
| 2854 | if lt add l 1 ta |
| 2855 | onlcopy_oa add oahin add l 1 r add oaout l r d |
| 2856 | end |
| 2857 | end |
| 2858 | onlcopy_oa add osp_hout tl r add oaout last_a r d |
| 2859 | end |
| 2860 | |
| 2861 | fn osp_guard_rcpt_init to void |
| 2862 | h = ulong 14695981039346656037 |
| 2863 | h = osp_mix64 h get ocl_st 11 |
| 2864 | for s ulong get ocl_st 1 |
| 2865 | h = osp_mix64 h bitcast ulong get ocl_wm s |
| 2866 | h = osp_mix64 h get ocl_ph s |
| 2867 | end |
| 2868 | put ocl_st 12 h |
| 2869 | end |
| 2870 | |
| 2871 | fn osp_guard_rcpt_step g ulong c ulong to ulong |
| 2872 | h = get ocl_st 12 |
| 2873 | h = osp_mix64 h g |
| 2874 | h = osp_mix64 h c |
| 2875 | h = osp_mix64 h get ocl_st 10 |
| 2876 | h = osp_mix64 h get ocl_st 16 |
| 2877 | h = osp_mix64 h get ocl_st 17 |
| 2878 | h = osp_mix64 h get ocl_st 13 |
| 2879 | put ocl_st 12 h |
| 2880 | ret h |
| 2881 | end |
| 2882 | |
| 2883 | fn osp_guard_emit step ulong tok ulong to void |
| 2884 | oputc 71 |
| 2885 | oputc 32 |
| 2886 | oputu step |
| 2887 | oputc 32 |
| 2888 | oputu tok |
| 2889 | oputc 32 |
| 2890 | oputu get ocl_st 10 |
| 2891 | oputc 32 |
| 2892 | oputu get ocl_st 16 |
| 2893 | oputc 32 |
| 2894 | oputu get ocl_st 17 |
| 2895 | oputc 32 |
| 2896 | oputu get ocl_st 13 |
| 2897 | oputc 32 |
| 2898 | oputx get ocl_st 12 |
| 2899 | oputc 10 |
| 2900 | oflush |
| 2901 | end |
| 2902 | |
| 2903 | fn osp_guard_eval nc ulong tl ulong to f64 |
| 2904 | osp_hsnap get ocl_st 7 osp_hout tl mul nc get og 2 |
| 2905 | for s ulong get ocl_st 1 |
| 2906 | osp_clip_br s nc |
| 2907 | end |
| 2908 | ret osp_clip_jsd |
| 2909 | end |
| 2910 | |
| 2911 | fn osp_guard_refine nc ulong tl ulong to void |
| 2912 | ex = ulong 0 |
| 2913 | mxex = get ocl_st 15 |
| 2914 | thresh = div f64 get ocl_st 14 1000.0 |
| 2915 | while lt ex mxex bound 8 |
| 2916 | ex = add ex 1 |
| 2917 | osp_guard_pass nc tl |
| 2918 | if lt osp_guard_eval nc tl thresh |
| 2919 | break |
| 2920 | end |
| 2921 | end |
| 2922 | put ocl_st 16 ex |
| 2923 | end |
| 2924 | |
| 2925 | fn osp_guard_step st ulong tm ulong to ulong |
| 2926 | nc = get og 9 |
| 2927 | tl = get ocl_st 3 |
| 2928 | put okv 0 0 |
| 2929 | put ogkm 1 0 |
| 2930 | oemb 0 |
| 2931 | for l ulong osp_app tl |
| 2932 | olayf l |
| 2933 | end |
| 2934 | put ocl_st 16 0 |
| 2935 | put ocl_st 17 0 |
| 2936 | thresh = div f64 get ocl_st 14 1000.0 |
| 2937 | if ge osp_guard_eval nc tl thresh |
| 2938 | put ocl_st 17 1 |
| 2939 | osp_guard_refine nc tl |
| 2940 | end |
| 2941 | osp_clip_fuse |
| 2942 | if eq tm 0 |
| 2943 | ret oargmax |
| 2944 | end |
| 2945 | ret odraw st div f64 tm 1000.0 |
| 2946 | end |
| 2947 | |
| 2948 | fn osp_guard_run nn ulong st ulong tm ulong to void |
| 2949 | con_tot = ulong 0 |
| 2950 | ex_tot = ulong 0 |
| 2951 | drawn = ulong 0 |
| 2952 | for g ulong nn |
| 2953 | c = osp_guard_step st tm |
| 2954 | if ne tm 0 |
| 2955 | st = add st 11400714819323198485 |
| 2956 | end |
| 2957 | if eq c 0 |
| 2958 | break |
| 2959 | end |
| 2960 | con_tot = add con_tot get ocl_st 17 |
| 2961 | ex_tot = add ex_tot get ocl_st 16 |
| 2962 | rcpt = osp_guard_rcpt_step g c |
| 2963 | osp_guard_emit g c |
| 2964 | drawn = add drawn 1 |
| 2965 | ocpush c |
| 2966 | end |
| 2967 | oputc 71 |
| 2968 | oputc 82 |
| 2969 | oputc 32 |
| 2970 | oputu drawn |
| 2971 | oputc 32 |
| 2972 | oputu con_tot |
| 2973 | oputc 32 |
| 2974 | oputu ex_tot |
| 2975 | oputc 32 |
| 2976 | oputu get ocl_st 13 |
| 2977 | oputc 32 |
| 2978 | oputx get ocl_st 11 |
| 2979 | oputc 32 |
| 2980 | oputx get ocl_st 12 |
| 2981 | oputc 10 |
| 2982 | oflush |
| 2983 | end |
| 2984 | |
| 2985 | note spguard BASE.ck DISAGREE_MILLI MAX_EXTRA PROMPT N TEMPMILLI SEED MERGES S W1 K1 A1..AK1 ... |
| 2986 | fn cmdspguard to void |
| 2987 | osp_clip_defaults |
| 2988 | dm = oargu 3 |
| 2989 | mx = oargu 4 |
| 2990 | if gt mx 4 |
| 2991 | exit 2 |
| 2992 | end |
| 2993 | nn = oargu 6 |
| 2994 | if or eq nn 0 gt nn 999999 |
| 2995 | exit 2 |
| 2996 | end |
| 2997 | tm = oargu 7 |
| 2998 | sd = oargu 8 |
| 2999 | osp_clip_parse_at 0 10 |
| 3000 | put ocl_st 14 dm |
| 3001 | put ocl_st 15 mx |
| 3002 | osp_clip_init |
| 3003 | v = get og 0 |
| 3004 | if gt v 256 |
| 3005 | obload 9 v |
| 3006 | end |
| 3007 | osp_prompt 5 v |
| 3008 | osp_guard_rcpt_init |
| 3009 | osp_guard_run nn sd tm |
| 3010 | end |
| 3011 | |
| 3012 | note One DNA-clipped decode step: shared trunk ONCE, then S strands over H_trunk, fused into TMP |
| 3013 | fn osp_clip_step st ulong tm ulong to ulong |
| 3014 | nc = get og 9 |
| 3015 | tl = get ocl_st 3 |
| 3016 | put okv 0 0 |
| 3017 | put ogkm 1 0 |
| 3018 | oemb 0 |
| 3019 | ta = osp_app tl |
| 3020 | for l ulong ta |
| 3021 | olayf l |
| 3022 | end |
| 3023 | osp_hsnap get ocl_st 7 osp_hout tl mul nc get og 2 |
| 3024 | for s ulong get ocl_st 1 |
| 3025 | osp_clip_br s nc |
| 3026 | end |
| 3027 | osp_clip_fuse |
| 3028 | if eq tm 0 |
| 3029 | ret oargmax |
| 3030 | end |
| 3031 | ret odraw st div f64 tm 1000.0 |
| 3032 | end |
| 3033 | |
| 3034 | fn osp_clip_loop nn ulong st ulong tm ulong to void |
| 3035 | v = get og 0 |
| 3036 | for g ulong nn |
| 3037 | c = osp_clip_step st tm |
| 3038 | if ne tm 0 |
| 3039 | st = add st 11400714819323198485 |
| 3040 | end |
| 3041 | if eq c 0 |
| 3042 | break |
| 3043 | end |
| 3044 | if gt v 256 |
| 3045 | obtput c |
| 3046 | else |
| 3047 | oputc c |
| 3048 | end |
| 3049 | oflush |
| 3050 | ocpush c |
| 3051 | end |
| 3052 | oflush |
| 3053 | end |
| 3054 | |
| 3055 | note ---- 11. Canonical .spclip Recipe & OLLMSPLIN01 Lineage Buffer Helpers ---- |
| 3056 | fn osr_reset to void |
| 3057 | put ocl_rlen 0 0 |
| 3058 | end |
| 3059 | |
| 3060 | fn osr_putc c ulong to void |
| 3061 | p = get ocl_rlen 0 |
| 3062 | if ge p 65536 |
| 3063 | exit 60 |
| 3064 | end |
| 3065 | put ocl_rec p uchar and c 255 |
| 3066 | put ocl_rlen 0 add p 1 |
| 3067 | end |
| 3068 | |
| 3069 | fn osr_putu v ulong to void |
| 3070 | d = new uchar 24 0 |
| 3071 | n = ulong 0 |
| 3072 | x = v |
| 3073 | while true bound 21 |
| 3074 | put d n uchar add rem x 10 48 |
| 3075 | n = add n 1 |
| 3076 | x = div x 10 |
| 3077 | if eq x 0 |
| 3078 | break |
| 3079 | end |
| 3080 | end |
| 3081 | for i ulong n |
| 3082 | osr_putc ulong get d sub sub n 1 i |
| 3083 | end |
| 3084 | end |
| 3085 | |
| 3086 | fn osr_putl v long to void |
| 3087 | if lt v 0 |
| 3088 | osr_putc 45 |
| 3089 | if eq v -9223372036854775808 |
| 3090 | osr_putu 9223372036854775808 |
| 3091 | else |
| 3092 | osr_putu ulong neg v |
| 3093 | end |
| 3094 | else |
| 3095 | osr_putu ulong v |
| 3096 | end |
| 3097 | end |
| 3098 | |
| 3099 | fn osr_putx64 v ulong to void |
| 3100 | for i ulong 16 |
| 3101 | h = and shr v mul sub 15 i 4 15 |
| 3102 | if lt h 10 |
| 3103 | osr_putc add h 48 |
| 3104 | else |
| 3105 | osr_putc add h 87 |
| 3106 | end |
| 3107 | end |
| 3108 | end |
| 3109 | |
| 3110 | fn osr_putsha_d to void |
| 3111 | for i ulong 32 |
| 3112 | b = ulong get osha_d i |
| 3113 | hi = shr b 4 |
| 3114 | lo = and b 15 |
| 3115 | if lt hi 10 |
| 3116 | osr_putc add hi 48 |
| 3117 | else |
| 3118 | osr_putc add hi 87 |
| 3119 | end |
| 3120 | if lt lo 10 |
| 3121 | osr_putc add lo 48 |
| 3122 | else |
| 3123 | osr_putc add lo 87 |
| 3124 | end |
| 3125 | end |
| 3126 | end |
| 3127 | |
| 3128 | fn osr_putslot sl ulong to void |
| 3129 | n = ovp_len sl |
| 3130 | if eq n 0 |
| 3131 | exit 60 |
| 3132 | end |
| 3133 | for i ulong n |
| 3134 | osr_putc ulong ovp_getb sl i |
| 3135 | end |
| 3136 | end |
| 3137 | |
| 3138 | fn osr_putkw kw ulong to void |
| 3139 | if eq kw 0 |
| 3140 | for i ulong len ot_rec_mag |
| 3141 | osr_putc ulong get ot_rec_mag i |
| 3142 | end |
| 3143 | ret |
| 3144 | end |
| 3145 | if eq kw 1 |
| 3146 | for i ulong len ot_lin_mag |
| 3147 | osr_putc ulong get ot_lin_mag i |
| 3148 | end |
| 3149 | ret |
| 3150 | end |
| 3151 | if eq kw 2 |
| 3152 | for i ulong len ot_k_base |
| 3153 | osr_putc ulong get ot_k_base i |
| 3154 | end |
| 3155 | ret |
| 3156 | end |
| 3157 | if eq kw 3 |
| 3158 | for i ulong len ot_k_bsha |
| 3159 | osr_putc ulong get ot_k_bsha i |
| 3160 | end |
| 3161 | ret |
| 3162 | end |
| 3163 | if eq kw 4 |
| 3164 | for i ulong len ot_k_bl |
| 3165 | osr_putc ulong get ot_k_bl i |
| 3166 | end |
| 3167 | ret |
| 3168 | end |
| 3169 | if eq kw 5 |
| 3170 | for i ulong len ot_k_bh |
| 3171 | osr_putc ulong get ot_k_bh i |
| 3172 | end |
| 3173 | ret |
| 3174 | end |
| 3175 | if eq kw 6 |
| 3176 | for i ulong len ot_k_mode |
| 3177 | osr_putc ulong get ot_k_mode i |
| 3178 | end |
| 3179 | ret |
| 3180 | end |
| 3181 | if eq kw 7 |
| 3182 | for i ulong len ot_k_tau |
| 3183 | osr_putc ulong get ot_k_tau i |
| 3184 | end |
| 3185 | ret |
| 3186 | end |
| 3187 | if eq kw 8 |
| 3188 | for i ulong len ot_k_strs |
| 3189 | osr_putc ulong get ot_k_strs i |
| 3190 | end |
| 3191 | ret |
| 3192 | end |
| 3193 | if eq kw 9 |
| 3194 | for i ulong len ot_k_str |
| 3195 | osr_putc ulong get ot_k_str i |
| 3196 | end |
| 3197 | ret |
| 3198 | end |
| 3199 | if eq kw 10 |
| 3200 | for i ulong len ot_k_wt |
| 3201 | osr_putc ulong get ot_k_wt i |
| 3202 | end |
| 3203 | ret |
| 3204 | end |
| 3205 | if eq kw 11 |
| 3206 | for i ulong len ot_k_spl |
| 3207 | osr_putc ulong get ot_k_spl i |
| 3208 | end |
| 3209 | ret |
| 3210 | end |
| 3211 | if eq kw 12 |
| 3212 | for i ulong len ot_k_lnks |
| 3213 | osr_putc ulong get ot_k_lnks i |
| 3214 | end |
| 3215 | ret |
| 3216 | end |
| 3217 | if eq kw 13 |
| 3218 | for i ulong len ot_k_lnk |
| 3219 | osr_putc ulong get ot_k_lnk i |
| 3220 | end |
| 3221 | ret |
| 3222 | end |
| 3223 | if eq kw 14 |
| 3224 | for i ulong len ot_k_rsha |
| 3225 | osr_putc ulong get ot_k_rsha i |
| 3226 | end |
| 3227 | ret |
| 3228 | end |
| 3229 | if eq kw 15 |
| 3230 | for i ulong len ot_k_alm |
| 3231 | osr_putc ulong get ot_k_alm i |
| 3232 | end |
| 3233 | ret |
| 3234 | end |
| 3235 | if eq kw 16 |
| 3236 | for i ulong len ot_k_chld |
| 3237 | osr_putc ulong get ot_k_chld i |
| 3238 | end |
| 3239 | ret |
| 3240 | end |
| 3241 | if eq kw 17 |
| 3242 | for i ulong len ot_k_csha |
| 3243 | osr_putc ulong get ot_k_csha i |
| 3244 | end |
| 3245 | ret |
| 3246 | end |
| 3247 | if eq kw 18 |
| 3248 | for i ulong len ot_k_cbl |
| 3249 | osr_putc ulong get ot_k_cbl i |
| 3250 | end |
| 3251 | ret |
| 3252 | end |
| 3253 | if eq kw 19 |
| 3254 | for i ulong len ot_k_csl |
| 3255 | osr_putc ulong get ot_k_csl i |
| 3256 | end |
| 3257 | ret |
| 3258 | end |
| 3259 | if eq kw 20 |
| 3260 | for i ulong len ot_k_cbh |
| 3261 | osr_putc ulong get ot_k_cbh i |
| 3262 | end |
| 3263 | ret |
| 3264 | end |
| 3265 | if eq kw 21 |
| 3266 | for i ulong len ot_k_cph |
| 3267 | osr_putc ulong get ot_k_cph i |
| 3268 | end |
| 3269 | ret |
| 3270 | end |
| 3271 | if eq kw 22 |
| 3272 | for i ulong len ot_k_cns |
| 3273 | osr_putc ulong get ot_k_cns i |
| 3274 | end |
| 3275 | ret |
| 3276 | end |
| 3277 | if eq kw 23 |
| 3278 | for i ulong len ot_k_tl |
| 3279 | osr_putc ulong get ot_k_tl i |
| 3280 | end |
| 3281 | ret |
| 3282 | end |
| 3283 | if eq kw 24 |
| 3284 | for i ulong len ot_k_prsh |
| 3285 | osr_putc ulong get ot_k_prsh i |
| 3286 | end |
| 3287 | ret |
| 3288 | end |
| 3289 | if eq kw 25 |
| 3290 | for i ulong len ot_k_dsha |
| 3291 | osr_putc ulong get ot_k_dsha i |
| 3292 | end |
| 3293 | ret |
| 3294 | end |
| 3295 | if eq kw 26 |
| 3296 | for i ulong len ot_k_stp |
| 3297 | osr_putc ulong get ot_k_stp i |
| 3298 | end |
| 3299 | ret |
| 3300 | end |
| 3301 | if eq kw 27 |
| 3302 | for i ulong len ot_k_lrm |
| 3303 | osr_putc ulong get ot_k_lrm i |
| 3304 | end |
| 3305 | ret |
| 3306 | end |
| 3307 | if eq kw 28 |
| 3308 | for i ulong len ot_k_bat |
| 3309 | osr_putc ulong get ot_k_bat i |
| 3310 | end |
| 3311 | ret |
| 3312 | end |
| 3313 | if eq kw 29 |
| 3314 | for i ulong len ot_k_ls0 |
| 3315 | osr_putc ulong get ot_k_ls0 i |
| 3316 | end |
| 3317 | ret |
| 3318 | end |
| 3319 | if eq kw 30 |
| 3320 | for i ulong len ot_k_ls1 |
| 3321 | osr_putc ulong get ot_k_ls1 i |
| 3322 | end |
| 3323 | ret |
| 3324 | end |
| 3325 | if eq kw 31 |
| 3326 | for i ulong len ot_k_lsha |
| 3327 | osr_putc ulong get ot_k_lsha i |
| 3328 | end |
| 3329 | end |
| 3330 | end |
| 3331 | |
| 3332 | fn osr_flush_file dst_ai ulong to void |
| 3333 | n = get ocl_rlen 0 |
| 3334 | for i ulong n |
| 3335 | put ock i get ocl_rec i |
| 3336 | end |
| 3337 | ocwopen dst_ai |
| 3338 | ocwput 0 n |
| 3339 | ocwend dst_ai |
| 3340 | end |
| 3341 | |
| 3342 | fn osr_read_file src_ai ulong to void |
| 3343 | sz = ofsz src_ai |
| 3344 | if or eq sz 0 gt sz 65536 |
| 3345 | exit 60 |
| 3346 | end |
| 3347 | if ne oprd src_ai 0 0 sz sz |
| 3348 | exit 60 |
| 3349 | end |
| 3350 | for i ulong sz |
| 3351 | put ocl_rec i get opw i |
| 3352 | end |
| 3353 | put ocl_rlen 0 sz |
| 3354 | put ocl_rcur 0 0 |
| 3355 | end |
| 3356 | |
| 3357 | fn osr_hexnib c ulong to ulong |
| 3358 | if and ge c 48 le c 57 |
| 3359 | ret sub c 48 |
| 3360 | end |
| 3361 | if and ge c 97 le c 102 |
| 3362 | ret add 10 sub c 97 |
| 3363 | end |
| 3364 | ret 255 |
| 3365 | end |
| 3366 | |
| 3367 | fn osr_eat_byte b ulong to void |
| 3368 | p = get ocl_rcur 0 |
| 3369 | if ge p get ocl_rlen 0 |
| 3370 | exit 60 |
| 3371 | end |
| 3372 | if ne ulong get ocl_rec p b |
| 3373 | exit 60 |
| 3374 | end |
| 3375 | put ocl_rcur 0 add p 1 |
| 3376 | end |
| 3377 | |
| 3378 | fn osr_eat_kw kw ulong to void |
| 3379 | p = get ocl_rcur 0 |
| 3380 | n = get ocl_rlen 0 |
| 3381 | if eq kw 0 |
| 3382 | if gt add p len ot_rec_mag n |
| 3383 | exit 60 |
| 3384 | end |
| 3385 | for i ulong len ot_rec_mag |
| 3386 | if ne get ocl_rec add p i get ot_rec_mag i |
| 3387 | exit 60 |
| 3388 | end |
| 3389 | end |
| 3390 | put ocl_rcur 0 add p len ot_rec_mag |
| 3391 | ret |
| 3392 | end |
| 3393 | if eq kw 1 |
| 3394 | if gt add p len ot_lin_mag n |
| 3395 | exit 60 |
| 3396 | end |
| 3397 | for i ulong len ot_lin_mag |
| 3398 | if ne get ocl_rec add p i get ot_lin_mag i |
| 3399 | exit 60 |
| 3400 | end |
| 3401 | end |
| 3402 | put ocl_rcur 0 add p len ot_lin_mag |
| 3403 | ret |
| 3404 | end |
| 3405 | if eq kw 2 |
| 3406 | if gt add p len ot_k_base n |
| 3407 | exit 60 |
| 3408 | end |
| 3409 | for i ulong len ot_k_base |
| 3410 | if ne get ocl_rec add p i get ot_k_base i |
| 3411 | exit 60 |
| 3412 | end |
| 3413 | end |
| 3414 | put ocl_rcur 0 add p len ot_k_base |
| 3415 | ret |
| 3416 | end |
| 3417 | if eq kw 3 |
| 3418 | if gt add p len ot_k_bsha n |
| 3419 | exit 60 |
| 3420 | end |
| 3421 | for i ulong len ot_k_bsha |
| 3422 | if ne get ocl_rec add p i get ot_k_bsha i |
| 3423 | exit 60 |
| 3424 | end |
| 3425 | end |
| 3426 | put ocl_rcur 0 add p len ot_k_bsha |
| 3427 | ret |
| 3428 | end |
| 3429 | if eq kw 4 |
| 3430 | if gt add p len ot_k_bl n |
| 3431 | exit 60 |
| 3432 | end |
| 3433 | for i ulong len ot_k_bl |
| 3434 | if ne get ocl_rec add p i get ot_k_bl i |
| 3435 | exit 60 |
| 3436 | end |
| 3437 | end |
| 3438 | put ocl_rcur 0 add p len ot_k_bl |
| 3439 | ret |
| 3440 | end |
| 3441 | if eq kw 5 |
| 3442 | if gt add p len ot_k_bh n |
| 3443 | exit 60 |
| 3444 | end |
| 3445 | for i ulong len ot_k_bh |
| 3446 | if ne get ocl_rec add p i get ot_k_bh i |
| 3447 | exit 60 |
| 3448 | end |
| 3449 | end |
| 3450 | put ocl_rcur 0 add p len ot_k_bh |
| 3451 | ret |
| 3452 | end |
| 3453 | if eq kw 6 |
| 3454 | if gt add p len ot_k_mode n |
| 3455 | exit 60 |
| 3456 | end |
| 3457 | for i ulong len ot_k_mode |
| 3458 | if ne get ocl_rec add p i get ot_k_mode i |
| 3459 | exit 60 |
| 3460 | end |
| 3461 | end |
| 3462 | put ocl_rcur 0 add p len ot_k_mode |
| 3463 | ret |
| 3464 | end |
| 3465 | if eq kw 7 |
| 3466 | if gt add p len ot_k_tau n |
| 3467 | exit 60 |
| 3468 | end |
| 3469 | for i ulong len ot_k_tau |
| 3470 | if ne get ocl_rec add p i get ot_k_tau i |
| 3471 | exit 60 |
| 3472 | end |
| 3473 | end |
| 3474 | put ocl_rcur 0 add p len ot_k_tau |
| 3475 | ret |
| 3476 | end |
| 3477 | if eq kw 8 |
| 3478 | if gt add p len ot_k_strs n |
| 3479 | exit 60 |
| 3480 | end |
| 3481 | for i ulong len ot_k_strs |
| 3482 | if ne get ocl_rec add p i get ot_k_strs i |
| 3483 | exit 60 |
| 3484 | end |
| 3485 | end |
| 3486 | put ocl_rcur 0 add p len ot_k_strs |
| 3487 | ret |
| 3488 | end |
| 3489 | if eq kw 9 |
| 3490 | if gt add p len ot_k_str n |
| 3491 | exit 60 |
| 3492 | end |
| 3493 | for i ulong len ot_k_str |
| 3494 | if ne get ocl_rec add p i get ot_k_str i |
| 3495 | exit 60 |
| 3496 | end |
| 3497 | end |
| 3498 | put ocl_rcur 0 add p len ot_k_str |
| 3499 | ret |
| 3500 | end |
| 3501 | if eq kw 10 |
| 3502 | if gt add p len ot_k_wt n |
| 3503 | exit 60 |
| 3504 | end |
| 3505 | for i ulong len ot_k_wt |
| 3506 | if ne get ocl_rec add p i get ot_k_wt i |
| 3507 | exit 60 |
| 3508 | end |
| 3509 | end |
| 3510 | put ocl_rcur 0 add p len ot_k_wt |
| 3511 | ret |
| 3512 | end |
| 3513 | if eq kw 11 |
| 3514 | if gt add p len ot_k_spl n |
| 3515 | exit 60 |
| 3516 | end |
| 3517 | for i ulong len ot_k_spl |
| 3518 | if ne get ocl_rec add p i get ot_k_spl i |
| 3519 | exit 60 |
| 3520 | end |
| 3521 | end |
| 3522 | put ocl_rcur 0 add p len ot_k_spl |
| 3523 | ret |
| 3524 | end |
| 3525 | if eq kw 12 |
| 3526 | if gt add p len ot_k_lnks n |
| 3527 | exit 60 |
| 3528 | end |
| 3529 | for i ulong len ot_k_lnks |
| 3530 | if ne get ocl_rec add p i get ot_k_lnks i |
| 3531 | exit 60 |
| 3532 | end |
| 3533 | end |
| 3534 | put ocl_rcur 0 add p len ot_k_lnks |
| 3535 | ret |
| 3536 | end |
| 3537 | if eq kw 13 |
| 3538 | if gt add p len ot_k_lnk n |
| 3539 | exit 60 |
| 3540 | end |
| 3541 | for i ulong len ot_k_lnk |
| 3542 | if ne get ocl_rec add p i get ot_k_lnk i |
| 3543 | exit 60 |
| 3544 | end |
| 3545 | end |
| 3546 | put ocl_rcur 0 add p len ot_k_lnk |
| 3547 | ret |
| 3548 | end |
| 3549 | if eq kw 14 |
| 3550 | if gt add p len ot_k_rsha n |
| 3551 | exit 60 |
| 3552 | end |
| 3553 | for i ulong len ot_k_rsha |
| 3554 | if ne get ocl_rec add p i get ot_k_rsha i |
| 3555 | exit 60 |
| 3556 | end |
| 3557 | end |
| 3558 | put ocl_rcur 0 add p len ot_k_rsha |
| 3559 | ret |
| 3560 | end |
| 3561 | if eq kw 15 |
| 3562 | if gt add p len ot_k_alm n |
| 3563 | exit 60 |
| 3564 | end |
| 3565 | for i ulong len ot_k_alm |
| 3566 | if ne get ocl_rec add p i get ot_k_alm i |
| 3567 | exit 60 |
| 3568 | end |
| 3569 | end |
| 3570 | put ocl_rcur 0 add p len ot_k_alm |
| 3571 | ret |
| 3572 | end |
| 3573 | osr_eat_kw2 kw |
| 3574 | end |
| 3575 | |
| 3576 | fn osr_eat_kw2 kw ulong to void |
| 3577 | p = get ocl_rcur 0 |
| 3578 | n = get ocl_rlen 0 |
| 3579 | if eq kw 16 |
| 3580 | if gt add p len ot_k_chld n |
| 3581 | exit 60 |
| 3582 | end |
| 3583 | for i ulong len ot_k_chld |
| 3584 | if ne get ocl_rec add p i get ot_k_chld i |
| 3585 | exit 60 |
| 3586 | end |
| 3587 | end |
| 3588 | put ocl_rcur 0 add p len ot_k_chld |
| 3589 | ret |
| 3590 | end |
| 3591 | if eq kw 17 |
| 3592 | if gt add p len ot_k_csha n |
| 3593 | exit 60 |
| 3594 | end |
| 3595 | for i ulong len ot_k_csha |
| 3596 | if ne get ocl_rec add p i get ot_k_csha i |
| 3597 | exit 60 |
| 3598 | end |
| 3599 | end |
| 3600 | put ocl_rcur 0 add p len ot_k_csha |
| 3601 | ret |
| 3602 | end |
| 3603 | if eq kw 18 |
| 3604 | if gt add p len ot_k_cbl n |
| 3605 | exit 60 |
| 3606 | end |
| 3607 | for i ulong len ot_k_cbl |
| 3608 | if ne get ocl_rec add p i get ot_k_cbl i |
| 3609 | exit 60 |
| 3610 | end |
| 3611 | end |
| 3612 | put ocl_rcur 0 add p len ot_k_cbl |
| 3613 | ret |
| 3614 | end |
| 3615 | if eq kw 19 |
| 3616 | if gt add p len ot_k_csl n |
| 3617 | exit 60 |
| 3618 | end |
| 3619 | for i ulong len ot_k_csl |
| 3620 | if ne get ocl_rec add p i get ot_k_csl i |
| 3621 | exit 60 |
| 3622 | end |
| 3623 | end |
| 3624 | put ocl_rcur 0 add p len ot_k_csl |
| 3625 | ret |
| 3626 | end |
| 3627 | if eq kw 20 |
| 3628 | if gt add p len ot_k_cbh n |
| 3629 | exit 60 |
| 3630 | end |
| 3631 | for i ulong len ot_k_cbh |
| 3632 | if ne get ocl_rec add p i get ot_k_cbh i |
| 3633 | exit 60 |
| 3634 | end |
| 3635 | end |
| 3636 | put ocl_rcur 0 add p len ot_k_cbh |
| 3637 | ret |
| 3638 | end |
| 3639 | if eq kw 21 |
| 3640 | if gt add p len ot_k_cph n |
| 3641 | exit 60 |
| 3642 | end |
| 3643 | for i ulong len ot_k_cph |
| 3644 | if ne get ocl_rec add p i get ot_k_cph i |
| 3645 | exit 60 |
| 3646 | end |
| 3647 | end |
| 3648 | put ocl_rcur 0 add p len ot_k_cph |
| 3649 | ret |
| 3650 | end |
| 3651 | if eq kw 22 |
| 3652 | if gt add p len ot_k_cns n |
| 3653 | exit 60 |
| 3654 | end |
| 3655 | for i ulong len ot_k_cns |
| 3656 | if ne get ocl_rec add p i get ot_k_cns i |
| 3657 | exit 60 |
| 3658 | end |
| 3659 | end |
| 3660 | put ocl_rcur 0 add p len ot_k_cns |
| 3661 | ret |
| 3662 | end |
| 3663 | if eq kw 23 |
| 3664 | if gt add p len ot_k_tl n |
| 3665 | exit 60 |
| 3666 | end |
| 3667 | for i ulong len ot_k_tl |
| 3668 | if ne get ocl_rec add p i get ot_k_tl i |
| 3669 | exit 60 |
| 3670 | end |
| 3671 | end |
| 3672 | put ocl_rcur 0 add p len ot_k_tl |
| 3673 | ret |
| 3674 | end |
| 3675 | if eq kw 24 |
| 3676 | if gt add p len ot_k_prsh n |
| 3677 | exit 60 |
| 3678 | end |
| 3679 | for i ulong len ot_k_prsh |
| 3680 | if ne get ocl_rec add p i get ot_k_prsh i |
| 3681 | exit 60 |
| 3682 | end |
| 3683 | end |
| 3684 | put ocl_rcur 0 add p len ot_k_prsh |
| 3685 | ret |
| 3686 | end |
| 3687 | if eq kw 25 |
| 3688 | if gt add p len ot_k_dsha n |
| 3689 | exit 60 |
| 3690 | end |
| 3691 | for i ulong len ot_k_dsha |
| 3692 | if ne get ocl_rec add p i get ot_k_dsha i |
| 3693 | exit 60 |
| 3694 | end |
| 3695 | end |
| 3696 | put ocl_rcur 0 add p len ot_k_dsha |
| 3697 | ret |
| 3698 | end |
| 3699 | if eq kw 26 |
| 3700 | if gt add p len ot_k_stp n |
| 3701 | exit 60 |
| 3702 | end |
| 3703 | for i ulong len ot_k_stp |
| 3704 | if ne get ocl_rec add p i get ot_k_stp i |
| 3705 | exit 60 |
| 3706 | end |
| 3707 | end |
| 3708 | put ocl_rcur 0 add p len ot_k_stp |
| 3709 | ret |
| 3710 | end |
| 3711 | if eq kw 27 |
| 3712 | if gt add p len ot_k_lrm n |
| 3713 | exit 60 |
| 3714 | end |
| 3715 | for i ulong len ot_k_lrm |
| 3716 | if ne get ocl_rec add p i get ot_k_lrm i |
| 3717 | exit 60 |
| 3718 | end |
| 3719 | end |
| 3720 | put ocl_rcur 0 add p len ot_k_lrm |
| 3721 | ret |
| 3722 | end |
| 3723 | if eq kw 28 |
| 3724 | if gt add p len ot_k_bat n |
| 3725 | exit 60 |
| 3726 | end |
| 3727 | for i ulong len ot_k_bat |
| 3728 | if ne get ocl_rec add p i get ot_k_bat i |
| 3729 | exit 60 |
| 3730 | end |
| 3731 | end |
| 3732 | put ocl_rcur 0 add p len ot_k_bat |
| 3733 | ret |
| 3734 | end |
| 3735 | if eq kw 29 |
| 3736 | if gt add p len ot_k_ls0 n |
| 3737 | exit 60 |
| 3738 | end |
| 3739 | for i ulong len ot_k_ls0 |
| 3740 | if ne get ocl_rec add p i get ot_k_ls0 i |
| 3741 | exit 60 |
| 3742 | end |
| 3743 | end |
| 3744 | put ocl_rcur 0 add p len ot_k_ls0 |
| 3745 | ret |
| 3746 | end |
| 3747 | if eq kw 30 |
| 3748 | if gt add p len ot_k_ls1 n |
| 3749 | exit 60 |
| 3750 | end |
| 3751 | for i ulong len ot_k_ls1 |
| 3752 | if ne get ocl_rec add p i get ot_k_ls1 i |
| 3753 | exit 60 |
| 3754 | end |
| 3755 | end |
| 3756 | put ocl_rcur 0 add p len ot_k_ls1 |
| 3757 | ret |
| 3758 | end |
| 3759 | if eq kw 31 |
| 3760 | if gt add p len ot_k_lsha n |
| 3761 | exit 60 |
| 3762 | end |
| 3763 | for i ulong len ot_k_lsha |
| 3764 | if ne get ocl_rec add p i get ot_k_lsha i |
| 3765 | exit 60 |
| 3766 | end |
| 3767 | end |
| 3768 | put ocl_rcur 0 add p len ot_k_lsha |
| 3769 | ret |
| 3770 | end |
| 3771 | exit 60 |
| 3772 | end |
| 3773 | |
| 3774 | fn osr_rd_u delim ulong to ulong |
| 3775 | p = get ocl_rcur 0 |
| 3776 | n = get ocl_rlen 0 |
| 3777 | v = ulong 0 |
| 3778 | d = ulong 0 |
| 3779 | while lt p n bound 32 |
| 3780 | c = ulong get ocl_rec p |
| 3781 | if eq c delim |
| 3782 | break |
| 3783 | end |
| 3784 | if or lt c 48 gt c 57 |
| 3785 | exit 60 |
| 3786 | end |
| 3787 | if ge d 19 |
| 3788 | exit 60 |
| 3789 | end |
| 3790 | v = add mul v 10 sub c 48 |
| 3791 | d = add d 1 |
| 3792 | p = add p 1 |
| 3793 | end |
| 3794 | if or eq d 0 ge p n |
| 3795 | exit 60 |
| 3796 | end |
| 3797 | if ne ulong get ocl_rec p delim |
| 3798 | exit 60 |
| 3799 | end |
| 3800 | put ocl_rcur 0 add p 1 |
| 3801 | ret v |
| 3802 | end |
| 3803 | |
| 3804 | fn osr_rd_l delim ulong to long |
| 3805 | p = get ocl_rcur 0 |
| 3806 | n = get ocl_rlen 0 |
| 3807 | if ge p n |
| 3808 | exit 60 |
| 3809 | end |
| 3810 | negf = ulong 0 |
| 3811 | if eq ulong get ocl_rec p 45 |
| 3812 | negf = ulong 1 |
| 3813 | p = add p 1 |
| 3814 | put ocl_rcur 0 p |
| 3815 | end |
| 3816 | v = osr_rd_u delim |
| 3817 | if eq negf 1 |
| 3818 | if gt v 9223372036854775807 |
| 3819 | exit 60 |
| 3820 | end |
| 3821 | ret neg long v |
| 3822 | end |
| 3823 | if gt v 9223372036854775807 |
| 3824 | exit 60 |
| 3825 | end |
| 3826 | ret long v |
| 3827 | end |
| 3828 | |
| 3829 | fn osr_rd_x64 delim ulong to ulong |
| 3830 | p = get ocl_rcur 0 |
| 3831 | if gt add p 17 get ocl_rlen 0 |
| 3832 | exit 60 |
| 3833 | end |
| 3834 | v = ulong 0 |
| 3835 | for i ulong 16 |
| 3836 | h = osr_hexnib ulong get ocl_rec add p i |
| 3837 | if gt h 15 |
| 3838 | exit 60 |
| 3839 | end |
| 3840 | v = or shl v 4 h |
| 3841 | end |
| 3842 | if ne ulong get ocl_rec add p 16 delim |
| 3843 | exit 60 |
| 3844 | end |
| 3845 | put ocl_rcur 0 add p 17 |
| 3846 | ret v |
| 3847 | end |
| 3848 | |
| 3849 | fn osr_rd_sha_d delim ulong to void |
| 3850 | p = get ocl_rcur 0 |
| 3851 | if gt add p 65 get ocl_rlen 0 |
| 3852 | exit 60 |
| 3853 | end |
| 3854 | for i ulong 32 |
| 3855 | hi = osr_hexnib ulong get ocl_rec add p mul i 2 |
| 3856 | lo = osr_hexnib ulong get ocl_rec add p add mul i 2 1 |
| 3857 | if or gt hi 15 gt lo 15 |
| 3858 | exit 60 |
| 3859 | end |
| 3860 | put osha_d i uchar or shl hi 4 lo |
| 3861 | end |
| 3862 | if ne ulong get ocl_rec add p 64 delim |
| 3863 | exit 60 |
| 3864 | end |
| 3865 | put ocl_rcur 0 add p 65 |
| 3866 | end |
| 3867 | |
| 3868 | fn osr_rd_path sl ulong delim ulong to ulong |
| 3869 | p = get ocl_rcur 0 |
| 3870 | n = get ocl_rlen 0 |
| 3871 | k = ulong 0 |
| 3872 | while lt p n bound 1025 |
| 3873 | c = ulong get ocl_rec p |
| 3874 | if eq c delim |
| 3875 | break |
| 3876 | end |
| 3877 | if or lt c 33 gt c 126 |
| 3878 | exit 60 |
| 3879 | end |
| 3880 | if ge k OVARG_STR |
| 3881 | exit 60 |
| 3882 | end |
| 3883 | ovp_putb sl k uchar c |
| 3884 | k = add k 1 |
| 3885 | p = add p 1 |
| 3886 | end |
| 3887 | if or eq k 0 ge p n |
| 3888 | exit 60 |
| 3889 | end |
| 3890 | if ne ulong get ocl_rec p delim |
| 3891 | exit 60 |
| 3892 | end |
| 3893 | ovp_setlen sl k |
| 3894 | put ocl_rcur 0 add p 1 |
| 3895 | ret add OVARG_BASE sl |
| 3896 | end |
| 3897 | |
| 3898 | note Write canonical OLLMSPCLIP01 recipe to dst_ai and store recipe_sha256 in ocl_rsha |
| 3899 | fn osp_rec_write dst_ai ulong to void |
| 3900 | osr_reset |
| 3901 | osr_putkw 0 |
| 3902 | osr_putkw 2 |
| 3903 | osr_putslot 0 |
| 3904 | osr_putc 10 |
| 3905 | osr_putkw 3 |
| 3906 | for i ulong 32 |
| 3907 | put osha_d i get ocl_bsha i |
| 3908 | end |
| 3909 | osr_putsha_d |
| 3910 | osr_putc 10 |
| 3911 | osr_putkw 4 |
| 3912 | osr_putu get ocl_st 2 |
| 3913 | osr_putc 10 |
| 3914 | osr_putkw 5 |
| 3915 | osr_putx64 get ocl_st 11 |
| 3916 | osr_putc 10 |
| 3917 | osr_putkw 6 |
| 3918 | osr_putu get ocl_st 0 |
| 3919 | osr_putc 10 |
| 3920 | osr_putkw 7 |
| 3921 | osr_putu get ocl_cfg 0 |
| 3922 | osr_putc 10 |
| 3923 | osr_putkw 8 |
| 3924 | osr_putu get ocl_st 1 |
| 3925 | osr_putc 10 |
| 3926 | ss = get ocl_st 1 |
| 3927 | for s ulong ss |
| 3928 | osr_putkw 9 |
| 3929 | osr_putu s |
| 3930 | osr_putc 32 |
| 3931 | osr_putkw 10 |
| 3932 | osr_putl get ocl_wm s |
| 3933 | osr_putc 32 |
| 3934 | osr_putkw 11 |
| 3935 | osr_putu get ocl_sp_s s |
| 3936 | osr_putc 58 |
| 3937 | osr_putu get ocl_sp_e s |
| 3938 | osr_putc 58 |
| 3939 | osr_putu get ocl_sp_g s |
| 3940 | osr_putc 32 |
| 3941 | osr_putkw 12 |
| 3942 | osr_putu get ocl_k s |
| 3943 | osr_putc 10 |
| 3944 | for j ulong get ocl_k s |
| 3945 | idx = add mul s 8 j |
| 3946 | osr_putkw 13 |
| 3947 | osr_putu s |
| 3948 | osr_putc 32 |
| 3949 | osr_putu j |
| 3950 | osr_putc 32 |
| 3951 | osr_putslot add 1 idx |
| 3952 | osr_putc 32 |
| 3953 | bo = mul idx 32 |
| 3954 | for b ulong 32 |
| 3955 | put osha_d b get ocl_lsha add bo b |
| 3956 | end |
| 3957 | osr_putsha_d |
| 3958 | osr_putc 32 |
| 3959 | osr_putx64 get ocl_lph idx |
| 3960 | osr_putc 10 |
| 3961 | end |
| 3962 | end |
| 3963 | osha_buf_ocl get ocl_rlen 0 |
| 3964 | osha_save_rsha |
| 3965 | osr_putkw 14 |
| 3966 | osr_putsha_d |
| 3967 | osr_putc 10 |
| 3968 | osr_flush_file dst_ai |
| 3969 | end |
| 3970 | |
| 3971 | fn osp_rec_rd_strand s ulong to void |
| 3972 | osr_eat_kw 9 |
| 3973 | if ne osr_rd_u 32 s |
| 3974 | exit 60 |
| 3975 | end |
| 3976 | osr_eat_kw 10 |
| 3977 | put ocl_wm s osr_rd_l 32 |
| 3978 | osr_eat_kw 11 |
| 3979 | sps = osr_rd_u 58 |
| 3980 | spe = osr_rd_u 58 |
| 3981 | spg = osr_rd_u 32 |
| 3982 | if or gt sps 24 gt spe 24 |
| 3983 | exit 60 |
| 3984 | end |
| 3985 | if or and eq sps 0 ne spe 0 and ne sps 0 eq spe 0 |
| 3986 | exit 60 |
| 3987 | end |
| 3988 | put ocl_sp_s s sps |
| 3989 | put ocl_sp_e s spe |
| 3990 | put ocl_sp_g s spg |
| 3991 | osr_eat_kw 12 |
| 3992 | ks = osr_rd_u 10 |
| 3993 | if or eq ks 0 gt ks 8 |
| 3994 | exit 60 |
| 3995 | end |
| 3996 | put ocl_k s ks |
| 3997 | for j ulong ks |
| 3998 | osr_eat_kw 13 |
| 3999 | if ne osr_rd_u 32 s |
| 4000 | exit 60 |
| 4001 | end |
| 4002 | if ne osr_rd_u 32 j |
| 4003 | exit 60 |
| 4004 | end |
| 4005 | idx = add mul s 8 j |
| 4006 | ai = osr_rd_path add 1 idx 32 |
| 4007 | put ocl_link idx ai |
| 4008 | osr_rd_sha_d 32 |
| 4009 | osha_save_lsha idx |
| 4010 | put ocl_lph idx osr_rd_x64 10 |
| 4011 | end |
| 4012 | end |
| 4013 | |
| 4014 | note Load and strictly verify OLLMSPCLIP01 recipe from rec_ai (exits 60 malformed, 61 tampered hash, 2 bad knobs) |
| 4015 | fn osp_rec_load rec_ai ulong to void |
| 4016 | osp_clip_defaults |
| 4017 | osr_read_file rec_ai |
| 4018 | osr_eat_kw 0 |
| 4019 | osr_eat_kw 2 |
| 4020 | put ocl_cfg 1 osr_rd_path 0 10 |
| 4021 | osr_eat_kw 3 |
| 4022 | osr_rd_sha_d 10 |
| 4023 | osha_save_bsha |
| 4024 | osr_eat_kw 4 |
| 4025 | put ocl_exp 0 osr_rd_u 10 |
| 4026 | osr_eat_kw 5 |
| 4027 | put ocl_exp 1 osr_rd_x64 10 |
| 4028 | osr_eat_kw 6 |
| 4029 | put ocl_st 0 osr_rd_u 10 |
| 4030 | osr_eat_kw 7 |
| 4031 | put ocl_cfg 0 osr_rd_u 10 |
| 4032 | osr_eat_kw 8 |
| 4033 | ss = osr_rd_u 10 |
| 4034 | if or lt ss 2 gt ss 4 |
| 4035 | exit 60 |
| 4036 | end |
| 4037 | put ocl_st 1 ss |
| 4038 | for s ulong ss |
| 4039 | osp_rec_rd_strand s |
| 4040 | end |
| 4041 | seal_end = get ocl_rcur 0 |
| 4042 | osr_eat_kw 14 |
| 4043 | osr_rd_sha_d 10 |
| 4044 | osha_save_rsha |
| 4045 | if ne get ocl_rcur 0 get ocl_rlen 0 |
| 4046 | exit 60 |
| 4047 | end |
| 4048 | osha_buf_ocl seal_end |
| 4049 | if not osha_eq_rsha |
| 4050 | exit 61 |
| 4051 | end |
| 4052 | put ocl_cfg 2 1 |
| 4053 | put ocl_cfg 3 1 |
| 4054 | osp_clip_validate_knobs |
| 4055 | end |
| 4056 | |
| 4057 | note ---- 12. CLI Subcommand & Dynamic Flag Parsing Helpers ---- |
| 4058 | fn osp_arg_eq_sub ai ulong kind ulong to bool |
| 4059 | r = oargr ai |
| 4060 | if le r 0 |
| 4061 | ret false |
| 4062 | end |
| 4063 | n = ulong r |
| 4064 | if eq kind 0 |
| 4065 | if ne n len ot_sub_cr |
| 4066 | ret false |
| 4067 | end |
| 4068 | for i ulong n |
| 4069 | if ne get oarg i get ot_sub_cr i |
| 4070 | ret false |
| 4071 | end |
| 4072 | end |
| 4073 | ret true |
| 4074 | end |
| 4075 | if eq kind 1 |
| 4076 | if ne n len ot_sub_ed |
| 4077 | ret false |
| 4078 | end |
| 4079 | for i ulong n |
| 4080 | if ne get oarg i get ot_sub_ed i |
| 4081 | ret false |
| 4082 | end |
| 4083 | end |
| 4084 | ret true |
| 4085 | end |
| 4086 | if eq kind 2 |
| 4087 | if ne n len ot_sub_vr |
| 4088 | ret false |
| 4089 | end |
| 4090 | for i ulong n |
| 4091 | if ne get oarg i get ot_sub_vr i |
| 4092 | ret false |
| 4093 | end |
| 4094 | end |
| 4095 | ret true |
| 4096 | end |
| 4097 | if eq kind 3 |
| 4098 | if ne n len ot_sub_in |
| 4099 | ret false |
| 4100 | end |
| 4101 | for i ulong n |
| 4102 | if ne get oarg i get ot_sub_in i |
| 4103 | ret false |
| 4104 | end |
| 4105 | end |
| 4106 | ret true |
| 4107 | end |
| 4108 | if eq kind 4 |
| 4109 | if ne n len ot_sub_rn |
| 4110 | ret false |
| 4111 | end |
| 4112 | for i ulong n |
| 4113 | if ne get oarg i get ot_sub_rn i |
| 4114 | ret false |
| 4115 | end |
| 4116 | end |
| 4117 | ret true |
| 4118 | end |
| 4119 | if eq kind 5 |
| 4120 | if ne n len ot_sub_ev |
| 4121 | ret false |
| 4122 | end |
| 4123 | for i ulong n |
| 4124 | if ne get oarg i get ot_sub_ev i |
| 4125 | ret false |
| 4126 | end |
| 4127 | end |
| 4128 | ret true |
| 4129 | end |
| 4130 | if eq kind 6 |
| 4131 | if ne n len ot_sub_tn |
| 4132 | ret false |
| 4133 | end |
| 4134 | for i ulong n |
| 4135 | if ne get oarg i get ot_sub_tn i |
| 4136 | ret false |
| 4137 | end |
| 4138 | end |
| 4139 | ret true |
| 4140 | end |
| 4141 | if eq kind 7 |
| 4142 | if ne n len ot_sub_vl |
| 4143 | ret false |
| 4144 | end |
| 4145 | for i ulong n |
| 4146 | if ne get oarg i get ot_sub_vl i |
| 4147 | ret false |
| 4148 | end |
| 4149 | end |
| 4150 | ret true |
| 4151 | end |
| 4152 | ret false |
| 4153 | end |
| 4154 | |
| 4155 | fn osp_arg_eq_fl ai ulong kind ulong to bool |
| 4156 | r = oargr ai |
| 4157 | if le r 0 |
| 4158 | ret false |
| 4159 | end |
| 4160 | n = ulong r |
| 4161 | if eq kind 0 |
| 4162 | if ne n len ot_fl_str |
| 4163 | ret false |
| 4164 | end |
| 4165 | for i ulong n |
| 4166 | if ne get oarg i get ot_fl_str i |
| 4167 | ret false |
| 4168 | end |
| 4169 | end |
| 4170 | ret true |
| 4171 | end |
| 4172 | if eq kind 1 |
| 4173 | if ne n len ot_fl_wts |
| 4174 | ret false |
| 4175 | end |
| 4176 | for i ulong n |
| 4177 | if ne get oarg i get ot_fl_wts i |
| 4178 | ret false |
| 4179 | end |
| 4180 | end |
| 4181 | ret true |
| 4182 | end |
| 4183 | if eq kind 2 |
| 4184 | if ne n len ot_fl_sw |
| 4185 | ret false |
| 4186 | end |
| 4187 | for i ulong n |
| 4188 | if ne get oarg i get ot_fl_sw i |
| 4189 | ret false |
| 4190 | end |
| 4191 | end |
| 4192 | ret true |
| 4193 | end |
| 4194 | if eq kind 3 |
| 4195 | if ne n len ot_fl_mod |
| 4196 | ret false |
| 4197 | end |
| 4198 | for i ulong n |
| 4199 | if ne get oarg i get ot_fl_mod i |
| 4200 | ret false |
| 4201 | end |
| 4202 | end |
| 4203 | ret true |
| 4204 | end |
| 4205 | if eq kind 4 |
| 4206 | if ne n len ot_fl_tau |
| 4207 | ret false |
| 4208 | end |
| 4209 | for i ulong n |
| 4210 | if ne get oarg i get ot_fl_tau i |
| 4211 | ret false |
| 4212 | end |
| 4213 | end |
| 4214 | ret true |
| 4215 | end |
| 4216 | if eq kind 5 |
| 4217 | if ne n len ot_fl_spl |
| 4218 | ret false |
| 4219 | end |
| 4220 | for i ulong n |
| 4221 | if ne get oarg i get ot_fl_spl i |
| 4222 | ret false |
| 4223 | end |
| 4224 | end |
| 4225 | ret true |
| 4226 | end |
| 4227 | if eq kind 6 |
| 4228 | if ne n len ot_fl_ss |
| 4229 | ret false |
| 4230 | end |
| 4231 | for i ulong n |
| 4232 | if ne get oarg i get ot_fl_ss i |
| 4233 | ret false |
| 4234 | end |
| 4235 | end |
| 4236 | ret true |
| 4237 | end |
| 4238 | if eq kind 7 |
| 4239 | if ne n len ot_fl_out |
| 4240 | ret false |
| 4241 | end |
| 4242 | for i ulong n |
| 4243 | if ne get oarg i get ot_fl_out i |
| 4244 | ret false |
| 4245 | end |
| 4246 | end |
| 4247 | ret true |
| 4248 | end |
| 4249 | if eq kind 8 |
| 4250 | if ne n len ot_fl_bat |
| 4251 | ret false |
| 4252 | end |
| 4253 | for i ulong n |
| 4254 | if ne get oarg i get ot_fl_bat i |
| 4255 | ret false |
| 4256 | end |
| 4257 | end |
| 4258 | ret true |
| 4259 | end |
| 4260 | if eq kind 9 |
| 4261 | if ne n len ot_fl_add |
| 4262 | ret false |
| 4263 | end |
| 4264 | for i ulong n |
| 4265 | if ne get oarg i get ot_fl_add i |
| 4266 | ret false |
| 4267 | end |
| 4268 | end |
| 4269 | ret true |
| 4270 | end |
| 4271 | if eq kind 10 |
| 4272 | if ne n len ot_fl_trl |
| 4273 | ret false |
| 4274 | end |
| 4275 | for i ulong n |
| 4276 | if ne get oarg i get ot_fl_trl i |
| 4277 | ret false |
| 4278 | end |
| 4279 | end |
| 4280 | ret true |
| 4281 | end |
| 4282 | if eq kind 11 |
| 4283 | if ne n len ot_fl_lin |
| 4284 | ret false |
| 4285 | end |
| 4286 | for i ulong n |
| 4287 | if ne get oarg i get ot_fl_lin i |
| 4288 | ret false |
| 4289 | end |
| 4290 | end |
| 4291 | ret true |
| 4292 | end |
| 4293 | if eq kind 12 |
| 4294 | if ne n len ot_fl_nln |
| 4295 | ret false |
| 4296 | end |
| 4297 | for i ulong n |
| 4298 | if ne get oarg i get ot_fl_nln i |
| 4299 | ret false |
| 4300 | end |
| 4301 | end |
| 4302 | ret true |
| 4303 | end |
| 4304 | ret false |
| 4305 | end |
| 4306 | |
| 4307 | note Parse comma-separated signed weights W1,W2[,W3[,W4]] into ocl_wm[0..S) |
| 4308 | fn osp_parse_weights ai ulong to void |
| 4309 | n = oargp ai |
| 4310 | if gt n 128 |
| 4311 | exit 2 |
| 4312 | end |
| 4313 | ss = get ocl_st 1 |
| 4314 | p = ulong 0 |
| 4315 | cnt = ulong 0 |
| 4316 | while lt p n bound 128 |
| 4317 | if ge cnt ss |
| 4318 | exit 2 |
| 4319 | end |
| 4320 | negf = ulong 0 |
| 4321 | if eq ulong get oarg p 45 |
| 4322 | negf = ulong 1 |
| 4323 | p = add p 1 |
| 4324 | end |
| 4325 | v = ulong 0 |
| 4326 | d = ulong 0 |
| 4327 | while lt p n bound 32 |
| 4328 | c = ulong get oarg p |
| 4329 | if eq c 44 |
| 4330 | break |
| 4331 | end |
| 4332 | if or lt c 48 gt c 57 |
| 4333 | exit 2 |
| 4334 | end |
| 4335 | if ge d 10 |
| 4336 | exit 2 |
| 4337 | end |
| 4338 | v = add mul v 10 sub c 48 |
| 4339 | d = add d 1 |
| 4340 | p = add p 1 |
| 4341 | end |
| 4342 | if eq d 0 |
| 4343 | exit 2 |
| 4344 | end |
| 4345 | w = long v |
| 4346 | if eq negf 1 |
| 4347 | w = neg long v |
| 4348 | end |
| 4349 | put ocl_wm cnt w |
| 4350 | cnt = add cnt 1 |
| 4351 | if lt p n |
| 4352 | p = add p 1 |
| 4353 | if eq p n |
| 4354 | exit 2 |
| 4355 | end |
| 4356 | end |
| 4357 | end |
| 4358 | if ne cnt ss |
| 4359 | exit 2 |
| 4360 | end |
| 4361 | end |
| 4362 | |
| 4363 | note Parse unsigned decimal from oarg[p..end) stopping at colon or end; returns new p via ocl_rcur[0] |
| 4364 | fn osp_oarg_u p ulong lim ulong to ulong |
| 4365 | v = ulong 0 |
| 4366 | d = ulong 0 |
| 4367 | while lt p lim bound 32 |
| 4368 | c = ulong get oarg p |
| 4369 | if eq c 58 |
| 4370 | break |
| 4371 | end |
| 4372 | if or lt c 48 gt c 57 |
| 4373 | exit 2 |
| 4374 | end |
| 4375 | if ge d 10 |
| 4376 | exit 2 |
| 4377 | end |
| 4378 | v = add mul v 10 sub c 48 |
| 4379 | d = add d 1 |
| 4380 | p = add p 1 |
| 4381 | end |
| 4382 | if eq d 0 |
| 4383 | exit 2 |
| 4384 | end |
| 4385 | put ocl_rcur 0 p |
| 4386 | ret v |
| 4387 | end |
| 4388 | |
| 4389 | fn osp_is_kw_all lo ulong to bool |
| 4390 | if ne ulong get oarg lo 97 |
| 4391 | ret false |
| 4392 | end |
| 4393 | if ne ulong get oarg add lo 1 108 |
| 4394 | ret false |
| 4395 | end |
| 4396 | ret eq ulong get oarg add lo 2 108 |
| 4397 | end |
| 4398 | |
| 4399 | note Parse one splice spec from oarg[lo..hi) into ocl_sp_s/e/g[s]: "all" | END | START:END | START:END:SCALE |
| 4400 | fn osp_parse_1splice lo ulong hi ulong s ulong to void |
| 4401 | ln = sub hi lo |
| 4402 | if eq ln 0 |
| 4403 | exit 2 |
| 4404 | end |
| 4405 | if eq ln 3 |
| 4406 | if osp_is_kw_all lo |
| 4407 | put ocl_sp_s s 0 |
| 4408 | put ocl_sp_e s 0 |
| 4409 | put ocl_sp_g s 1000 |
| 4410 | ret |
| 4411 | end |
| 4412 | end |
| 4413 | v1 = osp_oarg_u lo hi |
| 4414 | if or eq v1 0 gt v1 24 |
| 4415 | exit 2 |
| 4416 | end |
| 4417 | p = get ocl_rcur 0 |
| 4418 | if eq p hi |
| 4419 | put ocl_sp_s s OSP_SP_AUTO |
| 4420 | put ocl_sp_e s v1 |
| 4421 | put ocl_sp_g s 1000 |
| 4422 | ret |
| 4423 | end |
| 4424 | if ne ulong get oarg p 58 |
| 4425 | exit 2 |
| 4426 | end |
| 4427 | v2 = osp_oarg_u add p 1 hi |
| 4428 | if or eq v2 0 gt v2 24 |
| 4429 | exit 2 |
| 4430 | end |
| 4431 | p = get ocl_rcur 0 |
| 4432 | if eq p hi |
| 4433 | put ocl_sp_s s v1 |
| 4434 | put ocl_sp_e s v2 |
| 4435 | put ocl_sp_g s 1000 |
| 4436 | ret |
| 4437 | end |
| 4438 | if ne ulong get oarg p 58 |
| 4439 | exit 2 |
| 4440 | end |
| 4441 | v3 = osp_oarg_u add p 1 hi |
| 4442 | if ne get ocl_rcur 0 hi |
| 4443 | exit 2 |
| 4444 | end |
| 4445 | put ocl_sp_s s v1 |
| 4446 | put ocl_sp_e s v2 |
| 4447 | put ocl_sp_g s v3 |
| 4448 | end |
| 4449 | |
| 4450 | fn osp_parse_splice_list ai ulong to void |
| 4451 | n = oargp ai |
| 4452 | if gt n 128 |
| 4453 | exit 2 |
| 4454 | end |
| 4455 | ss = get ocl_st 1 |
| 4456 | p = ulong 0 |
| 4457 | cnt = ulong 0 |
| 4458 | while lt p n bound 128 |
| 4459 | if ge cnt ss |
| 4460 | exit 2 |
| 4461 | end |
| 4462 | lo = p |
| 4463 | while lt p n bound 128 |
| 4464 | if eq ulong get oarg p 44 |
| 4465 | break |
| 4466 | end |
| 4467 | p = add p 1 |
| 4468 | end |
| 4469 | osp_parse_1splice lo p cnt |
| 4470 | cnt = add cnt 1 |
| 4471 | if lt p n |
| 4472 | p = add p 1 |
| 4473 | if eq p n |
| 4474 | exit 2 |
| 4475 | end |
| 4476 | end |
| 4477 | end |
| 4478 | if ne cnt ss |
| 4479 | exit 2 |
| 4480 | end |
| 4481 | end |
| 4482 | |
| 4483 | note Parse --strand P1.sp[,P2.sp,...] from argv[ai] into strand s links |
| 4484 | fn osp_parse_strand_arg ai ulong s ulong to void |
| 4485 | n = oargp ai |
| 4486 | p = ulong 0 |
| 4487 | j = ulong 0 |
| 4488 | while lt p n bound 16 |
| 4489 | if ge j 8 |
| 4490 | exit 2 |
| 4491 | end |
| 4492 | sl = add 1 add mul s 8 j |
| 4493 | k = ulong 0 |
| 4494 | while lt p n bound 1025 |
| 4495 | c = ulong get oarg p |
| 4496 | if eq c 44 |
| 4497 | break |
| 4498 | end |
| 4499 | if or lt c 33 gt c 126 |
| 4500 | exit 2 |
| 4501 | end |
| 4502 | if ge k OVARG_STR |
| 4503 | exit 2 |
| 4504 | end |
| 4505 | ovp_putb sl k uchar c |
| 4506 | k = add k 1 |
| 4507 | p = add p 1 |
| 4508 | end |
| 4509 | if eq k 0 |
| 4510 | exit 2 |
| 4511 | end |
| 4512 | ovp_setlen sl k |
| 4513 | put ocl_link add mul s 8 j add OVARG_BASE sl |
| 4514 | j = add j 1 |
| 4515 | if lt p n |
| 4516 | p = add p 1 |
| 4517 | if eq p n |
| 4518 | exit 2 |
| 4519 | end |
| 4520 | end |
| 4521 | end |
| 4522 | if eq j 0 |
| 4523 | exit 2 |
| 4524 | end |
| 4525 | put ocl_k s j |
| 4526 | end |
| 4527 | |
| 4528 | note Parse dynamic clip override flags starting at argv[a0] (allow_edit: 1=edit flags, 2=tune flags, 0=run/eval/create) |
| 4529 | fn osp_parse_dyn_flags a0 ulong allow ulong to void |
| 4530 | na = oargc |
| 4531 | if gt sub na a0 64 |
| 4532 | exit 2 |
| 4533 | end |
| 4534 | i = a0 |
| 4535 | while lt i na bound 64 |
| 4536 | if osp_arg_eq_fl i 1 |
| 4537 | if ge add i 1 na |
| 4538 | exit 2 |
| 4539 | end |
| 4540 | osp_parse_weights add i 1 |
| 4541 | i = add i 2 |
| 4542 | continue |
| 4543 | end |
| 4544 | if osp_arg_eq_fl i 2 |
| 4545 | if ge add i 2 na |
| 4546 | exit 2 |
| 4547 | end |
| 4548 | si = oargu add i 1 |
| 4549 | if ge si get ocl_st 1 |
| 4550 | exit 2 |
| 4551 | end |
| 4552 | put ocl_wm si oargs add i 2 |
| 4553 | i = add i 3 |
| 4554 | continue |
| 4555 | end |
| 4556 | if osp_arg_eq_fl i 3 |
| 4557 | if ge add i 1 na |
| 4558 | exit 2 |
| 4559 | end |
| 4560 | put ocl_st 0 oargu add i 1 |
| 4561 | i = add i 2 |
| 4562 | continue |
| 4563 | end |
| 4564 | if osp_arg_eq_fl i 4 |
| 4565 | if ge add i 1 na |
| 4566 | exit 2 |
| 4567 | end |
| 4568 | put ocl_cfg 0 oargu add i 1 |
| 4569 | i = add i 2 |
| 4570 | continue |
| 4571 | end |
| 4572 | if osp_arg_eq_fl i 5 |
| 4573 | if ge add i 1 na |
| 4574 | exit 2 |
| 4575 | end |
| 4576 | osp_parse_splice_list add i 1 |
| 4577 | i = add i 2 |
| 4578 | continue |
| 4579 | end |
| 4580 | if osp_arg_eq_fl i 6 |
| 4581 | if ge add i 2 na |
| 4582 | exit 2 |
| 4583 | end |
| 4584 | si2 = oargu add i 1 |
| 4585 | if ge si2 get ocl_st 1 |
| 4586 | exit 2 |
| 4587 | end |
| 4588 | n2 = oargp add i 2 |
| 4589 | osp_parse_1splice 0 n2 si2 |
| 4590 | i = add i 3 |
| 4591 | continue |
| 4592 | end |
| 4593 | if and eq allow 1 osp_arg_eq_fl i 7 |
| 4594 | if ge add i 1 na |
| 4595 | exit 2 |
| 4596 | end |
| 4597 | put ocl_cfg 8 ovp_from_arg 37 add i 1 |
| 4598 | i = add i 2 |
| 4599 | continue |
| 4600 | end |
| 4601 | if eq allow 2 |
| 4602 | if osp_arg_eq_fl i 8 |
| 4603 | if ge add i 1 na |
| 4604 | exit 2 |
| 4605 | end |
| 4606 | nb = oargu add i 1 |
| 4607 | if or eq nb 0 gt nb 64 |
| 4608 | exit 2 |
| 4609 | end |
| 4610 | put ocl_cfg 6 nb |
| 4611 | i = add i 2 |
| 4612 | continue |
| 4613 | end |
| 4614 | if osp_arg_eq_fl i 9 |
| 4615 | if ge add i 1 na |
| 4616 | exit 2 |
| 4617 | end |
| 4618 | al = oargu add i 1 |
| 4619 | if gt al 8 |
| 4620 | exit 2 |
| 4621 | end |
| 4622 | put ocl_cfg 5 al |
| 4623 | i = add i 2 |
| 4624 | continue |
| 4625 | end |
| 4626 | if osp_arg_eq_fl i 10 |
| 4627 | put ocl_cfg 4 1 |
| 4628 | i = add i 1 |
| 4629 | continue |
| 4630 | end |
| 4631 | if osp_arg_eq_fl i 11 |
| 4632 | if ge add i 1 na |
| 4633 | exit 2 |
| 4634 | end |
| 4635 | put ocl_cfg 7 ovp_from_arg 35 add i 1 |
| 4636 | i = add i 2 |
| 4637 | continue |
| 4638 | end |
| 4639 | if osp_arg_eq_fl i 12 |
| 4640 | put ocl_cfg 7 999999 |
| 4641 | i = add i 1 |
| 4642 | continue |
| 4643 | end |
| 4644 | end |
| 4645 | exit 2 |
| 4646 | end |
| 4647 | end |
| 4648 | |
| 4649 | note ---- 13. spclip create / edit / verify / inspect / run / eval ---- |
| 4650 | |
| 4651 | note spclip create OUT.spclip BASE.ck (--strand ... | S W1 K1 ...) [--weights ...] [--mode M] [--tau T] [--splice ...] |
| 4652 | fn cmdspclip_create to void |
| 4653 | na = oargc |
| 4654 | if lt na 7 |
| 4655 | exit 2 |
| 4656 | end |
| 4657 | osp_clip_defaults |
| 4658 | out_ai = ovp_from_arg 37 3 |
| 4659 | put ocl_cfg 1 ovp_from_arg 0 4 |
| 4660 | put ocl_cfg 2 1 |
| 4661 | put ocl_cfg 3 2 |
| 4662 | put ocl_st 0 1 |
| 4663 | if osp_arg_eq_fl 5 0 |
| 4664 | ss = ulong 0 |
| 4665 | i = ulong 5 |
| 4666 | while lt i na bound 64 |
| 4667 | if not osp_arg_eq_fl i 0 |
| 4668 | break |
| 4669 | end |
| 4670 | if or ge add i 1 na ge ss 4 |
| 4671 | exit 2 |
| 4672 | end |
| 4673 | osp_parse_strand_arg add i 1 ss |
| 4674 | put ocl_wm ss 1000 |
| 4675 | ss = add ss 1 |
| 4676 | i = add i 2 |
| 4677 | end |
| 4678 | if lt ss 2 |
| 4679 | exit 2 |
| 4680 | end |
| 4681 | put ocl_st 1 ss |
| 4682 | osp_parse_dyn_flags i 0 |
| 4683 | else |
| 4684 | ss = oargu 5 |
| 4685 | if or lt ss 2 gt ss 4 |
| 4686 | exit 2 |
| 4687 | end |
| 4688 | put ocl_st 1 ss |
| 4689 | idx = ulong 6 |
| 4690 | for s ulong ss |
| 4691 | if gt add idx 2 na |
| 4692 | exit 2 |
| 4693 | end |
| 4694 | put ocl_wm s oargs idx |
| 4695 | ks = oargu add idx 1 |
| 4696 | if or eq ks 0 gt ks 8 |
| 4697 | exit 2 |
| 4698 | end |
| 4699 | if gt add add idx 2 ks na |
| 4700 | exit 2 |
| 4701 | end |
| 4702 | put ocl_k s ks |
| 4703 | for j ulong ks |
| 4704 | sl = add 1 add mul s 8 j |
| 4705 | put ocl_link add mul s 8 j ovp_from_arg sl add add idx 2 j |
| 4706 | end |
| 4707 | idx = add add idx 2 ks |
| 4708 | end |
| 4709 | osp_parse_dyn_flags idx 0 |
| 4710 | end |
| 4711 | osp_clip_validate_knobs |
| 4712 | osp_clip_init |
| 4713 | osp_rec_write out_ai |
| 4714 | oputc 83 |
| 4715 | oputc 80 |
| 4716 | oputc 67 |
| 4717 | oputc 76 |
| 4718 | oputc 73 |
| 4719 | oputc 80 |
| 4720 | oputc 95 |
| 4721 | oputc 67 |
| 4722 | oputc 82 |
| 4723 | oputc 69 |
| 4724 | oputc 65 |
| 4725 | oputc 84 |
| 4726 | oputc 69 |
| 4727 | oputc 32 |
| 4728 | oputu get ocl_st 1 |
| 4729 | oputc 32 |
| 4730 | oputu get ocl_st 0 |
| 4731 | oputc 32 |
| 4732 | oputu get ocl_cfg 0 |
| 4733 | oputc 32 |
| 4734 | oput_sha_rsha |
| 4735 | oputc 10 |
| 4736 | oflush |
| 4737 | end |
| 4738 | |
| 4739 | note spclip edit RECIPE.spclip [--out OUT.spclip] [--weights ...] [--set-weight I W] [--mode M] [--tau T] [--splice ...] [--set-splice I S] |
| 4740 | fn cmdspclip_edit to void |
| 4741 | na = oargc |
| 4742 | if lt na 4 |
| 4743 | exit 2 |
| 4744 | end |
| 4745 | rec_ai = ovp_from_arg 36 3 |
| 4746 | osp_rec_load rec_ai |
| 4747 | put ocl_cfg 8 rec_ai |
| 4748 | osp_parse_dyn_flags 4 1 |
| 4749 | osp_clip_validate_knobs |
| 4750 | osp_clip_init |
| 4751 | osp_rec_write get ocl_cfg 8 |
| 4752 | oputc 83 |
| 4753 | oputc 80 |
| 4754 | oputc 67 |
| 4755 | oputc 76 |
| 4756 | oputc 73 |
| 4757 | oputc 80 |
| 4758 | oputc 95 |
| 4759 | oputc 69 |
| 4760 | oputc 68 |
| 4761 | oputc 73 |
| 4762 | oputc 84 |
| 4763 | oputc 32 |
| 4764 | oputu get ocl_st 1 |
| 4765 | oputc 32 |
| 4766 | oputu get ocl_st 0 |
| 4767 | oputc 32 |
| 4768 | oputu get ocl_cfg 0 |
| 4769 | oputc 32 |
| 4770 | oput_sha_rsha |
| 4771 | oputc 10 |
| 4772 | oflush |
| 4773 | end |
| 4774 | |
| 4775 | fn cmdspclip_verify to void |
| 4776 | if ne oargc 4 |
| 4777 | exit 2 |
| 4778 | end |
| 4779 | rec_ai = ovp_from_arg 36 3 |
| 4780 | osp_rec_load rec_ai |
| 4781 | osp_clip_init |
| 4782 | oputc 83 |
| 4783 | oputc 80 |
| 4784 | oputc 67 |
| 4785 | oputc 76 |
| 4786 | oputc 73 |
| 4787 | oputc 80 |
| 4788 | oputc 95 |
| 4789 | oputc 86 |
| 4790 | oputc 69 |
| 4791 | oputc 82 |
| 4792 | oputc 73 |
| 4793 | oputc 70 |
| 4794 | oputc 89 |
| 4795 | oputc 32 |
| 4796 | oputc 79 |
| 4797 | oputc 75 |
| 4798 | oputc 32 |
| 4799 | oputu get ocl_st 1 |
| 4800 | oputc 32 |
| 4801 | oputu get ocl_st 0 |
| 4802 | oputc 32 |
| 4803 | oputu get ocl_cfg 0 |
| 4804 | oputc 32 |
| 4805 | oputu get ocl_st 2 |
| 4806 | oputc 32 |
| 4807 | oputu get ocl_st 3 |
| 4808 | oputc 32 |
| 4809 | oputu get ocl_st 5 |
| 4810 | oputc 32 |
| 4811 | oput_sha_rsha |
| 4812 | oputc 10 |
| 4813 | oflush |
| 4814 | end |
| 4815 | |
| 4816 | fn cmdspclip_inspect to void |
| 4817 | if ne oargc 4 |
| 4818 | exit 2 |
| 4819 | end |
| 4820 | rec_ai = ovp_from_arg 36 3 |
| 4821 | osp_rec_load rec_ai |
| 4822 | osp_clip_init |
| 4823 | oputc 83 |
| 4824 | oputc 80 |
| 4825 | oputc 67 |
| 4826 | oputc 76 |
| 4827 | oputc 73 |
| 4828 | oputc 80 |
| 4829 | oputc 95 |
| 4830 | oputc 73 |
| 4831 | oputc 78 |
| 4832 | oputc 83 |
| 4833 | oputc 80 |
| 4834 | oputc 69 |
| 4835 | oputc 67 |
| 4836 | oputc 84 |
| 4837 | oputc 32 |
| 4838 | oputu get ocl_st 1 |
| 4839 | oputc 32 |
| 4840 | oputu get ocl_st 0 |
| 4841 | oputc 32 |
| 4842 | oputu get ocl_cfg 0 |
| 4843 | oputc 32 |
| 4844 | oputu get ocl_st 2 |
| 4845 | oputc 32 |
| 4846 | oputu get ocl_st 3 |
| 4847 | oputc 32 |
| 4848 | oputu get ocl_st 5 |
| 4849 | oputc 32 |
| 4850 | oput_sha_rsha |
| 4851 | oputc 10 |
| 4852 | for s ulong get ocl_st 1 |
| 4853 | oputc 83 |
| 4854 | oputc 84 |
| 4855 | oputc 82 |
| 4856 | oputc 65 |
| 4857 | oputc 78 |
| 4858 | oputc 68 |
| 4859 | oputc 32 |
| 4860 | oputu s |
| 4861 | oputc 32 |
| 4862 | oputl get ocl_wm s |
| 4863 | oputc 32 |
| 4864 | oputu get ocl_sp_s s |
| 4865 | oputc 58 |
| 4866 | oputu get ocl_sp_e s |
| 4867 | oputc 58 |
| 4868 | oputu get ocl_sp_g s |
| 4869 | oputc 32 |
| 4870 | oputu get ocl_raw_sl s |
| 4871 | oputc 32 |
| 4872 | oputu get ocl_sl s |
| 4873 | oputc 32 |
| 4874 | oputu get ocl_k s |
| 4875 | oputc 10 |
| 4876 | end |
| 4877 | oflush |
| 4878 | end |
| 4879 | |
| 4880 | note spclip run RECIPE.spclip PROMPT N TEMPMILLI SEED MERGES [--weights ...] [--mode M] [--tau T] [--splice ...] |
| 4881 | fn cmdspclip_run to void |
| 4882 | if lt oargc 9 |
| 4883 | exit 2 |
| 4884 | end |
| 4885 | rec_ai = ovp_from_arg 36 3 |
| 4886 | osp_rec_load rec_ai |
| 4887 | nn = oargu 5 |
| 4888 | if gt nn 999999 |
| 4889 | exit 2 |
| 4890 | end |
| 4891 | tm = oargu 6 |
| 4892 | sd = oargu 7 |
| 4893 | osp_parse_dyn_flags 9 0 |
| 4894 | osp_clip_validate_knobs |
| 4895 | osp_clip_init |
| 4896 | v = get og 0 |
| 4897 | if gt v 256 |
| 4898 | obload 8 v |
| 4899 | end |
| 4900 | osp_prompt 4 v |
| 4901 | osp_clip_loop nn sd tm |
| 4902 | end |
| 4903 | |
| 4904 | note Evaluate one full window of T positions under clipped + spliced strands (exact per-row log-prob fusion) |
| 4905 | fn osp_clip_eval_br s ulong tt ulong hfin_off ulong to void |
| 4906 | tl = get ocl_st 3 |
| 4907 | sl = get ocl_sl s |
| 4908 | wo = get ocl_wo s |
| 4909 | wn = get ocl_wn s |
| 4910 | if gt wn 0 |
| 4911 | osp_c2wb get ocl_st 4 wo wn |
| 4912 | end |
| 4913 | osp_hrest osp_hout tl get ocl_st 7 mul tt get og 2 |
| 4914 | put og 9 tt |
| 4915 | put okv 0 0 |
| 4916 | put ogkm 1 0 |
| 4917 | ta = osp_app tl |
| 4918 | for k ulong sub sl tl |
| 4919 | olayf add ta k |
| 4920 | end |
| 4921 | td = mul tt get og 2 |
| 4922 | osp_hsnap add hfin_off mul s td osp_hout sl td |
| 4923 | end |
| 4924 | |
| 4925 | fn osp_clip_row_proj s ulong t ulong r ulong to void |
| 4926 | hf = add get og 15 r |
| 4927 | z = add get og 17 r |
| 4928 | s0 = add get og 16 t |
| 4929 | frms hf get og 33 z s0 |
| 4930 | klogit z get og 27 get og 0 get og 2 |
| 4931 | osp_clip_lsm s |
| 4932 | end |
| 4933 | |
| 4934 | fn osp_clip_eval_row_s s ulong t ulong tt ulong hfin_off ulong to void |
| 4935 | d = get og 2 |
| 4936 | r = mul t d |
| 4937 | osp_c2wb get og 33 add get ocl_wo s get ocl_wn s d |
| 4938 | osp_hrest add get og 15 r add add hfin_off mul s mul tt d r d |
| 4939 | osp_clip_row_proj s t r |
| 4940 | end |
| 4941 | |
| 4942 | fn osp_clip_eval_row t ulong tt ulong hfin_off ulong to f64 |
| 4943 | for s ulong get ocl_st 1 |
| 4944 | osp_clip_eval_row_s s t tt hfin_off |
| 4945 | end |
| 4946 | osp_clip_fuse |
| 4947 | ret olossrow get og 27 get og 0 get oby t |
| 4948 | end |
| 4949 | |
| 4950 | fn osp_clip_eval_win w ulong hfin_off ulong to f64 |
| 4951 | tt = get og 1 |
| 4952 | tl = get ocl_st 3 |
| 4953 | obrow 0 mul w tt |
| 4954 | put og 9 tt |
| 4955 | put okv 0 0 |
| 4956 | put ogkm 1 0 |
| 4957 | oemb 0 |
| 4958 | ta = osp_app tl |
| 4959 | for l ulong ta |
| 4960 | olayf l |
| 4961 | end |
| 4962 | osp_hsnap get ocl_st 7 osp_hout tl mul tt get og 2 |
| 4963 | for s ulong get ocl_st 1 |
| 4964 | osp_clip_eval_br s tt hfin_off |
| 4965 | end |
| 4966 | ls = 0.0f64 |
| 4967 | for t ulong tt |
| 4968 | ls = add ls osp_clip_eval_row t tt hfin_off |
| 4969 | end |
| 4970 | ret div ls f64 tt |
| 4971 | end |
| 4972 | |
| 4973 | note spclip eval RECIPE.spclip HELD W MERGES [--weights ...] [--mode M] [--tau T] [--splice ...] |
| 4974 | fn cmdspclip_eval to void |
| 4975 | if lt oargc 7 |
| 4976 | exit 2 |
| 4977 | end |
| 4978 | rec_ai = ovp_from_arg 36 3 |
| 4979 | osp_rec_load rec_ai |
| 4980 | ww = oargu 5 |
| 4981 | osp_parse_dyn_flags 7 0 |
| 4982 | osp_clip_validate_knobs |
| 4983 | osp_clip_init |
| 4984 | v = get og 0 |
| 4985 | if gt v 256 |
| 4986 | obload 6 v |
| 4987 | end |
| 4988 | odopen 4 |
| 4989 | tt = get og 1 |
| 4990 | m = get odn 0 |
| 4991 | if eq ww 0 |
| 4992 | exit 23 |
| 4993 | end |
| 4994 | if gt ww div sub m 1 tt |
| 4995 | exit 23 |
| 4996 | end |
| 4997 | hfin_off = get ocl_st 8 |
| 4998 | td = mul tt get og 2 |
| 4999 | if gt add hfin_off mul get ocl_st 1 td ocsinit |
| 5000 | exit 12 |
| 5001 | end |
| 5002 | ls = 0.0f64 |
| 5003 | nb = ulong 0 |
| 5004 | for w ulong ww |
| 5005 | ls = add ls osp_clip_eval_win w hfin_off |
| 5006 | if gt v 256 |
| 5007 | nb = add nb oevnb tt |
| 5008 | end |
| 5009 | end |
| 5010 | lo = div ls f64 ww |
| 5011 | bp = div lo 0.6931471805599453 |
| 5012 | if gt v 256 |
| 5013 | bp = div mul bp f64 mul ww tt f64 nb |
| 5014 | end |
| 5015 | oputc 83 |
| 5016 | oputc 80 |
| 5017 | oputc 67 |
| 5018 | oputc 76 |
| 5019 | oputc 73 |
| 5020 | oputc 80 |
| 5021 | oputc 95 |
| 5022 | oputc 69 |
| 5023 | oputc 86 |
| 5024 | oputc 65 |
| 5025 | oputc 76 |
| 5026 | oputc 32 |
| 5027 | oputu ww |
| 5028 | oputc 32 |
| 5029 | oputl rmic lo |
| 5030 | oputc 32 |
| 5031 | oputl rmic bp |
| 5032 | oputc 32 |
| 5033 | oputu get ocl_st 1 |
| 5034 | oputc 32 |
| 5035 | oputu get ocl_st 0 |
| 5036 | oputc 32 |
| 5037 | oputu get ocl_cfg 0 |
| 5038 | oputc 10 |
| 5039 | oflush |
| 5040 | end |
| 5041 | |
| 5042 | note ---- 14. spclip tune (Materialize + Frozen-Trunk Fine-Tune -> Verified OLLMSP01 + OLLMSPLIN01) ---- |
| 5043 | |
| 5044 | fn osp_tune_cal_s s2 ulong hfin_off ulong to void |
| 5045 | tt = get og 1 |
| 5046 | eh = 0.0f64 |
| 5047 | for t ulong tt |
| 5048 | osp_clip_eval_row_s s2 t tt hfin_off |
| 5049 | eh = add eh get ocl_ent s2 |
| 5050 | end |
| 5051 | put ocl_ent s2 div eh f64 tt |
| 5052 | end |
| 5053 | |
| 5054 | note Calibrate effective strand weights ocl_tun_al[0..S) (for MODE=1 measures mean entropy on window 0 of DATA) |
| 5055 | fn osp_tune_cal_al to void |
| 5056 | ss = get ocl_st 1 |
| 5057 | if eq get ocl_st 0 0 |
| 5058 | osp_clip_calc_al |
| 5059 | for s ulong ss |
| 5060 | put ocl_tun_al s get ocl_al s |
| 5061 | end |
| 5062 | ret |
| 5063 | end |
| 5064 | tt = get og 1 |
| 5065 | tl = get ocl_st 3 |
| 5066 | hfin_off = get ocl_st 8 |
| 5067 | td = mul tt get og 2 |
| 5068 | if gt add hfin_off mul ss td ocsinit |
| 5069 | exit 12 |
| 5070 | end |
| 5071 | obrow 0 0 |
| 5072 | put og 9 tt |
| 5073 | put okv 0 0 |
| 5074 | put ogkm 1 0 |
| 5075 | oemb 0 |
| 5076 | for l ulong osp_app tl |
| 5077 | olayf l |
| 5078 | end |
| 5079 | osp_hsnap get ocl_st 7 osp_hout tl td |
| 5080 | for s ulong ss |
| 5081 | osp_clip_eval_br s tt hfin_off |
| 5082 | end |
| 5083 | for s2 ulong ss |
| 5084 | osp_tune_cal_s s2 hfin_off |
| 5085 | end |
| 5086 | osp_clip_calc_al |
| 5087 | for s3 ulong ss |
| 5088 | put ocl_tun_al s3 get ocl_al s3 |
| 5089 | end |
| 5090 | end |
| 5091 | |
| 5092 | fn osp_is_res_off i ulong to bool |
| 5093 | d = get og 2 |
| 5094 | wo_lo = add d mul 3 mul d d |
| 5095 | wo_hi = add wo_lo mul d d |
| 5096 | if and ge i wo_lo lt i wo_hi |
| 5097 | ret true |
| 5098 | end |
| 5099 | w2_lo = add add wo_hi d mul d get og 4 |
| 5100 | ret ge i w2_lo |
| 5101 | end |
| 5102 | |
| 5103 | fn osp_tune_blend_1 k ulong i ulong psum f64 use_w bool to f64 |
| 5104 | ss = get ocl_st 1 |
| 5105 | tl = get ocl_st 3 |
| 5106 | koff = mul k get og 32 |
| 5107 | is_res = osp_is_res_off i |
| 5108 | acc = 0.0f64 |
| 5109 | for s ulong ss |
| 5110 | if gt sub get ocl_sl s tl k |
| 5111 | al = get ocl_tun_al s |
| 5112 | if use_w |
| 5113 | al = get ocl_w s |
| 5114 | end |
| 5115 | if or is_res gt al 0.0 |
| 5116 | acc = add acc mul al ocsg add add get ocl_wo s koff i |
| 5117 | end |
| 5118 | end |
| 5119 | end |
| 5120 | ret div acc psum |
| 5121 | end |
| 5122 | |
| 5123 | note Blend one materialized branch layer k into ow[fzt + k*lstr ..) using ocl_tun_al[0..S) |
| 5124 | fn osp_tune_blend_lay k ulong to void |
| 5125 | ss = get ocl_st 1 |
| 5126 | tl = get ocl_st 3 |
| 5127 | psum = 0.0f64 |
| 5128 | for s0 ulong ss |
| 5129 | if and gt get ocl_w s0 0.0 gt sub get ocl_sl s0 tl k |
| 5130 | psum = add psum get ocl_tun_al s0 |
| 5131 | end |
| 5132 | end |
| 5133 | use_w = false |
| 5134 | if le psum 0.0 |
| 5135 | use_w = true |
| 5136 | for s1 ulong ss |
| 5137 | if and gt get ocl_w s1 0.0 gt sub get ocl_sl s1 tl k |
| 5138 | psum = add psum get ocl_w s1 |
| 5139 | end |
| 5140 | end |
| 5141 | if le psum 0.0 |
| 5142 | exit 2 |
| 5143 | end |
| 5144 | end |
| 5145 | lstr = get og 32 |
| 5146 | dst = add get ocl_st 4 mul k lstr |
| 5147 | i = ulong 0 |
| 5148 | while lt i lstr bound 9223372036854775807 |
| 5149 | owp add dst i osp_tune_blend_1 k i psum use_w |
| 5150 | i = add i 1 |
| 5151 | end |
| 5152 | end |
| 5153 | |
| 5154 | fn osp_tune_blend_gf to void |
| 5155 | ss = get ocl_st 1 |
| 5156 | d = get og 2 |
| 5157 | psum_g = 0.0f64 |
| 5158 | for s0 ulong ss |
| 5159 | if gt get ocl_w s0 0.0 |
| 5160 | psum_g = add psum_g get ocl_tun_al s0 |
| 5161 | end |
| 5162 | end |
| 5163 | for g ulong d |
| 5164 | acc = 0.0f64 |
| 5165 | for s2 ulong ss |
| 5166 | if gt get ocl_w s2 0.0 |
| 5167 | goff = add get ocl_wo s2 get ocl_wn s2 |
| 5168 | acc = add acc mul get ocl_tun_al s2 ocsg add goff g |
| 5169 | end |
| 5170 | end |
| 5171 | put odl2 g div acc psum_g |
| 5172 | end |
| 5173 | end |
| 5174 | |
| 5175 | fn osp_tune_add_lays maxd ulong addl ulong to void |
| 5176 | tl = get ocl_st 3 |
| 5177 | fzt = get ocl_st 4 |
| 5178 | lstr = get og 32 |
| 5179 | src_off = add get og 31 mul sub add tl maxd 1 lstr |
| 5180 | for a ulong addl |
| 5181 | dst_off = add fzt mul add maxd a lstr |
| 5182 | i = ulong 0 |
| 5183 | while lt i lstr bound 9223372036854775807 |
| 5184 | owp add dst_off i owg add src_off i |
| 5185 | i = add i 1 |
| 5186 | end |
| 5187 | end |
| 5188 | ogrowsilent add tl maxd |
| 5189 | end |
| 5190 | |
| 5191 | fn osp_tune_finish_ow child_l ulong need_p ulong to void |
| 5192 | if ne child_l get og 5 |
| 5193 | if gt need_p ocsinit |
| 5194 | exit 12 |
| 5195 | end |
| 5196 | osp_w2c 0 0 need_p |
| 5197 | put og 5 child_l |
| 5198 | if not ogeom |
| 5199 | exit 12 |
| 5200 | end |
| 5201 | osp_c2wb 0 0 need_p |
| 5202 | end |
| 5203 | for g2 ulong get og 2 |
| 5204 | owp add get og 33 g2 get odl2 g2 |
| 5205 | end |
| 5206 | end |
| 5207 | |
| 5208 | note Materialize clipped + spliced mix (+ optional add_layers) into ow with target depth child_L |
| 5209 | fn osp_tune_materialize to ulong |
| 5210 | ss = get ocl_st 1 |
| 5211 | tl = get ocl_st 3 |
| 5212 | maxd = ulong 0 |
| 5213 | for s ulong ss |
| 5214 | if gt get ocl_w s 0.0 |
| 5215 | ds = sub get ocl_sl s tl |
| 5216 | if gt ds maxd |
| 5217 | maxd = ds |
| 5218 | end |
| 5219 | end |
| 5220 | end |
| 5221 | addl = get ocl_cfg 5 |
| 5222 | child_l = add add tl maxd addl |
| 5223 | if eq get ocl_cfg 4 0 |
| 5224 | put ocl_exp 11 get ocl_st 2 |
| 5225 | put ocl_exp 13 get ocl_st 11 |
| 5226 | else |
| 5227 | put ocl_exp 11 tl |
| 5228 | put ocl_exp 12 get ocl_st 4 |
| 5229 | put ocl_exp 13 get ocl_exp 14 |
| 5230 | end |
| 5231 | if or le child_l get ocl_exp 11 gt child_l 24 |
| 5232 | exit 2 |
| 5233 | end |
| 5234 | for k ulong maxd |
| 5235 | osp_tune_blend_lay k |
| 5236 | end |
| 5237 | osp_tune_blend_gf |
| 5238 | if gt addl 0 |
| 5239 | osp_tune_add_lays maxd addl |
| 5240 | end |
| 5241 | osp_tune_finish_ow child_l add get ocl_st 4 mul add maxd addl get og 32 |
| 5242 | ret child_l |
| 5243 | end |
| 5244 | |
| 5245 | note Write canonical OLLMSPLIN01 Merkle lineage certificate to dst_ai; stores lineage_sha256 in ocl_tsha |
| 5246 | fn osp_lin_write dst_ai ulong steps ulong lrm ulong bat ulong child_l ulong nspec ulong to void |
| 5247 | osr_reset |
| 5248 | osr_putkw 1 |
| 5249 | osr_putkw 16 |
| 5250 | osr_putslot 33 |
| 5251 | osr_putc 10 |
| 5252 | osr_putkw 17 |
| 5253 | for i ulong 32 |
| 5254 | put osha_d i get ocl_csha i |
| 5255 | end |
| 5256 | osr_putsha_d |
| 5257 | osr_putc 10 |
| 5258 | osr_putkw 18 |
| 5259 | osr_putu get ocl_exp 11 |
| 5260 | osr_putc 10 |
| 5261 | osr_putkw 19 |
| 5262 | osr_putu child_l |
| 5263 | osr_putc 10 |
| 5264 | osr_putkw 20 |
| 5265 | osr_putx64 get ocl_exp 13 |
| 5266 | osr_putc 10 |
| 5267 | osr_putkw 21 |
| 5268 | osr_putx64 get ocl_exp 15 |
| 5269 | osr_putc 10 |
| 5270 | osr_putkw 22 |
| 5271 | osr_putu nspec |
| 5272 | osr_putc 10 |
| 5273 | osr_putkw 2 |
| 5274 | osr_putslot 0 |
| 5275 | osr_putc 10 |
| 5276 | osr_putkw 3 |
| 5277 | for i2 ulong 32 |
| 5278 | put osha_d i2 get ocl_bsha i2 |
| 5279 | end |
| 5280 | osr_putsha_d |
| 5281 | osr_putc 10 |
| 5282 | osr_putkw 4 |
| 5283 | osr_putu get ocl_st 2 |
| 5284 | osr_putc 10 |
| 5285 | osr_putkw 5 |
| 5286 | osr_putx64 get ocl_st 11 |
| 5287 | osr_putc 10 |
| 5288 | osr_putkw 23 |
| 5289 | osr_putu get ocl_st 3 |
| 5290 | osr_putc 10 |
| 5291 | osr_putkw 24 |
| 5292 | for i3 ulong 32 |
| 5293 | put osha_d i3 get ocl_rsha i3 |
| 5294 | end |
| 5295 | osr_putsha_d |
| 5296 | osr_putc 10 |
| 5297 | osr_putkw 6 |
| 5298 | osr_putu get ocl_st 0 |
| 5299 | osr_putc 10 |
| 5300 | osr_putkw 7 |
| 5301 | osr_putu get ocl_cfg 0 |
| 5302 | osr_putc 10 |
| 5303 | osr_putkw 25 |
| 5304 | for i4 ulong 32 |
| 5305 | put osha_d i4 get ocl_dsha i4 |
| 5306 | end |
| 5307 | osr_putsha_d |
| 5308 | osr_putc 10 |
| 5309 | osr_putkw 26 |
| 5310 | osr_putu steps |
| 5311 | osr_putc 10 |
| 5312 | osr_putkw 27 |
| 5313 | osr_putu lrm |
| 5314 | osr_putc 10 |
| 5315 | osr_putkw 28 |
| 5316 | osr_putu bat |
| 5317 | osr_putc 10 |
| 5318 | osr_putkw 29 |
| 5319 | osr_putl rmic get ocl_tun_ls 0 |
| 5320 | osr_putc 10 |
| 5321 | osr_putkw 30 |
| 5322 | osr_putl rmic get ocl_tun_ls 1 |
| 5323 | osr_putc 10 |
| 5324 | osr_putkw 8 |
| 5325 | osr_putu get ocl_st 1 |
| 5326 | osr_putc 10 |
| 5327 | osp_lin_wr_strands |
| 5328 | osha_buf_ocl get ocl_rlen 0 |
| 5329 | osha_save_tsha |
| 5330 | osr_putkw 31 |
| 5331 | osr_putsha_d |
| 5332 | osr_putc 10 |
| 5333 | osr_flush_file dst_ai |
| 5334 | end |
| 5335 | |
| 5336 | fn osp_lin_wr_strands to void |
| 5337 | ss = get ocl_st 1 |
| 5338 | for s ulong ss |
| 5339 | osr_putkw 9 |
| 5340 | osr_putu s |
| 5341 | osr_putc 32 |
| 5342 | osr_putkw 10 |
| 5343 | osr_putl get ocl_wm s |
| 5344 | osr_putc 32 |
| 5345 | osr_putkw 15 |
| 5346 | osr_putl rmic get ocl_tun_al s |
| 5347 | osr_putc 32 |
| 5348 | osr_putkw 11 |
| 5349 | osr_putu get ocl_sp_s s |
| 5350 | osr_putc 58 |
| 5351 | osr_putu get ocl_sp_e s |
| 5352 | osr_putc 58 |
| 5353 | osr_putu get ocl_sp_g s |
| 5354 | osr_putc 32 |
| 5355 | osr_putkw 12 |
| 5356 | osr_putu get ocl_k s |
| 5357 | osr_putc 10 |
| 5358 | for j ulong get ocl_k s |
| 5359 | idx = add mul s 8 j |
| 5360 | osr_putkw 13 |
| 5361 | osr_putu s |
| 5362 | osr_putc 32 |
| 5363 | osr_putu j |
| 5364 | osr_putc 32 |
| 5365 | osr_putslot add 1 idx |
| 5366 | osr_putc 32 |
| 5367 | bo = mul idx 32 |
| 5368 | for b ulong 32 |
| 5369 | put osha_d b get ocl_lsha add bo b |
| 5370 | end |
| 5371 | osr_putsha_d |
| 5372 | osr_putc 32 |
| 5373 | osr_putx64 get ocl_lph idx |
| 5374 | osr_putc 10 |
| 5375 | end |
| 5376 | end |
| 5377 | end |
| 5378 | |
| 5379 | fn osp_tune_run_opt steps ulong lrm ulong to void |
| 5380 | tl = get ocl_st 3 |
| 5381 | fzt = get ocl_st 4 |
| 5382 | ozerom mul 2 get og 8 |
| 5383 | put ofreeze 0 fzt |
| 5384 | put ofzlay 0 osp_app tl |
| 5385 | put og 41 0 |
| 5386 | tot = steps |
| 5387 | if eq tot 0 |
| 5388 | tot = ulong 1 |
| 5389 | end |
| 5390 | put og 42 tot |
| 5391 | put og 43 bitcast ulong div f64 lrm 1000000.0 |
| 5392 | put og 44 1 |
| 5393 | put og 45 1 |
| 5394 | if ne get ocl_cfg 6 0 |
| 5395 | put og 6 get ocl_cfg 6 |
| 5396 | end |
| 5397 | obrow 0 0 |
| 5398 | put og 9 get og 1 |
| 5399 | put ocl_tun_ls 0 ofwd 0 |
| 5400 | s = ulong 0 |
| 5401 | while lt s steps bound 999999 |
| 5402 | ls = ostep |
| 5403 | s = add s 1 |
| 5404 | end |
| 5405 | obrow 0 0 |
| 5406 | put og 9 get og 1 |
| 5407 | put ocl_tun_ls 1 ofwd 0 |
| 5408 | put ofreeze 0 0 |
| 5409 | put ofzlay 0 0 |
| 5410 | end |
| 5411 | |
| 5412 | note spclip tune RECIPE.spclip DATA OUT.sp STEPS LRMICRO [--batch B] [--weights ...] [--mode M] [--tau T] [--splice ...] [--add-layers K] [--trunk-link] [--lineage PATH | --no-lineage] |
| 5413 | fn cmdspclip_tune to void |
| 5414 | if lt oargc 8 |
| 5415 | exit 2 |
| 5416 | end |
| 5417 | rec_ai = ovp_from_arg 36 3 |
| 5418 | osp_rec_load rec_ai |
| 5419 | data_ai = ovp_from_arg 34 4 |
| 5420 | out_ai = ovp_from_arg 33 5 |
| 5421 | steps = oargu 6 |
| 5422 | if gt steps 999999 |
| 5423 | exit 2 |
| 5424 | end |
| 5425 | lrm = oargu 7 |
| 5426 | if and gt steps 0 eq lrm 0 |
| 5427 | exit 2 |
| 5428 | end |
| 5429 | osp_parse_dyn_flags 8 2 |
| 5430 | osp_clip_validate_knobs |
| 5431 | lin_ai = get ocl_cfg 7 |
| 5432 | if eq lin_ai 0 |
| 5433 | lin_ai = ovp_set_lin 35 5 |
| 5434 | put ocl_cfg 7 lin_ai |
| 5435 | end |
| 5436 | osha_file data_ai |
| 5437 | osha_save_dsha |
| 5438 | osp_clip_init |
| 5439 | odopen data_ai |
| 5440 | osp_tune_cal_al |
| 5441 | child_l = osp_tune_materialize |
| 5442 | osp_tune_run_opt steps lrm |
| 5443 | ex_bl = get ocl_exp 11 |
| 5444 | ex_fz = get ocl_exp 12 |
| 5445 | ex_bh = get ocl_exp 13 |
| 5446 | if ne osp_basehash ex_bl ex_fz ex_bh |
| 5447 | exit 62 |
| 5448 | end |
| 5449 | if ne osp_basehash get ocl_st 3 get ocl_st 4 get ocl_exp 14 |
| 5450 | exit 62 |
| 5451 | end |
| 5452 | nspec = sub get og 8 ex_fz |
| 5453 | osp_wrpack out_ai ex_bl child_l ex_bh ex_fz nspec |
| 5454 | if ne oprd out_ai 0 0 48 48 |
| 5455 | exit 60 |
| 5456 | end |
| 5457 | put ocl_exp 15 opw8 40 |
| 5458 | osha_file out_ai |
| 5459 | osha_save_csha |
| 5460 | lin_ai = get ocl_cfg 7 |
| 5461 | if ne lin_ai 999999 |
| 5462 | osp_lin_write lin_ai steps lrm get og 6 child_l nspec |
| 5463 | else |
| 5464 | for z ulong 32 |
| 5465 | put ocl_tsha z 0 |
| 5466 | end |
| 5467 | end |
| 5468 | oputc 83 |
| 5469 | oputc 80 |
| 5470 | oputc 67 |
| 5471 | oputc 76 |
| 5472 | oputc 73 |
| 5473 | oputc 80 |
| 5474 | oputc 95 |
| 5475 | oputc 84 |
| 5476 | oputc 85 |
| 5477 | oputc 78 |
| 5478 | oputc 69 |
| 5479 | oputc 32 |
| 5480 | oputu ex_bl |
| 5481 | oputc 32 |
| 5482 | oputu child_l |
| 5483 | oputc 32 |
| 5484 | oputu nspec |
| 5485 | oputc 32 |
| 5486 | oputu steps |
| 5487 | oputc 32 |
| 5488 | oputl rmic get ocl_tun_ls 0 |
| 5489 | oputc 32 |
| 5490 | oputl rmic get ocl_tun_ls 1 |
| 5491 | oputc 32 |
| 5492 | oput_sha_csha |
| 5493 | oputc 32 |
| 5494 | oput_sha_tsha |
| 5495 | oputc 10 |
| 5496 | oflush |
| 5497 | end |
| 5498 | |
| 5499 | fn osp_lin_rd_strand s ulong to void |
| 5500 | osr_eat_kw 9 |
| 5501 | if ne osr_rd_u 32 s |
| 5502 | exit 60 |
| 5503 | end |
| 5504 | osr_eat_kw 10 |
| 5505 | put ocl_wm s osr_rd_l 32 |
| 5506 | osr_eat_kw 15 |
| 5507 | am = osr_rd_l 32 |
| 5508 | osr_eat_kw 11 |
| 5509 | sps = osr_rd_u 58 |
| 5510 | spe = osr_rd_u 58 |
| 5511 | spg = osr_rd_u 32 |
| 5512 | if or gt sps 24 gt spe 24 |
| 5513 | exit 60 |
| 5514 | end |
| 5515 | if or and eq sps 0 ne spe 0 and ne sps 0 eq spe 0 |
| 5516 | exit 60 |
| 5517 | end |
| 5518 | put ocl_sp_s s sps |
| 5519 | put ocl_sp_e s spe |
| 5520 | put ocl_sp_g s spg |
| 5521 | osr_eat_kw 12 |
| 5522 | ks = osr_rd_u 10 |
| 5523 | if or eq ks 0 gt ks 8 |
| 5524 | exit 60 |
| 5525 | end |
| 5526 | put ocl_k s ks |
| 5527 | for j ulong ks |
| 5528 | osr_eat_kw 13 |
| 5529 | if ne osr_rd_u 32 s |
| 5530 | exit 60 |
| 5531 | end |
| 5532 | if ne osr_rd_u 32 j |
| 5533 | exit 60 |
| 5534 | end |
| 5535 | idx = add mul s 8 j |
| 5536 | ai = osr_rd_path add 1 idx 32 |
| 5537 | put ocl_link idx ai |
| 5538 | osr_rd_sha_d 32 |
| 5539 | osha_save_lsha idx |
| 5540 | put ocl_lph idx osr_rd_x64 10 |
| 5541 | end |
| 5542 | end |
| 5543 | |
| 5544 | fn osp_lin_parse_hdr to ulong |
| 5545 | osr_eat_kw 1 |
| 5546 | osr_eat_kw 16 |
| 5547 | child_ai = osr_rd_path 33 10 |
| 5548 | osr_eat_kw 17 |
| 5549 | osr_rd_sha_d 10 |
| 5550 | osha_save_csha |
| 5551 | osr_eat_kw 18 |
| 5552 | put ocl_exp 2 osr_rd_u 10 |
| 5553 | osr_eat_kw 19 |
| 5554 | put ocl_exp 3 osr_rd_u 10 |
| 5555 | osr_eat_kw 20 |
| 5556 | put ocl_exp 4 osr_rd_x64 10 |
| 5557 | osr_eat_kw 21 |
| 5558 | put ocl_exp 5 osr_rd_x64 10 |
| 5559 | osr_eat_kw 22 |
| 5560 | put ocl_exp 6 osr_rd_u 10 |
| 5561 | osr_eat_kw 2 |
| 5562 | put ocl_cfg 1 osr_rd_path 0 10 |
| 5563 | osr_eat_kw 3 |
| 5564 | osr_rd_sha_d 10 |
| 5565 | osha_save_bsha |
| 5566 | osr_eat_kw 4 |
| 5567 | put ocl_exp 0 osr_rd_u 10 |
| 5568 | osr_eat_kw 5 |
| 5569 | put ocl_exp 1 osr_rd_x64 10 |
| 5570 | osr_eat_kw 23 |
| 5571 | put ocl_exp 7 osr_rd_u 10 |
| 5572 | osr_eat_kw 24 |
| 5573 | osr_rd_sha_d 10 |
| 5574 | osha_save_rsha |
| 5575 | osr_eat_kw 6 |
| 5576 | put ocl_st 0 osr_rd_u 10 |
| 5577 | osr_eat_kw 7 |
| 5578 | put ocl_cfg 0 osr_rd_u 10 |
| 5579 | osr_eat_kw 25 |
| 5580 | osr_rd_sha_d 10 |
| 5581 | osha_save_dsha |
| 5582 | osr_eat_kw 26 |
| 5583 | put ocl_exp 8 osr_rd_u 10 |
| 5584 | osr_eat_kw 27 |
| 5585 | put ocl_exp 9 osr_rd_u 10 |
| 5586 | osr_eat_kw 28 |
| 5587 | put ocl_exp 10 osr_rd_u 10 |
| 5588 | osr_eat_kw 29 |
| 5589 | z0 = osr_rd_l 10 |
| 5590 | osr_eat_kw 30 |
| 5591 | z1 = osr_rd_l 10 |
| 5592 | ret child_ai |
| 5593 | end |
| 5594 | |
| 5595 | note spclip verify-lineage FILE.lineage: fail-closed Merkle verification of lineage seal + child + base + all parents |
| 5596 | fn cmdspclip_vlin to void |
| 5597 | if ne oargc 4 |
| 5598 | exit 2 |
| 5599 | end |
| 5600 | osp_clip_defaults |
| 5601 | lin_ai = ovp_from_arg 35 3 |
| 5602 | osr_read_file lin_ai |
| 5603 | child_ai = osp_lin_parse_hdr |
| 5604 | osr_eat_kw 8 |
| 5605 | ss = osr_rd_u 10 |
| 5606 | if or lt ss 2 gt ss 4 |
| 5607 | exit 60 |
| 5608 | end |
| 5609 | put ocl_st 1 ss |
| 5610 | for s ulong ss |
| 5611 | osp_lin_rd_strand s |
| 5612 | end |
| 5613 | seal_end = get ocl_rcur 0 |
| 5614 | osr_eat_kw 31 |
| 5615 | osr_rd_sha_d 10 |
| 5616 | osha_save_tsha |
| 5617 | if ne get ocl_rcur 0 get ocl_rlen 0 |
| 5618 | exit 60 |
| 5619 | end |
| 5620 | osha_buf_ocl seal_end |
| 5621 | if not osha_eq_tsha |
| 5622 | exit 61 |
| 5623 | end |
| 5624 | put ocl_cfg 2 1 |
| 5625 | put ocl_cfg 3 1 |
| 5626 | osp_clip_validate_knobs |
| 5627 | osp_clip_init |
| 5628 | if ne get ocl_st 3 get ocl_exp 7 |
| 5629 | exit 62 |
| 5630 | end |
| 5631 | osha_file child_ai |
| 5632 | if not osha_eq_csha |
| 5633 | exit 61 |
| 5634 | end |
| 5635 | c_bl = get ocl_exp 2 |
| 5636 | c_bh = get ocl_exp 4 |
| 5637 | if eq c_bl get ocl_st 2 |
| 5638 | if ne c_bh get ocl_st 11 |
| 5639 | exit 62 |
| 5640 | end |
| 5641 | else |
| 5642 | if or ne c_bl get ocl_st 3 ne c_bh get ocl_exp 14 |
| 5643 | exit 62 |
| 5644 | end |
| 5645 | end |
| 5646 | osp_rdhdr child_ai c_bl c_bh |
| 5647 | if ne get ottt_st 1 get ocl_exp 3 |
| 5648 | exit 61 |
| 5649 | end |
| 5650 | if ne get ottt_st 3 get ocl_exp 6 |
| 5651 | exit 61 |
| 5652 | end |
| 5653 | if ne get ottt_st 4 get ocl_exp 5 |
| 5654 | exit 61 |
| 5655 | end |
| 5656 | osp_chkpay child_ai get ottt_st 3 get ottt_st 4 |
| 5657 | oputc 83 |
| 5658 | oputc 80 |
| 5659 | oputc 67 |
| 5660 | oputc 76 |
| 5661 | oputc 73 |
| 5662 | oputc 80 |
| 5663 | oputc 95 |
| 5664 | oputc 76 |
| 5665 | oputc 73 |
| 5666 | oputc 78 |
| 5667 | oputc 69 |
| 5668 | oputc 65 |
| 5669 | oputc 71 |
| 5670 | oputc 69 |
| 5671 | oputc 95 |
| 5672 | oputc 86 |
| 5673 | oputc 69 |
| 5674 | oputc 82 |
| 5675 | oputc 73 |
| 5676 | oputc 70 |
| 5677 | oputc 89 |
| 5678 | oputc 32 |
| 5679 | oputc 79 |
| 5680 | oputc 75 |
| 5681 | oputc 32 |
| 5682 | oput_sha_csha |
| 5683 | oputc 32 |
| 5684 | oputu get ocl_st 1 |
| 5685 | oputc 32 |
| 5686 | oputu get ocl_exp 3 |
| 5687 | oputc 32 |
| 5688 | oput_sha_tsha |
| 5689 | oputc 10 |
| 5690 | oflush |
| 5691 | end |
| 5692 | |
| 5693 | fn cmdspclip_legacy to void |
| 5694 | osp_clip_defaults |
| 5695 | osp_clip_parse |
| 5696 | nn = oargu 5 |
| 5697 | if gt nn 999999 |
| 5698 | exit 2 |
| 5699 | end |
| 5700 | tm = oargu 6 |
| 5701 | st = oargu 7 |
| 5702 | osp_clip_init |
| 5703 | v = get og 0 |
| 5704 | if gt v 256 |
| 5705 | obload 8 v |
| 5706 | end |
| 5707 | osp_prompt 4 v |
| 5708 | osp_clip_loop nn st tm |
| 5709 | end |
| 5710 | |
| 5711 | fn cmdspclip to void |
| 5712 | if lt oargc 3 |
| 5713 | exit 2 |
| 5714 | end |
| 5715 | if osp_arg_eq_sub 2 0 |
| 5716 | cmdspclip_create |
| 5717 | ret |
| 5718 | end |
| 5719 | if osp_arg_eq_sub 2 1 |
| 5720 | cmdspclip_edit |
| 5721 | ret |
| 5722 | end |
| 5723 | if osp_arg_eq_sub 2 2 |
| 5724 | cmdspclip_verify |
| 5725 | ret |
| 5726 | end |
| 5727 | if osp_arg_eq_sub 2 3 |
| 5728 | cmdspclip_inspect |
| 5729 | ret |
| 5730 | end |
| 5731 | if osp_arg_eq_sub 2 4 |
| 5732 | cmdspclip_run |
| 5733 | ret |
| 5734 | end |
| 5735 | if osp_arg_eq_sub 2 5 |
| 5736 | cmdspclip_eval |
| 5737 | ret |
| 5738 | end |
| 5739 | if osp_arg_eq_sub 2 6 |
| 5740 | cmdspclip_tune |
| 5741 | ret |
| 5742 | end |
| 5743 | if osp_arg_eq_sub 2 7 |
| 5744 | cmdspclip_vlin |
| 5745 | ret |
| 5746 | end |
| 5747 | cmdspclip_legacy |
| 5748 | end |