diff options
author | Weiyi Wang <wwylele@gmail.com> | 2019-01-25 18:16:23 +0100 |
---|---|---|
committer | fearlessTobi <thm.frey@gmail.com> | 2019-02-06 17:29:39 +0100 |
commit | 6b81ceb060a0e985380bc33d2f51dcc76aad3eb3 (patch) | |
tree | c24e09bdd88947696f7ea6827f18a10a847df8bb /src/common | |
parent | common/swap: remove default value for swap type internal storage (diff) | |
download | yuzu-6b81ceb060a0e985380bc33d2f51dcc76aad3eb3.tar yuzu-6b81ceb060a0e985380bc33d2f51dcc76aad3eb3.tar.gz yuzu-6b81ceb060a0e985380bc33d2f51dcc76aad3eb3.tar.bz2 yuzu-6b81ceb060a0e985380bc33d2f51dcc76aad3eb3.tar.lz yuzu-6b81ceb060a0e985380bc33d2f51dcc76aad3eb3.tar.xz yuzu-6b81ceb060a0e985380bc33d2f51dcc76aad3eb3.tar.zst yuzu-6b81ceb060a0e985380bc33d2f51dcc76aad3eb3.zip |
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/bit_field.h | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 21e07925d..bd9e21e1e 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h @@ -34,6 +34,7 @@ #include <limits> #include <type_traits> #include "common/common_funcs.h" +#include "common/swap.h" /* * Abstract bitfield class @@ -108,7 +109,7 @@ * symptoms. */ #pragma pack(1) -template <std::size_t Position, std::size_t Bits, typename T> +template <std::size_t Position, std::size_t Bits, typename T, typename EndianTag = LETag> struct BitField { private: // We hide the copy assigment operator here, because the default copy @@ -127,6 +128,8 @@ private: // We store the value as the unsigned type to avoid undefined behaviour on value shifting using StorageType = std::make_unsigned_t<UnderlyingType>; + using StorageTypeWithEndian = typename AddEndian<StorageType, EndianTag>::type; + public: /// Constants to allow limited introspection of fields if needed static constexpr std::size_t position = Position; @@ -172,7 +175,7 @@ public: } constexpr FORCE_INLINE void Assign(const T& value) { - storage = (storage & ~mask) | FormatValue(value); + storage = (static_cast<StorageType>(storage) & ~mask) | FormatValue(value); } constexpr T Value() const { @@ -184,7 +187,7 @@ public: } private: - StorageType storage; + StorageTypeWithEndian storage; static_assert(bits + position <= 8 * sizeof(T), "Bitfield out of range"); @@ -195,3 +198,6 @@ private: static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable in a BitField"); }; #pragma pack() + +template <std::size_t Position, std::size_t Bits, typename T> +using BitFieldBE = BitField<Position, Bits, T, BETag>; |