10#ifndef LLVM_MC_MCDECODER_H
11#define LLVM_MC_MCDECODER_H
32template <
typename IntType>
33#if defined(_MSC_VER) && !defined(__clang__)
36inline std::enable_if_t<std::is_integral_v<IntType>, IntType>
38 assert(StartBit + NumBits <= 64 && "Cannot support >64-bit extractions!
");
39 assert(StartBit + NumBits <= (sizeof(IntType) * 8) &&
41 const IntType Mask = maskTrailingOnes<IntType>(NumBits);
42 return (Insn >> StartBit) & Mask;
45template <typename InsnType>
46inline std::enable_if_t<!std::is_integral_v<InsnType>, uint64_t>
47fieldFromInstruction(const InsnType &Insn, unsigned StartBit,
49 return Insn.extractBitsAsZExtValue(NumBits, StartBit);
53uint64_t fieldFromInstruction(const std::bitset<N> &Insn, unsigned StartBit,
55 assert(StartBit + NumBits <= N && "Instruction field out of bounds!
");
56 assert(NumBits <= 64 && "Cannot
support >64-bit extractions!
");
57 const std::bitset<N> Mask(maskTrailingOnes<uint64_t>(NumBits));
58 return ((Insn >> StartBit) & Mask).to_ullong();
61// Helper function for inserting bits extracted from an encoded instruction into
62// an integer-typed field.
63template <typename IntType>
64static std::enable_if_t<std::is_integral_v<IntType>, void>
65insertBits(IntType &field, IntType bits, unsigned startBit, unsigned numBits) {
66 // Check that no bit beyond numBits is set, so that a simple bitwise |
68 assert((~(((IntType)1 << numBits) - 1) & bits) == 0 &&
69 "bits has more than numBits bits set
");
70 assert(startBit + numBits <= sizeof(IntType) * 8);
72 field |= bits << startBit;
75} // namespace llvm::MCD
77#endif // LLVM_MC_MCDECODER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
DecodeStatus
Ternary decode status.
bool Check(MCDisassembler::DecodeStatus &Out, MCDisassembler::DecodeStatus In)
std::enable_if_t< std::is_integral_v< IntType >, IntType > fieldFromInstruction(const IntType &Insn, unsigned StartBit, unsigned NumBits)