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 / polyglot / omx_encoder.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | note |
| 4 | note src/polyglot/omx_encoder.om -- pure seeded OM-2 POLYGLOT-0 lane B2: |
| 5 | note AArch64 scalar + SIMD instruction encoders, decoder, tiny assembler with |
| 6 | note labels/fixups/ADRP+ADD relocations, and B1 kernel emitters (sdot, crumb). |
| 7 | |
| 8 | const OMX_ENC_SDOT ulong 0 |
| 9 | const OMX_ENC_CRUMB ulong 1 |
| 10 | const OMX_ENC_KERNELS ulong 2 |
| 11 | |
| 12 | const OMX_ENC_FROM_OMEGA uchar 0 |
| 13 | const OMX_ENC_FROM_EXT uchar 1 |
| 14 | |
| 15 | const OMX_ENC_RELOC_NONE uchar 0 |
| 16 | const OMX_ENC_RELOC_ADRP_PAGE uchar 1 |
| 17 | const OMX_ENC_RELOC_ADD_LO12 uchar 2 |
| 18 | |
| 19 | const OMX_COND_NE ulong 1 |
| 20 | const OMX_COND_LO ulong 3 |
| 21 | |
| 22 | const OMX_FX_B ulong 0 |
| 23 | const OMX_FX_BCOND ulong 1 |
| 24 | const OMX_FX_CBZ ulong 2 |
| 25 | |
| 26 | note Assembler global state (concatenated after omx_common.om) |
| 27 | global g_enc_word uint 1024 |
| 28 | global g_enc_orig uchar 1024 |
| 29 | global g_enc_reloc uchar 1024 |
| 30 | global g_enc_bdisp int 1024 |
| 31 | global g_enc_lsl uchar 1024 |
| 32 | |
| 33 | global g_enc_lab long 32 |
| 34 | global g_enc_fix_at ulong 64 |
| 35 | global g_enc_fix_kind ulong 64 |
| 36 | global g_enc_fix_lab ulong 64 |
| 37 | global g_enc_fix_cond ulong 64 |
| 38 | global g_enc_fix_rt ulong 64 |
| 39 | note g_enc_st: [0]=n [1]=err [2]=nfix [3]=base [4]=data_off [5]=data_len |
| 40 | global g_enc_st ulong 8 |
| 41 | global g_enc_sdot_mask uchar 32 |
| 42 | |
| 43 | note ---- Extended AArch64 encoders (port of src/polyglot/omx_encoder_ext.c) ---- |
| 44 | note Each returns >= 0 (32-bit instruction word) on success, or -1 on invalid operand. |
| 45 | |
| 46 | fn oxe_addsub_imm op ulong rd ulong rn ulong imm12 ulong lsl12 ulong to long |
| 47 | if gt rd 31 |
| 48 | ret -1 |
| 49 | end |
| 50 | if gt rn 31 |
| 51 | ret -1 |
| 52 | end |
| 53 | if gt imm12 0xfff |
| 54 | ret -1 |
| 55 | end |
| 56 | if gt lsl12 1 |
| 57 | ret -1 |
| 58 | end |
| 59 | w = or shl ulong 1 31 shl op 30 |
| 60 | w = or w shl ulong 0x22 23 |
| 61 | w = or w shl lsl12 22 |
| 62 | w = or w shl imm12 10 |
| 63 | w = or w shl rn 5 |
| 64 | ret long or w rd |
| 65 | end |
| 66 | |
| 67 | fn oxe_add_imm_x rd ulong rn ulong imm12 ulong lsl12 ulong to long |
| 68 | ret oxe_addsub_imm 0 rd rn imm12 lsl12 |
| 69 | end |
| 70 | |
| 71 | fn oxe_sub_imm_x rd ulong rn ulong imm12 ulong lsl12 ulong to long |
| 72 | ret oxe_addsub_imm 1 rd rn imm12 lsl12 |
| 73 | end |
| 74 | |
| 75 | fn oxe_add_lsl_x rd ulong rn ulong rm ulong amount ulong to long |
| 76 | if gt rd 31 |
| 77 | ret -1 |
| 78 | end |
| 79 | if gt rn 31 |
| 80 | ret -1 |
| 81 | end |
| 82 | if gt rm 31 |
| 83 | ret -1 |
| 84 | end |
| 85 | if gt amount 63 |
| 86 | ret -1 |
| 87 | end |
| 88 | w = or shl ulong 1 31 shl ulong 0x0b 24 |
| 89 | w = or w shl rm 16 |
| 90 | w = or w shl amount 10 |
| 91 | w = or w shl rn 5 |
| 92 | ret long or w rd |
| 93 | end |
| 94 | |
| 95 | fn oxe_ubfm_x rd ulong rn ulong immr ulong imms ulong to long |
| 96 | if gt rd 31 |
| 97 | ret -1 |
| 98 | end |
| 99 | if gt rn 31 |
| 100 | ret -1 |
| 101 | end |
| 102 | if gt immr 63 |
| 103 | ret -1 |
| 104 | end |
| 105 | if gt imms 63 |
| 106 | ret -1 |
| 107 | end |
| 108 | w = or shl ulong 1 31 shl ulong 2 29 |
| 109 | w = or w shl ulong 0x26 23 |
| 110 | w = or w shl ulong 1 22 |
| 111 | w = or w shl immr 16 |
| 112 | w = or w shl imms 10 |
| 113 | w = or w shl rn 5 |
| 114 | ret long or w rd |
| 115 | end |
| 116 | |
| 117 | fn oxe_lsr_imm_x rd ulong rn ulong shift ulong to long |
| 118 | if gt shift 63 |
| 119 | ret -1 |
| 120 | end |
| 121 | ret oxe_ubfm_x rd rn shift 63 |
| 122 | end |
| 123 | |
| 124 | fn oxe_lsl_imm_x rd ulong rn ulong shift ulong to long |
| 125 | if gt shift 63 |
| 126 | ret -1 |
| 127 | end |
| 128 | ret oxe_ubfm_x rd rn and sub 64 shift 63 sub 63 shift |
| 129 | end |
| 130 | |
| 131 | fn oxe_ubfx_x rd ulong rn ulong lsb ulong width ulong to long |
| 132 | if lt width 1 |
| 133 | ret -1 |
| 134 | end |
| 135 | if gt lsb 63 |
| 136 | ret -1 |
| 137 | end |
| 138 | if gt width sub 64 lsb |
| 139 | ret -1 |
| 140 | end |
| 141 | ret oxe_ubfm_x rd rn lsb sub add lsb width 1 |
| 142 | end |
| 143 | |
| 144 | fn oxe_bm_lg imm ulong to ulong |
| 145 | size = ulong 64 |
| 146 | lg = ulong 6 |
| 147 | while gt size 2 bound 8 |
| 148 | half = div size 2 |
| 149 | mask = sub shl ulong 1 half 1 |
| 150 | if ne and imm mask and shr imm half mask |
| 151 | break |
| 152 | end |
| 153 | size = half |
| 154 | lg = sub lg 1 |
| 155 | end |
| 156 | ret lg |
| 157 | end |
| 158 | |
| 159 | fn oxe_bm_rot elt ulong size ulong emask ulong run ulong to long |
| 160 | for r ulong size bound 64 |
| 161 | rol = elt |
| 162 | if gt r 0 |
| 163 | rol = and or shl elt r shr elt sub size r emask |
| 164 | end |
| 165 | if eq rol run |
| 166 | ret long r |
| 167 | end |
| 168 | end |
| 169 | ret -1 |
| 170 | end |
| 171 | |
| 172 | fn oxe_bitmask_imm64 imm ulong res edit ulong 3 to int |
| 173 | if eq imm 0 |
| 174 | ret -1 |
| 175 | end |
| 176 | if eq imm 0xffffffffffffffff |
| 177 | ret -1 |
| 178 | end |
| 179 | lg = oxe_bm_lg imm |
| 180 | size = shl ulong 1 lg |
| 181 | emask = ulong 0xffffffffffffffff |
| 182 | if lt size 64 |
| 183 | emask = sub shl ulong 1 size 1 |
| 184 | end |
| 185 | elt = and imm emask |
| 186 | ones = ulong 0 |
| 187 | for i ulong size bound 64 |
| 188 | ones = add ones and shr elt i 1 |
| 189 | end |
| 190 | if or eq ones 0 eq ones size |
| 191 | ret -1 |
| 192 | end |
| 193 | run = sub shl ulong 1 ones 1 |
| 194 | rot = oxe_bm_rot elt size emask run |
| 195 | if lt rot 0 |
| 196 | ret -1 |
| 197 | end |
| 198 | nv = ulong 0 |
| 199 | if eq size 64 |
| 200 | nv = 1 |
| 201 | end |
| 202 | put res 0 nv |
| 203 | put res 1 ulong rot |
| 204 | imms_hi = and shl ulong 0x3f add lg 1 0x3f |
| 205 | put res 2 or imms_hi sub ones 1 |
| 206 | ret 0 |
| 207 | end |
| 208 | |
| 209 | fn oxe_logic_imm opc ulong rd ulong rn ulong imm ulong to long |
| 210 | if gt rd 31 |
| 211 | ret -1 |
| 212 | end |
| 213 | if gt rn 31 |
| 214 | ret -1 |
| 215 | end |
| 216 | res = new ulong 3 0 |
| 217 | if ne oxe_bitmask_imm64 imm res 0 |
| 218 | ret -1 |
| 219 | end |
| 220 | nv = get res 0 |
| 221 | immr = get res 1 |
| 222 | imms = get res 2 |
| 223 | w = or shl ulong 1 31 shl opc 29 |
| 224 | w = or w shl ulong 0x24 23 |
| 225 | w = or w shl nv 22 |
| 226 | w = or w shl immr 16 |
| 227 | w = or w shl imms 10 |
| 228 | w = or w shl rn 5 |
| 229 | ret long or w rd |
| 230 | end |
| 231 | |
| 232 | fn oxe_and_imm_x rd ulong rn ulong imm ulong to long |
| 233 | ret oxe_logic_imm 0 rd rn imm |
| 234 | end |
| 235 | |
| 236 | fn oxe_ands_imm_x rd ulong rn ulong imm ulong to long |
| 237 | ret oxe_logic_imm 3 rd rn imm |
| 238 | end |
| 239 | |
| 240 | fn oxe_csinc_x rd ulong rn ulong rm ulong cond ulong to long |
| 241 | if gt rd 31 |
| 242 | ret -1 |
| 243 | end |
| 244 | if gt rn 31 |
| 245 | ret -1 |
| 246 | end |
| 247 | if gt rm 31 |
| 248 | ret -1 |
| 249 | end |
| 250 | if gt cond 15 |
| 251 | ret -1 |
| 252 | end |
| 253 | w = or shl ulong 1 31 shl ulong 0xd4 21 |
| 254 | w = or w shl rm 16 |
| 255 | w = or w shl cond 12 |
| 256 | w = or w shl ulong 1 10 |
| 257 | w = or w shl rn 5 |
| 258 | ret long or w rd |
| 259 | end |
| 260 | |
| 261 | fn oxe_cinc_x rd ulong rn ulong cond ulong to long |
| 262 | if gt cond 13 |
| 263 | ret -1 |
| 264 | end |
| 265 | ret oxe_csinc_x rd rn rn xor cond 1 |
| 266 | end |
| 267 | |
| 268 | fn oxe_madd_w rd ulong rn ulong rm ulong ra ulong to long |
| 269 | if gt rd 31 |
| 270 | ret -1 |
| 271 | end |
| 272 | if gt rn 31 |
| 273 | ret -1 |
| 274 | end |
| 275 | if gt rm 31 |
| 276 | ret -1 |
| 277 | end |
| 278 | if gt ra 31 |
| 279 | ret -1 |
| 280 | end |
| 281 | w = or shl ulong 0x1b 24 shl rm 16 |
| 282 | w = or w shl ra 10 |
| 283 | w = or w shl rn 5 |
| 284 | ret long or w rd |
| 285 | end |
| 286 | |
| 287 | fn oxe_movn_w rd ulong imm16 ulong hw ulong to long |
| 288 | if gt rd 31 |
| 289 | ret -1 |
| 290 | end |
| 291 | if gt imm16 0xffff |
| 292 | ret -1 |
| 293 | end |
| 294 | if gt hw 1 |
| 295 | ret -1 |
| 296 | end |
| 297 | w = or shl ulong 0x25 23 shl hw 21 |
| 298 | w = or w shl imm16 5 |
| 299 | ret long or w rd |
| 300 | end |
| 301 | |
| 302 | fn oxe_adrp rd ulong page_delta long to long |
| 303 | if gt rd 31 |
| 304 | ret -1 |
| 305 | end |
| 306 | if lt page_delta -1048576 |
| 307 | ret -1 |
| 308 | end |
| 309 | if ge page_delta 1048576 |
| 310 | ret -1 |
| 311 | end |
| 312 | imm = and bitcast ulong page_delta 0x1fffff |
| 313 | w = or shl ulong 1 31 shl and imm 3 29 |
| 314 | w = or w shl ulong 0x10 24 |
| 315 | w = or w shl shr imm 2 5 |
| 316 | ret long or w rd |
| 317 | end |
| 318 | |
| 319 | fn oxe_ldp_x_off rt ulong rt2 ulong rn ulong off long to long |
| 320 | if gt rt 30 |
| 321 | ret -1 |
| 322 | end |
| 323 | if gt rt2 30 |
| 324 | ret -1 |
| 325 | end |
| 326 | if gt rn 31 |
| 327 | ret -1 |
| 328 | end |
| 329 | if eq rt rt2 |
| 330 | ret -1 |
| 331 | end |
| 332 | if ne rem off 8 0 |
| 333 | ret -1 |
| 334 | end |
| 335 | if lt off -512 |
| 336 | ret -1 |
| 337 | end |
| 338 | if gt off 504 |
| 339 | ret -1 |
| 340 | end |
| 341 | imm7 = and bitcast ulong div off 8 0x7f |
| 342 | w = or shl ulong 2 30 shl ulong 5 27 |
| 343 | w = or w shl ulong 2 23 |
| 344 | w = or w shl ulong 1 22 |
| 345 | w = or w shl imm7 15 |
| 346 | w = or w shl rt2 10 |
| 347 | w = or w shl rn 5 |
| 348 | ret long or w rt |
| 349 | end |
| 350 | |
| 351 | fn oxe_ldst_post sz ulong v ulong opc ulong rt ulong rn ulong simm9 long to long |
| 352 | if gt rt 31 |
| 353 | ret -1 |
| 354 | end |
| 355 | if gt rn 31 |
| 356 | ret -1 |
| 357 | end |
| 358 | if lt simm9 -256 |
| 359 | ret -1 |
| 360 | end |
| 361 | if gt simm9 255 |
| 362 | ret -1 |
| 363 | end |
| 364 | imm9 = and bitcast ulong simm9 0x1ff |
| 365 | w = or shl sz 30 shl ulong 7 27 |
| 366 | w = or w shl v 26 |
| 367 | w = or w shl opc 22 |
| 368 | w = or w shl imm9 12 |
| 369 | w = or w shl ulong 1 10 |
| 370 | w = or w shl rn 5 |
| 371 | ret long or w rt |
| 372 | end |
| 373 | |
| 374 | fn oxe_ldrsb_w_post rt ulong rn ulong simm9 long to long |
| 375 | if eq rt rn |
| 376 | if ne rn 31 |
| 377 | ret -1 |
| 378 | end |
| 379 | end |
| 380 | ret oxe_ldst_post 0 0 3 rt rn simm9 |
| 381 | end |
| 382 | |
| 383 | fn oxe_ldrb_w_post rt ulong rn ulong simm9 long to long |
| 384 | if eq rt rn |
| 385 | if ne rn 31 |
| 386 | ret -1 |
| 387 | end |
| 388 | end |
| 389 | ret oxe_ldst_post 0 0 1 rt rn simm9 |
| 390 | end |
| 391 | |
| 392 | fn oxe_strb_w_post rt ulong rn ulong simm9 long to long |
| 393 | if eq rt rn |
| 394 | if ne rn 31 |
| 395 | ret -1 |
| 396 | end |
| 397 | end |
| 398 | ret oxe_ldst_post 0 0 0 rt rn simm9 |
| 399 | end |
| 400 | |
| 401 | fn oxe_ldr_q_post qt ulong rn ulong simm9 long to long |
| 402 | ret oxe_ldst_post 0 1 3 qt rn simm9 |
| 403 | end |
| 404 | |
| 405 | fn oxe_str_q_post qt ulong rn ulong simm9 long to long |
| 406 | ret oxe_ldst_post 0 1 2 qt rn simm9 |
| 407 | end |
| 408 | |
| 409 | fn oxe_str_s_post st ulong rn ulong simm9 long to long |
| 410 | ret oxe_ldst_post 2 1 0 st rn simm9 |
| 411 | end |
| 412 | |
| 413 | fn oxe_ldr_q_uoff qt ulong rn ulong off ulong to long |
| 414 | if gt qt 31 |
| 415 | ret -1 |
| 416 | end |
| 417 | if gt rn 31 |
| 418 | ret -1 |
| 419 | end |
| 420 | if ne rem off 16 0 |
| 421 | ret -1 |
| 422 | end |
| 423 | if gt div off 16 0xfff |
| 424 | ret -1 |
| 425 | end |
| 426 | w = or shl ulong 7 27 shl ulong 1 26 |
| 427 | w = or w shl ulong 1 24 |
| 428 | w = or w shl ulong 3 22 |
| 429 | w = or w shl div off 16 10 |
| 430 | w = or w shl rn 5 |
| 431 | ret long or w qt |
| 432 | end |
| 433 | |
| 434 | fn oxe_stp_q_off qt ulong qt2 ulong rn ulong off long to long |
| 435 | if gt qt 31 |
| 436 | ret -1 |
| 437 | end |
| 438 | if gt qt2 31 |
| 439 | ret -1 |
| 440 | end |
| 441 | if gt rn 31 |
| 442 | ret -1 |
| 443 | end |
| 444 | if ne rem off 16 0 |
| 445 | ret -1 |
| 446 | end |
| 447 | if lt off -1024 |
| 448 | ret -1 |
| 449 | end |
| 450 | if gt off 1008 |
| 451 | ret -1 |
| 452 | end |
| 453 | imm7 = and bitcast ulong div off 16 0x7f |
| 454 | w = or shl ulong 2 30 shl ulong 5 27 |
| 455 | w = or w shl ulong 1 26 |
| 456 | w = or w shl ulong 2 23 |
| 457 | w = or w shl imm7 15 |
| 458 | w = or w shl qt2 10 |
| 459 | w = or w shl rn 5 |
| 460 | ret long or w qt |
| 461 | end |
| 462 | |
| 463 | fn oxe_ld1_4 vt ulong rn ulong post ulong to long |
| 464 | if gt vt 31 |
| 465 | ret -1 |
| 466 | end |
| 467 | if gt rn 31 |
| 468 | ret -1 |
| 469 | end |
| 470 | rmf = ulong 0 |
| 471 | if ne post 0 |
| 472 | rmf = shl ulong 31 16 |
| 473 | end |
| 474 | w = or shl ulong 1 30 shl ulong 0x0c 24 |
| 475 | w = or w shl post 23 |
| 476 | w = or w shl ulong 1 22 |
| 477 | w = or w rmf |
| 478 | w = or w shl ulong 2 12 |
| 479 | w = or w shl rn 5 |
| 480 | ret long or w vt |
| 481 | end |
| 482 | |
| 483 | fn oxe_ld1_4x16b vt ulong rn ulong to long |
| 484 | ret oxe_ld1_4 vt rn 0 |
| 485 | end |
| 486 | |
| 487 | fn oxe_ld1_4x16b_post vt ulong rn ulong imm ulong to long |
| 488 | if ne imm 64 |
| 489 | ret -1 |
| 490 | end |
| 491 | ret oxe_ld1_4 vt rn 1 |
| 492 | end |
| 493 | |
| 494 | fn oxe_movi_16b vd ulong imm8 ulong to long |
| 495 | if gt vd 31 |
| 496 | ret -1 |
| 497 | end |
| 498 | if gt imm8 0xff |
| 499 | ret -1 |
| 500 | end |
| 501 | w = or shl ulong 1 30 shl ulong 0x1e0 19 |
| 502 | w = or w shl shr imm8 5 16 |
| 503 | w = or w shl ulong 0x0e 12 |
| 504 | w = or w shl ulong 1 10 |
| 505 | w = or w shl and imm8 0x1f 5 |
| 506 | ret long or w vd |
| 507 | end |
| 508 | |
| 509 | fn oxe_three_same u ulong sz ulong op ulong vd ulong vn ulong vm ulong to long |
| 510 | if gt vd 31 |
| 511 | ret -1 |
| 512 | end |
| 513 | if gt vn 31 |
| 514 | ret -1 |
| 515 | end |
| 516 | if gt vm 31 |
| 517 | ret -1 |
| 518 | end |
| 519 | w = or shl ulong 1 30 shl u 29 |
| 520 | w = or w shl ulong 0x0e 24 |
| 521 | w = or w shl sz 22 |
| 522 | w = or w shl ulong 1 21 |
| 523 | w = or w shl vm 16 |
| 524 | w = or w shl op 11 |
| 525 | w = or w shl ulong 1 10 |
| 526 | w = or w shl vn 5 |
| 527 | ret long or w vd |
| 528 | end |
| 529 | |
| 530 | fn oxe_and_16b vd ulong vn ulong vm ulong to long |
| 531 | ret oxe_three_same 0 0 0x03 vd vn vm |
| 532 | end |
| 533 | |
| 534 | fn oxe_add_4s vd ulong vn ulong vm ulong to long |
| 535 | ret oxe_three_same 0 2 0x10 vd vn vm |
| 536 | end |
| 537 | |
| 538 | fn oxe_addp_4s vd ulong vn ulong vm ulong to long |
| 539 | ret oxe_three_same 0 2 0x17 vd vn vm |
| 540 | end |
| 541 | |
| 542 | fn oxe_sdot_4s vd ulong vn ulong vm ulong to long |
| 543 | if gt vd 31 |
| 544 | ret -1 |
| 545 | end |
| 546 | if gt vn 31 |
| 547 | ret -1 |
| 548 | end |
| 549 | if gt vm 31 |
| 550 | ret -1 |
| 551 | end |
| 552 | w = or shl ulong 1 30 shl ulong 0x0e 24 |
| 553 | w = or w shl ulong 2 22 |
| 554 | w = or w shl vm 16 |
| 555 | w = or w shl ulong 1 15 |
| 556 | w = or w shl ulong 2 11 |
| 557 | w = or w shl ulong 1 10 |
| 558 | w = or w shl vn 5 |
| 559 | ret long or w vd |
| 560 | end |
| 561 | |
| 562 | fn oxe_addv_4s sd ulong vn ulong to long |
| 563 | if gt sd 31 |
| 564 | ret -1 |
| 565 | end |
| 566 | if gt vn 31 |
| 567 | ret -1 |
| 568 | end |
| 569 | w = or shl ulong 1 30 shl ulong 0x0e 24 |
| 570 | w = or w shl ulong 2 22 |
| 571 | w = or w shl ulong 0x18 17 |
| 572 | w = or w shl ulong 0x1b 12 |
| 573 | w = or w shl ulong 2 10 |
| 574 | w = or w shl vn 5 |
| 575 | ret long or w sd |
| 576 | end |
| 577 | |
| 578 | fn oxe_shift_imm op ulong immhb ulong vd ulong vn ulong to long |
| 579 | if gt vd 31 |
| 580 | ret -1 |
| 581 | end |
| 582 | if gt vn 31 |
| 583 | ret -1 |
| 584 | end |
| 585 | if lt immhb 8 |
| 586 | ret -1 |
| 587 | end |
| 588 | if gt immhb 15 |
| 589 | ret -1 |
| 590 | end |
| 591 | w = or shl ulong 1 30 shl ulong 0x1e 23 |
| 592 | w = or w shl immhb 16 |
| 593 | w = or w shl op 11 |
| 594 | w = or w shl ulong 1 10 |
| 595 | w = or w shl vn 5 |
| 596 | ret long or w vd |
| 597 | end |
| 598 | |
| 599 | fn oxe_shl_16b vd ulong vn ulong shift ulong to long |
| 600 | if gt shift 7 |
| 601 | ret -1 |
| 602 | end |
| 603 | ret oxe_shift_imm 0x0a add 8 shift vd vn |
| 604 | end |
| 605 | |
| 606 | fn oxe_sshr_16b vd ulong vn ulong shift ulong to long |
| 607 | if lt shift 1 |
| 608 | ret -1 |
| 609 | end |
| 610 | if gt shift 8 |
| 611 | ret -1 |
| 612 | end |
| 613 | ret oxe_shift_imm 0x00 sub 16 shift vd vn |
| 614 | end |
| 615 | |
| 616 | note ---- Omega scalar AArch64 encoders & decoder (matching om/aarch64/aarch64_om2.om) ---- |
| 617 | |
| 618 | fn omx_a64_rrr base ulong sf ulong rd ulong rn ulong rm ulong to long |
| 619 | if gt sf 1 |
| 620 | ret -1 |
| 621 | end |
| 622 | if gt rd 31 |
| 623 | ret -1 |
| 624 | end |
| 625 | if gt rn 31 |
| 626 | ret -1 |
| 627 | end |
| 628 | if gt rm 31 |
| 629 | ret -1 |
| 630 | end |
| 631 | w = or base shl sf 31 |
| 632 | w = or w shl rm 16 |
| 633 | w = or w shl rn 5 |
| 634 | ret long or w rd |
| 635 | end |
| 636 | |
| 637 | fn omx_a64_addreg sf ulong rd ulong rn ulong rm ulong to long |
| 638 | ret omx_a64_rrr 0x0b000000 sf rd rn rm |
| 639 | end |
| 640 | |
| 641 | fn omx_a64_subreg sf ulong rd ulong rn ulong rm ulong to long |
| 642 | ret omx_a64_rrr 0x4b000000 sf rd rn rm |
| 643 | end |
| 644 | |
| 645 | fn omx_a64_orrreg sf ulong rd ulong rn ulong rm ulong to long |
| 646 | ret omx_a64_rrr 0x2a000000 sf rd rn rm |
| 647 | end |
| 648 | |
| 649 | fn omx_a64_movreg sf ulong rd ulong rm ulong to long |
| 650 | if gt rd 30 |
| 651 | ret -1 |
| 652 | end |
| 653 | if gt rm 30 |
| 654 | ret -1 |
| 655 | end |
| 656 | ret omx_a64_orrreg sf rd 31 rm |
| 657 | end |
| 658 | |
| 659 | fn omx_a64_movz sf ulong rd ulong imm16 ulong to long |
| 660 | if gt sf 1 |
| 661 | ret -1 |
| 662 | end |
| 663 | if gt rd 30 |
| 664 | ret -1 |
| 665 | end |
| 666 | if gt imm16 0xffff |
| 667 | ret -1 |
| 668 | end |
| 669 | w = or ulong 0x52800000 shl sf 31 |
| 670 | w = or w shl imm16 5 |
| 671 | ret long or w rd |
| 672 | end |
| 673 | |
| 674 | fn omx_a64_ret to long |
| 675 | ret long ulong 0xd65f03c0 |
| 676 | end |
| 677 | |
| 678 | fn omx_a64_b imm26 long to long |
| 679 | if lt imm26 -33554432 |
| 680 | ret -1 |
| 681 | end |
| 682 | if ge imm26 33554432 |
| 683 | ret -1 |
| 684 | end |
| 685 | ret long or ulong 0x14000000 and bitcast ulong imm26 0x03ffffff |
| 686 | end |
| 687 | |
| 688 | fn omx_a64_bcond cond ulong imm19 long to long |
| 689 | if gt cond 15 |
| 690 | ret -1 |
| 691 | end |
| 692 | if lt imm19 -262144 |
| 693 | ret -1 |
| 694 | end |
| 695 | if ge imm19 262144 |
| 696 | ret -1 |
| 697 | end |
| 698 | w = shl and bitcast ulong imm19 0x7ffff 5 |
| 699 | ret long or or ulong 0x54000000 w cond |
| 700 | end |
| 701 | |
| 702 | fn omx_a64_cbz sf ulong rt ulong imm19 long to long |
| 703 | if gt sf 1 |
| 704 | ret -1 |
| 705 | end |
| 706 | if gt rt 31 |
| 707 | ret -1 |
| 708 | end |
| 709 | if lt imm19 -262144 |
| 710 | ret -1 |
| 711 | end |
| 712 | if ge imm19 262144 |
| 713 | ret -1 |
| 714 | end |
| 715 | w = or ulong 0x34000000 shl sf 31 |
| 716 | w = or w shl and bitcast ulong imm19 0x7ffff 5 |
| 717 | ret long or w rt |
| 718 | end |
| 719 | |
| 720 | fn omx_a64_subsimm sf ulong rd ulong rn ulong imm12 ulong to long |
| 721 | if gt sf 1 |
| 722 | ret -1 |
| 723 | end |
| 724 | if gt rd 31 |
| 725 | ret -1 |
| 726 | end |
| 727 | if gt rn 31 |
| 728 | ret -1 |
| 729 | end |
| 730 | if gt imm12 0xfff |
| 731 | ret -1 |
| 732 | end |
| 733 | base = ulong 0x71000000 |
| 734 | if eq sf 1 |
| 735 | base = 0xf1000000 |
| 736 | end |
| 737 | w = or base shl imm12 10 |
| 738 | w = or w shl rn 5 |
| 739 | ret long or w rd |
| 740 | end |
| 741 | |
| 742 | fn omx_a64_ldruoff sf ulong rt ulong rn ulong uoff ulong to long |
| 743 | if gt sf 1 |
| 744 | ret -1 |
| 745 | end |
| 746 | if gt rt 30 |
| 747 | ret -1 |
| 748 | end |
| 749 | if gt rn 31 |
| 750 | ret -1 |
| 751 | end |
| 752 | sc = ulong 2 |
| 753 | sz = ulong 4 |
| 754 | base = ulong 0xb9400000 |
| 755 | if eq sf 1 |
| 756 | sc = 3 |
| 757 | sz = 8 |
| 758 | base = 0xf9400000 |
| 759 | end |
| 760 | if ne rem uoff sz 0 |
| 761 | ret -1 |
| 762 | end |
| 763 | if gt div uoff sz 0xfff |
| 764 | ret -1 |
| 765 | end |
| 766 | w = or base shl and shr uoff sc 0xfff 10 |
| 767 | w = or w shl rn 5 |
| 768 | ret long or w rt |
| 769 | end |
| 770 | |
| 771 | fn omx_a64_strpost rt ulong rn ulong simm9 long to long |
| 772 | if gt rt 31 |
| 773 | ret -1 |
| 774 | end |
| 775 | if gt rn 31 |
| 776 | ret -1 |
| 777 | end |
| 778 | if eq rt rn |
| 779 | ret -1 |
| 780 | end |
| 781 | if lt simm9 -256 |
| 782 | ret -1 |
| 783 | end |
| 784 | if gt simm9 255 |
| 785 | ret -1 |
| 786 | end |
| 787 | w = or ulong 0xb8000400 shl and bitcast ulong simm9 0x1ff 12 |
| 788 | w = or w shl rn 5 |
| 789 | ret long or w rt |
| 790 | end |
| 791 | |
| 792 | note Decoder matching om/aarch64/aarch64_om2.om (dst: [0]=op [1]=sf [2]=rd [3]=rn [4]=rm [5]=imm16 [6]=hw [7]=bimm [8]=cond) |
| 793 | fn omx_dregs dst edit ulong 9 op ulong insn ulong sb ulong n ulong to void |
| 794 | put dst 0 op |
| 795 | if lt sb 32 |
| 796 | put dst 1 and shr insn sb 1 |
| 797 | end |
| 798 | put dst 2 and insn 31 |
| 799 | if ge n 2 |
| 800 | put dst 3 and shr insn 5 31 |
| 801 | end |
| 802 | if ge n 3 |
| 803 | put dst 4 and shr insn 16 31 |
| 804 | end |
| 805 | end |
| 806 | |
| 807 | fn omx_dec1 insn ulong dst edit ulong 9 to ulong |
| 808 | if eq insn 0xd65f03c0 |
| 809 | put dst 0 8 |
| 810 | put dst 3 30 |
| 811 | ret 0 |
| 812 | end |
| 813 | if eq and insn 0xfc000000 0x14000000 |
| 814 | put dst 0 9 |
| 815 | put dst 7 and insn 0x03ffffff |
| 816 | ret 0 |
| 817 | end |
| 818 | if eq and insn 0xff000010 0x54000000 |
| 819 | put dst 0 10 |
| 820 | put dst 8 and insn 15 |
| 821 | put dst 7 and shr insn 5 0x7ffff |
| 822 | ret 0 |
| 823 | end |
| 824 | m = and insn 0x7f000000 |
| 825 | if eq m 0x34000000 |
| 826 | omx_dregs dst 11 insn 31 1 |
| 827 | put dst 7 and shr insn 5 0x7ffff |
| 828 | ret 0 |
| 829 | end |
| 830 | if eq m 0x35000000 |
| 831 | omx_dregs dst 12 insn 31 1 |
| 832 | put dst 7 and shr insn 5 0x7ffff |
| 833 | ret 0 |
| 834 | end |
| 835 | if eq and insn 0x7f800000 0x52800000 |
| 836 | omx_dregs dst 7 insn 31 1 |
| 837 | put dst 5 and shr insn 5 0xffff |
| 838 | put dst 6 and shr insn 21 3 |
| 839 | ret 0 |
| 840 | end |
| 841 | m2 = and insn 0x7f200000 |
| 842 | if eq m2 0x2a000000 |
| 843 | omx_dregs dst 5 insn 31 3 |
| 844 | ret 0 |
| 845 | end |
| 846 | if eq m2 0x0b000000 |
| 847 | omx_dregs dst 1 insn 31 3 |
| 848 | ret 0 |
| 849 | end |
| 850 | if eq m2 0x4b000000 |
| 851 | omx_dregs dst 2 insn 31 3 |
| 852 | ret 0 |
| 853 | end |
| 854 | ret 1 |
| 855 | end |
| 856 | |
| 857 | fn omx_a64_decode insn ulong dst edit ulong 9 to int |
| 858 | for i ulong 9 |
| 859 | put dst i 0 |
| 860 | end |
| 861 | if eq omx_dec1 insn dst 0 |
| 862 | ret 0 |
| 863 | end |
| 864 | m = and insn 0xbf400000 |
| 865 | if eq m 0xb9400000 |
| 866 | omx_dregs dst 15 insn 30 2 |
| 867 | ret 0 |
| 868 | end |
| 869 | if eq m 0xb9000000 |
| 870 | omx_dregs dst 16 insn 30 2 |
| 871 | ret 0 |
| 872 | end |
| 873 | m2 = and insn 0xbf800c00 |
| 874 | if eq m2 0xb8400400 |
| 875 | omx_dregs dst 15 insn 30 2 |
| 876 | ret 0 |
| 877 | end |
| 878 | if eq m2 0xb8000400 |
| 879 | omx_dregs dst 16 insn 30 2 |
| 880 | ret 0 |
| 881 | end |
| 882 | if eq and insn 0x7f000000 0x71000000 |
| 883 | omx_dregs dst 19 insn 31 2 |
| 884 | ret 0 |
| 885 | end |
| 886 | ret -1 |
| 887 | end |
| 888 | |
| 889 | note ---- Tiny assembler helpers ---- |
| 890 | |
| 891 | fn enc_put w long orig uchar is_lsl uchar to void |
| 892 | if ne get g_enc_st 1 0 |
| 893 | ret |
| 894 | end |
| 895 | n = get g_enc_st 0 |
| 896 | if or lt w 0 ge n 1024 |
| 897 | put g_enc_st 1 1 |
| 898 | ret |
| 899 | end |
| 900 | put g_enc_word n uint w |
| 901 | put g_enc_orig n orig |
| 902 | put g_enc_reloc n OMX_ENC_RELOC_NONE |
| 903 | put g_enc_bdisp n int 0 |
| 904 | put g_enc_lsl n is_lsl |
| 905 | put g_enc_st 0 add n 1 |
| 906 | end |
| 907 | |
| 908 | fn enc_o w long to void |
| 909 | enc_put w OMX_ENC_FROM_OMEGA 0 |
| 910 | end |
| 911 | |
| 912 | fn enc_x w long to void |
| 913 | enc_put w OMX_ENC_FROM_EXT 0 |
| 914 | end |
| 915 | |
| 916 | fn enc_xlsl w long to void |
| 917 | enc_put w OMX_ENC_FROM_EXT 1 |
| 918 | end |
| 919 | |
| 920 | fn enc_label l ulong to void |
| 921 | if ne get g_enc_st 1 0 |
| 922 | ret |
| 923 | end |
| 924 | if ge l 32 |
| 925 | put g_enc_st 1 1 |
| 926 | ret |
| 927 | end |
| 928 | if ge get g_enc_lab l 0 |
| 929 | put g_enc_st 1 1 |
| 930 | ret |
| 931 | end |
| 932 | put g_enc_lab l long get g_enc_st 0 |
| 933 | end |
| 934 | |
| 935 | fn enc_add_fix kind ulong l ulong cond ulong rt ulong to void |
| 936 | if ne get g_enc_st 1 0 |
| 937 | ret |
| 938 | end |
| 939 | nf = get g_enc_st 2 |
| 940 | n = get g_enc_st 0 |
| 941 | if or ge nf 64 or ge l 32 eq n 0 |
| 942 | put g_enc_st 1 1 |
| 943 | ret |
| 944 | end |
| 945 | put g_enc_fix_at nf sub n 1 |
| 946 | put g_enc_fix_kind nf kind |
| 947 | put g_enc_fix_lab nf l |
| 948 | put g_enc_fix_cond nf cond |
| 949 | put g_enc_fix_rt nf rt |
| 950 | put g_enc_st 2 add nf 1 |
| 951 | end |
| 952 | |
| 953 | fn enc_cbz rt ulong l ulong to void |
| 954 | enc_o omx_a64_cbz 1 rt 0 |
| 955 | enc_add_fix OMX_FX_CBZ l 0 rt |
| 956 | end |
| 957 | |
| 958 | fn enc_br l ulong to void |
| 959 | enc_o omx_a64_b 0 |
| 960 | enc_add_fix OMX_FX_B l 0 0 |
| 961 | end |
| 962 | |
| 963 | fn enc_bcond cond ulong l ulong to void |
| 964 | enc_o omx_a64_bcond cond 0 |
| 965 | enc_add_fix OMX_FX_BCOND l cond 0 |
| 966 | end |
| 967 | |
| 968 | fn enc_adr_data rd ulong to void |
| 969 | pos = get g_enc_st 0 |
| 970 | base = get g_enc_st 3 |
| 971 | doff = get g_enc_st 4 |
| 972 | page = long 0 |
| 973 | lo12 = ulong 0 |
| 974 | if ne base 0 |
| 975 | pc = add base mul 4 pos |
| 976 | tgt = add base doff |
| 977 | page = sub long shr tgt 12 long shr pc 12 |
| 978 | lo12 = and tgt 0xfff |
| 979 | end |
| 980 | enc_x oxe_adrp rd page |
| 981 | if eq get g_enc_st 1 0 |
| 982 | put g_enc_reloc sub get g_enc_st 0 1 OMX_ENC_RELOC_ADRP_PAGE |
| 983 | end |
| 984 | enc_x oxe_add_imm_x rd rd lo12 0 |
| 985 | if eq get g_enc_st 1 0 |
| 986 | put g_enc_reloc sub get g_enc_st 0 1 OMX_ENC_RELOC_ADD_LO12 |
| 987 | end |
| 988 | end |
| 989 | |
| 990 | fn enc_resolve to int |
| 991 | if ne get g_enc_st 1 0 |
| 992 | ret -1 |
| 993 | end |
| 994 | nf = get g_enc_st 2 |
| 995 | for i ulong nf bound 64 |
| 996 | lab = get g_enc_fix_lab i |
| 997 | tgt = get g_enc_lab lab |
| 998 | if lt tgt 0 |
| 999 | ret -1 |
| 1000 | end |
| 1001 | pos = get g_enc_fix_at i |
| 1002 | d = sub tgt long pos |
| 1003 | kind = get g_enc_fix_kind i |
| 1004 | w = long -1 |
| 1005 | if eq kind OMX_FX_B |
| 1006 | w = omx_a64_b d |
| 1007 | else |
| 1008 | if eq kind OMX_FX_BCOND |
| 1009 | w = omx_a64_bcond get g_enc_fix_cond i d |
| 1010 | else |
| 1011 | if eq kind OMX_FX_CBZ |
| 1012 | w = omx_a64_cbz 1 get g_enc_fix_rt i d |
| 1013 | end |
| 1014 | end |
| 1015 | end |
| 1016 | if lt w 0 |
| 1017 | ret -1 |
| 1018 | end |
| 1019 | put g_enc_word pos uint w |
| 1020 | put g_enc_bdisp pos int d |
| 1021 | end |
| 1022 | ret 0 |
| 1023 | end |
| 1024 | |
| 1025 | note ---- Kernel: asm_sdot (mirrors src/polyglot/asm/omx_sdot.S line by line) ---- |
| 1026 | note labels: 0=ERR 1=SCALAR 2=BLK4 3=ROWS1 4=ROW1 5=OK 6=B0 7=B1 8=B2 9=B3 10=B4 |
| 1027 | note 11=R0 12=R1 13=R2 14=R3 15=R4 16=C0 17=C1 |
| 1028 | |
| 1029 | fn emit_sdot_blk4 to void |
| 1030 | enc_label 2 |
| 1031 | enc_o omx_a64_subsimm 1 31 3 4 |
| 1032 | enc_bcond OMX_COND_LO 3 |
| 1033 | for v ulong 8 |
| 1034 | enc_x oxe_movi_16b add 24 v 0 |
| 1035 | end |
| 1036 | enc_o omx_a64_movreg 1 9 1 |
| 1037 | enc_o omx_a64_movreg 1 10 5 |
| 1038 | enc_o omx_a64_addreg 1 11 10 4 |
| 1039 | enc_o omx_a64_addreg 1 12 11 4 |
| 1040 | enc_o omx_a64_addreg 1 13 12 4 |
| 1041 | enc_cbz 6 7 |
| 1042 | enc_o omx_a64_movreg 1 14 6 |
| 1043 | enc_label 6 |
| 1044 | enc_x oxe_ld1_4x16b_post 0 9 64 |
| 1045 | enc_x oxe_ld1_4x16b_post 4 10 64 |
| 1046 | enc_x oxe_ld1_4x16b_post 16 11 64 |
| 1047 | enc_x oxe_sdot_4s 24 4 0 |
| 1048 | enc_x oxe_sdot_4s 28 5 1 |
| 1049 | enc_x oxe_sdot_4s 25 16 0 |
| 1050 | enc_x oxe_sdot_4s 29 17 1 |
| 1051 | enc_x oxe_ld1_4x16b_post 20 12 64 |
| 1052 | enc_x oxe_sdot_4s 24 6 2 |
| 1053 | enc_x oxe_sdot_4s 28 7 3 |
| 1054 | enc_x oxe_sdot_4s 25 18 2 |
| 1055 | enc_x oxe_sdot_4s 29 19 3 |
| 1056 | enc_x oxe_ld1_4x16b_post 4 13 64 |
| 1057 | enc_x oxe_sdot_4s 26 20 0 |
| 1058 | enc_x oxe_sdot_4s 30 21 1 |
| 1059 | enc_x oxe_sdot_4s 27 4 0 |
| 1060 | enc_x oxe_sdot_4s 31 5 1 |
| 1061 | enc_x oxe_sdot_4s 26 22 2 |
| 1062 | enc_x oxe_sdot_4s 30 23 3 |
| 1063 | enc_x oxe_sdot_4s 27 6 2 |
| 1064 | enc_x oxe_sdot_4s 31 7 3 |
| 1065 | enc_o omx_a64_subsimm 1 14 14 1 |
| 1066 | enc_bcond OMX_COND_NE 6 |
| 1067 | enc_label 7 |
| 1068 | enc_cbz 7 9 |
| 1069 | enc_o omx_a64_movreg 1 14 7 |
| 1070 | enc_label 8 |
| 1071 | enc_x oxe_ldr_q_post 0 9 16 |
| 1072 | enc_x oxe_ldr_q_post 4 10 16 |
| 1073 | enc_x oxe_ldr_q_post 5 11 16 |
| 1074 | enc_x oxe_ldr_q_post 6 12 16 |
| 1075 | enc_x oxe_ldr_q_post 7 13 16 |
| 1076 | enc_x oxe_sdot_4s 24 4 0 |
| 1077 | enc_x oxe_sdot_4s 25 5 0 |
| 1078 | enc_x oxe_sdot_4s 26 6 0 |
| 1079 | enc_x oxe_sdot_4s 27 7 0 |
| 1080 | enc_o omx_a64_subsimm 1 14 14 1 |
| 1081 | enc_bcond OMX_COND_NE 8 |
| 1082 | enc_label 9 |
| 1083 | enc_cbz 8 10 |
| 1084 | for r ulong 5 |
| 1085 | enc_o omx_a64_subreg 1 add 9 r add 9 r 15 |
| 1086 | end |
| 1087 | enc_x oxe_ldr_q_uoff 0 9 0 |
| 1088 | enc_x oxe_ldr_q_uoff 1 16 0 |
| 1089 | enc_x oxe_and_16b 0 0 1 |
| 1090 | enc_x oxe_ldr_q_uoff 4 10 0 |
| 1091 | enc_x oxe_ldr_q_uoff 5 11 0 |
| 1092 | enc_x oxe_ldr_q_uoff 6 12 0 |
| 1093 | enc_x oxe_ldr_q_uoff 7 13 0 |
| 1094 | enc_x oxe_sdot_4s 28 4 0 |
| 1095 | enc_x oxe_sdot_4s 29 5 0 |
| 1096 | enc_x oxe_sdot_4s 30 6 0 |
| 1097 | enc_x oxe_sdot_4s 31 7 0 |
| 1098 | enc_label 10 |
| 1099 | enc_x oxe_add_4s 24 24 28 |
| 1100 | enc_x oxe_add_4s 25 25 29 |
| 1101 | enc_x oxe_add_4s 26 26 30 |
| 1102 | enc_x oxe_add_4s 27 27 31 |
| 1103 | enc_x oxe_addp_4s 24 24 25 |
| 1104 | enc_x oxe_addp_4s 26 26 27 |
| 1105 | enc_x oxe_addp_4s 24 24 26 |
| 1106 | enc_x oxe_str_q_post 24 2 16 |
| 1107 | enc_xlsl oxe_add_lsl_x 5 5 4 2 |
| 1108 | enc_x oxe_sub_imm_x 3 3 4 0 |
| 1109 | enc_br 2 |
| 1110 | end |
| 1111 | |
| 1112 | fn emit_sdot_tail to void |
| 1113 | enc_label 3 |
| 1114 | enc_cbz 3 5 |
| 1115 | enc_label 4 |
| 1116 | for v ulong 4 |
| 1117 | enc_x oxe_movi_16b add 24 v 0 |
| 1118 | end |
| 1119 | enc_o omx_a64_movreg 1 9 1 |
| 1120 | enc_o omx_a64_movreg 1 10 5 |
| 1121 | enc_cbz 6 12 |
| 1122 | enc_o omx_a64_movreg 1 14 6 |
| 1123 | enc_label 11 |
| 1124 | enc_x oxe_ld1_4x16b_post 0 9 64 |
| 1125 | enc_x oxe_ld1_4x16b_post 4 10 64 |
| 1126 | enc_x oxe_sdot_4s 24 4 0 |
| 1127 | enc_x oxe_sdot_4s 25 5 1 |
| 1128 | enc_x oxe_sdot_4s 26 6 2 |
| 1129 | enc_x oxe_sdot_4s 27 7 3 |
| 1130 | enc_o omx_a64_subsimm 1 14 14 1 |
| 1131 | enc_bcond OMX_COND_NE 11 |
| 1132 | enc_label 12 |
| 1133 | enc_cbz 7 14 |
| 1134 | enc_o omx_a64_movreg 1 14 7 |
| 1135 | enc_label 13 |
| 1136 | enc_x oxe_ldr_q_post 0 9 16 |
| 1137 | enc_x oxe_ldr_q_post 4 10 16 |
| 1138 | enc_x oxe_sdot_4s 24 4 0 |
| 1139 | enc_o omx_a64_subsimm 1 14 14 1 |
| 1140 | enc_bcond OMX_COND_NE 13 |
| 1141 | enc_label 14 |
| 1142 | enc_cbz 8 15 |
| 1143 | enc_o omx_a64_subreg 1 9 9 15 |
| 1144 | enc_o omx_a64_subreg 1 10 10 15 |
| 1145 | enc_x oxe_ldr_q_uoff 0 9 0 |
| 1146 | enc_x oxe_ldr_q_uoff 1 16 0 |
| 1147 | enc_x oxe_and_16b 0 0 1 |
| 1148 | enc_x oxe_ldr_q_uoff 4 10 0 |
| 1149 | enc_x oxe_sdot_4s 25 4 0 |
| 1150 | enc_label 15 |
| 1151 | enc_x oxe_add_4s 24 24 25 |
| 1152 | enc_x oxe_add_4s 26 26 27 |
| 1153 | enc_x oxe_add_4s 24 24 26 |
| 1154 | enc_x oxe_addv_4s 24 24 |
| 1155 | enc_x oxe_str_s_post 24 2 4 |
| 1156 | enc_o omx_a64_addreg 1 5 5 4 |
| 1157 | enc_o omx_a64_subsimm 1 3 3 1 |
| 1158 | enc_bcond OMX_COND_NE 4 |
| 1159 | enc_label 5 |
| 1160 | enc_o omx_a64_movz 0 0 0 |
| 1161 | enc_o omx_a64_ret |
| 1162 | |
| 1163 | enc_label 1 |
| 1164 | enc_label 16 |
| 1165 | enc_o omx_a64_movz 0 6 0 |
| 1166 | enc_o omx_a64_movreg 1 9 1 |
| 1167 | enc_o omx_a64_movreg 1 14 4 |
| 1168 | enc_label 17 |
| 1169 | enc_x oxe_ldrsb_w_post 10 5 1 |
| 1170 | enc_x oxe_ldrsb_w_post 11 9 1 |
| 1171 | enc_x oxe_madd_w 6 10 11 6 |
| 1172 | enc_o omx_a64_subsimm 1 14 14 1 |
| 1173 | enc_bcond OMX_COND_NE 17 |
| 1174 | enc_o omx_a64_strpost 6 2 4 |
| 1175 | enc_o omx_a64_subsimm 1 3 3 1 |
| 1176 | enc_bcond OMX_COND_NE 16 |
| 1177 | enc_o omx_a64_movz 0 0 0 |
| 1178 | enc_o omx_a64_ret |
| 1179 | |
| 1180 | enc_label 0 |
| 1181 | enc_x oxe_movn_w 0 0 0 |
| 1182 | enc_o omx_a64_ret |
| 1183 | end |
| 1184 | |
| 1185 | fn emit_sdot to void |
| 1186 | enc_cbz 0 0 |
| 1187 | enc_cbz 1 0 |
| 1188 | enc_cbz 2 0 |
| 1189 | enc_x oxe_ldp_x_off 3 4 0 0 |
| 1190 | enc_o omx_a64_ldruoff 1 5 0 16 |
| 1191 | enc_cbz 5 0 |
| 1192 | enc_cbz 3 0 |
| 1193 | enc_cbz 4 0 |
| 1194 | enc_o omx_a64_subsimm 1 31 4 16 |
| 1195 | enc_bcond OMX_COND_LO 1 |
| 1196 | |
| 1197 | enc_x oxe_lsr_imm_x 6 4 6 |
| 1198 | enc_x oxe_ubfx_x 7 4 4 2 |
| 1199 | enc_x oxe_and_imm_x 8 4 15 |
| 1200 | enc_adr_data 16 |
| 1201 | enc_o omx_a64_addreg 1 16 16 8 |
| 1202 | enc_o omx_a64_movz 1 15 16 |
| 1203 | enc_o omx_a64_subreg 1 15 15 8 |
| 1204 | |
| 1205 | emit_sdot_blk4 |
| 1206 | emit_sdot_tail |
| 1207 | end |
| 1208 | |
| 1209 | note ---- Kernel: asm_crumb (mirrors src/polyglot/asm/omx_crumb.S line by line) ---- |
| 1210 | note labels: 0=ERR 1=BLK4 2=ROWS1 3=ROW1 4=OK 5=T0 6=T1 7=B0 8=B1 9=B2 10=R0 11=R1 12=R2 |
| 1211 | |
| 1212 | fn emit_crow wv ulong va ulong vb ulong tbase ulong to void |
| 1213 | t0 = tbase |
| 1214 | t1 = add tbase 1 |
| 1215 | t2 = add tbase 2 |
| 1216 | t3 = add tbase 3 |
| 1217 | enc_x oxe_shl_16b t0 wv 6 |
| 1218 | enc_x oxe_shl_16b t1 wv 4 |
| 1219 | enc_x oxe_shl_16b t2 wv 2 |
| 1220 | enc_x oxe_sshr_16b t3 wv 6 |
| 1221 | enc_x oxe_sshr_16b t0 t0 6 |
| 1222 | enc_x oxe_sshr_16b t1 t1 6 |
| 1223 | enc_x oxe_sshr_16b t2 t2 6 |
| 1224 | enc_x oxe_sdot_4s vb t3 3 |
| 1225 | enc_x oxe_sdot_4s va t0 0 |
| 1226 | enc_x oxe_sdot_4s vb t1 1 |
| 1227 | enc_x oxe_sdot_4s va t2 2 |
| 1228 | end |
| 1229 | |
| 1230 | fn emit_chunk4 to void |
| 1231 | enc_x oxe_ldr_q_post 4 10 16 |
| 1232 | enc_x oxe_ldr_q_post 5 11 16 |
| 1233 | enc_x oxe_ldr_q_post 6 12 16 |
| 1234 | enc_x oxe_ldr_q_post 7 13 16 |
| 1235 | emit_crow 4 24 28 16 |
| 1236 | emit_crow 5 25 29 20 |
| 1237 | emit_crow 6 26 30 16 |
| 1238 | emit_crow 7 27 31 20 |
| 1239 | end |
| 1240 | |
| 1241 | fn emit_crumb to void |
| 1242 | enc_cbz 0 0 |
| 1243 | enc_cbz 1 0 |
| 1244 | enc_cbz 2 0 |
| 1245 | enc_x oxe_ldp_x_off 3 4 0 0 |
| 1246 | enc_o omx_a64_ldruoff 1 5 0 16 |
| 1247 | enc_cbz 5 0 |
| 1248 | enc_cbz 3 0 |
| 1249 | enc_cbz 4 0 |
| 1250 | |
| 1251 | enc_x oxe_sub_imm_x 31 31 64 0 |
| 1252 | enc_x oxe_movi_16b 0 0 |
| 1253 | enc_x oxe_stp_q_off 0 0 31 0 |
| 1254 | enc_x oxe_stp_q_off 0 0 31 32 |
| 1255 | enc_x oxe_lsr_imm_x 6 4 6 |
| 1256 | enc_x oxe_ands_imm_x 8 4 63 |
| 1257 | enc_x oxe_cinc_x 7 6 OMX_COND_NE |
| 1258 | enc_x oxe_lsl_imm_x 7 7 4 |
| 1259 | enc_cbz 8 6 |
| 1260 | enc_xlsl oxe_add_lsl_x 9 1 6 6 |
| 1261 | enc_x oxe_add_imm_x 10 31 0 0 |
| 1262 | enc_o omx_a64_movreg 1 14 8 |
| 1263 | enc_label 5 |
| 1264 | enc_x oxe_ldrb_w_post 11 9 1 |
| 1265 | enc_x oxe_strb_w_post 11 10 1 |
| 1266 | enc_o omx_a64_subsimm 1 14 14 1 |
| 1267 | enc_bcond OMX_COND_NE 5 |
| 1268 | enc_label 6 |
| 1269 | |
| 1270 | enc_label 1 |
| 1271 | enc_o omx_a64_subsimm 1 31 3 4 |
| 1272 | enc_bcond OMX_COND_LO 2 |
| 1273 | for v ulong 8 |
| 1274 | enc_x oxe_movi_16b add 24 v 0 |
| 1275 | end |
| 1276 | enc_o omx_a64_movreg 1 9 1 |
| 1277 | enc_o omx_a64_movreg 1 10 5 |
| 1278 | enc_o omx_a64_addreg 1 11 10 7 |
| 1279 | enc_o omx_a64_addreg 1 12 11 7 |
| 1280 | enc_o omx_a64_addreg 1 13 12 7 |
| 1281 | enc_cbz 6 8 |
| 1282 | enc_o omx_a64_movreg 1 14 6 |
| 1283 | enc_label 7 |
| 1284 | enc_x oxe_ld1_4x16b_post 0 9 64 |
| 1285 | emit_chunk4 |
| 1286 | enc_o omx_a64_subsimm 1 14 14 1 |
| 1287 | enc_bcond OMX_COND_NE 7 |
| 1288 | enc_label 8 |
| 1289 | enc_cbz 8 9 |
| 1290 | enc_x oxe_ld1_4x16b 0 31 |
| 1291 | emit_chunk4 |
| 1292 | enc_label 9 |
| 1293 | enc_x oxe_add_4s 24 24 28 |
| 1294 | enc_x oxe_add_4s 25 25 29 |
| 1295 | enc_x oxe_add_4s 26 26 30 |
| 1296 | enc_x oxe_add_4s 27 27 31 |
| 1297 | enc_x oxe_addp_4s 24 24 25 |
| 1298 | enc_x oxe_addp_4s 26 26 27 |
| 1299 | enc_x oxe_addp_4s 24 24 26 |
| 1300 | enc_x oxe_str_q_post 24 2 16 |
| 1301 | enc_xlsl oxe_add_lsl_x 5 5 7 2 |
| 1302 | enc_x oxe_sub_imm_x 3 3 4 0 |
| 1303 | enc_br 1 |
| 1304 | |
| 1305 | enc_label 2 |
| 1306 | enc_cbz 3 4 |
| 1307 | enc_label 3 |
| 1308 | enc_x oxe_movi_16b 24 0 |
| 1309 | enc_x oxe_movi_16b 28 0 |
| 1310 | enc_o omx_a64_movreg 1 9 1 |
| 1311 | enc_o omx_a64_movreg 1 10 5 |
| 1312 | enc_cbz 6 11 |
| 1313 | enc_o omx_a64_movreg 1 14 6 |
| 1314 | enc_label 10 |
| 1315 | enc_x oxe_ld1_4x16b_post 0 9 64 |
| 1316 | enc_x oxe_ldr_q_post 4 10 16 |
| 1317 | emit_crow 4 24 28 16 |
| 1318 | enc_o omx_a64_subsimm 1 14 14 1 |
| 1319 | enc_bcond OMX_COND_NE 10 |
| 1320 | enc_label 11 |
| 1321 | enc_cbz 8 12 |
| 1322 | enc_x oxe_ld1_4x16b 0 31 |
| 1323 | enc_x oxe_ldr_q_post 4 10 16 |
| 1324 | emit_crow 4 24 28 16 |
| 1325 | enc_label 12 |
| 1326 | enc_x oxe_add_4s 24 24 28 |
| 1327 | enc_x oxe_addv_4s 24 24 |
| 1328 | enc_x oxe_str_s_post 24 2 4 |
| 1329 | enc_o omx_a64_addreg 1 5 5 7 |
| 1330 | enc_o omx_a64_subsimm 1 3 3 1 |
| 1331 | enc_bcond OMX_COND_NE 3 |
| 1332 | enc_label 4 |
| 1333 | enc_x oxe_add_imm_x 31 31 64 0 |
| 1334 | enc_o omx_a64_movz 0 0 0 |
| 1335 | enc_o omx_a64_ret |
| 1336 | |
| 1337 | enc_label 0 |
| 1338 | enc_x oxe_movn_w 0 0 0 |
| 1339 | enc_o omx_a64_ret |
| 1340 | end |
| 1341 | |
| 1342 | note Build kernel k (0=sdot, 1=crumb) into g_enc_word[0..n). base=0 object form, base!=0 final form. |
| 1343 | fn omx_encoder_build k ulong base ulong to int |
| 1344 | if ge k OMX_ENC_KERNELS |
| 1345 | ret -1 |
| 1346 | end |
| 1347 | if ne and base 0xfff 0 |
| 1348 | ret -1 |
| 1349 | end |
| 1350 | for i ulong 16 |
| 1351 | put g_enc_sdot_mask i uchar 0 |
| 1352 | put g_enc_sdot_mask add i 16 uchar 0xff |
| 1353 | end |
| 1354 | put g_enc_st 3 base |
| 1355 | off = ulong 0 |
| 1356 | for pass ulong 2 |
| 1357 | for i ulong 32 |
| 1358 | put g_enc_lab i -1 |
| 1359 | end |
| 1360 | put g_enc_st 0 0 |
| 1361 | put g_enc_st 1 0 |
| 1362 | put g_enc_st 2 0 |
| 1363 | put g_enc_st 4 off |
| 1364 | if eq k OMX_ENC_SDOT |
| 1365 | emit_sdot |
| 1366 | else |
| 1367 | emit_crumb |
| 1368 | end |
| 1369 | if ne get g_enc_st 1 0 |
| 1370 | ret -1 |
| 1371 | end |
| 1372 | n = get g_enc_st 0 |
| 1373 | off = and add mul n 4 15 0xfffffffffffffff0 |
| 1374 | if eq off get g_enc_st 4 |
| 1375 | break |
| 1376 | end |
| 1377 | if eq pass 1 |
| 1378 | ret -1 |
| 1379 | end |
| 1380 | end |
| 1381 | n = get g_enc_st 0 |
| 1382 | ub = ulong 512 |
| 1383 | if eq k OMX_ENC_SDOT |
| 1384 | ub = 256 |
| 1385 | end |
| 1386 | if gt n ub |
| 1387 | ret -1 |
| 1388 | end |
| 1389 | if ne enc_resolve 0 |
| 1390 | ret -1 |
| 1391 | end |
| 1392 | put g_enc_st 4 off |
| 1393 | if eq k OMX_ENC_SDOT |
| 1394 | put g_enc_st 5 32 |
| 1395 | else |
| 1396 | put g_enc_st 5 0 |
| 1397 | end |
| 1398 | ret 0 |
| 1399 | end |