diff options
author | Gabe Black <gabeblack@google.com> | 2018-01-06 05:30:46 -0800 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-01-20 07:29:24 +0000 |
commit | cd9450c1d95d9494e2714ec84620c548b0eebbb1 (patch) | |
tree | 1f9ec93031ec2a79ef8dbcefa57b7e44104deed9 /src/base/bituniontest.cc | |
parent | ecec88750729b2c94d5ca9dedbf7a755c46c41a7 (diff) | |
download | gem5-cd9450c1d95d9494e2714ec84620c548b0eebbb1.tar.xz |
base: Rework bitunions so they can be more flexible.
They are now oriented around a class which makes it easy to provide
custom setter/getter functions which let you set or read bits in an
arbitrary way.
Future additions may add the ability to add custom bitfield methods,
and index-able bitfields.
Change-Id: Ibd6d4d9e49107490f6dad30a4379a8c93bda9333
Reviewed-on: https://gem5-review.googlesource.com/7201
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/base/bituniontest.cc')
-rw-r--r-- | src/base/bituniontest.cc | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/base/bituniontest.cc b/src/base/bituniontest.cc index 1f24e7e66..ed7b77b66 100644 --- a/src/base/bituniontest.cc +++ b/src/base/bituniontest.cc @@ -66,6 +66,44 @@ EndBitUnion(EmptySixteen) BitUnion8(EmptyEight) EndBitUnion(EmptyEight) +class SplitField +{ + protected: + BitUnion64(In) + Bitfield<15, 12> high; + Bitfield<7, 4> low; + EndBitUnion(In) + + BitUnion64(Out) + Bitfield<7, 4> high; + Bitfield<3, 0> low; + EndBitUnion(Out) + public: + uint64_t + getter(const uint64_t &storage) const + { + Out out = 0; + In in = storage; + out.high = in.high; + out.low = in.low; + return out; + } + + void + setter(uint64_t &storage, uint64_t val) + { + Out out = val; + In in = 0; + in.high = out.high; + in.low = out.low; + storage = in; + } +}; + +BitUnion64(Split) + BitfieldType<SplitField> split; +EndBitUnion(Split) + struct ContainingStruct { BitUnion64(Contained) @@ -99,8 +137,9 @@ EmptyEight emptyEight(0); class BitUnionData : public testing::Test { protected: SixtyFour sixtyFour; + Split split; - void SetUp() override { sixtyFour = 0; } + void SetUp() override { sixtyFour = 0; split = 0; } }; TEST_F(BitUnionData, NormalBitfield) @@ -192,3 +231,11 @@ TEST_F(BitUnionData, Operators) sixtyFour = otherSixtyFour; EXPECT_TRUE(sixtyFour == otherSixtyFour); } + +TEST_F(BitUnionData, Custom) +{ + EXPECT_EQ(split, 0); + split.split = 0xfff; + EXPECT_EQ(split, 0xf0f0); + EXPECT_EQ((uint64_t)split.split, 0xff); +} |