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
omega-mv / src / searchtrace / st_corpus.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | note src/searchtrace/st_corpus.om: Pure seeded OM-2 M23 G1 search-trace corpus |
| 4 | note generator, strict verifier, task-set parser, hook API, and hook equivalence. |
| 5 | note Compose after st_holdout.om (reuses sh_dat/sh_all/sh_dig and sth_hex_nib). |
| 6 | |
| 7 | const STC_MAX_TASKS ulong 64 |
| 8 | const STC_MAX_PAIRS ulong 16 |
| 9 | const STC_MAX_PRIMS ulong 15 |
| 10 | const STC_MAX_CANDS ulong 512 |
| 11 | const STC_MAX_SIGS ulong 1024 |
| 12 | const STC_OUT_CAP ulong 2097152 |
| 13 | |
| 14 | const STC_PRUNE_NONE ulong 0 |
| 15 | const STC_PRUNE_TYPE ulong 1 |
| 16 | const STC_PRUNE_COST ulong 2 |
| 17 | const STC_PRUNE_EQUIV ulong 3 |
| 18 | const STC_PRUNE_BUDGET ulong 4 |
| 19 | |
| 20 | const STC_VERD_NONE ulong 0 |
| 21 | const STC_VERD_REJECT ulong 1 |
| 22 | const STC_VERD_SOLVED ulong 2 |
| 23 | const STC_VERD_VFAIL ulong 3 |
| 24 | |
| 25 | text stc_t_ts_magic "OMEGA-SEARCHTRACE-TASKSET v1" |
| 26 | text stc_t_c_magic "OMEGA-SEARCHTRACE v1" |
| 27 | text stc_t_end "end" |
| 28 | text stc_t_tasksp "task " |
| 29 | text stc_t_endsp "end " |
| 30 | text stc_t_tssp "taskset " |
| 31 | text stc_t_machsp "machine " |
| 32 | text stc_t_stepsp "step " |
| 33 | text stc_t_ressp "result " |
| 34 | text stc_t_dash "-" |
| 35 | text stc_t_nl "\n" |
| 36 | |
| 37 | text stc_k_depth "depth" |
| 38 | text stc_k_mcost "max_cost" |
| 39 | text stc_k_mcand "max_candidates" |
| 40 | text stc_k_dedup "dedup" |
| 41 | text stc_k_pairs "pairs" |
| 42 | text stc_k_bank "bank" |
| 43 | text stc_k_tasks "tasks" |
| 44 | text stc_k_steps "steps" |
| 45 | text stc_k_digest "digest" |
| 46 | text stc_k_name "name" |
| 47 | text stc_k_tid "task_id" |
| 48 | text stc_k_ex "examples" |
| 49 | text stc_k_solved "solved" |
| 50 | text stc_k_sol "solution" |
| 51 | text stc_k_gen "generated" |
| 52 | text stc_k_pt "pruned_type" |
| 53 | text stc_k_pe "pruned_equiv" |
| 54 | text stc_k_fail "failed" |
| 55 | text stc_k_sols "solutions" |
| 56 | text stc_k_d "d" |
| 57 | text stc_k_parent "parent" |
| 58 | text stc_k_prim "prim" |
| 59 | text stc_k_pname "pname" |
| 60 | text stc_k_xform "transform" |
| 61 | text stc_k_child "child" |
| 62 | text stc_k_nsteps "nsteps" |
| 63 | text stc_k_insn "insn" |
| 64 | text stc_k_body "body" |
| 65 | text stc_k_sig "sig" |
| 66 | text stc_k_prune "prune" |
| 67 | text stc_k_verd "verdict" |
| 68 | text stc_k_erc "erc" |
| 69 | text stc_k_vrc "vrc" |
| 70 | text stc_k_rrc "rrc" |
| 71 | text stc_k_rbytes "rbytes" |
| 72 | text stc_k_rcycles "rcycles" |
| 73 | text stc_k_rchk "rchecked" |
| 74 | |
| 75 | text stc_pn_0 "none" |
| 76 | text stc_pn_1 "type" |
| 77 | text stc_pn_2 "cost" |
| 78 | text stc_pn_3 "equiv" |
| 79 | text stc_pn_4 "budget" |
| 80 | |
| 81 | text stc_vn_0 "none" |
| 82 | text stc_vn_1 "reject" |
| 83 | text stc_vn_2 "solved" |
| 84 | text stc_vn_3 "verify_fail" |
| 85 | |
| 86 | text stc_m_name "NVIDIA_DGX_SPARK_GRACE_V2" |
| 87 | text stc_dom_prog "omega.program.v2" |
| 88 | text stc_attr_param "omega.param" |
| 89 | text stc_attr_comp "omega.compose" |
| 90 | text stc_val_seq "seq" |
| 91 | text stc_pre_str "x >= 0" |
| 92 | |
| 93 | text stc_p0 "add_1" |
| 94 | text stc_p1 "add_2" |
| 95 | text stc_p2 "add_3" |
| 96 | text stc_p3 "add_5" |
| 97 | text stc_p4 "sub_1" |
| 98 | text stc_p5 "sub_2" |
| 99 | text stc_p6 "sub_3" |
| 100 | text stc_p7 "sub_5" |
| 101 | text stc_p8 "mul_2" |
| 102 | text stc_p9 "mul_3" |
| 103 | text stc_p10 "mul_4" |
| 104 | text stc_p11 "and_ff" |
| 105 | text stc_p12 "and_0f" |
| 106 | text stc_p13 "or_1" |
| 107 | text stc_p14 "or_2" |
| 108 | |
| 109 | text stc_post0 "x + 1" |
| 110 | text stc_post1 "x + 2" |
| 111 | text stc_post2 "x + 3" |
| 112 | text stc_post3 "x + 5" |
| 113 | text stc_post4 "x - 1" |
| 114 | text stc_post5 "x - 2" |
| 115 | text stc_post6 "x - 3" |
| 116 | text stc_post7 "x - 5" |
| 117 | text stc_post8 "x * 2" |
| 118 | text stc_post9 "x * 3" |
| 119 | text stc_post10 "x * 4" |
| 120 | text stc_post11 "x & 255" |
| 121 | text stc_post12 "x & 15" |
| 122 | text stc_post13 "x | 1" |
| 123 | text stc_post14 "x | 2" |
| 124 | |
| 125 | text stc_f_bank " bank=15\n" |
| 126 | text stc_f_name " name=" |
| 127 | text stc_f_tid " task_id=" |
| 128 | text stc_f_dep " depth=" |
| 129 | text stc_f_mc " max_cost=" |
| 130 | text stc_f_mk " max_candidates=" |
| 131 | text stc_f_dd " dedup=" |
| 132 | text stc_f_ex " examples=" |
| 133 | text stc_f_d " d=" |
| 134 | text stc_f_par " parent=" |
| 135 | text stc_f_pr " prim=" |
| 136 | text stc_f_pn " pname=" |
| 137 | text stc_f_xf " transform=" |
| 138 | text stc_f_ch " child=" |
| 139 | text stc_f_ns " nsteps=" |
| 140 | text stc_f_in " insn=" |
| 141 | text stc_f_bd " body=" |
| 142 | text stc_f_nochild "- nsteps=- insn=- body=-" |
| 143 | text stc_f_sg " sig=" |
| 144 | text stc_f_nosg " sig=-" |
| 145 | text stc_f_pru " prune=" |
| 146 | text stc_f_vd " verdict=" |
| 147 | text stc_f_erc " erc=0 vrc=0" |
| 148 | text stc_f_rrc " rrc=0 rbytes=" |
| 149 | text stc_f_rcy " rcycles=" |
| 150 | text stc_f_rck " rchecked=84\n" |
| 151 | text stc_f_nor " rrc=- rbytes=- rcycles=- rchecked=-\n" |
| 152 | text stc_f_sol1 " solved=" |
| 153 | text stc_f_sol2 " solution=" |
| 154 | text stc_f_gen " generated=" |
| 155 | text stc_f_pt " pruned_type=0 pruned_equiv=" |
| 156 | text stc_f_fl " failed=" |
| 157 | text stc_f_sf " solutions=" |
| 158 | text stc_f_st " steps=" |
| 159 | text stc_f_et "end tasks=" |
| 160 | text stc_f_es " steps=" |
| 161 | text stc_f_ed " digest=" |
| 162 | |
| 163 | note Task set storage (slot 0 = primary, slot 1 = secondary for verify) |
| 164 | global stc_ts_n ulong 1 |
| 165 | global stc_ts_names uchar 4096 |
| 166 | global stc_ts_nlens ulong 64 |
| 167 | global stc_ts_depth ulong 64 |
| 168 | global stc_ts_mcost ulong 64 |
| 169 | global stc_ts_mcand ulong 64 |
| 170 | global stc_ts_dedup ulong 64 |
| 171 | global stc_ts_npairs ulong 64 |
| 172 | global stc_ts_in ulong 1024 |
| 173 | global stc_ts_out ulong 1024 |
| 174 | global stc_ts_dig uchar 32 |
| 175 | |
| 176 | note Precomputed OMG0 IDs for base primitives and constants |
| 177 | global stc_inited ulong 1 |
| 178 | global stc_mach_id uchar 32 |
| 179 | global stc_u64_tid uchar 32 |
| 180 | global stc_param0_id uchar 32 |
| 181 | global stc_pre_id uchar 32 |
| 182 | global stc_op_ids uchar 384 |
| 183 | global stc_p_op ulong 15 |
| 184 | global stc_p_imm ulong 15 |
| 185 | global stc_p_leaf_post uchar 480 |
| 186 | global stc_p_val_id uchar 480 |
| 187 | global stc_p_prog_id uchar 480 |
| 188 | |
| 189 | note Corpus output buffer (2 MiB) |
| 190 | global stc_out uchar 2097152 |
| 191 | global stc_out_len ulong 1 |
| 192 | |
| 193 | note Verifier / parser scratch |
| 194 | global stc_v_dig uchar 32 |
| 195 | global stc_v_steps ulong 1 |
| 196 | global stc_kv_off ulong 1 |
| 197 | global stc_kv_len ulong 1 |
| 198 | global stc_pos ulong 1 |
| 199 | |
| 200 | note Synthesis state (per task) |
| 201 | global stc_eq_cnt ulong 1 |
| 202 | global stc_eq_hash uchar 32768 |
| 203 | global stc_eq_cost ulong 1024 |
| 204 | |
| 205 | global stc_d1_cnt ulong 1 |
| 206 | global stc_d1_p0 ulong 32 |
| 207 | global stc_d1_seq ulong 32 |
| 208 | |
| 209 | global stc_d2_cnt ulong 1 |
| 210 | global stc_d2_p0 ulong 512 |
| 211 | global stc_d2_p1 ulong 512 |
| 212 | global stc_d2_seq ulong 512 |
| 213 | |
| 214 | note Current task synthesis stats & result |
| 215 | global stc_cur_t ulong 1 |
| 216 | global stc_seq ulong 1 |
| 217 | global stc_tot_steps ulong 1 |
| 218 | global stc_st_gen ulong 1 |
| 219 | global stc_st_peq ulong 1 |
| 220 | global stc_st_fail ulong 1 |
| 221 | global stc_st_sols ulong 1 |
| 222 | global stc_solved ulong 1 |
| 223 | global stc_sol_id uchar 32 |
| 224 | global stc_rec_mode ulong 1 |
| 225 | global stc_hook_events ulong 1 |
| 226 | |
| 227 | note Hook registration state (0 = none, 1 = external noop, 2 = recorder, 3 = counter) |
| 228 | global stc_synth_hook_fn ulong 1 |
| 229 | global stc_synth_hook_ctx ulong 1 |
| 230 | global stc_real_hook_fn ulong 1 |
| 231 | global stc_real_hook_ctx ulong 1 |
| 232 | |
| 233 | note Scratch buffers for OMG0 encoding |
| 234 | global stc_obj uchar 512 |
| 235 | global stc_task_raw uchar 2664 |
| 236 | |
| 237 | note ---- Hook API ---- |
| 238 | |
| 239 | fn stc_synth_set_hook fn_id ulong ctx ulong to long |
| 240 | if or eq fn_id 0 ne get stc_synth_hook_fn 0 0 |
| 241 | ret -1 |
| 242 | end |
| 243 | put stc_synth_hook_fn 0 fn_id |
| 244 | put stc_synth_hook_ctx 0 ctx |
| 245 | ret 0 |
| 246 | end |
| 247 | |
| 248 | fn stc_synth_clear_hook ctx ulong to long |
| 249 | if or eq get stc_synth_hook_fn 0 0 ne get stc_synth_hook_ctx 0 ctx |
| 250 | ret -1 |
| 251 | end |
| 252 | put stc_synth_hook_fn 0 0 |
| 253 | put stc_synth_hook_ctx 0 0 |
| 254 | ret 0 |
| 255 | end |
| 256 | |
| 257 | fn stc_real_set_hook fn_id ulong ctx ulong to long |
| 258 | if or eq fn_id 0 ne get stc_real_hook_fn 0 0 |
| 259 | ret -1 |
| 260 | end |
| 261 | put stc_real_hook_fn 0 fn_id |
| 262 | put stc_real_hook_ctx 0 ctx |
| 263 | ret 0 |
| 264 | end |
| 265 | |
| 266 | fn stc_real_clear_hook ctx ulong to long |
| 267 | if or eq get stc_real_hook_fn 0 0 ne get stc_real_hook_ctx 0 ctx |
| 268 | ret -1 |
| 269 | end |
| 270 | put stc_real_hook_fn 0 0 |
| 271 | put stc_real_hook_ctx 0 0 |
| 272 | ret 0 |
| 273 | end |
| 274 | |
| 275 | note ---- Output buffer helpers ---- |
| 276 | |
| 277 | fn stc_out_ch c uchar to void |
| 278 | p = get stc_out_len 0 |
| 279 | if lt p STC_OUT_CAP |
| 280 | put stc_out p c |
| 281 | put stc_out_len 0 add p 1 |
| 282 | end |
| 283 | end |
| 284 | |
| 285 | fn stc_out_txt s view uchar * to void |
| 286 | p = get stc_out_len 0 |
| 287 | n = len s |
| 288 | if le add p n STC_OUT_CAP |
| 289 | for i ulong n bound 256 |
| 290 | put stc_out add p i get s i |
| 291 | end |
| 292 | put stc_out_len 0 add p n |
| 293 | end |
| 294 | end |
| 295 | |
| 296 | fn stc_out_u64 v ulong to void |
| 297 | tmp = new uchar 24 0 |
| 298 | k = ulong 24 |
| 299 | x = v |
| 300 | while true bound 24 |
| 301 | k = sub k 1 |
| 302 | put tmp k uchar add 48 rem x 10 |
| 303 | x = div x 10 |
| 304 | if eq x 0 |
| 305 | break |
| 306 | end |
| 307 | end |
| 308 | n = sub 24 k |
| 309 | p = get stc_out_len 0 |
| 310 | if le add p n STC_OUT_CAP |
| 311 | for i ulong n bound 24 |
| 312 | put stc_out add p i get tmp add k i |
| 313 | end |
| 314 | put stc_out_len 0 add p n |
| 315 | end |
| 316 | end |
| 317 | |
| 318 | fn stc_out_hex2 v ulong to void |
| 319 | stc_out_ch sth_hex_nib and shr v 4 15 |
| 320 | stc_out_ch sth_hex_nib and v 15 |
| 321 | end |
| 322 | |
| 323 | fn stc_out_hex_u64 v ulong to void |
| 324 | tmp = new uchar 16 0 |
| 325 | k = ulong 16 |
| 326 | x = v |
| 327 | while true bound 16 |
| 328 | k = sub k 1 |
| 329 | put tmp k sth_hex_nib and x 15 |
| 330 | x = shr x 4 |
| 331 | if eq x 0 |
| 332 | break |
| 333 | end |
| 334 | end |
| 335 | n = sub 16 k |
| 336 | p = get stc_out_len 0 |
| 337 | if le add p n STC_OUT_CAP |
| 338 | for i ulong n bound 16 |
| 339 | put stc_out add p i get tmp add k i |
| 340 | end |
| 341 | put stc_out_len 0 add p n |
| 342 | end |
| 343 | end |
| 344 | |
| 345 | fn stc_out_hex32 d view uchar 32 to void |
| 346 | p = get stc_out_len 0 |
| 347 | if le add p 64 STC_OUT_CAP |
| 348 | for i ulong 32 |
| 349 | b = ulong get d i |
| 350 | put stc_out add p mul i 2 sth_hex_nib shr b 4 |
| 351 | put stc_out add p add mul i 2 1 sth_hex_nib and b 15 |
| 352 | end |
| 353 | put stc_out_len 0 add p 64 |
| 354 | end |
| 355 | end |
| 356 | |
| 357 | fn stc_out_prim_name idx ulong to void |
| 358 | if eq idx 0 |
| 359 | stc_out_txt stc_p0 |
| 360 | ret |
| 361 | end |
| 362 | if eq idx 1 |
| 363 | stc_out_txt stc_p1 |
| 364 | ret |
| 365 | end |
| 366 | if eq idx 2 |
| 367 | stc_out_txt stc_p2 |
| 368 | ret |
| 369 | end |
| 370 | if eq idx 3 |
| 371 | stc_out_txt stc_p3 |
| 372 | ret |
| 373 | end |
| 374 | if eq idx 4 |
| 375 | stc_out_txt stc_p4 |
| 376 | ret |
| 377 | end |
| 378 | if eq idx 5 |
| 379 | stc_out_txt stc_p5 |
| 380 | ret |
| 381 | end |
| 382 | if eq idx 6 |
| 383 | stc_out_txt stc_p6 |
| 384 | ret |
| 385 | end |
| 386 | if eq idx 7 |
| 387 | stc_out_txt stc_p7 |
| 388 | ret |
| 389 | end |
| 390 | if eq idx 8 |
| 391 | stc_out_txt stc_p8 |
| 392 | ret |
| 393 | end |
| 394 | if eq idx 9 |
| 395 | stc_out_txt stc_p9 |
| 396 | ret |
| 397 | end |
| 398 | if eq idx 10 |
| 399 | stc_out_txt stc_p10 |
| 400 | ret |
| 401 | end |
| 402 | if eq idx 11 |
| 403 | stc_out_txt stc_p11 |
| 404 | ret |
| 405 | end |
| 406 | if eq idx 12 |
| 407 | stc_out_txt stc_p12 |
| 408 | ret |
| 409 | end |
| 410 | if eq idx 13 |
| 411 | stc_out_txt stc_p13 |
| 412 | ret |
| 413 | end |
| 414 | stc_out_txt stc_p14 |
| 415 | end |
| 416 | |
| 417 | fn stc_out_prune_name pr ulong to void |
| 418 | if eq pr 0 |
| 419 | stc_out_txt stc_pn_0 |
| 420 | ret |
| 421 | end |
| 422 | if eq pr 1 |
| 423 | stc_out_txt stc_pn_1 |
| 424 | ret |
| 425 | end |
| 426 | if eq pr 2 |
| 427 | stc_out_txt stc_pn_2 |
| 428 | ret |
| 429 | end |
| 430 | if eq pr 3 |
| 431 | stc_out_txt stc_pn_3 |
| 432 | ret |
| 433 | end |
| 434 | stc_out_txt stc_pn_4 |
| 435 | end |
| 436 | |
| 437 | fn stc_out_verd_name vd ulong to void |
| 438 | if eq vd 0 |
| 439 | stc_out_txt stc_vn_0 |
| 440 | ret |
| 441 | end |
| 442 | if eq vd 1 |
| 443 | stc_out_txt stc_vn_1 |
| 444 | ret |
| 445 | end |
| 446 | if eq vd 2 |
| 447 | stc_out_txt stc_vn_2 |
| 448 | ret |
| 449 | end |
| 450 | stc_out_txt stc_vn_3 |
| 451 | end |
| 452 | |
| 453 | note ---- OMG0 canonical object hashing ---- |
| 454 | |
| 455 | fn stc_put_u16be pos ulong v ulong to ulong |
| 456 | put stc_obj pos uchar and shr v 8 255 |
| 457 | put stc_obj add pos 1 uchar and v 255 |
| 458 | ret add pos 2 |
| 459 | end |
| 460 | |
| 461 | fn stc_put_u32be pos ulong v ulong to ulong |
| 462 | put stc_obj pos uchar and shr v 24 255 |
| 463 | put stc_obj add pos 1 uchar and shr v 16 255 |
| 464 | put stc_obj add pos 2 uchar and shr v 8 255 |
| 465 | put stc_obj add pos 3 uchar and v 255 |
| 466 | ret add pos 4 |
| 467 | end |
| 468 | |
| 469 | fn stc_put_u64be pos ulong v ulong to ulong |
| 470 | for i ulong 8 |
| 471 | sh = sub 56 mul i 8 |
| 472 | put stc_obj add pos i uchar and shr v sh 255 |
| 473 | end |
| 474 | ret add pos 8 |
| 475 | end |
| 476 | |
| 477 | fn stc_put_u16le pos ulong v ulong to ulong |
| 478 | put stc_obj pos uchar and v 255 |
| 479 | put stc_obj add pos 1 uchar and shr v 8 255 |
| 480 | ret add pos 2 |
| 481 | end |
| 482 | |
| 483 | fn stc_put_u32le pos ulong v ulong to ulong |
| 484 | put stc_obj pos uchar and v 255 |
| 485 | put stc_obj add pos 1 uchar and shr v 8 255 |
| 486 | put stc_obj add pos 2 uchar and shr v 16 255 |
| 487 | put stc_obj add pos 3 uchar and shr v 24 255 |
| 488 | ret add pos 4 |
| 489 | end |
| 490 | |
| 491 | fn stc_obj_hdr kind ulong to ulong |
| 492 | put stc_obj 0 79 |
| 493 | put stc_obj 1 77 |
| 494 | put stc_obj 2 71 |
| 495 | put stc_obj 3 48 |
| 496 | put stc_obj 4 1 |
| 497 | put stc_obj 5 uchar kind |
| 498 | ret 6 |
| 499 | end |
| 500 | |
| 501 | fn stc_obj_hash n ulong dst edit uchar 32 to void |
| 502 | for i ulong n bound 512 |
| 503 | put sh_dat i get stc_obj i |
| 504 | end |
| 505 | sh_all n |
| 506 | for i ulong 32 |
| 507 | put dst i get sh_dig i |
| 508 | end |
| 509 | end |
| 510 | |
| 511 | fn stc_build_constraint_id ckind ulong ann view uchar * alen ulong dst edit uchar 32 to void |
| 512 | p = stc_obj_hdr 5 |
| 513 | p = stc_put_u16be p 0 |
| 514 | p = stc_put_u16be p 0 |
| 515 | p = stc_put_u16be p 1 |
| 516 | p = stc_put_u16be p ckind |
| 517 | p = stc_put_u16be p alen |
| 518 | for i ulong alen bound 128 |
| 519 | put stc_obj add p i get ann i |
| 520 | end |
| 521 | p = add p alen |
| 522 | p = stc_put_u32be p 0 |
| 523 | stc_obj_hash p dst |
| 524 | end |
| 525 | |
| 526 | fn stc_build_post_seq_2 a view uchar 32 b view uchar 32 dst edit uchar 32 to void |
| 527 | p = stc_obj_hdr 5 |
| 528 | p = stc_put_u16be p 1 |
| 529 | kl = len stc_attr_comp |
| 530 | put stc_obj p uchar kl |
| 531 | p = add p 1 |
| 532 | for i ulong kl bound 32 |
| 533 | put stc_obj add p i get stc_attr_comp i |
| 534 | end |
| 535 | p = add p kl |
| 536 | p = stc_put_u16be p 3 |
| 537 | for i ulong 3 |
| 538 | put stc_obj add p i get stc_val_seq i |
| 539 | end |
| 540 | p = add p 3 |
| 541 | p = stc_put_u16be p 0 |
| 542 | p = stc_put_u16be p 1 |
| 543 | p = stc_put_u16be p 8 |
| 544 | p = stc_put_u16be p 64 |
| 545 | for i ulong 32 |
| 546 | put stc_obj add p i get a i |
| 547 | put stc_obj add add p 32 i get b i |
| 548 | end |
| 549 | p = add p 64 |
| 550 | p = stc_put_u32be p 0 |
| 551 | stc_obj_hash p dst |
| 552 | end |
| 553 | |
| 554 | fn stc_build_apply op_idx ulong arg1 view uchar 32 arg2 view uchar 32 dst edit uchar 32 to void |
| 555 | p = stc_obj_hdr 3 |
| 556 | p = stc_put_u16be p 0 |
| 557 | p = stc_put_u16be p 0 |
| 558 | p = stc_put_u16be p 0 |
| 559 | p = stc_put_u32be p 161 |
| 560 | for i ulong 161 |
| 561 | put stc_obj add p i 0 |
| 562 | end |
| 563 | base = mul op_idx 32 |
| 564 | for i ulong 32 |
| 565 | put stc_obj add p i get stc_op_ids add base i |
| 566 | put stc_obj add add p 33 i get arg1 i |
| 567 | put stc_obj add add p 65 i get arg2 i |
| 568 | end |
| 569 | put stc_obj add p 32 2 |
| 570 | stc_obj_hash add p 161 dst |
| 571 | end |
| 572 | |
| 573 | fn stc_compute_prog_id root view uchar 32 post view uchar 32 dst edit uchar 32 to void |
| 574 | dl = len stc_dom_prog |
| 575 | for i ulong dl bound 32 |
| 576 | put sh_dat i get stc_dom_prog i |
| 577 | end |
| 578 | put sh_dat dl 0 |
| 579 | p = add dl 1 |
| 580 | for i ulong 32 |
| 581 | put sh_dat add p i get root i |
| 582 | put sh_dat add add p 32 i get stc_u64_tid i |
| 583 | put sh_dat add add p 64 i get stc_u64_tid i |
| 584 | put sh_dat add add p 96 i get stc_pre_id i |
| 585 | put sh_dat add add p 128 i get post i |
| 586 | end |
| 587 | sh_all add p 160 |
| 588 | for i ulong 32 |
| 589 | put dst i get sh_dig i |
| 590 | end |
| 591 | end |
| 592 | |
| 593 | fn stc_init_machine_id to void |
| 594 | p = ulong 0 |
| 595 | put stc_obj 0 79 |
| 596 | put stc_obj 1 77 |
| 597 | put stc_obj 2 71 |
| 598 | put stc_obj 3 48 |
| 599 | put stc_obj 4 7 |
| 600 | put stc_obj 5 1 |
| 601 | nl = len stc_m_name |
| 602 | put stc_obj 6 uchar nl |
| 603 | p = 7 |
| 604 | for i ulong nl bound 64 |
| 605 | put stc_obj add p i get stc_m_name i |
| 606 | end |
| 607 | p = add p nl |
| 608 | p = stc_put_u32be p 4 |
| 609 | p = stc_put_u32be p 256 |
| 610 | put stc_obj p 1 |
| 611 | put stc_obj add p 1 6 |
| 612 | p = add p 2 |
| 613 | note 6 units: (0,4,1,4), (1,2,1,2), (2,2,3,2), (3,1,12,1), (4,2,3,2), (5,4,2,4) |
| 614 | put stc_obj p 0 |
| 615 | put stc_obj add p 1 4 |
| 616 | put stc_obj add p 2 1 |
| 617 | put stc_obj add p 3 4 |
| 618 | put stc_obj add p 4 1 |
| 619 | put stc_obj add p 5 2 |
| 620 | put stc_obj add p 6 1 |
| 621 | put stc_obj add p 7 2 |
| 622 | put stc_obj add p 8 2 |
| 623 | put stc_obj add p 9 2 |
| 624 | put stc_obj add p 10 3 |
| 625 | put stc_obj add p 11 2 |
| 626 | put stc_obj add p 12 3 |
| 627 | put stc_obj add p 13 1 |
| 628 | put stc_obj add p 14 12 |
| 629 | put stc_obj add p 15 1 |
| 630 | put stc_obj add p 16 4 |
| 631 | put stc_obj add p 17 2 |
| 632 | put stc_obj add p 18 3 |
| 633 | put stc_obj add p 19 2 |
| 634 | put stc_obj add p 20 5 |
| 635 | put stc_obj add p 21 4 |
| 636 | put stc_obj add p 22 2 |
| 637 | put stc_obj add p 23 4 |
| 638 | p = add p 24 |
| 639 | put stc_obj p 31 |
| 640 | put stc_obj add p 1 64 |
| 641 | put stc_obj add p 2 32 |
| 642 | put stc_obj add p 3 128 |
| 643 | put stc_obj add p 4 4 |
| 644 | p = add p 5 |
| 645 | note L1I: 1, 1, 65536, 64, 4, 3 |
| 646 | put stc_obj p 1 |
| 647 | put stc_obj add p 1 1 |
| 648 | p = stc_put_u64be add p 2 65536 |
| 649 | put stc_obj p 64 |
| 650 | put stc_obj add p 1 4 |
| 651 | put stc_obj add p 2 3 |
| 652 | p = add p 3 |
| 653 | note L1D: 1, 0, 65536, 64, 8, 4 |
| 654 | put stc_obj p 1 |
| 655 | put stc_obj add p 1 0 |
| 656 | p = stc_put_u64be add p 2 65536 |
| 657 | put stc_obj p 64 |
| 658 | put stc_obj add p 1 8 |
| 659 | put stc_obj add p 2 4 |
| 660 | p = add p 3 |
| 661 | note L2: 2, 0, 1048576, 64, 8, 10 |
| 662 | put stc_obj p 2 |
| 663 | put stc_obj add p 1 0 |
| 664 | p = stc_put_u64be add p 2 1048576 |
| 665 | put stc_obj p 64 |
| 666 | put stc_obj add p 1 8 |
| 667 | put stc_obj add p 2 10 |
| 668 | p = add p 3 |
| 669 | note L3: 3, 0, 119537664, 64, 16, 35 |
| 670 | put stc_obj p 3 |
| 671 | put stc_obj add p 1 0 |
| 672 | p = stc_put_u64be add p 2 119537664 |
| 673 | put stc_obj p 64 |
| 674 | put stc_obj add p 1 16 |
| 675 | put stc_obj add p 2 35 |
| 676 | p = add p 3 |
| 677 | p = stc_put_u64be p 0x80000000 |
| 678 | p = stc_put_u64be p 137438953472 |
| 679 | put stc_obj p 1 |
| 680 | p = add p 1 |
| 681 | for i ulong 32 |
| 682 | put stc_obj add p i 0xa1 |
| 683 | end |
| 684 | p = add p 32 |
| 685 | id = new uchar 32 0 |
| 686 | stc_obj_hash p id |
| 687 | for i ulong 32 |
| 688 | put stc_mach_id i get id i |
| 689 | end |
| 690 | end |
| 691 | |
| 692 | fn stc_init_op_id op_code ulong to void |
| 693 | p = stc_obj_hdr 3 |
| 694 | p = stc_put_u16be p 0 |
| 695 | p = stc_put_u16be p 0 |
| 696 | p = stc_put_u16be p 0 |
| 697 | p = stc_put_u32be p 204 |
| 698 | for i ulong 204 |
| 699 | put stc_obj add p i 0 |
| 700 | end |
| 701 | r = stc_put_u32le p op_code |
| 702 | r = stc_put_u32le add p 4 1 |
| 703 | put stc_obj add p 40 2 |
| 704 | for i ulong 32 |
| 705 | v = get stc_u64_tid i |
| 706 | put stc_obj add add p 8 i v |
| 707 | put stc_obj add add p 41 i v |
| 708 | put stc_obj add add p 73 i v |
| 709 | put stc_obj add add p 169 i v |
| 710 | end |
| 711 | id = new uchar 32 0 |
| 712 | stc_obj_hash add p 204 id |
| 713 | base = mul op_code 32 |
| 714 | for i ulong 32 |
| 715 | put stc_op_ids add base i get id i |
| 716 | end |
| 717 | end |
| 718 | |
| 719 | fn stc_init_prim_val_prog idx ulong op ulong imm ulong lp view uchar 32 to void |
| 720 | base = mul idx 32 |
| 721 | p = stc_obj_hdr 1 |
| 722 | p = stc_put_u16be p 0 |
| 723 | p = stc_put_u16be p 0 |
| 724 | p = stc_put_u16be p 0 |
| 725 | p = stc_put_u32be p 98 |
| 726 | for i ulong 98 |
| 727 | put stc_obj add p i 0 |
| 728 | end |
| 729 | for i ulong 32 |
| 730 | put stc_obj add p i get stc_u64_tid i |
| 731 | end |
| 732 | r = stc_put_u16le add p 32 8 |
| 733 | r = stc_put_u64be add p 34 imm |
| 734 | vid = new uchar 32 0 |
| 735 | stc_obj_hash add p 98 vid |
| 736 | for i ulong 32 |
| 737 | put stc_p_val_id add base i get vid i |
| 738 | end |
| 739 | p0 = new uchar 32 0 |
| 740 | for i ulong 32 |
| 741 | put p0 i get stc_param0_id i |
| 742 | end |
| 743 | root = new uchar 32 0 |
| 744 | stc_build_apply op p0 vid root |
| 745 | stc_compute_prog_id root lp vid |
| 746 | for i ulong 32 |
| 747 | put stc_p_prog_id add base i get vid i |
| 748 | end |
| 749 | end |
| 750 | |
| 751 | fn stc_init_one_prim idx ulong op ulong imm ulong pstr view uchar * to void |
| 752 | put stc_p_op idx op |
| 753 | put stc_p_imm idx imm |
| 754 | lp = new uchar 32 0 |
| 755 | stc_build_constraint_id 8 pstr len pstr lp |
| 756 | base = mul idx 32 |
| 757 | for i ulong 32 |
| 758 | put stc_p_leaf_post add base i get lp i |
| 759 | end |
| 760 | stc_init_prim_val_prog idx op imm lp |
| 761 | end |
| 762 | |
| 763 | fn stc_init_prims to void |
| 764 | stc_init_one_prim 0 3 1 stc_post0 |
| 765 | stc_init_one_prim 1 3 2 stc_post1 |
| 766 | stc_init_one_prim 2 3 3 stc_post2 |
| 767 | stc_init_one_prim 3 3 5 stc_post3 |
| 768 | stc_init_one_prim 4 4 1 stc_post4 |
| 769 | stc_init_one_prim 5 4 2 stc_post5 |
| 770 | stc_init_one_prim 6 4 3 stc_post6 |
| 771 | stc_init_one_prim 7 4 5 stc_post7 |
| 772 | stc_init_one_prim 8 5 2 stc_post8 |
| 773 | stc_init_one_prim 9 5 3 stc_post9 |
| 774 | stc_init_one_prim 10 5 4 stc_post10 |
| 775 | stc_init_one_prim 11 9 255 stc_post11 |
| 776 | stc_init_one_prim 12 9 15 stc_post12 |
| 777 | stc_init_one_prim 13 10 1 stc_post13 |
| 778 | stc_init_one_prim 14 10 2 stc_post14 |
| 779 | end |
| 780 | |
| 781 | fn stc_init to void |
| 782 | if ne get stc_inited 0 0 |
| 783 | ret |
| 784 | end |
| 785 | put stc_inited 0 1 |
| 786 | stc_init_machine_id |
| 787 | note type_u64_id |
| 788 | p = stc_obj_hdr 2 |
| 789 | p = stc_put_u16be p 0 |
| 790 | p = stc_put_u16be p 0 |
| 791 | p = stc_put_u16be p 0 |
| 792 | p = stc_put_u32be p 44 |
| 793 | for i ulong 44 |
| 794 | put stc_obj add p i 0 |
| 795 | end |
| 796 | r = stc_put_u32le p 3 |
| 797 | r = stc_put_u16le add p 4 64 |
| 798 | id = new uchar 32 0 |
| 799 | stc_obj_hash add p 44 id |
| 800 | for i ulong 32 |
| 801 | put stc_u64_tid i get id i |
| 802 | end |
| 803 | note param0_id |
| 804 | p = stc_obj_hdr 1 |
| 805 | p = stc_put_u16be p 1 |
| 806 | kl = len stc_attr_param |
| 807 | put stc_obj p uchar kl |
| 808 | p = add p 1 |
| 809 | for i ulong kl bound 32 |
| 810 | put stc_obj add p i get stc_attr_param i |
| 811 | end |
| 812 | p = add p kl |
| 813 | p = stc_put_u16be p 2 |
| 814 | put stc_obj p 0 |
| 815 | put stc_obj add p 1 0 |
| 816 | p = add p 2 |
| 817 | p = stc_put_u16be p 0 |
| 818 | p = stc_put_u16be p 0 |
| 819 | p = stc_put_u32be p 98 |
| 820 | for i ulong 98 |
| 821 | put stc_obj add p i 0 |
| 822 | end |
| 823 | for i ulong 32 |
| 824 | put stc_obj add p i get stc_u64_tid i |
| 825 | end |
| 826 | stc_obj_hash add p 98 id |
| 827 | for i ulong 32 |
| 828 | put stc_param0_id i get id i |
| 829 | end |
| 830 | note pre_id ("x >= 0") |
| 831 | stc_build_constraint_id 7 stc_pre_str len stc_pre_str id |
| 832 | for i ulong 32 |
| 833 | put stc_pre_id i get id i |
| 834 | end |
| 835 | note op_bin_id for ADD(3), SUB(4), MUL(5), AND(9), OR(10) |
| 836 | stc_init_op_id 3 |
| 837 | stc_init_op_id 4 |
| 838 | stc_init_op_id 5 |
| 839 | stc_init_op_id 9 |
| 840 | stc_init_op_id 10 |
| 841 | stc_init_prims |
| 842 | end |
| 843 | |
| 844 | fn stc_task_raw_put64 off ulong v ulong to void |
| 845 | for b ulong 8 |
| 846 | if lt add off b 2664 |
| 847 | sh = mul b 8 |
| 848 | put stc_task_raw add off b uchar and shr v sh 255 |
| 849 | end |
| 850 | end |
| 851 | end |
| 852 | |
| 853 | fn stc_task_raw_pairs t ulong to void |
| 854 | np = get stc_ts_npairs t |
| 855 | put stc_task_raw 2432 uchar np |
| 856 | pbase = mul t 16 |
| 857 | for i ulong np bound 16 |
| 858 | stc_task_raw_put64 add 2440 mul i 8 get stc_ts_in add pbase i |
| 859 | stc_task_raw_put64 add 2568 mul i 8 get stc_ts_out add pbase i |
| 860 | end |
| 861 | end |
| 862 | |
| 863 | note Compute SynthesisTask.task_id (exact 2664-byte AArch64 struct prefix hash). |
| 864 | fn stc_compute_task_id t ulong dst edit uchar 32 to void |
| 865 | for i ulong 2664 bound 3000 |
| 866 | put stc_task_raw i 0 |
| 867 | end |
| 868 | nl = get stc_ts_nlens t |
| 869 | nbase = mul t 64 |
| 870 | nb = new uchar 64 0 |
| 871 | for i ulong nl bound 64 |
| 872 | c = get stc_ts_names add nbase i |
| 873 | put stc_task_raw add 32 i c |
| 874 | put nb i c |
| 875 | end |
| 876 | put stc_task_raw 160 3 |
| 877 | put stc_task_raw 164 64 |
| 878 | put stc_task_raw 168 3 |
| 879 | put stc_task_raw 172 64 |
| 880 | post_id = new uchar 32 0 |
| 881 | stc_build_constraint_id 8 nb nl post_id |
| 882 | for i ulong 32 |
| 883 | put stc_task_raw add 174 i get stc_pre_id i |
| 884 | put stc_task_raw add 206 i get post_id i |
| 885 | end |
| 886 | for i ulong len stc_pre_str bound 16 |
| 887 | put stc_task_raw add 238 i get stc_pre_str i |
| 888 | end |
| 889 | for i ulong nl bound 60 |
| 890 | put stc_task_raw add 302 i get nb i |
| 891 | end |
| 892 | put stc_task_raw 2416 10 |
| 893 | put stc_task_raw 2420 4 |
| 894 | put stc_task_raw 2428 10 |
| 895 | stc_task_raw_pairs t |
| 896 | for i ulong 2664 bound 3000 |
| 897 | put sh_dat i get stc_task_raw i |
| 898 | end |
| 899 | sh_all 2664 |
| 900 | for i ulong 32 |
| 901 | put dst i get sh_dig i |
| 902 | end |
| 903 | end |
| 904 | |
| 905 | note ---- Execution & program ID for 1..3 step compositions ---- |
| 906 | |
| 907 | fn stc_eval_step x ulong pidx ulong to ulong |
| 908 | op = get stc_p_op pidx |
| 909 | imm = get stc_p_imm pidx |
| 910 | if eq op 3 |
| 911 | ret add x imm |
| 912 | end |
| 913 | if eq op 4 |
| 914 | ret sub x imm |
| 915 | end |
| 916 | if eq op 5 |
| 917 | ret mul x imm |
| 918 | end |
| 919 | if eq op 9 |
| 920 | ret and x imm |
| 921 | end |
| 922 | ret or x imm |
| 923 | end |
| 924 | |
| 925 | fn stc_eval_chain x ulong d ulong p0 ulong p1 ulong p2 ulong to ulong |
| 926 | v = stc_eval_step x p0 |
| 927 | if ge d 2 |
| 928 | v = stc_eval_step v p1 |
| 929 | end |
| 930 | if ge d 3 |
| 931 | v = stc_eval_step v p2 |
| 932 | end |
| 933 | ret v |
| 934 | end |
| 935 | |
| 936 | fn stc_shdat_put64 off ulong v ulong to void |
| 937 | for b ulong 8 |
| 938 | sh = mul b 8 |
| 939 | put sh_dat add off b uchar and shr v sh 255 |
| 940 | end |
| 941 | end |
| 942 | |
| 943 | fn stc_compute_sig d ulong p0 ulong p1 ulong p2 ulong dst edit uchar 32 to void |
| 944 | probes = new ulong 6 0 |
| 945 | put probes 0 0 |
| 946 | put probes 1 1 |
| 947 | put probes 2 3 |
| 948 | put probes 3 7 |
| 949 | put probes 4 13 |
| 950 | put probes 5 42 |
| 951 | for i ulong 6 |
| 952 | y = stc_eval_chain get probes i d p0 p1 p2 |
| 953 | stc_shdat_put64 mul i 8 y |
| 954 | end |
| 955 | sh_all 48 |
| 956 | for i ulong 32 |
| 957 | put dst i get sh_dig i |
| 958 | end |
| 959 | end |
| 960 | |
| 961 | fn stc_prog_id_chain d ulong p0 ulong p1 ulong p2 ulong dst edit uchar 32 to void |
| 962 | if eq d 1 |
| 963 | base = mul p0 32 |
| 964 | for i ulong 32 |
| 965 | put dst i get stc_p_prog_id add base i |
| 966 | end |
| 967 | ret |
| 968 | end |
| 969 | cur = new uchar 32 0 |
| 970 | vid = new uchar 32 0 |
| 971 | nxt = new uchar 32 0 |
| 972 | for i ulong 32 |
| 973 | put cur i get stc_param0_id i |
| 974 | put vid i get stc_p_val_id add mul p0 32 i |
| 975 | end |
| 976 | stc_build_apply get stc_p_op p0 cur vid nxt |
| 977 | for i ulong 32 |
| 978 | put cur i get nxt i |
| 979 | put vid i get stc_p_val_id add mul p1 32 i |
| 980 | end |
| 981 | stc_build_apply get stc_p_op p1 cur vid nxt |
| 982 | if eq d 3 |
| 983 | for i ulong 32 |
| 984 | put cur i get nxt i |
| 985 | put vid i get stc_p_val_id add mul p2 32 i |
| 986 | end |
| 987 | stc_build_apply get stc_p_op p2 cur vid nxt |
| 988 | end |
| 989 | note postcondition right-fold: reuse cur, vid; nxt holds body_root |
| 990 | post = new uchar 32 0 |
| 991 | if eq d 2 |
| 992 | for i ulong 32 |
| 993 | put cur i get stc_p_leaf_post add mul p0 32 i |
| 994 | put vid i get stc_p_leaf_post add mul p1 32 i |
| 995 | end |
| 996 | stc_build_post_seq_2 cur vid post |
| 997 | else |
| 998 | for i ulong 32 |
| 999 | put cur i get stc_p_leaf_post add mul p1 32 i |
| 1000 | put vid i get stc_p_leaf_post add mul p2 32 i |
| 1001 | end |
| 1002 | stc_build_post_seq_2 cur vid post |
| 1003 | for i ulong 32 |
| 1004 | put cur i get stc_p_leaf_post add mul p0 32 i |
| 1005 | put vid i get post i |
| 1006 | end |
| 1007 | stc_build_post_seq_2 cur vid post |
| 1008 | end |
| 1009 | stc_compute_prog_id nxt post dst |
| 1010 | end |
| 1011 | |
| 1012 | note ---- Equivalence table ---- |
| 1013 | |
| 1014 | fn stc_equiv_contains_or_add sig view uchar 32 cost ulong to bool |
| 1015 | cnt = get stc_eq_cnt 0 |
| 1016 | for i ulong cnt bound 1024 |
| 1017 | base = mul i 32 |
| 1018 | same = ulong 1 |
| 1019 | for j ulong 32 |
| 1020 | if ne get stc_eq_hash add base j get sig j |
| 1021 | same = 0 |
| 1022 | break |
| 1023 | end |
| 1024 | end |
| 1025 | if eq same 1 |
| 1026 | if le get stc_eq_cost i cost |
| 1027 | ret true |
| 1028 | else |
| 1029 | put stc_eq_cost i cost |
| 1030 | ret false |
| 1031 | end |
| 1032 | end |
| 1033 | end |
| 1034 | if lt cnt STC_MAX_SIGS |
| 1035 | base = mul cnt 32 |
| 1036 | for j ulong 32 |
| 1037 | put stc_eq_hash add base j get sig j |
| 1038 | end |
| 1039 | put stc_eq_cost cnt cost |
| 1040 | put stc_eq_cnt 0 add cnt 1 |
| 1041 | end |
| 1042 | ret false |
| 1043 | end |
| 1044 | |
| 1045 | note ---- Task-set parser ---- |
| 1046 | |
| 1047 | fn stc_name_ok buf view uchar * off ulong n ulong to bool |
| 1048 | if or eq n 0 gt n 60 |
| 1049 | ret false |
| 1050 | end |
| 1051 | for i ulong n bound 64 |
| 1052 | c = ulong get buf add off i |
| 1053 | ok = ulong 0 |
| 1054 | if and ge c 97 le c 122 |
| 1055 | ok = 1 |
| 1056 | end |
| 1057 | if and ge c 65 le c 90 |
| 1058 | ok = 1 |
| 1059 | end |
| 1060 | if and ge c 48 le c 57 |
| 1061 | ok = 1 |
| 1062 | end |
| 1063 | if or eq c 46 or eq c 95 eq c 45 |
| 1064 | ok = 1 |
| 1065 | end |
| 1066 | if eq ok 0 |
| 1067 | ret false |
| 1068 | end |
| 1069 | end |
| 1070 | ret true |
| 1071 | end |
| 1072 | |
| 1073 | fn stc_parse_u64 buf view uchar * off ulong n ulong dst edit ulong 1 to bool |
| 1074 | if or eq n 0 gt n 20 |
| 1075 | ret false |
| 1076 | end |
| 1077 | if gt n 1 |
| 1078 | if eq ulong get buf off 48 |
| 1079 | ret false |
| 1080 | end |
| 1081 | end |
| 1082 | x = ulong 0 |
| 1083 | for i ulong n bound 24 |
| 1084 | c = ulong get buf add off i |
| 1085 | if or lt c 48 gt c 57 |
| 1086 | ret false |
| 1087 | end |
| 1088 | d = sub c 48 |
| 1089 | if gt x div sub 18446744073709551615 d 10 |
| 1090 | ret false |
| 1091 | end |
| 1092 | x = add mul x 10 d |
| 1093 | end |
| 1094 | put dst 0 x |
| 1095 | ret true |
| 1096 | end |
| 1097 | |
| 1098 | fn stc_parse_i64 buf view uchar * off ulong n ulong to bool |
| 1099 | if eq n 0 |
| 1100 | ret false |
| 1101 | end |
| 1102 | is_neg = ulong 0 |
| 1103 | cur = off |
| 1104 | remn = n |
| 1105 | if eq ulong get buf cur 45 |
| 1106 | is_neg = 1 |
| 1107 | cur = add cur 1 |
| 1108 | remn = sub remn 1 |
| 1109 | end |
| 1110 | if or eq remn 0 gt remn 20 |
| 1111 | ret false |
| 1112 | end |
| 1113 | if gt remn 1 |
| 1114 | if eq ulong get buf cur 48 |
| 1115 | ret false |
| 1116 | end |
| 1117 | end |
| 1118 | v = ulong 0 |
| 1119 | for i ulong remn bound 24 |
| 1120 | c = ulong get buf add cur i |
| 1121 | if or lt c 48 gt c 57 |
| 1122 | ret false |
| 1123 | end |
| 1124 | d = sub c 48 |
| 1125 | if gt v div sub 2147483648 d 10 |
| 1126 | ret false |
| 1127 | end |
| 1128 | v = add mul v 10 d |
| 1129 | end |
| 1130 | if gt v 2147483648 |
| 1131 | ret false |
| 1132 | end |
| 1133 | if and eq is_neg 1 eq v 0 |
| 1134 | ret false |
| 1135 | end |
| 1136 | ret true |
| 1137 | end |
| 1138 | |
| 1139 | fn stc_expect_kv buf view uchar * lend ulong key view uchar * to bool |
| 1140 | p = get stc_pos 0 |
| 1141 | kl = len key |
| 1142 | if lt sub lend p add kl 1 |
| 1143 | ret false |
| 1144 | end |
| 1145 | for i ulong kl bound 32 |
| 1146 | if ne get buf add p i get key i |
| 1147 | ret false |
| 1148 | end |
| 1149 | end |
| 1150 | if ne ulong get buf add p kl 61 |
| 1151 | ret false |
| 1152 | end |
| 1153 | p = add p add kl 1 |
| 1154 | q = p |
| 1155 | while lt q lend bound 4096 |
| 1156 | if eq ulong get buf q 32 |
| 1157 | break |
| 1158 | end |
| 1159 | q = add q 1 |
| 1160 | end |
| 1161 | put stc_kv_off 0 p |
| 1162 | put stc_kv_len 0 sub q p |
| 1163 | if lt q lend |
| 1164 | q = add q 1 |
| 1165 | end |
| 1166 | put stc_pos 0 q |
| 1167 | ret true |
| 1168 | end |
| 1169 | |
| 1170 | fn stc_find_ch buf view uchar * a ulong lim ulong ch ulong to ulong |
| 1171 | for i ulong sub lim a bound 1024 |
| 1172 | if eq ulong get buf add a i ch |
| 1173 | ret add a i |
| 1174 | end |
| 1175 | end |
| 1176 | ret lim |
| 1177 | end |
| 1178 | |
| 1179 | fn stc_parse_pairs buf view uchar * voff ulong vlen ulong t ulong to bool |
| 1180 | a = voff |
| 1181 | ve = add voff vlen |
| 1182 | np = ulong 0 |
| 1183 | u = new ulong 1 0 |
| 1184 | pbase = mul t 16 |
| 1185 | while lt a ve bound 32 |
| 1186 | cpos = stc_find_ch buf a ve 44 |
| 1187 | col = stc_find_ch buf a cpos 58 |
| 1188 | if or eq col cpos ge np STC_MAX_PAIRS |
| 1189 | ret false |
| 1190 | end |
| 1191 | if not stc_parse_u64 buf a sub col a u |
| 1192 | ret false |
| 1193 | end |
| 1194 | put stc_ts_in add pbase np get u 0 |
| 1195 | if not stc_parse_u64 buf add col 1 sub sub cpos col 1 u |
| 1196 | ret false |
| 1197 | end |
| 1198 | put stc_ts_out add pbase np get u 0 |
| 1199 | np = add np 1 |
| 1200 | if lt cpos ve |
| 1201 | if eq add cpos 1 ve |
| 1202 | ret false |
| 1203 | end |
| 1204 | a = add cpos 1 |
| 1205 | else |
| 1206 | a = ve |
| 1207 | end |
| 1208 | end |
| 1209 | if eq np 0 |
| 1210 | ret false |
| 1211 | end |
| 1212 | put stc_ts_npairs t np |
| 1213 | ret true |
| 1214 | end |
| 1215 | |
| 1216 | fn stc_name_eq_k k ulong buf view uchar * q ulong nl ulong to bool |
| 1217 | if ne get stc_ts_nlens k nl |
| 1218 | ret false |
| 1219 | end |
| 1220 | kb = mul k 64 |
| 1221 | for j ulong nl bound 64 |
| 1222 | if ne get stc_ts_names add kb j get buf add q j |
| 1223 | ret false |
| 1224 | end |
| 1225 | end |
| 1226 | ret true |
| 1227 | end |
| 1228 | |
| 1229 | fn stc_dup_name buf view uchar * q ulong nl ulong nt ulong to bool |
| 1230 | for k ulong nt bound 64 |
| 1231 | if stc_name_eq_k k buf q nl |
| 1232 | ret true |
| 1233 | end |
| 1234 | end |
| 1235 | ret false |
| 1236 | end |
| 1237 | |
| 1238 | fn stc_kv_u64 buf view uchar * lend ulong key view uchar * to long |
| 1239 | if not stc_expect_kv buf lend key |
| 1240 | ret -1 |
| 1241 | end |
| 1242 | u = new ulong 1 0 |
| 1243 | if not stc_parse_u64 buf get stc_kv_off 0 get stc_kv_len 0 u |
| 1244 | ret -1 |
| 1245 | end |
| 1246 | put stc_kv_off 0 get u 0 |
| 1247 | ret 0 |
| 1248 | end |
| 1249 | |
| 1250 | fn stc_parse_task_fields buf view uchar * lend ulong nt ulong to long |
| 1251 | if ne stc_kv_u64 buf lend stc_k_depth 0 |
| 1252 | ret -1 |
| 1253 | end |
| 1254 | v = get stc_kv_off 0 |
| 1255 | if or lt v 1 gt v 3 |
| 1256 | ret -1 |
| 1257 | end |
| 1258 | put stc_ts_depth nt v |
| 1259 | if ne stc_kv_u64 buf lend stc_k_mcost 0 |
| 1260 | ret -1 |
| 1261 | end |
| 1262 | v = get stc_kv_off 0 |
| 1263 | if or lt v 1 gt v 64 |
| 1264 | ret -1 |
| 1265 | end |
| 1266 | put stc_ts_mcost nt v |
| 1267 | if ne stc_kv_u64 buf lend stc_k_mcand 0 |
| 1268 | ret -1 |
| 1269 | end |
| 1270 | v = get stc_kv_off 0 |
| 1271 | if or lt v 1 gt v 100000 |
| 1272 | ret -1 |
| 1273 | end |
| 1274 | put stc_ts_mcand nt v |
| 1275 | if ne stc_kv_u64 buf lend stc_k_dedup 0 |
| 1276 | ret -1 |
| 1277 | end |
| 1278 | v = get stc_kv_off 0 |
| 1279 | if gt v 1 |
| 1280 | ret -1 |
| 1281 | end |
| 1282 | put stc_ts_dedup nt v |
| 1283 | if not stc_expect_kv buf lend stc_k_pairs |
| 1284 | ret -1 |
| 1285 | end |
| 1286 | if ne get stc_pos 0 lend |
| 1287 | ret -1 |
| 1288 | end |
| 1289 | if not stc_parse_pairs buf get stc_kv_off 0 get stc_kv_len 0 nt |
| 1290 | ret -1 |
| 1291 | end |
| 1292 | put stc_ts_n 0 add nt 1 |
| 1293 | ret 0 |
| 1294 | end |
| 1295 | |
| 1296 | fn stc_parse_task_line buf view uchar * p ulong lend ulong to long |
| 1297 | nt = get stc_ts_n 0 |
| 1298 | if ge nt STC_MAX_TASKS |
| 1299 | ret -1 |
| 1300 | end |
| 1301 | q = add p 5 |
| 1302 | nend = q |
| 1303 | while lt nend lend bound 256 |
| 1304 | if eq ulong get buf nend 32 |
| 1305 | break |
| 1306 | end |
| 1307 | nend = add nend 1 |
| 1308 | end |
| 1309 | nl = sub nend q |
| 1310 | if or not stc_name_ok buf q nl ge nend lend |
| 1311 | ret -1 |
| 1312 | end |
| 1313 | if stc_dup_name buf q nl nt |
| 1314 | ret -1 |
| 1315 | end |
| 1316 | nb = mul nt 64 |
| 1317 | for j ulong nl bound 64 |
| 1318 | put stc_ts_names add nb j get buf add q j |
| 1319 | end |
| 1320 | put stc_ts_nlens nt nl |
| 1321 | put stc_pos 0 add nend 1 |
| 1322 | ret stc_parse_task_fields buf lend nt |
| 1323 | end |
| 1324 | |
| 1325 | fn stc_taskset_parse buf view uchar * blen ulong to long |
| 1326 | put stc_ts_n 0 0 |
| 1327 | if eq blen 0 |
| 1328 | ret -1 |
| 1329 | end |
| 1330 | if ne ulong get buf sub blen 1 10 |
| 1331 | ret -1 |
| 1332 | end |
| 1333 | for i ulong blen bound 65536 |
| 1334 | b = ulong get buf i |
| 1335 | if or eq b 0 eq b 13 |
| 1336 | ret -1 |
| 1337 | end |
| 1338 | end |
| 1339 | p = ulong 0 |
| 1340 | lineno = ulong 0 |
| 1341 | got_end = ulong 0 |
| 1342 | while lt p blen bound 1024 |
| 1343 | nl = p |
| 1344 | while lt nl blen bound 4096 |
| 1345 | if eq ulong get buf nl 10 |
| 1346 | break |
| 1347 | end |
| 1348 | nl = add nl 1 |
| 1349 | end |
| 1350 | lineno = add lineno 1 |
| 1351 | if ne got_end 0 |
| 1352 | ret -1 |
| 1353 | end |
| 1354 | ln = sub nl p |
| 1355 | if gt ln 0 |
| 1356 | if eq ulong get buf sub nl 1 32 |
| 1357 | ret -1 |
| 1358 | end |
| 1359 | end |
| 1360 | if eq lineno 1 |
| 1361 | if not sth_slice_eq buf p ln stc_t_ts_magic |
| 1362 | ret -1 |
| 1363 | end |
| 1364 | else |
| 1365 | if and gt ln 0 eq ulong get buf p 35 |
| 1366 | note comment line |
| 1367 | else |
| 1368 | if sth_slice_eq buf p ln stc_t_end |
| 1369 | got_end = 1 |
| 1370 | else |
| 1371 | if and gt ln 5 sth_slice_eq buf p 5 stc_t_tasksp |
| 1372 | if ne stc_parse_task_line buf p nl 0 |
| 1373 | ret -1 |
| 1374 | end |
| 1375 | else |
| 1376 | ret -1 |
| 1377 | end |
| 1378 | end |
| 1379 | end |
| 1380 | end |
| 1381 | p = add nl 1 |
| 1382 | end |
| 1383 | if or eq got_end 0 eq get stc_ts_n 0 0 |
| 1384 | ret -1 |
| 1385 | end |
| 1386 | for i ulong blen bound 65536 |
| 1387 | put sh_dat i get buf i |
| 1388 | end |
| 1389 | sh_all blen |
| 1390 | for i ulong 32 |
| 1391 | put stc_ts_dig i get sh_dig i |
| 1392 | end |
| 1393 | ret 0 |
| 1394 | end |
| 1395 | |
| 1396 | note ---- Corpus generator (synthesis + recorder) ---- |
| 1397 | |
| 1398 | fn stc_emit_body d ulong p0 ulong p1 ulong p2 ulong to void |
| 1399 | stc_out_hex2 get stc_p_op p0 |
| 1400 | stc_out_ch 58 |
| 1401 | stc_out_hex_u64 get stc_p_imm p0 |
| 1402 | if ge d 2 |
| 1403 | stc_out_ch 47 |
| 1404 | stc_out_hex2 get stc_p_op p1 |
| 1405 | stc_out_ch 58 |
| 1406 | stc_out_hex_u64 get stc_p_imm p1 |
| 1407 | end |
| 1408 | if ge d 3 |
| 1409 | stc_out_ch 47 |
| 1410 | stc_out_hex2 get stc_p_op p2 |
| 1411 | stc_out_ch 58 |
| 1412 | stc_out_hex_u64 get stc_p_imm p2 |
| 1413 | end |
| 1414 | end |
| 1415 | |
| 1416 | fn stc_count_muls d ulong p0 ulong p1 ulong p2 ulong to ulong |
| 1417 | m = ulong 0 |
| 1418 | if eq get stc_p_op p0 5 |
| 1419 | m = add m 1 |
| 1420 | end |
| 1421 | if ge d 2 |
| 1422 | if eq get stc_p_op p1 5 |
| 1423 | m = add m 1 |
| 1424 | end |
| 1425 | end |
| 1426 | if ge d 3 |
| 1427 | if eq get stc_p_op p2 5 |
| 1428 | m = add m 1 |
| 1429 | end |
| 1430 | end |
| 1431 | ret m |
| 1432 | end |
| 1433 | |
| 1434 | fn stc_emit_step_prefix d ulong par_seq ulong prim ulong to void |
| 1435 | stc_out_txt stc_t_stepsp |
| 1436 | stc_out_u64 get stc_cur_t 0 |
| 1437 | stc_out_ch 32 |
| 1438 | stc_out_u64 get stc_seq 0 |
| 1439 | stc_out_txt stc_f_d |
| 1440 | stc_out_u64 d |
| 1441 | stc_out_txt stc_f_par |
| 1442 | if eq d 1 |
| 1443 | stc_out_ch 45 |
| 1444 | else |
| 1445 | stc_out_u64 par_seq |
| 1446 | end |
| 1447 | stc_out_txt stc_f_pr |
| 1448 | stc_out_u64 prim |
| 1449 | stc_out_txt stc_f_pn |
| 1450 | stc_out_prim_name prim |
| 1451 | stc_out_txt stc_f_xf |
| 1452 | stc_out_hex2 get stc_p_op prim |
| 1453 | stc_out_ch 58 |
| 1454 | stc_out_hex_u64 get stc_p_imm prim |
| 1455 | stc_out_txt stc_f_ch |
| 1456 | end |
| 1457 | |
| 1458 | fn stc_emit_step_tail has_sig ulong sig view uchar 32 pr ulong vd ulong to void |
| 1459 | if ne has_sig 0 |
| 1460 | stc_out_txt stc_f_sg |
| 1461 | stc_out_hex32 sig |
| 1462 | else |
| 1463 | stc_out_txt stc_f_nosg |
| 1464 | end |
| 1465 | stc_out_txt stc_f_pru |
| 1466 | stc_out_prune_name pr |
| 1467 | stc_out_txt stc_f_vd |
| 1468 | stc_out_verd_name vd |
| 1469 | stc_out_txt stc_f_erc |
| 1470 | end |
| 1471 | |
| 1472 | fn stc_emit_realize d ulong p0 ulong p1 ulong p2 ulong to void |
| 1473 | insn = add mul d 2 1 |
| 1474 | rbytes = mul insn 4 |
| 1475 | rcy = add insn mul 2 stc_count_muls d p0 p1 p2 |
| 1476 | stc_out_txt stc_f_rrc |
| 1477 | stc_out_u64 rbytes |
| 1478 | stc_out_txt stc_f_rcy |
| 1479 | stc_out_u64 rcy |
| 1480 | stc_out_txt stc_f_rck |
| 1481 | end |
| 1482 | |
| 1483 | fn stc_eval_task t ulong d ulong p0 ulong p1 ulong p2 ulong to bool |
| 1484 | np = get stc_ts_npairs t |
| 1485 | pbase = mul t 16 |
| 1486 | for i ulong np bound 16 |
| 1487 | x = get stc_ts_in add pbase i |
| 1488 | want = get stc_ts_out add pbase i |
| 1489 | if ne stc_eval_chain x d p0 p1 p2 want |
| 1490 | ret false |
| 1491 | end |
| 1492 | end |
| 1493 | ret true |
| 1494 | end |
| 1495 | |
| 1496 | global stc_cand_pid uchar 32 |
| 1497 | global stc_cand_sig uchar 32 |
| 1498 | global stc_cand_hsig ulong 1 |
| 1499 | |
| 1500 | fn stc_emit_cand_full d ulong par_seq ulong p0 ulong p1 ulong p2 ulong to void |
| 1501 | prim = p0 |
| 1502 | if eq d 2 |
| 1503 | prim = p1 |
| 1504 | end |
| 1505 | if eq d 3 |
| 1506 | prim = p2 |
| 1507 | end |
| 1508 | stc_emit_step_prefix d par_seq prim |
| 1509 | pid = new uchar 32 0 |
| 1510 | for i ulong 32 |
| 1511 | put pid i get stc_cand_pid i |
| 1512 | end |
| 1513 | stc_out_hex32 pid |
| 1514 | stc_out_txt stc_f_ns |
| 1515 | stc_out_u64 d |
| 1516 | stc_out_txt stc_f_in |
| 1517 | stc_out_u64 add mul d 2 1 |
| 1518 | stc_out_txt stc_f_bd |
| 1519 | stc_emit_body d p0 p1 p2 |
| 1520 | end |
| 1521 | |
| 1522 | fn stc_emit_cand_end pr ulong vd ulong to void |
| 1523 | sig = new uchar 32 0 |
| 1524 | for i ulong 32 |
| 1525 | put sig i get stc_cand_sig i |
| 1526 | end |
| 1527 | stc_emit_step_tail get stc_cand_hsig 0 sig pr vd |
| 1528 | end |
| 1529 | |
| 1530 | fn stc_eval_cand d ulong par_seq ulong p0 ulong p1 ulong p2 ulong to ulong |
| 1531 | t = get stc_cur_t 0 |
| 1532 | insn = add mul d 2 1 |
| 1533 | pid = new uchar 32 0 |
| 1534 | sig = new uchar 32 0 |
| 1535 | stc_prog_id_chain d p0 p1 p2 pid |
| 1536 | for i ulong 32 |
| 1537 | put stc_cand_pid i get pid i |
| 1538 | end |
| 1539 | put stc_cand_hsig 0 0 |
| 1540 | if gt d 1 |
| 1541 | if or gt insn 10 gt insn get stc_ts_mcost t |
| 1542 | if eq get stc_rec_mode 0 1 |
| 1543 | stc_emit_cand_full d par_seq p0 p1 p2 |
| 1544 | stc_emit_cand_end STC_PRUNE_COST STC_VERD_NONE |
| 1545 | stc_out_txt stc_f_nor |
| 1546 | end |
| 1547 | if eq get stc_rec_mode 0 2 |
| 1548 | put stc_hook_events 0 add get stc_hook_events 0 1 |
| 1549 | end |
| 1550 | put stc_seq 0 add get stc_seq 0 1 |
| 1551 | ret 0 |
| 1552 | end |
| 1553 | end |
| 1554 | if ne get stc_ts_dedup t 0 |
| 1555 | stc_compute_sig d p0 p1 p2 sig |
| 1556 | put stc_cand_hsig 0 1 |
| 1557 | for i ulong 32 |
| 1558 | put stc_cand_sig i get sig i |
| 1559 | end |
| 1560 | if stc_equiv_contains_or_add sig insn |
| 1561 | put stc_st_peq 0 add get stc_st_peq 0 1 |
| 1562 | if eq get stc_rec_mode 0 1 |
| 1563 | stc_emit_cand_full d par_seq p0 p1 p2 |
| 1564 | stc_emit_cand_end STC_PRUNE_EQUIV STC_VERD_NONE |
| 1565 | stc_out_txt stc_f_nor |
| 1566 | end |
| 1567 | if eq get stc_rec_mode 0 2 |
| 1568 | put stc_hook_events 0 add get stc_hook_events 0 1 |
| 1569 | end |
| 1570 | put stc_seq 0 add get stc_seq 0 1 |
| 1571 | ret 0 |
| 1572 | end |
| 1573 | end |
| 1574 | if stc_eval_task t d p0 p1 p2 |
| 1575 | if eq get stc_rec_mode 0 1 |
| 1576 | stc_emit_cand_full d par_seq p0 p1 p2 |
| 1577 | stc_emit_cand_end STC_PRUNE_NONE STC_VERD_SOLVED |
| 1578 | stc_emit_realize d p0 p1 p2 |
| 1579 | end |
| 1580 | if eq get stc_rec_mode 0 2 |
| 1581 | put stc_hook_events 0 add get stc_hook_events 0 1 |
| 1582 | end |
| 1583 | put stc_seq 0 add get stc_seq 0 1 |
| 1584 | put stc_solved 0 1 |
| 1585 | put stc_st_sols 0 add get stc_st_sols 0 1 |
| 1586 | for i ulong 32 |
| 1587 | put stc_sol_id i get pid i |
| 1588 | end |
| 1589 | ret 2 |
| 1590 | end |
| 1591 | put stc_st_fail 0 add get stc_st_fail 0 1 |
| 1592 | if eq get stc_rec_mode 0 1 |
| 1593 | stc_emit_cand_full d par_seq p0 p1 p2 |
| 1594 | stc_emit_cand_end STC_PRUNE_NONE STC_VERD_REJECT |
| 1595 | stc_emit_realize d p0 p1 p2 |
| 1596 | end |
| 1597 | if eq get stc_rec_mode 0 2 |
| 1598 | put stc_hook_events 0 add get stc_hook_events 0 1 |
| 1599 | end |
| 1600 | put stc_seq 0 add get stc_seq 0 1 |
| 1601 | ret 1 |
| 1602 | end |
| 1603 | |
| 1604 | fn stc_emit_budget d ulong par_seq ulong prim ulong to void |
| 1605 | sig = new uchar 32 0 |
| 1606 | if eq get stc_rec_mode 0 1 |
| 1607 | stc_emit_step_prefix d par_seq prim |
| 1608 | stc_out_txt stc_f_nochild |
| 1609 | stc_emit_step_tail 0 sig STC_PRUNE_BUDGET STC_VERD_NONE |
| 1610 | stc_out_txt stc_f_nor |
| 1611 | end |
| 1612 | if eq get stc_rec_mode 0 2 |
| 1613 | put stc_hook_events 0 add get stc_hook_events 0 1 |
| 1614 | end |
| 1615 | put stc_seq 0 add get stc_seq 0 1 |
| 1616 | end |
| 1617 | |
| 1618 | fn stc_synth_task t ulong to void |
| 1619 | put stc_cur_t 0 t |
| 1620 | put stc_seq 0 0 |
| 1621 | put stc_eq_cnt 0 0 |
| 1622 | put stc_d1_cnt 0 0 |
| 1623 | put stc_d2_cnt 0 0 |
| 1624 | put stc_st_gen 0 0 |
| 1625 | put stc_st_peq 0 0 |
| 1626 | put stc_st_fail 0 0 |
| 1627 | put stc_st_sols 0 0 |
| 1628 | put stc_solved 0 0 |
| 1629 | for i ulong 32 |
| 1630 | put stc_sol_id i 0 |
| 1631 | end |
| 1632 | maxd = get stc_ts_depth t |
| 1633 | mcand = get stc_ts_mcand t |
| 1634 | note Depth 1 |
| 1635 | for i ulong STC_MAX_PRIMS |
| 1636 | put stc_st_gen 0 add get stc_st_gen 0 1 |
| 1637 | seq_now = get stc_seq 0 |
| 1638 | rc = stc_eval_cand 1 0 i 0 0 |
| 1639 | if eq rc 2 |
| 1640 | ret |
| 1641 | end |
| 1642 | if eq rc 1 |
| 1643 | c1 = get stc_d1_cnt 0 |
| 1644 | put stc_d1_p0 c1 i |
| 1645 | put stc_d1_seq c1 seq_now |
| 1646 | put stc_d1_cnt 0 add c1 1 |
| 1647 | end |
| 1648 | end |
| 1649 | if lt maxd 2 |
| 1650 | ret |
| 1651 | end |
| 1652 | note Depth 2 |
| 1653 | n1 = get stc_d1_cnt 0 |
| 1654 | for i ulong n1 bound 32 |
| 1655 | p0 = get stc_d1_p0 i |
| 1656 | s0 = get stc_d1_seq i |
| 1657 | for j ulong STC_MAX_PRIMS |
| 1658 | if ge get stc_st_gen 0 mcand |
| 1659 | stc_emit_budget 2 s0 j |
| 1660 | ret |
| 1661 | end |
| 1662 | put stc_st_gen 0 add get stc_st_gen 0 1 |
| 1663 | seq_now = get stc_seq 0 |
| 1664 | rc = stc_eval_cand 2 s0 p0 j 0 |
| 1665 | if eq rc 2 |
| 1666 | ret |
| 1667 | end |
| 1668 | if eq rc 1 |
| 1669 | c2 = get stc_d2_cnt 0 |
| 1670 | if lt c2 STC_MAX_CANDS |
| 1671 | put stc_d2_p0 c2 p0 |
| 1672 | put stc_d2_p1 c2 j |
| 1673 | put stc_d2_seq c2 seq_now |
| 1674 | put stc_d2_cnt 0 add c2 1 |
| 1675 | end |
| 1676 | end |
| 1677 | end |
| 1678 | end |
| 1679 | if lt maxd 3 |
| 1680 | ret |
| 1681 | end |
| 1682 | note Depth 3 |
| 1683 | n2 = get stc_d2_cnt 0 |
| 1684 | for i ulong n2 bound 512 |
| 1685 | p0 = get stc_d2_p0 i |
| 1686 | p1 = get stc_d2_p1 i |
| 1687 | s1 = get stc_d2_seq i |
| 1688 | for j ulong STC_MAX_PRIMS |
| 1689 | if ge get stc_st_gen 0 mcand |
| 1690 | stc_emit_budget 3 s1 j |
| 1691 | ret |
| 1692 | end |
| 1693 | put stc_st_gen 0 add get stc_st_gen 0 1 |
| 1694 | rc = stc_eval_cand 3 s1 p0 p1 j |
| 1695 | if eq rc 2 |
| 1696 | ret |
| 1697 | end |
| 1698 | end |
| 1699 | end |
| 1700 | end |
| 1701 | |
| 1702 | fn stc_emit_task_hdr t ulong to void |
| 1703 | tid = new uchar 32 0 |
| 1704 | stc_compute_task_id t tid |
| 1705 | stc_out_txt stc_t_tasksp |
| 1706 | stc_out_u64 t |
| 1707 | stc_out_txt stc_f_name |
| 1708 | nl = get stc_ts_nlens t |
| 1709 | nb = mul t 64 |
| 1710 | for i ulong nl bound 64 |
| 1711 | stc_out_ch get stc_ts_names add nb i |
| 1712 | end |
| 1713 | stc_out_txt stc_f_tid |
| 1714 | stc_out_hex32 tid |
| 1715 | stc_out_txt stc_f_dep |
| 1716 | stc_out_u64 get stc_ts_depth t |
| 1717 | stc_out_txt stc_f_mc |
| 1718 | stc_out_u64 get stc_ts_mcost t |
| 1719 | stc_out_txt stc_f_mk |
| 1720 | stc_out_u64 get stc_ts_mcand t |
| 1721 | stc_out_txt stc_f_dd |
| 1722 | stc_out_u64 get stc_ts_dedup t |
| 1723 | stc_out_txt stc_f_ex |
| 1724 | stc_out_u64 get stc_ts_npairs t |
| 1725 | stc_out_ch 10 |
| 1726 | end |
| 1727 | |
| 1728 | fn stc_emit_task_res t ulong to void |
| 1729 | sid = new uchar 32 0 |
| 1730 | stc_out_txt stc_t_ressp |
| 1731 | stc_out_u64 t |
| 1732 | stc_out_txt stc_f_sol1 |
| 1733 | stc_out_u64 get stc_solved 0 |
| 1734 | stc_out_txt stc_f_sol2 |
| 1735 | if ne get stc_solved 0 0 |
| 1736 | for i ulong 32 |
| 1737 | put sid i get stc_sol_id i |
| 1738 | end |
| 1739 | stc_out_hex32 sid |
| 1740 | else |
| 1741 | stc_out_ch 45 |
| 1742 | end |
| 1743 | stc_out_txt stc_f_gen |
| 1744 | stc_out_u64 get stc_st_gen 0 |
| 1745 | stc_out_txt stc_f_pt |
| 1746 | stc_out_u64 get stc_st_peq 0 |
| 1747 | stc_out_txt stc_f_fl |
| 1748 | stc_out_u64 get stc_st_fail 0 |
| 1749 | stc_out_txt stc_f_sf |
| 1750 | stc_out_u64 get stc_st_sols 0 |
| 1751 | stc_out_txt stc_f_st |
| 1752 | stc_out_u64 get stc_seq 0 |
| 1753 | stc_out_ch 10 |
| 1754 | end |
| 1755 | |
| 1756 | fn stc_corpus_generate to long |
| 1757 | stc_init |
| 1758 | if ne stc_synth_set_hook 2 9001 0 |
| 1759 | ret -1 |
| 1760 | end |
| 1761 | if ne stc_real_set_hook 2 9001 0 |
| 1762 | r = stc_synth_clear_hook 9001 |
| 1763 | ret -1 |
| 1764 | end |
| 1765 | put stc_out_len 0 0 |
| 1766 | put stc_tot_steps 0 0 |
| 1767 | put stc_rec_mode 0 1 |
| 1768 | stc_out_txt stc_t_c_magic |
| 1769 | stc_out_ch 10 |
| 1770 | stc_out_txt stc_t_tssp |
| 1771 | d = new uchar 32 0 |
| 1772 | for i ulong 32 |
| 1773 | put d i get stc_ts_dig i |
| 1774 | end |
| 1775 | stc_out_hex32 d |
| 1776 | stc_out_ch 10 |
| 1777 | stc_out_txt stc_t_machsp |
| 1778 | for i ulong 32 |
| 1779 | put d i get stc_mach_id i |
| 1780 | end |
| 1781 | stc_out_hex32 d |
| 1782 | stc_out_txt stc_f_bank |
| 1783 | nt = get stc_ts_n 0 |
| 1784 | for t ulong nt bound 64 |
| 1785 | stc_emit_task_hdr t |
| 1786 | stc_synth_task t |
| 1787 | stc_emit_task_res t |
| 1788 | put stc_tot_steps 0 add get stc_tot_steps 0 get stc_seq 0 |
| 1789 | end |
| 1790 | put stc_rec_mode 0 0 |
| 1791 | r1 = stc_synth_clear_hook 9001 |
| 1792 | r2 = stc_real_clear_hook 9001 |
| 1793 | ol = get stc_out_len 0 |
| 1794 | for i ulong ol bound 2097152 |
| 1795 | put sh_dat i get stc_out i |
| 1796 | end |
| 1797 | sh_all ol |
| 1798 | for i ulong 32 |
| 1799 | put d i get sh_dig i |
| 1800 | end |
| 1801 | stc_out_txt stc_f_et |
| 1802 | stc_out_u64 nt |
| 1803 | stc_out_txt stc_f_es |
| 1804 | stc_out_u64 get stc_tot_steps 0 |
| 1805 | stc_out_txt stc_f_ed |
| 1806 | stc_out_hex32 d |
| 1807 | stc_out_ch 10 |
| 1808 | ret 0 |
| 1809 | end |
| 1810 | |
| 1811 | note ---- Strict corpus verifier ---- |
| 1812 | |
| 1813 | fn stc_hex_ok buf view uchar * off ulong n ulong want ulong to bool |
| 1814 | if ne n want |
| 1815 | ret false |
| 1816 | end |
| 1817 | for i ulong n bound 64 |
| 1818 | c = ulong get buf add off i |
| 1819 | ok = ulong 0 |
| 1820 | if and ge c 48 le c 57 |
| 1821 | ok = 1 |
| 1822 | end |
| 1823 | if and ge c 97 le c 102 |
| 1824 | ok = 1 |
| 1825 | end |
| 1826 | if eq ok 0 |
| 1827 | ret false |
| 1828 | end |
| 1829 | end |
| 1830 | ret true |
| 1831 | end |
| 1832 | |
| 1833 | fn stc_is_dash buf view uchar * off ulong n ulong to bool |
| 1834 | if ne n 1 |
| 1835 | ret false |
| 1836 | end |
| 1837 | ret eq ulong get buf off 45 |
| 1838 | end |
| 1839 | |
| 1840 | fn stc_opimm_ok buf view uchar * off ulong n ulong to bool |
| 1841 | if lt n 4 |
| 1842 | ret false |
| 1843 | end |
| 1844 | if not stc_hex_ok buf off 2 2 |
| 1845 | ret false |
| 1846 | end |
| 1847 | if ne ulong get buf add off 2 58 |
| 1848 | ret false |
| 1849 | end |
| 1850 | m = sub n 3 |
| 1851 | if gt m 16 |
| 1852 | ret false |
| 1853 | end |
| 1854 | if gt m 1 |
| 1855 | if eq ulong get buf add off 3 48 |
| 1856 | ret false |
| 1857 | end |
| 1858 | end |
| 1859 | ret stc_hex_ok buf add off 3 m m |
| 1860 | end |
| 1861 | |
| 1862 | fn stc_body_ok buf view uchar * off ulong n ulong want_steps ulong to bool |
| 1863 | a = off |
| 1864 | e = add off n |
| 1865 | cnt = ulong 0 |
| 1866 | while lt a e bound 65 |
| 1867 | sp = e |
| 1868 | has_s = ulong 0 |
| 1869 | for i ulong sub e a bound 256 |
| 1870 | if eq ulong get buf add a i 47 |
| 1871 | sp = add a i |
| 1872 | has_s = 1 |
| 1873 | break |
| 1874 | end |
| 1875 | end |
| 1876 | if not stc_opimm_ok buf a sub sp a |
| 1877 | ret false |
| 1878 | end |
| 1879 | cnt = add cnt 1 |
| 1880 | if eq has_s 1 |
| 1881 | if eq add sp 1 e |
| 1882 | ret false |
| 1883 | end |
| 1884 | a = add sp 1 |
| 1885 | else |
| 1886 | a = e |
| 1887 | end |
| 1888 | end |
| 1889 | ret and gt cnt 0 eq cnt want_steps |
| 1890 | end |
| 1891 | |
| 1892 | fn stc_parse_prune buf view uchar * off ulong n ulong to long |
| 1893 | if sth_slice_eq buf off n stc_pn_0 |
| 1894 | ret 0 |
| 1895 | end |
| 1896 | if sth_slice_eq buf off n stc_pn_1 |
| 1897 | ret 1 |
| 1898 | end |
| 1899 | if sth_slice_eq buf off n stc_pn_2 |
| 1900 | ret 2 |
| 1901 | end |
| 1902 | if sth_slice_eq buf off n stc_pn_3 |
| 1903 | ret 3 |
| 1904 | end |
| 1905 | if sth_slice_eq buf off n stc_pn_4 |
| 1906 | ret 4 |
| 1907 | end |
| 1908 | ret -1 |
| 1909 | end |
| 1910 | |
| 1911 | fn stc_parse_verd buf view uchar * off ulong n ulong to long |
| 1912 | if sth_slice_eq buf off n stc_vn_0 |
| 1913 | ret 0 |
| 1914 | end |
| 1915 | if sth_slice_eq buf off n stc_vn_1 |
| 1916 | ret 1 |
| 1917 | end |
| 1918 | if sth_slice_eq buf off n stc_vn_2 |
| 1919 | ret 2 |
| 1920 | end |
| 1921 | if sth_slice_eq buf off n stc_vn_3 |
| 1922 | ret 3 |
| 1923 | end |
| 1924 | ret -1 |
| 1925 | end |
| 1926 | |
| 1927 | fn stc_v_find_sp buf view uchar * q ulong lend ulong to ulong |
| 1928 | r = q |
| 1929 | while lt r lend bound 4096 |
| 1930 | if eq ulong get buf r 32 |
| 1931 | ret r |
| 1932 | end |
| 1933 | r = add r 1 |
| 1934 | end |
| 1935 | ret lend |
| 1936 | end |
| 1937 | |
| 1938 | fn stc_v_tok_u64 buf view uchar * lend ulong want ulong to bool |
| 1939 | p = get stc_pos 0 |
| 1940 | nend = stc_v_find_sp buf p lend |
| 1941 | if ge nend lend |
| 1942 | ret false |
| 1943 | end |
| 1944 | u = new ulong 1 0 |
| 1945 | if not stc_parse_u64 buf p sub nend p u |
| 1946 | ret false |
| 1947 | end |
| 1948 | if ne get u 0 want |
| 1949 | ret false |
| 1950 | end |
| 1951 | put stc_pos 0 add nend 1 |
| 1952 | ret true |
| 1953 | end |
| 1954 | |
| 1955 | fn stc_v_task_line buf view uchar * p ulong lend ulong n_tasks ulong check_ts ulong to long |
| 1956 | put stc_pos 0 add p 5 |
| 1957 | if not stc_v_tok_u64 buf lend n_tasks |
| 1958 | ret -1 |
| 1959 | end |
| 1960 | if not stc_expect_kv buf lend stc_k_name |
| 1961 | ret -1 |
| 1962 | end |
| 1963 | if not stc_name_ok buf get stc_kv_off 0 get stc_kv_len 0 |
| 1964 | ret -1 |
| 1965 | end |
| 1966 | if ne check_ts 0 |
| 1967 | if or ge n_tasks get stc_ts_n 0 not stc_name_eq_k n_tasks buf get stc_kv_off 0 get stc_kv_len 0 |
| 1968 | ret -1 |
| 1969 | end |
| 1970 | end |
| 1971 | if not stc_expect_kv buf lend stc_k_tid |
| 1972 | ret -1 |
| 1973 | end |
| 1974 | if not stc_hex_ok buf get stc_kv_off 0 get stc_kv_len 0 64 |
| 1975 | ret -1 |
| 1976 | end |
| 1977 | if ne stc_kv_u64 buf lend stc_k_depth 0 |
| 1978 | ret -1 |
| 1979 | end |
| 1980 | if ne stc_kv_u64 buf lend stc_k_mcost 0 |
| 1981 | ret -1 |
| 1982 | end |
| 1983 | if ne stc_kv_u64 buf lend stc_k_mcand 0 |
| 1984 | ret -1 |
| 1985 | end |
| 1986 | if ne stc_kv_u64 buf lend stc_k_dedup 0 |
| 1987 | ret -1 |
| 1988 | end |
| 1989 | if ne stc_kv_u64 buf lend stc_k_ex 0 |
| 1990 | ret -1 |
| 1991 | end |
| 1992 | if ne get stc_pos 0 lend |
| 1993 | ret -1 |
| 1994 | end |
| 1995 | ret 0 |
| 1996 | end |
| 1997 | |
| 1998 | fn stc_v_result_line buf view uchar * p ulong lend ulong cur_t ulong seq ulong to long |
| 1999 | put stc_pos 0 add p 7 |
| 2000 | if not stc_v_tok_u64 buf lend cur_t |
| 2001 | ret -1 |
| 2002 | end |
| 2003 | if ne stc_kv_u64 buf lend stc_k_solved 0 |
| 2004 | ret -1 |
| 2005 | end |
| 2006 | sol = get stc_kv_off 0 |
| 2007 | if gt sol 1 |
| 2008 | ret -1 |
| 2009 | end |
| 2010 | if not stc_expect_kv buf lend stc_k_sol |
| 2011 | ret -1 |
| 2012 | end |
| 2013 | if eq sol 1 |
| 2014 | if not stc_hex_ok buf get stc_kv_off 0 get stc_kv_len 0 64 |
| 2015 | ret -1 |
| 2016 | end |
| 2017 | else |
| 2018 | if not stc_is_dash buf get stc_kv_off 0 get stc_kv_len 0 |
| 2019 | ret -1 |
| 2020 | end |
| 2021 | end |
| 2022 | if ne stc_kv_u64 buf lend stc_k_gen 0 |
| 2023 | ret -1 |
| 2024 | end |
| 2025 | if ne stc_kv_u64 buf lend stc_k_pt 0 |
| 2026 | ret -1 |
| 2027 | end |
| 2028 | if ne stc_kv_u64 buf lend stc_k_pe 0 |
| 2029 | ret -1 |
| 2030 | end |
| 2031 | if ne stc_kv_u64 buf lend stc_k_fail 0 |
| 2032 | ret -1 |
| 2033 | end |
| 2034 | if ne stc_kv_u64 buf lend stc_k_sols 0 |
| 2035 | ret -1 |
| 2036 | end |
| 2037 | if ne stc_kv_u64 buf lend stc_k_steps 0 |
| 2038 | ret -1 |
| 2039 | end |
| 2040 | if or ne get stc_kv_off 0 seq ne get stc_pos 0 lend |
| 2041 | ret -1 |
| 2042 | end |
| 2043 | ret 0 |
| 2044 | end |
| 2045 | |
| 2046 | fn stc_v_step_real buf view uchar * lend ulong realized ulong to long |
| 2047 | u = new ulong 1 0 |
| 2048 | if not stc_expect_kv buf lend stc_k_rrc |
| 2049 | ret -1 |
| 2050 | end |
| 2051 | if ne realized 0 |
| 2052 | if not stc_parse_i64 buf get stc_kv_off 0 get stc_kv_len 0 |
| 2053 | ret -1 |
| 2054 | end |
| 2055 | else |
| 2056 | if not stc_is_dash buf get stc_kv_off 0 get stc_kv_len 0 |
| 2057 | ret -1 |
| 2058 | end |
| 2059 | end |
| 2060 | if not stc_expect_kv buf lend stc_k_rbytes |
| 2061 | ret -1 |
| 2062 | end |
| 2063 | if ne realized 0 |
| 2064 | if not stc_parse_u64 buf get stc_kv_off 0 get stc_kv_len 0 u |
| 2065 | ret -1 |
| 2066 | end |
| 2067 | else |
| 2068 | if not stc_is_dash buf get stc_kv_off 0 get stc_kv_len 0 |
| 2069 | ret -1 |
| 2070 | end |
| 2071 | end |
| 2072 | if not stc_expect_kv buf lend stc_k_rcycles |
| 2073 | ret -1 |
| 2074 | end |
| 2075 | if ne realized 0 |
| 2076 | if not stc_parse_u64 buf get stc_kv_off 0 get stc_kv_len 0 u |
| 2077 | ret -1 |
| 2078 | end |
| 2079 | else |
| 2080 | if not stc_is_dash buf get stc_kv_off 0 get stc_kv_len 0 |
| 2081 | ret -1 |
| 2082 | end |
| 2083 | end |
| 2084 | if not stc_expect_kv buf lend stc_k_rchk |
| 2085 | ret -1 |
| 2086 | end |
| 2087 | if ne realized 0 |
| 2088 | if not stc_parse_u64 buf get stc_kv_off 0 get stc_kv_len 0 u |
| 2089 | ret -1 |
| 2090 | end |
| 2091 | else |
| 2092 | if not stc_is_dash buf get stc_kv_off 0 get stc_kv_len 0 |
| 2093 | ret -1 |
| 2094 | end |
| 2095 | end |
| 2096 | if ne get stc_pos 0 lend |
| 2097 | ret -1 |
| 2098 | end |
| 2099 | ret 0 |
| 2100 | end |
| 2101 | |
| 2102 | fn stc_v_step_tail buf view uchar * lend ulong dep ulong has_ch ulong to long |
| 2103 | if not stc_expect_kv buf lend stc_k_sig |
| 2104 | ret -1 |
| 2105 | end |
| 2106 | has_sig = ulong 1 |
| 2107 | if stc_is_dash buf get stc_kv_off 0 get stc_kv_len 0 |
| 2108 | has_sig = 0 |
| 2109 | else |
| 2110 | if not stc_hex_ok buf get stc_kv_off 0 get stc_kv_len 0 64 |
| 2111 | ret -1 |
| 2112 | end |
| 2113 | end |
| 2114 | if not stc_expect_kv buf lend stc_k_prune |
| 2115 | ret -1 |
| 2116 | end |
| 2117 | pr = stc_parse_prune buf get stc_kv_off 0 get stc_kv_len 0 |
| 2118 | if not stc_expect_kv buf lend stc_k_verd |
| 2119 | ret -1 |
| 2120 | end |
| 2121 | vd = stc_parse_verd buf get stc_kv_off 0 get stc_kv_len 0 |
| 2122 | if or lt pr 0 lt vd 0 |
| 2123 | ret -1 |
| 2124 | end |
| 2125 | if ne eq pr 0 ne vd 0 |
| 2126 | ret -1 |
| 2127 | end |
| 2128 | no_ch = or eq pr 1 eq pr 4 |
| 2129 | if eq no_ch eq has_ch 1 |
| 2130 | ret -1 |
| 2131 | end |
| 2132 | if and eq pr 3 eq has_sig 0 |
| 2133 | ret -1 |
| 2134 | end |
| 2135 | if eq dep 1 |
| 2136 | if or eq pr 1 or eq pr 2 eq pr 4 |
| 2137 | ret -1 |
| 2138 | end |
| 2139 | end |
| 2140 | if or not stc_expect_kv buf lend stc_k_erc not stc_parse_i64 buf get stc_kv_off 0 get stc_kv_len 0 |
| 2141 | ret -1 |
| 2142 | end |
| 2143 | if or not stc_expect_kv buf lend stc_k_vrc not stc_parse_i64 buf get stc_kv_off 0 get stc_kv_len 0 |
| 2144 | ret -1 |
| 2145 | end |
| 2146 | rlz = ulong 0 |
| 2147 | if eq pr 0 |
| 2148 | rlz = 1 |
| 2149 | end |
| 2150 | if ne stc_v_step_real buf lend rlz 0 |
| 2151 | ret -1 |
| 2152 | end |
| 2153 | ret pr |
| 2154 | end |
| 2155 | |
| 2156 | fn stc_v_step_line buf view uchar * p ulong lend ulong cur_t ulong seq ulong to long |
| 2157 | put stc_pos 0 add p 5 |
| 2158 | if not stc_v_tok_u64 buf lend cur_t |
| 2159 | ret -1 |
| 2160 | end |
| 2161 | if not stc_v_tok_u64 buf lend seq |
| 2162 | ret -1 |
| 2163 | end |
| 2164 | if ne stc_kv_u64 buf lend stc_k_d 0 |
| 2165 | ret -1 |
| 2166 | end |
| 2167 | dep = get stc_kv_off 0 |
| 2168 | if or lt dep 1 gt dep 3 |
| 2169 | ret -1 |
| 2170 | end |
| 2171 | if eq dep 1 |
| 2172 | if not stc_expect_kv buf lend stc_k_parent |
| 2173 | ret -1 |
| 2174 | end |
| 2175 | if not stc_is_dash buf get stc_kv_off 0 get stc_kv_len 0 |
| 2176 | ret -1 |
| 2177 | end |
| 2178 | else |
| 2179 | if ne stc_kv_u64 buf lend stc_k_parent 0 |
| 2180 | ret -1 |
| 2181 | end |
| 2182 | if ge get stc_kv_off 0 seq |
| 2183 | ret -1 |
| 2184 | end |
| 2185 | end |
| 2186 | if ne stc_kv_u64 buf lend stc_k_prim 0 |
| 2187 | ret -1 |
| 2188 | end |
| 2189 | if ge get stc_kv_off 0 32 |
| 2190 | ret -1 |
| 2191 | end |
| 2192 | if not stc_expect_kv buf lend stc_k_pname |
| 2193 | ret -1 |
| 2194 | end |
| 2195 | if and not stc_name_ok buf get stc_kv_off 0 get stc_kv_len 0 not stc_is_dash buf get stc_kv_off 0 get stc_kv_len 0 |
| 2196 | ret -1 |
| 2197 | end |
| 2198 | if or not stc_expect_kv buf lend stc_k_xform not stc_opimm_ok buf get stc_kv_off 0 get stc_kv_len 0 |
| 2199 | ret -1 |
| 2200 | end |
| 2201 | if not stc_expect_kv buf lend stc_k_child |
| 2202 | ret -1 |
| 2203 | end |
| 2204 | has_ch = ulong 1 |
| 2205 | if stc_is_dash buf get stc_kv_off 0 get stc_kv_len 0 |
| 2206 | has_ch = 0 |
| 2207 | else |
| 2208 | if not stc_hex_ok buf get stc_kv_off 0 get stc_kv_len 0 64 |
| 2209 | ret -1 |
| 2210 | end |
| 2211 | end |
| 2212 | nsteps = ulong 0 |
| 2213 | if eq has_ch 1 |
| 2214 | if ne stc_kv_u64 buf lend stc_k_nsteps 0 |
| 2215 | ret -1 |
| 2216 | end |
| 2217 | nsteps = get stc_kv_off 0 |
| 2218 | if ne stc_kv_u64 buf lend stc_k_insn 0 |
| 2219 | ret -1 |
| 2220 | end |
| 2221 | if not stc_expect_kv buf lend stc_k_body |
| 2222 | ret -1 |
| 2223 | end |
| 2224 | if not stc_body_ok buf get stc_kv_off 0 get stc_kv_len 0 nsteps |
| 2225 | ret -1 |
| 2226 | end |
| 2227 | else |
| 2228 | if or not stc_expect_kv buf lend stc_k_nsteps not stc_is_dash buf get stc_kv_off 0 get stc_kv_len 0 |
| 2229 | ret -1 |
| 2230 | end |
| 2231 | if or not stc_expect_kv buf lend stc_k_insn not stc_is_dash buf get stc_kv_off 0 get stc_kv_len 0 |
| 2232 | ret -1 |
| 2233 | end |
| 2234 | if or not stc_expect_kv buf lend stc_k_body not stc_is_dash buf get stc_kv_off 0 get stc_kv_len 0 |
| 2235 | ret -1 |
| 2236 | end |
| 2237 | end |
| 2238 | ret stc_v_step_tail buf lend dep has_ch |
| 2239 | end |
| 2240 | |
| 2241 | fn stc_v_end_dig_ok buf view uchar * p ulong vo ulong to bool |
| 2242 | for i ulong p bound 2097152 |
| 2243 | put sh_dat i get buf i |
| 2244 | end |
| 2245 | sh_all p |
| 2246 | for i ulong 32 |
| 2247 | bv = ulong get sh_dig i |
| 2248 | if ne sth_hex_nib shr bv 4 get buf add vo mul i 2 |
| 2249 | ret false |
| 2250 | end |
| 2251 | if ne sth_hex_nib and bv 15 get buf add vo add mul i 2 1 |
| 2252 | ret false |
| 2253 | end |
| 2254 | end |
| 2255 | ret true |
| 2256 | end |
| 2257 | |
| 2258 | fn stc_v_end_line buf view uchar * p ulong lend ulong n_tasks ulong check_ts ulong to long |
| 2259 | put stc_pos 0 add p 4 |
| 2260 | if ne stc_kv_u64 buf lend stc_k_tasks 0 |
| 2261 | ret -1 |
| 2262 | end |
| 2263 | if ne get stc_kv_off 0 n_tasks |
| 2264 | ret -1 |
| 2265 | end |
| 2266 | if ne stc_kv_u64 buf lend stc_k_steps 0 |
| 2267 | ret -1 |
| 2268 | end |
| 2269 | if ne get stc_kv_off 0 get stc_v_steps 0 |
| 2270 | ret -1 |
| 2271 | end |
| 2272 | if not stc_expect_kv buf lend stc_k_digest |
| 2273 | ret -1 |
| 2274 | end |
| 2275 | if or not stc_hex_ok buf get stc_kv_off 0 get stc_kv_len 0 64 ne get stc_pos 0 lend |
| 2276 | ret -1 |
| 2277 | end |
| 2278 | if not stc_v_end_dig_ok buf p get stc_kv_off 0 |
| 2279 | ret -1 |
| 2280 | end |
| 2281 | if and ne check_ts 0 ne n_tasks get stc_ts_n 0 |
| 2282 | ret -1 |
| 2283 | end |
| 2284 | if eq n_tasks 0 |
| 2285 | ret -1 |
| 2286 | end |
| 2287 | for i ulong 32 |
| 2288 | put stc_v_dig i get sh_dig i |
| 2289 | end |
| 2290 | ret 0 |
| 2291 | end |
| 2292 | |
| 2293 | fn stc_v_hdr_lines buf view uchar * p ulong ln ulong st ulong check_ts ulong to long |
| 2294 | if eq st 0 |
| 2295 | if not sth_slice_eq buf p ln stc_t_c_magic |
| 2296 | ret -1 |
| 2297 | end |
| 2298 | ret 1 |
| 2299 | end |
| 2300 | if eq st 1 |
| 2301 | if or ne ln 72 not sth_slice_eq buf p 8 stc_t_tssp |
| 2302 | ret -1 |
| 2303 | end |
| 2304 | if not stc_hex_ok buf add p 8 64 64 |
| 2305 | ret -1 |
| 2306 | end |
| 2307 | if ne check_ts 0 |
| 2308 | for i ulong 32 |
| 2309 | bv = ulong get stc_ts_dig i |
| 2310 | if ne sth_hex_nib shr bv 4 get buf add add p 8 mul i 2 |
| 2311 | ret -1 |
| 2312 | end |
| 2313 | if ne sth_hex_nib and bv 15 get buf add add p 8 add mul i 2 1 |
| 2314 | ret -1 |
| 2315 | end |
| 2316 | end |
| 2317 | end |
| 2318 | ret 2 |
| 2319 | end |
| 2320 | if or lt ln 73 not sth_slice_eq buf p 8 stc_t_machsp |
| 2321 | ret -1 |
| 2322 | end |
| 2323 | if or not stc_hex_ok buf add p 8 64 64 ne ulong get buf add p 72 32 |
| 2324 | ret -1 |
| 2325 | end |
| 2326 | put stc_pos 0 add p 73 |
| 2327 | if ne stc_kv_u64 buf add p ln stc_k_bank 0 |
| 2328 | ret -1 |
| 2329 | end |
| 2330 | bk = get stc_kv_off 0 |
| 2331 | if or eq bk 0 gt bk 32 |
| 2332 | ret -1 |
| 2333 | end |
| 2334 | if ne get stc_pos 0 add p ln |
| 2335 | ret -1 |
| 2336 | end |
| 2337 | ret 3 |
| 2338 | end |
| 2339 | |
| 2340 | global stc_vst ulong 5 |
| 2341 | |
| 2342 | fn stc_v_line buf view uchar * p ulong nl ulong check_ts ulong to long |
| 2343 | ln = sub nl p |
| 2344 | if eq ln 0 |
| 2345 | ret -1 |
| 2346 | end |
| 2347 | if eq ulong get buf sub nl 1 32 |
| 2348 | ret -1 |
| 2349 | end |
| 2350 | st = get stc_vst 0 |
| 2351 | if lt st 3 |
| 2352 | nst = stc_v_hdr_lines buf p ln st check_ts |
| 2353 | if lt nst 0 |
| 2354 | ret -1 |
| 2355 | end |
| 2356 | put stc_vst 0 ulong nst |
| 2357 | ret 0 |
| 2358 | end |
| 2359 | if eq st 3 |
| 2360 | if and ge ln 4 sth_slice_eq buf p 4 stc_t_endsp |
| 2361 | put stc_v_steps 0 get stc_vst 3 |
| 2362 | if ne stc_v_end_line buf p nl get stc_vst 1 check_ts 0 |
| 2363 | ret -1 |
| 2364 | end |
| 2365 | put stc_vst 0 5 |
| 2366 | ret 0 |
| 2367 | end |
| 2368 | if or lt ln 5 not sth_slice_eq buf p 5 stc_t_tasksp |
| 2369 | ret -1 |
| 2370 | end |
| 2371 | if ne stc_v_task_line buf p nl get stc_vst 1 check_ts 0 |
| 2372 | ret -1 |
| 2373 | end |
| 2374 | put stc_vst 1 add get stc_vst 1 1 |
| 2375 | put stc_vst 2 0 |
| 2376 | put stc_vst 4 0 |
| 2377 | put stc_vst 0 4 |
| 2378 | ret 0 |
| 2379 | end |
| 2380 | if eq st 4 |
| 2381 | cur_t = sub get stc_vst 1 1 |
| 2382 | seq = get stc_vst 2 |
| 2383 | if and ge ln 7 sth_slice_eq buf p 7 stc_t_ressp |
| 2384 | if ne stc_v_result_line buf p nl cur_t seq 0 |
| 2385 | ret -1 |
| 2386 | end |
| 2387 | put stc_vst 3 add get stc_vst 3 seq |
| 2388 | put stc_vst 0 3 |
| 2389 | ret 0 |
| 2390 | end |
| 2391 | if lt ln 5 |
| 2392 | ret -1 |
| 2393 | end |
| 2394 | if not sth_slice_eq buf p 5 stc_t_stepsp |
| 2395 | ret -1 |
| 2396 | end |
| 2397 | if ne get stc_vst 4 0 |
| 2398 | ret -1 |
| 2399 | end |
| 2400 | pr = stc_v_step_line buf p nl cur_t seq |
| 2401 | if lt pr 0 |
| 2402 | ret -1 |
| 2403 | end |
| 2404 | if eq pr 4 |
| 2405 | put stc_vst 4 1 |
| 2406 | end |
| 2407 | put stc_vst 2 add seq 1 |
| 2408 | ret 0 |
| 2409 | end |
| 2410 | ret -1 |
| 2411 | end |
| 2412 | |
| 2413 | fn stc_corpus_verify buf view uchar * blen ulong check_ts ulong to long |
| 2414 | if eq blen 0 |
| 2415 | ret -1 |
| 2416 | end |
| 2417 | if ne ulong get buf sub blen 1 10 |
| 2418 | ret -1 |
| 2419 | end |
| 2420 | for i ulong blen bound 2097152 |
| 2421 | b = ulong get buf i |
| 2422 | if or eq b 0 eq b 13 |
| 2423 | ret -1 |
| 2424 | end |
| 2425 | end |
| 2426 | for i ulong 5 |
| 2427 | put stc_vst i 0 |
| 2428 | end |
| 2429 | p = ulong 0 |
| 2430 | while lt p blen bound 200000 |
| 2431 | nl = p |
| 2432 | while lt nl blen bound 4096 |
| 2433 | if eq ulong get buf nl 10 |
| 2434 | break |
| 2435 | end |
| 2436 | nl = add nl 1 |
| 2437 | end |
| 2438 | if ne stc_v_line buf p nl check_ts 0 |
| 2439 | ret -1 |
| 2440 | end |
| 2441 | p = add nl 1 |
| 2442 | end |
| 2443 | if ne get stc_vst 0 5 |
| 2444 | ret -1 |
| 2445 | end |
| 2446 | ret 0 |
| 2447 | end |
| 2448 | |
| 2449 | note ---- Hooks-off equivalence ---- |
| 2450 | |
| 2451 | fn stc_hook_equivalence to long |
| 2452 | stc_init |
| 2453 | nt = get stc_ts_n 0 |
| 2454 | s1 = new ulong 5 0 |
| 2455 | s1_id = new uchar 32 0 |
| 2456 | for t ulong nt bound 64 |
| 2457 | put stc_rec_mode 0 0 |
| 2458 | stc_synth_task t |
| 2459 | put s1 0 get stc_solved 0 |
| 2460 | put s1 1 get stc_st_gen 0 |
| 2461 | put s1 2 get stc_st_peq 0 |
| 2462 | put s1 3 get stc_st_fail 0 |
| 2463 | put s1 4 get stc_st_sols 0 |
| 2464 | for i ulong 32 |
| 2465 | put s1_id i get stc_sol_id i |
| 2466 | end |
| 2467 | if ne stc_synth_set_hook 3 9002 0 |
| 2468 | ret -1 |
| 2469 | end |
| 2470 | put stc_hook_events 0 0 |
| 2471 | put stc_rec_mode 0 2 |
| 2472 | stc_synth_task t |
| 2473 | put stc_rec_mode 0 0 |
| 2474 | r = stc_synth_clear_hook 9002 |
| 2475 | if ne get s1 0 get stc_solved 0 |
| 2476 | ret -1 |
| 2477 | end |
| 2478 | if ne get s1 1 get stc_st_gen 0 |
| 2479 | ret -1 |
| 2480 | end |
| 2481 | if ne get s1 2 get stc_st_peq 0 |
| 2482 | ret -1 |
| 2483 | end |
| 2484 | if ne get s1 3 get stc_st_fail 0 |
| 2485 | ret -1 |
| 2486 | end |
| 2487 | if ne get s1 4 get stc_st_sols 0 |
| 2488 | ret -1 |
| 2489 | end |
| 2490 | if eq get stc_hook_events 0 0 |
| 2491 | ret -1 |
| 2492 | end |
| 2493 | if ne get s1 0 0 |
| 2494 | for i ulong 32 |
| 2495 | if ne get s1_id i get stc_sol_id i |
| 2496 | ret -1 |
| 2497 | end |
| 2498 | end |
| 2499 | end |
| 2500 | end |
| 2501 | ret 0 |
| 2502 | end |