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/bench/prime_race/tests/prime_race_host_test.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 / bench / prime_race / tests / prime_race_host_test.om` 555 lines ยท 14038 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 note Pure seeded OM-2 host test for the prime race protocol helper and cpu_base baseline. 4 note Oracle: independent trial division (no sieve). Compares canonical bitmaps word for word. 5 note Concatenated after bench/prime_race/prime_race_impl.om and bench/prime_race/cpu_base.om. 6 7 global ht_checks ulong 1 8 global ht_fail ulong 1 9 global ht_nlim ulong 1 10 global ht_lims ulong 8192 11 global ht_master ulong 32768 12 global ht_exp ulong 32768 13 global ht_bad ulong 32768 14 global ht_saved ulong 32768 15 16 text ht_t_fail "FAIL check: " 17 text ht_t_nl "\n" 18 text ht_t_design "design limits checked: " 19 text ht_t_sum1 "prime_race_host_test: " 20 text ht_t_sum2 " checks, " 21 text ht_t_sum3 " failures\n" 22 text ht_t_pass "PRIME_RACE_HOST_TEST PASS\n" 23 text ht_t_fail_end "PRIME_RACE_HOST_TEST FAIL\n" 24 text ht_t_expect_line "aien-cpu-c-base;1234;5.000123;1;algorithm=base,faithful=yes,bits=1" 25 text ht_t_json_in "a\"b\\c\n\t" 26 text ht_t_json_expect "\"a\\\"b\\\\c\\n\\t\\u0001z\"" 27 text ht_t_s_schema "\"schema\": \"aien-prime-race/impl-report/v1\"" 28 text ht_t_s_label "\"label\": \"aien-cpu-c-base\"" 29 text ht_t_s_ok "\"status\": \"COMPLETE\"" 30 text ht_t_s_null "\"error\": null" 31 text ht_t_s_passes "\"passes\": 7" 32 text ht_t_s_elap "\"elapsed_s\": 5.250000" 33 text ht_t_s_env "\"environment\": \"linux-host-cpu\"" 34 text ht_t_s_build "\"build\": {\"source_commit\"" 35 text ht_t_s_boom "boom \"x\"" 36 text ht_t_s_boomesc "\"error\": \"boom \\\"x\\\"\"" 37 text ht_t_a_x "x" 38 text ht_t_a_1000 "1000" 39 text ht_t_a_05 "0.5" 40 text ht_t_a_3 "3" 41 text ht_t_a_tmpb "/tmp/b" 42 text ht_t_a_12abc "12abc" 43 text ht_t_a_neg5 "-5" 44 text ht_t_a_2p40p1 "`1099511627777`" 45 text ht_t_a_2p40 "`1099511627776`" 46 text ht_t_a_nan "nan" 47 text ht_t_a_0 "0" 48 text ht_t_a_2 "2" 49 text ht_t_a_bogus "--bogus" 50 text ht_t_empty "" 51 text ht_t_m_lim "limit mismatch" 52 text ht_t_m_mpfx "master prefix disagrees" 53 text ht_t_m_pi "pi(limit) mismatch" 54 text ht_t_m_neg "negative control failed" 55 text ht_t_m_rep "repeat pass failed" 56 text ht_t_m_fmt "formatting check failed" 57 text ht_t_m_arg "arg parse check failed" 58 59 fn ht_check cond bool msg view uchar * to void 60 put ht_checks 0 add get ht_checks 0 1 61 if not cond 62 put ht_fail 0 add get ht_fail 0 1 63 ign1 = pr_write_all 2 view ht_t_fail len ht_t_fail 64 ign2 = pr_write_all 2 msg len msg 65 ign3 = pr_write_all 2 view ht_t_nl len ht_t_nl 66 end 67 end 68 69 fn ht_is_prime_td n ulong to int 70 if lt n 2 71 ret 0 72 end 73 if eq and n 1 0 74 if eq n 2 75 ret 1 76 end 77 ret 0 78 end 79 d = ulong 3 80 while le mul d d n bound `9223372036854775807` 81 if eq rem n d 0 82 ret 0 83 end 84 d = add d 2 85 end 86 ret 1 87 end 88 89 fn ht_oracle_exp limit ulong to void 90 nw = pr_words64 limit 91 for w ulong nw bound `9223372036854775807` 92 put ht_exp w 0 93 end 94 odd = pr_odd_count limit 95 for k ulong odd bound `9223372036854775807` 96 if ne ht_is_prime_td add shl k 1 1 0 97 w = shr k 6 98 b = and k 63 99 put ht_exp w or get ht_exp w shl ulong 1 b 100 end 101 end 102 end 103 104 fn ht_oracle_master limit ulong to void 105 nw = pr_words64 limit 106 for w ulong nw bound `9223372036854775807` 107 put ht_master w 0 108 end 109 odd = pr_odd_count limit 110 for k ulong odd bound `9223372036854775807` 111 if ne ht_is_prime_td add shl k 1 1 0 112 w = shr k 6 113 b = and k 63 114 put ht_master w or get ht_master w shl ulong 1 b 115 end 116 end 117 end 118 119 fn ht_popcount64 x ulong to ulong 120 v = x 121 v = sub v and shr v 1 0x5555555555555555 122 v = add and v 0x3333333333333333 and shr v 2 0x3333333333333333 123 v = and add v shr v 4 0x0f0f0f0f0f0f0f0f 124 ret shr mul v 0x0101010101010101 56 125 end 126 127 fn ht_count_primes_cpu limit ulong to ulong 128 c = ulong 0 129 if ge limit 2 130 c = 1 131 end 132 nw = pr_words64 limit 133 for w ulong nw bound `9223372036854775807` 134 c = add c ht_popcount64 cpu_get_export_word w 135 end 136 ret c 137 end 138 139 fn ht_first_diff_exp_cpu nw ulong to long 140 for w ulong nw bound `9223372036854775807` 141 if ne get ht_exp w cpu_get_export_word w 142 ret long w 143 end 144 end 145 ret -1 146 end 147 148 fn ht_first_diff_exp_bad nw ulong to long 149 for w ulong nw bound `9223372036854775807` 150 if ne get ht_exp w get ht_bad w 151 ret long w 152 end 153 end 154 ret -1 155 end 156 157 fn ht_first_diff_saved_cpu nw ulong to long 158 for w ulong nw bound `9223372036854775807` 159 if ne get ht_saved w cpu_get_export_word w 160 ret long w 161 end 162 end 163 ret -1 164 end 165 166 fn ht_run_cpu limit ulong to int 167 if ne cpu_setup limit 0 168 ret -1 169 end 170 if ne cpu_pass limit 0 171 ret -1 172 end 173 if ne cpu_export limit 0 174 ret -1 175 end 176 ret 0 177 end 178 179 fn ht_check_limit limit ulong to void 180 ok = ht_run_cpu limit 181 ht_check eq ok 0 view ht_t_m_lim 182 if ne ok 0 183 ret 184 end 185 d = ht_first_diff_exp_cpu pr_words64 limit 186 ht_check lt d 0 view ht_t_m_lim 187 end 188 189 fn ht_addlim l ulong to void 190 n = get ht_nlim 0 191 if and le l `2000000` lt n 8192 192 put ht_lims n l 193 put ht_nlim 0 add n 1 194 end 195 end 196 197 fn ht_addrange a ulong b ulong to void 198 l = a 199 while le l b bound `1000000` 200 ht_addlim l 201 l = add l 1 202 end 203 end 204 205 fn ht_buf_eq a view uchar * alen ulong b view uchar * to bool 206 if ne alen len b 207 ret false 208 end 209 for i ulong alen 210 if ne get a i get b i 211 ret false 212 end 213 end 214 ret true 215 end 216 217 fn ht_buf_contains hay view uchar * hlen ulong needle view uchar * to bool 218 nlen = len needle 219 if eq nlen 0 220 ret true 221 end 222 if gt nlen hlen 223 ret false 224 end 225 lim = add sub hlen nlen 1 226 for i ulong lim 227 ok = true 228 for j ulong nlen 229 if ne get hay add i j get needle j 230 ok = false 231 break 232 end 233 end 234 if ok 235 ret true 236 end 237 end 238 ret false 239 end 240 241 fn ht_set_arg idx ulong s view uchar * to void 242 n = len s 243 base = mul idx 256 244 for i ulong n 245 put pr_argv add base i get s i 246 end 247 put pr_arglen idx n 248 end 249 250 fn ht_set_empty_arg idx ulong to void 251 put pr_arglen idx 0 252 end 253 254 fn ht_test_fmt_report to void 255 rbuf = new uchar 2048 0 256 rep1 = new PrReport 1 100 5.0f64 0 7 5.25f64 0 257 rlen = pr_build_report edit rbuf 2048 view rep1 part ht_t_empty 0 0 258 ht_check gt rlen 0 view ht_t_m_fmt 259 if gt rlen 0 260 rl = ulong rlen 261 ht_check ht_buf_contains view rbuf rl view ht_t_s_schema view ht_t_m_fmt 262 ht_check ht_buf_contains view rbuf rl view ht_t_s_label view ht_t_m_fmt 263 ht_check ht_buf_contains view rbuf rl view ht_t_s_ok view ht_t_m_fmt 264 ht_check ht_buf_contains view rbuf rl view ht_t_s_null view ht_t_m_fmt 265 ht_check ht_buf_contains view rbuf rl view ht_t_s_passes view ht_t_m_fmt 266 ht_check ht_buf_contains view rbuf rl view ht_t_s_elap view ht_t_m_fmt 267 ht_check ht_buf_contains view rbuf rl view ht_t_s_env view ht_t_m_fmt 268 ht_check ht_buf_contains view rbuf rl view ht_t_s_build view ht_t_m_fmt 269 end 270 271 rep2 = new PrReport 1 100 5.0f64 0 7 5.25f64 1 272 rlen2 = pr_build_report edit rbuf 2048 view rep2 view ht_t_s_boom 273 ht_check gt rlen2 0 view ht_t_m_fmt 274 if gt rlen2 0 275 ht_check ht_buf_contains view rbuf ulong rlen2 view ht_t_s_boomesc view ht_t_m_fmt 276 end 277 end 278 279 fn ht_test_formatting to void 280 buf = new uchar 512 0 281 n = pr_format_line edit buf 512 1234 5.`000123456f64` 1 282 ht_check gt n 0 view ht_t_m_fmt 283 if gt n 0 284 ht_check ht_buf_eq view buf ulong n view ht_t_expect_line view ht_t_m_fmt 285 end 286 tiny = new uchar 8 0 287 ht_check lt pr_format_line edit tiny 8 1 1.0f64 1 0 view ht_t_m_fmt 288 ht_check eq pr_line_allowed 0 1 5.0f64 5.0f64 1 view ht_t_m_fmt 289 ht_check eq pr_line_allowed 1 1 5.0f64 5.0f64 0 view ht_t_m_fmt 290 ht_check eq pr_line_allowed 0 0 5.0f64 5.0f64 0 view ht_t_m_fmt 291 ht_check eq pr_line_allowed 0 3 4.999f64 5.0f64 0 view ht_t_m_fmt 292 293 jin = new uchar 9 0 294 for i ulong 7 295 put jin i get ht_t_json_in i 296 end 297 put jin 7 1 298 put jin 8 122 299 jout = new uchar 64 0 300 jlen = pr_json_string edit jout 0 64 view jin 301 ht_check ht_buf_eq view jout jlen view ht_t_json_expect view ht_t_m_fmt 302 ht_test_fmt_report 303 end 304 305 fn ht_test_args to void 306 a = new PrArgs 0 0.0f64 0 0 0 307 put pr_argc 0 9 308 ht_set_arg 0 view ht_t_a_x 309 ht_set_arg 1 view pr_t_opt_limit 310 ht_set_arg 2 view ht_t_a_1000 311 ht_set_arg 3 view pr_t_opt_minsec 312 ht_set_arg 4 view ht_t_a_05 313 ht_set_arg 5 view pr_t_opt_audit 314 ht_set_arg 6 view ht_t_a_3 315 ht_set_arg 7 view pr_t_opt_bmout 316 ht_set_arg 8 view ht_t_a_tmpb 317 rc1 = pr_parse_args edit a 318 ht_check eq rc1 0 view ht_t_m_arg 319 ht_check eq get a limit 1000 view ht_t_m_arg 320 ht_check eq get a min_sec 0.5f64 view ht_t_m_arg 321 ht_check eq get a audit_passes 3 view ht_t_m_arg 322 323 put pr_argc 0 1 324 ht_set_arg 0 view ht_t_a_x 325 rc2 = pr_parse_args edit a 326 ht_check eq rc2 0 view ht_t_m_arg 327 ht_check eq get a limit `1000000` view ht_t_m_arg 328 ht_check eq get a min_sec 5.0f64 view ht_t_m_arg 329 ht_check eq get a audit_passes 0 view ht_t_m_arg 330 331 put pr_argc 0 3 332 ht_set_arg 1 view pr_t_opt_limit 333 ht_set_arg 2 view ht_t_a_12abc 334 ht_check ne pr_parse_args edit a 0 view ht_t_m_arg 335 336 ht_set_arg 2 view ht_t_a_neg5 337 ht_check ne pr_parse_args edit a 0 view ht_t_m_arg 338 339 ht_set_arg 2 view ht_t_a_2p40p1 340 ht_check ne pr_parse_args edit a 0 view ht_t_m_arg 341 342 put pr_argc 0 2 343 ht_check ne pr_parse_args edit a 0 view ht_t_m_arg 344 345 put pr_argc 0 3 346 ht_set_arg 1 view pr_t_opt_minsec 347 ht_set_arg 2 view ht_t_a_nan 348 ht_check ne pr_parse_args edit a 0 view ht_t_m_arg 349 350 put pr_argc 0 5 351 ht_set_arg 1 view pr_t_opt_audit 352 ht_set_arg 2 view ht_t_a_0 353 ht_set_arg 3 view pr_t_opt_bmout 354 ht_set_arg 4 view ht_t_a_tmpb 355 ht_check ne pr_parse_args edit a 0 view ht_t_m_arg 356 357 put pr_argc 0 2 358 ht_set_arg 1 view ht_t_a_bogus 359 ht_check ne pr_parse_args edit a 0 view ht_t_m_arg 360 361 put pr_argc 0 3 362 ht_set_arg 1 view pr_t_opt_audit 363 ht_set_arg 2 view ht_t_a_2 364 ht_check ne pr_parse_args edit a 0 view ht_t_m_arg 365 366 put pr_argc 0 3 367 ht_set_arg 1 view pr_t_opt_limit 368 ht_set_empty_arg 2 369 ht_check ne pr_parse_args edit a 0 view ht_t_m_arg 370 371 ht_set_arg 2 view ht_t_a_2p40 372 ht_check eq pr_parse_args edit a 0 view ht_t_m_arg 373 end 374 375 fn ht_test_negative_one limit ulong to void 376 nw = pr_words64 limit 377 ht_oracle_exp limit 378 for w ulong nw 379 put ht_bad w get ht_exp w 380 end 381 ht_check lt ht_first_diff_exp_bad nw 0 view ht_t_m_neg 382 mid = shr nw 1 383 put ht_bad mid xor get ht_bad mid 2 384 ht_check eq ht_first_diff_exp_bad nw long mid view ht_t_m_neg 385 for w ulong nw 386 put ht_bad w get ht_exp w 387 end 388 odd = pr_odd_count limit 389 if ne and odd 63 0 390 last = sub nw 1 391 put ht_bad last or get ht_bad last shl ulong 1 63 392 ht_check ge ht_first_diff_exp_bad nw 0 view ht_t_m_neg 393 end 394 for w ulong nw 395 put ht_bad w 0 396 end 397 ht_check ge ht_first_diff_exp_bad nw 0 view ht_t_m_neg 398 end 399 400 fn ht_test_negative to void 401 ht_test_negative_one 100 402 ht_test_negative_one 1000 403 ht_test_negative_one 4097 404 ht_test_negative_one `1000000` 405 end 406 407 fn ht_test_repeat_pass to void 408 lim = ulong 12345 409 nw = pr_words64 lim 410 ht_check eq cpu_setup lim 0 view ht_t_m_rep 411 ht_check and eq cpu_pass lim 0 eq cpu_export lim 0 view ht_t_m_rep 412 for w ulong nw 413 put ht_saved w cpu_get_export_word w 414 end 415 ht_check and eq cpu_pass lim 0 eq cpu_export lim 0 view ht_t_m_rep 416 ht_check lt ht_first_diff_saved_cpu nw 0 view ht_t_m_rep 417 ht_check eq cpu_threads 1 view ht_t_m_rep 418 end 419 420 fn ht_test_pi_one lim ulong expect_pi ulong to void 421 ok = ht_run_cpu lim 422 ht_check eq ok 0 view ht_t_m_pi 423 if ne ok 0 424 ret 425 end 426 c = ht_count_primes_cpu lim 427 ht_check eq c expect_pi view ht_t_m_pi 428 end 429 430 fn ht_test_pi_table to void 431 ht_test_pi_one 10 4 432 ht_test_pi_one 100 25 433 ht_test_pi_one 1000 168 434 ht_test_pi_one 10000 1229 435 ht_test_pi_one 100000 9592 436 ht_test_pi_one `1000000` 78498 437 ht_test_pi_one `10000000` 664579 438 end 439 440 fn ht_test_all_small to void 441 for lim ulong 3001 442 ht_oracle_exp lim 443 ht_check_limit lim 444 end 445 end 446 447 fn ht_check_design_one lim ulong to void 448 nw = pr_words64 lim 449 odd = pr_odd_count lim 450 for w ulong nw 451 put ht_exp w get ht_master w 452 end 453 if and gt nw 0 ne and odd 63 0 454 mask = sub shl ulong 1 and odd 63 1 455 last = sub nw 1 456 put ht_exp last and get ht_exp last mask 457 end 458 if le lim 3000 459 for w ulong nw 460 put ht_bad w get ht_exp w 461 end 462 ht_oracle_exp lim 463 ht_check lt ht_first_diff_exp_bad nw 0 view ht_t_m_mpfx 464 end 465 ht_check_limit lim 466 end 467 468 fn ht_test_design_limits to void 469 put ht_nlim 0 0 470 ht_addlim 0 471 ht_addlim 1 472 ht_addlim 2 473 ht_addlim 3 474 ht_addlim 4 475 ht_addlim 5 476 ht_addlim 8 477 ht_addlim 9 478 ht_addlim 15 479 ht_addlim 25 480 ht_addlim 49 481 ht_addlim 121 482 ht_addlim 169 483 ht_addlim 289 484 ht_addlim 361 485 ht_addlim 961 486 ht_addlim `1000000` 487 ht_addlim `2000000` 488 ht_addrange 31 34 489 ht_addrange 63 66 490 ht_addrange 95 97 491 ht_addrange 127 130 492 ht_addrange 255 258 493 ht_addrange 1023 1025 494 ht_addrange 1999 2001 495 ht_addrange 4095 4097 496 ht_addrange 999983 `1000003` 497 k = ulong 1 498 while le mul 2048 k `2000000` bound 2000 499 v = mul 2048 k 500 ht_addlim sub v 1 501 ht_addlim v 502 ht_addlim add v 1 503 k = add k 1 504 end 505 p = ulong 2 506 while le p 997 bound 1000 507 if ne ht_is_prime_td p 0 508 pp = mul p p 509 ht_addlim sub pp 1 510 ht_addlim pp 511 ht_addlim add pp 1 512 end 513 p = add p 1 514 end 515 516 ht_oracle_master `2000000` 517 nlim = get ht_nlim 0 518 for i ulong nlim 519 ht_check_design_one get ht_lims i 520 end 521 522 msg = new uchar 128 0 523 pos = ulong 0 524 pos = pr_buf_put_str edit msg pos 128 view ht_t_design 525 pos = pr_buf_put_u64 edit msg pos 128 nlim 526 pos = pr_buf_put_byte edit msg pos 128 10 527 ign = pr_write_all 1 view msg pos 528 end 529 530 fn main to int 531 put ht_checks 0 0 532 put ht_fail 0 0 533 ht_test_formatting 534 ht_test_args 535 ht_test_negative 536 ht_test_repeat_pass 537 ht_test_pi_table 538 ht_test_all_small 539 ht_test_design_limits 540 541 msg = new uchar 128 0 542 pos = ulong 0 543 pos = pr_buf_put_str edit msg pos 128 view ht_t_sum1 544 pos = pr_buf_put_u64 edit msg pos 128 get ht_checks 0 545 pos = pr_buf_put_str edit msg pos 128 view ht_t_sum2 546 pos = pr_buf_put_u64 edit msg pos 128 get ht_fail 0 547 pos = pr_buf_put_str edit msg pos 128 view ht_t_sum3 548 ign1 = pr_write_all 1 view msg pos 549 if ne get ht_fail 0 0 550 ign2 = pr_write_all 1 view ht_t_fail_end len ht_t_fail_end 551 ret 1 552 end 553 ign3 = pr_write_all 1 view ht_t_pass len ht_t_pass 554 ret 0 555 end