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 / tests / polyglot / test_encoder.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | note |
| 4 | note tests/polyglot/test_encoder.om -- pure seeded OM-2 POLYGLOT-0 lane B2 gate: |
| 5 | note A. Byte comparison vs GNU as .text.bin (argv[1] sdot, argv[2] crumb) |
| 6 | note B. Final-form ADRP/ADD data relocation verification |
| 7 | note C. Omega AArch64 decoder round-trip verification |
| 8 | note D. Fail-closed invalid-operand checks (39) + all 5,334 logical immediates |
| 9 | note E. Error contract + MA-3 shape grid + random + large magnitudes up to OMX_MAX_N |
| 10 | |
| 11 | note [0]=checks [1]=fail [2]=cases [3]=rng [4]=identical [5]=differ |
| 12 | note [6]=rt_full [7]=rt_partial [8]=rt_ext_unsup [9]=rt_ext_alias |
| 13 | global g_te_st ulong 12 |
| 14 | global g_te_arg uchar 512 |
| 15 | global g_te_obj uint 1024 |
| 16 | global g_te_ns ulong 31 |
| 17 | global g_te_ms ulong 10 |
| 18 | global g_te_sps f64 5 |
| 19 | global g_te_bad byte 5 |
| 20 | |
| 21 | text t_te_usage "usage: test_encoder <gnu-as sdot .text.bin> <gnu-as crumb .text.bin>\n" |
| 22 | text t_te_banner "POLYGLOT test-encoder: byte comparison vs GNU as (B1 .text)\n" |
| 23 | text t_te_bc1 " byte-compare " |
| 24 | text t_te_sdot "enc_sdot" |
| 25 | text t_te_crumb "enc_crumb" |
| 26 | text t_te_bc2 ": " |
| 27 | text t_te_bc3 " instructions, " |
| 28 | text t_te_bc4 " identical, " |
| 29 | text t_te_bc5 " differ (object form; " |
| 30 | text t_te_bc6 " carry a data relocation, fields zero in both)\n" |
| 31 | text t_te_diff " DIFF +" |
| 32 | text t_te_omega " omega=" |
| 33 | text t_te_gnu " gnu-as=" |
| 34 | text t_te_fin1 " final " |
| 35 | text t_te_fin2 ": " |
| 36 | text t_te_fin3 " bytes at page-aligned base 0x10000000; " |
| 37 | text t_te_fin4 " relocated instruction(s) differ from object form, 0 others\n" |
| 38 | text t_te_rt1 " omega-decoder round trip: " |
| 39 | text t_te_rt2 " full, " |
| 40 | text t_te_rt3 " partial, " |
| 41 | text t_te_rt4 " ext-unsupported, " |
| 42 | text t_te_rt5 " ext-alias (ADD lsl)\n" |
| 43 | text t_te_fc1 " fail-closed: " |
| 44 | text t_te_fc2 " invalid-operand calls checked; logical immediates round-tripped: " |
| 45 | text t_te_hdr "POLYGLOT test-encoder " |
| 46 | text t_te_pass "PASS" |
| 47 | text t_te_fail "FAIL" |
| 48 | text t_te_s1 ": " |
| 49 | text t_te_s2 " checks, " |
| 50 | text t_te_s3 " failures; 2 candidates; byte-compare " |
| 51 | text t_te_s4 " identical, " |
| 52 | text t_te_s5 " differ; encoder checks " |
| 53 | text t_te_s6 "; cases: grid " |
| 54 | text t_te_s7 ", random " |
| 55 | text t_te_s8 ", large " |
| 56 | text t_te_s9 "; error-contract checks " |
| 57 | text t_te_efail "FAIL test_encoder check #" |
| 58 | |
| 59 | fn te_init to void |
| 60 | for i ulong 12 |
| 61 | put g_te_st i 0 |
| 62 | end |
| 63 | put g_te_st 3 0x504f4c59454e4331 |
| 64 | |
| 65 | put g_te_ns 0 1 |
| 66 | put g_te_ns 1 2 |
| 67 | put g_te_ns 2 3 |
| 68 | put g_te_ns 3 4 |
| 69 | put g_te_ns 4 5 |
| 70 | put g_te_ns 5 7 |
| 71 | put g_te_ns 6 15 |
| 72 | put g_te_ns 7 16 |
| 73 | put g_te_ns 8 17 |
| 74 | put g_te_ns 9 31 |
| 75 | put g_te_ns 10 32 |
| 76 | put g_te_ns 11 33 |
| 77 | put g_te_ns 12 63 |
| 78 | put g_te_ns 13 64 |
| 79 | put g_te_ns 14 65 |
| 80 | put g_te_ns 15 79 |
| 81 | put g_te_ns 16 80 |
| 82 | put g_te_ns 17 81 |
| 83 | put g_te_ns 18 127 |
| 84 | put g_te_ns 19 128 |
| 85 | put g_te_ns 20 129 |
| 86 | put g_te_ns 21 159 |
| 87 | put g_te_ns 22 160 |
| 88 | put g_te_ns 23 161 |
| 89 | put g_te_ns 24 255 |
| 90 | put g_te_ns 25 256 |
| 91 | put g_te_ns 26 257 |
| 92 | put g_te_ns 27 1000 |
| 93 | put g_te_ns 28 1023 |
| 94 | put g_te_ns 29 1024 |
| 95 | put g_te_ns 30 1025 |
| 96 | |
| 97 | put g_te_ms 0 1 |
| 98 | put g_te_ms 1 2 |
| 99 | put g_te_ms 2 3 |
| 100 | put g_te_ms 3 4 |
| 101 | put g_te_ms 4 5 |
| 102 | put g_te_ms 5 7 |
| 103 | put g_te_ms 6 15 |
| 104 | put g_te_ms 7 16 |
| 105 | put g_te_ms 8 17 |
| 106 | put g_te_ms 9 33 |
| 107 | |
| 108 | put g_te_sps 0 0.0f64 |
| 109 | put g_te_sps 1 0.3f64 |
| 110 | put g_te_sps 2 0.6f64 |
| 111 | put g_te_sps 3 0.9f64 |
| 112 | put g_te_sps 4 1.0f64 |
| 113 | |
| 114 | put g_te_bad 0 byte 2 |
| 115 | put g_te_bad 1 byte -2 |
| 116 | put g_te_bad 2 byte -128 |
| 117 | put g_te_bad 3 byte 127 |
| 118 | put g_te_bad 4 byte 3 |
| 119 | end |
| 120 | |
| 121 | fn te_rnd to ulong |
| 122 | st = new ulong 1 0 |
| 123 | put st 0 get g_te_st 3 |
| 124 | v = omx_rng_next st |
| 125 | put g_te_st 3 get st 0 |
| 126 | ret v |
| 127 | end |
| 128 | |
| 129 | fn te_rnd01 to f64 |
| 130 | st = new ulong 1 0 |
| 131 | put st 0 get g_te_st 3 |
| 132 | v = omx_rng_01 st |
| 133 | put g_te_st 3 get st 0 |
| 134 | ret v |
| 135 | end |
| 136 | |
| 137 | fn te_chk cond bool to void |
| 138 | c = add get g_te_st 0 1 |
| 139 | put g_te_st 0 c |
| 140 | if not cond |
| 141 | f = add get g_te_st 1 1 |
| 142 | put g_te_st 1 f |
| 143 | if le f 20 |
| 144 | omx_eputs t_te_efail |
| 145 | omx_eputu c |
| 146 | omx_enl |
| 147 | end |
| 148 | end |
| 149 | end |
| 150 | |
| 151 | fn te_kname k ulong to void |
| 152 | if eq k OMX_ENC_SDOT |
| 153 | omx_puts t_te_sdot |
| 154 | else |
| 155 | omx_puts t_te_crumb |
| 156 | end |
| 157 | end |
| 158 | |
| 159 | note A. Byte comparison vs GNU as .text.bin |
| 160 | fn te_byte_compare k ulong argi ulong to void |
| 161 | alen = argread argi g_te_arg 0 512 |
| 162 | te_chk gt alen 0 |
| 163 | if le alen 0 |
| 164 | ret |
| 165 | end |
| 166 | te_chk eq omx_encoder_build k 0 0 |
| 167 | n = get g_enc_st 0 |
| 168 | fd = fopen g_te_arg 0 ulong alen 0 0 |
| 169 | te_chk ge fd 0 |
| 170 | if lt fd 0 |
| 171 | ret |
| 172 | end |
| 173 | tot = ulong 0 |
| 174 | while lt tot 262144 bound 262144 |
| 175 | r = read int fd g_omx_fbuf tot sub 262144 tot |
| 176 | if le r 0 |
| 177 | break |
| 178 | end |
| 179 | tot = add tot ulong r |
| 180 | end |
| 181 | _c = fclose int fd |
| 182 | te_chk eq tot mul 4 n |
| 183 | same = ulong 0 |
| 184 | diff = ulong 0 |
| 185 | relocs = ulong 0 |
| 186 | for i ulong n bound 1024 |
| 187 | if le add mul 4 i 4 tot |
| 188 | g = uint omx_u32_le_fbuf mul 4 i |
| 189 | e = get g_enc_word i |
| 190 | if ne get g_enc_reloc i OMX_ENC_RELOC_NONE |
| 191 | relocs = add relocs 1 |
| 192 | end |
| 193 | if eq g e |
| 194 | same = add same 1 |
| 195 | else |
| 196 | diff = add diff 1 |
| 197 | omx_puts t_te_diff |
| 198 | omx_putu mul 4 i |
| 199 | omx_puts t_te_omega |
| 200 | omx_putx32 e |
| 201 | omx_puts t_te_gnu |
| 202 | omx_putx32 g |
| 203 | omx_nl |
| 204 | end |
| 205 | end |
| 206 | end |
| 207 | put g_te_st 4 add get g_te_st 4 same |
| 208 | put g_te_st 5 add get g_te_st 5 diff |
| 209 | te_chk eq diff 0 |
| 210 | omx_puts t_te_bc1 |
| 211 | te_kname k |
| 212 | omx_puts t_te_bc2 |
| 213 | omx_putu n |
| 214 | omx_puts t_te_bc3 |
| 215 | omx_putu same |
| 216 | omx_puts t_te_bc4 |
| 217 | omx_putu diff |
| 218 | omx_puts t_te_bc5 |
| 219 | omx_putu relocs |
| 220 | omx_puts t_te_bc6 |
| 221 | end |
| 222 | |
| 223 | note B. Final-form relocation check |
| 224 | fn te_final_form k ulong to void |
| 225 | te_chk eq omx_encoder_build k 0 0 |
| 226 | n0 = get g_enc_st 0 |
| 227 | for i ulong n0 bound 1024 |
| 228 | put g_te_obj i get g_enc_word i |
| 229 | end |
| 230 | base = ulong 0x10000000 |
| 231 | te_chk eq omx_encoder_build k base 0 |
| 232 | n1 = get g_enc_st 0 |
| 233 | doff = get g_enc_st 4 |
| 234 | te_chk eq n0 n1 |
| 235 | te_chk eq and doff 15 0 |
| 236 | reloc_diff = ulong 0 |
| 237 | other_diff = ulong 0 |
| 238 | for i ulong n1 bound 1024 |
| 239 | if ne get g_te_obj i get g_enc_word i |
| 240 | if ne get g_enc_reloc i OMX_ENC_RELOC_NONE |
| 241 | reloc_diff = add reloc_diff 1 |
| 242 | else |
| 243 | other_diff = add other_diff 1 |
| 244 | end |
| 245 | end |
| 246 | end |
| 247 | te_chk eq other_diff 0 |
| 248 | omx_puts t_te_fin1 |
| 249 | te_kname k |
| 250 | omx_puts t_te_fin2 |
| 251 | omx_putu mul 4 n1 |
| 252 | omx_puts t_te_fin3 |
| 253 | omx_putu reloc_diff |
| 254 | omx_puts t_te_fin4 |
| 255 | end |
| 256 | |
| 257 | note C. Omega decoder round trip |
| 258 | fn te_sext v ulong bits ulong to long |
| 259 | m = shl ulong 1 sub bits 1 |
| 260 | mask = sub shl ulong 1 bits 1 |
| 261 | u = and v mask |
| 262 | ret sub long xor u m long m |
| 263 | end |
| 264 | |
| 265 | fn te_check_dec_insn i ulong w ulong dec view ulong 9 to void |
| 266 | op = get dec 0 |
| 267 | re = long -1 |
| 268 | full = ulong 1 |
| 269 | if eq op 9 |
| 270 | d = te_sext get dec 7 26 |
| 271 | te_chk eq d long get g_enc_bdisp i |
| 272 | re = omx_a64_b d |
| 273 | else |
| 274 | if eq op 10 |
| 275 | d = te_sext get dec 7 19 |
| 276 | te_chk eq d long get g_enc_bdisp i |
| 277 | re = omx_a64_bcond get dec 8 d |
| 278 | else |
| 279 | if eq op 11 |
| 280 | d = te_sext get dec 7 19 |
| 281 | te_chk eq d long get g_enc_bdisp i |
| 282 | re = omx_a64_cbz get dec 1 get dec 2 d |
| 283 | else |
| 284 | if eq op 1 |
| 285 | re = omx_a64_addreg get dec 1 get dec 2 get dec 3 get dec 4 |
| 286 | else |
| 287 | if eq op 2 |
| 288 | re = omx_a64_subreg get dec 1 get dec 2 get dec 3 get dec 4 |
| 289 | else |
| 290 | if eq op 5 |
| 291 | re = omx_a64_orrreg get dec 1 get dec 2 get dec 3 get dec 4 |
| 292 | else |
| 293 | if eq op 7 |
| 294 | re = omx_a64_movz get dec 1 get dec 2 get dec 5 |
| 295 | else |
| 296 | if eq op 8 |
| 297 | re = omx_a64_ret |
| 298 | else |
| 299 | full = 0 |
| 300 | end |
| 301 | end |
| 302 | end |
| 303 | end |
| 304 | end |
| 305 | end |
| 306 | end |
| 307 | end |
| 308 | if eq full 1 |
| 309 | if ge re 0 |
| 310 | te_chk eq ulong re w |
| 311 | else |
| 312 | te_chk false |
| 313 | end |
| 314 | put g_te_st 6 add get g_te_st 6 1 |
| 315 | else |
| 316 | te_chk or eq op 19 or eq op 15 eq op 16 |
| 317 | te_chk and eq get dec 2 and w 31 eq get dec 3 and shr w 5 31 |
| 318 | put g_te_st 7 add get g_te_st 7 1 |
| 319 | end |
| 320 | end |
| 321 | |
| 322 | fn te_decoder_round_trip k ulong to void |
| 323 | te_chk eq omx_encoder_build k 0 0 |
| 324 | n = get g_enc_st 0 |
| 325 | dec = new ulong 9 0 |
| 326 | for i ulong n bound 1024 |
| 327 | w = ulong get g_enc_word i |
| 328 | rc = omx_a64_decode w dec |
| 329 | if eq get g_enc_orig i OMX_ENC_FROM_EXT |
| 330 | if ne rc 0 |
| 331 | put g_te_st 8 add get g_te_st 8 1 |
| 332 | else |
| 333 | put g_te_st 9 add get g_te_st 9 1 |
| 334 | te_chk and eq get dec 0 1 eq get g_enc_lsl i 1 |
| 335 | end |
| 336 | continue |
| 337 | end |
| 338 | te_chk eq rc 0 |
| 339 | if eq rc 0 |
| 340 | te_check_dec_insn i w dec |
| 341 | end |
| 342 | end |
| 343 | end |
| 344 | |
| 345 | note D. Fail-closed invalid-operand checks + all 5,334 logical immediates |
| 346 | fn te_bm_topbit v ulong to long |
| 347 | b = long 6 |
| 348 | while ge b 0 bound 8 |
| 349 | if ne and v shl ulong 1 ulong b 0 |
| 350 | ret b |
| 351 | end |
| 352 | b = sub b 1 |
| 353 | end |
| 354 | ret -1 |
| 355 | end |
| 356 | |
| 357 | fn te_bm_rep elem ulong esize ulong to ulong |
| 358 | res = ulong 0 |
| 359 | sh = ulong 0 |
| 360 | while lt sh 64 bound 64 |
| 361 | res = or res shl elem sh |
| 362 | sh = add sh esize |
| 363 | end |
| 364 | ret res |
| 365 | end |
| 366 | |
| 367 | fn te_bm_elem s ulong r ulong esize ulong to ulong |
| 368 | emask = ulong 0xffffffffffffffff |
| 369 | if lt esize 64 |
| 370 | emask = sub shl ulong 1 esize 1 |
| 371 | end |
| 372 | welem = sub shl ulong 1 add s 1 1 |
| 373 | if gt r 0 |
| 374 | ret and or shr welem r shl welem sub esize r emask |
| 375 | end |
| 376 | ret welem |
| 377 | end |
| 378 | |
| 379 | fn te_decode_bitmask nbit ulong immr ulong imms ulong ok edit ulong 1 to ulong |
| 380 | put ok 0 0 |
| 381 | blen = te_bm_topbit or shl nbit 6 and not imms 0x3f |
| 382 | if lt blen 1 |
| 383 | ret 0 |
| 384 | end |
| 385 | lu = ulong blen |
| 386 | levels = sub shl ulong 1 lu 1 |
| 387 | s = and imms levels |
| 388 | if eq s levels |
| 389 | ret 0 |
| 390 | end |
| 391 | elem = te_bm_elem s and immr levels shl ulong 1 lu |
| 392 | put ok 0 1 |
| 393 | ret te_bm_rep elem shl ulong 1 lu |
| 394 | end |
| 395 | |
| 396 | fn te_check_bm_one nb ulong immr ulong imms ulong to ulong |
| 397 | ok = new ulong 1 0 |
| 398 | v = te_decode_bitmask nb immr imms ok |
| 399 | if eq get ok 0 0 |
| 400 | ret 0 |
| 401 | end |
| 402 | esize = ulong 0 |
| 403 | if eq nb 1 |
| 404 | esize = 64 |
| 405 | else |
| 406 | b = long 5 |
| 407 | while ge b 1 bound 8 |
| 408 | if eq and imms shl ulong 1 ulong b 0 |
| 409 | esize = shl ulong 1 ulong b |
| 410 | break |
| 411 | end |
| 412 | b = sub b 1 |
| 413 | end |
| 414 | end |
| 415 | if or eq esize 0 ge immr esize |
| 416 | ret 0 |
| 417 | end |
| 418 | enc = new ulong 3 0 |
| 419 | rc = oxe_bitmask_imm64 v enc |
| 420 | m0 = eq rc 0 |
| 421 | m1 = eq get enc 0 nb |
| 422 | m2 = eq get enc 1 immr |
| 423 | m3 = eq get enc 2 imms |
| 424 | te_chk and and m0 m1 and m2 m3 |
| 425 | ret 1 |
| 426 | end |
| 427 | |
| 428 | fn te_check_all_bm to ulong |
| 429 | valid = ulong 0 |
| 430 | for nb ulong 2 |
| 431 | for immr ulong 64 |
| 432 | for imms ulong 64 |
| 433 | valid = add valid te_check_bm_one nb immr imms |
| 434 | end |
| 435 | end |
| 436 | end |
| 437 | ret valid |
| 438 | end |
| 439 | |
| 440 | fn te_fail_closed to void |
| 441 | te_chk eq oxe_sdot_4s 32 0 0 -1 |
| 442 | te_chk eq oxe_sdot_4s 0 0 40 -1 |
| 443 | te_chk eq oxe_sdot_4s 0 32 0 -1 |
| 444 | te_chk eq oxe_sshr_16b 0 0 0 -1 |
| 445 | te_chk eq oxe_sshr_16b 0 0 9 -1 |
| 446 | te_chk eq oxe_shl_16b 0 0 8 -1 |
| 447 | te_chk eq oxe_movi_16b 0 256 -1 |
| 448 | te_chk eq oxe_ld1_4x16b_post 0 9 32 -1 |
| 449 | te_chk eq oxe_ld1_4x16b 0 32 -1 |
| 450 | te_chk eq oxe_ldp_x_off 3 4 0 4 -1 |
| 451 | te_chk eq oxe_ldp_x_off 3 4 0 512 -1 |
| 452 | te_chk eq oxe_ldp_x_off 3 3 0 0 -1 |
| 453 | te_chk eq oxe_ldr_q_post 0 9 256 -1 |
| 454 | te_chk eq oxe_str_q_post 0 9 -257 -1 |
| 455 | te_chk eq oxe_ldr_q_uoff 0 9 8 -1 |
| 456 | te_chk eq oxe_ldr_q_uoff 0 9 65536 -1 |
| 457 | te_chk eq oxe_stp_q_off 0 0 31 1024 -1 |
| 458 | te_chk eq oxe_stp_q_off 0 0 31 8 -1 |
| 459 | te_chk eq oxe_ldrsb_w_post 5 5 1 -1 |
| 460 | te_chk eq oxe_and_imm_x 8 4 0 -1 |
| 461 | te_chk eq oxe_and_imm_x 8 4 0xffffffffffffffff -1 |
| 462 | te_chk eq oxe_and_imm_x 8 4 5 -1 |
| 463 | te_chk eq oxe_ands_imm_x 8 4 0x1234 -1 |
| 464 | te_chk eq oxe_ubfx_x 7 4 60 5 -1 |
| 465 | te_chk eq oxe_ubfx_x 7 4 4 0 -1 |
| 466 | te_chk eq oxe_lsl_imm_x 7 7 64 -1 |
| 467 | te_chk eq oxe_lsr_imm_x 7 7 64 -1 |
| 468 | te_chk eq oxe_add_imm_x 31 31 4096 0 -1 |
| 469 | te_chk eq oxe_sub_imm_x 31 31 64 2 -1 |
| 470 | te_chk eq oxe_add_lsl_x 5 5 4 64 -1 |
| 471 | te_chk eq oxe_cinc_x 7 6 14 -1 |
| 472 | te_chk eq oxe_csinc_x 7 6 6 16 -1 |
| 473 | te_chk eq oxe_movn_w 0 0x10000 0 -1 |
| 474 | te_chk eq oxe_movn_w 0 0 2 -1 |
| 475 | te_chk eq oxe_adrp 16 1048576 -1 |
| 476 | te_chk eq oxe_adrp 16 -1048577 -1 |
| 477 | te_chk eq oxe_madd_w 6 10 11 32 -1 |
| 478 | te_chk eq oxe_addv_4s 32 24 -1 |
| 479 | te_chk eq oxe_str_s_post 24 2 300 -1 |
| 480 | |
| 481 | valid = te_check_all_bm |
| 482 | te_chk eq valid 5334 |
| 483 | omx_puts t_te_fc1 |
| 484 | omx_putu 39 |
| 485 | omx_puts t_te_fc2 |
| 486 | omx_putu valid |
| 487 | omx_nl |
| 488 | end |
| 489 | |
| 490 | note E. Correctness suite for enc_sdot & enc_crumb |
| 491 | fn te_fill_w cnt ulong wk ulong sp f64 to void |
| 492 | for i ulong cnt bound 16777216 |
| 493 | if eq wk 1 |
| 494 | put g_omx_w i byte 0 |
| 495 | else |
| 496 | if eq wk 2 |
| 497 | put g_omx_w i byte 1 |
| 498 | else |
| 499 | if eq wk 3 |
| 500 | put g_omx_w i byte -1 |
| 501 | else |
| 502 | if lt te_rnd01 sp |
| 503 | put g_omx_w i byte 0 |
| 504 | else |
| 505 | if eq and te_rnd 1 1 |
| 506 | put g_omx_w i byte 1 |
| 507 | else |
| 508 | put g_omx_w i byte -1 |
| 509 | end |
| 510 | end |
| 511 | end |
| 512 | end |
| 513 | end |
| 514 | end |
| 515 | end |
| 516 | |
| 517 | fn te_fill_x xoff ulong n ulong xk ulong to void |
| 518 | for j ulong n bound 16777216 |
| 519 | if eq xk 1 |
| 520 | put g_omx_x add xoff j byte -128 |
| 521 | else |
| 522 | if eq xk 2 |
| 523 | put g_omx_x add xoff j byte 127 |
| 524 | else |
| 525 | if eq xk 3 |
| 526 | if eq and j 1 1 |
| 527 | put g_omx_x add xoff j byte 127 |
| 528 | else |
| 529 | put g_omx_x add xoff j byte -128 |
| 530 | end |
| 531 | else |
| 532 | if eq xk 4 |
| 533 | put g_omx_x add xoff j byte 0 |
| 534 | else |
| 535 | u = and te_rnd 255 |
| 536 | if ge u 128 |
| 537 | put g_omx_x add xoff j byte sub long u 256 |
| 538 | else |
| 539 | put g_omx_x add xoff j byte long u |
| 540 | end |
| 541 | end |
| 542 | end |
| 543 | end |
| 544 | end |
| 545 | end |
| 546 | end |
| 547 | |
| 548 | fn te_run_rep kind ulong m ulong xoff ulong yoff ulong to void |
| 549 | for i ulong m bound 65536 |
| 550 | put g_omx_y add yoff i int 0x5a5a5a5a |
| 551 | end |
| 552 | te_chk eq omx_run_cand kind xoff yoff 1 1 OMX_OK |
| 553 | bad = ulong 0 |
| 554 | for i ulong m bound 65536 |
| 555 | if ne get g_omx_y add yoff i get g_omx_yref i |
| 556 | bad = add bad 1 |
| 557 | end |
| 558 | end |
| 559 | te_chk eq bad 0 |
| 560 | end |
| 561 | |
| 562 | fn te_check_impl kind ulong m ulong n ulong xoff ulong yoff ulong to void |
| 563 | rc = omx_pack_cand kind m n 1 |
| 564 | te_chk eq rc OMX_OK |
| 565 | if ne rc OMX_OK |
| 566 | omx_plan_zero |
| 567 | ret |
| 568 | end |
| 569 | te_chk and gt get g_omx_plan 2 0 ge get g_omx_plan 3 get g_omx_plan 2 |
| 570 | te_run_rep kind m xoff yoff |
| 571 | te_run_rep kind m xoff yoff |
| 572 | omx_plan_zero |
| 573 | put g_te_st 2 add get g_te_st 2 1 |
| 574 | end |
| 575 | |
| 576 | fn te_run_case m ulong n ulong wk ulong sp f64 xk ulong to void |
| 577 | te_fill_w mul m n wk sp |
| 578 | te_fill_x 0 n xk |
| 579 | te_chk eq omx_oracle m n 0 OMX_OK |
| 580 | te_check_impl OMX_CAND_ENC_SDOT m n 0 0 |
| 581 | te_check_impl OMX_CAND_ENC_CRUMB m n 0 0 |
| 582 | end |
| 583 | |
| 584 | fn te_check_spill ybase ulong yend ulong ytot ulong to void |
| 585 | spill = ulong 0 |
| 586 | for i ulong ybase bound 65536 |
| 587 | if ne get g_omx_y i int -1515870811 |
| 588 | spill = add spill 1 |
| 589 | end |
| 590 | end |
| 591 | i = yend |
| 592 | while lt i ytot bound 65536 |
| 593 | if ne get g_omx_y i int -1515870811 |
| 594 | spill = add spill 1 |
| 595 | end |
| 596 | i = add i 1 |
| 597 | end |
| 598 | te_chk eq spill 0 |
| 599 | end |
| 600 | |
| 601 | fn te_run_random m ulong n ulong sp f64 xk ulong xo ulong yo ulong to void |
| 602 | te_fill_w mul m n 0 sp |
| 603 | te_fill_x xo n xk |
| 604 | te_chk eq omx_oracle m n xo OMX_OK |
| 605 | ybase = add 16 yo |
| 606 | yend = add ybase m |
| 607 | ytot = add m 48 |
| 608 | for c ulong 2 |
| 609 | kind = OMX_CAND_ENC_SDOT |
| 610 | if eq c 1 |
| 611 | kind = OMX_CAND_ENC_CRUMB |
| 612 | end |
| 613 | for i ulong ytot bound 65536 |
| 614 | put g_omx_y i int -1515870811 |
| 615 | end |
| 616 | te_check_impl kind m n xo ybase |
| 617 | te_check_spill ybase yend ytot |
| 618 | end |
| 619 | end |
| 620 | |
| 621 | fn te_test_errors to void |
| 622 | put g_omx_w 0 byte 1 |
| 623 | put g_omx_w 1 byte 0 |
| 624 | put g_omx_w 2 byte -1 |
| 625 | put g_omx_w 3 byte 1 |
| 626 | put g_omx_w 4 byte 0 |
| 627 | put g_omx_w 5 byte 1 |
| 628 | put g_omx_x 0 byte 1 |
| 629 | put g_omx_x 1 byte 2 |
| 630 | put g_omx_x 2 byte 3 |
| 631 | for c ulong 2 |
| 632 | kind = OMX_CAND_ENC_SDOT |
| 633 | if eq c 1 |
| 634 | kind = OMX_CAND_ENC_CRUMB |
| 635 | end |
| 636 | for b ulong 5 |
| 637 | put g_omx_w 3 get g_te_bad b |
| 638 | put g_omx_plan 5 77 |
| 639 | te_chk eq omx_pack_cand kind 2 3 1 OMX_E_TRIT |
| 640 | te_chk eq omx_plan_is_zero 1 |
| 641 | end |
| 642 | put g_omx_w 3 byte 1 |
| 643 | put g_omx_plan 5 77 |
| 644 | te_chk eq omx_pack_cand kind 0 3 1 OMX_E_ARG |
| 645 | te_chk eq omx_plan_is_zero 1 |
| 646 | te_chk eq omx_pack_cand kind 2 0 1 OMX_E_ARG |
| 647 | te_chk eq omx_pack_cand kind 2 3 0 OMX_E_ARG |
| 648 | te_chk eq omx_plan_is_zero 1 |
| 649 | te_chk eq omx_pack_cand kind 1 add OMX_MAX_N 1 1 OMX_E_ARG |
| 650 | te_chk eq omx_pack_cand kind 1 OMX_ULONG_MAX 1 OMX_E_ARG |
| 651 | te_chk eq omx_pack_cand kind div OMX_ULONG_MAX 2 1000 1 OMX_E_OVERFLOW |
| 652 | te_chk eq omx_plan_is_zero 1 |
| 653 | omx_plan_zero |
| 654 | te_chk eq omx_run_cand kind 0 0 1 1 OMX_E_ARG |
| 655 | te_chk eq omx_pack_cand kind 2 3 1 OMX_OK |
| 656 | te_chk eq omx_run_cand kind 0 0 0 1 OMX_E_ARG |
| 657 | te_chk eq omx_run_cand kind 0 0 1 0 OMX_E_ARG |
| 658 | te_chk eq omx_run_cand kind 0 0 1 1 OMX_OK |
| 659 | te_chk eq get g_omx_y 0 int -2 |
| 660 | te_chk eq get g_omx_y 1 int 4 |
| 661 | omx_plan_zero |
| 662 | end |
| 663 | end |
| 664 | |
| 665 | fn main to int |
| 666 | if ne argcnt 3 |
| 667 | omx_eputs t_te_usage |
| 668 | ret 2 |
| 669 | end |
| 670 | te_init |
| 671 | omx_puts t_te_banner |
| 672 | te_byte_compare OMX_ENC_SDOT 1 |
| 673 | te_byte_compare OMX_ENC_CRUMB 2 |
| 674 | for k ulong OMX_ENC_KERNELS |
| 675 | te_final_form k |
| 676 | te_decoder_round_trip k |
| 677 | end |
| 678 | omx_puts t_te_rt1 |
| 679 | omx_putu get g_te_st 6 |
| 680 | omx_puts t_te_rt2 |
| 681 | omx_putu get g_te_st 7 |
| 682 | omx_puts t_te_rt3 |
| 683 | omx_putu get g_te_st 8 |
| 684 | omx_puts t_te_rt4 |
| 685 | omx_putu get g_te_st 9 |
| 686 | omx_puts t_te_rt5 |
| 687 | te_fail_closed |
| 688 | enc_checks = get g_te_st 0 |
| 689 | te_test_errors |
| 690 | c0 = get g_te_st 0 |
| 691 | |
| 692 | for a ulong 31 |
| 693 | nv = get g_te_ns a |
| 694 | for b ulong 10 |
| 695 | mv = get g_te_ms b |
| 696 | te_run_case mv nv 1 0.0f64 0 |
| 697 | te_run_case mv nv 2 0.0f64 1 |
| 698 | te_run_case mv nv 2 0.0f64 2 |
| 699 | te_run_case mv nv 3 0.0f64 1 |
| 700 | te_run_case mv nv 3 0.0f64 2 |
| 701 | te_run_case mv nv 0 get g_te_sps rem add a b 5 3 |
| 702 | te_run_case mv nv 0 get g_te_sps rem add mul a 3 b 5 0 |
| 703 | end |
| 704 | end |
| 705 | grid_cases = get g_te_st 2 |
| 706 | |
| 707 | for it ulong 2000 bound 2000 |
| 708 | n = add 1 rem te_rnd 2100 |
| 709 | m = add 1 rem te_rnd 70 |
| 710 | xk = ulong 0 |
| 711 | if eq rem te_rnd 4 0 |
| 712 | xk = rem te_rnd 5 |
| 713 | end |
| 714 | xo = add 1 rem te_rnd 15 |
| 715 | yo = add 1 rem te_rnd 15 |
| 716 | te_run_random m n te_rnd01 xk xo yo |
| 717 | end |
| 718 | random_cases = sub get g_te_st 2 grid_cases |
| 719 | |
| 720 | te_run_case 5 16384 3 0.0f64 1 |
| 721 | te_run_case 5 16384 2 0.0f64 1 |
| 722 | te_run_case 1 100003 3 0.0f64 1 |
| 723 | te_run_case 6 1048613 0 0.3f64 0 |
| 724 | te_run_case 17 4099 0 0.97f64 0 |
| 725 | te_run_case 1 OMX_MAX_N 3 0.0f64 1 |
| 726 | te_run_case 1 OMX_MAX_N 2 0.0f64 1 |
| 727 | te_run_case 1 OMX_MAX_N 0 0.5f64 3 |
| 728 | large_cases = sub sub get g_te_st 2 grid_cases random_cases |
| 729 | |
| 730 | omx_puts t_te_hdr |
| 731 | if eq get g_te_st 1 0 |
| 732 | omx_puts t_te_pass |
| 733 | else |
| 734 | omx_puts t_te_fail |
| 735 | end |
| 736 | omx_puts t_te_s1 |
| 737 | omx_putu get g_te_st 0 |
| 738 | omx_puts t_te_s2 |
| 739 | omx_putu get g_te_st 1 |
| 740 | omx_puts t_te_s3 |
| 741 | omx_putu get g_te_st 4 |
| 742 | omx_puts t_te_s4 |
| 743 | omx_putu get g_te_st 5 |
| 744 | omx_puts t_te_s5 |
| 745 | omx_putu enc_checks |
| 746 | omx_puts t_te_s6 |
| 747 | omx_putu grid_cases |
| 748 | omx_puts t_te_s7 |
| 749 | omx_putu random_cases |
| 750 | omx_puts t_te_s8 |
| 751 | omx_putu large_cases |
| 752 | omx_puts t_te_s9 |
| 753 | omx_putu sub c0 enc_checks |
| 754 | omx_nl |
| 755 | if ne get g_te_st 1 0 |
| 756 | ret 1 |
| 757 | end |
| 758 | ret 0 |
| 759 | end |