14 #ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64ADDRESSINGMODES_H
15 #define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64ADDRESSINGMODES_H
26 namespace AArch64_AM {
74 switch ((Imm >> 6) & 0x7) {
100 assert((Imm & 0x3f) == Imm &&
"Illegal shifted immedate value!");
110 return (STEnc << 6) | (Imm & 0x3f);
124 assert((Imm & 0x7) == Imm &&
"invalid immediate!");
172 assert((Imm & 0x7) == Imm &&
"Illegal shifted immedate value!");
179 return (Imm & 0x1) != 0;
205 static inline uint64_t
ror(uint64_t elt,
unsigned size) {
206 return ((elt & 1) << (size-1)) | (elt >> 1);
214 uint64_t &Encoding) {
215 if (Imm == 0ULL || Imm == ~0ULL ||
216 (RegSize != 64 && (Imm >> RegSize != 0 || Imm == ~0U)))
220 unsigned Size = RegSize;
224 uint64_t Mask = (1ULL << Size) - 1;
226 if ((Imm & Mask) != ((Imm >> Size) & Mask)) {
234 uint64_t Mask = ((uint64_t)-1LL) >> (64 - Size);
239 assert(I < 64 &&
"undefined behavior");
254 assert(Size > I &&
"I should be smaller than element size");
255 unsigned Immr = (Size -
I) & (Size - 1);
259 uint64_t NImms = ~(Size-1) << 1;
266 unsigned N = ((NImms >> 6) & 1) ^ 1;
268 Encoding = (N << 12) | (Immr << 6) | (NImms & 0x3f);
282 uint64_t encoding = 0;
284 assert(res &&
"invalid logical immediate");
294 unsigned N = (val >> 12) & 1;
295 unsigned immr = (val >> 6) & 0x3f;
296 unsigned imms = val & 0x3f;
298 assert((regSize == 64 || N == 0) &&
"undefined logical immediate encoding");
300 assert(len >= 0 &&
"undefined logical immediate encoding");
301 unsigned size = (1 << len);
302 unsigned R = immr & (size - 1);
303 unsigned S = imms & (size - 1);
304 assert(S != size - 1 &&
"undefined logical immediate encoding");
305 uint64_t pattern = (1ULL << (S + 1)) - 1;
306 for (
unsigned i = 0; i < R; ++i)
307 pattern =
ror(pattern, size);
310 while (size != regSize) {
311 pattern |= (pattern <<
size);
323 unsigned N = (val >> 12) & 1;
324 unsigned imms = val & 0x3f;
326 if (regSize == 32 && N != 0)
331 unsigned size = (1 << len);
332 unsigned S = imms & (size - 1);
349 uint8_t Sign = (Imm >> 7) & 0x1;
350 uint8_t Exp = (Imm >> 4) & 0x7;
351 uint8_t Mantissa = Imm & 0xf;
359 FPUnion.I |= Sign << 31;
360 FPUnion.I |= ((Exp & 0x4) != 0 ? 0 : 1) << 30;
361 FPUnion.I |= ((Exp & 0x4) != 0 ? 0x1f : 0) << 25;
362 FPUnion.I |= (Exp & 0x3) << 23;
363 FPUnion.I |= Mantissa << 19;
377 if (Mantissa & 0x7ffff)
380 if ((Mantissa & 0xf) != Mantissa)
384 if (Exp < -3 || Exp > 4)
386 Exp = ((Exp+3) & 0x7) ^ 4;
388 return ((
int)Sign << 7) | (Exp << 4) | Mantissa;
401 uint64_t Mantissa = Imm.
getZExtValue() & 0xfffffffffffffULL;
405 if (Mantissa & 0xffffffffffffULL)
408 if ((Mantissa & 0xf) != Mantissa)
412 if (Exp < -3 || Exp > 4)
414 Exp = ((Exp+3) & 0x7) ^ 4;
416 return ((
int)Sign << 7) | (Exp << 4) | Mantissa;
429 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
430 ((Imm & 0xffffff00ffffff00ULL) == 0);
434 return (Imm & 0xffULL);
438 uint64_t EncVal = Imm;
439 return (EncVal << 32) | EncVal;
444 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
445 ((Imm & 0xffff00ffffff00ffULL) == 0);
449 return (Imm & 0xff00ULL) >> 8;
453 uint64_t EncVal = Imm;
454 return (EncVal << 40) | (EncVal << 8);
459 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
460 ((Imm & 0xff00ffffff00ffffULL) == 0);
464 return (Imm & 0xff0000ULL) >> 16;
468 uint64_t EncVal = Imm;
469 return (EncVal << 48) | (EncVal << 16);
474 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
475 ((Imm & 0x00ffffff00ffffffULL) == 0);
479 return (Imm & 0xff000000ULL) >> 24;
483 uint64_t EncVal = Imm;
484 return (EncVal << 56) | (EncVal << 24);
489 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
490 (((Imm & 0x00ff0000ULL) >> 16) == (Imm & 0x000000ffULL)) &&
491 ((Imm & 0xff00ff00ff00ff00ULL) == 0);
495 return (Imm & 0xffULL);
499 uint64_t EncVal = Imm;
500 return (EncVal << 48) | (EncVal << 32) | (EncVal << 16) | EncVal;
505 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
506 (((Imm & 0xff000000ULL) >> 16) == (Imm & 0x0000ff00ULL)) &&
507 ((Imm & 0x00ff00ff00ff00ffULL) == 0);
511 return (Imm & 0xff00ULL) >> 8;
515 uint64_t EncVal = Imm;
516 return (EncVal << 56) | (EncVal << 40) | (EncVal << 24) | (EncVal << 8);
521 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
522 ((Imm & 0xffff00ffffff00ffULL) == 0x000000ff000000ffULL);
526 return (Imm & 0xff00ULL) >> 8;
530 uint64_t EncVal = Imm;
531 return (EncVal << 40) | (EncVal << 8) | 0x000000ff000000ffULL;
536 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
537 ((Imm & 0xff00ffffff00ffffULL) == 0x0000ffff0000ffffULL);
541 uint64_t EncVal = Imm;
542 return (EncVal << 48) | (EncVal << 16) | 0x0000ffff0000ffffULL;
546 return (Imm & 0x00ff0000ULL) >> 16;
551 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
552 ((Imm >> 48) == (Imm & 0x0000ffffULL)) &&
553 ((Imm >> 56) == (Imm & 0x000000ffULL));
557 return (Imm & 0xffULL);
561 uint64_t EncVal = Imm;
562 EncVal |= (EncVal << 8);
563 EncVal |= (EncVal << 16);
564 EncVal |= (EncVal << 32);
571 uint64_t ByteA = Imm & 0xff00000000000000ULL;
572 uint64_t ByteB = Imm & 0x00ff000000000000ULL;
573 uint64_t ByteC = Imm & 0x0000ff0000000000ULL;
574 uint64_t ByteD = Imm & 0x000000ff00000000ULL;
575 uint64_t ByteE = Imm & 0x00000000ff000000ULL;
576 uint64_t ByteF = Imm & 0x0000000000ff0000ULL;
577 uint64_t ByteG = Imm & 0x000000000000ff00ULL;
578 uint64_t ByteH = Imm & 0x00000000000000ffULL;
580 return (ByteA == 0ULL || ByteA == 0xff00000000000000ULL) &&
581 (ByteB == 0ULL || ByteB == 0x00ff000000000000ULL) &&
582 (ByteC == 0ULL || ByteC == 0x0000ff0000000000ULL) &&
583 (ByteD == 0ULL || ByteD == 0x000000ff00000000ULL) &&
584 (ByteE == 0ULL || ByteE == 0x00000000ff000000ULL) &&
585 (ByteF == 0ULL || ByteF == 0x0000000000ff0000ULL) &&
586 (ByteG == 0ULL || ByteG == 0x000000000000ff00ULL) &&
587 (ByteH == 0ULL || ByteH == 0x00000000000000ffULL);
591 uint8_t BitA = (Imm & 0xff00000000000000ULL) != 0;
592 uint8_t BitB = (Imm & 0x00ff000000000000ULL) != 0;
593 uint8_t BitC = (Imm & 0x0000ff0000000000ULL) != 0;
594 uint8_t BitD = (Imm & 0x000000ff00000000ULL) != 0;
595 uint8_t BitE = (Imm & 0x00000000ff000000ULL) != 0;
596 uint8_t BitF = (Imm & 0x0000000000ff0000ULL) != 0;
597 uint8_t BitG = (Imm & 0x000000000000ff00ULL) != 0;
598 uint8_t BitH = (Imm & 0x00000000000000ffULL) != 0;
600 uint8_t EncVal = BitA;
620 if (Imm & 0x80) EncVal |= 0xff00000000000000ULL;
621 if (Imm & 0x40) EncVal |= 0x00ff000000000000ULL;
622 if (Imm & 0x20) EncVal |= 0x0000ff0000000000ULL;
623 if (Imm & 0x10) EncVal |= 0x000000ff00000000ULL;
624 if (Imm & 0x08) EncVal |= 0x00000000ff000000ULL;
625 if (Imm & 0x04) EncVal |= 0x0000000000ff0000ULL;
626 if (Imm & 0x02) EncVal |= 0x000000000000ff00ULL;
627 if (Imm & 0x01) EncVal |= 0x00000000000000ffULL;
633 uint64_t BString = (Imm & 0x7E000000ULL) >> 25;
634 return ((Imm >> 32) == (Imm & 0xffffffffULL)) &&
635 (BString == 0x1f || BString == 0x20) &&
636 ((Imm & 0x0007ffff0007ffffULL) == 0);
640 uint8_t BitA = (Imm & 0x80000000ULL) != 0;
641 uint8_t BitB = (Imm & 0x20000000ULL) != 0;
642 uint8_t BitC = (Imm & 0x01000000ULL) != 0;
643 uint8_t BitD = (Imm & 0x00800000ULL) != 0;
644 uint8_t BitE = (Imm & 0x00400000ULL) != 0;
645 uint8_t BitF = (Imm & 0x00200000ULL) != 0;
646 uint8_t BitG = (Imm & 0x00100000ULL) != 0;
647 uint8_t BitH = (Imm & 0x00080000ULL) != 0;
649 uint8_t EncVal = BitA;
669 if (Imm & 0x80) EncVal |= 0x80000000ULL;
670 if (Imm & 0x40) EncVal |= 0x3e000000ULL;
671 else EncVal |= 0x40000000ULL;
672 if (Imm & 0x20) EncVal |= 0x01000000ULL;
673 if (Imm & 0x10) EncVal |= 0x00800000ULL;
674 if (Imm & 0x08) EncVal |= 0x00400000ULL;
675 if (Imm & 0x04) EncVal |= 0x00200000ULL;
676 if (Imm & 0x02) EncVal |= 0x00100000ULL;
677 if (Imm & 0x01) EncVal |= 0x00080000ULL;
678 return (EncVal << 32) | EncVal;
683 uint64_t BString = (Imm & 0x7fc0000000000000ULL) >> 54;
684 return ((BString == 0xff || BString == 0x100) &&
685 ((Imm & 0x0000ffffffffffffULL) == 0));
689 uint8_t BitA = (Imm & 0x8000000000000000ULL) != 0;
690 uint8_t BitB = (Imm & 0x0040000000000000ULL) != 0;
691 uint8_t BitC = (Imm & 0x0020000000000000ULL) != 0;
692 uint8_t BitD = (Imm & 0x0010000000000000ULL) != 0;
693 uint8_t BitE = (Imm & 0x0008000000000000ULL) != 0;
694 uint8_t BitF = (Imm & 0x0004000000000000ULL) != 0;
695 uint8_t BitG = (Imm & 0x0002000000000000ULL) != 0;
696 uint8_t BitH = (Imm & 0x0001000000000000ULL) != 0;
698 uint8_t EncVal = BitA;
718 if (Imm & 0x80) EncVal |= 0x8000000000000000ULL;
719 if (Imm & 0x40) EncVal |= 0x3fc0000000000000ULL;
720 else EncVal |= 0x4000000000000000ULL;
721 if (Imm & 0x20) EncVal |= 0x0020000000000000ULL;
722 if (Imm & 0x10) EncVal |= 0x0010000000000000ULL;
723 if (Imm & 0x08) EncVal |= 0x0008000000000000ULL;
724 if (Imm & 0x04) EncVal |= 0x0004000000000000ULL;
725 if (Imm & 0x02) EncVal |= 0x0002000000000000ULL;
726 if (Imm & 0x01) EncVal |= 0x0001000000000000ULL;
727 return (EncVal << 32) | EncVal;
static bool isAdvSIMDModImmType6(uint64_t Imm)
static uint64_t decodeAdvSIMDModImmType9(uint8_t Imm)
static float getFPImmFloat(unsigned Imm)
static uint8_t encodeAdvSIMDModImmType3(uint64_t Imm)
static unsigned getArithShiftValue(unsigned Imm)
getArithShiftValue - get the arithmetic shift value.
uint64_t getZExtValue() const
Get zero extended value.
static bool isAdvSIMDModImmType12(uint64_t Imm)
static bool isAdvSIMDModImmType4(uint64_t Imm)
static uint8_t encodeAdvSIMDModImmType1(uint64_t Imm)
static uint64_t decodeAdvSIMDModImmType3(uint8_t Imm)
static bool processLogicalImmediate(uint64_t Imm, unsigned RegSize, uint64_t &Encoding)
processLogicalImmediate - Determine if an immediate value can be encoded as the immediate operand of ...
static uint64_t decodeAdvSIMDModImmType12(uint8_t Imm)
static bool isAdvSIMDModImmType3(uint64_t Imm)
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
static bool getMemDoShift(unsigned Imm)
getMemDoShift - Extract the "do shift" flag value for load/store instructions.
static bool isAdvSIMDModImmType7(uint64_t Imm)
static uint64_t decodeAdvSIMDModImmType5(uint8_t Imm)
std::size_t countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static uint8_t encodeAdvSIMDModImmType6(uint64_t Imm)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const
Logical right-shift function.
static bool isLogicalImmediate(uint64_t imm, unsigned regSize)
isLogicalImmediate - Return true if the immediate is valid for a logical immediate instruction of the...
static bool isAdvSIMDModImmType5(uint64_t Imm)
This file implements a class to represent arbitrary precision integral constant values and operations...
static AArch64_AM::ShiftExtendType getMemExtendType(unsigned Imm)
getExtendType - Extract the extend type for the offset operand of loads/stores.
static bool isAdvSIMDModImmType2(uint64_t Imm)
static unsigned getShifterImm(AArch64_AM::ShiftExtendType ST, unsigned Imm)
getShifterImm - Encode the shift type and amount: imm: 6-bit shift amount shifter: 000 ==> lsl 001 ==...
static bool isAdvSIMDModImmType9(uint64_t Imm)
static unsigned getShiftValue(unsigned Imm)
getShiftValue - Extract the shift value.
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
static int getFP32Imm(const APInt &Imm)
getFP32Imm - Return an 8-bit floating-point version of the 32-bit floating-point value.
static const char * getShiftExtendName(AArch64_AM::ShiftExtendType ST)
getShiftName - Get the string encoding for the shift type.
static AArch64_AM::ShiftExtendType getArithExtendType(unsigned Imm)
int64_t getSExtValue() const
Get sign extended value.
static uint64_t decodeLogicalImmediate(uint64_t val, unsigned regSize)
decodeLogicalImmediate - Decode a logical immediate value in the form "N:immr:imms" (where the immr a...
static unsigned getMemExtendImm(AArch64_AM::ShiftExtendType ET, bool DoShift)
getExtendImm - Encode the extend type and amount for a load/store inst: doshift: should the offset be...
static uint64_t decodeAdvSIMDModImmType6(uint8_t Imm)
static bool isAdvSIMDModImmType1(uint64_t Imm)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
static bool isAdvSIMDModImmType8(uint64_t Imm)
static uint8_t encodeAdvSIMDModImmType12(uint64_t Imm)
unsigned getExtendEncoding(AArch64_AM::ShiftExtendType ET)
Mapping from extend bits to required operation: shifter: 000 ==> uxtb 001 ==> uxth 010 ==> uxtw 011 =...
bool isShiftedMask_64(uint64_t Value)
isShiftedMask_64 - This function returns true if the argument contains a non-empty sequence of ones w...
static uint8_t encodeAdvSIMDModImmType2(uint64_t Imm)
static uint64_t encodeLogicalImmediate(uint64_t imm, unsigned regSize)
encodeLogicalImmediate - Return the encoded immediate value for a logical immediate instruction of th...
static int getFP64Imm(const APInt &Imm)
getFP64Imm - Return an 8-bit floating-point version of the 64-bit floating-point value.
static AArch64_AM::ShiftExtendType getExtendType(unsigned Imm)
getExtendType - Extract the extend type for operands of arithmetic ops.
static uint64_t decodeAdvSIMDModImmType7(uint8_t Imm)
Class for arbitrary precision integers.
static uint8_t encodeAdvSIMDModImmType10(uint64_t Imm)
APInt bitcastToAPInt() const
static uint64_t decodeAdvSIMDModImmType1(uint8_t Imm)
static unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET, unsigned Imm)
getArithExtendImm - Encode the extend type and shift amount for an arithmetic instruction: imm: 3-bit...
static uint8_t encodeAdvSIMDModImmType5(uint64_t Imm)
static uint64_t decodeAdvSIMDModImmType8(uint8_t Imm)
static bool isAdvSIMDModImmType10(uint64_t Imm)
static uint8_t encodeAdvSIMDModImmType8(uint64_t Imm)
static AArch64_AM::ShiftExtendType getShiftType(unsigned Imm)
getShiftType - Extract the shift type.
static uint8_t encodeAdvSIMDModImmType4(uint64_t Imm)
static uint8_t encodeAdvSIMDModImmType11(uint64_t Imm)
static uint64_t decodeAdvSIMDModImmType10(uint8_t Imm)
static bool isValidDecodeLogicalImmediate(uint64_t val, unsigned regSize)
isValidDecodeLogicalImmediate - Check to see if the logical immediate value in the form "N:immr:imms"...
static uint64_t decodeAdvSIMDModImmType11(uint8_t Imm)
static uint64_t decodeAdvSIMDModImmType4(uint8_t Imm)
static uint64_t decodeAdvSIMDModImmType2(uint8_t Imm)
static uint64_t ror(uint64_t elt, unsigned size)
static uint8_t encodeAdvSIMDModImmType9(uint64_t Imm)
static bool isAdvSIMDModImmType11(uint64_t Imm)
static uint8_t encodeAdvSIMDModImmType7(uint64_t Imm)
std::size_t countLeadingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the most significant bit to the first zero bit.