Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/train/aien-train/native/btwave/main.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / train / aien-train / native / btwave / main.om` 545 lines ยท 7308 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note BTWAVE-P0: Main Driver, Self-Test, Deterministic Trace, and CLI (native/btwave/main.om). 3 4 global Obuf uchar 65536 5 global Olen ulong 2 6 7 text Tbt6 "BT6 " 8 text Tbtall "BT6_ALL 729 " 9 text Tswar "SWAR32 " 10 text Thc3 "HC3 " 11 text Th16 "H16 " 12 text Tsha "SHA " 13 text Tldg "LDG " 14 text Tend "END " 15 text Tipc1 "IPC PASS coreA=" 16 text Tipc2 " coreB=" 17 text Tipc3 " rounds=" 18 text Tipc4 " contrib=" 19 text Tipc5 " extract=" 20 text Tipc6 " odraft_refused=" 21 text Tipc7 " elapsed_ns=" 22 text Ctrace "trace" 23 text Cself "selftest" 24 text Cipc "ipc" 25 text Ctrapt "trap-trit" 26 text Ctrapd "trap-dup" 27 text Ctrapr "trap-req" 28 text Covf "ovf-probe" 29 30 fn oflush to void 31 n = get Olen 0 32 if gt n 0 33 x = write 1 Obuf 0 n 34 put Olen 0 0 35 end 36 end 37 38 fn oputc ch uchar to void 39 n = get Olen 0 40 if ge n 65500 41 oflush 42 n = 0 43 end 44 put Obuf n ch 45 put Olen 0 add n 1 46 end 47 48 fn ostr s view uchar * to void 49 for i ulong len s 50 oputc get s i 51 end 52 end 53 54 fn osp to void 55 oputc 32 56 end 57 58 fn onl to void 59 oputc 10 60 end 61 62 fn ou64 v ulong to void 63 dg = new uchar 24 0 64 if eq v 0 65 oputc 48 66 ret 67 end 68 k = ulong 0 69 x = v 70 while gt x 0 bound 24 71 put dg k uchar add 48 and rem x 10 0xff 72 x = div x 10 73 k = add k 1 74 end 75 for i ulong k 76 oputc get dg sub sub k 1 i 77 end 78 end 79 80 fn oi64 v long to void 81 if ge v 0 82 ou64 ulong v 83 ret 84 end 85 oputc 45 86 vp = neg add v 1 87 ou64 add ulong vp 1 88 end 89 90 fn eq_txt a view uchar * n ulong b view uchar * to bool 91 if ne n len b 92 ret false 93 end 94 for i ulong n 95 if ne get a i get b i 96 ret false 97 end 98 end 99 ret true 100 end 101 102 fn emit_bt6_one u long to void 103 w = bt6enc u 104 wa = open w 105 ostr Tbt6 106 oi64 u 107 osp 108 ou64 shr wa 32 109 osp 110 ou64 and wa M32 111 osp 112 oi64 bt6dec w 113 osp 114 oi64 bt6dec t32neg w 115 osp 116 oi64 t32pow w 117 onl 118 end 119 120 fn calc_bt6_stats st edit long 4 to void 121 bij = long 0 122 nsym = long 0 123 zcnt = long 0 124 tpow = long 0 125 for idx ulong 729 126 u = sub long idx 364 127 w = bt6enc u 128 if eq bt6dec w u 129 bij = add bij 1 130 end 131 if eq open bt6enc neg u open t32neg w 132 nsym = add nsym 1 133 end 134 pw = t32pow w 135 if eq pw 0 136 zcnt = add zcnt 1 137 end 138 tpow = add tpow pw 139 end 140 put st 0 bij 141 put st 1 nsym 142 put st 2 zcnt 143 put st 3 tpow 144 end 145 146 fn build_swar_vec mulk ulong addk ulong to Trit32 147 p = ulong 0 148 n = ulong 0 149 for i ulong 32 150 rm = rem add mul mulk i addk 3 151 ib = shl ulong 1 i 152 if eq rm 2 153 p = or p ib 154 else 155 if eq rm 0 156 n = or n ib 157 end 158 end 159 end 160 ret Trit32mk or shl p 32 n 161 end 162 163 fn emit_swar to long 164 wa = build_swar_vec 1 0 165 wb = build_swar_vec 2 1 166 ra = open wa 167 rb = open wb 168 dab = t32dot wa wb 169 daa = t32dot wa wa 170 dbb = t32dot wb wb 171 pab = t32pow t32mul wa wb 172 ostr Tswar 173 ou64 shr ra 32 174 osp 175 ou64 and ra M32 176 osp 177 ou64 shr rb 32 178 osp 179 ou64 and rb M32 180 osp 181 oi64 dab 182 osp 183 oi64 daa 184 osp 185 oi64 dbb 186 osp 187 oi64 pab 188 onl 189 if or ne dab 10 or ne daa 21 or ne dbb 21 ne pab 10 190 ret 1 191 end 192 ret 0 193 end 194 195 fn calc_hc3_ok to long 196 ok = long 0 197 for m ulong 16 198 if eq hc3dec hc3enc m m 199 ok = add ok 1 200 end 201 end 202 ret ok 203 end 204 205 fn emit_hc3 to long 206 ok = calc_hc3_ok 207 cf = open hc3enc 0 208 cz = open hc3enc 7 209 cl = open hc3enc 15 210 oob = hc3dec Trit32mk 7 211 ostr Thc3 212 oi64 ok 213 osp 214 ou64 shr cf 32 215 osp 216 ou64 and cf M32 217 osp 218 ou64 shr cz 32 219 osp 220 ou64 and cz M32 221 osp 222 ou64 shr cl 32 223 osp 224 ou64 and cl M32 225 osp 226 ou64 oob 227 onl 228 if or ne ok 16 ne oob 99 229 ret 1 230 end 231 ret 0 232 end 233 234 fn h16_ok01 st edit long 5 to void 235 ok0 = long 0 236 ok1 = long 0 237 for s ulong 32 238 w = h16enc s 239 if eq h16dec w long s 240 ok0 = add ok0 1 241 end 242 for c ulong 16 243 if eq h16dec t32flip w c long s 244 ok1 = add ok1 1 245 end 246 end 247 end 248 put st 0 ok0 249 put st 1 ok1 250 end 251 252 fn h16_ok2 st edit long 5 to void 253 ok2 = long 0 254 w5 = h16enc 5 255 w21 = h16enc 21 256 for c1 ulong 16 257 for c2 ulong 16 258 if lt c1 c2 259 if eq h16dec t32flip t32flip w5 c1 c2 5 260 ok2 = add ok2 1 261 end 262 if eq h16dec t32flip t32flip w21 c1 c2 21 263 ok2 = add ok2 1 264 end 265 if eq h16dec t32eras t32eras w5 c1 c2 5 266 ok2 = add ok2 1 267 end 268 end 269 end 270 end 271 put st 2 ok2 272 end 273 274 fn h16_ok3 st edit long 5 to void 275 ok3 = long 0 276 w13 = h16enc 13 277 for c1 ulong 16 278 for c2 ulong 16 279 if lt c1 c2 280 for c3 ulong 16 281 if lt c2 c3 282 if eq h16dec t32flip t32flip t32flip w13 c1 c2 c3 13 283 ok3 = add ok3 1 284 end 285 if eq h16dec t32eras t32eras t32eras w13 c1 c2 c3 13 286 ok3 = add ok3 1 287 end 288 end 289 end 290 end 291 end 292 end 293 put st 3 ok3 294 end 295 296 fn h16_ref4 st edit long 5 to void 297 rf = long 0 298 w0 = h16enc 0 299 for a ulong 8 300 for b ulong 8 301 if lt a b 302 for c ulong 8 303 if lt b c 304 for d ulong 8 305 if lt c d 306 rx = t32flip t32flip w0 add mul 2 a 1 add mul 2 b 1 307 rx = t32flip t32flip rx add mul 2 c 1 add mul 2 d 1 308 if eq h16dec rx -1 309 rf = add rf 1 310 end 311 end 312 end 313 end 314 end 315 end 316 end 317 end 318 put st 4 rf 319 end 320 321 fn sha_abc_hi64 to ulong 322 m = new uchar 3 0 323 dg = new uchar 32 0 324 put m 0 97 325 put m 1 98 326 put m 2 99 327 sha256_slice view m dg 328 ret rd64be view dg 0 329 end 330 331 fn run_ldg_suite emit bool to int 332 ev = new long 7 0 333 ldg_reset 334 init_cases 335 bad = int 0 336 for cid ulong 16 337 o = mul cid 7 338 for j ulong 7 unroll 339 put ev j get Lcases add o j 340 end 341 st = ldg_step ev 342 if ne st get Lexp cid 343 bad = 1 344 end 345 if gt get Lstate 2 get Lstate 1 346 bad = 2 347 end 348 if emit 349 ostr Tldg 350 ou64 cid 351 osp 352 oi64 st 353 osp 354 oi64 get Lresp 0 355 osp 356 ou64 get Lstate 0 357 osp 358 ou64 get Lstate 1 359 osp 360 ou64 get Lstate 2 361 osp 362 ou64 ldg_chid 363 onl 364 end 365 end 366 if emit 367 ostr Tend 368 ou64 get Lstate 3 369 osp 370 ou64 get Lstate 4 371 osp 372 ou64 get Lstate 5 373 osp 374 ou64 get Lstate 1 375 osp 376 ou64 get Lstate 2 377 onl 378 end 379 if or ne get Lstate 1 90 ne get Lstate 2 90 380 bad = 3 381 end 382 ret bad 383 end 384 385 fn cmd_trace to int 386 bs = new long 4 0 387 hs = new long 5 0 388 emit_bt6_one -364 389 emit_bt6_one -243 390 emit_bt6_one -40 391 emit_bt6_one -1 392 emit_bt6_one 0 393 emit_bt6_one 1 394 emit_bt6_one 40 395 emit_bt6_one 243 396 emit_bt6_one 364 397 calc_bt6_stats bs 398 ostr Tbtall 399 oi64 get bs 0 400 osp 401 oi64 get bs 1 402 osp 403 oi64 get bs 2 404 osp 405 oi64 get bs 3 406 onl 407 rc1 = emit_swar 408 rc2 = emit_hc3 409 h16_ok01 hs 410 h16_ok2 hs 411 h16_ok3 hs 412 h16_ref4 hs 413 ostr Th16 414 oi64 get hs 0 415 osp 416 oi64 get hs 1 417 osp 418 oi64 get hs 2 419 osp 420 oi64 get hs 3 421 osp 422 oi64 get hs 4 423 onl 424 ostr Tsha 425 ou64 sha_abc_hi64 426 onl 427 rc3 = run_ldg_suite true 428 oflush 429 ret int add add rc1 rc2 long rc3 430 end 431 432 fn cmd_selftest to int 433 bs = new long 4 0 434 hs = new long 5 0 435 calc_bt6_stats bs 436 if or ne get bs 0 729 or ne get bs 1 729 or ne get bs 2 1 ne get bs 3 2916 437 ret 10 438 end 439 if ne bt6tor 364 1 -364 440 ret 11 441 end 442 if ne calc_hc3_ok 16 443 ret 12 444 end 445 if ne hc3dec Trit32mk 7 99 446 ret 13 447 end 448 h16_ok01 hs 449 h16_ok2 hs 450 h16_ok3 hs 451 h16_ref4 hs 452 if or ne get hs 0 32 or ne get hs 1 512 or ne get hs 2 360 or ne get hs 3 1120 ne get hs 4 70 453 ret 14 454 end 455 if ne sha_abc_hi64 `13436514500253700074` 456 ret 15 457 end 458 if ne t32dot h16enc 0 h16enc 16 -16 459 ret 16 460 end 461 rc = run_ldg_suite false 462 if ne rc 0 463 ret add 20 rc 464 end 465 ret 0 466 end 467 468 fn cmd_ipc to int 469 rc = ipc_run 470 if ne rc 0 471 ret rc 472 end 473 ostr Tipc1 474 oi64 get IpcOut 0 475 ostr Tipc2 476 oi64 get IpcOut 1 477 ostr Tipc3 478 oi64 get IpcOut 2 479 ostr Tipc4 480 oi64 get IpcOut 3 481 ostr Tipc5 482 oi64 get IpcOut 4 483 ostr Tipc6 484 oi64 get IpcOut 5 485 ostr Tipc7 486 oi64 get IpcOut 6 487 onl 488 oflush 489 ret 0 490 end 491 492 fn cmd_ovf_probe to int 493 ev = new long 7 0 494 ldg_reset 495 put ev 0 1 496 put ev 1 1 497 put ev 2 10 498 put ev 3 0 499 put ev 4 `4611686018427387904` 500 put ev 5 0 501 put ev 6 0 502 st = ldg_step ev 503 if ne st -6 504 ret 41 505 end 506 ret 0 507 end 508 509 fn main to int 510 abuf = new uchar 64 0 511 ac = argcnt 512 if ne ac 2 513 ret 2 514 end 515 al = argread 1 abuf 0 64 516 if lt al 0 517 ret 2 518 end 519 nl = ulong al 520 if eq_txt view abuf nl Ctrace 521 ret cmd_trace 522 end 523 if eq_txt view abuf nl Cself 524 ret cmd_selftest 525 end 526 if eq_txt view abuf nl Cipc 527 ret cmd_ipc 528 end 529 if eq_txt view abuf nl Ctrapt 530 badt = Trit32mk 0x0000000100000001 531 ret int and open badt 1 532 end 533 if eq_txt view abuf nl Ctrapd 534 badd = WaveDupmk 0x0000000100000002 535 ret int and open badd 1 536 end 537 if eq_txt view abuf nl Ctrapr 538 badr = bt6enc 365 539 ret int and open badr 1 540 end 541 if eq_txt view abuf nl Covf 542 ret cmd_ovf_probe 543 end 544 ret 2 545 end