mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-14 17:30:05 +00:00
bit_field: Left/right shifts are well defined in C++20
This commit is contained in:
parent
334567d33b
commit
7ad3e3c7bb
@ -175,6 +175,10 @@ constexpr OutputType ExtractBits(const RawType& raw) {
|
||||
static_assert(sizeof(RawType) == sizeof(SignedType));
|
||||
constexpr auto RightShift = BitSize<RawType>() - NumBits;
|
||||
constexpr auto LeftShift = RightShift - Position;
|
||||
// C++20: Signed Integers are Two’s Complement
|
||||
// Left-shift on signed integer types produces the same results as
|
||||
// left-shift on the corresponding unsigned integer type.
|
||||
// Right-shift is an arithmetic right shift which performs sign-extension.
|
||||
return AutoBitCast<OutputType>((AutoBitCast<SignedType>(raw) << LeftShift) >> RightShift);
|
||||
} else {
|
||||
using UnsignedType = SmallestUIntType<BitSize<RawType>()>;
|
||||
|
Loading…
Reference in New Issue
Block a user