10#ifndef LLVM_MC_MCDECODER_H
11#define LLVM_MC_MCDECODER_H
31template <
typename IntType>
32#if defined(_MSC_VER) && !defined(__clang__)
35inline std::enable_if_t<std::is_integral_v<IntType>, IntType>
37 assert(StartBit + NumBits <= 64 && "Cannot support >64-bit extractions!
");
38 assert(StartBit + NumBits <= (sizeof(IntType) * 8) &&
40 const IntType Mask = maskTrailingOnes<IntType>(NumBits);
41 return (Insn >> StartBit) & Mask;
44template <typename InsnType>
45inline std::enable_if_t<!std::is_integral_v<InsnType>, uint64_t>
46fieldFromInstruction(const InsnType &Insn, unsigned StartBit,
48 return Insn.extractBitsAsZExtValue(NumBits, StartBit);
51// Helper function for inserting bits extracted from an encoded instruction into
52// an integer-typed field.
53template <typename IntType>
54static std::enable_if_t<std::is_integral_v<IntType>, void>
55insertBits(IntType &field, IntType bits, unsigned startBit, unsigned numBits) {
56 // Check that no bit beyond numBits is set, so that a simple bitwise |
58 assert((~(((IntType)1 << numBits) - 1) & bits) == 0 &&
59 "bits has more than numBits bits set
");
60 assert(startBit + numBits <= sizeof(IntType) * 8);
62 field |= bits << startBit;
65} // namespace llvm::MCD
67#endif // LLVM_MC_MCDECODER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
DecodeStatus
Ternary decode status.
std::enable_if_t< std::is_integral_v< IntType >, IntType > fieldFromInstruction(const IntType &Insn, unsigned StartBit, unsigned NumBits)