22 for (
unsigned i = 0; i <
NumPairs; ++i) {
23 if (
Pairs[i].Value == Value) {
34 std::string LowerCaseName = Name.
lower();
35 for (
unsigned i = 0; i <
NumPairs; ++i) {
36 if (
Pairs[i].Name == LowerCaseName) {
249 InstPairs = &MRSPairs[0];
272 InstPairs = &MSRPairs[0];
759 std::string NameLower = Name.
lower();
761 if (SysRegPairs[i].Name == NameLower) {
763 return SysRegPairs[i].Value;
769 for (
unsigned i = 0; i < NumInstPairs; ++i) {
770 if (InstPairs[i].Name == NameLower) {
772 return InstPairs[i].Value;
778 Regex GenericRegPattern(
"^s3_([0-7])_c(1[15])_c([0-9]|1[0-5])_([0-7])$");
781 if (!GenericRegPattern.
match(NameLower, &Ops)) {
786 uint32_t Op0 = 3, Op1 = 0, CRn = 0, CRm = 0, Op2 = 0;
788 Ops[1].getAsInteger(10, Op1);
789 Ops[2].getAsInteger(10, CRn);
790 Ops[3].getAsInteger(10, CRm);
791 Ops[4].getAsInteger(10, Op2);
792 Bits = (Op0 << 14) | (Op1 << 11) | (CRn << 7) | (CRm << 3) | Op2;
801 if (SysRegPairs[i].
Value == Bits) {
803 return SysRegPairs[i].Name;
807 for (
unsigned i = 0; i < NumInstPairs; ++i) {
808 if (InstPairs[i].
Value == Bits) {
810 return InstPairs[i].Name;
814 uint32_t Op0 = (Bits >> 14) & 0x3;
815 uint32_t Op1 = (Bits >> 11) & 0x7;
816 uint32_t CRn = (Bits >> 7) & 0xf;
817 uint32_t CRm = (Bits >> 3) & 0xf;
818 uint32_t Op2 = Bits & 0x7;
822 if (Op0 != 3 || (CRn != 11 && CRn != 15)) {
827 assert(Op0 == 3 && (CRn == 11 || CRn == 15) &&
"Invalid generic sysreg");
894 uint32_t ExpStart = FracBits;
895 uint64_t FracMask = (1ULL << FracBits) - 1;
900 uint64_t Fraction = Bits & FracMask;
901 int32_t Exponent = ((Bits >> ExpStart) & ExpMask);
902 Exponent -= ExpMask >> 1;
907 uint64_t A64FracStart = FracBits - 4;
908 uint64_t A64FracMask = 0xf;
911 if (Fraction & ~(A64FracMask << A64FracStart))
914 if (Exponent < -3 || Exponent > 4)
917 uint32_t PackedFraction = (Fraction >> A64FracStart) & A64FracMask;
918 uint32_t PackedExp = (Exponent + 7) & 0x7;
920 Imm8Bits = (Sign << 7) | (PackedExp << 4) | PackedFraction;
953 if (Imm == 0)
return false;
955 for (RepeatWidth = RegWidth; RepeatWidth > 1; RepeatWidth /= 2) {
956 uint64_t RepeatMask = RepeatWidth == 64 ? -1 : (1ULL << RepeatWidth) - 1;
957 uint64_t ReplicatedMask = Imm & RepeatMask;
959 if (ReplicatedMask == 0)
continue;
963 bool IsReplicatedMask =
true;
964 for (
unsigned i = RepeatWidth; i < RegWidth; i += RepeatWidth) {
965 if (((Imm >> i) & RepeatMask) != ReplicatedMask) {
966 IsReplicatedMask =
false;
970 if (!IsReplicatedMask)
continue;
981 Rotation = RepeatWidth - Rotation;
984 uint64_t ReplicatedOnes = ReplicatedMask;
985 if (Rotation != 0 && Rotation != 64)
986 ReplicatedOnes = (ReplicatedMask >> Rotation)
987 | ((ReplicatedMask << (RepeatWidth - Rotation)) & RepeatMask);
1001 if (RepeatWidth == 1 || Num1s == RepeatWidth)
return false;
1003 uint32_t
N = RepeatWidth == 64;
1004 uint32_t ImmR = RepeatWidth - Rotation;
1005 uint32_t ImmS = Num1s - 1;
1007 switch (RepeatWidth) {
1009 case 16: ImmS |= 0x20;
break;
1010 case 8: ImmS |= 0x30;
break;
1011 case 4: ImmS |= 0x38;
break;
1012 case 2: ImmS |= 0x3c;
break;
1015 Bits = ImmS | (ImmR << 6) | (N << 12);
1023 uint32_t
N = Bits >> 12;
1024 uint32_t ImmR = (Bits >> 6) & 0x3f;
1025 uint32_t ImmS = Bits & 0x3f;
1029 if (RegWidth == 32 && N != 0)
return false;
1034 else if ((ImmS & 0x20) == 0)
1036 else if ((ImmS & 0x10) == 0)
1038 else if ((ImmS & 0x08) == 0)
1040 else if ((ImmS & 0x04) == 0)
1042 else if ((ImmS & 0x02) == 0)
1049 int Num1s = (ImmS & (Width - 1)) + 1;
1052 if (Num1s == Width)
return false;
1054 int Rotation = (ImmR & (Width - 1));
1055 uint64_t Mask = (1ULL << Num1s) - 1;
1056 uint64_t WidthMask = Width == 64 ? -1 : (1ULL << Width) - 1;
1057 if (Rotation != 0 && Rotation != 64)
1058 Mask = (Mask >> Rotation)
1059 | ((Mask << (Width - Rotation)) & WidthMask);
1062 for (
unsigned i = 1; i < RegWidth / Width; ++i) {
1072 if (RegWidth == 32 && (Value & ~0xffffffffULL))
1075 for (
int i = 0; i < RegWidth; i += 16) {
1078 if ((Value & ~(0xffffULL << i)) == 0) {
1080 UImm16 = (Value >> i) & 0xffff;
1093 if (RegWidth == 32 && (Value & ~0xffffffffULL))
1096 uint64_t MOVZEquivalent = RegWidth == 32 ? ~Value & 0xffffffff : ~Value;
1098 return isMOVZImm(RegWidth, MOVZEquivalent, UImm16, Shift);
1102 int &UImm16,
int &Shift) {
1103 if (
isMOVZImm(RegWidth, Value, UImm16, Shift))
1106 return isMOVNImm(RegWidth, Value, UImm16, Shift);
1113 unsigned &ShiftOnesIn) {
1115 ShiftOnesIn =
false;
1116 bool HasShift =
true;
1118 if (OpCmode == 0xe) {
1121 }
else if (OpCmode == 0x1e) {
1124 }
else if ((OpCmode & 0xc) == 0x8) {
1126 ShiftImm = ((OpCmode & 0x2) >> 1);
1127 }
else if ((OpCmode & 0x8) == 0) {
1129 ShiftImm = ((OpCmode & 0x6) >> 1);
1130 }
else if ((OpCmode & 0xe) == 0xc) {
1133 ShiftImm = (OpCmode & 0x1);
1145 unsigned &EltBits) {
1146 uint64_t DecodedVal = Val;
1149 if (OpCmode == 0xe) {
1152 }
else if (OpCmode == 0x1e) {
1155 for (
unsigned ByteNum = 0; ByteNum < 8; ++ByteNum) {
1156 if ((Val >> ByteNum) & 1)
1157 DecodedVal |= (uint64_t)0xff << (8 * ByteNum);
1160 }
else if ((OpCmode & 0xc) == 0x8) {
1163 }
else if ((OpCmode & 0x8) == 0) {
1166 }
else if ((OpCmode & 0xe) == 0xc) {
static const NamedImmMapper::Mapping SysRegPairs[]
bool isMOVNImm(int RegWidth, uint64_t Value, int &UImm16, int &Shift)
static const Mapping ICPairs[]
bool isLogicalImmBits(unsigned RegWidth, uint32_t Bits, uint64_t &Imm)
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
static const Mapping PRFMPairs[]
bool isLogicalImm(unsigned RegWidth, uint64_t Imm, uint32_t &Bits)
unsigned CountTrailingOnes_64(uint64_t Value)
#define llvm_unreachable(msg)
bool isMOVZImm(int RegWidth, uint64_t Value, int &UImm16, int &Shift)
bool decodeNeonModShiftImm(unsigned OpCmode, unsigned &ShiftImm, unsigned &ShiftOnesIn)
size_t array_lengthof(T(&)[N])
Find the length of an array.
enable_if_c< std::numeric_limits< T >::is_integer &&!std::numeric_limits< T >::is_signed, std::size_t >::type 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...
bool isMask_64(uint64_t Value)
static std::string utostr(uint64_t X, bool isNeg=false)
static unsigned int semanticsPrecision(const fltSemantics &)
bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=0)
static const NamedImmMapper::Mapping MRSPairs[]
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
static const Mapping TLBIPairs[]
static const NamedImmMapper::Mapping MSRPairs[]
uint64_t decodeNeonModImm(unsigned Val, unsigned OpCmode, unsigned &EltBits)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
bool validImm(uint32_t Value) const
static const Mapping ATPairs[]
static const Mapping DBarrierPairs[]
static const Mapping PStatePairs[]
unsigned CountLeadingOnes_64(uint64_t Value)
std::string toString(uint32_t Bits, bool &Valid) const
APInt bitcastToAPInt() const
static const Mapping DCPairs[]
StringRef toString(uint32_t Value, bool &Valid) const
uint32_t fromString(StringRef Name, bool &Valid) const
bool isOnlyMOVNImm(int RegWidth, uint64_t Value, int &UImm16, int &Shift)
LLVM Value Representation.
uint32_t fromString(StringRef Name, bool &Valid) const
bool isFPImm(const APFloat &Val, uint32_t &Imm8Bits)
static const Mapping ISBPairs[]
const fltSemantics & getSemantics() const
std::string lower() const
unsigned CountLeadingOnes_32(uint32_t Value)