Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/polyglot/test_asm.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / polyglot / test_asm.om` 480 lines ยท 12244 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 note 4 note tests/polyglot/test_asm.om -- pure seeded OM-2 POLYGLOT-0 lane B1 correctness gate 5 note (asm_sdot, asm_crumb): loads/verifies actual AArch64 machine code from 6 note src/polyglot/asm/omx_{sdot,crumb}.S (when .text.bin paths are passed) or 7 note omx_encoder_build, audits every instruction word and callee-saved ABI 8 note (x19..x28, d8..d15), runs negative bit-mutation differential checks, and 9 note executes the AArch64 machine code via omx_vm_exec across error contract, 10 note MA-3 shape grid, random unaligned+canary+guard cases, and large magnitudes 11 note up to OMX_MAX_N (16,777,215). 12 13 global g_ta_st ulong 8 14 note [0]=checks [1]=fail [2]=cases [3]=rng [4]=mut_caught [5]=gnu_matched 15 global g_ta_arg uchar 512 16 global g_ta_ns ulong 31 17 global g_ta_ms ulong 10 18 global g_ta_sps f64 5 19 global g_ta_bad byte 5 20 21 text t_ta_hdr "POLYGLOT test-asm " 22 text t_ta_pass "PASS" 23 text t_ta_fail "FAIL" 24 text t_ta_sep1 ": " 25 text t_ta_chk " checks, " 26 text t_ta_fls " failures; 2 candidates (AArch64 machine-code exec + ABI/guard); cases: grid " 27 text t_ta_rnd ", random " 28 text t_ta_lrg ", large " 29 text t_ta_mut "; mut-caught " 30 text t_ta_gnu ", gnu-as-words " 31 text t_ta_err "; error-contract checks " 32 text t_ta_efail "FAIL test_asm check #" 33 34 fn ta_init_tables to void 35 for i ulong 8 36 put g_ta_st i 0 37 end 38 put g_ta_st 3 0x504f4c5941534d31 39 40 put g_ta_ns 0 1 41 put g_ta_ns 1 2 42 put g_ta_ns 2 3 43 put g_ta_ns 3 4 44 put g_ta_ns 4 5 45 put g_ta_ns 5 7 46 put g_ta_ns 6 15 47 put g_ta_ns 7 16 48 put g_ta_ns 8 17 49 put g_ta_ns 9 31 50 put g_ta_ns 10 32 51 put g_ta_ns 11 33 52 put g_ta_ns 12 63 53 put g_ta_ns 13 64 54 put g_ta_ns 14 65 55 put g_ta_ns 15 79 56 put g_ta_ns 16 80 57 put g_ta_ns 17 81 58 put g_ta_ns 18 127 59 put g_ta_ns 19 128 60 put g_ta_ns 20 129 61 put g_ta_ns 21 159 62 put g_ta_ns 22 160 63 put g_ta_ns 23 161 64 put g_ta_ns 24 255 65 put g_ta_ns 25 256 66 put g_ta_ns 26 257 67 put g_ta_ns 27 1000 68 put g_ta_ns 28 1023 69 put g_ta_ns 29 1024 70 put g_ta_ns 30 1025 71 72 put g_ta_ms 0 1 73 put g_ta_ms 1 2 74 put g_ta_ms 2 3 75 put g_ta_ms 3 4 76 put g_ta_ms 4 5 77 put g_ta_ms 5 7 78 put g_ta_ms 6 15 79 put g_ta_ms 7 16 80 put g_ta_ms 8 17 81 put g_ta_ms 9 33 82 83 put g_ta_sps 0 0.0f64 84 put g_ta_sps 1 0.3f64 85 put g_ta_sps 2 0.6f64 86 put g_ta_sps 3 0.9f64 87 put g_ta_sps 4 1.0f64 88 89 put g_ta_bad 0 byte 2 90 put g_ta_bad 1 byte -2 91 put g_ta_bad 2 byte -128 92 put g_ta_bad 3 byte 127 93 put g_ta_bad 4 byte 3 94 end 95 96 fn ta_rnd to ulong 97 st = new ulong 1 0 98 put st 0 get g_ta_st 3 99 v = omx_rng_next st 100 put g_ta_st 3 get st 0 101 ret v 102 end 103 104 fn ta_rnd01 to f64 105 st = new ulong 1 0 106 put st 0 get g_ta_st 3 107 v = omx_rng_01 st 108 put g_ta_st 3 get st 0 109 ret v 110 end 111 112 fn ta_chk cond bool to void 113 c = add get g_ta_st 0 1 114 put g_ta_st 0 c 115 if not cond 116 f = add get g_ta_st 1 1 117 put g_ta_st 1 f 118 if le f 20 119 omx_eputs t_ta_efail 120 omx_eputu c 121 omx_enl 122 end 123 end 124 end 125 126 note Verify GNU as .text.bin matches emitted object form, then load final form into VM. 127 fn ta_verify_gnu_bin k ulong argi ulong to void 128 alen = argread argi g_ta_arg 0 512 129 ta_chk gt alen 0 130 if le alen 0 131 ret 132 end 133 ta_chk eq omx_encoder_build k 0 0 134 n = get g_enc_st 0 135 fd = fopen g_ta_arg 0 ulong alen 0 0 136 ta_chk ge fd 0 137 if lt fd 0 138 ret 139 end 140 tot = ulong 0 141 while lt tot 262144 bound 262144 142 r = read int fd g_omx_fbuf tot sub 262144 tot 143 if le r 0 144 break 145 end 146 tot = add tot ulong r 147 end 148 _c = fclose int fd 149 ta_chk eq tot mul 4 n 150 same = ulong 0 151 diff = ulong 0 152 for i ulong n bound 512 153 if le add mul 4 i 4 tot 154 g = uint omx_u32_le_fbuf mul 4 i 155 e = get g_enc_word i 156 if eq g e 157 same = add same 1 158 else 159 diff = add diff 1 160 end 161 end 162 end 163 ta_chk eq diff 0 164 put g_ta_st 5 add get g_ta_st 5 same 165 end 166 167 note Negative differential checks: mutating emitted machine code MUST fail audit/ABI/exec! 168 fn ta_test_mutations to void 169 for i ulong 64 170 put g_omx_w i byte 1 171 put g_omx_x i byte 2 172 end 173 ta_chk eq omx_oracle 1 64 0 OMX_OK 174 175 note 1. Corrupt opcode bit (bit 28) in sdot -> audit & exec must reject 176 ta_chk eq omx_pack_sdot 1 64 1 OMX_OK 177 orig0 = get g_vm_c0 10 178 put g_vm_c0 10 xor orig0 uint 0x10000000 179 ta_chk ne omx_vm_audit_kernel OMX_ENC_SDOT 0 180 rc_bad = omx_vm_exec OMX_ENC_SDOT 7 0 0 181 ta_chk ne rc_bad 0 182 put g_vm_c0 10 orig0 183 put g_ta_st 4 add get g_ta_st 4 1 184 185 note 2. Clobber callee-saved x19 in sdot -> audit returns -2 & exec returns -104 (ABI) 186 orig1 = get g_vm_c0 11 187 clob = uint omx_a64_movz 1 19 42 188 put g_vm_c0 11 clob 189 ta_chk eq omx_vm_audit_word ulong clob -2 190 rc_abi = omx_vm_exec OMX_ENC_SDOT 7 0 0 191 ta_chk eq rc_abi -104 192 put g_vm_c0 11 orig1 193 put g_ta_st 4 add get g_ta_st 4 1 194 195 note 3. Functional mutation in crumb (change movz w0, #0 at ok exit to movz w0, #7) -> exec returns 7 != 0 196 ta_chk eq omx_pack_crumb 1 64 1 OMX_OK 197 nc1 = get g_vm_meta 3 198 ok_idx = sub nc1 4 199 orig2 = get g_vm_c1 ok_idx 200 put g_vm_c1 ok_idx uint omx_a64_movz 0 0 7 201 rc_mut = omx_vm_exec OMX_ENC_CRUMB 7 0 0 202 ta_chk eq rc_mut 7 203 put g_vm_c1 ok_idx orig2 204 put g_ta_st 4 add get g_ta_st 4 1 205 206 note 4. Verify clean kernels pass after restoration 207 ta_chk eq omx_vm_audit_kernel OMX_ENC_SDOT 0 208 ta_chk eq omx_vm_audit_kernel OMX_ENC_CRUMB 0 209 ta_chk eq omx_vm_exec OMX_ENC_CRUMB 7 0 0 OMX_OK 210 ta_chk eq get g_omx_y 0 get g_omx_yref 0 211 omx_plan_zero 212 end 213 214 note wk: 0=random 1=zero 2=pos 3=neg 215 fn ta_fill_w cnt ulong wk ulong sp f64 to void 216 for i ulong cnt bound `16777216` 217 if eq wk 1 218 put g_omx_w i byte 0 219 else 220 if eq wk 2 221 put g_omx_w i byte 1 222 else 223 if eq wk 3 224 put g_omx_w i byte -1 225 else 226 if lt ta_rnd01 sp 227 put g_omx_w i byte 0 228 else 229 if eq and ta_rnd 1 1 230 put g_omx_w i byte 1 231 else 232 put g_omx_w i byte -1 233 end 234 end 235 end 236 end 237 end 238 end 239 end 240 241 note xk: 0=random 1=min(-128) 2=max(127) 3=alt 4=zero 242 fn ta_fill_x xoff ulong n ulong xk ulong to void 243 for j ulong n bound `16777216` 244 if eq xk 1 245 put g_omx_x add xoff j byte -128 246 else 247 if eq xk 2 248 put g_omx_x add xoff j byte 127 249 else 250 if eq xk 3 251 if eq and j 1 1 252 put g_omx_x add xoff j byte 127 253 else 254 put g_omx_x add xoff j byte -128 255 end 256 else 257 if eq xk 4 258 put g_omx_x add xoff j byte 0 259 else 260 u = and ta_rnd 255 261 if ge u 128 262 put g_omx_x add xoff j byte sub long u 256 263 else 264 put g_omx_x add xoff j byte long u 265 end 266 end 267 end 268 end 269 end 270 end 271 end 272 273 fn ta_run_rep kind ulong m ulong xoff ulong yoff ulong to void 274 for i ulong m bound 65536 275 put g_omx_y add yoff i int 0x5a5a5a5a 276 end 277 ta_chk eq omx_vm_run_cand kind xoff yoff 1 1 OMX_OK 278 bad = ulong 0 279 for i ulong m bound 65536 280 if ne get g_omx_y add yoff i get g_omx_yref i 281 bad = add bad 1 282 end 283 end 284 ta_chk eq bad 0 285 end 286 287 fn ta_check_impl kind ulong m ulong n ulong xoff ulong yoff ulong to void 288 rc = omx_pack_cand kind m n 1 289 ta_chk eq rc OMX_OK 290 if ne rc OMX_OK 291 omx_plan_zero 292 ret 293 end 294 ta_chk and gt get g_omx_plan 2 0 ge get g_omx_plan 3 get g_omx_plan 2 295 ta_run_rep kind m xoff yoff 296 ta_run_rep kind m xoff yoff 297 omx_plan_zero 298 put g_ta_st 2 add get g_ta_st 2 1 299 end 300 301 fn ta_run_case m ulong n ulong wk ulong sp f64 xk ulong to void 302 ta_fill_w mul m n wk sp 303 ta_fill_x 0 n xk 304 ta_chk eq omx_oracle m n 0 OMX_OK 305 ta_check_impl OMX_CAND_SDOT m n 0 0 306 ta_check_impl OMX_CAND_CRUMB m n 0 0 307 end 308 309 fn ta_check_spill ybase ulong yend ulong ytot ulong to void 310 spill = ulong 0 311 for i ulong ybase bound 65536 312 if ne get g_omx_y i int -`1515870811` 313 spill = add spill 1 314 end 315 end 316 i = yend 317 while lt i ytot bound 65536 318 if ne get g_omx_y i int -`1515870811` 319 spill = add spill 1 320 end 321 i = add i 1 322 end 323 ta_chk eq spill 0 324 end 325 326 fn ta_run_random m ulong n ulong sp f64 xk ulong xo ulong yo ulong to void 327 ta_fill_w mul m n 0 sp 328 ta_fill_x xo n xk 329 ta_chk eq omx_oracle m n xo OMX_OK 330 ybase = add 16 yo 331 yend = add ybase m 332 ytot = add m 48 333 for c ulong 2 334 kind = OMX_CAND_SDOT 335 if eq c 1 336 kind = OMX_CAND_CRUMB 337 end 338 for i ulong ytot bound 65536 339 put g_omx_y i int -`1515870811` 340 end 341 ta_check_impl kind m n xo ybase 342 ta_check_spill ybase yend ytot 343 end 344 end 345 346 fn ta_test_errors to void 347 put g_omx_w 0 byte 1 348 put g_omx_w 1 byte 0 349 put g_omx_w 2 byte -1 350 put g_omx_w 3 byte 1 351 put g_omx_w 4 byte 0 352 put g_omx_w 5 byte 1 353 put g_omx_x 0 byte 1 354 put g_omx_x 1 byte 2 355 put g_omx_x 2 byte 3 356 for c ulong 2 357 kind = OMX_CAND_SDOT 358 k = OMX_ENC_SDOT 359 if eq c 1 360 kind = OMX_CAND_CRUMB 361 k = OMX_ENC_CRUMB 362 end 363 for b ulong 5 364 put g_omx_w 3 get g_ta_bad b 365 put g_omx_plan 5 77 366 ta_chk eq omx_pack_cand kind 2 3 1 OMX_E_TRIT 367 ta_chk eq omx_plan_is_zero 1 368 end 369 put g_omx_w 3 byte 1 370 put g_omx_plan 5 77 371 ta_chk eq omx_pack_cand kind 0 3 1 OMX_E_ARG 372 ta_chk eq omx_plan_is_zero 1 373 ta_chk eq omx_pack_cand kind 2 0 1 OMX_E_ARG 374 ta_chk eq omx_pack_cand kind 2 3 0 OMX_E_ARG 375 ta_chk eq omx_plan_is_zero 1 376 ta_chk eq omx_pack_cand kind 1 add OMX_MAX_N 1 1 OMX_E_ARG 377 ta_chk eq omx_pack_cand kind 1 OMX_ULONG_MAX 1 OMX_E_ARG 378 ta_chk eq omx_pack_cand kind div OMX_ULONG_MAX 2 1000 1 OMX_E_OVERFLOW 379 ta_chk eq omx_plan_is_zero 1 380 omx_plan_zero 381 note Real AArch64 machine-code null/empty plan checks (cbz x0/x1/x2/x3/x4/x5) 382 ta_chk eq omx_vm_exec k 7 0 0 OMX_E_ARG 383 ta_chk eq omx_vm_exec k 6 0 0 OMX_E_ARG 384 ta_chk eq omx_pack_cand kind 2 3 1 OMX_OK 385 ta_chk eq omx_vm_exec k 5 0 0 OMX_E_ARG 386 ta_chk eq omx_vm_exec k 3 0 0 OMX_E_ARG 387 put g_omx_plan 0 0 388 ta_chk eq omx_vm_exec k 7 0 0 OMX_E_ARG 389 put g_omx_plan 0 2 390 put g_omx_plan 1 0 391 ta_chk eq omx_vm_exec k 7 0 0 OMX_E_ARG 392 put g_omx_plan 1 3 393 ta_chk eq omx_vm_exec k 7 0 0 OMX_OK 394 ta_chk eq get g_omx_y 0 int -2 395 ta_chk eq get g_omx_y 1 int 4 396 omx_plan_zero 397 end 398 end 399 400 fn main to int 401 ta_init_tables 402 if eq argcnt 3 403 ta_verify_gnu_bin OMX_ENC_SDOT 1 404 ta_verify_gnu_bin OMX_ENC_CRUMB 2 405 end 406 ta_chk eq omx_vm_load_kernel OMX_ENC_SDOT 0 407 ta_chk eq omx_vm_load_kernel OMX_ENC_CRUMB 0 408 ta_test_mutations 409 ta_test_errors 410 c0 = get g_ta_st 0 411 412 note 1. MA-3 shape grid executed on actual AArch64 machine code 413 for a ulong 31 414 nv = get g_ta_ns a 415 for b ulong 10 416 mv = get g_ta_ms b 417 ta_run_case mv nv 1 0.0f64 0 418 ta_run_case mv nv 2 0.0f64 1 419 ta_run_case mv nv 2 0.0f64 2 420 ta_run_case mv nv 3 0.0f64 1 421 ta_run_case mv nv 3 0.0f64 2 422 ta_run_case mv nv 0 get g_ta_sps rem add a b 5 3 423 ta_run_case mv nv 0 get g_ta_sps rem add mul a 3 b 5 0 424 end 425 end 426 grid_cases = get g_ta_st 2 427 428 note 2. random cases with unaligned offsets, guard bounds & y canaries 429 for it ulong 500 bound 500 430 n = add 1 rem ta_rnd 2100 431 m = add 1 rem ta_rnd 70 432 xk = ulong 0 433 if eq rem ta_rnd 4 0 434 xk = rem ta_rnd 5 435 end 436 xo = add 1 rem ta_rnd 15 437 yo = add 1 rem ta_rnd 15 438 ta_run_random m n ta_rnd01 xk xo yo 439 end 440 random_cases = sub get g_ta_st 2 grid_cases 441 442 note 3. large magnitudes up to OMX_MAX_N 443 ta_run_case 5 16384 3 0.0f64 1 444 ta_run_case 5 16384 2 0.0f64 1 445 ta_run_case 1 100003 3 0.0f64 1 446 ta_run_case 6 `1048613` 0 0.3f64 0 447 ta_run_case 17 4099 0 0.97f64 0 448 ta_run_case 1 OMX_MAX_N 3 0.0f64 1 449 ta_run_case 1 OMX_MAX_N 2 0.0f64 1 450 ta_run_case 1 OMX_MAX_N 0 0.5f64 3 451 large_cases = sub sub get g_ta_st 2 grid_cases random_cases 452 453 omx_puts t_ta_hdr 454 if eq get g_ta_st 1 0 455 omx_puts t_ta_pass 456 else 457 omx_puts t_ta_fail 458 end 459 omx_puts t_ta_sep1 460 omx_putu get g_ta_st 0 461 omx_puts t_ta_chk 462 omx_putu get g_ta_st 1 463 omx_puts t_ta_fls 464 omx_putu grid_cases 465 omx_puts t_ta_rnd 466 omx_putu random_cases 467 omx_puts t_ta_lrg 468 omx_putu large_cases 469 omx_puts t_ta_mut 470 omx_putu get g_ta_st 4 471 omx_puts t_ta_gnu 472 omx_putu get g_ta_st 5 473 omx_puts t_ta_err 474 omx_putu c0 475 omx_nl 476 if ne get g_ta_st 1 0 477 ret 1 478 end 479 ret 0 480 end