[llvm] [LLVM][MC][DecoderEmitter] Add support to specialize decoder per bitwidth (PR #154865)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 2 08:43:02 PDT 2025
jurahul wrote:
One the topic of using the same underlying type for > 1 bitwidths: I had earlier prototyped using something like:
```
tempate <typename T> constexpr bool isBitwidthSupported(uint32_t N) { return false;}
template<> constexpr bool isBitwidthSupported<uint64_t>(uint32_t N) { return N == 48 || N == 64; }
```
This ran into MSVC issues and I wasn't able to find a code pattern that worked. However, it seems we can achieve the same by having a wrapper type to do this:
```
template <typename T, size_ N> // represents a N bit int using an underlying type `T`.
class UIntNBits {
T value;
UIntNBits(T v) : value(v) {
static_assert(std::is_integral_v<T>, "Underlying type expected to be int");
}
uint64_t extractBitsAsZExtValue() { ... }
};
```
We can do this for RISCV if we do need 48 vs 64-bit distinction and do not want to use `std::bitset<>`. I am not sure through if `std::bitset<48>` is any different, will need to look at the generated code for one platform and see if there is any difference.
https://github.com/llvm/llvm-project/pull/154865
More information about the llvm-commits
mailing list