1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 #if defined(_TARGET_ARM64_)
7 // The ARM64 instructions are all 32 bits in size.
8 // we use an unsigned int to hold the encoded instructions.
9 // This typedef defines the type that we use to hold encoded instructions.
11 typedef unsigned int code_t;
13 static bool strictArmAsm;
15 /************************************************************************/
16 /* Routines that compute the size of / encode instructions */
17 /************************************************************************/
21 /************************************************************************/
22 /* Debug-only routines to display instructions */
23 /************************************************************************/
25 const char* emitFPregName(unsigned reg, bool varName = true);
26 const char* emitVectorRegName(regNumber reg);
28 void emitDispInst(instruction ins);
29 void emitDispImm(ssize_t imm, bool addComma, bool alwaysHex = false);
30 void emitDispFloatZero();
31 void emitDispFloatImm(ssize_t imm8);
32 void emitDispImmOptsLSL12(ssize_t imm, insOpts opt);
33 void emitDispCond(insCond cond);
34 void emitDispFlags(insCflags flags);
35 void emitDispBarrier(insBarrier barrier);
36 void emitDispShiftOpts(insOpts opt);
37 void emitDispExtendOpts(insOpts opt);
38 void emitDispLSExtendOpts(insOpts opt);
39 void emitDispReg(regNumber reg, emitAttr attr, bool addComma);
40 void emitDispVectorReg(regNumber reg, insOpts opt, bool addComma);
41 void emitDispVectorRegIndex(regNumber reg, emitAttr elemsize, ssize_t index, bool addComma);
42 void emitDispArrangement(insOpts opt);
43 void emitDispShiftedReg(regNumber reg, insOpts opt, ssize_t imm, emitAttr attr);
44 void emitDispExtendReg(regNumber reg, insOpts opt, ssize_t imm);
45 void emitDispAddrRI(regNumber reg, insOpts opt, ssize_t imm);
46 void emitDispAddrRRExt(regNumber reg1, regNumber reg2, insOpts opt, bool isScaled, emitAttr size);
48 void emitDispIns(instrDesc* id,
58 /************************************************************************/
59 /* Private members that deal with target-dependent instr. descriptors */
60 /************************************************************************/
63 instrDesc* emitNewInstrCallDir(int argCnt,
64 VARSET_VALARG_TP GCvars,
68 emitAttr secondRetSize);
70 instrDesc* emitNewInstrCallInd(int argCnt,
72 VARSET_VALARG_TP GCvars,
76 emitAttr secondRetSize);
78 /************************************************************************/
79 /* Private helpers for instruction output */
80 /************************************************************************/
83 bool emitInsIsCompare(instruction ins);
84 bool emitInsIsLoad(instruction ins);
85 bool emitInsIsStore(instruction ins);
86 bool emitInsIsLoadOrStore(instruction ins);
87 emitAttr emitInsAdjustLoadStoreAttr(instruction ins, emitAttr attr);
88 emitAttr emitInsTargetRegSize(instrDesc* id);
89 emitAttr emitInsLoadStoreSize(instrDesc* id);
91 emitter::insFormat emitInsFormat(instruction ins);
92 emitter::code_t emitInsCode(instruction ins, insFormat fmt);
94 // Generate code for a load or store operation and handle the case of contained GT_LEA op1 with [base + index<<scale +
96 void emitInsLoadStoreOp(instruction ins, emitAttr attr, regNumber dataReg, GenTreeIndir* indir);
98 // Emit the 32-bit Arm64 instruction 'code' into the 'dst' buffer
99 static unsigned emitOutput_Instr(BYTE* dst, code_t code);
101 // A helper method to return the natural scale for an EA 'size'
102 static unsigned NaturalScale_helper(emitAttr size);
104 // A helper method to perform a Rotate-Right shift operation
105 static UINT64 ROR_helper(UINT64 value, unsigned sh, unsigned width);
107 // A helper method to perform a 'NOT' bitwise complement operation
108 static UINT64 NOT_helper(UINT64 value, unsigned width);
110 // A helper method to perform a bit Replicate operation
111 static UINT64 Replicate_helper(UINT64 value, unsigned width, emitAttr size);
113 /************************************************************************
115 * This union is used to to encode/decode the special ARM64 immediate values
116 * that is listed as imm(N,r,s) and referred to as 'bitmask immediate'
122 unsigned immS : 6; // bits 0..5
123 unsigned immR : 6; // bits 6..11
124 unsigned immN : 1; // bits 12
126 unsigned immNRS; // concat N:R:S forming a 13-bit unsigned immediate
129 /************************************************************************
131 * Convert between a 64-bit immediate and its 'bitmask immediate'
132 * representation imm(i16,hw)
135 static emitter::bitMaskImm emitEncodeBitMaskImm(INT64 imm, emitAttr size);
137 static INT64 emitDecodeBitMaskImm(const emitter::bitMaskImm bmImm, emitAttr size);
139 /************************************************************************
141 * This union is used to to encode/decode the special ARM64 immediate values
142 * that is listed as imm(i16,hw) and referred to as 'halfword immediate'
148 unsigned immVal : 16; // bits 0..15
149 unsigned immHW : 2; // bits 16..17
151 unsigned immHWVal; // concat HW:Val forming a 18-bit unsigned immediate
154 /************************************************************************
156 * Convert between a 64-bit immediate and its 'halfword immediate'
157 * representation imm(i16,hw)
160 static emitter::halfwordImm emitEncodeHalfwordImm(INT64 imm, emitAttr size);
162 static INT64 emitDecodeHalfwordImm(const emitter::halfwordImm hwImm, emitAttr size);
164 /************************************************************************
166 * This union is used to encode/decode the special ARM64 immediate values
167 * that is listed as imm(i16,by) and referred to as 'byteShifted immediate'
170 union byteShiftedImm {
173 unsigned immVal : 8; // bits 0..7
174 unsigned immBY : 2; // bits 8..9
175 unsigned immOnes : 1; // bit 10
177 unsigned immBSVal; // concat Ones:BY:Val forming a 10-bit unsigned immediate
180 /************************************************************************
182 * Convert between a 16/32-bit immediate and its 'byteShifted immediate'
183 * representation imm(i8,by)
186 static emitter::byteShiftedImm emitEncodeByteShiftedImm(INT64 imm, emitAttr size, bool allow_MSL);
188 static INT32 emitDecodeByteShiftedImm(const emitter::byteShiftedImm bsImm, emitAttr size);
190 /************************************************************************
192 * This union is used to to encode/decode the special ARM64 immediate values
193 * that are use for FMOV immediate and referred to as 'float 8-bit immediate'
199 unsigned immMant : 4; // bits 0..3
200 unsigned immExp : 3; // bits 4..6
201 unsigned immSign : 1; // bits 7
203 unsigned immFPIVal; // concat Sign:Exp:Mant forming an 8-bit unsigned immediate
206 /************************************************************************
208 * Convert between a double and its 'float 8-bit immediate' representation
211 static emitter::floatImm8 emitEncodeFloatImm8(double immDbl);
213 static double emitDecodeFloatImm8(const emitter::floatImm8 fpImm);
215 /************************************************************************
217 * This union is used to to encode/decode the cond, nzcv and imm5 values for
218 * instructions that use them in the small constant immediate field
224 insCond cond : 4; // bits 0..3
225 insCflags flags : 4; // bits 4..7
226 unsigned imm5 : 5; // bits 8..12
228 unsigned immCFVal; // concat imm5:flags:cond forming an 13-bit unsigned immediate
231 // Returns an encoding for the specified register used in the 'Rd' position
232 static code_t insEncodeReg_Rd(regNumber reg);
234 // Returns an encoding for the specified register used in the 'Rt' position
235 static code_t insEncodeReg_Rt(regNumber reg);
237 // Returns an encoding for the specified register used in the 'Rn' position
238 static code_t insEncodeReg_Rn(regNumber reg);
240 // Returns an encoding for the specified register used in the 'Rm' position
241 static code_t insEncodeReg_Rm(regNumber reg);
243 // Returns an encoding for the specified register used in the 'Ra' position
244 static code_t insEncodeReg_Ra(regNumber reg);
246 // Returns an encoding for the specified register used in the 'Vd' position
247 static code_t insEncodeReg_Vd(regNumber reg);
249 // Returns an encoding for the specified register used in the 'Vt' position
250 static code_t insEncodeReg_Vt(regNumber reg);
252 // Returns an encoding for the specified register used in the 'Vn' position
253 static code_t insEncodeReg_Vn(regNumber reg);
255 // Returns an encoding for the specified register used in the 'Vm' position
256 static code_t insEncodeReg_Vm(regNumber reg);
258 // Returns an encoding for the specified register used in the 'Va' position
259 static code_t insEncodeReg_Va(regNumber reg);
261 // Returns an encoding for the imm which represents the condition code.
262 static code_t insEncodeCond(insCond cond);
264 // Returns an encoding for the imm whioch represents the 'condition code'
265 // with the lowest bit inverted (marked by invert(<cond>) in the architecture manual.
266 static code_t insEncodeInvertedCond(insCond cond);
268 // Returns an encoding for the imm which represents the flags.
269 static code_t insEncodeFlags(insCflags flags);
271 // Returns the encoding for the Shift Count bits to be used for Arm64 encodings
272 static code_t insEncodeShiftCount(ssize_t imm, emitAttr size);
274 // Returns the encoding to select the datasize for most Arm64 instructions
275 static code_t insEncodeDatasize(emitAttr size);
277 // Returns the encoding to select the datasize for the general load/store Arm64 instructions
278 static code_t insEncodeDatasizeLS(code_t code, emitAttr size);
280 // Returns the encoding to select the datasize for the vector load/store Arm64 instructions
281 static code_t insEncodeDatasizeVLS(code_t code, emitAttr size);
283 // Returns the encoding to select the datasize for the vector load/store pair Arm64 instructions
284 static code_t insEncodeDatasizeVPLS(code_t code, emitAttr size);
286 // Returns the encoding to select the datasize for bitfield Arm64 instructions
287 static code_t insEncodeDatasizeBF(code_t code, emitAttr size);
289 // Returns the encoding to select the vectorsize for SIMD Arm64 instructions
290 static code_t insEncodeVectorsize(emitAttr size);
292 // Returns the encoding to select 'index' for an Arm64 vector elem instruction
293 static code_t insEncodeVectorIndex(emitAttr elemsize, ssize_t index);
295 // Returns the encoding to select 'index2' for an Arm64 'ins' elem instruction
296 static code_t insEncodeVectorIndex2(emitAttr elemsize, ssize_t index2);
298 // Returns the encoding to select 'index' for an Arm64 'mul' elem instruction
299 static code_t insEncodeVectorIndexLMH(emitAttr elemsize, ssize_t index);
301 // Returns the encoding to shift by 'shift' bits for an Arm64 vector or scalar instruction
302 static code_t insEncodeVectorShift(emitAttr size, ssize_t shift);
304 // Returns the encoding to select the 1/2/4/8 byte elemsize for an Arm64 vector instruction
305 static code_t insEncodeElemsize(emitAttr size);
307 // Returns the encoding to select the 4/8 byte elemsize for an Arm64 float vector instruction
308 static code_t insEncodeFloatElemsize(emitAttr size);
310 // Returns the encoding to select the index for an Arm64 float vector by elem instruction
311 static code_t insEncodeFloatIndex(emitAttr elemsize, ssize_t index);
313 // Returns the encoding to select the 'conversion' operation for a type 'fmt' Arm64 instruction
314 static code_t insEncodeConvertOpt(insFormat fmt, insOpts conversion);
316 // Returns the encoding to have the Rn register of a ld/st reg be Pre/Post/Not indexed updated
317 static code_t insEncodeIndexedOpt(insOpts opt);
319 // Returns the encoding to have the Rn register of a ld/st pair be Pre/Post/Not indexed updated
320 static code_t insEncodePairIndexedOpt(instruction ins, insOpts opt);
322 // Returns the encoding to apply a Shift Type on the Rm register
323 static code_t insEncodeShiftType(insOpts opt);
325 // Returns the encoding to apply a 12 bit left shift to the immediate
326 static code_t insEncodeShiftImm12(insOpts opt);
328 // Returns the encoding to have the Rm register use an extend operation
329 static code_t insEncodeExtend(insOpts opt);
331 // Returns the encoding to scale the Rm register by {0,1,2,3,4} in an extend operation
332 static code_t insEncodeExtendScale(ssize_t imm);
334 // Returns the encoding to have the Rm register be auto scaled by the ld/st size
335 static code_t insEncodeReg3Scale(bool isScaled);
337 // Returns true if 'reg' represents an integer register.
338 static bool isIntegerRegister(regNumber reg)
340 return (reg >= REG_INT_FIRST) && (reg <= REG_INT_LAST);
343 // Returns true if 'value' is a legal unsigned immediate 8 bit encoding (such as for fMOV).
344 static bool isValidUimm8(ssize_t value)
346 return (0 <= value) && (value <= 0xFFLL);
349 // Returns true if 'value' is a legal unsigned immediate 12 bit encoding (such as for CMP, CMN).
350 static bool isValidUimm12(ssize_t value)
352 return (0 <= value) && (value <= 0xFFFLL);
355 // Returns true if 'value' is a legal unsigned immediate 16 bit encoding (such as for MOVZ, MOVN, MOVK).
356 static bool isValidUimm16(ssize_t value)
358 return (0 <= value) && (value <= 0xFFFFLL);
361 // Returns true if 'value' is a legal signed immediate 26 bit encoding (such as for B or BL).
362 static bool isValidSimm26(ssize_t value)
364 return (-0x2000000LL <= value) && (value <= 0x1FFFFFFLL);
367 // Returns true if 'value' is a legal signed immediate 19 bit encoding (such as for B.cond, CBNZ, CBZ).
368 static bool isValidSimm19(ssize_t value)
370 return (-0x40000LL <= value) && (value <= 0x3FFFFLL);
373 // Returns true if 'value' is a legal signed immediate 14 bit encoding (such as for TBNZ, TBZ).
374 static bool isValidSimm14(ssize_t value)
376 return (-0x2000LL <= value) && (value <= 0x1FFFLL);
379 // Returns true if 'value' represents a valid 'bitmask immediate' encoding.
380 static bool isValidImmNRS(size_t value, emitAttr size)
382 return (value >= 0) && (value < 0x2000);
383 } // any unsigned 13-bit immediate
385 // Returns true if 'value' represents a valid 'halfword immediate' encoding.
386 static bool isValidImmHWVal(size_t value, emitAttr size)
388 return (value >= 0) && (value < 0x40000);
389 } // any unsigned 18-bit immediate
391 // Returns true if 'value' represents a valid 'byteShifted immediate' encoding.
392 static bool isValidImmBSVal(size_t value, emitAttr size)
394 return (value >= 0) && (value < 0x800);
395 } // any unsigned 11-bit immediate
397 // The return value replaces REG_ZR with REG_SP
398 static regNumber encodingZRtoSP(regNumber reg)
400 return (reg == REG_ZR) ? REG_SP : reg;
401 } // ZR (R31) encodes the SP register
403 // The return value replaces REG_SP with REG_ZR
404 static regNumber encodingSPtoZR(regNumber reg)
406 return (reg == REG_SP) ? REG_ZR : reg;
407 } // SP is encoded using ZR (R31)
409 // For the given 'ins' returns the reverse instruction, if one exists, otherwise returns INS_INVALID
410 static instruction insReverse(instruction ins);
412 // For the given 'datasize' and 'elemsize' returns the insOpts that specifies the vector register arrangement
413 static insOpts optMakeArrangement(emitAttr datasize, emitAttr elemsize);
415 // For the given 'datasize' and 'opt' returns true if it specifies a valid vector register arrangement
416 static bool isValidArrangement(emitAttr datasize, insOpts opt);
418 // For the given 'arrangement' returns the 'datasize' specified by the vector register arrangement
419 static emitAttr optGetDatasize(insOpts arrangement);
421 // For the given 'arrangement' returns the 'elemsize' specified by the vector register arrangement
422 static emitAttr optGetElemsize(insOpts arrangement);
424 // For the given 'arrangement' returns the 'widen-arrangement' specified by the vector register arrangement
425 static insOpts optWidenElemsize(insOpts arrangement);
427 // For the given 'conversion' returns the 'dstsize' specified by the conversion option
428 static emitAttr optGetDstsize(insOpts conversion);
430 // For the given 'conversion' returns the 'srcsize' specified by the conversion option
431 static emitAttr optGetSrcsize(insOpts conversion);
433 // For the given 'datasize', 'elemsize' and 'index' returns true, if it specifies a valid 'index'
434 // for an element of size 'elemsize' in a vector register of size 'datasize'
435 static bool isValidVectorIndex(emitAttr datasize, emitAttr elemsize, ssize_t index);
437 /************************************************************************/
438 /* Public inline informational methods */
439 /************************************************************************/
442 // true if this 'imm' can be encoded as a input operand to a mov instruction
443 static bool emitIns_valid_imm_for_mov(INT64 imm, emitAttr size);
445 // true if this 'imm' can be encoded as a input operand to a vector movi instruction
446 static bool emitIns_valid_imm_for_movi(INT64 imm, emitAttr size);
448 // true if this 'immDbl' can be encoded as a input operand to a fmov instruction
449 static bool emitIns_valid_imm_for_fmov(double immDbl);
451 // true if this 'imm' can be encoded as a input operand to an add instruction
452 static bool emitIns_valid_imm_for_add(INT64 imm, emitAttr size = EA_8BYTE);
454 // true if this 'imm' can be encoded as a input operand to a cmp instruction
455 static bool emitIns_valid_imm_for_cmp(INT64 imm, emitAttr size);
457 // true if this 'imm' can be encoded as a input operand to an alu instruction
458 static bool emitIns_valid_imm_for_alu(INT64 imm, emitAttr size);
460 // true if this 'imm' can be encoded as the offset in a ldr/str instruction
461 static bool emitIns_valid_imm_for_ldst_offset(INT64 imm, emitAttr size);
463 // true if 'imm' can use the left shifted by 12 bits encoding
464 static bool canEncodeWithShiftImmBy12(INT64 imm);
466 // Normalize the 'imm' so that the upper bits, as defined by 'size' are zero
467 static INT64 normalizeImm64(INT64 imm, emitAttr size);
469 // Normalize the 'imm' so that the upper bits, as defined by 'size' are zero
470 static INT32 normalizeImm32(INT32 imm, emitAttr size);
472 // true if 'imm' can be encoded using a 'bitmask immediate', also returns the encoding if wbBMI is non-null
473 static bool canEncodeBitMaskImm(INT64 imm, emitAttr size, emitter::bitMaskImm* wbBMI = nullptr);
475 // true if 'imm' can be encoded using a 'halfword immediate', also returns the encoding if wbHWI is non-null
476 static bool canEncodeHalfwordImm(INT64 imm, emitAttr size, emitter::halfwordImm* wbHWI = nullptr);
478 // true if 'imm' can be encoded using a 'byteShifted immediate', also returns the encoding if wbBSI is non-null
479 static bool canEncodeByteShiftedImm(INT64 imm, emitAttr size, bool allow_MSL, emitter::byteShiftedImm* wbBSI = nullptr);
481 // true if 'immDbl' can be encoded using a 'float immediate', also returns the encoding if wbFPI is non-null
482 static bool canEncodeFloatImm8(double immDbl, emitter::floatImm8* wbFPI = nullptr);
484 // Returns the number of bits used by the given 'size'.
485 inline static unsigned getBitWidth(emitAttr size)
487 assert(size <= EA_8BYTE);
488 return (unsigned)size * BITS_PER_BYTE;
491 // Returns true if the imm represents a valid bit shift or bit position for the given 'size' [0..31] or [0..63]
492 inline static unsigned isValidImmShift(ssize_t imm, emitAttr size)
494 return (imm >= 0) && (imm < getBitWidth(size));
497 inline static bool isValidGeneralDatasize(emitAttr size)
499 return (size == EA_8BYTE) || (size == EA_4BYTE);
502 inline static bool isValidScalarDatasize(emitAttr size)
504 return (size == EA_8BYTE) || (size == EA_4BYTE);
507 inline static bool isValidVectorDatasize(emitAttr size)
509 return (size == EA_16BYTE) || (size == EA_8BYTE);
512 inline static bool isValidGeneralLSDatasize(emitAttr size)
514 return (size == EA_8BYTE) || (size == EA_4BYTE) || (size == EA_2BYTE) || (size == EA_1BYTE);
517 inline static bool isValidVectorLSDatasize(emitAttr size)
519 return (size == EA_16BYTE) || (size == EA_8BYTE) || (size == EA_4BYTE) || (size == EA_2BYTE) || (size == EA_1BYTE);
522 inline static bool isValidVectorLSPDatasize(emitAttr size)
524 return (size == EA_16BYTE) || (size == EA_8BYTE) || (size == EA_4BYTE);
527 inline static bool isValidVectorElemsize(emitAttr size)
529 return (size == EA_8BYTE) || (size == EA_4BYTE) || (size == EA_2BYTE) || (size == EA_1BYTE);
532 inline static bool isValidVectorFcvtsize(emitAttr size)
534 return (size == EA_8BYTE) || (size == EA_4BYTE) || (size == EA_2BYTE);
537 inline static bool isValidVectorElemsizeFloat(emitAttr size)
539 return (size == EA_8BYTE) || (size == EA_4BYTE);
542 inline static bool isGeneralRegister(regNumber reg)
544 return (reg >= REG_INT_FIRST) && (reg <= REG_LR);
547 inline static bool isGeneralRegisterOrZR(regNumber reg)
549 return (reg >= REG_INT_FIRST) && (reg <= REG_ZR);
552 inline static bool isGeneralRegisterOrSP(regNumber reg)
554 return isGeneralRegister(reg) || (reg == REG_SP);
555 } // Includes REG_SP, Excludes REG_ZR
557 inline static bool isVectorRegister(regNumber reg)
559 return (reg >= REG_FP_FIRST && reg <= REG_FP_LAST);
562 inline static bool isFloatReg(regNumber reg)
564 return isVectorRegister(reg);
567 inline static bool insOptsNone(insOpts opt)
569 return (opt == INS_OPTS_NONE);
572 inline static bool insOptsIndexed(insOpts opt)
574 return (opt == INS_OPTS_PRE_INDEX) || (opt == INS_OPTS_POST_INDEX);
577 inline static bool insOptsPreIndex(insOpts opt)
579 return (opt == INS_OPTS_PRE_INDEX);
582 inline static bool insOptsPostIndex(insOpts opt)
584 return (opt == INS_OPTS_POST_INDEX);
587 inline static bool insOptsLSL12(insOpts opt) // special 12-bit shift only used for imm12
589 return (opt == INS_OPTS_LSL12);
592 inline static bool insOptsAnyShift(insOpts opt)
594 return ((opt >= INS_OPTS_LSL) && (opt <= INS_OPTS_ROR));
597 inline static bool insOptsAluShift(insOpts opt) // excludes ROR
599 return ((opt >= INS_OPTS_LSL) && (opt <= INS_OPTS_ASR));
602 inline static bool insOptsVectorImmShift(insOpts opt)
604 return ((opt == INS_OPTS_LSL) || (opt == INS_OPTS_MSL));
607 inline static bool insOptsLSL(insOpts opt)
609 return (opt == INS_OPTS_LSL);
612 inline static bool insOptsLSR(insOpts opt)
614 return (opt == INS_OPTS_LSR);
617 inline static bool insOptsASR(insOpts opt)
619 return (opt == INS_OPTS_ASR);
622 inline static bool insOptsROR(insOpts opt)
624 return (opt == INS_OPTS_ROR);
627 inline static bool insOptsAnyExtend(insOpts opt)
629 return ((opt >= INS_OPTS_UXTB) && (opt <= INS_OPTS_SXTX));
632 inline static bool insOptsLSExtend(insOpts opt)
634 return ((opt == INS_OPTS_NONE) || (opt == INS_OPTS_LSL) || (opt == INS_OPTS_UXTW) || (opt == INS_OPTS_SXTW) ||
635 (opt == INS_OPTS_UXTX) || (opt == INS_OPTS_SXTX));
638 inline static bool insOpts32BitExtend(insOpts opt)
640 return ((opt == INS_OPTS_UXTW) || (opt == INS_OPTS_SXTW));
643 inline static bool insOpts64BitExtend(insOpts opt)
645 return ((opt == INS_OPTS_UXTX) || (opt == INS_OPTS_SXTX));
648 inline static bool insOptsAnyArrangement(insOpts opt)
650 return ((opt >= INS_OPTS_8B) && (opt <= INS_OPTS_2D));
653 inline static bool insOptsConvertFloatToFloat(insOpts opt)
655 return ((opt >= INS_OPTS_S_TO_D) && (opt <= INS_OPTS_D_TO_H));
658 inline static bool insOptsConvertFloatToInt(insOpts opt)
660 return ((opt >= INS_OPTS_S_TO_4BYTE) && (opt <= INS_OPTS_D_TO_8BYTE));
663 inline static bool insOptsConvertIntToFloat(insOpts opt)
665 return ((opt >= INS_OPTS_4BYTE_TO_S) && (opt <= INS_OPTS_8BYTE_TO_D));
668 static bool isValidImmCond(ssize_t imm);
669 static bool isValidImmCondFlags(ssize_t imm);
670 static bool isValidImmCondFlagsImm5(ssize_t imm);
672 /************************************************************************/
673 /* The public entry points to output instructions */
674 /************************************************************************/
677 void emitIns(instruction ins);
679 void emitIns_I(instruction ins, emitAttr attr, ssize_t imm);
681 void emitIns_R(instruction ins, emitAttr attr, regNumber reg);
683 void emitIns_R_I(instruction ins, emitAttr attr, regNumber reg, ssize_t imm, insOpts opt = INS_OPTS_NONE);
685 void emitIns_R_F(instruction ins, emitAttr attr, regNumber reg, double immDbl, insOpts opt = INS_OPTS_NONE);
687 void emitIns_R_R(instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, insOpts opt = INS_OPTS_NONE);
689 void emitIns_R_R(instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, insFlags flags)
691 emitIns_R_R(ins, attr, reg1, reg2);
695 instruction ins, emitAttr attr, regNumber reg1, ssize_t imm1, ssize_t imm2, insOpts opt = INS_OPTS_NONE);
698 instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, ssize_t imm, insOpts opt = INS_OPTS_NONE);
700 // Checks for a large immediate that needs a second instruction
701 void emitIns_R_R_Imm(instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, ssize_t imm);
704 instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, regNumber reg3, insOpts opt = INS_OPTS_NONE);
706 void emitIns_R_R_R_I(instruction ins,
712 insOpts opt = INS_OPTS_NONE,
713 emitAttr attrReg2 = EA_UNKNOWN);
715 void emitIns_R_R_R_Ext(instruction ins,
720 insOpts opt = INS_OPTS_NONE,
721 int shiftAmount = -1);
723 void emitIns_R_R_I_I(instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, int imm1, int imm2);
725 void emitIns_R_R_R_R(instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, regNumber reg3, regNumber reg4);
727 void emitIns_R_COND(instruction ins, emitAttr attr, regNumber reg, insCond cond);
729 void emitIns_R_R_COND(instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, insCond cond);
731 void emitIns_R_R_R_COND(instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, regNumber reg3, insCond cond);
733 void emitIns_R_R_FLAGS_COND(
734 instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, insCflags flags, insCond cond);
736 void emitIns_R_I_FLAGS_COND(instruction ins, emitAttr attr, regNumber reg1, int imm, insCflags flags, insCond cond);
738 void emitIns_BARR(instruction ins, insBarrier barrier);
740 void emitIns_C(instruction ins, emitAttr attr, CORINFO_FIELD_HANDLE fdlHnd, int offs);
742 void emitIns_S(instruction ins, emitAttr attr, int varx, int offs);
744 void emitIns_S_R(instruction ins, emitAttr attr, regNumber ireg, int varx, int offs);
746 void emitIns_S_S_R_R(
747 instruction ins, emitAttr attr, emitAttr attr2, regNumber ireg, regNumber ireg2, int varx, int offs);
749 void emitIns_R_S(instruction ins, emitAttr attr, regNumber ireg, int varx, int offs);
751 void emitIns_R_R_S_S(
752 instruction ins, emitAttr attr, emitAttr attr2, regNumber ireg, regNumber ireg2, int varx, int offs);
754 void emitIns_S_I(instruction ins, emitAttr attr, int varx, int offs, int val);
757 instruction ins, emitAttr attr, regNumber reg, regNumber tmpReg, CORINFO_FIELD_HANDLE fldHnd, int offs);
759 void emitIns_C_R(instruction ins, emitAttr attr, CORINFO_FIELD_HANDLE fldHnd, regNumber reg, int offs);
761 void emitIns_C_I(instruction ins, emitAttr attr, CORINFO_FIELD_HANDLE fdlHnd, ssize_t offs, ssize_t val);
763 void emitIns_R_L(instruction ins, emitAttr attr, BasicBlock* dst, regNumber reg);
765 void emitIns_R_D(instruction ins, emitAttr attr, unsigned offs, regNumber reg);
767 void emitIns_J_R(instruction ins, emitAttr attr, BasicBlock* dst, regNumber reg);
769 void emitIns_J_R_I(instruction ins, emitAttr attr, BasicBlock* dst, regNumber reg, int imm);
771 void emitIns_I_AR(instruction ins, emitAttr attr, int val, regNumber reg, int offs);
773 void emitIns_R_AR(instruction ins, emitAttr attr, regNumber ireg, regNumber reg, int offs);
775 void emitIns_R_AI(instruction ins, emitAttr attr, regNumber ireg, ssize_t disp);
777 void emitIns_AR_R(instruction ins, emitAttr attr, regNumber ireg, regNumber reg, int offs);
779 void emitIns_R_ARR(instruction ins, emitAttr attr, regNumber ireg, regNumber reg, regNumber rg2, int disp);
781 void emitIns_ARR_R(instruction ins, emitAttr attr, regNumber ireg, regNumber reg, regNumber rg2, int disp);
784 instruction ins, emitAttr attr, regNumber ireg, regNumber reg, regNumber rg2, unsigned mul, int disp);
789 // I have included here, but commented out, all the values used by the x86 emitter.
790 // However, ARM has a much reduced instruction set, and so the ARM emitter only
791 // supports a subset of the x86 variants. By leaving them commented out, it becomes
792 // a compile time error if code tries to use them (and hopefully see this comment
793 // and know why they are unavailible on ARM), while making it easier to stay
794 // in-sync with x86 and possibly add them back in if needed.
796 EC_FUNC_TOKEN, // Direct call to a helper/static/nonvirtual/global method
797 // EC_FUNC_TOKEN_INDIR, // Indirect call to a helper/static/nonvirtual/global method
798 EC_FUNC_ADDR, // Direct call to an absolute address
800 // EC_FUNC_VIRTUAL, // Call to a virtual method (using the vtable)
801 EC_INDIR_R, // Indirect call via register
802 // EC_INDIR_SR, // Indirect call via stack-reference (local var)
803 // EC_INDIR_C, // Indirect call via static class var
804 // EC_INDIR_ARD, // Indirect call via an addressing mode
809 void emitIns_Call(EmitCallType callType,
810 CORINFO_METHOD_HANDLE methHnd,
811 INDEBUG_LDISASM_COMMA(CORINFO_SIG_INFO* sigInfo) // used to report call sites to the EE
815 emitAttr secondRetSize,
816 VARSET_VALARG_TP ptrVars,
819 IL_OFFSETX ilOffset = BAD_IL_OFFSET,
820 regNumber ireg = REG_NA,
821 regNumber xreg = REG_NA,
826 bool isProfLeaveCB = false);
828 BYTE* emitOutputLJ(insGroup* ig, BYTE* dst, instrDesc* i);
829 unsigned emitOutputCall(insGroup* ig, BYTE* dst, instrDesc* i, code_t code);
830 BYTE* emitOutputLoadLabel(BYTE* dst, BYTE* srcAddr, BYTE* dstAddr, instrDescJmp* id);
831 BYTE* emitOutputShortBranch(BYTE* dst, instruction ins, insFormat fmt, ssize_t distVal, instrDescJmp* id);
832 BYTE* emitOutputShortAddress(BYTE* dst, instruction ins, insFormat fmt, ssize_t distVal, regNumber reg);
833 BYTE* emitOutputShortConstant(
834 BYTE* dst, instruction ins, insFormat fmt, ssize_t distVal, regNumber reg, emitAttr opSize);
836 /*****************************************************************************
838 * Given an instrDesc, return true if it's a conditional jump.
841 inline bool emitIsCondJump(instrDesc* jmp)
843 return ((jmp->idInsFmt() == IF_BI_0B) || (jmp->idInsFmt() == IF_BI_1A) || (jmp->idInsFmt() == IF_BI_1B) ||
844 (jmp->idInsFmt() == IF_LARGEJMP));
847 /*****************************************************************************
849 * Given a instrDesc, return true if it's an unconditional jump.
852 inline bool emitIsUncondJump(instrDesc* jmp)
854 return (jmp->idInsFmt() == IF_BI_0A);
857 /*****************************************************************************
859 * Given a instrDesc, return true if it's a direct call.
862 inline bool emitIsDirectCall(instrDesc* call)
864 return (call->idInsFmt() == IF_BI_0C);
867 /*****************************************************************************
869 * Given a instrDesc, return true if it's a load label instruction.
872 inline bool emitIsLoadLabel(instrDesc* jmp)
874 return ((jmp->idInsFmt() == IF_DI_1E) || // adr or arp
875 (jmp->idInsFmt() == IF_LARGEADR));
878 /*****************************************************************************
880 * Given a instrDesc, return true if it's a load constant instruction.
883 inline bool emitIsLoadConstant(instrDesc* jmp)
885 return ((jmp->idInsFmt() == IF_LS_1A) || // ldr
886 (jmp->idInsFmt() == IF_LARGELDC));
889 #endif // _TARGET_ARM64_