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/seed/ng/src/a64.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 / seed / ng / src / a64.om` 5511 lines · 119666 bytes Raw Blame History 1 note a64: the Omega NG AArch64 back end (lane ng-a64), one unit of the ng compiler (DECISIONS.md D1b): ng is the 2 note concatenation listed in seed/ng/ng.units, so this file has no fn main; its functions are a6_*, its globals a_*. 3 note Design: seed/ng/a64/DESIGN.md. Instruction bits: Arm ARM DDI 0487 M.d, section named at each form (the source 4 note of seed/rung2/table.s2). Input is the payload main read into region 0 of ir.om's arena (i_in before the no-caps 5 note arena; the notes below still say i_in for it) from offset 0, a_inlen bytes; main's 6 note hooks are a6_mode m (does the mode line name a mode of this unit) and a6_run (run it). `@ng a64-enc` takes an 7 note encoder case list (seed/ng/a64/tests/enc.cases after its mode line) and writes one little-endian word per case. 8 note OM-2 (hex words) comes from the unit's first line, at the top of ir.om. 9 10 note ---- input and output pools ---- 11 global a_inlen ulong 1 12 global a_cn ulong 1 13 14 note a_emsg: line 0 the prefix, line k the class of refusal k (a6_die c k n) 15 text a_emsg "a64:\n input unreadable\n input too large\n output failed\n bad encoder case at line\n unsupported\n immediate out of range\n branch out of range\n IR refused (exit status = IR.md s11 class) at payload byte\n reserved operand value\n" 16 17 note ---- fatal refusal: one stderr line `a64: [ ]` and exit code c (nothing on stdout) ---- 18 fn a6_lst k ulong to ulong 19 note byte offset of line k of a_emsg 20 i = ulong 0 21 j = ulong 0 22 while and lt j k lt i len a_emsg bound 4096 23 if eq get a_emsg i 10 24 j = add j 1 25 end 26 i = add i 1 27 end 28 ret i 29 end 30 31 global a_nbuf uchar 24 32 33 fn a6_pnum v ulong to void 34 p = ulong 23 35 put a_nbuf 23 10 36 x = v 37 go = true 38 while go bound 24 39 p = sub p 1 40 put a_nbuf p uchar add rem x 10 48 41 x = div x 10 42 if eq x 0 43 go = false 44 end 45 end 46 p = sub p 1 47 put a_nbuf p 32 48 w = write 2 a_nbuf p sub 24 p 49 end 50 51 fn a6_die c ulong k ulong n ulong to void 52 w = write 2 a_emsg 0 4 53 o = a6_lst k 54 e = sub a6_lst add k 1 1 55 w2 = write 2 a_emsg o sub e o 56 if ne n `18446744073709551615` 57 a6_pnum n 58 else 59 w3 = write 2 a_emsg 4 1 60 end 61 exit int c 62 end 63 64 note ---- output: little-endian words into a_code (arena group a64code, no-caps 2026-11-11; it was a fixed 16 MiB), 65 note then all of it to stdout. What bounds the ELF's code is the machine: B and BL reach 2^27 bytes (imm26), so a 66 note word at or past `134217728` is `a64: branch out of range` (exit 5) before any output, as omc's AArch64 output 67 note stops there; the Mach-O layout keeps its own 16 MiB less 16 KiB (a6_macho). A full arena is ng's arena full. 68 fn a6_emitw w ulong to void 69 o = get a_cn 0 70 if gt add o 4 `134217728` 71 a6_die 5 7 o 72 end 73 if ne ar_need 29 add o 3 0 74 ar_die 75 end 76 note o is a multiple of 4, so the word is the low or the high half of one arena word (masked: a function's 77 note second emission rewrites words of its first) 78 x = add get ar_rb 107 shr o 3 79 if eq and o 7 0 80 put ar_m x or and get ar_m x `18446744069414584320` and w `4294967295` 81 else 82 put ar_m x or and get ar_m x `4294967295` shl and w `4294967295` 32 83 end 84 put a_cn 0 add o 4 85 end 86 87 fn a6_flush to void 88 if eq ar_out 1 107 0 get a_cn 0 0 89 a6_die 4 3 `18446744073709551615` 90 end 91 end 92 93 note ======== encoder: one 32-bit A64 instruction word per form ======== 94 note A form is a row of the table set by a6_init: base word (the encoding diagram with every operand field 0, 95 note Arm ARM DDI 0487 M.d section in the note above each group) and an operand kind. a6_enc f a b c d e builds the 96 note word from up to five operands. Register numbers are 0..31 (31 is ZR or SP as the form says). An operand that 97 note does not fit its field is refused (a6_die 6 or 7), never masked; so is an in-field value whose encoding the 98 note form reserves (a6_die 9, a6_rsv). The names in a_fnam are the names the encoder case list 99 note (seed/ng/a64/tests/enc.cases) uses, in form id order. 100 note Kinds: 1 R3 (d n m sh amt): base | d | n<<5 | m<<16 | sh<<22 | amt<<10; 2 R4 (d n m a): | a<<10; 101 note 3 EXT (d n m opt amt): | opt<<13 | amt<<10; 4 IMM12 (d n imm sh): | imm<<10 | sh<<22; 5 LOGI (d n value); 102 note 6 MOVW (d imm16 hw): | imm<<5 | hw<<21; 7 BFM (d n immr imms); 8 CSEL (d n m cond): | cond<<12; 103 note 9 LDST (t n imm12); 10 LDSR (t n m s): register offset LSL, s = scaled; 11 PAIR (t t2 n off): signed 104 note byte offset /8 at bit 15; 12 B26 (words); 13 BCOND (cond words); 14 CB (t words); 15 TB (t bit words); 105 note 16 BR (n); 17 SVC (imm16); 18 ADR (d bytes); 19 R2 (d n); 20 FCMP (n m); 21 EXTR (d n m lsb). 106 note 22 RT (t): | t (MSR FPCR); 23 DUPE (d n idx): DUP element, S idx 0..3 at bit 19, D idx 0..1 at bit 20. 107 note Signed operands (distances, pair offsets) are two's complement ulongs. 108 109 global a_fbase ulong 256 110 global a_fkind uchar 256 111 global a_nform ulong 1 112 113 text a_fnam "addx addw subx subw addsx addsw subsx subsw andx andw orrx orrw eorx eorw andsx bicx ornx mulx mulw smulh umulh sdivx udivx sdivw udivw lslvx lsrvx asrvx rorvx lslvw lsrvw asrvw maddx msubx addxe subsxe addxi addwi subxi subwi addsxi subsxi subswi addswi andxi orrxi eorxi andsxi andwi orrwi eorwi movzx movnx movkx movzw movnw ubfmx sbfmx ubfmw sbfmw extrx cselx csincx csinvx csnegx strb ldrb ldrsbx strh ldrh ldrshx strw ldrw ldrsw strx ldrx strs ldrs strd ldrd strbr ldrbr ldrsbxr strhr ldrhr ldrshxr strwr ldrwr ldrswr strxr ldrxr strsr ldrsr strdr ldrdr stpx ldpx stpxpre ldpxpre stpxpost ldpxpost stpd ldpd b bl bcond cbzx cbnzx cbzw cbnzw tbz tbnz ret br blr svc adr faddd fsubd fmuld fdivd fmaxd fmind fmaxnmd fminnmd fadds fsubs fmuls fdivs fmaxs fmins fmaxnms fminnms fsqrtd fabsd fnegd fmovd fsqrts fabss fnegs fmovs fcmpd fcmps fmaddd fmadds fcvtds fcvtsd fmovxd fmovdx fmovws fmovsw scvtfdx ucvtfdx scvtfsx ucvtfsx fcvtzsxd fcvtzuxd fcvtzsxs fcvtzuxs rorvw fcseld fcsels msrfpcr dup2d strqr strq ldrq ldrqr orr16b dupv4s dupv2d dups dupd fadd4s fadd2d fsub4s fsub2d fmul4s fmul2d fmla4s fmla2d" 114 115 fn a6_fset i ulong b ulong k ulong to void 116 put a_fbase i b 117 put a_fkind i uchar k 118 if ge i get a_nform 0 119 put a_nform 0 add i 1 120 end 121 end 122 123 note form ids used by the selector (index into a_fnam) 124 const a_addx ulong 0 125 const a_addw ulong 1 126 const a_subx ulong 2 127 const a_subw ulong 3 128 const a_addsx ulong 4 129 const a_subsx ulong 6 130 const a_subsw ulong 7 131 const a_andx ulong 8 132 const a_orrx ulong 10 133 const a_eorx ulong 12 134 const a_andsx ulong 14 135 const a_ornx ulong 16 136 const a_mulx ulong 17 137 const a_mulw ulong 18 138 const a_smulh ulong 19 139 const a_umulh ulong 20 140 const a_sdivx ulong 21 141 const a_udivx ulong 22 142 const a_udivw ulong 24 143 const a_lslvx ulong 25 144 const a_lsrvx ulong 26 145 const a_asrvx ulong 27 146 const a_lslvw ulong 29 147 const a_maddx ulong 32 148 const a_msubx ulong 33 149 const a_subsxe ulong 35 150 const a_addxi ulong 36 151 const a_subxi ulong 38 152 const a_addsxi ulong 40 153 const a_subsxi ulong 41 154 const a_andxi ulong 44 155 const a_orrxi ulong 45 156 const a_eorxi ulong 46 157 const a_movzx ulong 51 158 const a_movnx ulong 52 159 const a_movkx ulong 53 160 const a_ubfmx ulong 56 161 const a_sbfmx ulong 57 162 const a_cselx ulong 61 163 const a_csincx ulong 62 164 const a_csnegx ulong 64 165 const a_strb ulong 65 166 const a_ldrb ulong 66 167 const a_strx ulong 74 168 const a_ldrx ulong 75 169 const a_strd ulong 78 170 const a_ldrd ulong 79 171 const a_strbr ulong 80 172 const a_ldrbr ulong 81 173 const a_ldrxr ulong 90 174 const a_stpx ulong 95 175 const a_ldpx ulong 96 176 const a_stpxpr ulong 97 177 const a_ldpxpo ulong 100 178 const a_stpd ulong 101 179 const a_ldpd ulong 102 180 const a_b ulong 103 181 const a_bl ulong 104 182 const a_bcond ulong 105 183 const a_cbzx ulong 106 184 const a_cbnzx ulong 107 185 const a_ret ulong 112 186 const a_svc ulong 115 187 const a_adr ulong 116 188 const a_fmovd ulong 136 189 const a_fcmpd ulong 141 190 const a_fmovxd ulong 147 191 const a_fmovdx ulong 148 192 const a_strsr ulong 91 193 const a_ldrsr ulong 92 194 const a_strdr ulong 93 195 const a_ldrdr ulong 94 196 const a_faddd ulong 117 197 const a_fmaxnmd ulong 123 198 const a_fminnmd ulong 124 199 const a_fadds ulong 125 200 const a_fmaxnms ulong 131 201 const a_fminnms ulong 132 202 const a_fsqrtd ulong 133 203 const a_fabsd ulong 134 204 const a_fnegd ulong 135 205 const a_fsqrts ulong 137 206 const a_fabss ulong 138 207 const a_fnegs ulong 139 208 const a_fcmps ulong 142 209 const a_fmaddd ulong 143 210 const a_fmadds ulong 144 211 const a_fcvtds ulong 145 212 const a_fcvtsd ulong 146 213 const a_fmovws ulong 149 214 const a_fmovsw ulong 150 215 const a_scvtfdx ulong 151 216 const a_ucvtfdx ulong 152 217 const a_scvtfsx ulong 153 218 const a_ucvtfsx ulong 154 219 const a_fcvtzsxd ulong 155 220 const a_fcvtzuxd ulong 156 221 const a_fcvtzsxs ulong 157 222 const a_fcvtzuxs ulong 158 223 const a_fcseld ulong 160 224 const a_fcsels ulong 161 225 const a_msrfpcr ulong 162 226 const a_dup2d ulong 163 227 const a_strqr ulong 164 228 const a_strq ulong 165 229 const a_ldrq ulong 166 230 const a_ldrqr ulong 167 231 const a_orr16b ulong 168 232 const a_dupv4s ulong 169 233 const a_dupv2d ulong 170 234 const a_dups ulong 171 235 const a_dupd ulong 172 236 const a_fadd4s ulong 173 237 const a_fadd2d ulong 174 238 const a_fsub4s ulong 175 239 const a_fsub2d ulong 176 240 const a_fmul4s ulong 177 241 const a_fmul2d ulong 178 242 const a_fmla4s ulong 179 243 const a_fmla2d ulong 180 244 note a_tbz: TBZ (form 110), used directly with a word distance by the fill tails 245 const a_tbz ulong 110 246 note a_d0: the move location of d0, the float argument 0 and result register (32 + V0) 247 const a_d0 ulong 32 248 249 note the form table. Sections: C6.2.6 ADD, C6.2.458 SUB, C6.2.8 ADDS, C6.2.465 SUBS, C6.2.15 AND, C6.2.302 ORR, 250 note C6.2.156 EOR, C6.2.17 ANDS, C6.2.32 BIC, C6.2.300 ORN (shifted register; 32-bit forms clear bit 31) 251 fn a6_formdp to void 252 a6_fset 0 0x8b000000 1 253 a6_fset 1 0x0b000000 1 254 a6_fset 2 0xcb000000 1 255 a6_fset 3 0x4b000000 1 256 a6_fset 4 0xab000000 1 257 a6_fset 5 0x2b000000 1 258 a6_fset 6 0xeb000000 1 259 a6_fset 7 0x6b000000 1 260 a6_fset 8 0x8a000000 1 261 a6_fset 9 0x0a000000 1 262 a6_fset 10 0xaa000000 1 263 a6_fset 11 0x2a000000 1 264 a6_fset 12 0xca000000 1 265 a6_fset 13 0x4a000000 1 266 a6_fset 14 0xea000000 1 267 a6_fset 15 0x8a200000 1 268 a6_fset 16 0xaa200000 1 269 note C6.2.293 MUL (MADD Ra=31), C6.2.370 SMULH, C6.2.505 UMULH, C6.2.366 SDIV, C6.2.490 UDIV, C6.2.271 LSLV, 270 note C6.2.274 LSRV, C6.2.21 ASRV, C6.2.343 RORV 271 a6_fset 17 0x9b007c00 1 272 a6_fset 18 0x1b007c00 1 273 a6_fset 19 0x9b407c00 1 274 a6_fset 20 0x9bc07c00 1 275 a6_fset 21 0x9ac00c00 1 276 a6_fset 22 0x9ac00800 1 277 a6_fset 23 0x1ac00c00 1 278 a6_fset 24 0x1ac00800 1 279 a6_fset 25 0x9ac02000 1 280 a6_fset 26 0x9ac02400 1 281 a6_fset 27 0x9ac02800 1 282 a6_fset 28 0x9ac02c00 1 283 a6_fset 29 0x1ac02000 1 284 a6_fset 30 0x1ac02400 1 285 a6_fset 31 0x1ac02800 1 286 note C6.2.275 MADD, C6.2.291 MSUB 287 a6_fset 32 0x9b000000 2 288 a6_fset 33 0x9b008000 2 289 note C6.2.4 ADD (extended register), C6.2.463 SUBS (extended register) 290 a6_fset 34 0x8b200000 3 291 a6_fset 35 0xeb200000 3 292 note C6.2.5 ADD, C6.2.457 SUB, C6.2.7 ADDS, C6.2.464 SUBS (immediate) 293 a6_fset 36 0x91000000 4 294 a6_fset 37 0x11000000 4 295 a6_fset 38 0xd1000000 4 296 a6_fset 39 0x51000000 4 297 a6_fset 40 0xb1000000 4 298 a6_fset 41 0xf1000000 4 299 a6_fset 42 0x71000000 4 300 a6_fset 43 0x31000000 4 301 note C6.2.14 AND, C6.2.301 ORR, C6.2.155 EOR, C6.2.16 ANDS (immediate) 302 a6_fset 44 0x92000000 5 303 a6_fset 45 0xb2000000 5 304 a6_fset 46 0xd2000000 5 305 a6_fset 47 0xf2000000 5 306 a6_fset 48 0x12000000 5 307 a6_fset 49 0x32000000 5 308 a6_fset 50 0x52000000 5 309 note C6.2.285 MOVZ, C6.2.284 MOVN, C6.2.283 MOVK 310 a6_fset 51 0xd2800000 6 311 a6_fset 52 0x92800000 6 312 a6_fset 53 0xf2800000 6 313 a6_fset 54 0x52800000 6 314 a6_fset 55 0x12800000 6 315 note C6.2.488 UBFM, C6.2.355 SBFM, C6.2.162 EXTR 316 a6_fset 56 0xd3400000 7 317 a6_fset 57 0x93400000 7 318 a6_fset 58 0x53000000 7 319 a6_fset 59 0x13000000 7 320 a6_fset 60 0x93c00000 21 321 note C6.2.115 CSEL, C6.2.117 CSINC, C6.2.118 CSINV, C6.2.119 CSNEG 322 a6_fset 61 0x9a800000 8 323 a6_fset 62 0x9a800400 8 324 a6_fset 63 0xda800000 8 325 a6_fset 64 0xda800400 8 326 end 327 328 note loads and stores: C6.2.417 STRB, C6.2.220 LDRB, C6.2.224 LDRSB, C6.2.419 STRH, C6.2.222 LDRH, C6.2.226 329 note LDRSH, C6.2.415 STR, C6.2.216 LDR, C6.2.228 LDRSW, C7.2.331 STR (SIMD&FP), C7.2.191 LDR (SIMD&FP); unsigned 330 note offset (kind 9) then the same bases as register offset (kind 10) 331 fn a6_formls to void 332 a6_fset 65 0x39000000 9 333 a6_fset 66 0x39400000 9 334 a6_fset 67 0x39800000 9 335 a6_fset 68 0x79000000 9 336 a6_fset 69 0x79400000 9 337 a6_fset 70 0x79800000 9 338 a6_fset 71 0xb9000000 9 339 a6_fset 72 0xb9400000 9 340 a6_fset 73 0xb9800000 9 341 a6_fset 74 0xf9000000 9 342 a6_fset 75 0xf9400000 9 343 a6_fset 76 0xbd000000 9 344 a6_fset 77 0xbd400000 9 345 a6_fset 78 0xfd000000 9 346 a6_fset 79 0xfd400000 9 347 i = ulong 0 348 while lt i 15 bound 15 349 a6_fset add 80 i get a_fbase add 65 i 10 350 i = add i 1 351 end 352 note C6.2.414 STP, C6.2.213 LDP (64-bit: signed offset, pre-index, post-index); C7.2.330 STP, C7.2.190 LDP (D) 353 a6_fset 95 0xa9000000 11 354 a6_fset 96 0xa9400000 11 355 a6_fset 97 0xa9800000 11 356 a6_fset 98 0xa9c00000 11 357 a6_fset 99 0xa8800000 11 358 a6_fset 100 0xa8c00000 11 359 a6_fset 101 0x6d000000 11 360 a6_fset 102 0x6d400000 11 361 note C6.2.35 B, C6.2.43 BL, C6.2.34 B.cond, C6.2.78 CBZ, C6.2.77 CBNZ, C6.2.481 TBZ, C6.2.480 TBNZ, 362 note C6.2.338 RET, C6.2.46 BR, C6.2.44 BLR, C6.2.466 SVC, C6.2.11 ADR 363 a6_fset 103 0x14000000 12 364 a6_fset 104 0x94000000 12 365 a6_fset 105 0x54000000 13 366 a6_fset 106 0xb4000000 14 367 a6_fset 107 0xb5000000 14 368 a6_fset 108 0x34000000 14 369 a6_fset 109 0x35000000 14 370 a6_fset 110 0x36000000 15 371 a6_fset 111 0x37000000 15 372 a6_fset 112 0xd65f0000 16 373 a6_fset 113 0xd61f0000 16 374 a6_fset 114 0xd63f0000 16 375 a6_fset 115 0xd4000001 17 376 a6_fset 116 0x10000000 18 377 end 378 379 note scalar floating point (ftype bits 22..23: 00 single, 01 double): C7.2.50 FADD, C7.2.161 FSUB, C7.2.133 FMUL, 380 note C7.2.98 FDIV, C7.2.111 FMAX, C7.2.121 FMIN, C7.2.113 FMAXNM, C7.2.123 FMINNM; C7.2.157 FSQRT, C7.2.46 FABS, 381 note C7.2.139 FNEG, C7.2.129 FMOV (register); C7.2.66 FCMP; C7.2.105 FMADD; C7.2.69 FCVT; C7.2.131 FMOV 382 note (general); C7.2.236 SCVTF, C7.2.355 UCVTF, C7.2.92 FCVTZS, C7.2.96 FCVTZU (scalar, integer) 383 fn a6_formfp to void 384 a6_fset 117 0x1e602800 1 385 a6_fset 118 0x1e603800 1 386 a6_fset 119 0x1e600800 1 387 a6_fset 120 0x1e601800 1 388 a6_fset 121 0x1e604800 1 389 a6_fset 122 0x1e605800 1 390 a6_fset 123 0x1e606800 1 391 a6_fset 124 0x1e607800 1 392 a6_fset 125 0x1e202800 1 393 a6_fset 126 0x1e203800 1 394 a6_fset 127 0x1e200800 1 395 a6_fset 128 0x1e201800 1 396 a6_fset 129 0x1e204800 1 397 a6_fset 130 0x1e205800 1 398 a6_fset 131 0x1e206800 1 399 a6_fset 132 0x1e207800 1 400 a6_fset 133 0x1e61c000 19 401 a6_fset 134 0x1e60c000 19 402 a6_fset 135 0x1e614000 19 403 a6_fset 136 0x1e604000 19 404 a6_fset 137 0x1e21c000 19 405 a6_fset 138 0x1e20c000 19 406 a6_fset 139 0x1e214000 19 407 a6_fset 140 0x1e204000 19 408 a6_fset 141 0x1e602000 20 409 a6_fset 142 0x1e202000 20 410 a6_fset 143 0x1f400000 2 411 a6_fset 144 0x1f000000 2 412 a6_fset 145 0x1e22c000 19 413 a6_fset 146 0x1e624000 19 414 a6_fset 147 0x9e660000 19 415 a6_fset 148 0x9e670000 19 416 a6_fset 149 0x1e260000 19 417 a6_fset 150 0x1e270000 19 418 a6_fset 151 0x9e620000 19 419 a6_fset 152 0x9e630000 19 420 a6_fset 153 0x9e220000 19 421 a6_fset 154 0x9e230000 19 422 a6_fset 155 0x9e780000 19 423 a6_fset 156 0x9e790000 19 424 a6_fset 157 0x9e380000 19 425 a6_fset 158 0x9e390000 19 426 note C6.2.302 RORV, 32-bit variant (sf 0): w rotate right by the low 5 bits of m (u32 rotations) 427 a6_fset 159 0x1ac02c00 1 428 note FCSEL (scalar, SIMD&FP): Rd | Rn << 5 | cond << 12 | Rm << 16 on base 0x1e200c00, ftype bits 22..23 (00 S, 429 note 01 D), the kind-8 shape. MSR (register) with o0 1 (op0 3), op1 3, CRn 4, CRm 4, op2 0, the FPCR tuple: the 430 note one Rt field in bits 0..4 (kind 22). Wolfram: FromDigits["`d5100000`",16] + 2^19 + 3*2^16 + 4*2^12 + 4*2^8 gives 431 note `d51b4400` (NgA64Float-design.md); every word is checked against GNU objdump by gate.om (tests/enc.cases). 432 a6_fset 160 0x1e600c00 8 433 a6_fset 161 0x1e200c00 8 434 a6_fset 162 0xd51b4400 22 435 note DUP (general) Vd.2D, Xn: Q 1, imm5 01000 (kind 19: Rd, Rn << 5); STR (register, SIMD&FP) Qt, [Xn, Xm{, LSL 436 note #4}]: size 00, opc 10, option 011 (kind 10, S at bit 12; like the other kind-10 forms it is given the 437 note unsigned-offset base, STR Qt, [Xn, #imm] 0x3d800000, from which a6_enc derives 0x3ca06800), the fill's 16-byte 438 note block store; both checked against GNU objdump by gate.om 439 a6_fset 163 0x4e080c00 19 440 a6_fset 164 0x3d800000 10 441 note Packed 16-byte SIMD (NgVecA64, DESIGN.md section 12): C7.2.331 STR Qt, [Xn, #imm] (kind 9), C7.2.191 LDR Qt, 442 note [Xn, #imm] (kind 9), C7.2.192 LDR Qt, [Xn, Xm{, LSL #4}] (kind 10 on the unsigned-offset base 0x3dc00000, 443 note giving 0x3ce06800); C7.2.206 ORR Vd.16B, Vn.16B, Vm.16B (kind 1, MOV alias when Vn = Vm); C7.2.42 DUP 444 note (element) vector Vd.4S/2D and scalar Sd/Dd from Vn.S/D[idx] (kind 23); C7.2.50 FADD, C7.2.161 FSUB, 445 note C7.2.133 FMUL, C7.2.125 FMLA on 4S (Q=1, sz=0) and 2D (Q=1, sz=1) (kind 1). 446 a6_fset 165 0x3d800000 9 447 a6_fset 166 0x3dc00000 9 448 a6_fset 167 0x3dc00000 10 449 a6_fset 168 0x4ea01c00 1 450 a6_fset 169 0x4e040400 23 451 a6_fset 170 0x4e080400 23 452 a6_fset 171 0x5e040400 23 453 a6_fset 172 0x5e080400 23 454 a6_fset 173 0x4e20d400 1 455 a6_fset 174 0x4e60d400 1 456 a6_fset 175 0x4ea0d400 1 457 a6_fset 176 0x4ee0d400 1 458 a6_fset 177 0x6e20dc00 1 459 a6_fset 178 0x6e60dc00 1 460 a6_fset 179 0x4e20cc00 1 461 a6_fset 180 0x4e60cc00 1 462 end 463 464 fn a6_init to void 465 a6_formdp 466 a6_formls 467 a6_formfp 468 end 469 470 fn a6_fld v ulong w ulong to ulong 471 if ge v shl ulong 1 w 472 a6_die 5 6 v 473 end 474 ret v 475 end 476 477 note a6_dsig: a signed distance d (two's complement ulong) that must fit w bits, masked to w bits (a6_die 7 if not) 478 fn a6_dsig d ulong w ulong to ulong 479 h = shl ulong 1 sub w 1 480 if ne shr d 63 0 481 if lt d sub 0 h 482 a6_die 5 7 d 483 end 484 else 485 if ge d h 486 a6_die 5 7 d 487 end 488 end 489 ret and d sub shl ulong 1 w 1 490 end 491 492 note ---- bitmask immediates (DDI 0487 M.d J1 shared pseudocode DecodeBitMasks, run backwards): a6_bmenc v w 493 note returns N << 12 | immr << 6 | imms for the w-bit (32 or 64) value v, or 65536 when v has no encoding ---- 494 fn a6_rotl x ulong r ulong e ulong to ulong 495 note rotate the low e bits of x left by r (0 <= r < e <= 64) 496 if eq r 0 497 ret x 498 end 499 m = ulong `18446744073709551615` 500 if lt e 64 501 m = sub shl ulong 1 e 1 502 end 503 ret and or shl x r shr x sub e r m 504 end 505 506 note a6_bmsz: the smallest element size e (2..64) whose pattern repeats through all of x 507 fn a6_bmsz x ulong to ulong 508 e = ulong 64 509 go = true 510 while and go gt e 2 bound 6 511 h = shr e 1 512 m = sub shl ulong 1 h 1 513 if eq and x m and shr x h m 514 e = h 515 else 516 go = false 517 end 518 end 519 ret e 520 end 521 522 fn a6_popc x ulong e ulong to ulong 523 k = ulong 0 524 i = ulong 0 525 while lt i e bound 64 526 k = add k and shr x i 1 527 i = add i 1 528 end 529 ret k 530 end 531 532 fn a6_bmenc v ulong w ulong to ulong 533 x = v 534 if eq w 32 535 x = and v 0xffffffff 536 x = or x shl x 32 537 end 538 if or eq x 0 eq x `18446744073709551615` 539 ret 65536 540 end 541 e = a6_bmsz x 542 if and eq w 32 eq e 64 543 ret 65536 544 end 545 m = ulong `18446744073709551615` 546 if lt e 64 547 m = sub shl ulong 1 e 1 548 end 549 el = and x m 550 k = a6_popc el e 551 ones = sub shl ulong 1 k 1 552 r = ulong 0 553 found = e 554 while lt r e bound 64 555 if eq a6_rotl el r e ones 556 found = r 557 r = e 558 else 559 r = add r 1 560 end 561 end 562 if eq found e 563 ret 65536 564 end 565 ret a6_bmpk e found k 566 end 567 568 note a6_bmpk: N:immr:imms for element size e, rotation r, k ones 569 fn a6_bmpk e ulong r ulong k ulong to ulong 570 if eq e 64 571 ret or or shl ulong 1 12 shl r 6 sub k 1 572 end 573 pre = and 0x3f not sub shl e 1 1 574 ret or shl r 6 or pre sub k 1 575 end 576 577 note a6_poff: a signed byte offset (multiple of 8, -512 .. 504) as the 7-bit imm7 field 578 fn a6_poff off ulong to ulong 579 if ne and off 7 0 580 a6_die 5 6 off 581 end 582 q = shr off 3 583 if ne shr off 63 0 584 q = or q 0xe000000000000000 585 if lt q 0xffffffffffffffc0 586 a6_die 5 6 off 587 end 588 else 589 if gt q 63 590 a6_die 5 6 off 591 end 592 end 593 ret and q 127 594 end 595 596 note a6_rdn: base | d | n << 5 (both 5-bit fields) 597 fn a6_rdn b ulong d ulong n ulong to ulong 598 ret or or b a6_fld d 5 shl a6_fld n 5 5 599 end 600 601 fn a6_enca k ulong b ulong x ulong y ulong z ulong u ulong to ulong 602 note kinds 1..10 (a6_enc splits the table so each part stays small) 603 if eq k 1 604 ret or or a6_rdn b x y shl a6_fld z 5 16 shl a6_fld u 6 10 605 end 606 if eq k 4 607 ret or or a6_rdn b x y shl a6_fld z 12 10 shl a6_fld u 1 22 608 end 609 if eq k 5 610 c = a6_bmenc z shl ulong 32 shr b 31 611 if eq c 65536 612 a6_die 5 6 z 613 end 614 ret or a6_rdn b x y shl c 10 615 end 616 if eq k 6 617 ret or or or b a6_fld x 5 shl a6_fld y 16 5 shl a6_fld z 2 21 618 end 619 if eq k 7 620 ret or or a6_rdn b x y shl a6_fld z 6 16 shl a6_fld u 6 10 621 end 622 if eq k 9 623 ret or a6_rdn b x y shl a6_fld z 12 10 624 end 625 if eq k 10 626 ret or or a6_rdn or sub b 0x01000000 0x00206800 x y shl a6_fld z 5 16 shl a6_fld u 1 12 627 end 628 a6_die 5 5 k 629 ret 0 630 end 631 632 note a6_encbr: kinds 12..18 (branches, BR, SVC, ADR) 633 fn a6_encbr k ulong bs ulong a ulong b ulong c ulong to ulong 634 if eq k 12 635 ret or bs a6_dsig a 26 636 end 637 if eq k 13 638 ret or or bs shl a6_dsig b 19 5 a6_fld a 4 639 end 640 if eq k 14 641 ret or or bs shl a6_dsig b 19 5 a6_fld a 5 642 end 643 if eq k 15 644 x = or or bs shl shr a6_fld b 6 5 31 shl and b 31 19 645 ret or or x shl a6_dsig c 14 5 a6_fld a 5 646 end 647 if eq k 16 648 ret or bs shl a6_fld a 5 5 649 end 650 if eq k 17 651 ret or bs shl a6_fld a 16 5 652 end 653 y = a6_dsig b 21 654 lo = shl and y 3 29 655 hi = shl shr y 2 5 656 ret or or or bs lo hi a6_fld a 5 657 end 658 659 note a6_rsv k bs c d e: refuse (a6_die 5 9) in-field operand values whose encoding Arm ARM DDI 0487 M.d leaves 660 note UNDEFINED or unallocated. A 32-bit form (sf, bit 31 of the base, clear) takes shift amounts, BFM immr and imms 661 note and EXTR lsb 0..31 and MOVZ/MOVN hw 0..1. Kind 1 shifted register: logical (base bits 28..24 = 01010, C6.2.14) 662 note takes sh 0..3; add/sub (01011, C6.2.5) reserves sh 3; every other kind-1 form (multiply, two-source, float) 663 note has opcode bits where sh and amt go, so both must be 0. Operands as a6_enc passes them: kind 1 sh d, amt e; 664 note kind 6 hw c; kind 7 immr c, imms d; kind 21 lsb d. 665 fn a6_rsv k ulong bs ulong c ulong d ulong e ulong to void 666 w32 = eq shr bs 31 0 667 if eq k 1 668 cl = and shr bs 24 31 669 if and ne cl 10 ne cl 11 670 if ne or d e 0 671 a6_die 5 9 or d e 672 end 673 end 674 if and eq cl 11 eq d 3 675 a6_die 5 9 d 676 end 677 if and w32 ge e 32 678 a6_die 5 9 e 679 end 680 end 681 if and and w32 eq k 6 ge c 2 682 a6_die 5 9 c 683 end 684 if and and w32 or eq k 7 eq k 21 ge d 32 685 a6_die 5 9 d 686 end 687 if and and w32 eq k 7 ge c 32 688 a6_die 5 9 c 689 end 690 end 691 692 note a6_enc f a b c d e: the instruction word of form f with operands a..e (unused operands 0) 693 fn a6_enc f ulong a ulong b ulong c ulong d ulong e ulong to ulong 694 if ge f get a_nform 0 695 a6_die 5 5 f 696 end 697 k = ulong get a_fkind f 698 bs = get a_fbase f 699 a6_rsv k bs c d e 700 if eq k 1 701 x = a6_enca 1 bs a b c e 702 ret or x shl a6_fld d 2 22 703 end 704 if eq k 3 705 x = or a6_rdn bs a b shl a6_fld c 5 16 706 ret or or x shl a6_fld d 3 13 shl a6_fld e 3 10 707 end 708 if eq k 2 709 ret or or a6_rdn bs a b shl a6_fld c 5 16 shl a6_fld d 5 10 710 end 711 if eq k 8 712 ret or or a6_rdn bs a b shl a6_fld c 5 16 shl a6_fld d 4 12 713 end 714 if eq k 11 715 ret or or a6_rdn bs a c shl a6_fld b 5 10 shl a6_poff d 15 716 end 717 if and ge k 12 le k 18 718 ret a6_encbr k bs a b c 719 end 720 if eq k 19 721 ret a6_rdn bs a b 722 end 723 if eq k 20 724 ret or or bs shl a6_fld a 5 5 shl a6_fld b 5 16 725 end 726 if eq k 21 727 ret or or a6_rdn bs a b shl a6_fld c 5 16 shl a6_fld d 6 10 728 end 729 if eq k 22 730 ret or bs a6_fld a 5 731 end 732 if eq k 23 733 ret a6_encdp bs a b c 734 end 735 ret a6_enca k bs a b c d 736 end 737 738 fn a6_encdp bs ulong a ulong b ulong c ulong to ulong 739 if ne and shr bs 19 1 0 740 ret or a6_rdn bs a b shl a6_fld c 1 20 741 end 742 ret or a6_rdn bs a b shl a6_fld c 2 19 743 end 744 745 note a6_ew: emit the word of form f 746 fn a6_ew f ulong a ulong b ulong c ulong d ulong e ulong to void 747 a6_emitw a6_enc f a b c d e 748 end 749 750 note ======== in-band mode `a64 enc`: one word per case line `NAME a b c d e | expected` ======== 751 note Lines that are blank or start with `;` are skipped. Operands are decimal (a leading - makes the two's 752 note complement) or lowercase 0x hex. A line that names no form or has a bad operand is refused (a6_die 5 4 line). 753 global a_cv ulong 8 754 755 fn a6_isws c ulong to bool 756 ret or eq c 32 eq c 9 757 end 758 759 note a6_samew: a_fnam[i .. i+n) equals i_in[s .. s+n) 760 fn a6_samew i ulong s ulong n ulong to bool 761 q = ulong 0 762 while lt q n bound 64 763 if ne get a_fnam add i q ar_ib add s q 764 ret false 765 end 766 q = add q 1 767 end 768 ret true 769 end 770 771 note a6_innm: byte j of a_fnam exists and is part of a name (and/or are eager, so the bound is tested here) 772 fn a6_innm j ulong to bool 773 if ge j len a_fnam 774 ret false 775 end 776 ret ne get a_fnam j 32 777 end 778 779 note a6_fname: the form id whose name in a_fnam equals i_in[s .. s+n), or a_nform when there is none 780 fn a6_fname s ulong n ulong to ulong 781 i = ulong 0 782 id = ulong 0 783 ln = len a_fnam 784 while lt i ln bound 4096 785 j = i 786 while a6_innm j bound 64 787 j = add j 1 788 end 789 if eq sub j i n 790 if a6_samew i s n 791 ret id 792 end 793 end 794 id = add id 1 795 i = add j 1 796 end 797 ret get a_nform 0 798 end 799 800 note a6_numtk: the number at i_in[s .. e), into a_cv[7]; false if malformed 801 fn a6_numtk s ulong e ulong to bool 802 p = s 803 ng = false 804 if eq ar_ib p 45 805 ng = true 806 p = add p 1 807 end 808 if ge p e 809 ret false 810 end 811 v = ulong 0 812 hex = false 813 if lt add p 1 e 814 if and eq ar_ib p 48 eq ar_ib add p 1 120 815 hex = true 816 p = add p 2 817 end 818 end 819 while lt p e bound 64 820 c = ulong ar_ib p 821 dg = ulong 99 822 if and ge c 48 le c 57 823 dg = sub c 48 824 end 825 if and hex and ge c 97 le c 102 826 dg = sub c 87 827 end 828 if and hex ge dg 16 829 ret false 830 end 831 if ge dg 10 832 if not hex 833 ret false 834 end 835 end 836 if hex 837 v = or shl v 4 dg 838 else 839 v = add mul v 10 dg 840 end 841 p = add p 1 842 end 843 if ng 844 v = sub 0 v 845 end 846 put a_cv 7 v 847 ret true 848 end 849 850 note a6_skipws: the first byte at or after p (before e) that is not a blank 851 fn a6_skipws p ulong e ulong to ulong 852 q = p 853 while and lt q e a6_isws ulong ar_ib q bound 100000 854 q = add q 1 855 end 856 ret q 857 end 858 859 note a6_tokend: the end of the operand token at p (a blank, `|` or e) 860 fn a6_tokend p ulong e ulong to ulong 861 q = p 862 while lt q e bound 64 863 c = ulong ar_ib q 864 if or a6_isws c eq c 124 865 ret q 866 end 867 q = add q 1 868 end 869 ret q 870 end 871 872 note a6_encln: one case line i_in[s .. e) (line number ln): the word for it 873 fn a6_encln s ulong e ulong ln ulong to void 874 p = a6_tokend s e 875 f = a6_fname s sub p s 876 if ge f get a_nform 0 877 a6_die 5 4 ln 878 end 879 k = ulong 0 880 while lt k 5 bound 5 881 put a_cv k 0 882 k = add k 1 883 end 884 k = ulong 0 885 go = true 886 while go bound 16 887 p = a6_skipws p e 888 if or ge p e eq ar_ib p 124 889 go = false 890 else 891 q = a6_tokend p e 892 if or ge k 5 not a6_numtk p q 893 a6_die 5 4 ln 894 end 895 put a_cv k get a_cv 7 896 k = add k 1 897 p = q 898 end 899 end 900 a6_ewcv f 901 end 902 903 note a6_ewcv: emit form f with the operands in a_cv[0..4] 904 fn a6_ewcv f ulong to void 905 a = get a_cv 0 906 b = get a_cv 1 907 c = get a_cv 2 908 d = get a_cv 3 909 e = get a_cv 4 910 a6_ew f a b c d e 911 end 912 913 note a6_enctest: one word per case line of the payload; ln numbers lines as in the case file, whose line 1 is the 914 note mode line main read apart 915 fn a6_enctest to void 916 n = get a_inlen 0 917 p = ulong 0 918 ln = ulong 1 919 while lt p n bound `1000000` 920 ln = add ln 1 921 s = p 922 while and lt p n ne ar_ib p 10 bound 100000 923 p = add p 1 924 end 925 q = s 926 while and lt q p a6_isws ulong ar_ib q bound 100000 927 q = add q 1 928 end 929 if lt q p 930 if ne ar_ib q 59 931 a6_encln q p ln 932 end 933 end 934 p = add p 1 935 end 936 a6_flush 937 exit 0 938 end 939 940 941 note ======== back end: ΩIR tables (ir.om) -> AArch64 ELF (seed/ng/a64/DESIGN.md) ======== 942 note Slice scope: integer scalar functions and exports (the bench-kernel subset grows from here). Allocated registers: 943 note x0..x14 (caller-saved) and x19..x27 (callee-saved); scratch x15, x16, x17; x28 holds the stack floor (omc's map: 944 note stack 0x10000000..0x10800000, sp starts at the top); x18 retains the Linux entry stack for env words, x29 unused; x30 link. Arguments x0..x7, result x0. 945 note A narrow integer lives in its register extended to 64 bits by its type (zero: u8..u32, sign: i8..i32), so 64-bit 946 note compares are exact and arithmetic followed by re-extension gives ΩIR's modulo 2^w result (IR.md s7.3). 947 note Positions: function parameters are defined at 0; block x starts at a_bst[x] (its parameters are defined there), 948 note op o is at a_opos[o] (its operands are read there, its result is defined at a_opos[o] + 1). 949 note An interval is one range [a_vs, a_ve] per value, widened over every block where the value is live in or out. 950 951 note The per-wire tables (a_vh .. a_nu), the liveness bitsets (a_lin .. a_ldef, blocks x words), the call sites 952 note (a_cpc, a_cft) and the branch fixups (a_xpc, a_xfm, a_xa, a_xl: regions 108..111) are arena groups a64val, 953 note a64live, a64call and a64fix (src/ir.om ar_*; no-caps 2026-11-11), grown per function and bounded by the arena 954 note only: a full arena is `ng: arena full` with the ng-use record, exit 14. They were fixed at 262144 wires and 955 note `2097152` liveness words per function and `1048576` call sites (a6_unsup), which calls_524289 (one function, 956 note `1048591` wires) passed, and at 262144 fixups per function (a6_unsup), which 270000 checked adds in one function 957 note passed. Blocks and positions per function stay IR.md s12's. 958 const a_maxb ulong 65536 959 const a_maxp ulong `4194304` 960 961 note a_vln[w] = the length wire of slice value wire w, plus 1 (0: not a slice); a_mal the machine argument list of 962 note one call or of the function's parameters (a6_xcall, a6_xpar), a_man its length 963 global a_mal ulong 136 964 note a_mac: the class of machine argument k (1: f32/f64, in a V register; 0: integer, reference or length wire); 965 note a_mab: its ABI place from a6_abi (register location, or 1000 + outgoing slot) 966 global a_mac uchar 136 967 global a_mab ulong 136 968 note a_vf[w] = 1 when wire w holds an f32/f64 value (allocated from V registers, locations 32..63) 969 global a_man ulong 1 970 global a_bh ulong 65536 971 global a_bst ulong 65536 972 global a_ben ulong 65536 973 global a_bpc ulong 65536 974 global a_opos ulong `4194305` 975 global a_ccnt ulong `4194305` 976 global a_phd ulong `4194305` 977 note a_fs (per function): 0 values, 1 blocks, 2 bitset words per block, 3 positions, 4 spill slots, 5 callee-saved 978 note mask, 6 has a call, 7 frame bytes, 8 function, 9 liveness changed, 10 trap codes used (mask), 11 saved count, 979 note 12 fixups, 13 current block index, 14 E tail sites (0: no accumulator), 15 code offset of the E loop head 980 global a_fs ulong 17 981 note fusion: use counts by wire; a_skip 0 is the one consumer (cbr or select) a fused compare emitted at its own site, 982 note skipped at the consumer's turn in a6_sel after a6_sel's refusals. 983 global a_skip ulong 1 984 note a_sform: 0 save pairs (STP/LDP, variant A), 1 separate STR/LDR (variant B); `@ng a64 split` selects 1 985 global a_sform ulong 1 986 note a_tgt: 0 static AArch64 Linux ELF (`@ng a64`, `@ng a64 split`), 1 dynamic arm64 Mach-O for macOS (`@ng a64 987 note macho`, save pairs). Mach-O code is position independent: the start code derives the stack floor x28 from 988 note its own address (ADR), and a global's address is x28 plus (class 0) or minus (class 1) a constant. 989 global a_tgt ulong 1 990 note a_bks: the image offset of the sixteen callback entries (a6_back), 0 when the unit has no callback function 991 global a_bks ulong 1 992 global a_ract ulong 64 993 global a_svl ulong 32 994 global a_ncl ulong 1 995 global a_fpc ulong 65537 996 global a_tpc ulong 16 997 global a_mvd ulong 64 998 global a_mvs ulong 64 999 global a_mvn ulong 1 1000 note E loop shape: tail call sites (call ops), accumulator wire and type 1001 global a_tco ulong 64 1002 global a_taw ulong 1 1003 global a_tat ulong 1 1004 note memory: alloca ops of the function with their frame offset and zero-filled size (16-byte multiple); global 1005 note handle -> absolute address (class 0 in the RW pool from 0x10800000, class 1 in the code image); pool bytes 1006 global a_alo ulong 64 1007 global a_aof ulong 64 1008 global a_asz ulong 64 1009 global a_anum ulong 1 1010 global a_gtot ulong 1 1011 1012 const a_rorvx ulong 28 1013 const a_lsrvw ulong 30 1014 const a_asrvw ulong 31 1015 const a_rorvw ulong 159 1016 const a_tbnz ulong 111 1017 const a_lsbx ulong 82 1018 const a_strhr ulong 83 1019 const a_ldrhr ulong 84 1020 const a_lshx ulong 85 1021 const a_strwr ulong 86 1022 const a_ldrwr ulong 87 1023 const a_lsw ulong 88 1024 const a_strxr ulong 89 1025 const a_stpxpo ulong 99 1026 1027 note ---- small accessors ---- 1028 fn a6_wi v ulong to ulong 1029 ret ulong get i_vno v 1030 end 1031 1032 fn a6_istk v ulong to bool 1033 ret eq get i_vty v 20 1034 end 1035 1036 fn a6_arg o ulong k ulong to ulong 1037 ret ulong get i_arg add ulong get i_oa0 o k 1038 end 1039 1040 fn a6_bix b ulong to ulong 1041 ret ulong get i_bix b 1042 end 1043 1044 fn a6_vty v ulong to ulong 1045 ret ulong get i_vty v 1046 end 1047 1048 fn a6_unsup k ulong to void 1049 a6_die 5 5 k 1050 end 1051 1052 note bit width of an integer type id (bool 1); 0 for anything else 1053 fn a6_wid t ulong to ulong 1054 if or eq t 2 eq t 6 1055 ret 8 1056 end 1057 if or eq t 3 eq t 7 1058 ret 16 1059 end 1060 if or eq t 4 eq t 8 1061 ret 32 1062 end 1063 if or eq t 5 eq t 9 1064 ret 64 1065 end 1066 if eq t 1 1067 ret 1 1068 end 1069 ret 0 1070 end 1071 1072 fn a6_sgn t ulong to bool 1073 ret and ge t 6 le t 9 1074 end 1075 1076 note the value types this slice handles: bool and the integers 1077 fn a6_isint t ulong to bool 1078 ret and ge t 1 le t 9 1079 end 1080 1081 note ---- bit sets: k 0 live-in, 1 live-out, 2 upward-exposed uses, 3 definitions; block x, value w ---- 1082 fn a6_lget k ulong i ulong to ulong 1083 if eq k 0 1084 ret get ar_m add get ar_rb 101 i 1085 end 1086 if eq k 1 1087 ret get ar_m add get ar_rb 102 i 1088 end 1089 if eq k 2 1090 ret get ar_m add get ar_rb 103 i 1091 end 1092 ret get ar_m add get ar_rb 104 i 1093 end 1094 1095 fn a6_lset k ulong i ulong v ulong to void 1096 if eq k 0 1097 put ar_m add get ar_rb 101 i v 1098 end 1099 if eq k 1 1100 put ar_m add get ar_rb 102 i v 1101 end 1102 if eq k 2 1103 put ar_m add get ar_rb 103 i v 1104 end 1105 if eq k 3 1106 put ar_m add get ar_rb 104 i v 1107 end 1108 end 1109 1110 fn a6_bit k ulong x ulong w ulong to bool 1111 i = add mul x get a_fs 2 shr w 6 1112 ret ne and shr a6_lget k i and w 63 1 0 1113 end 1114 1115 fn a6_bset k ulong x ulong w ulong to void 1116 i = add mul x get a_fs 2 shr w 6 1117 a6_lset k i or a6_lget k i shl ulong 1 and w 63 1118 end 1119 1120 note ---- wires, layout, calls ---- 1121 note a6_wmap f: a_vh[wire] = value handle for every value of f (the order of ir_num) 1122 fn a6_wmap f ulong to void 1123 v = ulong get i_ftk f 1124 put ar_m add get ar_rb 91 a6_wi v v 1125 v = ulong get i_fp1 f 1126 while ne v 0 bound 65 1127 put ar_m add get ar_rb 91 a6_wi v v 1128 v = ulong get i_vnx v 1129 end 1130 b = ulong get i_fb1 f 1131 while ne b 0 bound 65537 1132 a6_wmb b 1133 b = ulong get i_bnx b 1134 end 1135 end 1136 1137 fn a6_wmb b ulong to void 1138 v = ulong get i_bp1 b 1139 while ne v 0 bound 65 1140 put ar_m add get ar_rb 91 a6_wi v v 1141 v = ulong get i_vnx v 1142 end 1143 o = ulong get i_bo1 b 1144 while ne o 0 bound `4194305` 1145 t = ulong get i_otk o 1146 if ne t 0 1147 put ar_m add get ar_rb 91 a6_wi t t 1148 end 1149 r = ulong get i_ors o 1150 if ne r 0 1151 put ar_m add get ar_rb 91 a6_wi r r 1152 end 1153 o = ulong get i_onx o 1154 end 1155 end 1156 1157 note a6_lay f: block index tables and positions (a_fs 1 blocks, 3 positions) 1158 fn a6_lay f ulong to void 1159 nb = ulong 0 1160 p = ulong 2 1161 b = ulong get i_fb1 f 1162 while ne b 0 bound 65537 1163 put a_bh nb b 1164 put a_bst nb p 1165 p = add p 2 1166 o = ulong get i_bo1 b 1167 while ne o 0 bound `4194305` 1168 if ge p sub a_maxp 4 1169 a6_unsup p 1170 end 1171 put a_opos o p 1172 p = add p 2 1173 o = ulong get i_onx o 1174 end 1175 put a_ben nb sub p 1 1176 nb = add nb 1 1177 b = ulong get i_bnx b 1178 end 1179 put a_fs 1 nb 1180 put a_fs 3 p 1181 end 1182 1183 note a6_ccalls: a_ccnt[q] = the number of calls and host words at positions < q, for q in 0..positions; a_fs 6 = 1184 note any call (x30 is saved). A host word's SVC clobbers x0 only, but its arguments go to x0..x2, so values live 1185 note across it take callee-saved registers like values live across a call. 1186 fn a6_ccalls to void 1187 np = get a_fs 3 1188 q = ulong 0 1189 while le q np bound `4194305` 1190 put a_ccnt q 0 1191 q = add q 1 1192 end 1193 put a_fs 6 0 1194 x = ulong 0 1195 while lt x get a_fs 1 bound 65536 1196 o = ulong get i_bo1 get a_bh x 1197 while ne o 0 bound `4194305` 1198 if and eq get i_oop o 64 not a6_istc o 1199 put a_ccnt get a_opos o 1 1200 put a_fs 6 1 1201 end 1202 if a6_hostcall ulong get i_oop o 1203 put a_ccnt get a_opos o 1 1204 end 1205 if eq get i_oop o 111 1206 put a_fs 6 1 1207 end 1208 o = ulong get i_onx o 1209 end 1210 x = add x 1 1211 end 1212 a6_cpre np 1213 end 1214 1215 fn a6_cpre np ulong to void 1216 run = ulong 0 1217 q = ulong 0 1218 while le q np bound `4194305` 1219 t = get a_ccnt q 1220 put a_ccnt q run 1221 run = add run t 1222 q = add q 1 1223 end 1224 end 1225 1226 note ---- liveness (SSA with block parameters) ---- 1227 fn a6_lzero to void 1228 n = mul get a_fs 1 get a_fs 2 1229 i = ulong 0 1230 while lt i n bound `16777217` 1231 put ar_m add get ar_rb 101 i 0 1232 put ar_m add get ar_rb 102 i 0 1233 put ar_m add get ar_rb 103 i 0 1234 put ar_m add get ar_rb 104 i 0 1235 i = add i 1 1236 end 1237 end 1238 1239 note a6_lgen: per block the uses not defined earlier in it (2) and its definitions (3) 1240 fn a6_lgen to void 1241 x = ulong 0 1242 while lt x get a_fs 1 bound 65536 1243 b = get a_bh x 1244 v = ulong get i_bp1 b 1245 while ne v 0 bound 65 1246 if not a6_istk v 1247 a6_bset 3 x a6_wi v 1248 end 1249 v = ulong get i_vnx v 1250 end 1251 o = ulong get i_bo1 b 1252 while ne o 0 bound `4194305` 1253 a6_lgo x o 1254 o = ulong get i_onx o 1255 end 1256 x = add x 1 1257 end 1258 end 1259 1260 fn a6_lgo x ulong o ulong to void 1261 op = get i_oop o 1262 n = ulong get i_ona o 1263 k = ulong 0 1264 while lt k n bound `1048576` 1265 if eq ir_okd uint op k 0 1266 v = a6_arg o k 1267 if not a6_istk v 1268 w = a6_wi v 1269 if not a6_bit 3 x w 1270 a6_bset 2 x w 1271 end 1272 end 1273 end 1274 k = add k 1 1275 end 1276 r = ulong get i_ors o 1277 if ne r 0 1278 if not a6_istk r 1279 a6_bset 3 x a6_wi r 1280 end 1281 end 1282 end 1283 1284 note word i of the union of the live-in sets of block b's successors (terminator t) 1285 fn a6_succw t ulong i ulong to ulong 1286 op = get i_oop t 1287 lw = get a_fs 2 1288 if eq op 60 1289 s = a6_bix a6_arg t 0 1290 ret get ar_m add get ar_rb 101 add mul s lw i 1291 end 1292 if eq op 61 1293 s1 = a6_bix a6_arg t 2 1294 s2 = a6_bix a6_arg t 3 1295 ret or ar_w 101 add mul s1 lw i get ar_m add get ar_rb 101 add mul s2 lw i 1296 end 1297 ret 0 1298 end 1299 1300 fn a6_lblk x ulong to void 1301 lw = get a_fs 2 1302 t = ulong get i_bot get a_bh x 1303 i = ulong 0 1304 while lt i lw bound `16777217` 1305 j = add mul x lw i 1306 so = a6_succw t i 1307 put ar_m add get ar_rb 102 j so 1308 nin = or ar_w 103 j and so not ar_w 104 j 1309 if ne nin get ar_m add get ar_rb 101 j 1310 put ar_m add get ar_rb 101 j nin 1311 put a_fs 9 1 1312 end 1313 i = add i 1 1314 end 1315 end 1316 1317 fn a6_lflow to void 1318 go = true 1319 while go bound 100000 1320 put a_fs 9 0 1321 x = get a_fs 1 1322 while gt x 0 bound 65537 1323 x = sub x 1 1324 a6_lblk x 1325 end 1326 go = ne get a_fs 9 0 1327 end 1328 end 1329 1330 note ---- intervals ---- 1331 fn a6_dpos v ulong to ulong 1332 k = get i_vk v 1333 if le k 1 1334 ret 0 1335 end 1336 if eq k 2 1337 ret get a_bst a6_bix ulong get i_vo v 1338 end 1339 ret add get a_opos ulong get i_vo v 1 1340 end 1341 1342 fn a6_ivinit to void 1343 w = ulong 0 1344 while lt w get a_fs 0 bound `16777217` 1345 v = get ar_m add get ar_rb 91 w 1346 put ar_m add get ar_rb 96 w 0 1347 ar_pc 94 w 0 1348 ar_pc 99 w 0 1349 if a6_istk v 1350 ar_pc 95 w 254 1351 put ar_m add get ar_rb 92 w 0 1352 put ar_m add get ar_rb 93 w 0 1353 else 1354 p = a6_dpos v 1355 ar_pc 95 w 255 1356 put ar_m add get ar_rb 92 w p 1357 put ar_m add get ar_rb 93 w p 1358 if a6_isfv v 1359 ar_pc 99 w 1 1360 end 1361 if eq get i_tk a6_vty v 1 1362 if not a6_isvv v 1363 a6_unsup a6_vty v 1364 end 1365 ar_pc 99 w 2 1366 end 1367 end 1368 w = add w 1 1369 end 1370 end 1371 1372 fn a6_ext w ulong p ulong to void 1373 if lt p get ar_m add get ar_rb 92 w 1374 put ar_m add get ar_rb 92 w p 1375 end 1376 if gt p get ar_m add get ar_rb 93 w 1377 put ar_m add get ar_rb 93 w p 1378 end 1379 end 1380 1381 note a6_ivuse: every non-token operand use extends its value to the op's position 1382 fn a6_ivuse to void 1383 x = ulong 0 1384 while lt x get a_fs 1 bound 65536 1385 o = ulong get i_bo1 get a_bh x 1386 while ne o 0 bound `4194305` 1387 a6_ivop o 1388 o = ulong get i_onx o 1389 end 1390 x = add x 1 1391 end 1392 end 1393 1394 fn a6_ivop o ulong to void 1395 op = get i_oop o 1396 n = ulong get i_ona o 1397 p = get a_opos o 1398 k = ulong 0 1399 while lt k n bound `1048576` 1400 if eq ir_okd uint op k 0 1401 v = a6_arg o k 1402 if not a6_istk v 1403 a6_ext a6_wi v p 1404 end 1405 end 1406 k = add k 1 1407 end 1408 end 1409 1410 note a6_ivlive: live-in values cover their block's start, live-out values its end 1411 fn a6_ivlive to void 1412 x = ulong 0 1413 lw = get a_fs 2 1414 while lt x get a_fs 1 bound 65536 1415 i = ulong 0 1416 while lt i lw bound `16777217` 1417 a6_ivw x i get ar_m add get ar_rb 101 add mul x lw i get a_bst x 1418 a6_ivw x i get ar_m add get ar_rb 102 add mul x lw i get a_ben x 1419 i = add i 1 1420 end 1421 x = add x 1 1422 end 1423 end 1424 1425 fn a6_ivw x ulong i ulong m ulong p ulong to void 1426 if eq m 0 1427 ret 1428 end 1429 j = ulong 0 1430 while lt j 64 bound 64 1431 if ne and shr m j 1 0 1432 a6_ext add shl i 6 j p 1433 end 1434 j = add j 1 1435 end 1436 end 1437 1438 note a6_ivcross: a_vx[w] = 1 when a call sits strictly inside w's interval 1439 fn a6_ivcross to void 1440 w = ulong 0 1441 while lt w get a_fs 0 bound `16777217` 1442 s = get ar_m add get ar_rb 92 w 1443 e = get ar_m add get ar_rb 93 w 1444 if and eq uchar get ar_m add get ar_rb 95 w 255 gt e add s 1 1445 if gt get a_ccnt e get a_ccnt add s 1 1446 ar_pc 94 w 1 1447 end 1448 end 1449 w = add w 1 1450 end 1451 end 1452 1453 note ---- linear scan (Poletto and Sarkar), intervals in start order ---- 1454 fn a6_scan to void 1455 np = get a_fs 3 1456 q = ulong 0 1457 while le q np bound `4194305` 1458 put a_phd q 0 1459 q = add q 1 1460 end 1461 w = get a_fs 0 1462 while gt w 0 bound `16777217` 1463 w = sub w 1 1464 if ne uchar get ar_m add get ar_rb 95 w 254 1465 s = get ar_m add get ar_rb 92 w 1466 put ar_m add get ar_rb 97 w get a_phd s 1467 put a_phd s add w 1 1468 end 1469 end 1470 r = ulong 0 1471 while lt r 64 bound 64 1472 put a_ract r 0 1473 r = add r 1 1474 end 1475 put a_fs 4 a6_outm 1476 put a_fs 5 0 1477 q = ulong 0 1478 while le q np bound `4194305` 1479 h = get a_phd q 1480 while ne h 0 bound `16777217` 1481 a6_alloc sub h 1 1482 h = get ar_m add get ar_rb 97 sub h 1 1483 end 1484 q = add q 1 1485 end 1486 end 1487 1488 fn a6_expire s ulong to void 1489 r = ulong 0 1490 while lt r 64 bound 64 1491 a = get a_ract r 1492 if ne a 0 1493 if lt get ar_m add get ar_rb 93 sub a 1 s 1494 put a_ract r 0 1495 end 1496 end 1497 r = add r 1 1498 end 1499 end 1500 1501 note a6_free x: a free register, caller-saved first unless the interval crosses a call (x); 255 if none 1502 fn a6_free x bool to ulong 1503 if not x 1504 r = ulong 0 1505 while lt r 15 bound 15 1506 if eq get a_ract r 0 1507 ret r 1508 end 1509 r = add r 1 1510 end 1511 end 1512 r = ulong 19 1513 while lt r 28 bound 9 1514 if eq get a_ract r 0 1515 ret r 1516 end 1517 r = add r 1 1518 end 1519 ret 255 1520 end 1521 1522 note a6_ffree x: a free V register (location 32 + V) for an f32/f64 interval: v0..v7 and v16..v28 (caller-saved) 1523 note first unless it crosses a call (x), then d8..d15 (callee-saved: the low 64 bits are preserved, all a scalar 1524 note needs); v29..v31 are the float scratch and never allocated; 255 if none 1525 fn a6_ffree x bool to ulong 1526 if not x 1527 r = ulong 32 1528 while lt r 61 bound 29 1529 if or lt r 40 gt r 47 1530 if eq get a_ract r 0 1531 ret r 1532 end 1533 end 1534 r = add r 1 1535 end 1536 end 1537 r = ulong 40 1538 while lt r 48 bound 8 1539 if eq get a_ract r 0 1540 ret r 1541 end 1542 r = add r 1 1543 end 1544 ret 255 1545 end 1546 1547 fn a6_give w ulong r ulong to void 1548 ar_pc 95 w uchar r 1549 put a_ract r add w 1 1550 if ge r 19 1551 if or lt r 28 and ge r 40 lt r 48 1552 put a_fs 5 or get a_fs 5 shl ulong 1 r 1553 end 1554 end 1555 end 1556 1557 fn a6_slot w ulong to void 1558 n = get a_fs 4 1559 if eq uchar get ar_m add get ar_rb 99 w 2 1560 n = and add n 1 not ulong 1 1561 put ar_m add get ar_rb 96 w add n 1 1562 put a_fs 4 add n 2 1563 ret 1564 end 1565 put ar_m add get ar_rb 96 w add n 1 1566 put a_fs 4 add n 1 1567 end 1568 1569 fn a6_alloc w ulong to void 1570 a6_expire get ar_m add get ar_rb 92 w 1571 x = ne uchar get ar_m add get ar_rb 94 w 0 1572 if and x eq uchar get ar_m add get ar_rb 99 w 2 1573 a6_slot w 1574 ret 1575 end 1576 fl = ne uchar get ar_m add get ar_rb 99 w 0 1577 r = ulong 255 1578 if fl 1579 r = a6_ffree x 1580 else 1581 r = a6_free x 1582 end 1583 if ne r 255 1584 a6_give w r 1585 ret 1586 end 1587 a6_spill w x fl 1588 end 1589 1590 note a6_spill w x: w found no free register of its class (x: callee-saved only). The active interval of that class 1591 note ending last keeps its register when it ends no later than w (w gets a stack slot); otherwise it moves to a 1592 note stack slot and w takes its register. The class is the integer registers, or the V registers when fl. 1593 fn a6_spill w ulong x bool fl bool to void 1594 best = ulong 255 1595 bend = ulong 0 1596 r = ulong 0 1597 rh = ulong 28 1598 if fl 1599 r = 32 1600 rh = 61 1601 end 1602 while lt r rh bound 61 1603 if a6_okreg r x 1604 a = get a_ract r 1605 if ne a 0 1606 e = get ar_m add get ar_rb 93 sub a 1 1607 if or eq best 255 gt e bend 1608 best = r 1609 bend = e 1610 end 1611 end 1612 end 1613 r = add r 1 1614 end 1615 if and ne best 255 gt bend get ar_m add get ar_rb 93 w 1616 v = sub get a_ract best 1 1617 ar_pc 95 v 255 1618 a6_slot v 1619 a6_give w best 1620 ret 1621 end 1622 a6_slot w 1623 end 1624 1625 fn a6_okreg r ulong x bool to bool 1626 if ge r 32 1627 if and ge r 40 le r 47 1628 ret true 1629 end 1630 ret not x 1631 end 1632 if and ge r 19 le r 27 1633 ret true 1634 end 1635 ret and not x lt r 15 1636 end 1637 1638 note ---- frame: spill slots at [sp, 8k], then the saved registers (callee-saved in use, x30 if any call), both 1639 note below 4096 bytes; then the alloca areas (16-byte aligned); the whole frame below 2^24 ---- 1640 fn a6_frame to void 1641 n = ulong 0 1642 r = ulong 19 1643 while lt r 28 bound 9 1644 if ne and shr get a_fs 5 r 1 0 1645 put a_svl n r 1646 n = add n 1 1647 end 1648 r = add r 1 1649 end 1650 if ne get a_fs 6 0 1651 put a_svl n 30 1652 n = add n 1 1653 end 1654 r = ulong 40 1655 while lt r 48 bound 8 1656 if ne and shr get a_fs 5 r 1 0 1657 put a_svl n r 1658 n = add n 1 1659 end 1660 r = add r 1 1661 end 1662 put a_fs 11 n 1663 f = mul 8 add get a_fs 4 n 1664 f = and add f 15 not ulong 15 1665 if gt f 4095 1666 a6_unsup f 1667 end 1668 f = a6_alay f 1669 if ge f `16777216` 1670 a6_unsup f 1671 end 1672 put a_fs 7 f 1673 end 1674 1675 note a6_alay b: give every alloca of the function an area from frame offset b up; returns the frame size 1676 fn a6_alay b ulong to ulong 1677 put a_anum 0 0 1678 f = b 1679 x = ulong 0 1680 while lt x get a_fs 1 bound 65536 1681 o = ulong get i_bo1 get a_bh x 1682 while ne o 0 bound `4194305` 1683 if eq get i_oop o 50 1684 f = a6_alo1 o f 1685 end 1686 o = ulong get i_onx o 1687 end 1688 x = add x 1 1689 end 1690 ret f 1691 end 1692 1693 fn a6_alo1 o ulong f ulong to ulong 1694 k = get a_anum 0 1695 if ge k len a_alo 1696 a6_unsup 50 1697 end 1698 t = ulong get i_oty o 1699 if ne get i_tk t 4 1700 a6_unsup t 1701 end 1702 s = ir_tsize get i_t1 t 1703 s = and add s 15 not ulong 15 1704 if ge s `16777216` 1705 a6_unsup s 1706 end 1707 put a_alo k o 1708 put a_aof k f 1709 put a_asz k s 1710 put a_anum 0 add k 1 1711 ret add f s 1712 end 1713 1714 note a6_saves st: store (st) or reload the saved registers, as pairs (a_sform 0) or one by one (1); a pair is two 1715 note registers of one class (STP/LDP X or D: x19..x27 and x30 come first, d8..d15 after them) 1716 fn a6_saves st bool to void 1717 n = get a_fs 11 1718 base = mul 8 get a_fs 4 1719 pair = and eq get a_sform 0 0 le add base mul 8 n 504 1720 j = ulong 0 1721 if pair 1722 while lt add j 1 n bound 32 1723 r1 = get a_svl j 1724 r2 = get a_svl add j 1 1725 if eq a6_rcls r1 a6_rcls r2 1726 a6_pr st r1 r2 add base mul 8 j 1727 j = add j 2 1728 else 1729 a6_sr st r1 add shr base 3 j 1730 j = add j 1 1731 end 1732 end 1733 end 1734 while lt j n bound 32 1735 a6_sr st get a_svl j add shr base 3 j 1736 j = add j 1 1737 end 1738 end 1739 1740 note a6_rcls r: the class of a saved register location: 0 integer, 1 V (location 32 + V) 1741 fn a6_rcls r ulong to ulong 1742 if ge r 32 1743 ret 1 1744 end 1745 ret 0 1746 end 1747 1748 fn a6_pr st bool r1 ulong r2 ulong off ulong to void 1749 if ge r1 32 1750 if st 1751 a6_ew a_stpd sub r1 32 sub r2 32 31 off 0 1752 else 1753 a6_ew a_ldpd sub r1 32 sub r2 32 31 off 0 1754 end 1755 ret 1756 end 1757 if st 1758 a6_ew a_stpx r1 r2 31 off 0 1759 else 1760 a6_ew a_ldpx r1 r2 31 off 0 1761 end 1762 end 1763 1764 fn a6_sr st bool r ulong k ulong to void 1765 if ge r 32 1766 if st 1767 a6_ew a_strd sub r 32 31 k 0 0 1768 else 1769 a6_ew a_ldrd sub r 32 31 k 0 0 1770 end 1771 ret 1772 end 1773 if st 1774 a6_ew a_strx r 31 k 0 0 1775 else 1776 a6_ew a_ldrx r 31 k 0 0 1777 end 1778 end 1779 1780 note ---- branch fixups: a label below a_tlab is a block index, a_tlab + c the trap stub of code c. a_tlab is 2^32, 1781 note above every block index (it was 1000, which a function of 1000 blocks or more reached: the block index was read 1782 note as a trap code, and 1064 and up shifted by 64, trap 7; found by c2-00308's 513 nested ifs). Every trap branch 1783 note names its stub as add a_tlab c: ten sites (traps 1, 3, 5 and 6, the prologue's stack check among them) still 1784 note passed the literal 1000 + c after the change, read as block 1000 + c (b.cc 0, stub never marked) ---- 1785 const a_tlab ulong `4294967296` 1786 note prologue: sub sp; cmp sp, x28; b.lo trap 6 (before the first store: no write below the floor); saves 1787 fn a6_pro to void 1788 f = get a_fs 7 1789 if eq f 0 1790 ret 1791 end 1792 a6_spadj true f 1793 a6_ew a_subsxe 31 31 28 3 0 1794 a6_fx a_bcond 3 add a_tlab 6 1795 a6_saves true 1796 end 1797 1798 fn a6_epi to void 1799 f = get a_fs 7 1800 if ne f 0 1801 a6_saves false 1802 a6_spadj false f 1803 end 1804 a6_ew a_ret 30 0 0 0 0 1805 end 1806 1807 note a6_spadj s f: SP = SP - f (s) or SP + f, f < 2^24, as #hi, LSL 12 and #lo 1808 fn a6_spadj s bool f ulong to void 1809 h = shr f 12 1810 l = and f 4095 1811 if s 1812 if ne h 0 1813 a6_ew a_subxi 31 31 h 1 0 1814 end 1815 if ne l 0 1816 a6_ew a_subxi 31 31 l 0 0 1817 end 1818 ret 1819 end 1820 if ne h 0 1821 a6_ew a_addxi 31 31 h 1 0 1822 end 1823 if ne l 0 1824 a6_ew a_addxi 31 31 l 0 0 1825 end 1826 end 1827 1828 fn a6_fx f ulong a ulong l ulong to void 1829 if ne get a_fs 16 0 1830 if and ge f a_bcond le f 109 1831 if eq f a_bcond 1832 a6_ew f xor a 1 2 0 0 0 1833 else 1834 a6_ew xor f 1 a 2 0 0 0 1835 end 1836 f = a_b 1837 a = 0 1838 end 1839 end 1840 n = get a_fs 12 1841 if ne ar_need 30 n 0 1842 ar_die 1843 end 1844 put ar_m add get ar_rb 108 n get a_cn 0 1845 put ar_m add get ar_rb 109 n f 1846 put ar_m add get ar_rb 110 n a 1847 put ar_m add get ar_rb 111 n l 1848 put a_fs 12 add n 1 1849 if ge l a_tlab 1850 put a_fs 10 or get a_fs 10 shl ulong 1 sub l a_tlab 1851 end 1852 a6_emitw 0 1853 end 1854 1855 note distance in words from pc to t, two's complement 1856 fn a6_wd pc ulong t ulong to ulong 1857 if ge t pc 1858 ret div sub t pc 4 1859 end 1860 ret sub 0 div sub pc t 4 1861 end 1862 1863 fn a6_putw pc ulong w ulong to void 1864 ar_bp 107 pc uchar and w 255 1865 ar_bp 107 add pc 1 uchar and shr w 8 255 1866 ar_bp 107 add pc 2 uchar and shr w 16 255 1867 ar_bp 107 add pc 3 uchar and shr w 24 255 1868 end 1869 1870 note fixup i is a_xpc .. a_xl (regions 108..111) at index i; every fixup emits at least one code word below the 1871 note 2^27-byte reach (a6_emitw), so a function has at most 2^25 of them: the bound below is that reach, not a capacity 1872 fn a6_fixb to void 1873 i = ulong 0 1874 while lt i get a_fs 12 bound `33554433` 1875 l = get ar_m add get ar_rb 111 i 1876 t = ulong 0 1877 if ge l a_tlab 1878 t = get a_tpc sub l a_tlab 1879 else 1880 t = get a_bpc l 1881 end 1882 a6_fix1 i t 1883 i = add i 1 1884 end 1885 end 1886 1887 fn a6_fix1 i ulong t ulong to void 1888 pc = get ar_m add get ar_rb 108 i 1889 f = get ar_m add get ar_rb 109 i 1890 d = a6_wd pc t 1891 if or eq f 110 eq f 111 1892 a = get ar_m add get ar_rb 110 i 1893 if and ge d 8192 lt d sub ulong 0 8192 1894 put a_fs 16 1 1895 ret 1896 end 1897 a6_putw pc a6_enc f and a 31 shr a 5 d 0 0 1898 ret 1899 end 1900 if eq f a_b 1901 a6_putw pc a6_enc f d 0 0 0 0 1902 else 1903 if and ge d 262144 lt d sub ulong 0 262144 1904 put a_fs 16 1 1905 ret 1906 end 1907 a6_putw pc a6_enc f ar_w 110 i d 0 0 0 1908 end 1909 end 1910 1911 note a6_exit: the exit call, status in x0: Linux exit (mov x8, #93; svc #0), or for Mach-O Darwin exit 1912 note (mov x16, #1; svc #0x80) 1913 fn a6_exit to void 1914 if eq get a_tgt 0 1 1915 a6_ew a_movzx 16 1 0 0 0 1916 a6_ew a_svc 128 0 0 0 0 1917 ret 1918 end 1919 a6_ew a_movzx 8 93 0 0 0 1920 a6_ew a_svc 0 0 0 0 0 1921 end 1922 1923 note trap tail (omc's: add x0, x1, #100; mov x8, #93; svc #0) and one stub per used code: mov x1, #c; b tail 1924 fn a6_tstubs to void 1925 m = get a_fs 10 1926 if eq m 0 1927 ret 1928 end 1929 t = get a_cn 0 1930 a6_ew a_addxi 0 1 100 0 0 1931 a6_exit 1932 c = ulong 1 1933 while lt c 15 bound 14 1934 if ne and shr m c 1 0 1935 put a_tpc c get a_cn 0 1936 a6_ew a_movzx 1 c 0 0 0 1937 a6_ew a_b a6_wd get a_cn 0 t 0 0 0 0 1938 end 1939 c = add c 1 1940 end 1941 end 1942 1943 note ---- values in registers: operands, results, constants, canonical extension ---- 1944 note a6_src v s: a register holding value v (its own, or scratch s loaded from its slot) 1945 fn a6_src v ulong s ulong to ulong 1946 w = a6_wi v 1947 r = ulong uchar get ar_m add get ar_rb 95 w 1948 if lt r 32 1949 ret r 1950 end 1951 a6_ew a_ldrx s 31 sub get ar_m add get ar_rb 96 w 1 0 0 1952 ret s 1953 end 1954 1955 fn a6_dst v ulong to ulong 1956 r = ulong uchar get ar_m add get ar_rb 95 a6_wi v 1957 if lt r 32 1958 ret r 1959 end 1960 ret 16 1961 end 1962 1963 fn a6_fin v ulong r ulong to void 1964 w = a6_wi v 1965 if ge ulong uchar get ar_m add get ar_rb 95 w 32 1966 a6_ew a_strx r 31 sub get ar_m add get ar_rb 96 w 1 0 0 1967 end 1968 end 1969 1970 note move location of value v: its register (x0..x30, or 32 + V for a float), or 64 + its slot 1971 fn a6_loc v ulong to ulong 1972 ret a6_wloc a6_wi v 1973 end 1974 1975 fn a6_wloc w ulong to ulong 1976 r = ulong uchar get ar_m add get ar_rb 95 w 1977 if eq uchar get ar_m add get ar_rb 99 w 2 1978 if lt r 64 1979 ret add 568 r 1980 end 1981 ret add 700 shr sub get ar_m add get ar_rb 96 w 1 1 1982 end 1983 if lt r 64 1984 ret r 1985 end 1986 ret add 64 sub get ar_m add get ar_rb 96 w 1 1987 end 1988 1989 note ---- SLICE values (IR.md s4.2 kind 5): two wires. The value's own wire holds the address of element 0; its length 1990 note wire (a6_shw: same interval, allocated like any wire) holds the element count. Every move of a slice moves both: 1991 note block arguments (a6_mvv), call arguments and parameters (two machine argument positions, a6_xv) ---- 1992 fn a6_issl v ulong to bool 1993 ret eq get i_tk a6_vty v 5 1994 end 1995 1996 fn a6_lw v ulong to ulong 1997 ret sub get ar_m add get ar_rb 98 a6_wi v 1 1998 end 1999 2000 note a6_lsrc v s: a register holding slice v's element count (its length wire's own, or scratch s loaded from its slot) 2001 fn a6_lsrc v ulong s ulong to ulong 2002 l = a6_wloc a6_lw v 2003 if lt l 32 2004 ret l 2005 end 2006 a6_ew a_ldrx s 31 sub l 64 0 0 2007 ret s 2008 end 2009 2010 note a6_mvv d s: value d = value s in the pending parallel move (both wires of a slice) 2011 fn a6_mvv d ulong s ulong to void 2012 a6_mvadd a6_loc d a6_loc s 2013 if a6_issl d 2014 a6_mvadd a6_wloc a6_lw d a6_wloc a6_lw s 2015 end 2016 end 2017 2018 note a6_xv v: append v's machine arguments (one location, two for a slice) to a_mal 2019 fn a6_xv v ulong to void 2020 n = get a_man 0 2021 if ge add n 2 len a_mal 2022 a6_unsup n 2023 end 2024 put a_mal n a6_loc v 2025 put a_mac n 0 2026 if a6_isfv v 2027 put a_mac n 1 2028 end 2029 if a6_isvv v 2030 put a_mac n 2 2031 end 2032 n = add n 1 2033 if a6_issl v 2034 put a_mal n a6_wloc a6_lw v 2035 put a_mac n 0 2036 n = add n 1 2037 end 2038 put a_man 0 n 2039 end 2040 2041 note a6_xcall o: the locations of call o's machine arguments in a_mal; their count 2042 fn a6_xcall o ulong to ulong 2043 put a_man 0 0 2044 n = sub ulong get i_ona o 2 2045 k = ulong 0 2046 while lt k n bound 65 2047 a6_xv a6_arg o add k 2 2048 k = add k 1 2049 end 2050 ret get a_man 0 2051 end 2052 2053 note a6_xpar f: the locations of f's machine parameters in a_mal; their count 2054 fn a6_xpar f ulong to ulong 2055 put a_man 0 0 2056 p = ulong get i_fp1 f 2057 while ne p 0 bound 65 2058 a6_xv p 2059 p = ulong get i_vnx p 2060 end 2061 ret get a_man 0 2062 end 2063 2064 note a6_abi n: the ABI place of each of the n machine arguments in a_mal (scalar AAPCS64): integer, reference and 2065 note length wires take x0..x7 in order, f32/f64 values v0..v7 in order (a_mac), and the rest the outgoing slots 0.. in 2066 note argument order; a_mab[k] is the register location, or 1000 + the slot. Returns the number of slots 2067 fn a6_abi n ulong to ulong 2068 ki = ulong 0 2069 kf = ulong 0 2070 ks = ulong 0 2071 k = ulong 0 2072 while lt k n bound 137 2073 c = ulong get a_mac k 2074 if eq c 2 2075 if lt kf 8 2076 put a_mab k add 600 kf 2077 kf = add kf 1 2078 else 2079 ks = and add ks 1 not ulong 1 2080 put a_mab k add 3000 ks 2081 ks = add ks 2 2082 end 2083 else 2084 if ne c 0 2085 if lt kf 8 2086 put a_mab k add 32 kf 2087 kf = add kf 1 2088 else 2089 put a_mab k add 1000 ks 2090 ks = add ks 1 2091 end 2092 else 2093 if lt ki 8 2094 put a_mab k ki 2095 ki = add ki 1 2096 else 2097 put a_mab k add 1000 ks 2098 ks = add ks 1 2099 end 2100 end 2101 end 2102 k = add k 1 2103 end 2104 ret ks 2105 end 2106 2107 note a6_xstk o: the outgoing slots call o needs (before allocation: a6_outm sizes the frame with it): its integer, 2108 note scalar float and 16-byte vector arguments past eight in argument order 2109 fn a6_xstk o ulong to ulong 2110 n = sub ulong get i_ona o 2 2111 ki = ulong 0 2112 kf = ulong 0 2113 ks = ulong 0 2114 k = ulong 0 2115 while lt k n bound 65 2116 v = a6_arg o add k 2 2117 if a6_isvv v 2118 if lt kf 8 2119 kf = add kf 1 2120 else 2121 ks = and add ks 1 not ulong 1 2122 ks = add ks 2 2123 end 2124 else 2125 if a6_isfv v 2126 if lt kf 8 2127 kf = add kf 1 2128 else 2129 ks = add ks 1 2130 end 2131 else 2132 w = ulong 1 2133 if a6_issl v 2134 w = 2 2135 end 2136 while gt w 0 bound 2 2137 if lt ki 8 2138 ki = add ki 1 2139 else 2140 ks = add ks 1 2141 end 2142 w = sub w 1 2143 end 2144 end 2145 end 2146 k = add k 1 2147 end 2148 ret ks 2149 end 2150 2151 note a6_shw: one length wire per slice value, with the value's interval (after a6_ivlive) 2152 fn a6_shw to void 2153 n = get a_fs 0 2154 w = ulong 0 2155 while lt w n bound `16777217` 2156 put ar_m add get ar_rb 98 w 0 2157 w = add w 1 2158 end 2159 w = ulong 0 2160 while lt w n bound `16777217` 2161 if a6_wsl get ar_m add get ar_rb 91 w 2162 m = get a_fs 0 2163 if ne ar_need 26 m 0 2164 ar_die 2165 end 2166 put ar_m add get ar_rb 98 w add m 1 2167 put ar_m add get ar_rb 91 m 0 2168 put ar_m add get ar_rb 96 m 0 2169 ar_pc 94 m 0 2170 ar_pc 99 m 0 2171 ar_pc 95 m 255 2172 put ar_m add get ar_rb 92 m get ar_m add get ar_rb 92 w 2173 put ar_m add get ar_rb 93 m get ar_m add get ar_rb 93 w 2174 put a_fs 0 add m 1 2175 end 2176 w = add w 1 2177 end 2178 end 2179 2180 fn a6_wsl v ulong to bool 2181 if eq v 0 2182 ret false 2183 end 2184 if a6_istk v 2185 ret false 2186 end 2187 ret a6_issl v 2188 end 2189 2190 fn a6_movi r ulong v ulong to void 2191 if lt v 65536 2192 a6_ew a_movzx r v 0 0 0 2193 ret 2194 end 2195 if lt not v 65536 2196 a6_ew a_movnx r not v 0 0 0 2197 ret 2198 end 2199 first = true 2200 h = ulong 0 2201 while lt h 4 bound 4 2202 c = and shr v mul h 16 65535 2203 if ne c 0 2204 if first 2205 a6_ew a_movzx r c h 0 0 2206 first = false 2207 else 2208 a6_ew a_movkx r c h 0 0 2209 end 2210 end 2211 h = add h 1 2212 end 2213 end 2214 2215 note a6_canon r t: re-extend register r to type t (zero for u8..u32, sign for i8..i32) 2216 fn a6_canon r ulong t ulong to void 2217 w = a6_wid t 2218 if or ge w 64 le w 1 2219 ret 2220 end 2221 if a6_sgn t 2222 a6_ew a_sbfmx r r 0 sub w 1 0 2223 else 2224 a6_ew a_ubfmx r r 0 sub w 1 0 2225 end 2226 end 2227 2228 fn a6_mov d ulong s ulong to void 2229 if ne d s 2230 a6_ew a_orrx d 31 s 0 0 2231 end 2232 end 2233 2234 note ---- parallel moves (block arguments, call arguments, entry parameters); x15 breaks a cycle ---- 2235 fn a6_mvclr to void 2236 put a_mvn 0 0 2237 end 2238 2239 fn a6_mvadd d ulong s ulong to void 2240 n = get a_mvn 0 2241 if ge n len a_mvd 2242 a6_unsup n 2243 end 2244 if ne d s 2245 put a_mvd n d 2246 put a_mvs n s 2247 put a_mvn 0 add n 1 2248 end 2249 end 2250 2251 fn a6_isvq l ulong to bool 2252 ret and ge l 600 lt l 632 2253 end 2254 2255 fn a6_mvq d ulong s ulong to void 2256 if and a6_isvq d a6_isvq s 2257 if ne d s 2258 a6_ew a_orr16b sub d 600 sub s 600 sub s 600 0 0 2259 end 2260 ret 2261 end 2262 if a6_isvq d 2263 a6_ew a_ldrq sub d 600 31 sub s 700 0 0 2264 ret 2265 end 2266 if a6_isvq s 2267 a6_ew a_strq sub s 600 31 sub d 700 0 0 2268 ret 2269 end 2270 note v30, not v31: v31 is the parallel-move cycle breaker (location 631). A slot-to-slot 2271 note swap loads the breaker into v31, then this copy would clobber it and both slots get one value. 2272 a6_ew a_ldrq 30 31 sub s 700 0 0 2273 a6_ew a_strq 30 31 sub d 700 0 0 2274 end 2275 2276 fn a6_mv1 d ulong s ulong to void 2277 if or ge d 600 ge s 600 2278 a6_mvq d s 2279 ret 2280 end 2281 if and lt d 32 lt s 32 2282 a6_mov d s 2283 ret 2284 end 2285 if or a6_isvl d a6_isvl s 2286 a6_mvf d s 2287 ret 2288 end 2289 if lt d 32 2290 a6_ew a_ldrx d 31 sub s 64 0 0 2291 ret 2292 end 2293 if lt s 32 2294 a6_ew a_strx s 31 sub d 64 0 0 2295 ret 2296 end 2297 a6_ew a_ldrx 16 31 sub s 64 0 0 2298 a6_ew a_strx 16 31 sub d 64 0 0 2299 end 2300 2301 note a6_isvl l: move location l is a V register (32 + V) 2302 fn a6_isvl l ulong to bool 2303 ret and ge l 32 lt l 64 2304 end 2305 2306 note a6_mvf d s: a move with a V register on one side, bit for bit (an f32 rides in the low 32 bits of the D view): 2307 note FMOV D, D; FMOV D, X or X, D (raw bits, never a numeric conversion); LDR D or STR D for a stack slot 2308 fn a6_mvf d ulong s ulong to void 2309 if and a6_isvl d a6_isvl s 2310 if ne d s 2311 a6_ew a_fmovd sub d 32 sub s 32 0 0 0 2312 end 2313 ret 2314 end 2315 if a6_isvl d 2316 if lt s 32 2317 a6_ew a_fmovdx sub d 32 s 0 0 0 2318 else 2319 a6_ew a_ldrd sub d 32 31 sub s 64 0 0 2320 end 2321 ret 2322 end 2323 if lt d 32 2324 a6_ew a_fmovxd d sub s 32 0 0 0 2325 else 2326 a6_ew a_strd sub s 32 31 sub d 64 0 0 2327 end 2328 end 2329 2330 note a6_isrc l: some pending move reads location l 2331 fn a6_isrc l ulong to bool 2332 i = ulong 0 2333 while lt i get a_mvn 0 bound 64 2334 if and ne get a_mvd i 999 eq get a_mvs i l 2335 ret true 2336 end 2337 i = add i 1 2338 end 2339 ret false 2340 end 2341 2342 fn a6_pmove to void 2343 left = get a_mvn 0 2344 while gt left 0 bound 4096 2345 prog = false 2346 i = ulong 0 2347 while lt i get a_mvn 0 bound 64 2348 d = get a_mvd i 2349 if ne d 999 2350 if not a6_isrc d 2351 a6_mv1 d get a_mvs i 2352 put a_mvd i 999 2353 left = sub left 1 2354 prog = true 2355 end 2356 end 2357 i = add i 1 2358 end 2359 if not prog 2360 a6_mvbrk 2361 end 2362 end 2363 end 2364 2365 fn a6_mvbrk to void 2366 i = ulong 0 2367 while eq get a_mvd i 999 bound 64 2368 i = add i 1 2369 end 2370 s = get a_mvs i 2371 t = ulong 15 2372 if ge s 600 2373 t = 631 2374 end 2375 a6_mv1 t s 2376 j = ulong 0 2377 while lt j get a_mvn 0 bound 64 2378 if and ne get a_mvd j 999 eq get a_mvs j s 2379 put a_mvs j t 2380 end 2381 j = add j 1 2382 end 2383 end 2384 2385 note ---- selection ---- 2386 fn a6_sel o ulong x ulong to void 2387 op = ulong get i_oop o 2388 r = ulong get i_ors o 2389 if ne r 0 2390 if and ne op 54 a6_issl r 2391 a6_unsup op 2392 end 2393 end 2394 note a compare-fused consumer (a_skip) is emitted at its compare, but still meets the refusal above (select of SLICE) 2395 if eq o get a_skip 0 2396 ret 2397 end 2398 if and ge op 111 le op 116 2399 a6_spool o op 2400 ret 2401 end 2402 if a6_isvo o op 2403 a6_svec o op 2404 ret 2405 end 2406 if a6_isfo o op 2407 a6_sflt o op 2408 ret 2409 end 2410 if eq op 1 2411 a6_sconst o 2412 ret 2413 end 2414 if and ge op 10 le op 19 2415 a6_sarith o op 2416 ret 2417 end 2418 if and ge op 20 le op 25 2419 a6_sshift o op 2420 ret 2421 end 2422 if and ge op 30 le op 35 2423 a6_scmp o op 2424 ret 2425 end 2426 if and ge op 2 le op 37 2427 a6_smisc o op 2428 ret 2429 end 2430 if and ge op 60 le op 66 2431 a6_sterm o op x 2432 ret 2433 end 2434 if and ge op 70 le op 82 2435 a6_schk o op 2436 ret 2437 end 2438 if and ge op 42 le op 59 2439 a6_smem o op 2440 ret 2441 end 2442 if eq op 110 2443 a6_shost o 2444 ret 2445 end 2446 if and ge op 90 le op 93 2447 ret 2448 end 2449 a6_unsup op 2450 end 2451 2452 note ---- memory (IR.md s7.5): a REF is the address of its object in one register, a SLICE its address and count wires; 2453 note only REF to ARRAY or SLICE of bool or integers, and only these ops: load, store, alloca, gaddr, len, slice, fill. 2454 note Coverage (s8) is ngcheck's: an access here follows the check that covers it ---- 2455 fn a6_smem o ulong op ulong to void 2456 if eq op 42 2457 a6_sload o 2458 ret 2459 end 2460 if eq op 43 2461 a6_sstore o 2462 ret 2463 end 2464 if eq op 50 2465 a6_salloc o 2466 ret 2467 end 2468 r = ulong get i_ors o 2469 d = a6_dst r 2470 if eq op 52 2471 a6_movi d get ar_m add get ar_rb 90 get i_oim o 2472 if eq get a_tgt 0 1 2473 if eq ar_c 88 get i_oim o 1 2474 a6_ew a_subx d 28 d 0 0 2475 else 2476 a6_ew a_addx d 28 d 0 0 2477 end 2478 end 2479 a6_fin r d 2480 ret 2481 end 2482 if eq op 53 2483 if a6_issl a6_arg o 0 2484 a6_mov d a6_lsrc a6_arg o 0 17 2485 else 2486 a6_movi d a6_alen a6_arg o 0 2487 end 2488 a6_fin r d 2489 ret 2490 end 2491 if eq op 54 2492 a6_sslc o 2493 ret 2494 end 2495 if eq op 51 2496 a6_sfill o 2497 ret 2498 end 2499 a6_unsup op 2500 end 2501 2502 note fill tok r v (op 51; DESIGN.md section 10): every element of r (a REF to an ARRAY, count from the type, or a 2503 note SLICE, count from its length wire) = v, for bool, integer, f32 and f64 elements. x17 = v's raw bits repeated to 2504 note 64 bits (a6_fpat); v31 = DUP x17 (16 bytes); x15 = the byte count (count << log2 size: a REF's is a constant, a 2505 note slice's count times its element size fits its one storage object); the base stays in its register. From the end 2506 note down: 16-byte blocks (STR Q31, [base, x15]) while 16 or more bytes remain, then an 8, 4, 2 and 1-byte tail, each 2507 note when that bit of the remaining count is set; tails narrower than the element are never needed and not emitted. 2508 note Each store starts a whole number of elements past the base, so the pattern lines up with the elements whatever 2509 note the base's alignment; a count of 0 stores nothing; no byte outside the span is written and nothing is read 2510 fn a6_sfill o ulong to void 2511 v = a6_arg o 2 2512 t = a6_vty v 2513 if not a6_iselt t 2514 a6_unsup t 2515 end 2516 a = a6_arg o 1 2517 a6_aref a 2518 sz = a6_lsz t 2519 b = a6_src a 16 2520 if a6_isfv v 2521 x = a6_fsrc v 31 2522 a6_ew a6_ff t a_fmovxd a_fmovws 17 x 0 0 0 2523 else 2524 x = a6_src v 17 2525 a6_fmask x sz 2526 end 2527 a6_fpat sz 2528 if a6_issl a 2529 c = a6_lsrc a 15 2530 a6_ew a_addx 15 31 c 0 sz 2531 else 2532 a6_movi 15 shl a6_alen a sz 2533 end 2534 a6_ew a_dup2d 31 17 0 0 0 2535 a6_ew a_subsxi 31 15 16 0 0 2536 a6_ew a_bcond 3 4 0 0 0 2537 a6_ew a_subxi 15 15 16 0 0 2538 a6_ew a_strqr 31 b 15 0 0 2539 a6_ew a_b sub ulong 0 4 0 0 0 0 2540 a6_ew a_tbz 15 3 3 0 0 2541 a6_ew a_subxi 15 15 8 0 0 2542 a6_ew a_strxr 17 b 15 0 0 2543 if lt sz 3 2544 a6_ew a_tbz 15 2 3 0 0 2545 a6_ew a_subxi 15 15 4 0 0 2546 a6_ew a_strwr 17 b 15 0 0 2547 end 2548 if lt sz 2 2549 a6_ew a_tbz 15 1 3 0 0 2550 a6_ew a_subxi 15 15 2 0 0 2551 a6_ew a_strhr 17 b 15 0 0 2552 end 2553 if lt sz 1 2554 a6_ew a_tbz 15 0 3 0 0 2555 a6_ew a_subxi 15 15 1 0 0 2556 a6_ew a_strbr 17 b 15 0 0 2557 end 2558 end 2559 2560 note a6_fmask x sz: x17 = the low 8 << sz bits of integer register x (a signed value's canonical extension dropped) 2561 fn a6_fmask x ulong sz ulong to void 2562 if eq sz 3 2563 a6_mov 17 x 2564 ret 2565 end 2566 a6_ew a_andxi 17 x sub shl ulong 1 shl ulong 8 sz 1 0 0 2567 end 2568 2569 note a6_fpat sz: x17 (an element of 1 << sz bytes, zero above it) repeated to fill all 64 bits 2570 fn a6_fpat sz ulong to void 2571 if eq sz 0 2572 a6_ew a_orrx 17 17 17 0 8 2573 end 2574 if le sz 1 2575 a6_ew a_orrx 17 17 17 0 16 2576 end 2577 if le sz 2 2578 a6_ew a_orrx 17 17 17 0 32 2579 end 2580 end 2581 2582 note a6_alen v: the element count of the ARRAY that REF v refers to 2583 fn a6_alen v ulong to ulong 2584 t = a6_vty v 2585 if ne get i_tk t 4 2586 a6_unsup t 2587 end 2588 a = ulong get i_t1 t 2589 if ne get i_tk a 2 2590 a6_unsup a 2591 end 2592 e = ulong get i_t1 a 2593 if not a6_iselt e 2594 a6_unsup e 2595 end 2596 ret ulong get i_t2 a 2597 end 2598 2599 note load: LDR (register offset, scaled by the element size); the signed narrow types sign-extend (canonical form) 2600 fn a6_ldf t ulong to ulong 2601 if or eq t 1 eq t 2 2602 ret a_ldrbr 2603 end 2604 if eq t 6 2605 ret a_lsbx 2606 end 2607 if eq t 3 2608 ret a_ldrhr 2609 end 2610 if eq t 7 2611 ret a_lshx 2612 end 2613 if eq t 4 2614 ret a_ldrwr 2615 end 2616 if eq t 8 2617 ret a_lsw 2618 end 2619 ret a_ldrxr 2620 end 2621 2622 fn a6_stf t ulong to ulong 2623 if or eq t 1 or eq t 2 eq t 6 2624 ret a_strbr 2625 end 2626 if or eq t 3 eq t 7 2627 ret a_strhr 2628 end 2629 if or eq t 4 eq t 8 2630 ret a_strwr 2631 end 2632 ret a_strxr 2633 end 2634 2635 note the S bit of a register-offset access: 0 for one-byte elements, else scale the index by the size 2636 fn a6_sh1 t ulong to ulong 2637 if or eq t 1 eq a6_wid t 8 2638 ret 0 2639 end 2640 ret 1 2641 end 2642 2643 note a6_aref v: v is a REF to an ARRAY or a SLICE of bool, integer, f32 or f64 elements (refused otherwise) 2644 fn a6_aref v ulong to void 2645 if a6_issl v 2646 e = ulong get i_t1 a6_vty v 2647 if not a6_iselt e 2648 a6_unsup e 2649 end 2650 ret 2651 end 2652 n = a6_alen v 2653 end 2654 2655 note a6_iselt e: an element type of this slice's memory ops: bool, the integers, f32 and f64 2656 fn a6_iselt e ulong to bool 2657 ret or a6_isint e a6_isft e 2658 end 2659 2660 note a6_lsz t: log2 of the byte size of element type t (bool, the integers, f32 and f64) 2661 fn a6_lsz t ulong to ulong 2662 if eq t 13 2663 ret 2 2664 end 2665 if eq t 14 2666 ret 3 2667 end 2668 w = a6_wid t 2669 if le w 8 2670 ret 0 2671 end 2672 if eq w 16 2673 ret 1 2674 end 2675 if eq w 32 2676 ret 2 2677 end 2678 ret 3 2679 end 2680 2681 note slice r off n: x16 = address of element off (b + off << log2 size), x15 = n (operands read before either result 2682 note wire is written: both may reuse operand registers), then the value's wire and its length wire 2683 fn a6_sslc o ulong to void 2684 r = ulong get i_ors o 2685 e = ulong get i_t1 a6_vty r 2686 if not a6_iselt e 2687 a6_unsup e 2688 end 2689 a6_aref a6_arg o 1 2690 b = a6_src a6_arg o 1 16 2691 f = a6_src a6_arg o 2 17 2692 a6_ew a_addx 16 b f 0 a6_lsz e 2693 n = a6_src a6_arg o 3 17 2694 a6_mov 15 n 2695 d = a6_dst r 2696 if ne d 16 2697 a6_mov d 16 2698 end 2699 a6_fin r d 2700 l = a6_wloc a6_lw r 2701 if lt l 32 2702 a6_mov l 15 2703 else 2704 a6_ew a_strx 15 31 sub l 64 0 0 2705 end 2706 end 2707 2708 fn a6_sload o ulong to void 2709 t = a6_rty o 2710 a6_aref a6_arg o 1 2711 b = a6_src a6_arg o 1 16 2712 i = a6_src a6_arg o 2 17 2713 r = ulong get i_ors o 2714 d = a6_dst r 2715 a6_ew a6_ldf t d b i a6_sh1 t 0 2716 a6_fin r d 2717 end 2718 2719 fn a6_sstore o ulong to void 2720 v = a6_arg o 3 2721 t = a6_vty v 2722 if not a6_isint t 2723 a6_unsup t 2724 end 2725 a6_aref a6_arg o 1 2726 b = a6_src a6_arg o 1 16 2727 i = a6_src a6_arg o 2 17 2728 x = a6_src v 15 2729 a6_ew a6_stf t x b i a6_sh1 t 0 2730 end 2731 2732 note alloca: the address of the op's frame area, then zero it 16 bytes per STP XZR, XZR (every logical invocation: 2733 note the op runs on each pass of an E loop as well) 2734 fn a6_salloc o ulong to void 2735 k = ulong 0 2736 while ne get a_alo k o bound 64 2737 k = add k 1 2738 end 2739 f = get a_aof k 2740 r = ulong get i_ors o 2741 d = a6_dst r 2742 h = shr f 12 2743 b = ulong 31 2744 if ne h 0 2745 a6_ew a_addxi d 31 h 1 0 2746 b = d 2747 end 2748 a6_ew a_addxi d b and f 4095 0 0 2749 a6_fin r d 2750 a6_mov 16 d 2751 a6_movi 17 shr get a_asz k 4 2752 a6_ew a_stpxpo 31 31 16 16 0 2753 a6_ew a_subsxi 17 17 1 0 0 2754 a6_ew a_bcond 1 sub ulong 0 2 0 0 0 2755 end 2756 2757 note ---- host words (IR.md s7.11): read 53 and write 54, as Linux SVC 63 and 64 (x0 fd, x1 address, x2 count, 2758 note x8 number; the kernel returns the count or minus errno in x0 and preserves every other register); cpufence 199 2759 note as DSB SY (`d5033f9f`) and cpurelax 200 as YIELD (`d503203f`), omc's words (omc.om cpufence/cpurelax notes); monons 2760 note 109 and realns 130 as omc's hclock (a6_hclk below) ---- 2761 fn a6_shost o ulong to void 2762 w = get i_oim o 2763 if or eq w 136 eq w 137 2764 a6_henv o w 2765 ret 2766 end 2767 if eq w 199 2768 a6_emitw 0xd5033f9f 2769 ret 2770 end 2771 if eq w 200 2772 a6_emitw 0xd503203f 2773 ret 2774 end 2775 if or eq w 109 eq w 130 2776 if eq get a_tgt 0 1 2777 a6_unsup w 2778 end 2779 a6_hclk o w 2780 ret 2781 end 2782 if and ge w 241 le w 243 2783 if ne get a_tgt 0 1 2784 a6_unsup w 2785 end 2786 a6_hlib o w 2787 ret 2788 end 2789 nr = ulong 64 2790 if eq w 53 2791 nr = 63 2792 end 2793 if and ne w 53 ne w 54 2794 a6_unsup w 2795 end 2796 a = a6_arg o 2 2797 a6_aref a 2798 b = a6_src a 16 2799 f = a6_src a6_arg o 3 17 2800 a6_ew a_addx 17 b f 0 0 2801 a6_mvclr 2802 a6_mvadd 0 a6_loc a6_arg o 1 2803 a6_mvadd 1 17 2804 a6_mvadd 2 a6_loc a6_arg o 4 2805 a6_pmove 2806 if eq get a_tgt 0 1 2807 a6_ew a_movzx 16 sub nr 60 0 0 0 2808 a6_ew a_svc 128 0 0 0 0 2809 a6_ew a_csnegx 0 0 0 3 0 2810 else 2811 a6_ew a_movzx 8 nr 0 0 0 2812 a6_ew a_svc 0 0 0 0 0 2813 end 2814 r = ulong get i_ors o 2815 if ne r 0 2816 a6_mvfrom r 0 2817 end 2818 end 2819 2820 note ---- calls into system libraries, Mach-O only (IR.md s7.11, DESIGN.md s13): libfn 241, libptr 242, libcall 243. 2821 note The link page is the 16 KiB below the stack floor x28: +0 dlopen and +8 dlsym (bound by dyld, a6_macho), +16 the 2822 note stack dyld entered on (start code). x16, x17 and x9 are scratch; a host word counts as a call for allocation, so 2823 note no live value sits in x0..x14 or a caller-saved V register here. 2824 note libfn k: 0 for k above 1, else the word at link page + 8k. MOV X0, #0; CMP X16, #2; B.HS +8; 2825 note LDR X0, [X17, X16, LSL #3]. 2826 note libptr A off n: the address of byte off of A (the slice is checked by its chk.slice). 2827 note libcall F A off n: A[off, off+n) is the register file, 128 bytes at least (fewer: trap 3; F = 0: trap 3): 2828 note x0..x7 at 0..63, d0..d7 at 64..127. Saves x19 and x20 on the Omega stack (floor checked, trap 6), keeps the 2829 note Omega sp in x19 and the file's address in x20, moves sp to the saved system stack, loads the sixteen registers, 2830 note BLR X16, stores x0, x1 back at 0 and d0..d3 at 64, and restores. The word's value is x0. 2831 fn a6_hlib o ulong w ulong to void 2832 if eq w 241 2833 k = a6_src a6_arg o 1 16 2834 a6_mov 16 k 2835 a6_emitw 0xd1401391 2836 a6_emitw 0xd2800000 2837 a6_emitw 0xf1000a1f 2838 a6_emitw 0x54000042 2839 a6_emitw 0xf8707a20 2840 note k 2..17 with a callback function: the address of entry k - 2, as a class-1 address (x28 less a constant): 2841 note SUB X17, X16, #2; x9 = x28 - (16 MiB - a_bks) + 8 * x17; CMP X17, #16; CSEL X0, X9, X0, LO 2842 if ne get a_bks 0 0 2843 a6_emitw 0xd1000a11 2844 a6_movi 9 sub `16777216` get a_bks 0 2845 a6_emitw 0xcb090389 2846 a6_emitw 0x8b110d29 2847 a6_emitw 0xf100423f 2848 a6_emitw 0x9a803120 2849 end 2850 end 2851 if eq w 242 2852 a = a6_arg o 1 2853 a6_aref a 2854 b = a6_src a 16 2855 f = a6_src a6_arg o 2 17 2856 a6_ew a_addx 17 b f 0 0 2857 a6_emitw 0xaa1103e0 2858 end 2859 if eq w 243 2860 a = a6_arg o 2 2861 a6_aref a 2862 b = a6_src a 16 2863 f = a6_src a6_arg o 3 17 2864 a6_ew a_addx 17 b f 0 0 2865 n = a6_src a6_arg o 4 16 2866 a6_ew a_subsxi 31 n 128 0 0 2867 a6_fx a_bcond 3 add a_tlab 3 2868 fr = a6_src a6_arg o 1 16 2869 a6_mov 16 fr 2870 a6_ew a_subsxi 31 16 0 0 0 2871 a6_fx a_bcond 0 add a_tlab 3 2872 a6_emitw 0xa9bf53f3 2873 a6_ew a_subsxe 31 31 28 3 0 2874 a6_fx a_bcond 3 add a_tlab 6 2875 a6_emitw 0x910003f3 2876 a6_emitw 0xaa1103f4 2877 a6_emitw 0xd1401389 2878 a6_emitw 0xf9000d33 2879 a6_emitw 0xf9400929 2880 a6_emitw 0x9100013f 2881 a6_emitw 0xa9400680 2882 a6_emitw 0xa9410e82 2883 a6_emitw 0xa9421684 2884 a6_emitw 0xa9431e86 2885 a6_emitw 0x6d440680 2886 a6_emitw 0x6d450e82 2887 a6_emitw 0x6d461684 2888 a6_emitw 0x6d471e86 2889 a6_emitw 0xd63f0200 2890 a6_emitw 0xa9000680 2891 a6_emitw 0x6d040680 2892 a6_emitw 0x6d050e82 2893 a6_emitw 0x9100027f 2894 a6_emitw 0xa8c153f3 2895 end 2896 r = ulong get i_ors o 2897 if ne r 0 2898 a6_mvfrom r 0 2899 end 2900 end 2901 2902 note monons 109 and realns 130 as omc's hclock: SVC 113 clock_gettime(CLOCK_MONOTONIC 1 / CLOCK_REALTIME 0) into a 2903 note 16-byte area below SP (stack floor checked, trap 6), result sec * 10^9 + nsec with omc's traps (sec above 2904 note `9223372036`: B.HI trap 1; the add: B.VS trap 1); a failed call returns x0 (minus errno). The area is zeroed first, 2905 note so a failed call reads 0 and 0 and cannot trap; CSEL LT then picks x0, which omc reaches by a branch. x0..x3, x8 2906 note are scratch (a host word counts as a call for allocation). 2907 fn a6_hclk o ulong w ulong to void 2908 ck = ulong 1 2909 if eq w 130 2910 ck = ulong 0 2911 end 2912 a6_ew a_subxi 31 31 16 0 0 2913 a6_ew a_subsxe 31 31 28 3 0 2914 a6_fx a_bcond 3 add a_tlab 6 2915 a6_ew a_stpx 31 31 31 0 0 2916 a6_ew a_movzx 0 ck 0 0 0 2917 a6_ew a_addxi 1 31 0 0 0 2918 a6_ew a_movzx 8 113 0 0 0 2919 a6_ew a_svc 0 0 0 0 0 2920 a6_ew a_ldrx 1 31 0 0 0 2921 a6_ew a_ldrx 2 31 1 0 0 2922 a6_movi 3 `9223372036` 2923 a6_ew a_subsx 31 1 3 0 0 2924 a6_fx a_bcond 8 add a_tlab 1 2925 a6_movi 3 `1000000000` 2926 a6_ew a_mulx 1 1 3 0 0 2927 a6_ew a_addsx 2 1 2 0 0 2928 a6_fx a_bcond 6 add a_tlab 1 2929 a6_ew a_subsxi 31 0 0 0 0 2930 a6_ew a_cselx 0 0 2 11 0 2931 a6_ew a_addxi 31 31 16 0 0 2932 r = ulong get i_ors o 2933 if ne r 0 2934 a6_mvfrom r 0 2935 end 2936 end 2937 2938 fn a6_rty o ulong to ulong 2939 t = ulong get i_oty o 2940 if not a6_isint t 2941 a6_unsup t 2942 end 2943 ret t 2944 end 2945 2946 fn a6_sconst o ulong to void 2947 r = ulong get i_ors o 2948 t = a6_rty o 2949 d = a6_dst r 2950 a6_movi d get i_oim o 2951 a6_fin r d 2952 end 2953 2954 note result of an op whose operands are already in registers a, b: computed into d, extended, stored 2955 fn a6_sarith o ulong op ulong to void 2956 r = ulong get i_ors o 2957 t = a6_rty o 2958 a = a6_src a6_arg o 0 16 2959 b = ulong 31 2960 if and ne op 15 ne op 19 2961 b = a6_src a6_arg o 1 17 2962 end 2963 d = a6_dst r 2964 a6_ar2 op t d a b 2965 a6_canon d t 2966 a6_fin r d 2967 end 2968 2969 fn a6_ar2 op ulong t ulong d ulong a ulong b ulong to void 2970 if eq op 10 2971 a6_ew a_addx d a b 0 0 2972 end 2973 if eq op 11 2974 a6_ew a_subx d a b 0 0 2975 end 2976 if eq op 12 2977 a6_ew a_mulx d a b 0 0 2978 end 2979 if eq op 13 2980 a6_div d a b t 2981 end 2982 if eq op 14 2983 a6_rem d a b t 2984 end 2985 if eq op 15 2986 a6_ew a_subx d 31 a 0 0 2987 end 2988 if eq op 16 2989 a6_ew a_andx d a b 0 0 2990 end 2991 if eq op 17 2992 a6_ew a_orrx d a b 0 0 2993 end 2994 if eq op 18 2995 a6_ew a_eorx d a b 0 0 2996 end 2997 if eq op 19 2998 a6_not d a t 2999 end 3000 end 3001 3002 fn a6_not d ulong a ulong t ulong to void 3003 if eq t 1 3004 a6_ew a_eorxi d a 1 0 0 3005 else 3006 a6_ew a_ornx d 31 a 0 0 3007 end 3008 end 3009 3010 fn a6_div d ulong a ulong b ulong t ulong to void 3011 if a6_sgn t 3012 a6_ew a_sdivx d a b 0 0 3013 else 3014 a6_ew a_udivx d a b 0 0 3015 end 3016 end 3017 3018 note rem: a - (a / b) * b, and 0 when b = 0 (IR.md s7.3); the flags are set before d may overwrite a or b 3019 fn a6_rem d ulong a ulong b ulong t ulong to void 3020 a6_div 15 a b t 3021 a6_ew a_subsxi 31 b 0 0 0 3022 a6_ew a_msubx d 15 b a 0 3023 a6_ew a_cselx d 31 d 0 0 3024 end 3025 3026 note shl shr rotl rotr (amount modulo the width) and min max 3027 fn a6_sshift o ulong op ulong to void 3028 r = ulong get i_ors o 3029 t = a6_rty o 3030 a = a6_src a6_arg o 0 16 3031 b = a6_src a6_arg o 1 17 3032 d = a6_dst r 3033 if ge op 24 3034 a6_ew a_subsx 31 a b 0 0 3035 a6_ew a_cselx d a b a6_mmc op t 0 3036 else 3037 a6_sh2 op t d a b 3038 end 3039 a6_canon d t 3040 a6_fin r d 3041 end 3042 3043 note condition for min (24) / max (25): a selected when a < b / a > b 3044 fn a6_mmc op ulong t ulong to ulong 3045 s = a6_sgn t 3046 if eq op 24 3047 if s 3048 ret 11 3049 end 3050 ret 3 3051 end 3052 if s 3053 ret 12 3054 end 3055 ret 8 3056 end 3057 3058 fn a6_sh2 op ulong t ulong d ulong a ulong b ulong to void 3059 w = a6_wid t 3060 if ge op 22 3061 a6_rot op t d a b 3062 ret 3063 end 3064 if and lt w 32 gt w 1 3065 a6_ew a_andxi 15 b sub w 1 0 0 3066 b = 15 3067 end 3068 if eq w 32 3069 a6_sh32 op t d a b 3070 ret 3071 end 3072 if eq op 20 3073 a6_ew a_lslvx d a b 0 0 3074 ret 3075 end 3076 if a6_sgn t 3077 a6_ew a_asrvx d a b 0 0 3078 else 3079 a6_ew a_lsrvx d a b 0 0 3080 end 3081 end 3082 3083 fn a6_sh32 op ulong t ulong d ulong a ulong b ulong to void 3084 if eq op 20 3085 a6_ew a_lslvw d a b 0 0 3086 ret 3087 end 3088 if a6_sgn t 3089 a6_ew a_asrvw d a b 0 0 3090 else 3091 a6_ew a_lsrvw d a b 0 0 3092 end 3093 end 3094 3095 note rotl = rotr by the negated amount (RORV takes it modulo the width). u8 and u16 (zero-extended) are copied across 3096 note the low 32 bits in x16 (ORR x16, a, a, LSL w, and again by 16 for u8) and rotated as 32 bits: w divides 32 and 3097 note the copy repeats every w bits, so the low w bits are the w-bit rotation by the amount modulo w; the caller 3098 note re-extends d (a6_canon). x16 holds only a's spill reload and b is never in x16, so the copy clobbers nothing. 3099 fn a6_rot op ulong t ulong d ulong a ulong b ulong to void 3100 w = a6_wid t 3101 if a6_sgn t 3102 a6_unsup t 3103 end 3104 if lt w 8 3105 a6_unsup t 3106 end 3107 n = b 3108 if eq op 22 3109 a6_ew a_subx 15 31 b 0 0 3110 n = 15 3111 end 3112 if eq w 64 3113 a6_ew a_rorvx d a n 0 0 3114 ret 3115 end 3116 s = a 3117 if lt w 32 3118 a6_ew a_orrx 16 a a 0 w 3119 if eq w 8 3120 a6_ew a_orrx 16 16 16 0 16 3121 end 3122 s = 16 3123 end 3124 a6_ew a_rorvw d s n 0 0 3125 end 3126 3127 note compare: cmp a, b; cset d, cond (cset = csinc d, xzr, xzr, inverted cond) 3128 fn a6_scmp o ulong op ulong to void 3129 r = ulong get i_ors o 3130 v = a6_arg o 0 3131 t = a6_vty v 3132 if not a6_isint t 3133 a6_unsup t 3134 end 3135 a = a6_src v 16 3136 b = a6_src a6_arg o 1 17 3137 d = a6_dst r 3138 n = a6_cuse o 3139 if ne n 0 3140 a6_cmpuse o n op t a b 3141 ret 3142 end 3143 a6_ew a_subsx 31 a b 0 0 3144 a6_ew a_csincx d 31 31 xor a6_cc op t 1 0 3145 a6_fin r d 3146 end 3147 3148 note Compare fusion is local: a sole, immediately following cbr/select consumer. Operand lifetimes therefore do 3149 note not change, no effect or flag-setting instruction moves, and a compare used elsewhere stays materialised. 3150 fn a6_ucnt to void 3151 w = ulong 0 3152 while lt w get a_fs 0 bound `16777217` 3153 ar_pu 100 w 0 3154 w = add w 1 3155 end 3156 x = ulong 0 3157 while lt x get a_fs 1 bound 65536 3158 o = ulong get i_bo1 get a_bh x 3159 while ne o 0 bound `4194305` 3160 k = ulong 0 3161 while lt k ulong get i_ona o bound `1048576` 3162 if eq ir_okd uint get i_oop o k 0 3163 v = a6_arg o k 3164 if not a6_istk v 3165 w = a6_wi v 3166 ar_pu 100 w add uint get ar_m add get ar_rb 100 w 1 3167 end 3168 end 3169 k = add k 1 3170 end 3171 o = ulong get i_onx o 3172 end 3173 x = add x 1 3174 end 3175 end 3176 fn a6_cuse o ulong to ulong 3177 r = ulong get i_ors o 3178 if ne uint get ar_m add get ar_rb 100 a6_wi r 1 3179 ret 0 3180 end 3181 n = ulong get i_onx o 3182 if eq n 0 3183 ret 0 3184 end 3185 op = get i_oop n 3186 if eq op 61 3187 if eq a6_arg n 1 r 3188 ret n 3189 end 3190 end 3191 if eq op 2 3192 if and eq a6_arg n 0 r and not a6_isfv ulong get i_ors n not a6_isvv ulong get i_ors n 3193 ret n 3194 end 3195 end 3196 ret 0 3197 end 3198 fn a6_czero v ulong to bool 3199 if ne get i_vk v 4 3200 ret false 3201 end 3202 o = get i_vo v 3203 ret and eq get i_oop o 1 eq get i_oim o 0 3204 end 3205 note A single-bit AND followed by eq/ne zero can test its result with TBZ/TBNZ, no CMP or boolean. 3206 fn a6_cbit v ulong to ulong 3207 if ne get i_vk v 4 3208 ret 64 3209 end 3210 o = ulong get i_vo v 3211 if ne get i_oop o 16 3212 ret 64 3213 end 3214 k = ulong 0 3215 while lt k 2 bound 2 3216 s = a6_arg o k 3217 if eq get i_vk s 4 3218 p = get i_vo s 3219 if eq get i_oop p 1 3220 m = get i_oim p 3221 j = ulong 0 3222 while lt j 64 bound 64 3223 if eq m shl ulong 1 j 3224 ret j 3225 end 3226 j = add j 1 3227 end 3228 end 3229 end 3230 k = add k 1 3231 end 3232 ret 64 3233 end 3234 fn a6_tbfx f ulong r ulong bit ulong l ulong to void 3235 if ne get a_fs 16 0 3236 a6_ew xor f 1 r bit 2 0 0 3237 a6_fx a_b 0 l 3238 else 3239 a6_fx f add r shl bit 5 l 3240 end 3241 end 3242 fn a6_cjump o ulong op ulong cc ulong a ulong b ulong l ulong to void 3243 zero = false 3244 if or eq op 30 eq op 31 3245 zero = a6_czero a6_arg o 1 3246 end 3247 if zero 3248 f = a_cbnzx 3249 if eq cc 0 3250 f = a_cbzx 3251 end 3252 bit = a6_cbit a6_arg o 0 3253 if lt bit 64 3254 f = 111 3255 if eq cc 0 3256 f = 110 3257 end 3258 a6_tbfx f a bit l 3259 else 3260 a6_fx f a l 3261 end 3262 else 3263 a6_ew a_subsx 31 a b 0 0 3264 a6_fx a_bcond cc l 3265 end 3266 end 3267 3268 fn a6_cmpuse o ulong n ulong op ulong t ulong a ulong b ulong to void 3269 put a_skip 0 n 3270 cc = a6_cc op t 3271 if eq get i_oop n 2 3272 a6_ew a_subsx 31 a b 0 0 3273 u = a6_src a6_arg n 1 17 3274 v = a6_src a6_arg n 2 15 3275 r = ulong get i_ors n 3276 d = a6_dst r 3277 a6_ew a_cselx d u v cc 0 3278 a6_fin r d 3279 ret 3280 end 3281 bt = a6_bix a6_arg n 2 3282 bf = a6_bix a6_arg n 3 3283 x = a6_bix ulong get i_ob n 3284 inv = eq bt add x 1 3285 l = bt 3286 if inv 3287 l = bf 3288 cc = xor cc 1 3289 end 3290 a6_cjump o op cc a b l 3291 if not inv 3292 if ne bf add x 1 3293 a6_fx a_b 0 bf 3294 end 3295 end 3296 end 3297 3298 fn a6_cc op ulong t ulong to ulong 3299 if eq op 30 3300 ret 0 3301 end 3302 if eq op 31 3303 ret 1 3304 end 3305 s = a6_sgn t 3306 if eq op 32 3307 if s 3308 ret 11 3309 end 3310 ret 3 3311 end 3312 if eq op 33 3313 if s 3314 ret 13 3315 end 3316 ret 9 3317 end 3318 if eq op 34 3319 if s 3320 ret 12 3321 end 3322 ret 8 3323 end 3324 if s 3325 ret 10 3326 end 3327 ret 2 3328 end 3329 3330 note select (2), conv (36, integer to integer), bitcast (37, integer to integer) 3331 fn a6_smisc o ulong op ulong to void 3332 r = ulong get i_ors o 3333 t = a6_rty o 3334 if eq op 2 3335 c = a6_src a6_arg o 0 16 3336 a = a6_src a6_arg o 1 17 3337 b = a6_src a6_arg o 2 15 3338 d = a6_dst r 3339 a6_ew a_subsxi 31 c 0 0 0 3340 a6_ew a_cselx d a b 1 0 3341 a6_fin r d 3342 ret 3343 end 3344 if or eq op 36 eq op 37 3345 v = a6_arg o 0 3346 if not a6_isint a6_vty v 3347 a6_unsup op 3348 end 3349 a = a6_src v 16 3350 d = a6_dst r 3351 a6_mov d a 3352 a6_canon d t 3353 a6_fin r d 3354 ret 3355 end 3356 a6_unsup op 3357 end 3358 3359 note ---- scalar floats (IR.md s7.2 to s7.5 and s7.9; DESIGN.md section 9): an f32/f64 value lives in a V register 3360 note (location 32 + V, a6_ffree) or a stack slot (8 bytes, LDR/STR D); an f32 uses the S view of its register. v29, 3361 note v30 and v31 are the float scratch (operands reloaded from slots, a result bound for a slot, chk.conv bounds). 3362 note FPCR is 0 (round to nearest even, no flush to zero, no default NaN) from _start on; a toward-zero conversion 3363 note sets RMode 11 for its one rounding instruction and writes 0 back right after it (a6_rz) ---- 3364 fn a6_isft t ulong to bool 3365 ret or eq t 13 eq t 14 3366 end 3367 3368 fn a6_isfv v ulong to bool 3369 ret a6_isft a6_vty v 3370 end 3371 3372 note a6_rloc v: the register location of a call result or retv operand v: d0 (location 32) for a float, else x0 3373 fn a6_rloc v ulong to ulong 3374 if a6_isvv v 3375 ret 600 3376 end 3377 if a6_isfv v 3378 ret a_d0 3379 end 3380 ret 0 3381 end 3382 3383 note a6_ff t fd fs: form fd for an f64 operation, fs for an f32 one 3384 fn a6_ff t ulong fd ulong fs ulong to ulong 3385 if eq t 14 3386 ret fd 3387 end 3388 ret fs 3389 end 3390 3391 note a6_fsrc v s: the V register holding float value v: its own, or scratch V s loaded from its slot (LDR D) 3392 fn a6_fsrc v ulong s ulong to ulong 3393 w = a6_wi v 3394 r = ulong uchar get ar_m add get ar_rb 95 w 3395 if a6_isvl r 3396 ret sub r 32 3397 end 3398 a6_ew a_ldrd s 31 sub get ar_m add get ar_rb 96 w 1 0 0 3399 ret s 3400 end 3401 3402 note a6_fdst v: the V register to compute float value v into: its own, or v31 when it lives in a slot (a6_ffin) 3403 fn a6_fdst v ulong to ulong 3404 r = ulong uchar get ar_m add get ar_rb 95 a6_wi v 3405 if a6_isvl r 3406 ret sub r 32 3407 end 3408 ret 31 3409 end 3410 3411 fn a6_ffin v ulong r ulong to void 3412 w = a6_wi v 3413 if ge ulong uchar get ar_m add get ar_rb 95 w 64 3414 a6_ew a_strd r 31 sub get ar_m add get ar_rb 96 w 1 0 0 3415 end 3416 end 3417 3418 note a6_isfo o op: op o is one of this slice's scalar float operations: a const, select, arithmetic, fma or load with 3419 note an f32/f64 result; a compare, conv or bitcast with an f32/f64 side; a store of an f32/f64; a chk.conv of one 3420 fn a6_isfo o ulong op ulong to bool 3421 r = ulong get i_ors o 3422 fr = false 3423 if ne r 0 3424 fr = a6_isfv r 3425 end 3426 if or eq op 1 eq op 2 3427 ret fr 3428 end 3429 if and ge op 10 le op 28 3430 ret fr 3431 end 3432 if or eq op 42 eq op 46 3433 ret fr 3434 end 3435 if and ge op 30 le op 37 3436 if fr 3437 ret true 3438 end 3439 ret a6_isfv a6_arg o 0 3440 end 3441 if eq op 43 3442 ret a6_isfv a6_arg o 3 3443 end 3444 if eq op 78 3445 ret a6_isfv a6_arg o 1 3446 end 3447 ret false 3448 end 3449 3450 fn a6_sflt o ulong op ulong to void 3451 r = ulong get i_ors o 3452 if eq op 1 3453 a6_fconst o r 3454 ret 3455 end 3456 if eq op 2 3457 a6_fpick o r 3458 ret 3459 end 3460 if or or eq op 10 eq op 11 or eq op 12 eq op 13 3461 a6_fbin o op r 3462 ret 3463 end 3464 if or eq op 24 eq op 25 3465 a6_fbin o op r 3466 ret 3467 end 3468 if or eq op 15 or eq op 26 eq op 27 3469 a6_fun o op r 3470 ret 3471 end 3472 if and ge op 30 le op 35 3473 a6_fcmp o op r 3474 ret 3475 end 3476 if eq op 36 3477 a6_fconv o r 3478 ret 3479 end 3480 if eq op 37 3481 a6_fbcast o r 3482 ret 3483 end 3484 if eq op 46 3485 a6_ffma o r 3486 ret 3487 end 3488 if eq op 42 3489 a6_fload o r 3490 ret 3491 end 3492 if eq op 43 3493 a6_fstore o 3494 ret 3495 end 3496 if eq op 78 3497 a6_fchk o 3498 ret 3499 end 3500 a6_unsup op 3501 end 3502 3503 note const: the raw bits into x16 (MOVZ/MOVN/MOVK), then FMOV D, X or S, W: the sign and every NaN payload bit kept 3504 fn a6_fconst o ulong r ulong to void 3505 t = ulong get i_oty o 3506 d = a6_fdst r 3507 a6_movi 16 get i_oim o 3508 a6_ew a6_ff t a_fmovdx a_fmovsw d 16 0 0 0 3509 a6_ffin r d 3510 end 3511 3512 note select of floats: CMP c, #0; FCSEL d, a, b, NE (the selected operand's raw bits) 3513 fn a6_fpick o ulong r ulong to void 3514 t = ulong get i_oty o 3515 c = a6_src a6_arg o 0 16 3516 a = a6_fsrc a6_arg o 1 29 3517 b = a6_fsrc a6_arg o 2 30 3518 d = a6_fdst r 3519 a6_ew a_subsxi 31 c 0 0 0 3520 a6_ew a6_ff t a_fcseld a_fcsels d a b 1 0 3521 a6_ffin r d 3522 end 3523 3524 note add sub mul div: FADD FSUB FMUL FDIV (one rounding each, never contracted); min max: FMINNM FMAXNM, the IR.md 3525 note s7.3 rule (one quiet NaN gives the other operand, a signaling NaN a quiet NaN, -0 below +0) 3526 fn a6_fbin o ulong op ulong r ulong to void 3527 t = ulong get i_oty o 3528 a = a6_fsrc a6_arg o 0 29 3529 b = a6_fsrc a6_arg o 1 30 3530 d = a6_fdst r 3531 fm = a6_ff t a_faddd a_fadds 3532 if le op 13 3533 fm = add fm sub op 10 3534 end 3535 if eq op 24 3536 fm = a6_ff t a_fminnmd a_fminnms 3537 end 3538 if eq op 25 3539 fm = a6_ff t a_fmaxnmd a_fmaxnms 3540 end 3541 a6_ew fm d a b 0 0 3542 a6_ffin r d 3543 end 3544 3545 note neg FNEG, fsqrt FSQRT, fabs FABS (FNEG and FABS change the sign bit only, NaNs included) 3546 fn a6_fun o ulong op ulong r ulong to void 3547 t = ulong get i_oty o 3548 a = a6_fsrc a6_arg o 0 29 3549 d = a6_fdst r 3550 fm = a6_ff t a_fnegd a_fnegs 3551 if eq op 26 3552 fm = a6_ff t a_fsqrtd a_fsqrts 3553 end 3554 if eq op 27 3555 fm = a6_ff t a_fabsd a_fabss 3556 end 3557 a6_ew fm d a 0 0 0 3558 a6_ffin r d 3559 end 3560 3561 note compare: FCMP a, b; CSET d, cond. Unordered sets C and V and clears N and Z, so EQ, MI (lt), LS (le), GT and GE 3562 note are false on it and NE true (IR.md s7.3); the integer LT and LE would be true there 3563 fn a6_fcmp o ulong op ulong r ulong to void 3564 v = a6_arg o 0 3565 t = a6_vty v 3566 a = a6_fsrc v 29 3567 b = a6_fsrc a6_arg o 1 30 3568 d = a6_dst r 3569 a6_ew a6_ff t a_fcmpd a_fcmps a b 0 0 0 3570 a6_ew a_csincx d 31 31 xor a6_fcc op 1 0 3571 a6_fin r d 3572 end 3573 3574 note a6_fcc op: the condition of float compare op 30..35 (eq EQ 0, ne NE 1, lt MI 4, le LS 9, gt GT 12, ge GE 10), 3575 note four bits per op from the low end 3576 fn a6_fcc op ulong to ulong 3577 ret and shr ulong 0xac9410 mul 4 sub op 30 15 3578 end 3579 3580 note a6_rz z on: toward-zero rounding around one instruction when z: FPCR = RMode 11 (0xc00000, through x15) before 3581 note it, FPCR = 0 (the program's environment) after it 3582 fn a6_rz z bool on bool to void 3583 if not z 3584 ret 3585 end 3586 if on 3587 a6_ew a_movzx 15 0xc0 1 0 0 3588 a6_ew a_msrfpcr 15 0 0 0 0 3589 else 3590 a6_ew a_msrfpcr 31 0 0 0 0 3591 end 3592 end 3593 3594 note conv (IR.md s7.3; imm bits 0..1 the rounding of a float destination, 0 nearest even, 1 toward zero; bit 2 3595 note saturation): int -> float SCVTF/UCVTF from the canonical X; f32 -> f64 FCVT (exact); f64 -> f32 FCVT, and with 3596 note bit 2 an infinite result of a finite source becomes the largest finite of its sign (a6_fsat); float -> int 3597 note a6_f2i. The source of f64 -> f32 is read (x17) before its register may be reused by the result 3598 fn a6_fconv o ulong r ulong to void 3599 t = ulong get i_oty o 3600 v = a6_arg o 0 3601 s = a6_vty v 3602 im = get i_oim o 3603 z = eq and im 3 1 3604 if a6_isint s 3605 a = a6_src v 16 3606 d = a6_fdst r 3607 a6_rz z true 3608 fm = a6_ff t a_ucvtfdx a_ucvtfsx 3609 if a6_sgn s 3610 fm = a6_ff t a_scvtfdx a_scvtfsx 3611 end 3612 a6_ew fm d a 0 0 0 3613 a6_rz z false 3614 a6_ffin r d 3615 ret 3616 end 3617 a = a6_fsrc v 29 3618 if a6_isint t 3619 d = a6_dst r 3620 a6_f2i t s d a 3621 a6_fin r d 3622 ret 3623 end 3624 d = a6_fdst r 3625 if eq t 14 3626 a6_ew a_fcvtds d a 0 0 0 3627 a6_ffin r d 3628 ret 3629 end 3630 sat = ne and im 4 0 3631 if sat 3632 a6_ew a_fmovxd 17 a 0 0 0 3633 end 3634 a6_rz z true 3635 a6_ew a_fcvtsd d a 0 0 0 3636 a6_rz z false 3637 if sat 3638 a6_fsat d 3639 end 3640 a6_ffin r d 3641 end 3642 3643 note a6_fsat d: saturation of an f64 -> f32 conv whose source bits are in x17: when S d is infinite (exponent 255) 3644 note and the source is finite (exponent below 2047), S d = its bits - 1, the largest finite of the same sign 3645 fn a6_fsat d ulong to void 3646 a6_ew a_fmovws 16 d 0 0 0 3647 a6_ew a_ubfmx 15 16 23 30 0 3648 a6_ew a_subsxi 31 15 255 0 0 3649 a6_ew a_csincx 15 31 31 1 0 3650 a6_ew a_ubfmx 17 17 52 62 0 3651 a6_ew a_subsxi 31 17 2047 0 0 3652 a6_ew a_cselx 15 31 15 0 0 3653 a6_ew a_subx 16 16 15 0 0 3654 a6_ew a_fmovsw d 16 0 0 0 3655 end 3656 3657 note a6_f2i t s d a: x d = the float of type s in V a, toward zero, as integer type t: FCVTZS (signed t) or FCVTZU X 3658 note saturate at 64 bits and give 0 for NaN; a narrower t is clamped to its bounds (CMP with x17, CSEL GT/LT or HI) 3659 fn a6_f2i t ulong s ulong d ulong a ulong to void 3660 w = a6_wid t 3661 if a6_sgn t 3662 a6_ew a6_ff s a_fcvtzsxd a_fcvtzsxs d a 0 0 0 3663 if lt w 64 3664 a6_movi 17 sub shl ulong 1 sub w 1 1 3665 a6_ew a_subsx 31 d 17 0 0 3666 a6_ew a_cselx d 17 d 12 0 3667 a6_movi 17 sub ulong 0 shl ulong 1 sub w 1 3668 a6_ew a_subsx 31 d 17 0 0 3669 a6_ew a_cselx d 17 d 11 0 3670 end 3671 ret 3672 end 3673 a6_ew a6_ff s a_fcvtzuxd a_fcvtzuxs d a 0 0 0 3674 if lt w 64 3675 a6_movi 17 sub shl ulong 1 w 1 3676 a6_ew a_subsx 31 d 17 0 0 3677 a6_ew a_cselx d 17 d 8 0 3678 end 3679 end 3680 3681 note bitcast (IR.md s7.3, every bit kept): float -> int FMOV X, D or W, S, then the integer's canonical extension; 3682 note int -> float FMOV D, X or S, W; float -> float FMOV D 3683 fn a6_fbcast o ulong r ulong to void 3684 t = ulong get i_oty o 3685 v = a6_arg o 0 3686 s = a6_vty v 3687 if and a6_isft s a6_isft t 3688 a = a6_fsrc v 29 3689 d = a6_fdst r 3690 a6_ew a_fmovd d a 0 0 0 3691 a6_ffin r d 3692 ret 3693 end 3694 if a6_isft s 3695 a = a6_fsrc v 29 3696 d = a6_dst r 3697 a6_ew a6_ff s a_fmovxd a_fmovws d a 0 0 0 3698 a6_canon d t 3699 a6_fin r d 3700 ret 3701 end 3702 a = a6_src v 16 3703 d = a6_fdst r 3704 a6_ew a6_ff t a_fmovdx a_fmovsw d a 0 0 0 3705 a6_ffin r d 3706 end 3707 3708 note fma (IR.md s7.4, op 46 only): FMADD d, a, b, c = a x b + c, rounded once 3709 fn a6_ffma o ulong r ulong to void 3710 t = ulong get i_oty o 3711 a = a6_fsrc a6_arg o 0 29 3712 b = a6_fsrc a6_arg o 1 30 3713 c = a6_fsrc a6_arg o 2 31 3714 d = a6_fdst r 3715 a6_ew a6_ff t a_fmaddd a_fmadds d a b c 0 3716 a6_ffin r d 3717 end 3718 3719 note load and store of an f32/f64 element: LDR/STR S or D, register offset, the index scaled by the element size 3720 fn a6_fload o ulong r ulong to void 3721 t = ulong get i_oty o 3722 a6_aref a6_arg o 1 3723 b = a6_src a6_arg o 1 16 3724 i = a6_src a6_arg o 2 17 3725 d = a6_fdst r 3726 a6_ew a6_ff t a_ldrdr a_ldrsr d b i 1 0 3727 a6_ffin r d 3728 end 3729 3730 fn a6_fstore o ulong to void 3731 v = a6_arg o 3 3732 t = a6_vty v 3733 a6_aref a6_arg o 1 3734 b = a6_src a6_arg o 1 16 3735 i = a6_src a6_arg o 2 17 3736 x = a6_fsrc v 29 3737 a6_ew a6_ff t a_strdr a_strsr x b i 1 0 3738 end 3739 3740 note chk.conv of a float v into integer type t (IR.md s7.9, trap 5): v as f64 in V a (FCVT D, S for an f32, exact); 3741 note unordered traps (B.VS); then v <= lo (B.LS) or v >= hi (B.GE) traps, with the f64 bounds of the truncated value's 3742 note range: unsigned lo -1, hi 2^w; signed w < 64 lo -(2^(w-1) + 1), hi 2^(w-1); i64 v < -2^63 (B.MI) or v >= 2^63. 3743 note The bound bits (exponent 1023 + k at bit 52) are checked with Wolfram in DESIGN.md section 9 3744 fn a6_fchk o ulong to void 3745 t = ulong get i_oty o 3746 v = a6_arg o 1 3747 a = a6_fsrc v 29 3748 if eq a6_vty v 13 3749 a6_ew a_fcvtds 30 a 0 0 0 3750 a = 30 3751 end 3752 a6_ew a_fcmpd a a 0 0 0 3753 a6_fx a_bcond 6 add a_tlab 5 3754 w = a6_wid t 3755 lo = ulong 0xbff0000000000000 3756 lc = ulong 9 3757 hi = shl add ulong 1023 w 52 3758 if a6_sgn t 3759 hi = shl add ulong 1022 w 52 3760 if eq w 64 3761 lo = or 0x8000000000000000 hi 3762 lc = 4 3763 else 3764 lo = or 0x8000000000000000 or hi shl ulong 1 sub 53 w 3765 end 3766 end 3767 a6_movi 16 lo 3768 a6_ew a_fmovdx 31 16 0 0 0 3769 a6_ew a_fcmpd a 31 0 0 0 3770 a6_fx a_bcond lc add a_tlab 5 3771 a6_movi 16 hi 3772 a6_ew a_fmovdx 31 16 0 0 0 3773 a6_ew a_fcmpd a 31 0 0 0 3774 a6_fx a_bcond 10 add a_tlab 5 3775 end 3776 3777 note ---- packed 16-byte float vectors: vec f32 4 and vec f64 2 (IR.md s7.3, s7.4, s7.5, s7.8; DESIGN.md s12) ---- 3778 fn a6_isvt t ulong to bool 3779 if ne get i_tk t 1 3780 ret false 3781 end 3782 e = ulong get i_t1 t 3783 l = ulong get i_t2 t 3784 if and eq e 13 eq l 4 3785 ret true 3786 end 3787 ret and eq e 14 eq l 2 3788 end 3789 3790 fn a6_isvv v ulong to bool 3791 ret a6_isvt a6_vty v 3792 end 3793 3794 fn a6_vf t ulong fd ulong fs ulong to ulong 3795 if eq get i_t1 t 14 3796 ret fd 3797 end 3798 ret fs 3799 end 3800 3801 fn a6_vsrc v ulong s ulong to ulong 3802 w = a6_wi v 3803 r = ulong uchar get ar_m add get ar_rb 95 w 3804 if a6_isvl r 3805 ret sub r 32 3806 end 3807 a6_ew a_ldrq s 31 shr sub get ar_m add get ar_rb 96 w 1 1 0 0 3808 ret s 3809 end 3810 3811 fn a6_vdst v ulong to ulong 3812 r = ulong uchar get ar_m add get ar_rb 95 a6_wi v 3813 if a6_isvl r 3814 ret sub r 32 3815 end 3816 ret 31 3817 end 3818 3819 fn a6_vfin v ulong r ulong to void 3820 w = a6_wi v 3821 if ge ulong uchar get ar_m add get ar_rb 95 w 64 3822 a6_ew a_strq r 31 shr sub get ar_m add get ar_rb 96 w 1 1 0 0 3823 end 3824 end 3825 3826 fn a6_isvo o ulong op ulong to bool 3827 if and ge op 60 le op 66 3828 ret false 3829 end 3830 r = ulong get i_ors o 3831 if ne r 0 3832 if a6_isvv r 3833 ret true 3834 end 3835 end 3836 if or eq op 58 eq op 59 3837 ret true 3838 end 3839 if and ge op 100 le op 106 3840 ret true 3841 end 3842 if eq op 43 3843 ret a6_isvv a6_arg o 3 3844 end 3845 ret false 3846 end 3847 3848 fn a6_svec o ulong op ulong to void 3849 r = ulong get i_ors o 3850 if or or eq op 10 eq op 11 eq op 12 3851 a6_vbin o op r 3852 ret 3853 end 3854 if eq op 46 3855 a6_vfma o r 3856 ret 3857 end 3858 if eq op 58 3859 a6_vld o r 3860 ret 3861 end 3862 if eq op 59 3863 a6_vst o 3864 ret 3865 end 3866 if eq op 100 3867 a6_vsplt o r 3868 ret 3869 end 3870 if eq op 101 3871 a6_vext o r 3872 ret 3873 end 3874 a6_unsup op 3875 end 3876 3877 fn a6_vbin o ulong op ulong r ulong to void 3878 t = ulong get i_oty o 3879 a = a6_vsrc a6_arg o 0 29 3880 b = a6_vsrc a6_arg o 1 30 3881 d = a6_vdst r 3882 fm = a6_vf t a_fadd2d a_fadd4s 3883 if eq op 11 3884 fm = a6_vf t a_fsub2d a_fsub4s 3885 end 3886 if eq op 12 3887 fm = a6_vf t a_fmul2d a_fmul4s 3888 end 3889 a6_ew fm d a b 0 0 3890 a6_vfin r d 3891 end 3892 3893 note packed fma (c + a * b, single rounding per lane): FMLA accumulates into Vd; when Vd aliases Va or Vb (and is 3894 note not already Vc), compute in scratch v31 first so moving Vc never clobbers a live multiplicand 3895 fn a6_vfma o ulong r ulong to void 3896 fm = a6_vf ulong get i_oty o a_fmla2d a_fmla4s 3897 a = a6_vsrc a6_arg o 0 29 3898 b = a6_vsrc a6_arg o 1 30 3899 c = a6_vsrc a6_arg o 2 31 3900 d = a6_vdst r 3901 if eq d c 3902 a6_ew fm d a b 0 0 3903 else 3904 if or eq d a eq d b 3905 if ne c 31 3906 a6_ew a_orr16b 31 c c 0 0 3907 end 3908 a6_ew fm 31 a b 0 0 3909 a6_ew a_orr16b d 31 31 0 0 3910 else 3911 a6_ew a_orr16b d c c 0 0 3912 a6_ew fm d a b 0 0 3913 end 3914 end 3915 a6_vfin r d 3916 end 3917 3918 fn a6_vsplt o ulong r ulong to void 3919 t = ulong get i_oty o 3920 a = a6_fsrc a6_arg o 0 29 3921 d = a6_vdst r 3922 a6_ew a6_vf t a_dupv2d a_dupv4s d a 0 0 0 3923 a6_vfin r d 3924 end 3925 3926 fn a6_vext o ulong r ulong to void 3927 v = a6_arg o 0 3928 vt = a6_vty v 3929 m = get i_oim o 3930 if ge m ulong get i_t2 vt 3931 a6_unsup m 3932 end 3933 a = a6_vsrc v 29 3934 d = a6_fdst r 3935 a6_ew a6_vf vt a_dupd a_dups d a m 0 0 3936 a6_ffin r d 3937 end 3938 3939 fn a6_vqimm iv ulong sz ulong to ulong 3940 if ne get i_vk iv 4 3941 ret 4096 3942 end 3943 o = ulong get i_vo iv 3944 if ne get i_oop o 1 3945 ret 4096 3946 end 3947 k = get i_oim o 3948 if ge k 65536 3949 ret 4096 3950 end 3951 bo = shl k sz 3952 if ne and bo 15 0 3953 ret 4096 3954 end 3955 ret shr bo 4 3956 end 3957 3958 fn a6_vld o ulong r ulong to void 3959 t = ulong get i_oty o 3960 if not a6_isvt t 3961 a6_unsup t 3962 end 3963 sz = a6_lsz ulong get i_t1 t 3964 a6_aref a6_arg o 1 3965 b = a6_src a6_arg o 1 16 3966 iv = a6_arg o 2 3967 d = a6_vdst r 3968 q = a6_vqimm iv sz 3969 if lt q 4096 3970 a6_ew a_ldrq d b q 0 0 3971 else 3972 i = a6_src iv 17 3973 a6_ew a_addx 15 31 i 0 sz 3974 a6_ew a_ldrqr d b 15 0 0 3975 end 3976 a6_vfin r d 3977 end 3978 3979 fn a6_vst o ulong to void 3980 v = a6_arg o 3 3981 if not a6_isvv v 3982 a6_unsup a6_vty v 3983 end 3984 sz = a6_lsz ulong get i_t1 a6_vty v 3985 a6_aref a6_arg o 1 3986 b = a6_src a6_arg o 1 16 3987 iv = a6_arg o 2 3988 x = a6_vsrc v 29 3989 q = a6_vqimm iv sz 3990 if lt q 4096 3991 a6_ew a_strq x b q 0 0 3992 else 3993 i = a6_src iv 17 3994 a6_ew a_addx 15 31 i 0 sz 3995 a6_ew a_strqr x b 15 0 0 3996 end 3997 end 3998 3999 note ---- terminators, calls, exit ---- 4000 fn a6_sterm o ulong op ulong x ulong to void 4001 if eq op 60 4002 a6_sbr o x 4003 end 4004 if eq op 61 4005 a6_scbr o x 4006 end 4007 if eq op 62 4008 a6_epi 4009 end 4010 if eq op 63 4011 if a6_issl a6_arg o 1 4012 a6_unsup 5 4013 end 4014 v = a6_arg o 1 4015 a6_mvto a6_rloc v v 4016 if ne get a_fs 14 0 4017 a6_tsum 0 0 4018 end 4019 a6_epi 4020 end 4021 if eq op 64 4022 a6_scall o 4023 end 4024 if eq op 65 4025 a6_fx a_b 0 add a_tlab get i_oim o 4026 end 4027 if eq op 66 4028 a6_mvto 0 a6_arg o 1 4029 a6_exit 4030 end 4031 end 4032 4033 note a6_mvto r v: register location r = value v 4034 fn a6_mvto r ulong v ulong to void 4035 a6_mv1 r a6_loc v 4036 end 4037 4038 note br: the values after the token go to the target's parameters after its token, as one parallel move 4039 fn a6_sbr o ulong x ulong to void 4040 t = a6_arg o 0 4041 a6_mvclr 4042 p = ulong get i_vnx get i_bp1 t 4043 k = ulong 2 4044 while ne p 0 bound 65 4045 a6_mvv p a6_arg o k 4046 p = ulong get i_vnx p 4047 k = add k 1 4048 end 4049 a6_pmove 4050 ti = a6_bix t 4051 if ne ti add x 1 4052 a6_fx a_b 0 ti 4053 end 4054 end 4055 4056 fn a6_scbr o ulong x ulong to void 4057 c = a6_src a6_arg o 1 16 4058 bt = a6_bix a6_arg o 2 4059 bf = a6_bix a6_arg o 3 4060 if eq bt add x 1 4061 a6_fx a_cbzx c bf 4062 ret 4063 end 4064 a6_fx a_cbnzx c bt 4065 if ne bf add x 1 4066 a6_fx a_b 0 bf 4067 end 4068 end 4069 4070 note call: the arguments a6_abi puts on the stack to the outgoing area [sp, 8j] (the first a6_outm slots of the 4071 note frame; k below is 8 + j), the others to x0..x7 and v0..v7 (one parallel move), BL (fixed up when every function 4072 note is placed), result from x0, or d0 for a float (a6_rloc) 4073 fn a6_outq q ulong l ulong to void 4074 if a6_isvq l 4075 a6_ew a_strq sub l 600 31 q 0 0 4076 ret 4077 end 4078 a6_ew a_ldrq 31 31 sub l 700 0 0 4079 a6_ew a_strq 31 31 q 0 0 4080 end 4081 4082 fn a6_scall o ulong to void 4083 n = a6_xcall o 4084 ns = a6_abi n 4085 i = ulong 0 4086 while lt i n bound 137 4087 p = get a_mab i 4088 if ge p 1000 4089 if ge p 3000 4090 a6_outq shr sub p 3000 1 get a_mal i 4091 else 4092 k = sub p 992 4093 l = get a_mal i 4094 if lt l 32 4095 a6_ew a_strx l 31 sub k 8 0 0 4096 else 4097 if a6_isvl l 4098 a6_ew a_strd sub l 32 31 sub k 8 0 0 4099 else 4100 a6_ew a_ldrx 16 31 sub l 64 0 0 4101 a6_ew a_strx 16 31 sub k 8 0 0 4102 end 4103 end 4104 end 4105 end 4106 i = add i 1 4107 end 4108 a6_mvclr 4109 i = ulong 0 4110 while lt i n bound 137 4111 p = get a_mab i 4112 if lt p 1000 4113 a6_mvadd p get a_mal i 4114 end 4115 i = add i 1 4116 end 4117 a6_pmove 4118 c = get a_ncl 0 4119 if ne ar_need 28 c 0 4120 ar_die 4121 end 4122 put ar_m add get ar_rb 105 c get a_cn 0 4123 put ar_m add get ar_rb 106 c a6_arg o 1 4124 put a_ncl 0 add c 1 4125 a6_emitw 0 4126 r = ulong get i_ors o 4127 if ne r 0 4128 a6_mvfrom r a6_rloc r 4129 end 4130 end 4131 4132 note a6_mvfrom v r: value v = register location r 4133 fn a6_mvfrom v ulong r ulong to void 4134 a6_mv1 a6_loc v r 4135 end 4136 4137 note ---- checks (IR.md s7.9): compare, then branch to the stub of the op's trap code ---- 4138 fn a6_schk o ulong op ulong to void 4139 c = ulong get i_oim o 4140 if le op 73 4141 a6_cova o op c 4142 ret 4143 end 4144 if eq op 74 4145 a6_fx a_cbzx a6_src a6_arg o 1 16 add a_tlab c 4146 ret 4147 end 4148 if eq op 75 4149 a6_cdivo o c 4150 ret 4151 end 4152 if eq op 76 4153 a6_cshl o c 4154 ret 4155 end 4156 if eq op 77 4157 a6_cshift o c 4158 ret 4159 end 4160 if eq op 78 4161 a6_cconv o c 4162 ret 4163 end 4164 if eq op 81 4165 a6_ew a_subsx 31 a6_src a6_arg o 1 16 a6_src a6_arg o 2 17 0 0 4166 a6_fx a_bcond 2 add a_tlab c 4167 ret 4168 end 4169 if eq op 82 4170 a6_fx a_cbzx a6_src a6_arg o 1 16 add a_tlab c 4171 ret 4172 end 4173 if eq op 79 4174 a6_cbnd o c 4175 ret 4176 end 4177 if eq op 80 4178 a6_cslc o c 4179 ret 4180 end 4181 a6_unsup op 4182 end 4183 4184 note chk.bounds on a SLICE r: trap when e = 0, e > len r (B.LO on the borrow of len - e) or i > len r - e 4185 fn a6_cbsl o ulong c ulong to void 4186 i = a6_src a6_arg o 2 16 4187 e = a6_src a6_arg o 3 17 4188 a6_fx a_cbzx e add a_tlab c 4189 l = a6_lsrc a6_arg o 1 15 4190 a6_ew a_subsx 15 l e 0 0 4191 a6_fx a_bcond 3 add a_tlab c 4192 a6_ew a_subsx 31 i 15 0 0 4193 a6_fx a_bcond 8 add a_tlab c 4194 end 4195 4196 note chk.slice on a SLICE r: trap when off > len r or n > len r - off 4197 fn a6_csls o ulong c ulong to void 4198 f = a6_src a6_arg o 2 16 4199 n = a6_src a6_arg o 3 17 4200 l = a6_lsrc a6_arg o 1 15 4201 a6_ew a_subsx 31 f l 0 0 4202 a6_fx a_bcond 8 add a_tlab c 4203 a6_ew a_subx 15 l f 0 0 4204 a6_ew a_subsx 31 n 15 0 0 4205 a6_fx a_bcond 8 add a_tlab c 4206 end 4207 4208 note chk.bounds r i e: trap when i + e > len r or e = 0. A constant e (the covering form of every load and store, 4209 note s8) is one compare of i with len - e (B.HI: unsigned, exact, no add that could wrap); e = 0 or e > len always 4210 note traps; any other e computes len - e first (B.LO on a borrow) 4211 fn a6_cbnd o ulong c ulong to void 4212 if a6_issl a6_arg o 1 4213 a6_cbsl o c 4214 ret 4215 end 4216 l = a6_alen a6_arg o 1 4217 v = a6_arg o 3 4218 i = a6_src a6_arg o 2 16 4219 if a6_iscon v 4220 e = get i_oim get i_vo v 4221 if or eq e 0 gt e l 4222 a6_fx a_b 0 add a_tlab c 4223 ret 4224 end 4225 a6_cmpk i sub l e 4226 a6_fx a_bcond 8 add a_tlab c 4227 ret 4228 end 4229 e = a6_src v 17 4230 a6_fx a_cbzx e add a_tlab c 4231 a6_movi 15 l 4232 a6_ew a_subsx 15 15 e 0 0 4233 a6_fx a_bcond 3 add a_tlab c 4234 a6_ew a_subsx 31 i 15 0 0 4235 a6_fx a_bcond 8 add a_tlab c 4236 end 4237 4238 note chk.slice r off n: trap when off > len r or n > len r - off 4239 fn a6_cslc o ulong c ulong to void 4240 if a6_issl a6_arg o 1 4241 a6_csls o c 4242 ret 4243 end 4244 l = a6_alen a6_arg o 1 4245 f = a6_src a6_arg o 2 16 4246 n = a6_src a6_arg o 3 17 4247 a6_cmpk f l 4248 a6_fx a_bcond 8 add a_tlab c 4249 a6_movi 15 l 4250 a6_ew a_subx 15 15 f 0 0 4251 a6_ew a_subsx 31 n 15 0 0 4252 a6_fx a_bcond 8 add a_tlab c 4253 end 4254 4255 note a6_cmpk r k: CMP Xr, #k (k <= 4095) or by x15 4256 fn a6_cmpk r ulong k ulong to void 4257 if le k 4095 4258 a6_ew a_subsxi 31 r k 0 0 4259 ret 4260 end 4261 a6_movi 15 k 4262 a6_ew a_subsx 31 r 15 0 0 4263 end 4264 4265 note a6_iscon v: v is the result of a const op 4266 fn a6_iscon v ulong to bool 4267 if ne get i_vk v 4 4268 ret false 4269 end 4270 ret eq get i_oop get i_vo v 1 4271 end 4272 4273 note chk.add sub mul neg: 64-bit by flags (V signed, C unsigned) or the high product; narrower types compute the exact 4274 note result in 64 bits (x15) and trap when re-extending it changes it 4275 fn a6_cova o ulong op ulong c ulong to void 4276 v = a6_arg o 1 4277 t = a6_vty v 4278 if not a6_isint t 4279 a6_unsup t 4280 end 4281 a = a6_src v 16 4282 b = ulong 31 4283 if ne op 73 4284 b = a6_src a6_arg o 2 17 4285 end 4286 if eq a6_wid t 64 4287 a6_cov64 op t a b c 4288 ret 4289 end 4290 if eq op 70 4291 a6_ew a_addx 15 a b 0 0 4292 end 4293 if eq op 71 4294 a6_ew a_subx 15 a b 0 0 4295 end 4296 if eq op 72 4297 a6_ew a_mulx 15 a b 0 0 4298 end 4299 if eq op 73 4300 a6_ew a_subx 15 31 a 0 0 4301 end 4302 a6_cext t c 4303 end 4304 4305 note a6_cext t c: trap c unless x15 equals its own extension to t (x16 is free: the operands were read) 4306 fn a6_cext t ulong c ulong to void 4307 a6_mov 16 15 4308 a6_canon 16 t 4309 a6_ew a_subsx 31 15 16 0 0 4310 a6_fx a_bcond 1 add a_tlab c 4311 end 4312 4313 fn a6_cov64 op ulong t ulong a ulong b ulong c ulong to void 4314 s = a6_sgn t 4315 l = add a_tlab c 4316 if eq op 72 4317 a6_cmul64 s a b l 4318 ret 4319 end 4320 if eq op 70 4321 a6_ew a_addsx 31 a b 0 0 4322 end 4323 if eq op 71 4324 a6_ew a_subsx 31 a b 0 0 4325 end 4326 if eq op 73 4327 a6_ew a_subsx 31 31 a 0 0 4328 end 4329 if s 4330 a6_fx a_bcond 6 l 4331 ret 4332 end 4333 if eq op 70 4334 a6_fx a_bcond 2 l 4335 end 4336 if eq op 71 4337 a6_fx a_bcond 3 l 4338 end 4339 if eq op 73 4340 a6_fx a_bcond 1 l 4341 end 4342 end 4343 4344 note signed: the high half must be the sign of the low half; unsigned: the high half must be 0 4345 fn a6_cmul64 s bool a ulong b ulong l ulong to void 4346 if s 4347 a6_ew a_mulx 15 a b 0 0 4348 a6_ew a_smulh 16 a b 0 0 4349 a6_ew a_subsx 31 16 15 2 63 4350 a6_fx a_bcond 1 l 4351 else 4352 a6_ew a_umulh 15 a b 0 0 4353 a6_fx a_cbnzx 15 l 4354 end 4355 end 4356 4357 note chk.divovf a b: trap when a = MIN and b = -1 of a's type: ((b + 1) | (a ^ MIN)) = 0 4358 fn a6_cdivo o ulong c ulong to void 4359 v = a6_arg o 1 4360 t = a6_vty v 4361 a = a6_src v 16 4362 b = a6_src a6_arg o 2 17 4363 a6_ew a_addxi 15 b 1 0 0 4364 a6_movi 17 sub ulong 0 shl ulong 1 sub a6_wid t 1 4365 a6_ew a_eorx 17 a 17 0 0 4366 a6_ew a_orrx 15 15 17 0 0 4367 a6_fx a_cbzx 15 add a_tlab c 4368 end 4369 4370 note chk.shl a b (signed, b already < width): 64-bit: (a << b) >> b must be a; narrower: a << b must survive extension 4371 fn a6_cshl o ulong c ulong to void 4372 v = a6_arg o 1 4373 t = a6_vty v 4374 a = a6_src v 16 4375 b = a6_src a6_arg o 2 17 4376 a6_ew a_lslvx 15 a b 0 0 4377 if eq a6_wid t 64 4378 a6_ew a_asrvx 17 15 b 0 0 4379 a6_ew a_subsx 31 17 a 0 0 4380 a6_fx a_bcond 1 add a_tlab c 4381 ret 4382 end 4383 a6_cext t c 4384 end 4385 4386 note chk.shift b: trap unless 0 <= b < width (unsigned compare of the extended value) 4387 fn a6_cshift o ulong c ulong to void 4388 v = a6_arg o 1 4389 t = a6_vty v 4390 b = a6_src v 16 4391 a6_ew a_subsxi 31 b a6_wid t 0 0 4392 a6_fx a_bcond 2 add a_tlab c 4393 end 4394 4395 note chk.conv to integer type ty from integer v (float sources are not in the slice) 4396 fn a6_cconv o ulong c ulong to void 4397 d = ulong get i_oty o 4398 v = a6_arg o 1 4399 s = a6_vty v 4400 if or not a6_isint s not a6_isint d 4401 a6_unsup s 4402 end 4403 a = a6_src v 16 4404 l = add a_tlab c 4405 wd = a6_wid d 4406 if eq wd 64 4407 if and a6_sgn s eq d 5 4408 a6_ew a_subsxi 31 a 0 0 0 4409 a6_fx a_bcond 11 l 4410 end 4411 if and eq s 5 eq d 9 4412 a6_ew a_subsxi 31 a 0 0 0 4413 a6_fx a_bcond 11 l 4414 end 4415 ret 4416 end 4417 if eq s 5 4418 a6_movi 15 sub shl ulong 1 wd 1 4419 if a6_sgn d 4420 a6_movi 15 sub shl ulong 1 sub wd 1 1 4421 end 4422 a6_ew a_subsx 31 a 15 0 0 4423 a6_fx a_bcond 8 l 4424 ret 4425 end 4426 a6_mov 15 a 4427 a6_cext d c 4428 end 4429 4430 note ---- E loop shape (D13) ---- 4431 note A block ending `r = call f(...); s = add a r` (or `add r a`) `; retv s` inside f itself, with r and s used once 4432 note each, becomes `acc = acc + a; f's parameters = the call's arguments; B head`: no call, no add, no retv. Every other 4433 note `retv x` of f returns acc + x. acc (wire a_taw, type a_tat) is 0 at the head, which follows the entry parameter 4434 note moves. Integer add is modulo 2^w (IR.md s7.3), hence associative and commutative, so every result is exact. 4435 note A checked add (chk.add on r) is a second use of r and keeps the call. Stack depth falls, and trap 6 is not 4436 note semantic (IR.md s7.9, D9). 4437 fn a6_tre f ulong to void 4438 put a_fs 14 0 4439 x = ulong 0 4440 while lt x get a_fs 1 bound 65536 4441 a6_tblk f get a_bh x 4442 x = add x 1 4443 end 4444 end 4445 4446 fn a6_tblk f ulong b ulong to void 4447 c = ulong 0 4448 m = ulong 0 4449 l = ulong 0 4450 o = ulong get i_bo1 b 4451 while ne o 0 bound `4194305` 4452 c = m 4453 m = l 4454 l = o 4455 o = ulong get i_onx o 4456 end 4457 if eq c 0 4458 ret 4459 end 4460 if not a6_tpat f c m l 4461 ret 4462 end 4463 n = get a_fs 14 4464 if ge n len a_tco 4465 ret 4466 end 4467 put a_tco n c 4468 put a_fs 14 add n 1 4469 put a_tat 0 ulong get i_oty m 4470 end 4471 4472 note a6_tpat f c m l: the last three ops of a block are the E shape (call c to f, add m, retv l) 4473 fn a6_tpat f ulong c ulong m ulong l ulong to bool 4474 if ne get i_oop c 64 4475 ret false 4476 end 4477 if ne get i_oop m 10 4478 ret false 4479 end 4480 if ne get i_oop l 63 4481 ret false 4482 end 4483 r = ulong get i_ors c 4484 s = ulong get i_ors m 4485 if eq r 0 4486 ret false 4487 end 4488 if ne a6_arg c 1 f 4489 ret false 4490 end 4491 if ne a6_arg l 1 s 4492 ret false 4493 end 4494 if not or eq a6_arg m 0 r eq a6_arg m 1 r 4495 ret false 4496 end 4497 if ne a6_uses r 1 4498 ret false 4499 end 4500 if ne a6_uses s 1 4501 ret false 4502 end 4503 ret a6_isint ulong get i_oty m 4504 end 4505 4506 note a6_uses v: the number of value operands in the function that are v 4507 fn a6_uses v ulong to ulong 4508 c = ulong 0 4509 x = ulong 0 4510 while lt x get a_fs 1 bound 65536 4511 o = ulong get i_bo1 get a_bh x 4512 while ne o 0 bound `4194305` 4513 op = get i_oop o 4514 n = ulong get i_ona o 4515 k = ulong 0 4516 while lt k n bound `1048576` 4517 if eq ir_okd uint op k 0 4518 if eq a6_arg o k v 4519 c = add c 1 4520 end 4521 end 4522 k = add k 1 4523 end 4524 o = ulong get i_onx o 4525 end 4526 x = add x 1 4527 end 4528 ret c 4529 end 4530 4531 fn a6_istc o ulong to bool 4532 i = ulong 0 4533 while lt i get a_fs 14 bound 64 4534 if eq get a_tco i o 4535 ret true 4536 end 4537 i = add i 1 4538 end 4539 ret false 4540 end 4541 4542 note a6_tacc: the accumulator is one more wire, defined at 0 and live to the end (it crosses every call in f) 4543 fn a6_tacc to void 4544 if eq get a_fs 14 0 4545 ret 4546 end 4547 w = get a_fs 0 4548 if ne ar_need 26 w 0 4549 ar_die 4550 end 4551 put a_taw 0 w 4552 put ar_m add get ar_rb 91 w 0 4553 put ar_m add get ar_rb 96 w 0 4554 ar_pc 94 w 0 4555 ar_pc 99 w 0 4556 ar_pc 95 w 255 4557 put ar_m add get ar_rb 92 w 0 4558 put ar_m add get ar_rb 93 w get a_fs 3 4559 put a_fs 0 add w 1 4560 end 4561 4562 fn a6_accl to ulong 4563 w = get a_taw 0 4564 r = ulong uchar get ar_m add get ar_rb 95 w 4565 if lt r 32 4566 ret r 4567 end 4568 ret add 64 sub get ar_m add get ar_rb 96 w 1 4569 end 4570 4571 note a6_tsum d a: register d = acc + register a, re-extended to the accumulator's type (acc from its slot via x17) 4572 fn a6_tsum d ulong a ulong to void 4573 l = a6_accl 4574 c = l 4575 if ge l 32 4576 a6_ew a_ldrx 17 31 sub l 64 0 0 4577 c = ulong 17 4578 end 4579 a6_ew a_addx d c a 0 0 4580 a6_canon d get a_tat 0 4581 end 4582 4583 note a6_stail o: the tail site at call o (the add and retv after it emit nothing) 4584 fn a6_stail o ulong to void 4585 m = ulong get i_onx o 4586 r = ulong get i_ors o 4587 v = a6_arg m 0 4588 if eq v r 4589 v = a6_arg m 1 4590 end 4591 a = a6_src v 16 4592 l = a6_accl 4593 if lt l 32 4594 a6_tsum l a 4595 else 4596 a6_tsum 17 a 4597 a6_ew a_strx 17 31 sub l 64 0 0 4598 end 4599 a6_mvclr 4600 p = ulong get i_fp1 get a_fs 8 4601 k = ulong 2 4602 while ne p 0 bound 65 4603 a6_mvv p a6_arg o k 4604 p = ulong get i_vnx p 4605 k = add k 1 4606 end 4607 a6_pmove 4608 a6_ew a_b a6_wd get a_cn 0 get a_fs 15 0 0 0 0 4609 end 4610 4611 note ---- one function ---- 4612 fn a6_func f ulong to void 4613 if eq get i_fk f 1 4614 a6_unsup 1 4615 end 4616 nv = ulong ir_num uint f 4617 if ne ar_need 26 add nv 1 0 4618 ar_die 4619 end 4620 put a_fs 0 nv 4621 put a_fs 8 f 4622 a6_wmap f 4623 a6_lay f 4624 a6_tre f 4625 a6_ucnt 4626 put a_skip 0 0 4627 put a_fs 16 0 4628 lw = shr add nv 63 6 4629 put a_fs 2 lw 4630 if ne ar_need 27 mul get a_fs 1 lw 0 4631 ar_die 4632 end 4633 a6_ccalls 4634 a6_lzero 4635 a6_lgen 4636 a6_lflow 4637 a6_ivinit 4638 a6_ivuse 4639 a6_ivlive 4640 a6_tacc 4641 a6_shw 4642 a6_ivcross 4643 a6_scan 4644 a6_frame 4645 pc = get a_cn 0 4646 nc = get a_ncl 0 4647 a6_fbody f 4648 if ne get a_fs 16 0 4649 put a_cn 0 pc 4650 put a_ncl 0 nc 4651 a6_fbody f 4652 end 4653 end 4654 4655 note a6_al64: pad the code with NOP (C6.2.238, never executed: the previous function ends in RET or its trap stubs) 4656 note to a 64-byte boundary. Text file offset k loads at 0x400000 + k, so this aligns the virtual address (D13). 4657 fn a6_al64 to void 4658 while ne and get a_cn 0 63 0 bound 16 4659 a6_emitw 0xd503201f 4660 end 4661 end 4662 4663 note a6_outm: the outgoing argument slots of the function, the most arguments past the eighth of any of its calls; 4664 note they are frame slots 0.. (spill slots follow), so the callee finds argument 8+j at its [sp + frame + 8j] 4665 fn a6_outm to ulong 4666 m = ulong 0 4667 x = ulong 0 4668 while lt x get a_fs 1 bound 65536 4669 o = ulong get i_bo1 get a_bh x 4670 while ne o 0 bound `4194305` 4671 if eq get i_oop o 64 4672 n = a6_xstk o 4673 if gt n m 4674 m = n 4675 end 4676 end 4677 o = ulong get i_onx o 4678 end 4679 x = add x 1 4680 end 4681 ret m 4682 end 4683 4684 note a6_inpar n: the machine parameters of the n in a_mal (a6_xpar) that a6_abi puts on the stack, from the caller's 4685 note outgoing area through x17 = sp + frame (parameter j of the stack at [x17, 8j]) 4686 fn a6_inpar n ulong to void 4687 m = ulong 0 4688 k = ulong 0 4689 while lt k n bound 137 4690 if ge get a_mab k 1000 4691 m = add m 1 4692 end 4693 k = add k 1 4694 end 4695 if eq m 0 4696 ret 4697 end 4698 f = get a_fs 7 4699 a6_ew a_addxi 17 31 shr f 12 1 0 4700 a6_ew a_addxi 17 17 and f 4095 0 0 4701 k = ulong 0 4702 while lt k n bound 137 4703 p = get a_mab k 4704 if ge p 1000 4705 if ge p 3000 4706 a6_inpq shr sub p 3000 1 get a_mal k 4707 else 4708 j = sub p 1000 4709 d = get a_mal k 4710 if lt d 32 4711 a6_ew a_ldrx d 17 j 0 0 4712 else 4713 if a6_isvl d 4714 a6_ew a_ldrd sub d 32 17 j 0 0 4715 else 4716 a6_ew a_ldrx 16 17 j 0 0 4717 a6_ew a_strx 16 31 sub d 64 0 0 4718 end 4719 end 4720 end 4721 end 4722 k = add k 1 4723 end 4724 end 4725 4726 fn a6_inpq q ulong d ulong to void 4727 if a6_isvq d 4728 a6_ew a_ldrq sub d 600 17 q 0 0 4729 ret 4730 end 4731 a6_ew a_ldrq 31 17 q 0 0 4732 a6_ew a_strq 31 31 sub d 700 0 0 4733 end 4734 4735 fn a6_fbody f ulong to void 4736 a6_al64 4737 put a_skip 0 0 4738 put a_fpc f get a_cn 0 4739 put a_fs 12 0 4740 put a_fs 10 0 4741 a6_pro 4742 a6_mvclr 4743 n = a6_xpar f 4744 ns = a6_abi n 4745 k = ulong 0 4746 while lt k n bound 137 4747 p = get a_mab k 4748 if lt p 1000 4749 a6_mvadd get a_mal k p 4750 end 4751 k = add k 1 4752 end 4753 a6_pmove 4754 a6_inpar n 4755 if ne get a_fs 14 0 4756 l = a6_accl 4757 if lt l 32 4758 a6_ew a_movzx l 0 0 0 0 4759 else 4760 a6_ew a_strx 31 31 sub l 64 0 0 4761 end 4762 put a_fs 15 get a_cn 0 4763 end 4764 x = ulong 0 4765 while lt x get a_fs 1 bound 65536 4766 put a_bpc x get a_cn 0 4767 o = ulong get i_bo1 get a_bh x 4768 while ne o 0 bound `4194305` 4769 if a6_istc o 4770 a6_stail o 4771 o = ulong 0 4772 else 4773 a6_sel o x 4774 o = ulong get i_onx o 4775 end 4776 end 4777 x = add x 1 4778 end 4779 a6_tstubs 4780 a6_fixb 4781 end 4782 4783 note ---- module: ELF (omc's map), _start, functions, call fixups ---- 4784 note a6_hasf: some value of the module is an f32 or f64; then _start writes FPCR = 0 (MSR FPCR, XZR) before main 4785 fn a6_hasf to bool 4786 n = get i_n 3 4787 f = ulong 1 4788 while le f n bound 65537 4789 p = ulong get i_fp1 f 4790 while ne p 0 bound 65 4791 if or a6_isfv p a6_isvv p 4792 ret true 4793 end 4794 p = ulong get i_vnx p 4795 end 4796 b = ulong get i_fb1 f 4797 while ne b 0 bound 65537 4798 p = ulong get i_bp1 b 4799 while ne p 0 bound 65 4800 if or a6_isfv p a6_isvv p 4801 ret true 4802 end 4803 p = ulong get i_vnx p 4804 end 4805 o = ulong get i_bo1 b 4806 while ne o 0 bound `4194305` 4807 r = ulong get i_ors o 4808 if ne r 0 4809 if or a6_isfv r a6_isvv r 4810 ret true 4811 end 4812 end 4813 o = ulong get i_onx o 4814 end 4815 b = ulong get i_bnx b 4816 end 4817 f = add f 1 4818 end 4819 ret false 4820 end 4821 4822 note entry (D11): the single export (kind 2) with no parameters and result i32 4823 fn a6_isent f ulong to bool 4824 if ne get i_fk f 2 4825 ret false 4826 end 4827 ret and eq get i_fnp f 0 eq get i_frs f 8 4828 end 4829 4830 fn a6_entry to ulong 4831 n = get i_n 3 4832 e = ulong 0 4833 f = ulong 1 4834 while le f n bound 65537 4835 if a6_isent f 4836 if ne e 0 4837 a6_unsup f 4838 end 4839 e = f 4840 end 4841 f = add f 1 4842 end 4843 if eq e 0 4844 a6_unsup 0 4845 end 4846 ret e 4847 end 4848 4849 note The callback entries of a Mach-O program (DESIGN.md s14). Sixteen entries of two words (MOVZ X16, #k; B body) 4850 note and one body. Library code enters with the C convention on its own stack, inside a libcall. The body keeps 4851 note x29, x30, x27 and x28 and the link words 16 and 24 in a 48-byte C frame, finds x28 again from its own address, 4852 note makes the C stack the one later libcalls use (link word 16), moves to the Omega stack where the enclosing 4853 note libcall left it (link word 24), calls the callback function with (k, x0..x4) and gives its x0 back. 4854 fn a6_back to void 4855 put a_bks 0 0 4856 n = get i_n 3 4857 b = ulong 0 4858 f = ulong 1 4859 while le f n bound 65537 4860 if ge ulong get i_ffl f 2 4861 if ne b 0 4862 a6_unsup f 4863 end 4864 b = f 4865 end 4866 f = add f 1 4867 end 4868 if eq b 0 4869 ret 4870 end 4871 if or ne ulong get i_fnp b 6 ne ulong get i_frs b 5 4872 a6_unsup b 4873 end 4874 put a_bks 0 get a_cn 0 4875 for k ulong 16 4876 a6_ew a_movzx 16 k 0 0 0 4877 a6_emitw add `335544320` sub 31 mul 2 k 4878 end 4879 a6_emitw 0xa9bd7bfd 4880 a6_emitw 0x910003fd 4881 a6_emitw 0xa90173fb 4882 pc = get a_cn 0 4883 a6_ew a_adr 9 0 0 0 0 4884 a6_movi 10 sub `16777216` pc 4885 a6_ew a_addx 28 9 10 0 0 4886 a6_emitw 0xd1401389 4887 a6_emitw 0xa9412d2a 4888 a6_emitw 0xa9022fea 4889 a6_emitw 0x910003fb 4890 a6_emitw 0xf900093b 4891 a6_emitw 0x9100017f 4892 a6_emitw 0xaa0403e5 4893 a6_emitw 0xaa0303e4 4894 a6_emitw 0xaa0203e3 4895 a6_emitw 0xaa0103e2 4896 a6_emitw 0xaa0003e1 4897 a6_emitw 0xaa1003e0 4898 c = get a_ncl 0 4899 if ne ar_need 28 c 0 4900 ar_die 4901 end 4902 put ar_m add get ar_rb 105 c get a_cn 0 4903 put ar_m add get ar_rb 106 c b 4904 put a_ncl 0 add c 1 4905 a6_emitw 0 4906 a6_emitw 0x9100037f 4907 a6_emitw 0xd1401389 4908 a6_emitw 0xa9422fea 4909 a6_emitw 0xa9012d2a 4910 a6_emitw 0xa94173fb 4911 a6_emitw 0xa8c37bfd 4912 a6_emitw 0xd65f03c0 4913 end 4914 4915 fn a6_comp to void 4916 put a_cn 0 176 4917 if eq get a_tgt 0 1 4918 put a_cn 0 16384 4919 end 4920 put a_ncl 0 0 4921 e = a6_entry 4922 if eq get a_tgt 0 1 4923 a6_ew a_adr 16 0 0 0 0 4924 a6_ew a_movzx 17 49152 0 0 0 4925 a6_ew a_movkx 17 255 1 0 0 4926 a6_ew a_addx 28 16 17 0 0 4927 a6_ew a_movzx 17 128 1 0 0 4928 a6_ew a_addx 16 28 17 0 0 4929 note the link page (a6_macho, DESIGN.md s13) keeps the stack dyld entered on: MOV X9, SP; SUB X10, X28, #4, LSL #12; 4930 note STR X9, [X10, #16]. libcall runs library code on that stack. 4931 a6_emitw 0x910003e9 4932 a6_emitw 0xd140138a 4933 a6_emitw 0xf9000949 4934 else 4935 if a6_hasenv 4936 a6_ew a_addxi 18 31 0 0 0 4937 end 4938 a6_ew a_movzx 28 4096 1 0 0 4939 a6_ew a_movzx 16 4224 1 0 0 4940 end 4941 a6_ew a_addxi 31 16 0 0 0 4942 if a6_hasf 4943 fz = ulong 31 4944 a6_ew a_msrfpcr fz 0 0 0 0 4945 end 4946 if ne ar_need 28 0 0 4947 ar_die 4948 end 4949 put ar_m add get ar_rb 105 0 get a_cn 0 4950 put ar_m add get ar_rb 106 0 e 4951 put a_ncl 0 1 4952 a6_emitw 0 4953 a6_exit 4954 a6_glay 4955 put a_bks 0 0 4956 if eq get a_tgt 0 1 4957 a6_back 4958 end 4959 n = get i_n 3 4960 f = ulong 1 4961 while le f n bound 65537 4962 a6_func f 4963 f = add f 1 4964 end 4965 i = ulong 0 4966 while lt i get a_ncl 0 bound `16777217` 4967 pc = get ar_m add get ar_rb 105 i 4968 a6_putw pc a6_enc a_bl a6_wd pc get a_fpc get ar_m add get ar_rb 106 i 0 0 0 0 4969 i = add i 1 4970 end 4971 if eq get a_tgt 0 1 4972 a6_macho get a_cn 0 4973 else 4974 a6_elf get a_cn 0 4975 end 4976 end 4977 4978 fn a6_pn o ulong v ulong k ulong to void 4979 i = ulong 0 4980 while lt i k bound 8 4981 ar_bp 107 add o i uchar and shr v shl i 3 255 4982 i = add i 1 4983 end 4984 end 4985 4986 note ELF64 header and two PT_LOAD headers: text R+X at 0x400000 (file offset 0), RW pool at 0x10000000: the 8 MiB 4987 note stack, then the class-0 globals (zero-filled, no file bytes) 4988 fn a6_elf n ulong to void 4989 i = ulong 0 4990 while lt i 176 bound 176 4991 ar_bp 107 i 0 4992 i = add i 1 4993 end 4994 a6_pn 0 0x00010102464c457f 8 4995 a6_pn 16 0x00b70002 4 4996 a6_pn 20 1 4 4997 a6_pn 24 0x4000b0 8 4998 a6_pn 32 64 8 4999 a6_pn 52 0x00380040 4 5000 a6_pn 56 2 2 5001 a6_pn 64 0x500000001 8 5002 a6_pn 80 0x400000 8 5003 a6_pn 88 0x400000 8 5004 a6_pn 96 n 8 5005 a6_pn 104 n 8 5006 a6_pn 112 4096 8 5007 a6_pn 120 0x600000001 8 5008 a6_pn 136 0x10000000 8 5009 a6_pn 144 0x10000000 8 5010 a6_pn 160 add 0x800000 and add get a_gtot 0 4095 not ulong 4095 8 5011 a6_pn 168 4096 8 5012 end 5013 5014 note a6_macho n: the Mach-O container around the code a_code[16384, n) (`@ng a64 macho`). File: a 16 KiB header 5015 note page (mach_header_64 and 12 load commands, 680 bytes; the rest is room for the signature command), the code, 5016 note zero padding to a 16 KiB multiple F, then 40 bytes of __LINKEDIT (24 of bind records, then the empty 16-byte 5017 note string table). Memory, from the slid base B (0x100000000 before the slide): __TEXT B..B+F read+execute (F at 5018 note most 16 MiB less 16 KiB), __DATA from B+16 MiB-16 KiB zero-filled read+write (the 16 KiB link page, 8 MiB of 5019 note stack, then the class-0 globals, rounded up to 16 KiB), __LINKEDIT after it. dyld binds two words of the link 5020 note page: dlopen at +0 and dlsym at +8 (LC_DYLD_INFO_ONLY bind_off F, bind_size 24). LC_MAIN enters at file 5021 note offset 16384, the start code: ADR x16, .; x28 = x16 + 0xFFC000 (the stack floor B+16 MiB); the entry sp to 5022 note link page +16; sp = x28 + 8 MiB; BL main; Darwin exit. Library code runs only through libcall (a6_hlib). The 5023 note code signature (required on arm64 macOS) is added on the Mac by `codesign --sign -`, which this layout leaves 5024 note room for. 5025 fn a6_macho n ulong to void 5026 f = and add n 16383 not ulong 16383 5027 if gt f `16760832` 5028 a6_die 4 3 `18446744073709551615` 5029 end 5030 if ne ar_need 29 add f 39 0 5031 ar_die 5032 end 5033 i = ulong 0 5034 while lt i 16384 bound 16384 5035 ar_bp 107 i 0 5036 i = add i 1 5037 end 5038 gv = add 0x800000 and add get a_gtot 0 16383 not ulong 16383 5039 a6_pn 0 0xfeedfacf 4 5040 a6_pn 4 0x0100000c 4 5041 a6_pn 12 2 4 5042 a6_pn 16 12 4 5043 a6_pn 20 680 4 5044 a6_pn 24 0x200085 4 5045 a6_pn 32 25 4 5046 a6_pn 36 72 4 5047 a6_pn 40 `4997382908861767519` 8 5048 a6_pn 48 20306 8 5049 a6_pn 64 0x100000000 8 5050 a6_pn 104 25 4 5051 a6_pn 108 152 4 5052 a6_pn 112 `92738097012575` 8 5053 a6_pn 120 0 8 5054 a6_pn 128 0x100000000 8 5055 a6_pn 136 f 8 5056 a6_pn 152 f 8 5057 a6_pn 160 5 4 5058 a6_pn 164 5 4 5059 a6_pn 168 1 4 5060 a6_pn 176 `128060447022943` 8 5061 a6_pn 184 0 8 5062 a6_pn 192 `92738097012575` 8 5063 a6_pn 200 0 8 5064 a6_pn 208 0x100004000 8 5065 a6_pn 216 sub n 16384 8 5066 a6_pn 224 16384 4 5067 a6_pn 228 6 4 5068 a6_pn 240 0x80000400 4 5069 a6_pn 256 25 4 5070 a6_pn 260 72 4 5071 a6_pn 264 `71830128058207` 8 5072 a6_pn 272 0 8 5073 a6_pn 280 0x100ffc000 8 5074 a6_pn 288 add gv 16384 8 5075 a6_pn 296 f 8 5076 a6_pn 312 3 4 5077 a6_pn 316 3 4 5078 a6_pn 328 25 4 5079 a6_pn 332 72 4 5080 a6_pn 336 `4919420967581409119` 8 5081 a6_pn 344 21577 8 5082 a6_pn 352 add 0x101000000 gv 8 5083 a6_pn 360 16384 8 5084 a6_pn 368 f 8 5085 a6_pn 376 40 8 5086 a6_pn 384 1 4 5087 a6_pn 388 1 4 5088 a6_pn 400 0x80000022 4 5089 a6_pn 404 48 4 5090 a6_pn 416 f 4 5091 a6_pn 420 24 4 5092 a6_pn 448 2 4 5093 a6_pn 452 24 4 5094 a6_pn 456 add f 24 4 5095 a6_pn 464 add f 24 4 5096 a6_pn 468 16 4 5097 a6_pn 472 11 4 5098 a6_pn 476 80 4 5099 a6_pn 552 14 4 5100 a6_pn 556 32 4 5101 a6_pn 560 12 4 5102 a6_pn 564 `7091318039310988591` 8 5103 a6_pn 572 `431316624431` 8 5104 a6_pn 584 12 4 5105 a6_pn 588 56 4 5106 a6_pn 592 24 4 5107 a6_pn 600 65536 4 5108 a6_pn 604 65536 4 5109 a6_pn 608 `7091318039310988591` 8 5110 a6_pn 616 `8391183929761688623` 8 5111 a6_pn 624 `7816388778119818597` 8 5112 a6_pn 632 25193 8 5113 a6_pn 640 50 4 5114 a6_pn 644 24 4 5115 a6_pn 648 1 4 5116 a6_pn 652 720896 4 5117 a6_pn 656 720896 4 5118 a6_pn 664 27 4 5119 a6_pn 668 24 4 5120 a6_pn 672 `7161089769139693422` 8 5121 a6_pn 680 `212436143976` 8 5122 a6_pn 688 0x80000028 4 5123 a6_pn 692 24 4 5124 a6_pn 696 16384 8 5125 note the bind records: dylib 1, _dlopen, pointer, segment 2 offset 0, bind; _dlsym, bind (the next word); done 5126 a6_pn f 0x65706f6c645f4011 8 5127 a6_pn add f 8 0x5f4090007251006e 8 5128 a6_pn add f 16 0x0090006d79736c64 8 5129 put a_cn 0 add f 40 5130 end 5131 5132 note a6_glay: class-0 globals in the RW pool from 0x10800000 (16-byte aligned, as omc), at most 1 GiB; class-1 5133 note globals' bytes into the code image here (between the start code and the first function), padded to a word 5134 note Their addresses are arena group a64glob (index = global id), bounded by the arena (no-caps 2026-11-11). 5135 fn a6_glay to void 5136 n = get i_n 2 5137 p = ulong 0 5138 g = ulong 1 5139 if ne ar_need 25 n 0 5140 ar_die 5141 end 5142 while le g n bound `134217729` 5143 s = ir_tsize uint get ar_m add get ar_rb 87 g 5144 if eq ar_c 88 g 2 5145 s = 16 5146 end 5147 if eq ar_c 88 g 1 5148 if eq get a_tgt 0 1 5149 put ar_m add get ar_rb 90 g sub `16777216` get a_cn 0 5150 else 5151 put ar_m add get ar_rb 90 g add 0x400000 get a_cn 0 5152 end 5153 a6_gdat g s 5154 else 5155 if eq get a_tgt 0 1 5156 put ar_m add get ar_rb 90 g add 0x800000 p 5157 else 5158 put ar_m add get ar_rb 90 g add 0x10800000 p 5159 end 5160 p = and add add p s 15 not ulong 15 5161 end 5162 if gt p `1073741824` 5163 a6_unsup p 5164 end 5165 g = add g 1 5166 end 5167 put a_gtot 0 p 5168 end 5169 5170 fn a6_gdat g ulong s ulong to void 5171 c = get a_cn 0 5172 if gt add c add s 3 `134217728` 5173 a6_die 5 7 c 5174 end 5175 if ne ar_need 29 add c add s 3 0 5176 ar_die 5177 end 5178 d = get ar_m add get ar_rb 89 g 5179 k = ulong 0 5180 while lt k s bound `1073741824` 5181 ar_bp 107 add c k ar_bg 2 add d k 5182 k = add k 1 5183 end 5184 while ne and k 3 0 bound 4 5185 ar_bp 107 add c k 0 5186 k = add k 1 5187 end 5188 put a_cn 0 add c k 5189 end 5190 5191 note the mode lines of this unit: 0 `@ng a64-enc` (encoder test), 1 `@ng a64` (compile, save pairs), 2 `@ng a64 split` 5192 note (compile, separate saves) 5193 text a_tmag "@ng a64-enc" 5194 text a_tmg1 "@ng a64" 5195 text a_tmg2 "@ng a64 split" 5196 text a_tmg3 "@ng a64 macho" 5197 fn a6_tlen k ulong to ulong 5198 if eq k 0 5199 ret len a_tmag 5200 end 5201 if eq k 1 5202 ret len a_tmg1 5203 end 5204 if eq k 2 5205 ret len a_tmg2 5206 end 5207 ret len a_tmg3 5208 end 5209 5210 fn a6_tch k ulong i ulong to ulong 5211 if eq k 0 5212 ret ulong get a_tmag i 5213 end 5214 if eq k 1 5215 ret ulong get a_tmg1 i 5216 end 5217 if eq k 2 5218 ret ulong get a_tmg2 i 5219 end 5220 ret ulong get a_tmg3 i 5221 end 5222 5223 note a6_isln k m: the mode line (length m, main's ng_mlb) is exactly mode line k 5224 fn a6_isln k ulong m ulong to bool 5225 n = a6_tlen k 5226 if ne m n 5227 ret false 5228 end 5229 i = ulong 0 5230 while lt i n bound 16 5231 if ne ng_mlb i a6_tch k i 5232 ret false 5233 end 5234 i = add i 1 5235 end 5236 ret true 5237 end 5238 5239 note a6_mode m: main's hook before it reads the payload: the mode the mode line (length m) names, 0 `@ng a64-enc`, 5240 note 1 `@ng a64`, 2 `@ng a64 split`, 3 `@ng a64 macho`; 255 when it is not a mode of this unit 5241 fn a6_mode m ulong to ulong 5242 k = ulong 0 5243 while lt k 4 bound 4 5244 if a6_isln k m 5245 ret k 5246 end 5247 k = add k 1 5248 end 5249 ret 255 5250 end 5251 5252 note a6_run a n: run mode a (a6_mode) on the payload i_in[0, n) main read; exits 5253 fn a6_run a ulong n ulong to void 5254 put a_inlen 0 n 5255 a6_init 5256 if eq a 0 5257 a6_enctest 5258 end 5259 if eq a 3 5260 put a_sform 0 0 5261 put a_tgt 0 1 5262 else 5263 put a_sform 0 sub a 1 5264 end 5265 a6_build n 5266 end 5267 5268 note a6_build n: read the ΩIR module in i_in[0, n), compile it, write the ELF to stdout, exit 0 5269 fn a6_build n ulong to void 5270 c = ir_read 0 n 5271 if ne c 0 5272 a6_die c 8 ir_badat 5273 end 5274 a6_comp 5275 a6_flush 5276 exit 0 5277 end 5278 5279 5280 note Pool operations name descriptors, never data addresses. The descriptor is loaded after operands. 5281 fn a6_spool o ulong op ulong to void 5282 if ne get a_tgt 0 0 5283 a6_unsup op 5284 end 5285 if eq op 111 5286 a6_pgrow o 5287 ret 5288 end 5289 if ge op 115 5290 a6_pio o op 5291 ret 5292 end 5293 g = get i_oim o 5294 a6_movi 16 ar_g 90 g 5295 r = ulong get i_ors o 5296 if eq op 112 5297 d = a6_dst r 5298 a6_ew a_ldrx d 16 1 0 0 5299 a6_fin r d 5300 ret 5301 end 5302 i = a6_src a6_arg o 1 17 5303 a6_ew a_ldrx 15 16 1 0 0 5304 a6_ew a_subsx 31 i 15 0 0 5305 a6_fx a_bcond 2 add a_tlab 3 5306 a6_ew a_ldrx 16 16 0 0 0 5307 t = ulong ar_u 87 g 5308 if eq op 113 5309 if a6_isft t 5310 d = a6_fdst r 5311 a6_ew a6_ff t a_ldrdr a_ldrsr d 16 i 1 0 5312 a6_ffin r d 5313 else 5314 d = a6_dst r 5315 a6_ew a6_ldf t d 16 i a6_sh1 t 0 5316 a6_fin r d 5317 end 5318 ret 5319 end 5320 v = a6_arg o 2 5321 if a6_isft t 5322 x = a6_fsrc v 29 5323 a6_ew a6_ff t a_strdr a_strsr x 16 i 1 0 5324 else 5325 x = a6_src v 15 5326 a6_ew a6_stf t x 16 i a6_sh1 t 0 5327 end 5328 end 5329 5330 note Exact canonical en_help instruction sequence from omc, including the branch over its body. 5331 note The ordinary call classification saves LR and protects values across the helper's clobbers. 5332 fn a6_pgrow o ulong to void 5333 g = get i_oim o 5334 a6_mvclr 5335 a6_mvadd 1 a6_loc a6_arg o 1 5336 a6_pmove 5337 a6_movi 0 ar_g 90 g 5338 a6_movi 2 a6_lsz ulong ar_u 87 g 5339 note The helper is a BL target, so retain D13 even though its body is inline. 5340 while ne and add get a_cn 0 4 63 0 5341 a6_emitw `3573751839` 5342 end 5343 entry = add get a_cn 0 4 5344 a6_emitw `335544362` 5345 a6_emitw `2852127721` 5346 a6_emitw `2852193258` 5347 a6_emitw `4181722403` 5348 a6_emitw `3942842719` 5349 a6_emitw `1409287209` 5350 a6_emitw `3531605988` 5351 a6_emitw `3405906052` 5352 a6_emitw `2596545861` 5353 a6_emitw `3036677093` 5354 a6_emitw `2596413765` 5355 a6_emitw `2436889765` 5356 a6_emitw `2457128101` 5357 a6_emitw `2596413542` 5358 a6_emitw `2436889798` 5359 a6_emitw `2457128134` 5360 a6_emitw `3943039167` 5361 a6_emitw `1409286793` 5362 a6_emitw `3019899142` 5363 a6_emitw `4181721376` 5364 a6_emitw `2852520929` 5365 a6_emitw `2852455394` 5366 a6_emitw `3531604003` 5367 a6_emitw `3531610888` 5368 a6_emitw `3556769793` 5369 a6_emitw `335544329` 5370 a6_emitw `3531603968` 5371 a6_emitw `2852455393` 5372 a6_emitw `3531604066` 5373 a6_emitw `3531605059` 5374 a6_emitw `2457862148` 5375 a6_emitw `3531603973` 5376 a6_emitw `3531611080` 5377 a6_emitw `3556769793` 5378 a6_emitw `2973760543` 5379 a6_emitw `1409286274` 5380 a6_emitw `4177527072` 5381 a6_emitw `4177528106` 5382 a6_emitw `3531603968` 5383 a6_emitw `3596551104` 5384 a6_emitw `2457862816` 5385 a6_emitw `3596551104` 5386 off = sub entry get a_cn 0 5387 a6_emitw or `2483027968` and shr off 2 `67108863` 5388 a6_mvfrom ulong get i_ors o 0 5389 end 5390 5391 fn a6_pio o ulong op ulong to void 5392 a6_mvclr 5393 a6_mvadd 0 a6_loc a6_arg o 1 5394 a6_mvadd 1 a6_loc a6_arg o 2 5395 a6_mvadd 2 a6_loc a6_arg o 3 5396 a6_pmove 5397 a6_movi 16 ar_g 90 get i_oim o 5398 a6_ew a_ldrx 15 16 1 0 0 5399 a6_ew a_subsx 31 1 15 0 0 5400 a6_fx a_bcond 8 add a_tlab 3 5401 a6_ew a_subx 15 15 1 0 0 5402 a6_ew a_subsx 31 2 15 0 0 5403 a6_fx a_bcond 8 add a_tlab 3 5404 a6_ew a_ldrx 16 16 0 0 0 5405 a6_ew a_addx 1 16 1 0 0 5406 nr = ulong 64 5407 if eq op 115 5408 nr = 63 5409 end 5410 a6_ew a_movzx 8 nr 0 0 0 5411 a6_ew a_svc 0 0 0 0 0 5412 a6_mvfrom ulong get i_ors o 0 5413 end 5414 5415 fn a6_hostcall op ulong to bool 5416 ret or or eq op 110 eq op 111 or eq op 115 eq op 116 5417 end 5418 5419 note Linux entry layout matches omc hargs: argc, argv and envp stay on the original kernel stack. 5420 note x18 is excluded from the allocator and retains that initial stack only for modules using env words. 5421 note Host ops are call boundaries: x0..x14 may be scratch. The kernel environment remains read-only. 5422 fn a6_hasenv to bool 5423 for j ulong get i_n 5 bound `4194305` 5424 o = add j 1 5425 if eq get i_oop o 110 5426 w = get i_oim o 5427 if or eq w 136 eq w 137 5428 ret true 5429 end 5430 end 5431 end 5432 ret false 5433 end 5434 5435 fn a6_envbr pos ulong form ulong reg ulong to void 5436 a6_putw pos a6_enc form reg a6_wd pos get a_cn 0 0 0 0 5437 end 5438 5439 fn a6_henv o ulong w ulong to void 5440 if ne get a_tgt 0 0 5441 a6_unsup w 5442 end 5443 if eq w 137 5444 a = a6_arg o 2 5445 a6_aref a 5446 b = a6_src a 16 5447 off = a6_src a6_arg o 3 17 5448 a6_ew a_addx 17 b off 0 0 5449 a6_mvclr 5450 a6_mvadd 0 a6_loc a6_arg o 1 5451 a6_mvadd 1 17 5452 limit = a6_loc a6_arg o 4 5453 a6_mvadd 2 limit 5454 a6_pmove 5455 end 5456 a6_ew a_ldrx 3 18 0 0 0 5457 a6_ew a_addxi 3 3 2 0 0 5458 a6_ew a_addx 3 18 3 0 3 5459 if eq w 136 5460 a6_movi 0 0 5461 loop = get a_cn 0 5462 a6_ew a_ldrx 4 3 0 0 0 5463 done = get a_cn 0 5464 a6_emitw 0 5465 a6_ew a_addxi 0 0 1 0 0 5466 a6_ew a_addxi 3 3 8 0 0 5467 a6_ew a_b a6_wd get a_cn 0 loop 0 0 0 0 5468 a6_envbr done a_cbzx 4 5469 else 5470 loop = get a_cn 0 5471 a6_ew a_ldrx 4 3 0 0 0 5472 a6_fx a_cbzx 4 add a_tlab 3 5473 found = get a_cn 0 5474 a6_emitw 0 5475 a6_ew a_subxi 0 0 1 0 0 5476 a6_ew a_addxi 3 3 8 0 0 5477 a6_ew a_b a6_wd get a_cn 0 loop 0 0 0 0 5478 a6_envbr found a_cbzx 0 5479 a6_movi 5 0 5480 scan = get a_cn 0 5481 a6_ew a_ldrbr 6 4 5 0 0 5482 done = get a_cn 0 5483 a6_emitw 0 5484 a6_ew a_addxi 5 5 1 0 0 5485 a6_ew a_b a6_wd get a_cn 0 scan 0 0 0 0 5486 a6_envbr done a_cbzx 6 5487 a6_ew a_subsx 31 5 2 0 0 5488 small = get a_cn 0 5489 a6_emitw 0 5490 a6_movi 0 0 5491 copy = get a_cn 0 5492 a6_ew a_subsx 31 0 5 0 0 5493 done = get a_cn 0 5494 a6_emitw 0 5495 a6_ew a_ldrbr 6 4 0 0 0 5496 a6_ew a_strbr 6 1 0 0 0 5497 a6_ew a_addxi 0 0 1 0 0 5498 a6_ew a_b a6_wd get a_cn 0 copy 0 0 0 0 5499 a6_envbr done a_bcond 0 5500 a6_mov 0 5 5501 finish = get a_cn 0 5502 a6_emitw 0 5503 a6_envbr small a_bcond 8 5504 a6_movi 0 `18446744073709551511` 5505 a6_putw finish a6_enc a_b a6_wd finish get a_cn 0 0 0 0 0 5506 end 5507 r = ulong get i_ors o 5508 if ne r 0 5509 a6_mvfrom r 0 5510 end 5511 end