omega-helix
This project has not described itself yet.
Brought by drakestapleton
omega-helix / native / arboris.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note native/arboris.om: Pillar 5 - Arboris 1 us Associative CPU Bypass + Warp-Compacted Early Exit Gating |
| 3 | note + OMG Native Semantic-Graph Recall, 3-Layer Guided Decoding & Hippocampus->Cortex Sleep Export. |
| 4 | note Pure seeded OM-2 library unit (compose under `om2` or `target a64macos\nom2`). |
| 5 | |
| 6 | const ARB_CAP ulong 4096 |
| 7 | const ARB_MASK ulong 4095 |
| 8 | const ARB_MAX_PROBE ulong 32 |
| 9 | const ARB_MAX_NGRAM ulong 8 |
| 10 | const ARB_MAX_TOK ulong 512 |
| 11 | const ARB_WARP_SZ ulong 32 |
| 12 | const ARB_MAX_WARPS ulong 16 |
| 13 | |
| 14 | const ARB_EXIT_CPU ulong 0 |
| 15 | const ARB_EXIT_L1 ulong 1 |
| 16 | const ARB_EXIT_L2 ulong 2 |
| 17 | const ARB_EXIT_CONTESTED ulong 99 |
| 18 | |
| 19 | const ARB_OMG_CAP ulong 256 |
| 20 | const ARB_OMG_SLEN ulong 64 |
| 21 | |
| 22 | note Open-addressed associative table (4096 slots, L1/L2 resident for sub-microsecond probe) |
| 23 | global arb_key ulong 4096 |
| 24 | global arb_sig ulong 4096 |
| 25 | global arb_len uchar 4096 |
| 26 | global arb_tok ulong 4096 |
| 27 | global arb_conf ulong 4096 |
| 28 | global arb_hits ulong 4096 |
| 29 | global arb_stat ulong 8 |
| 30 | |
| 31 | note Per-token bypass / adaptive-loop / spclip routing arrays + dense compacted active list + warp ballot masks |
| 32 | global arb_bypass_conf ulong 512 |
| 33 | global arb_loop_delta ulong 512 |
| 34 | global arb_sp_jsd ulong 512 |
| 35 | global arb_exit_layer ulong 512 |
| 36 | global arb_active_idx ulong 512 |
| 37 | global arb_warp_mask ulong 16 |
| 38 | global arb_cfg ulong 8 |
| 39 | |
| 40 | note OMG semantic-graph Hippocampus->Cortex memory (256 verified subgraphs, up to 64 tokens each) |
| 41 | global arb_omg_n ulong 1 |
| 42 | global arb_omg_sem ulong 256 |
| 43 | global arb_omg_io ulong 256 |
| 44 | global arb_omg_opm ulong 256 |
| 45 | global arb_omg_mtok ulong 256 |
| 46 | global arb_omg_util ulong 256 |
| 47 | global arb_omg_slen ulong 256 |
| 48 | global arb_omg_act ulong 256 |
| 49 | global arb_omg_toks ulong 16384 |
| 50 | |
| 51 | note 3-layer guided decoding step buffers (OMG vocab <= 512) |
| 52 | global arb_omg_logits f64 512 |
| 53 | global arb_omg_mask uchar 512 |
| 54 | global arb_omg_biased f64 512 |
| 55 | |
| 56 | note ---- Self-contained Wolfram-verified f64 log for JSD strand disagreement (matches math.om) ---- |
| 57 | |
| 58 | fn arb_flog x f64 to f64 |
| 59 | if ne x x |
| 60 | ret x |
| 61 | end |
| 62 | if lt x 0.0 |
| 63 | ret bitcast f64 ulong 9221120237041090560 |
| 64 | end |
| 65 | if eq x 0.0 |
| 66 | ret bitcast f64 ulong 18442240474082181120 |
| 67 | end |
| 68 | b = bitcast ulong x |
| 69 | if eq b 9218868437227405312 |
| 70 | ret x |
| 71 | end |
| 72 | e = long 0 |
| 73 | if lt b 4503599627370496 |
| 74 | b = bitcast ulong mul x 18014398509481984.0 |
| 75 | e = long -54 |
| 76 | end |
| 77 | e = add e sub long shr b 52 1023 |
| 78 | m = bitcast f64 or and b 4503599627370495 4607182418800017408 |
| 79 | if gt m 1.4142135623730951 |
| 80 | m = mul m 0.5 |
| 81 | e = add e 1 |
| 82 | end |
| 83 | f = sub m 1.0 |
| 84 | s = div f add f 2.0 |
| 85 | z = mul s s |
| 86 | q = add mul z 0.043478260869565216 0.047619047619047616 |
| 87 | q = add mul q z 0.05263157894736842 |
| 88 | q = add mul q z 0.058823529411764705 |
| 89 | q = add mul q z 0.06666666666666667 |
| 90 | q = add mul q z 0.07692307692307693 |
| 91 | q = add mul q z 0.09090909090909091 |
| 92 | q = add mul q z 0.1111111111111111 |
| 93 | q = add mul q z 0.14285714285714285 |
| 94 | q = add mul q z 0.2 |
| 95 | q = add mul q z 0.3333333333333333 |
| 96 | q = add mul q z 1.0 |
| 97 | lm = mul add s s q |
| 98 | fe = f64 e |
| 99 | ret add mul fe 0.6931471803691238 add lm mul fe 1.9082149292705877e-10 |
| 100 | end |
| 101 | |
| 102 | note ---- Fast FNV-1a-64 + SplitMix64 Context N-Gram Hashing ---- |
| 103 | |
| 104 | fn arb_smx x ulong to ulong |
| 105 | z = add x 0x9e3779b97f4a7c15 |
| 106 | z = mul xor z shr z 30 0xbf58476d1ce4e5b9 |
| 107 | z = mul xor z shr z 27 0x94d049bb133111eb |
| 108 | ret xor z shr z 31 |
| 109 | end |
| 110 | |
| 111 | fn arboris_fnv64_ngram ctx view ulong * off ulong n ulong to ulong |
| 112 | h = ulong 0xcbf29ce484222325 |
| 113 | for i ulong n bound 16 |
| 114 | w = get ctx add off i |
| 115 | for b ulong 4 |
| 116 | by = and shr w mul b 8 255 |
| 117 | h = mul xor h by 0x100000001b3 |
| 118 | end |
| 119 | end |
| 120 | if eq h 0 |
| 121 | h = ulong 1 |
| 122 | end |
| 123 | ret h |
| 124 | end |
| 125 | |
| 126 | fn arboris_sig64_ngram ctx view ulong * off ulong n ulong to ulong |
| 127 | s = mul n 0x9e3779b97f4a7c15 |
| 128 | for i ulong n bound 16 |
| 129 | s = arb_smx xor s get ctx add off i |
| 130 | end |
| 131 | ret s |
| 132 | end |
| 133 | |
| 134 | note ---- Open-Addressed Associative Pattern Table ---- |
| 135 | |
| 136 | fn arboris_clear to void |
| 137 | for i ulong ARB_CAP bound 4096 |
| 138 | put arb_key i 0 |
| 139 | put arb_sig i 0 |
| 140 | put arb_len i 0 |
| 141 | put arb_tok i 0 |
| 142 | put arb_conf i 0 |
| 143 | put arb_hits i 0 |
| 144 | end |
| 145 | for j ulong 8 |
| 146 | put arb_stat j 0 |
| 147 | end |
| 148 | for t ulong ARB_MAX_TOK bound 512 |
| 149 | put arb_bypass_conf t 0 |
| 150 | put arb_loop_delta t 0 |
| 151 | put arb_sp_jsd t 0 |
| 152 | put arb_exit_layer t ARB_EXIT_CONTESTED |
| 153 | put arb_active_idx t 0 |
| 154 | put arb_omg_logits t 0.0f64 |
| 155 | put arb_omg_mask t 1 |
| 156 | put arb_omg_biased t 0.0f64 |
| 157 | end |
| 158 | for w ulong ARB_MAX_WARPS bound 16 |
| 159 | put arb_warp_mask w 0 |
| 160 | end |
| 161 | put arb_omg_n 0 0 |
| 162 | for m ulong ARB_OMG_CAP bound 256 |
| 163 | put arb_omg_sem m 0 |
| 164 | put arb_omg_io m 0 |
| 165 | put arb_omg_opm m 0 |
| 166 | put arb_omg_mtok m 0 |
| 167 | put arb_omg_util m 0 |
| 168 | put arb_omg_slen m 0 |
| 169 | put arb_omg_act m 0 |
| 170 | end |
| 171 | put arb_cfg 0 900000 |
| 172 | put arb_cfg 1 50000 |
| 173 | put arb_cfg 2 100 |
| 174 | put arb_cfg 3 25000 |
| 175 | put arb_cfg 4 900000 |
| 176 | put arb_cfg 5 2000 |
| 177 | put arb_cfg 6 2500 |
| 178 | put arb_cfg 7 0 |
| 179 | end |
| 180 | |
| 181 | fn arboris_slot_match slot ulong h ulong sg ulong n ulong to bool |
| 182 | if ne get arb_key slot h |
| 183 | ret false |
| 184 | end |
| 185 | if ne get arb_sig slot sg |
| 186 | ret false |
| 187 | end |
| 188 | ret eq ulong get arb_len slot n |
| 189 | end |
| 190 | |
| 191 | fn arboris_slot_store slot ulong h ulong sg ulong n ulong pred_tok ulong conf ulong to void |
| 192 | put arb_key slot h |
| 193 | put arb_sig slot sg |
| 194 | put arb_len slot uchar n |
| 195 | put arb_tok slot pred_tok |
| 196 | put arb_conf slot conf |
| 197 | put arb_hits slot 1 |
| 198 | put arb_stat 0 add get arb_stat 0 1 |
| 199 | put arb_stat 1 add get arb_stat 1 1 |
| 200 | end |
| 201 | |
| 202 | fn arboris_slot_update slot ulong pred_tok ulong conf ulong to void |
| 203 | put arb_hits slot add get arb_hits slot 1 |
| 204 | put arb_stat 1 add get arb_stat 1 1 |
| 205 | if eq get arb_tok slot pred_tok |
| 206 | if gt conf get arb_conf slot |
| 207 | put arb_conf slot conf |
| 208 | end |
| 209 | else |
| 210 | put arb_conf slot 0 |
| 211 | put arb_stat 5 add get arb_stat 5 1 |
| 212 | end |
| 213 | end |
| 214 | |
| 215 | note Insert or reinforce context n-gram -> predicted token. |
| 216 | note Ambiguous continuations (same n-gram seen with different pred_tok) automatically demote conf to 0. |
| 217 | fn arboris_put ctx view ulong * off ulong n ulong pred_tok ulong conf_micro ulong to bool |
| 218 | if or eq n 0 gt n ARB_MAX_NGRAM |
| 219 | ret false |
| 220 | end |
| 221 | if gt add off n len ctx |
| 222 | ret false |
| 223 | end |
| 224 | if gt conf_micro 1000000 |
| 225 | ret false |
| 226 | end |
| 227 | h = arboris_fnv64_ngram ctx off n |
| 228 | sg = arboris_sig64_ngram ctx off n |
| 229 | idx = and h ARB_MASK |
| 230 | for p ulong ARB_MAX_PROBE bound 32 |
| 231 | slot = and add idx p ARB_MASK |
| 232 | if eq get arb_key slot 0 |
| 233 | arboris_slot_store slot h sg n pred_tok conf_micro |
| 234 | ret true |
| 235 | end |
| 236 | if arboris_slot_match slot h sg n |
| 237 | arboris_slot_update slot pred_tok conf_micro |
| 238 | ret true |
| 239 | end |
| 240 | put arb_stat 4 add get arb_stat 4 1 |
| 241 | end |
| 242 | ret false |
| 243 | end |
| 244 | |
| 245 | note Probe associative pattern table in ~1 us; out_res[0]=pred_tok, out_res[1]=conf_micro |
| 246 | fn arboris_probe ctx view ulong * off ulong n ulong out_res edit ulong 2 to bool |
| 247 | if or eq n 0 gt n ARB_MAX_NGRAM |
| 248 | ret false |
| 249 | end |
| 250 | if gt add off n len ctx |
| 251 | ret false |
| 252 | end |
| 253 | put arb_stat 2 add get arb_stat 2 1 |
| 254 | h = arboris_fnv64_ngram ctx off n |
| 255 | sg = arboris_sig64_ngram ctx off n |
| 256 | idx = and h ARB_MASK |
| 257 | for p ulong ARB_MAX_PROBE bound 32 |
| 258 | slot = and add idx p ARB_MASK |
| 259 | if eq get arb_key slot 0 |
| 260 | ret false |
| 261 | end |
| 262 | if arboris_slot_match slot h sg n |
| 263 | cf = get arb_conf slot |
| 264 | if eq cf 0 |
| 265 | ret false |
| 266 | end |
| 267 | put out_res 0 get arb_tok slot |
| 268 | put out_res 1 cf |
| 269 | put arb_stat 3 add get arb_stat 3 1 |
| 270 | ret true |
| 271 | end |
| 272 | end |
| 273 | ret false |
| 274 | end |
| 275 | |
| 276 | note ---- 1 us Associative CPU Sequence Bypass (Zero GPU Matmuls) ---- |
| 277 | |
| 278 | fn arboris_probe_pos seq view ulong * pos ulong max_ng ulong th ulong out_res edit ulong 2 to bool |
| 279 | ng = max_ng |
| 280 | if gt ng add pos 1 |
| 281 | ng = add pos 1 |
| 282 | end |
| 283 | if gt ng ARB_MAX_NGRAM |
| 284 | ng = ARB_MAX_NGRAM |
| 285 | end |
| 286 | while ge ng 2 bound 8 |
| 287 | off = sub add pos 1 ng |
| 288 | if arboris_probe seq off ng out_res |
| 289 | if ge get out_res 1 th |
| 290 | ret true |
| 291 | end |
| 292 | end |
| 293 | ng = sub ng 1 |
| 294 | end |
| 295 | ret false |
| 296 | end |
| 297 | |
| 298 | note Scan seq[0..n_seq), populate out_pred[pos], arb_bypass_conf[pos], and arb_active_idx[0..n_contested). |
| 299 | note Returns count of tokens bypassed on CPU with zero GPU matmuls; sets arb_stat[6] = n_contested. |
| 300 | fn arboris_bypass_seq seq view ulong * n_gram ulong thresh_micro ulong out_pred edit ulong * to ulong |
| 301 | n_seq = len seq |
| 302 | if or gt n_seq ARB_MAX_TOK gt n_seq len out_pred |
| 303 | ret 0 |
| 304 | end |
| 305 | res = new ulong 2 0 |
| 306 | n_bypass = ulong 0 |
| 307 | n_cont = ulong 0 |
| 308 | for pos ulong n_seq bound 512 |
| 309 | put arb_bypass_conf pos 0 |
| 310 | put out_pred pos 0 |
| 311 | if arboris_probe_pos seq pos n_gram thresh_micro res |
| 312 | put out_pred pos get res 0 |
| 313 | put arb_bypass_conf pos get res 1 |
| 314 | put arb_exit_layer pos ARB_EXIT_CPU |
| 315 | n_bypass = add n_bypass 1 |
| 316 | else |
| 317 | put arb_exit_layer pos ARB_EXIT_CONTESTED |
| 318 | put arb_active_idx n_cont pos |
| 319 | n_cont = add n_cont 1 |
| 320 | end |
| 321 | end |
| 322 | put arb_stat 6 n_cont |
| 323 | ret n_bypass |
| 324 | end |
| 325 | |
| 326 | note ---- d9b7422 Adaptive Loop Exit + spclip Strand Disagreement Warp Compaction ---- |
| 327 | |
| 328 | fn arboris_set_thresholds bypass_th ulong delta_th ulong jsd_th ulong l1_delta_th ulong to void |
| 329 | put arb_cfg 0 bypass_th |
| 330 | put arb_cfg 1 delta_th |
| 331 | put arb_cfg 2 jsd_th |
| 332 | put arb_cfg 3 l1_delta_th |
| 333 | end |
| 334 | |
| 335 | fn arboris_set_token_signals t ulong bypass_conf ulong loop_delta_micro ulong sp_jsd_milli ulong to void |
| 336 | if lt t ARB_MAX_TOK |
| 337 | put arb_bypass_conf t bypass_conf |
| 338 | put arb_loop_delta t loop_delta_micro |
| 339 | put arb_sp_jsd t sp_jsd_milli |
| 340 | end |
| 341 | end |
| 342 | |
| 343 | note Compute Jensen-Shannon Disagreement in milli-nats between two strand probability vectors (matches spclip) |
| 344 | fn arboris_jsd_milli pa view f64 * pb view f64 * to ulong |
| 345 | v = len pa |
| 346 | if or eq v 0 ne v len pb |
| 347 | ret 0 |
| 348 | end |
| 349 | ha = 0.0f64 |
| 350 | hb = 0.0f64 |
| 351 | hm = 0.0f64 |
| 352 | for j ulong v bound 4096 |
| 353 | va = get pa j |
| 354 | vb = get pb j |
| 355 | if gt va 1.0e-15f64 |
| 356 | ha = sub ha mul va arb_flog va |
| 357 | end |
| 358 | if gt vb 1.0e-15f64 |
| 359 | hb = sub hb mul vb arb_flog vb |
| 360 | end |
| 361 | vm = mul 0.5 add va vb |
| 362 | if gt vm 1.0e-15f64 |
| 363 | hm = sub hm mul vm arb_flog vm |
| 364 | end |
| 365 | end |
| 366 | jsd = sub hm mul 0.5 add ha hb |
| 367 | if lt jsd 0.0 |
| 368 | jsd = 0.0f64 |
| 369 | end |
| 370 | ret ulong add mul jsd 1000.0 0.5 |
| 371 | end |
| 372 | |
| 373 | note Classify tokens and compact contested tokens into dense arb_active_idx[] + 32-bit arb_warp_mask[]. |
| 374 | note Returns n_active (number of contested tokens routed to deeper LTP0 passes). |
| 375 | fn arboris_compact_one t ulong n_act ulong to ulong |
| 376 | jsd = get arb_sp_jsd t |
| 377 | bc = get arb_bypass_conf t |
| 378 | dl = get arb_loop_delta t |
| 379 | disagree = ge jsd get arb_cfg 2 |
| 380 | if and not disagree ge bc get arb_cfg 0 |
| 381 | put arb_exit_layer t ARB_EXIT_CPU |
| 382 | ret n_act |
| 383 | end |
| 384 | if and not disagree lt dl get arb_cfg 3 |
| 385 | put arb_exit_layer t ARB_EXIT_L1 |
| 386 | ret n_act |
| 387 | end |
| 388 | if and not disagree lt dl get arb_cfg 1 |
| 389 | put arb_exit_layer t ARB_EXIT_L2 |
| 390 | ret n_act |
| 391 | end |
| 392 | put arb_exit_layer t ARB_EXIT_CONTESTED |
| 393 | put arb_active_idx n_act t |
| 394 | wid = div t 32 |
| 395 | lane = rem t 32 |
| 396 | put arb_warp_mask wid or get arb_warp_mask wid shl ulong 1 lane |
| 397 | ret add n_act 1 |
| 398 | end |
| 399 | |
| 400 | fn arboris_compact_mask n_tok ulong to ulong |
| 401 | if gt n_tok ARB_MAX_TOK |
| 402 | ret 0 |
| 403 | end |
| 404 | n_warps = div add n_tok 31 32 |
| 405 | for w ulong n_warps bound 16 |
| 406 | put arb_warp_mask w 0 |
| 407 | end |
| 408 | n_act = ulong 0 |
| 409 | for t ulong n_tok bound 512 |
| 410 | n_act = arboris_compact_one t n_act |
| 411 | end |
| 412 | put arb_stat 7 n_act |
| 413 | ret n_act |
| 414 | end |
| 415 | |
| 416 | fn arboris_popcnt32 mask ulong to ulong |
| 417 | m = and mask 0xffffffff |
| 418 | c = ulong 0 |
| 419 | for i ulong 32 |
| 420 | if ne and shr m i 1 0 |
| 421 | c = add c 1 |
| 422 | end |
| 423 | end |
| 424 | ret c |
| 425 | end |
| 426 | |
| 427 | fn arboris_popcnt64 mask ulong to ulong |
| 428 | c = ulong 0 |
| 429 | for i ulong 64 |
| 430 | if ne and shr mask i 1 0 |
| 431 | c = add c 1 |
| 432 | end |
| 433 | end |
| 434 | ret c |
| 435 | end |
| 436 | |
| 437 | note ---- OMG Semantic-Graph Recall + 3-Layer Guided Decoding + Hippocampus->Cortex Sleep Export ---- |
| 438 | |
| 439 | fn arboris_omg_find sem_id ulong to ulong |
| 440 | cnt = get arb_omg_n 0 |
| 441 | for m ulong cnt bound 256 |
| 442 | if eq get arb_omg_sem m sem_id |
| 443 | ret m |
| 444 | end |
| 445 | end |
| 446 | ret ARB_OMG_CAP |
| 447 | end |
| 448 | |
| 449 | fn arboris_omg_victim to ulong |
| 450 | cnt = get arb_omg_n 0 |
| 451 | if lt cnt ARB_OMG_CAP |
| 452 | put arb_omg_n 0 add cnt 1 |
| 453 | ret cnt |
| 454 | end |
| 455 | best = ulong 0 |
| 456 | bu = get arb_omg_util 0 |
| 457 | for m ulong ARB_OMG_CAP bound 256 |
| 458 | u = get arb_omg_util m |
| 459 | if lt u bu |
| 460 | bu = u |
| 461 | best = m |
| 462 | end |
| 463 | end |
| 464 | ret best |
| 465 | end |
| 466 | |
| 467 | note Hippocampus->Cortex online insert on verified oracle pass; returns slot index (0..255). |
| 468 | fn arboris_insert_verified_omg sem_id ulong io_sig ulong op_mask ulong macro_tok ulong utility_milli ulong to long |
| 469 | if eq sem_id 0 |
| 470 | ret long -1 |
| 471 | end |
| 472 | idx = arboris_omg_find sem_id |
| 473 | if lt idx ARB_OMG_CAP |
| 474 | put arb_omg_util idx add get arb_omg_util idx utility_milli |
| 475 | put arb_omg_mtok idx macro_tok |
| 476 | ret long idx |
| 477 | end |
| 478 | slot = arboris_omg_victim |
| 479 | put arb_omg_sem slot sem_id |
| 480 | put arb_omg_io slot io_sig |
| 481 | put arb_omg_opm slot op_mask |
| 482 | put arb_omg_mtok slot macro_tok |
| 483 | put arb_omg_util slot utility_milli |
| 484 | put arb_omg_slen slot 0 |
| 485 | ret long slot |
| 486 | end |
| 487 | |
| 488 | fn arboris_set_omg_stream slot ulong pos ulong tok ulong to void |
| 489 | if and lt slot ARB_OMG_CAP lt pos ARB_OMG_SLEN |
| 490 | put arb_omg_toks add mul slot ARB_OMG_SLEN pos tok |
| 491 | if ge add pos 1 get arb_omg_slen slot |
| 492 | put arb_omg_slen slot add pos 1 |
| 493 | end |
| 494 | end |
| 495 | end |
| 496 | |
| 497 | note Exact OMG subgraph recall via ~1 us spreading activation over SEMANTIC_ID, IO signature, and opcode cues. |
| 498 | note out_res: [0]=best_slot, [1]=best_sem_id, [2]=best_macro_tok, [3]=peak_activation_milli. |
| 499 | fn arboris_omg_score m ulong cue_sem ulong cue_io ulong cue_opm ulong to ulong |
| 500 | act = ulong 0 |
| 501 | if and ne cue_sem 0 eq get arb_omg_sem m cue_sem |
| 502 | act = add act 4000 |
| 503 | end |
| 504 | if and ne cue_io 0 eq get arb_omg_io m cue_io |
| 505 | act = add act 2000 |
| 506 | end |
| 507 | ov = arboris_popcnt64 and get arb_omg_opm m cue_opm |
| 508 | act = add act mul ov 250 |
| 509 | ub = div get arb_omg_util m 10 |
| 510 | if gt ub 500 |
| 511 | ub = ulong 500 |
| 512 | end |
| 513 | ret add act ub |
| 514 | end |
| 515 | |
| 516 | fn arboris_omg_recall cue_sem ulong cue_io ulong cue_opm ulong out_res edit ulong 4 to bool |
| 517 | cnt = get arb_omg_n 0 |
| 518 | if eq cnt 0 |
| 519 | ret false |
| 520 | end |
| 521 | best = ulong 0 |
| 522 | bact = ulong 0 |
| 523 | for m ulong cnt bound 256 |
| 524 | act = arboris_omg_score m cue_sem cue_io cue_opm |
| 525 | put arb_omg_act m act |
| 526 | if gt act bact |
| 527 | bact = act |
| 528 | best = m |
| 529 | end |
| 530 | end |
| 531 | if eq bact 0 |
| 532 | ret false |
| 533 | end |
| 534 | put out_res 0 best |
| 535 | put out_res 1 get arb_omg_sem best |
| 536 | put out_res 2 get arb_omg_mtok best |
| 537 | put out_res 3 bact |
| 538 | put arb_cfg 7 get arb_omg_mtok best |
| 539 | ret true |
| 540 | end |
| 541 | |
| 542 | note 3-layer guided decoding step: |
| 543 | note (a) gsamp/OMG bitmask wall (illegal tokens zeroed via -1e300 logit floor) |
| 544 | note (b) Arboris 1 us logit bias toward recalled high-activation OMG opcode/macro |
| 545 | note (c) LTP0 deep-compute trigger (set to 1 when peak_act < ltp0_act_thresh OR jsd_milli >= jsd_thresh) |
| 546 | note out_step: [0]=selected_tok, [1]=need_ltp0 (0 or 1), [2]=peak_act, [3]=jsd_milli |
| 547 | fn arboris_set_omg_step_in tok ulong logit f64 valid uchar to void |
| 548 | if lt tok ARB_MAX_TOK |
| 549 | put arb_omg_logits tok logit |
| 550 | put arb_omg_mask tok valid |
| 551 | end |
| 552 | end |
| 553 | |
| 554 | fn arboris_set_guide_cfg bias_gain_milli ulong ltp0_act_th ulong bias_tok ulong to void |
| 555 | put arb_cfg 5 bias_gain_milli |
| 556 | put arb_cfg 6 ltp0_act_th |
| 557 | put arb_cfg 7 bias_tok |
| 558 | end |
| 559 | |
| 560 | fn arboris_guide_pick v ulong btok ulong b_on bool gain f64 to ulong |
| 561 | best_tok = ulong 0 |
| 562 | best_val = -1.0e300f64 |
| 563 | found = false |
| 564 | for c ulong v bound 512 |
| 565 | if eq get arb_omg_mask c 0 |
| 566 | put arb_omg_biased c -1.0e300f64 |
| 567 | else |
| 568 | lv = get arb_omg_logits c |
| 569 | if and b_on eq c btok |
| 570 | lv = add lv gain |
| 571 | end |
| 572 | put arb_omg_biased c lv |
| 573 | if or not found gt lv best_val |
| 574 | best_val = lv |
| 575 | best_tok = c |
| 576 | found = true |
| 577 | end |
| 578 | end |
| 579 | end |
| 580 | ret best_tok |
| 581 | end |
| 582 | |
| 583 | fn arboris_guide_omg_step v ulong peak_act ulong jsd_milli ulong out_step edit ulong 4 to ulong |
| 584 | if or eq v 0 gt v ARB_MAX_TOK |
| 585 | ret 0 |
| 586 | end |
| 587 | gain = div f64 get arb_cfg 5 1000.0 |
| 588 | b_on = ge peak_act get arb_cfg 6 |
| 589 | best_tok = arboris_guide_pick v get arb_cfg 7 b_on gain |
| 590 | need_ltp0 = ulong 0 |
| 591 | if or lt peak_act get arb_cfg 6 ge jsd_milli get arb_cfg 2 |
| 592 | need_ltp0 = ulong 1 |
| 593 | end |
| 594 | put out_step 0 best_tok |
| 595 | put out_step 1 need_ltp0 |
| 596 | put out_step 2 peak_act |
| 597 | put out_step 3 jsd_milli |
| 598 | ret best_tok |
| 599 | end |
| 600 | |
| 601 | note Export high-utility OMG traces (records: sem_id, io_sig, op_mask, macro_tok, util, len, toks...) |
| 602 | note into out_buf for Hippocampus->Cortex sleep consolidation (fcachem / sp_solve.om). |
| 603 | fn arboris_export_one m ulong pos ulong out_buf edit ulong * to ulong |
| 604 | sl = get arb_omg_slen m |
| 605 | put out_buf pos get arb_omg_sem m |
| 606 | put out_buf add pos 1 get arb_omg_io m |
| 607 | put out_buf add pos 2 get arb_omg_opm m |
| 608 | put out_buf add pos 3 get arb_omg_mtok m |
| 609 | put out_buf add pos 4 get arb_omg_util m |
| 610 | put out_buf add pos 5 sl |
| 611 | base = mul m ARB_OMG_SLEN |
| 612 | dst = add pos 6 |
| 613 | for k ulong sl bound 64 |
| 614 | put out_buf add dst k get arb_omg_toks add base k |
| 615 | end |
| 616 | ret add 6 sl |
| 617 | end |
| 618 | |
| 619 | fn arboris_export_sleep_traces min_util ulong out_buf edit ulong * out_cnt edit ulong 1 to ulong |
| 620 | cnt = get arb_omg_n 0 |
| 621 | cap = len out_buf |
| 622 | pos = ulong 0 |
| 623 | n_exp = ulong 0 |
| 624 | for m ulong cnt bound 256 |
| 625 | if ge get arb_omg_util m min_util |
| 626 | need = add 6 get arb_omg_slen m |
| 627 | if gt add pos need cap |
| 628 | break |
| 629 | end |
| 630 | pos = add pos arboris_export_one m pos out_buf |
| 631 | n_exp = add n_exp 1 |
| 632 | end |
| 633 | end |
| 634 | put out_cnt 0 n_exp |
| 635 | ret pos |
| 636 | end |
| 637 | |
| 638 | text arb_cli_ok "ARBORIS_SELFTEST PASS\n" |
| 639 | |
| 640 | fn cmdarboris to void |
| 641 | arboris_clear |
| 642 | sq = new ulong 4 0 |
| 643 | put sq 0 11 |
| 644 | put sq 1 22 |
| 645 | put sq 2 33 |
| 646 | put sq 3 44 |
| 647 | ok = arboris_put sq 0 3 99 950000 |
| 648 | if not ok |
| 649 | exit 1 |
| 650 | end |
| 651 | res = new ulong 2 0 |
| 652 | if not arboris_probe sq 0 3 res |
| 653 | exit 2 |
| 654 | end |
| 655 | if or ne get res 0 99 lt get res 1 900000 |
| 656 | exit 3 |
| 657 | end |
| 658 | w = write 1 arb_cli_ok 0 len arb_cli_ok |
| 659 | end |