28 #include <gtest/gtest.h>
32 #include <type_traits>
42 Bitfield<39, 32> byte5;
44 BitfieldRO<39, 32> byte5RO;
45 BitfieldWO<39, 32> byte5WO;
47 Bitfield<43, 42> bits43To42;
49 SignedBitfield<41> bit41Signed;
51 SignedBitfield<47, 40> byte6Signed;
52 SignedBitfieldRO<47, 40> byte6SignedRO;
53 SignedBitfieldWO<47, 40> byte6SignedWO;
72 Bitfield<15, 12> high;
82 getter(
const uint64_t &storage)
const
92 setter(uint64_t &storage, uint64_t
val)
106 struct ContainingStruct
109 Bitfield<63, 60> topNibble;
116 containingFunc(uint64_t init_val, uint64_t fieldVal)
119 Bitfield<16, 15> field;
122 Contained contained = init_val;
123 contained.field = fieldVal;
141 void SetUp()
override { sixtyFour = 0; split = 0; }
143 template <
typename T>
146 template <
typename T>
158 sixtyFour.byte5 = 0xff;
160 sixtyFour.byte5 = 0xfff;
168 sixtyFour.bit2 = 0x1;
176 sixtyFour.byte5 = 0xff;
182 sixtyFour.byte5WO = 0xff;
189 sixtyFour.byte6 = 0x2;
191 sixtyFour.byte6.bits43To42 = 0x3;
193 sixtyFour.byte6 = 0xff;
194 sixtyFour.byte6.bit41 = 0;
200 sixtyFour.byte6 = 0xff;
203 sixtyFour.byte6SignedWO = 0;
211 ContainingStruct containing;
212 containing.contained = 0;
213 containing.contained.topNibble = 0xd;
214 EXPECT_EQ(containing.contained, 0xd000000000000000);
219 EXPECT_EQ(containingFunc(0xfffff, 0), 0xe7fff);
224 SixtyFour otherSixtyFour = 0;
226 otherSixtyFour.byte6.bit41 = sixtyFour.bit2;
227 EXPECT_EQ(otherSixtyFour, 0x20000000000);
228 otherSixtyFour.bit2 = sixtyFour.bit2;
229 EXPECT_EQ(otherSixtyFour, 0x20000000004);
234 SixtyFour otherSixtyFour = 0x4;
235 sixtyFour = otherSixtyFour;
241 sixtyFour = otherSixtyFour;
256 EXPECT_EQ(templatedFunction(sixtyFour), 0xff);
257 EXPECT_EQ(templatedFunction((uint64_t)sixtyFour), 0);
266 is64 = std::is_same<BitUnionBaseType<Dummy64>, uint64_t>::value;
268 is64 = std::is_same<BitUnionBaseType<Dummy32>, uint64_t>::value;
274 sixtyFour = 1234567812345678;
275 std::stringstream
ss;
280 EmptyEight eight = 65;