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/src/visor/visor_realization.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 / src / visor / visor_realization.om` 520 lines ยท 12392 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Pure seeded OM-2 Visor lane 5: realization lab (replaces src/visor/visor_realization.c). 3 note Depends on visor.om, omega_lower.om, visor_machine.om. 4 5 global vrl_regs ulong 32 6 global vrl_run_out ulong 1 7 global vrl_why uchar 256 8 global vrl_wlen ulong 1 9 10 text vrl_w_div "DIV is not supported by pure AArch64 realizer" 11 text vrl_w_ovf "overflow policy must be WRAP" 12 text vrl_w_wid "operand width must be 64" 13 text vrl_w_kind "object is not a realizable APPLY" 14 text vrl_w_ok "direct pure AArch64 realization" 15 text vrl_w_incompat "INCOMPATIBLE" 16 text vrl_w_unr "program is not realized" 17 text vrl_sp2 " " 18 text vrl_sp4 " " 19 text vrl_d_ret "ret" 20 text vrl_d_add "add x0, x0, x1" 21 text vrl_d_sub "sub x0, x0, x1" 22 text vrl_d_mul "mul x0, x0, x1" 23 text vrl_d_and "and x0, x0, x1" 24 text vrl_d_orr "orr x0, x0, x1" 25 text vrl_d_eor "eor x0, x0, x1" 26 text vrl_d_movz "movz x1, #" 27 text vrl_d_movk1 "movk x1, #" 28 text vrl_d_movk2 ", lsl #16" 29 text vrl_d_insn "insn" 30 text vrl_c1 "cost (four separate classes; never merged)\n predicted cycles=" 31 text vrl_c2 " insns=" 32 text vrl_c3 " (static model)\n estimated cycles=" 33 text vrl_c4 " (omega_machine_estimate_latency)\n measured ABSENT (no receipt ingested in V1)\n qualified ABSENT (no qualified gate ingested in V1)\n" 34 text vrl_cj1 "{\"predicted\":{\"present\":true,\"cycles\":" 35 text vrl_cj2 "},\"estimated\":{\"present\":true,\"cycles\":" 36 text vrl_cj3 "},\"measured\":{\"present\":false,\"cycles\":0},\"qualified\":{\"present\":false,\"cycles\":0}}" 37 text vrl_f1 "realization: sha256:" 38 text vrl_f2 " compatible " 39 text vrl_f3 "yes\n runnable yes\n" 40 text vrl_f4 "no\n runnable no\n" 41 text vrl_f5 " code_len " 42 text vrl_j1 "{\"realization_id\":\"sha256:" 43 text vrl_j2 "\",\"compatible\":" 44 text vrl_j3 "true,\"runnable\":true" 45 text vrl_j4 "false,\"runnable\":false" 46 text vrl_j5 ",\"disasm\":[" 47 text vrl_j6 "],\"cost\":{\"predicted\":{\"present\":true,\"cycles\":" 48 text vrl_j7 "},\"estimated\":{\"present\":true,\"cycles\":" 49 text vrl_j8 "},\"measured\":{\"present\":false,\"cycles\":0},\"qualified\":{\"present\":false,\"cycles\":0}}}" 50 51 fn vrl_set_why s view uchar * to void 52 n = len s 53 if gt n 255 54 n = 255 55 end 56 for i ulong n bound 256 57 put vrl_why i get s i 58 end 59 put vrl_wlen 0 n 60 end 61 62 fn vrl_dec_insn32 ridx ulong off ulong to ulong 63 base = add mul ridx 256 off 64 b0 = ulong get v_real_code base 65 b1 = ulong get v_real_code add base 1 66 b2 = ulong get v_real_code add base 2 67 b3 = ulong get v_real_code add base 3 68 ret or or b0 shl b1 8 or shl b2 16 shl b3 24 69 end 70 71 fn vrl_put_insn32 ridx ulong off ulong w ulong to void 72 base = add mul ridx 256 off 73 put v_real_code base uchar and w 0xff 74 put v_real_code add base 1 uchar and shr w 8 0xff 75 put v_real_code add base 2 uchar and shr w 16 0xff 76 put v_real_code add base 3 uchar and shr w 24 0xff 77 end 78 79 fn vrl_disasm_insn w ulong to void 80 ob_put_hex_byte and shr w 24 0xff 81 ob_put_hex_byte and shr w 16 0xff 82 ob_put_hex_byte and shr w 8 0xff 83 ob_put_hex_byte and w 0xff 84 ob_puts vrl_sp2 85 if eq w 0xd65f03c0 86 ob_puts vrl_d_ret 87 ret 88 end 89 if eq w 0x8b010000 90 ob_puts vrl_d_add 91 ret 92 end 93 if eq w 0xcb010000 94 ob_puts vrl_d_sub 95 ret 96 end 97 if eq w 0x9b017c00 98 ob_puts vrl_d_mul 99 ret 100 end 101 if eq w 0x8a010000 102 ob_puts vrl_d_and 103 ret 104 end 105 if eq w 0xaa010000 106 ob_puts vrl_d_orr 107 ret 108 end 109 if eq w 0xca010000 110 ob_puts vrl_d_eor 111 ret 112 end 113 if eq and w 0xff80001f 0xd2800001 114 ob_puts vrl_d_movz 115 ob_put_u64 and shr w 5 0xffff 116 ret 117 end 118 if eq and w 0xff80001f 0xf2a00001 119 ob_puts vrl_d_movk1 120 ob_put_u64 and shr w 5 0xffff 121 ob_puts vrl_d_movk2 122 ret 123 end 124 ob_puts vrl_d_insn 125 end 126 127 fn vrl_is_pure_insn w ulong to bool 128 if or eq w 0x8b010000 eq w 0xcb010000 129 ret true 130 end 131 if or eq w 0x9b017c00 eq w 0x8a010000 132 ret true 133 end 134 if or eq w 0xaa010000 eq w 0xca010000 135 ret true 136 end 137 m = and w 0xff80001f 138 if or eq m 0xd2800001 eq m 0xf2a00001 139 ret true 140 end 141 ret false 142 end 143 144 fn vrl_validate_pure ridx ulong to long 145 if ge ridx get v_real_cnt 0 146 ret -3 147 end 148 if ne get v_real_prof ridx 1 149 ret -3 150 end 151 if ne get v_real_vknown ridx 0 152 if eq get v_real_compat ridx 0 153 ret -3 154 end 155 end 156 tl = get v_real_tlen ridx 157 if ge tl 9 158 tb = mul ridx 32 159 if and eq get v_real_tname tb uchar 98 eq get v_real_tname add tb 1 uchar 108 160 ret -3 161 end 162 end 163 if ne get v_real_has_mach ridx 0 164 mb = mul ridx 32 165 is_bw = true 166 for i ulong 32 167 if ne get v_real_mach_id add mb i get vmch_bw_id i 168 is_bw = false 169 break 170 end 171 end 172 if is_bw 173 ret -3 174 end 175 end 176 cl = get v_real_clen ridx 177 if or lt cl 4 ne rem cl 4 0 178 ret -3 179 end 180 nins = div cl 4 181 last = vrl_dec_insn32 ridx sub cl 4 182 if ne last 0xd65f03c0 183 ret -3 184 end 185 for i ulong sub nins 1 bound 64 186 w = vrl_dec_insn32 ridx mul i 4 187 if not vrl_is_pure_insn w 188 ret -3 189 end 190 end 191 ret 0 192 end 193 194 fn vrl_run_pure ridx ulong a0 ulong a1 ulong a2 ulong argc ulong to long 195 if gt argc 3 196 ret -3 197 end 198 if lt vrl_validate_pure ridx 0 199 ret -3 200 end 201 for i ulong 32 202 put vrl_regs i 0 203 end 204 put vrl_regs 0 a0 205 put vrl_regs 1 a1 206 put vrl_regs 2 a2 207 cl = get v_real_clen ridx 208 nins = div cl 4 209 for i ulong nins bound 64 210 w = vrl_dec_insn32 ridx mul i 4 211 if eq w 0xd65f03c0 212 break 213 end 214 if eq w 0x8b010000 215 put vrl_regs 0 add get vrl_regs 0 get vrl_regs 1 216 else 217 if eq w 0xcb010000 218 put vrl_regs 0 sub get vrl_regs 0 get vrl_regs 1 219 else 220 if eq w 0x9b017c00 221 put vrl_regs 0 mul get vrl_regs 0 get vrl_regs 1 222 else 223 if eq w 0x8a010000 224 put vrl_regs 0 and get vrl_regs 0 get vrl_regs 1 225 else 226 if eq w 0xaa010000 227 put vrl_regs 0 or get vrl_regs 0 get vrl_regs 1 228 else 229 if eq w 0xca010000 230 put vrl_regs 0 xor get vrl_regs 0 get vrl_regs 1 231 else 232 if eq and w 0xff80001f 0xd2800001 233 put vrl_regs 1 and shr w 5 0xffff 234 else 235 if eq and w 0xff80001f 0xf2a00001 236 imm = and shr w 5 0xffff 237 cur = and get vrl_regs 1 0xffffffff0000ffff 238 put vrl_regs 1 or cur shl imm 16 239 end 240 end 241 end 242 end 243 end 244 end 245 end 246 end 247 end 248 put vrl_run_out 0 get vrl_regs 0 249 ret 0 250 end 251 252 fn vrl_estimate_cycles ridx ulong is_spark ulong to ulong 253 nins = div get v_real_clen ridx 4 254 if eq is_spark 1 255 ret add nins 1 256 end 257 ret add mul nins 2 1 258 end 259 260 fn vrl_finish_apply_meta rc ulong apply_idx ulong opi ulong to void 261 tl = len vmch_t_a64 262 put v_real_tlen rc tl 263 tb = mul rc 32 264 for i ulong tl bound 32 265 put v_real_tname add tb i get vmch_t_a64 i 266 end 267 sb = mul apply_idx 32 268 ob = mul opi 32 269 rb = mul rc 32 270 for i ulong 32 271 put v_real_subj_id add rb i get v_og_id add sb i 272 put v_real_sem_id add rb i get v_og_id add ob i 273 put v_real_mach_id add rb i get vmch_id i 274 end 275 cb = mul rc 256 276 for i ulong 8 277 put v_sha_in i get v_real_code add cb i 278 end 279 for i ulong 32 280 put v_sha_in add 8 i get v_real_sem_id add rb i 281 end 282 sha256_hash 40 283 for i ulong 32 284 put v_real_id add rb i get v_sha_out i 285 end 286 end 287 288 fn vrl_realize_apply apply_idx ulong to long 289 if ge apply_idx get v_og_cnt 0 290 vrl_set_why vrl_w_kind 291 ret -2 292 end 293 if or ne get v_og_kind apply_idx V_KIND_OP ne get v_og_plen apply_idx 161 294 vrl_set_why vrl_w_kind 295 ret -2 296 end 297 pb = mul apply_idx V_MAX_PAYLOAD 298 for i ulong 32 299 put v_tmp_id i get v_og_pay add pb i 300 end 301 opi = og_find_by_tmp 302 if lt opi 0 303 vrl_set_why vrl_w_kind 304 ret -2 305 end 306 opb = mul ulong opi V_MAX_PAYLOAD 307 opc = v_dec_u32le_pay opb 0 308 ovf = v_dec_u32le_pay opb 4 309 info = olw_obj_type_info ulong opi 310 wid = and info 0xffff 311 if eq opc V_OP_DIV 312 vrl_set_why vrl_w_div 313 ret -2 314 end 315 if ne ovf V_OVF_WRAP 316 vrl_set_why vrl_w_ovf 317 ret -2 318 end 319 if ne wid 64 320 vrl_set_why vrl_w_wid 321 ret -2 322 end 323 insn = ulong 0 324 if eq opc V_OP_ADD 325 insn = 0x8b010000 326 else 327 if eq opc V_OP_SUB 328 insn = 0xcb010000 329 else 330 if eq opc V_OP_MUL 331 insn = 0x9b017c00 332 else 333 if eq opc V_OP_AND 334 insn = 0x8a010000 335 else 336 if eq opc V_OP_OR 337 insn = 0xaa010000 338 else 339 if eq opc V_OP_XOR 340 insn = 0xca010000 341 else 342 vrl_set_why vrl_w_kind 343 ret -2 344 end 345 end 346 end 347 end 348 end 349 end 350 rc = get v_real_cnt 0 351 if ge rc V_MAX_REALS 352 ret -1 353 end 354 put v_real_cnt 0 add rc 1 355 vrl_put_insn32 rc 0 insn 356 vrl_put_insn32 rc 4 0xd65f03c0 357 put v_real_clen rc 8 358 put v_real_prof rc 1 359 put v_real_is_prog rc 0 360 put v_real_pidx rc -1 361 put v_real_vknown rc 1 362 put v_real_compat rc 1 363 put v_real_ilen rc 0 364 put v_real_has_mach rc 1 365 put v_real_has_est rc 1 366 put v_real_est rc vrl_estimate_cycles rc get vmch_is_spark 0 367 vrl_finish_apply_meta rc apply_idx ulong opi 368 vrl_set_why vrl_w_ok 369 ret long rc 370 end 371 372 fn vrl_realize_program pidx ulong to long 373 if ge pidx get v_prog_cnt 0 374 ret -2 375 end 376 if eq get v_prog_realized pidx 0 377 vrl_set_why vrl_w_unr 378 ret -2 379 end 380 rc = get v_real_cnt 0 381 if ge rc V_MAX_REALS 382 ret -1 383 end 384 put v_real_cnt 0 add rc 1 385 cl = get v_prog_clen pidx 386 put v_real_clen rc cl 387 pcb = mul pidx 256 388 rcb = mul rc 256 389 for i ulong cl bound 256 390 put v_real_code add rcb i get v_prog_code add pcb i 391 put v_sha_in i get v_prog_code add pcb i 392 end 393 put v_real_prof rc 1 394 put v_real_is_prog rc 1 395 put v_real_pidx rc long pidx 396 put v_real_vknown rc 1 397 put v_real_compat rc 1 398 put v_real_ilen rc 0 399 put v_real_has_mach rc 1 400 put v_real_has_est rc 1 401 put v_real_est rc vrl_estimate_cycles rc get vmch_is_spark 0 402 tl = len vmch_t_a64 403 put v_real_tlen rc tl 404 tb = mul rc 32 405 for i ulong tl bound 32 406 put v_real_tname add tb i get vmch_t_a64 i 407 end 408 pb = mul pidx 32 409 rb = mul rc 32 410 for i ulong 32 411 put v_real_subj_id add rb i get v_prog_id add pb i 412 put v_real_sem_id add rb i get v_prog_id add pb i 413 put v_real_mach_id add rb i get vmch_id i 414 put v_sha_in add cl i get v_prog_id add pb i 415 end 416 sha256_hash add cl 32 417 for i ulong 32 418 put v_real_id add rb i get v_sha_out i 419 end 420 vrl_set_why vrl_w_ok 421 ret long rc 422 end 423 424 fn vrl_format_cost_text ridx ulong cap ulong to long 425 ob_reset cap 426 nins = div get v_real_clen ridx 4 427 est = get v_real_est ridx 428 ob_puts vrl_c1 429 ob_put_u64 nins 430 ob_puts vrl_c2 431 ob_put_u64 nins 432 ob_puts vrl_c3 433 ob_put_u64 est 434 ob_puts vrl_c4 435 if ne get v_ob_ovf 0 0 436 ret -1 437 end 438 ret long get v_ob_len 0 439 end 440 441 fn vrl_format_cost_json ridx ulong cap ulong to long 442 ob_reset cap 443 nins = div get v_real_clen ridx 4 444 est = get v_real_est ridx 445 ob_puts vrl_cj1 446 ob_put_u64 nins 447 ob_puts vrl_cj2 448 ob_put_u64 est 449 ob_puts vrl_cj3 450 if ne get v_ob_ovf 0 0 451 ret -1 452 end 453 ret long get v_ob_len 0 454 end 455 456 fn vrl_format_text ridx ulong cap ulong to long 457 ob_reset cap 458 rb = mul ridx 32 459 ob_puts vrl_f1 460 for i ulong 32 461 ob_put_hex_byte ulong get v_real_id add rb i 462 end 463 ob_putc uchar 10 464 ok = eq vrl_validate_pure ridx 0 465 ob_puts vrl_f2 466 if ok 467 ob_puts vrl_f3 468 else 469 ob_puts vrl_f4 470 end 471 ob_puts vrl_f5 472 ob_put_u64 get v_real_clen ridx 473 ob_putc uchar 10 474 nins = div get v_real_clen ridx 4 475 for i ulong nins bound 64 476 ob_puts vrl_sp4 477 vrl_disasm_insn vrl_dec_insn32 ridx mul i 4 478 ob_putc uchar 10 479 end 480 if ne get v_ob_ovf 0 0 481 ret -1 482 end 483 ret long get v_ob_len 0 484 end 485 486 fn vrl_format_json ridx ulong cap ulong to long 487 ob_reset cap 488 rb = mul ridx 32 489 ok = eq vrl_validate_pure ridx 0 490 nins = div get v_real_clen ridx 4 491 est = get v_real_est ridx 492 ob_puts vrl_j1 493 for i ulong 32 494 ob_put_hex_byte ulong get v_real_id add rb i 495 end 496 ob_puts vrl_j2 497 if ok 498 ob_puts vrl_j3 499 else 500 ob_puts vrl_j4 501 end 502 ob_puts vrl_j5 503 for i ulong nins bound 64 504 if gt i 0 505 ob_putc uchar 44 506 end 507 ob_putc uchar 34 508 vrl_disasm_insn vrl_dec_insn32 ridx mul i 4 509 ob_putc uchar 34 510 end 511 ob_puts vrl_j6 512 ob_put_u64 nins 513 ob_puts vrl_j7 514 ob_put_u64 est 515 ob_puts vrl_j8 516 if ne get v_ob_ovf 0 0 517 ret -1 518 end 519 ret long get v_ob_len 0 520 end