[llvm] [LLVM][MC][DecoderEmitter] Add support to specialize decoder per bitwidth (PR #154865)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 29 13:52:01 PDT 2025
================
@@ -700,6 +700,12 @@ static constexpr DecoderListEntry DecoderList32[]{
{DecoderTableZdinxRV32Only32, {}, "RV32-only Zdinx (Double in Integer)"},
};
+// Define bitwidths for various types used to instantiate the decoder.
+template <> static constexpr uint32_t llvm::MCD::InsnBitWidth<uint16_t> = 16;
+template <> static constexpr uint32_t llvm::MCD::InsnBitWidth<uint32_t> = 32;
+// Use uint64_t to represent 48 bit instructions.
+template <> static constexpr uint32_t llvm::MCD::InsnBitWidth<uint64_t> = 48;
----------------
jurahul wrote:
So something like?
```
template <>
struct TypeForBitWidth<32> {
using T = uint32_t;
};
template <>
struct TypeForBitWidth<64> {
using T = uint64_t;
};
int decodeToMCInst(TypeForBitWidth<32>::T Insn) {
return 32;
}
int decodeToMCInst(TypeForBitWidth<64>::T Insn) {
return 64;
}
int main() {
uint32_t x = 0;
std::cout << decodeToMCInst(x) << '\n';
uint64_t y = 0;
std::cout << decodeToMCInst(y) << '\n';
}
```
@topperc and @s-barannikov WDYT? It conveys the same information, but I agree its more directly expressing things. Note that with this though it won't directly work if/when we want to support > 1 bitwidth for a given type (which I did attempt in this PR but gave up because MSVC broke).
https://github.com/llvm/llvm-project/pull/154865
More information about the llvm-commits
mailing list