summaryrefslogtreecommitdiffstats
path: root/src/common/bit_field.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2019-03-21 04:44:20 +0100
committerGitHub <noreply@github.com>2019-03-21 04:44:20 +0100
commit3e930304fe6fb29a2421dd0fdfef6e66ebb213ad (patch)
tree3298c05a68692803d9124b919f7f3fe284d535c8 /src/common/bit_field.h
parentMerge pull request #2262 from lioncash/enum (diff)
parentMake bitfield assignment operator public (diff)
downloadyuzu-3e930304fe6fb29a2421dd0fdfef6e66ebb213ad.tar
yuzu-3e930304fe6fb29a2421dd0fdfef6e66ebb213ad.tar.gz
yuzu-3e930304fe6fb29a2421dd0fdfef6e66ebb213ad.tar.bz2
yuzu-3e930304fe6fb29a2421dd0fdfef6e66ebb213ad.tar.lz
yuzu-3e930304fe6fb29a2421dd0fdfef6e66ebb213ad.tar.xz
yuzu-3e930304fe6fb29a2421dd0fdfef6e66ebb213ad.tar.zst
yuzu-3e930304fe6fb29a2421dd0fdfef6e66ebb213ad.zip
Diffstat (limited to '')
-rw-r--r--src/common/bit_field.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/common/bit_field.h b/src/common/bit_field.h
index 7433c39ba..8e35c463f 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:
// UnderlyingType is T for non-enum types and the underlying type of T if
@@ -121,7 +122,11 @@ 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:
+ BitField& operator=(const BitField&) = default;
+
/// Constants to allow limited introspection of fields if needed
static constexpr std::size_t position = Position;
static constexpr std::size_t bits = Bits;
@@ -170,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 {
@@ -182,7 +187,7 @@ public:
}
private:
- StorageType storage;
+ StorageTypeWithEndian storage;
static_assert(bits + position <= 8 * sizeof(T), "Bitfield out of range");
@@ -193,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>;