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.
6 #if defined(_TARGET_ARM64_)
8 // The ARM64 instructions are all 32 bits in size.
9 // we use an unsigned int to hold the encoded instructions.
10 // This typedef defines the type that we use to hold encoded instructions.
12 typedef unsigned int code_t;
15 static bool strictArmAsm;
17 /************************************************************************/
18 /* Routines that compute the size of / encode instructions */
19 /************************************************************************/
31 /************************************************************************/
32 /* Debug-only routines to display instructions */
33 /************************************************************************/
35 const char * emitFPregName (unsigned reg,
37 const char * emitVectorRegName(regNumber reg);
39 void emitDispInst (instruction ins);
40 void emitDispReloc (int value, bool addComma);
41 void emitDispImm (ssize_t imm, bool addComma, bool alwaysHex = false);
42 void emitDispFloatZero();
43 void emitDispFloatImm(ssize_t imm8);
44 void emitDispImmOptsLSL12(ssize_t imm, insOpts opt);
45 void emitDispCond (insCond cond);
46 void emitDispFlags (insCflags flags);
47 void emitDispBarrier (insBarrier barrier);
48 void emitDispShiftOpts(insOpts opt);
49 void emitDispExtendOpts(insOpts opt);
50 void emitDispLSExtendOpts(insOpts opt);
51 void emitDispReg (regNumber reg, emitAttr attr, bool addComma);
52 void emitDispVectorReg (regNumber reg, insOpts opt, bool addComma);
53 void emitDispVectorRegIndex(regNumber reg, emitAttr elemsize, ssize_t index, bool addComma);
54 void emitDispArrangement(insOpts opt);
55 void emitDispShiftedReg(regNumber reg, insOpts opt, ssize_t imm, emitAttr attr);
56 void emitDispExtendReg(regNumber reg, insOpts opt, ssize_t imm);
57 void emitDispAddrRI (regNumber reg, insOpts opt, ssize_t imm);
58 void emitDispAddrRRExt(regNumber reg1, regNumber reg2, insOpts opt, bool isScaled, emitAttr size);
60 void emitDispIns (instrDesc *id, bool isNew, bool doffs, bool asmfm,
61 unsigned offs = 0, BYTE * pCode = 0, size_t sz = 0,
65 /************************************************************************/
66 /* Private members that deal with target-dependent instr. descriptors */
67 /************************************************************************/
71 instrDesc *emitNewInstrAmd (emitAttr attr, int dsp);
72 instrDesc *emitNewInstrAmdCns (emitAttr attr, int dsp, int cns);
74 instrDesc *emitNewInstrCallDir (int argCnt,
75 VARSET_VALARG_TP GCvars,
79 emitAttr secondRetSize);
81 instrDesc *emitNewInstrCallInd( int argCnt,
83 VARSET_VALARG_TP GCvars,
87 emitAttr secondRetSize);
89 void emitGetInsCns (instrDesc *id, CnsVal *cv);
90 ssize_t emitGetInsAmdCns(instrDesc *id, CnsVal *cv);
91 void emitGetInsDcmCns(instrDesc *id, CnsVal *cv);
92 ssize_t emitGetInsAmdAny(instrDesc *id);
94 /************************************************************************/
95 /* Private helpers for instruction output */
96 /************************************************************************/
100 bool emitInsIsCompare(instruction ins);
101 bool emitInsIsLoad (instruction ins);
102 bool emitInsIsStore (instruction ins);
103 bool emitInsIsLoadOrStore(instruction ins);
104 emitAttr emitInsAdjustLoadStoreAttr(instruction ins, emitAttr attr);
105 emitAttr emitInsTargetRegSize(instrDesc *id);
106 emitAttr emitInsLoadStoreSize(instrDesc *id);
108 emitter::insFormat emitInsFormat(instruction ins);
109 emitter::code_t emitInsCode(instruction ins, insFormat fmt);
111 // Generate code for a load or store operation and handle the case of contained GT_LEA op1 with [base + index<<scale + offset]
112 void emitInsLoadStoreOp(instruction ins, emitAttr attr, regNumber dataReg, GenTreeIndir* indir);
114 // Emit the 32-bit Arm64 instruction 'code' into the 'dst' buffer
115 static unsigned emitOutput_Instr(BYTE *dst, code_t code);
117 // A helper method to return the natural scale for an EA 'size'
118 static unsigned NaturalScale_helper(emitAttr size);
120 // A helper method to perform a Rotate-Right shift operation
121 static UINT64 ROR_helper(UINT64 value, unsigned sh, unsigned width);
123 // A helper method to perform a 'NOT' bitwise complement operation
124 static UINT64 NOT_helper(UINT64 value, unsigned width);
126 // A helper method to perform a bit Replicate operation
127 static UINT64 Replicate_helper(UINT64 value, unsigned width, emitAttr size);
130 /************************************************************************
132 * This union is used to to encode/decode the special ARM64 immediate values
133 * that is listed as imm(N,r,s) and referred to as 'bitmask immediate'
139 unsigned immS:6; // bits 0..5
140 unsigned immR:6; // bits 6..11
141 unsigned immN:1; // bits 12
143 unsigned immNRS; // concat N:R:S forming a 13-bit unsigned immediate
146 /************************************************************************
148 * Convert between a 64-bit immediate and its 'bitmask immediate'
149 * representation imm(i16,hw)
152 static emitter::bitMaskImm emitEncodeBitMaskImm(INT64 imm, emitAttr size);
154 static INT64 emitDecodeBitMaskImm(const emitter::bitMaskImm bmImm,
158 /************************************************************************
160 * This union is used to to encode/decode the special ARM64 immediate values
161 * that is listed as imm(i16,hw) and referred to as 'halfword immediate'
167 unsigned immVal:16; // bits 0..15
168 unsigned immHW:2; // bits 16..17
170 unsigned immHWVal; // concat HW:Val forming a 18-bit unsigned immediate
173 /************************************************************************
175 * Convert between a 64-bit immediate and its 'halfword immediate'
176 * representation imm(i16,hw)
179 static emitter::halfwordImm emitEncodeHalfwordImm(INT64 imm, emitAttr size);
181 static INT64 emitDecodeHalfwordImm(const emitter::halfwordImm hwImm,
184 /************************************************************************
186 * This union is used to encode/decode the special ARM64 immediate values
187 * that is listed as imm(i16,by) and referred to as 'byteShifted immediate'
193 unsigned immVal:8; // bits 0..7
194 unsigned immBY:2; // bits 8..9
195 unsigned immOnes:1; // bit 10
197 unsigned immBSVal; // concat Ones:BY:Val forming a 10-bit unsigned immediate
200 /************************************************************************
202 * Convert between a 16/32-bit immediate and its 'byteShifted immediate'
203 * representation imm(i8,by)
206 static emitter::byteShiftedImm emitEncodeByteShiftedImm(INT64 imm, emitAttr size, bool allow_MSL);
208 static INT32 emitDecodeByteShiftedImm(const emitter::byteShiftedImm bsImm,
211 /************************************************************************
213 * This union is used to to encode/decode the special ARM64 immediate values
214 * that are use for FMOV immediate and referred to as 'float 8-bit immediate'
220 unsigned immMant:4; // bits 0..3
221 unsigned immExp:3; // bits 4..6
222 unsigned immSign:1; // bits 7
224 unsigned immFPIVal; // concat Sign:Exp:Mant forming an 8-bit unsigned immediate
227 /************************************************************************
229 * Convert between a double and its 'float 8-bit immediate' representation
232 static emitter::floatImm8 emitEncodeFloatImm8(double immDbl);
234 static double emitDecodeFloatImm8(const emitter::floatImm8 fpImm);
236 /************************************************************************
238 * This union is used to to encode/decode the cond, nzcv and imm5 values for
239 * instructions that use them in the small constant immediate field
245 insCond cond :4; // bits 0..3
246 insCflags flags:4; // bits 4..7
247 unsigned imm5 :5; // bits 8..12
249 unsigned immCFVal; // concat imm5:flags:cond forming an 13-bit unsigned immediate
252 // Returns an encoding for the specified register used in the 'Rd' position
253 static code_t insEncodeReg_Rd(regNumber reg);
255 // Returns an encoding for the specified register used in the 'Rt' position
256 static code_t insEncodeReg_Rt(regNumber reg);
258 // Returns an encoding for the specified register used in the 'Rn' position
259 static code_t insEncodeReg_Rn(regNumber reg);
261 // Returns an encoding for the specified register used in the 'Rm' position
262 static code_t insEncodeReg_Rm(regNumber reg);
264 // Returns an encoding for the specified register used in the 'Ra' position
265 static code_t insEncodeReg_Ra(regNumber reg);
267 // Returns an encoding for the specified register used in the 'Vd' position
268 static code_t insEncodeReg_Vd(regNumber reg);
270 // Returns an encoding for the specified register used in the 'Vt' position
271 static code_t insEncodeReg_Vt(regNumber reg);
273 // Returns an encoding for the specified register used in the 'Vn' position
274 static code_t insEncodeReg_Vn(regNumber reg);
276 // Returns an encoding for the specified register used in the 'Vm' position
277 static code_t insEncodeReg_Vm(regNumber reg);
279 // Returns an encoding for the specified register used in the 'Va' position
280 static code_t insEncodeReg_Va(regNumber reg);
282 // Returns an encoding for the imm which represents the condition code.
283 static code_t insEncodeCond(insCond cond);
285 // Returns an encoding for the imm whioch represents the 'condition code'
286 // with the lowest bit inverted (marked by invert(<cond>) in the architecture manual.
287 static code_t insEncodeInvertedCond(insCond cond);
289 // Returns an encoding for the imm which represents the flags.
290 static code_t insEncodeFlags(insCflags flags);
292 // Returns the encoding for the Shift Count bits to be used for Arm64 encodings
293 static code_t insEncodeShiftCount(ssize_t imm, emitAttr size);
295 // Returns the encoding to select the datasize for most Arm64 instructions
296 static code_t insEncodeDatasize(emitAttr size);
298 // Returns the encoding to select the datasize for the general load/store Arm64 instructions
299 static code_t insEncodeDatasizeLS(code_t code, emitAttr size);
301 // Returns the encoding to select the datasize for the vector load/store Arm64 instructions
302 static code_t insEncodeDatasizeVLS(code_t code, emitAttr size);
304 // Returns the encoding to select the datasize for the vector load/store pair Arm64 instructions
305 static code_t insEncodeDatasizeVPLS(code_t code, emitAttr size);
307 // Returns the encoding to select the datasize for bitfield Arm64 instructions
308 static code_t insEncodeDatasizeBF(code_t code, emitAttr size);
310 // Returns the encoding to select the vectorsize for SIMD Arm64 instructions
311 static code_t insEncodeVectorsize(emitAttr size);
313 // Returns the encoding to select 'index' for an Arm64 vector elem instruction
314 static code_t insEncodeVectorIndex(emitAttr elemsize, ssize_t index);
316 // Returns the encoding to select 'index2' for an Arm64 'ins' elem instruction
317 static code_t insEncodeVectorIndex2(emitAttr elemsize, ssize_t index2);
319 // Returns the encoding to select 'index' for an Arm64 'mul' elem instruction
320 static code_t insEncodeVectorIndexLMH(emitAttr elemsize, ssize_t index);
322 // Returns the encoding to shift by 'shift' bits for an Arm64 vector or scalar instruction
323 static code_t insEncodeVectorShift(emitAttr size, ssize_t shift);
325 // Returns the encoding to select the 1/2/4/8 byte elemsize for an Arm64 vector instruction
326 static code_t insEncodeElemsize(emitAttr size);
328 // Returns the encoding to select the 4/8 byte elemsize for an Arm64 float vector instruction
329 static code_t insEncodeFloatElemsize(emitAttr size);
331 // Returns the encoding to select the index for an Arm64 float vector by elem instruction
332 static code_t insEncodeFloatIndex(emitAttr elemsize, ssize_t index);
334 // Returns the encoding to select the 'conversion' operation for a type 'fmt' Arm64 instruction
335 static code_t insEncodeConvertOpt(insFormat fmt, insOpts conversion);
337 // Returns the encoding to have the Rn register of a ld/st reg be Pre/Post/Not indexed updated
338 static code_t insEncodeIndexedOpt(insOpts opt);
340 // Returns the encoding to have the Rn register of a ld/st pair be Pre/Post/Not indexed updated
341 static code_t insEncodePairIndexedOpt(instruction ins, insOpts opt);
343 // Returns the encoding to apply a Shift Type on the Rm register
344 static code_t insEncodeShiftType(insOpts opt);
346 // Returns the encoding to apply a 12 bit left shift to the immediate
347 static code_t insEncodeShiftImm12(insOpts opt);
349 // Returns the encoding to have the Rm register use an extend operation
350 static code_t insEncodeExtend(insOpts opt);
352 // Returns the encoding to scale the Rm register by {0,1,2,3,4} in an extend operation
353 static code_t insEncodeExtendScale(ssize_t imm);
355 // Returns the encoding to have the Rm register be auto scaled by the ld/st size
356 static code_t insEncodeReg3Scale(bool isScaled);
358 // Returns true if 'reg' represents an integer register.
359 static bool isIntegerRegister (regNumber reg)
360 { return (reg >= REG_INT_FIRST) && (reg <= REG_INT_LAST); }
362 // Returns true if 'value' is a legal unsigned immediate 8 bit encoding (such as for fMOV).
363 static bool isValidUimm8(ssize_t value)
364 { return (0 <= value) && (value <= 0xFFLL); };
366 // Returns true if 'value' is a legal unsigned immediate 12 bit encoding (such as for CMP, CMN).
367 static bool isValidUimm12(ssize_t value)
368 { return (0 <= value) && (value <= 0xFFFLL); };
370 // Returns true if 'value' is a legal unsigned immediate 16 bit encoding (such as for MOVZ, MOVN, MOVK).
371 static bool isValidUimm16(ssize_t value)
372 { return (0 <= value) && (value <= 0xFFFFLL); };
374 // Returns true if 'value' is a legal signed immediate 26 bit encoding (such as for B or BL).
375 static bool isValidSimm26(ssize_t value)
376 { return (-0x2000000LL <= value) && (value <= 0x1FFFFFFLL); };
378 // Returns true if 'value' is a legal signed immediate 19 bit encoding (such as for B.cond, CBNZ, CBZ).
379 static bool isValidSimm19(ssize_t value)
380 { return (-0x40000LL <= value) && (value <= 0x3FFFFLL); };
382 // Returns true if 'value' is a legal signed immediate 14 bit encoding (such as for TBNZ, TBZ).
383 static bool isValidSimm14(ssize_t value)
384 { return (-0x2000LL <= value) && (value <= 0x1FFFLL); };
386 // Returns true if 'value' represents a valid 'bitmask immediate' encoding.
387 static bool isValidImmNRS (size_t value, emitAttr size)
388 { return (value >= 0) && (value < 0x2000); } // any unsigned 13-bit immediate
390 // Returns true if 'value' represents a valid 'halfword immediate' encoding.
391 static bool isValidImmHWVal (size_t value, emitAttr size)
392 { return (value >= 0) && (value < 0x40000); } // any unsigned 18-bit immediate
394 // Returns true if 'value' represents a valid 'byteShifted immediate' encoding.
395 static bool isValidImmBSVal (size_t value, emitAttr size)
396 { return (value >= 0) && (value < 0x800); } // any unsigned 11-bit immediate
398 // The return value replaces REG_ZR with REG_SP
399 static regNumber encodingZRtoSP(regNumber reg)
400 { return (reg == REG_ZR) ? REG_SP : reg; } // ZR (R31) encodes the SP register
402 // The return value replaces REG_SP with REG_ZR
403 static regNumber encodingSPtoZR(regNumber reg)
404 { return (reg == REG_SP) ? REG_ZR : reg; } // SP is encoded using ZR (R31)
406 // For the given 'ins' returns the reverse instruction, if one exists, otherwise returns INS_INVALID
407 static instruction insReverse(instruction ins);
409 // For the given 'datasize' and 'elemsize' returns the insOpts that specifies the vector register arrangement
410 static insOpts optMakeArrangement(emitAttr datasize, emitAttr elemsize);
412 // For the given 'datasize' and 'opt' returns true if it specifies a valid vector register arrangement
413 static bool isValidArrangement(emitAttr datasize, insOpts opt);
415 // For the given 'arrangement' returns the 'datasize' specified by the vector register arrangement
416 static emitAttr optGetDatasize(insOpts arrangement);
418 // For the given 'arrangement' returns the 'elemsize' specified by the vector register arrangement
419 static emitAttr optGetElemsize(insOpts arrangement);
421 // For the given 'arrangement' returns the 'widen-arrangement' specified by the vector register arrangement
422 static insOpts optWidenElemsize(insOpts arrangement);
424 // For the given 'conversion' returns the 'dstsize' specified by the conversion option
425 static emitAttr optGetDstsize(insOpts conversion);
427 // For the given 'conversion' returns the 'srcsize' specified by the conversion option
428 static emitAttr optGetSrcsize(insOpts conversion);
430 // For the given 'datasize', 'elemsize' and 'index' returns true, if it specifies a valid 'index'
431 // for an element of size 'elemsize' in a vector register of size 'datasize'
432 static bool isValidVectorIndex(emitAttr datasize, emitAttr elemsize, ssize_t index);
434 /************************************************************************/
435 /* Public inline informational methods */
436 /************************************************************************/
440 // true if this 'imm' can be encoded as a input operand to a mov instruction
441 static bool emitIns_valid_imm_for_mov(INT64 imm, emitAttr size);
443 // true if this 'imm' can be encoded as a input operand to a vector movi instruction
444 static bool emitIns_valid_imm_for_movi(INT64 imm, emitAttr size);
446 // true if this 'immDbl' can be encoded as a input operand to a fmov instruction
447 static bool emitIns_valid_imm_for_fmov(double immDbl);
449 // true if this 'imm' can be encoded as a input operand to an add instruction
450 static bool emitIns_valid_imm_for_add(INT64 imm, emitAttr size);
452 // true if this 'imm' can be encoded as a input operand to a cmp instruction
453 static bool emitIns_valid_imm_for_cmp(INT64 imm, emitAttr size);
455 // true if this 'imm' can be encoded as a input operand to an alu instruction
456 static bool emitIns_valid_imm_for_alu(INT64 imm, emitAttr size);
458 // true if this 'imm' can be encoded as the offset in a ldr/str instruction
459 static bool emitIns_valid_imm_for_ldst_offset(INT64 imm, emitAttr size);
461 // true if 'imm' can use the left shifted by 12 bits encoding
462 static bool canEncodeWithShiftImmBy12(INT64 imm);
464 // Normalize the 'imm' so that the upper bits, as defined by 'size' are zero
465 static INT64 normalizeImm64(INT64 imm, emitAttr size);
467 // Normalize the 'imm' so that the upper bits, as defined by 'size' are zero
468 static INT32 normalizeImm32(INT32 imm, emitAttr size);
470 // true if 'imm' can be encoded using a 'bitmask immediate', also returns the encoding if wbBMI is non-null
471 static bool canEncodeBitMaskImm(INT64 imm, emitAttr size,
472 emitter::bitMaskImm* wbBMI = nullptr);
474 // true if 'imm' can be encoded using a 'halfword immediate', also returns the encoding if wbHWI is non-null
475 static bool canEncodeHalfwordImm(INT64 imm, emitAttr size,
476 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,
480 emitter::byteShiftedImm* wbBSI = nullptr);
482 // true if 'immDbl' can be encoded using a 'float immediate', also returns the encoding if wbFPI is non-null
483 static bool canEncodeFloatImm8(double immDbl,
484 emitter::floatImm8* wbFPI = nullptr);
486 // Returns the number of bits used by the given 'size'.
487 inline static unsigned getBitWidth (emitAttr size)
488 { assert(size <= EA_8BYTE); return (unsigned)size * BITS_PER_BYTE; }
490 // Returns true if the imm represents a valid bit shift or bit position for the given 'size' [0..31] or [0..63]
491 inline static unsigned isValidImmShift (ssize_t imm, emitAttr size)
492 { return (imm >= 0) && (imm < getBitWidth(size)); }
494 inline static bool isValidGeneralDatasize (emitAttr size)
495 { return (size == EA_8BYTE) || (size == EA_4BYTE); }
497 inline static bool isValidScalarDatasize (emitAttr size)
498 { return (size == EA_8BYTE) || (size == EA_4BYTE); }
500 inline static bool isValidVectorDatasize (emitAttr size)
501 { return (size == EA_16BYTE) || (size == EA_8BYTE); }
503 inline static bool isValidGeneralLSDatasize (emitAttr size)
504 { return (size == EA_8BYTE) || (size == EA_4BYTE) ||
505 (size == EA_2BYTE) || (size == EA_1BYTE); }
507 inline static bool isValidVectorLSDatasize (emitAttr size)
508 { return (size == EA_16BYTE) ||
509 (size == EA_8BYTE) || (size == EA_4BYTE) ||
510 (size == EA_2BYTE) || (size == EA_1BYTE); }
512 inline static bool isValidVectorLSPDatasize (emitAttr size)
513 { return (size == EA_16BYTE) ||
514 (size == EA_8BYTE) || (size == EA_4BYTE); }
516 inline static bool isValidVectorElemsize (emitAttr size)
517 { return (size == EA_8BYTE) || (size == EA_4BYTE) ||
518 (size == EA_2BYTE) || (size == EA_1BYTE); }
520 inline static bool isValidVectorFcvtsize(emitAttr size)
521 { return (size == EA_8BYTE) || (size == EA_4BYTE) ||
522 (size == EA_2BYTE); }
524 inline static bool isValidVectorElemsizeFloat (emitAttr size)
525 { return (size == EA_8BYTE) || (size == EA_4BYTE); }
527 inline static bool isGeneralRegister (regNumber reg)
528 { return (reg >= REG_INT_FIRST) && (reg <= REG_LR); } // Excludes REG_ZR
530 inline static bool isGeneralRegisterOrZR (regNumber reg)
531 { return (reg >= REG_INT_FIRST) && (reg <= REG_ZR); } // Includes REG_ZR
533 inline static bool isGeneralRegisterOrSP (regNumber reg)
534 { return isGeneralRegister(reg) || (reg == REG_SP); } // Includes REG_SP, Excludes REG_ZR
536 inline static bool isVectorRegister (regNumber reg)
537 { return (reg >= REG_FP_FIRST && reg <= REG_FP_LAST); }
539 inline static bool isFloatReg (regNumber reg)
540 { return isVectorRegister(reg); }
542 inline static bool insOptsNone (insOpts opt)
543 { return (opt == INS_OPTS_NONE); }
545 inline static bool insOptsIndexed (insOpts opt)
546 { return (opt == INS_OPTS_PRE_INDEX) ||
547 (opt == INS_OPTS_POST_INDEX); }
549 inline static bool insOptsPreIndex (insOpts opt)
550 { return (opt == INS_OPTS_PRE_INDEX); }
552 inline static bool insOptsPostIndex (insOpts opt)
553 { return (opt == INS_OPTS_POST_INDEX); }
555 inline static bool insOptsLSL12 (insOpts opt) // special 12-bit shift only used for imm12
556 { return (opt == INS_OPTS_LSL12); }
558 inline static bool insOptsAnyShift (insOpts opt)
559 { return ((opt >= INS_OPTS_LSL) &&
560 (opt <= INS_OPTS_ROR) ); }
562 inline static bool insOptsAluShift (insOpts opt) // excludes ROR
563 { return ((opt >= INS_OPTS_LSL) &&
564 (opt <= INS_OPTS_ASR) ); }
566 inline static bool insOptsVectorImmShift (insOpts opt)
567 { return ((opt == INS_OPTS_LSL) ||
568 (opt == INS_OPTS_MSL) ); }
570 inline static bool insOptsLSL (insOpts opt)
571 { return (opt == INS_OPTS_LSL); }
573 inline static bool insOptsLSR (insOpts opt)
574 { return (opt == INS_OPTS_LSR); }
576 inline static bool insOptsASR (insOpts opt)
577 { return (opt == INS_OPTS_ASR); }
579 inline static bool insOptsROR (insOpts opt)
580 { return (opt == INS_OPTS_ROR); }
582 inline static bool insOptsAnyExtend (insOpts opt)
583 { return ((opt >= INS_OPTS_UXTB) &&
584 (opt <= INS_OPTS_SXTX) ); }
586 inline static bool insOptsLSExtend (insOpts opt)
587 { return ((opt == INS_OPTS_NONE) || (opt == INS_OPTS_LSL) ||
588 (opt == INS_OPTS_UXTW) || (opt == INS_OPTS_SXTW) ||
589 (opt == INS_OPTS_UXTX) || (opt == INS_OPTS_SXTX) ); }
591 inline static bool insOpts32BitExtend (insOpts opt)
592 { return ((opt == INS_OPTS_UXTW) || (opt == INS_OPTS_SXTW)); }
594 inline static bool insOpts64BitExtend (insOpts opt)
595 { return ((opt == INS_OPTS_UXTX) || (opt == INS_OPTS_SXTX)); }
597 inline static bool insOptsAnyArrangement(insOpts opt)
598 { return ((opt >= INS_OPTS_8B) && (opt <= INS_OPTS_2D)); }
600 inline static bool insOptsConvertFloatToFloat (insOpts opt)
601 { return ((opt >= INS_OPTS_S_TO_D) && (opt <= INS_OPTS_D_TO_H)); }
603 inline static bool insOptsConvertFloatToInt (insOpts opt)
604 { return ((opt >= INS_OPTS_S_TO_4BYTE) && (opt <= INS_OPTS_D_TO_8BYTE)); }
606 inline static bool insOptsConvertIntToFloat (insOpts opt)
607 { return ((opt >= INS_OPTS_4BYTE_TO_S) && (opt <= INS_OPTS_8BYTE_TO_D)); }
609 static bool isValidImmCond (ssize_t imm);
610 static bool isValidImmCondFlags (ssize_t imm);
611 static bool isValidImmCondFlagsImm5 (ssize_t imm);
613 /************************************************************************/
614 /* The public entry points to output instructions */
615 /************************************************************************/
619 void emitIns (instruction ins);
621 void emitIns_I (instruction ins,
625 void emitIns_R (instruction ins,
629 void emitIns_R_I (instruction ins,
633 insOpts opt = INS_OPTS_NONE);
635 void emitIns_R_F (instruction ins,
639 insOpts opt = INS_OPTS_NONE);
641 void emitIns_R_R (instruction ins,
645 insOpts opt = INS_OPTS_NONE);
647 void emitIns_R_R (instruction ins,
653 emitIns_R_R(ins,attr,reg1,reg2);
656 void emitIns_R_I_I (instruction ins,
661 insOpts opt = INS_OPTS_NONE);
663 void emitIns_R_R_I (instruction ins,
668 insOpts opt = INS_OPTS_NONE);
670 // Checks for a large immediate that needs a second instruction
671 void emitIns_R_R_Imm(instruction ins,
677 void emitIns_R_R_R (instruction ins,
682 insOpts opt = INS_OPTS_NONE);
684 void emitIns_R_R_R_I(instruction ins,
690 insOpts opt = INS_OPTS_NONE);
692 void emitIns_R_R_R_Ext(instruction ins,
697 insOpts opt = INS_OPTS_NONE,
698 int shiftAmount = -1);
700 void emitIns_R_R_I_I(instruction ins,
707 void emitIns_R_R_R_R(instruction ins,
714 void emitIns_R_COND (instruction ins,
719 void emitIns_R_R_COND (instruction ins,
725 void emitIns_R_R_R_COND (instruction ins,
732 void emitIns_R_R_FLAGS_COND (instruction ins,
739 void emitIns_R_I_FLAGS_COND (instruction ins,
746 void emitIns_BARR (instruction ins,
749 void emitIns_C (instruction ins,
751 CORINFO_FIELD_HANDLE fdlHnd,
754 void emitIns_S (instruction ins,
759 void emitIns_S_R (instruction ins,
765 void emitIns_R_S (instruction ins,
771 void emitIns_S_I (instruction ins,
777 void emitIns_R_C (instruction ins,
781 CORINFO_FIELD_HANDLE fldHnd,
784 void emitIns_C_R (instruction ins,
786 CORINFO_FIELD_HANDLE fldHnd,
790 void emitIns_C_I (instruction ins,
792 CORINFO_FIELD_HANDLE fdlHnd,
796 void emitIns_R_L (instruction ins,
801 void emitIns_R_D (instruction ins,
806 void emitIns_J_R (instruction ins,
811 void emitIns_I_AR (instruction ins,
817 void * clsCookie = NULL);
819 void emitIns_R_AR (instruction ins,
825 void * clsCookie = NULL);
827 void emitIns_R_AI (instruction ins,
832 void emitIns_AR_R (instruction ins,
838 void * clsCookie = NULL);
840 void emitIns_R_ARR (instruction ins,
847 void emitIns_ARR_R (instruction ins,
854 void emitIns_R_ARX (instruction ins,
865 // I have included here, but commented out, all the values used by the x86 emitter.
866 // However, ARM has a much reduced instruction set, and so the ARM emitter only
867 // supports a subset of the x86 variants. By leaving them commented out, it becomes
868 // a compile time error if code tries to use them (and hopefully see this comment
869 // and know why they are unavailible on ARM), while making it easier to stay
870 // in-sync with x86 and possibly add them back in if needed.
872 EC_FUNC_TOKEN, // Direct call to a helper/static/nonvirtual/global method
873 // EC_FUNC_TOKEN_INDIR, // Indirect call to a helper/static/nonvirtual/global method
874 EC_FUNC_ADDR, // Direct call to an absolute address
876 // EC_FUNC_VIRTUAL, // Call to a virtual method (using the vtable)
877 EC_INDIR_R, // Indirect call via register
878 // EC_INDIR_SR, // Indirect call via stack-reference (local var)
879 // EC_INDIR_C, // Indirect call via static class var
880 // EC_INDIR_ARD, // Indirect call via an addressing mode
885 void emitIns_Call (EmitCallType callType,
886 CORINFO_METHOD_HANDLE methHnd,
887 INDEBUG_LDISASM_COMMA(CORINFO_SIG_INFO* sigInfo) // used to report call sites to the EE
891 emitAttr secondRetSize,
892 VARSET_VALARG_TP ptrVars,
895 IL_OFFSETX ilOffset = BAD_IL_OFFSET,
896 regNumber ireg = REG_NA,
897 regNumber xreg = REG_NA,
902 bool isProfLeaveCB = false);
904 BYTE* emitOutputLJ (insGroup *ig, BYTE *dst, instrDesc *i);
905 unsigned emitOutputCall(insGroup *ig, BYTE *dst, instrDesc *i, code_t code);
906 BYTE* emitOutputLoadLabel(BYTE* dst, BYTE* srcAddr, BYTE* dstAddr, instrDescJmp* id);
907 BYTE* emitOutputShortBranch(BYTE *dst, instruction ins, insFormat fmt, ssize_t distVal, instrDescJmp* id);
908 BYTE* emitOutputShortAddress(BYTE *dst, instruction ins, insFormat fmt, ssize_t distVal, regNumber reg);
909 BYTE* emitOutputShortConstant(BYTE *dst, instruction ins, insFormat fmt, ssize_t distVal, regNumber reg, emitAttr opSize);
911 /*****************************************************************************
913 * Given an instrDesc, return true if it's a conditional jump.
916 inline bool emitIsCondJump(instrDesc *jmp)
918 return ((jmp->idInsFmt() == IF_BI_0B) ||
919 (jmp->idInsFmt() == IF_LARGEJMP));
923 /*****************************************************************************
925 * Given an instrDesc, return true if it's a compare and jump.
928 inline bool emitIsCmpJump(instrDesc *jmp)
930 return ((jmp->idInsFmt() == IF_BI_1A) ||
931 (jmp->idInsFmt() == IF_BI_1B));
934 /*****************************************************************************
936 * Given a instrDesc, return true if it's an unconditional jump.
939 inline bool emitIsUncondJump(instrDesc *jmp)
941 return (jmp->idInsFmt() == IF_BI_0A);
944 /*****************************************************************************
946 * Given a instrDesc, return true if it's a direct call.
949 inline bool emitIsDirectCall(instrDesc *call)
951 return (call->idInsFmt() == IF_BI_0C);
954 /*****************************************************************************
956 * Given a instrDesc, return true if it's a load label instruction.
959 inline bool emitIsLoadLabel(instrDesc *jmp)
961 return ((jmp->idInsFmt() == IF_DI_1E) || // adr or arp
962 (jmp->idInsFmt() == IF_LARGEADR));
965 /*****************************************************************************
967 * Given a instrDesc, return true if it's a load constant instruction.
970 inline bool emitIsLoadConstant(instrDesc *jmp)
972 return ((jmp->idInsFmt() == IF_LS_1A) || // ldr
973 (jmp->idInsFmt() == IF_LARGELDC));
976 #endif // _TARGET_ARM64_