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/tests/algebra/test_realize.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 / tests / algebra / test_realize.om` 588 lines ยท 13388 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Pure seeded OM-2 MA-2 correctness gate (all 10 realizations + selector tie rule). 3 note Replaces tests/algebra/test_realize.c. 4 note Concatenated after src/algebra/oma_lib.om + src/algebra/realize.om. 5 6 global r_chk ulong 2 7 global r_rng ulong 1 8 9 note Selector test table (up to 32 rows; rz ids are 0..9, 0=R1_plain, 1=R1_sdot, 3=R1_smmla, 6=R2c_crumb, 8=R4_rns) 10 global st_nruns int 1 11 global st_nrows ulong 1 12 global st_run int 32 13 global st_rz ulong 32 14 global st_ver int 32 15 global st_med f64 32 16 global st_noise f64 32 17 18 note Decision outputs 19 global sd_chosen ulong 1 20 global sd_cheapest ulong 1 21 global sd_runner ulong 1 22 global sd_chosen_ns f64 1 23 global sd_tie int 1 24 global sd_res int 1 25 global sd_ntie ulong 1 26 global sd_tset ulong 16 27 global sc_elig int 10 28 global sc_cost f64 10 29 global sc_wn f64 10 30 global sc_cn f64 10 31 32 const SEL_RES_NONE int 0 33 const SEL_RES_INCUMBENT int 1 34 const SEL_RES_REFERENCE int 2 35 const SEL_RES_CHEAPEST int 3 36 const SEL_NO_INC ulong 99 37 38 text r_hdr_p "MA2 test-realize PASS: " 39 text r_hdr_f "MA2 test-realize FAIL: " 40 text r_chk_s " checks, " 41 text r_rz_s " failures, 10 realizations\n" 42 43 fn rchk ok bool to void 44 put r_chk 0 add get r_chk 0 1 45 if not ok 46 put r_chk 1 add get r_chk 1 1 47 end 48 end 49 50 fn rrnd to ulong 51 s = add get r_rng 0 0x9e3779b97f4a7c15 52 put r_rng 0 s 53 z = mul xor s shr s 30 0xbf58476d1ce4e5b9 54 z = mul xor z shr z 27 0x94d049bb133111eb 55 ret xor z shr z 31 56 end 57 58 fn rrnd01 to f64 59 ret mul f64 shr rrnd 11 div 1.0f64 `9007199254740992`.0f64 60 end 61 62 fn r_fill_w cnt ulong wk int sp f64 to void 63 for i ulong cnt bound 262144 64 if eq wk 1 65 put rz_w i byte 0 66 else 67 if eq wk 2 68 put rz_w i byte 1 69 else 70 if eq wk 3 71 put rz_w i byte -1 72 else 73 if lt rrnd01 sp 74 put rz_w i byte 0 75 else 76 if eq and rrnd 1 1 77 put rz_w i byte 1 78 else 79 put rz_w i byte -1 80 end 81 end 82 end 83 end 84 end 85 end 86 end 87 88 fn r_fill_x n ulong xk int to void 89 for j ulong n bound 131072 90 if eq xk 1 91 put rz_x j byte -128 92 else 93 if eq xk 2 94 put rz_x j byte 127 95 else 96 if eq xk 3 97 if eq and j 1 1 98 put rz_x j byte 127 99 else 100 put rz_x j byte -128 101 end 102 else 103 if eq xk 4 104 put rz_x j byte 0 105 else 106 rb = and rrnd 255 107 if ge rb 128 108 put rz_x j byte sub int rb 256 109 else 110 put rz_x j byte rb 111 end 112 end 113 end 114 end 115 end 116 end 117 end 118 119 fn check_oracle_lib_row i ulong n ulong xloc view byte * to void 120 row = new byte 4099 0 121 blk = new ulong 130 0 122 d = new int 1 0 123 nb = oma_bitplane_blocks n 124 base = mul i n 125 for j ulong n bound 5000 126 put row j get rz_w add base j 127 end 128 rchk eq oma_pack_bitplane row n blk nb OMA_OK 129 rc = oma_dot_tw_i8 blk xloc n d 130 rchk and eq rc OMA_OK eq get d 0 get rz_yref i 131 end 132 133 fn check_oracle_vs_lib m ulong n ulong to void 134 if gt n 4099 135 ret 136 end 137 xloc = new byte 4099 0 138 for j ulong n bound 5000 139 put xloc j get rz_x j 140 end 141 for i ulong m bound 128 142 check_oracle_lib_row i n xloc 143 end 144 end 145 146 fn check_d5_lane row_off ulong bv int col0 ulong n ulong to ulong 147 t5 = new byte 5 0 148 if ne oma_dense_byte_decode bv t5 OMA_OK 149 ret 1 150 end 151 bad = ulong 0 152 for k ulong 5 153 col = add col0 mul 16 k 154 want = int 0 155 if lt col n 156 want = int get rz_w add row_off col 157 end 158 if ne int get t5 k want 159 bad = add bad 1 160 end 161 end 162 ret bad 163 end 164 165 fn check_d5_chunk i ulong c ulong n ulong rb ulong to ulong 166 row_off = mul i n 167 base_c = add mul i rb mul c 16 168 cbase = mul c 80 169 bad = ulong 0 170 for j ulong 16 171 bv = int get rz_mem add base_c j 172 bad = add bad check_d5_lane row_off bv add cbase j n 173 end 174 ret bad 175 end 176 177 fn check_dense5_decode m ulong n ulong to void 178 chunks = div add n 79 80 179 rb = mul chunks 16 180 bad = ulong 0 181 for i ulong m bound 128 182 for c ulong chunks bound 2048 183 bad = add bad check_d5_chunk i c n rb 184 end 185 end 186 rchk eq bad 0 187 end 188 189 fn run_one_rz rid ulong m ulong n ulong to void 190 rc = oma_rz_pack_g rid m n 191 if gt n oma_rz_max_n rid 192 rchk eq rc OMA_RZ_E_ARG 193 ret 194 end 195 rchk eq rc OMA_RZ_OK 196 if ne rc OMA_RZ_OK 197 ret 198 end 199 for i ulong m bound 1024 200 put rz_y i 0x5a5a5a5a 201 end 202 for rep ulong 2 203 rchk eq oma_rz_run_g OMA_RZ_OK 204 bad = ulong 0 205 for i ulong m bound 1024 206 if ne get rz_y i get rz_yref i 207 bad = add bad 1 208 end 209 end 210 rchk eq bad 0 211 end 212 wb = get rz_plan 2 213 fp = get rz_plan 3 214 rchk and gt wb 0 ge fp wb 215 if eq rid RZ_R5_DENSE5 216 check_dense5_decode m n 217 end 218 end 219 220 fn run_case m ulong n ulong wk int sp f64 xk int lib_chk int to void 221 r_fill_w mul m n wk sp 222 r_fill_x n xk 223 rchk eq oma_rz_oracle_g m n OMA_RZ_OK 224 if ne lib_chk 0 225 check_oracle_vs_lib m n 226 end 227 for rid ulong OMA_RZ_COUNT 228 run_one_rz rid m n 229 end 230 end 231 232 fn test_rejections to void 233 put rz_w 0 byte 1 234 put rz_w 1 byte 0 235 put rz_w 2 byte -1 236 put rz_w 3 byte 2 237 put rz_w 4 byte 0 238 put rz_w 5 byte 1 239 for rid ulong OMA_RZ_COUNT 240 put rz_w 3 byte 2 241 rchk eq oma_rz_pack_g rid 2 3 OMA_RZ_E_TRIT 242 put rz_w 3 byte -2 243 rchk eq oma_rz_pack_g rid 2 3 OMA_RZ_E_TRIT 244 put rz_w 3 byte -128 245 rchk eq oma_rz_pack_g rid 2 3 OMA_RZ_E_TRIT 246 put rz_w 3 byte 2 247 rchk eq oma_rz_pack_g rid 0 3 OMA_RZ_E_ARG 248 rchk eq oma_rz_pack_g rid 2 0 OMA_RZ_E_ARG 249 rchk eq oma_rz_pack_g rid 1 add OMA_RZ_MAX_N 1 OMA_RZ_E_ARG 250 rchk le oma_rz_max_n rid OMA_RZ_MAX_N 251 put rz_plan 5 0 252 rchk eq oma_rz_run_g OMA_RZ_E_ARG 253 end 254 rchk le mul long 128 long OMA_RZ_MAX_N long `2147483647` 255 rchk gt mul long 128 add long OMA_RZ_MAX_N 1 long `2147483647` 256 end 257 258 note ---- selector tie rule (ADR 0019 section 9.1) ---- 259 260 fn sel_reset nruns int to void 261 put st_nruns 0 nruns 262 put st_nrows 0 ulong 0 263 end 264 265 fn sel_row run int rz ulong med f64 noise f64 to void 266 idx = get st_nrows 0 267 put st_run idx run 268 put st_rz idx rz 269 put st_ver idx 1 270 put st_med idx med 271 put st_noise idx noise 272 put st_nrows 0 add idx 1 273 end 274 275 fn sel_in_tset rz ulong to bool 276 nt = get sd_ntie 0 277 for i ulong nt bound 16 278 if eq get sd_tset i rz 279 ret true 280 end 281 end 282 ret false 283 end 284 285 fn sel_eval_cand k ulong to void 286 nr = get st_nrows 0 287 seen = int 0 288 bad = int 0 289 sumc = 0.0f64 290 lo = `1000000000`.0f64 291 hi = 0.0f64 292 wn = 0.0f64 293 for i ulong nr bound 64 294 if eq get st_rz i k 295 if eq get st_ver i 0 296 bad = 1 297 else 298 c = get st_med i 299 sumc = add sumc c 300 if lt c lo 301 lo = c 302 end 303 if gt c hi 304 hi = c 305 end 306 nz = get st_noise i 307 if gt nz wn 308 wn = nz 309 end 310 seen = add seen 1 311 end 312 end 313 end 314 if or ne bad 0 eq seen 0 315 put sc_elig k 0 316 ret 317 end 318 mean = div sumc f64 seen 319 put sc_elig k 1 320 put sc_cost k mean 321 put sc_wn k wn 322 if gt seen 1 323 put sc_cn k div sub hi lo mean 324 else 325 put sc_cn k 0.0f64 326 end 327 end 328 329 fn sel_find_top dst edit ulong 2 to void 330 w = int -1 331 u = int -1 332 for k ulong OMA_RZ_COUNT 333 if ne get sc_elig k 0 334 ck = get sc_cost k 335 if lt w 0 336 w = int k 337 else 338 if lt ck get sc_cost ulong w 339 u = w 340 w = int k 341 else 342 if lt u 0 343 u = int k 344 else 345 if lt ck get sc_cost ulong u 346 u = int k 347 end 348 end 349 end 350 end 351 end 352 end 353 put dst 0 ulong w 354 put dst 1 ulong u 355 end 356 357 fn sel_decide inc ulong to void 358 for k ulong OMA_RZ_COUNT 359 sel_eval_cand k 360 end 361 top2 = new ulong 2 0 362 sel_find_top top2 363 wu = get top2 0 364 uu = get top2 1 365 put sd_chosen 0 wu 366 put sd_cheapest 0 wu 367 put sd_runner 0 uu 368 put sd_chosen_ns 0 get sc_cost wu 369 put sd_res 0 SEL_RES_NONE 370 band = get sc_wn wu 371 if gt get sc_wn uu band 372 band = get sc_wn uu 373 end 374 if gt get sc_cn wu band 375 band = get sc_cn wu 376 end 377 if gt get sc_cn uu band 378 band = get sc_cn uu 379 end 380 cw = get sc_cost wu 381 put sd_tset 0 wu 382 nt = ulong 1 383 for k ulong OMA_RZ_COUNT 384 if and ne get sc_elig k 0 ne k wu 385 if le div sub get sc_cost k cw cw band 386 put sd_tset nt k 387 nt = add nt 1 388 end 389 end 390 end 391 put sd_ntie 0 nt 392 if le nt 1 393 put sd_tie 0 0 394 ret 395 end 396 put sd_tie 0 1 397 if and ne inc SEL_NO_INC sel_in_tset inc 398 put sd_chosen 0 inc 399 put sd_chosen_ns 0 get sc_cost inc 400 put sd_res 0 SEL_RES_INCUMBENT 401 else 402 if sel_in_tset RZ_R1_PLAIN 403 put sd_chosen 0 RZ_R1_PLAIN 404 put sd_chosen_ns 0 get sc_cost RZ_R1_PLAIN 405 put sd_res 0 SEL_RES_REFERENCE 406 else 407 put sd_res 0 SEL_RES_CHEAPEST 408 end 409 end 410 end 411 412 fn sel_expect tie int chosen ulong res int to void 413 rchk and eq get sd_tie 0 tie and eq get sd_chosen 0 chosen eq get sd_res 0 res 414 rchk sel_in_tset get sd_chosen 0 415 if gt get sd_ntie 0 1 416 rchk eq get sd_tie 0 1 417 else 418 rchk eq get sd_tie 0 0 419 end 420 end 421 422 fn test_selector_tie_rule to void 423 sel_reset 1 424 sel_row 0 RZ_R1_SDOT 100.0f64 0.05f64 425 sel_row 0 RZ_R1_SMMLA 101.0f64 0.05f64 426 sel_row 0 RZ_R1_PLAIN 300.0f64 0.05f64 427 sel_decide SEL_NO_INC 428 rchk and eq get sd_cheapest 0 RZ_R1_SDOT eq get sd_runner 0 RZ_R1_SMMLA 429 sel_expect 1 RZ_R1_SDOT SEL_RES_CHEAPEST 430 rchk and eq get sd_ntie 0 2 and sel_in_tset RZ_R1_SDOT and sel_in_tset RZ_R1_SMMLA not sel_in_tset RZ_R1_PLAIN 431 rchk eq get sd_chosen_ns 0 100.0f64 432 sel_decide RZ_R1_SMMLA 433 sel_expect 1 RZ_R1_SMMLA SEL_RES_INCUMBENT 434 rchk eq get sd_chosen_ns 0 101.0f64 435 sel_decide RZ_R1_SDOT 436 sel_expect 1 RZ_R1_SDOT SEL_RES_INCUMBENT 437 sel_decide RZ_R1_PLAIN 438 sel_expect 1 RZ_R1_SDOT SEL_RES_CHEAPEST 439 sel_decide RZ_R4_RNS 440 sel_expect 1 RZ_R1_SDOT SEL_RES_CHEAPEST 441 442 sel_reset 1 443 sel_row 0 RZ_R1_SDOT 100.0f64 0.05f64 444 sel_row 0 RZ_R1_SMMLA 101.0f64 0.05f64 445 sel_row 0 RZ_R1_PLAIN 103.0f64 0.05f64 446 sel_row 0 RZ_R2C_CRUMB 200.0f64 0.05f64 447 sel_decide SEL_NO_INC 448 sel_expect 1 RZ_R1_PLAIN SEL_RES_REFERENCE 449 rchk and eq get sd_ntie 0 3 not sel_in_tset RZ_R2C_CRUMB 450 rchk eq get sd_chosen_ns 0 103.0f64 451 sel_decide RZ_R1_SMMLA 452 sel_expect 1 RZ_R1_SMMLA SEL_RES_INCUMBENT 453 sel_decide RZ_R2C_CRUMB 454 sel_expect 1 RZ_R1_PLAIN SEL_RES_REFERENCE 455 456 sel_reset 1 457 sel_row 0 RZ_R1_SDOT 100.0f64 0.01f64 458 sel_row 0 RZ_R1_SMMLA 150.0f64 0.01f64 459 sel_row 0 RZ_R1_PLAIN 300.0f64 0.01f64 460 sel_decide RZ_R1_PLAIN 461 sel_expect 0 RZ_R1_SDOT SEL_RES_NONE 462 rchk and eq get sd_ntie 0 1 and sel_in_tset RZ_R1_SDOT not sel_in_tset RZ_R1_SMMLA 463 464 sel_reset 1 465 sel_row 0 RZ_R1_SDOT 100.0f64 0.05f64 466 sel_row 0 RZ_R1_SMMLA 101.0f64 0.05f64 467 sel_decide SEL_NO_INC 468 sel_expect 1 RZ_R1_SDOT SEL_RES_CHEAPEST 469 470 sel_reset 2 471 sel_row 0 RZ_R1_SDOT 100.0f64 0.05f64 472 sel_row 0 RZ_R1_SMMLA 101.0f64 0.05f64 473 sel_row 0 RZ_R1_PLAIN 102.0f64 0.05f64 474 sel_row 1 RZ_R1_SDOT 100.0f64 0.05f64 475 sel_row 1 RZ_R1_SMMLA 101.0f64 0.05f64 476 sel_row 1 RZ_R1_PLAIN 102.0f64 0.05f64 477 put st_ver 5 0 478 sel_decide SEL_NO_INC 479 sel_expect 1 RZ_R1_SDOT SEL_RES_CHEAPEST 480 rchk not sel_in_tset RZ_R1_PLAIN 481 482 sel_reset 2 483 sel_row 0 RZ_R1_SDOT 100.0f64 0.001f64 484 sel_row 0 RZ_R1_SMMLA 104.0f64 0.001f64 485 sel_row 0 RZ_R1_PLAIN 300.0f64 0.001f64 486 sel_row 1 RZ_R1_SDOT 104.0f64 0.001f64 487 sel_row 1 RZ_R1_SMMLA 100.0f64 0.001f64 488 sel_row 1 RZ_R1_PLAIN 300.0f64 0.001f64 489 sel_decide SEL_NO_INC 490 rchk and eq get sd_tie 0 1 eq get sd_ntie 0 2 491 rchk and ne get sd_chosen 0 RZ_R1_PLAIN eq get sd_res 0 SEL_RES_CHEAPEST 492 rchk sel_in_tset get sd_chosen 0 493 end 494 495 fn run_structured_grid to void 496 ns = new ulong 23 0 497 put ns 0 1 498 put ns 1 2 499 put ns 2 3 500 put ns 3 4 501 put ns 4 5 502 put ns 5 7 503 put ns 6 15 504 put ns 7 16 505 put ns 8 17 506 put ns 9 31 507 put ns 10 32 508 put ns 11 33 509 put ns 12 63 510 put ns 13 64 511 put ns 14 65 512 put ns 15 79 513 put ns 16 80 514 put ns 17 81 515 put ns 18 127 516 put ns 19 128 517 put ns 20 129 518 put ns 21 255 519 put ns 22 257 520 ms = new ulong 8 0 521 put ms 0 1 522 put ms 1 2 523 put ms 2 3 524 put ms 3 4 525 put ms 4 7 526 put ms 5 15 527 put ms 6 16 528 put ms 7 17 529 sps = new f64 5 0.0f64 530 put sps 0 0.0f64 531 put sps 1 0.3f64 532 put sps 2 0.6f64 533 put sps 3 0.9f64 534 put sps 4 1.0f64 535 for a ulong 23 536 for b ulong 8 537 mv = get ms b 538 nv = get ns a 539 run_case mv nv 1 0.0f64 0 0 540 run_case mv nv 2 0.0f64 1 0 541 run_case mv nv 2 0.0f64 2 0 542 run_case mv nv 3 0.0f64 1 0 543 run_case mv nv 3 0.0f64 2 0 544 run_case mv nv 0 get sps rem add a b 5 3 1 545 run_case mv nv 0 get sps rem add mul a 3 b 5 0 1 546 end 547 end 548 end 549 550 fn main to int 551 put r_rng 0 ulong 0x4d41332d7265616c 552 test_rejections 553 run_structured_grid 554 for it ulong 100 555 n = add 1 rem rrnd 1200 556 m = add 1 rem rrnd 40 557 xk = int rem rrnd 5 558 lc = int 0 559 if eq rem it 4 0 560 lc = 1 561 end 562 run_case m n 0 rrnd01 xk lc 563 end 564 run_case 5 16384 3 0.0f64 1 0 565 run_case 5 16384 2 0.0f64 1 0 566 run_case 3 64512 3 0.0f64 1 0 567 run_case 3 64512 2 0.0f64 1 0 568 run_case 2 64513 3 0.0f64 1 0 569 run_case 2 65536 0 0.5f64 0 0 570 run_case 2 65537 3 0.0f64 1 0 571 run_case 1 100003 3 0.0f64 1 0 572 run_case 17 4099 0 0.97f64 0 1 573 test_selector_tie_rule 574 575 if eq get r_chk 1 0 576 oma_put_str r_hdr_p 577 else 578 oma_put_str r_hdr_f 579 end 580 oma_put_u64 1 get r_chk 0 581 oma_put_str r_chk_s 582 oma_put_u64 1 get r_chk 1 583 oma_put_str r_rz_s 584 if eq get r_chk 1 0 585 ret 0 586 end 587 ret 1 588 end