Go to the documentation of this file.
29 #ifndef __BASE_BITUNION_HH__
30 #define __BASE_BITUNION_HH__
34 #include <type_traits>
54 static_assert(std::is_empty<Base>::value,
55 "Bitfield base class must be empty.");
64 template<
typename C,
typename Type1,
typename Type2>
65 struct T<void (C::*)(Type1 &, Type2)>
107 return *
this = (
Type)other;
123 operator Type ()
const {
return Impl::operator
Type(); }
145 operator Type ()
const {
return Impl::operator
Type(); }
149 template <
class Base>
172 template<
class Storage,
int first,
int last>
175 static_assert(first >= last,
176 "Bitfield ranges must be specified as <msb, lsb>");
182 return bits(storage, first, last);
192 template<
class Storage,
int first,
int last>
195 static_assert(first >= last,
196 "Bitfield ranges must be specified as <msb, lsb>");
202 return sext<first - last + 1>(
bits(storage, first, last));
215 template<
class Storage>
220 template<
int first,
int last=first>
222 template<
int first,
int last=first>
225 template<
int first,
int last=first>
229 template<
int first,
int last=first>
232 template<
int first,
int last=first>
235 template<
int first,
int last=first>
246 template <
class Base>
249 static_assert(
sizeof(Base) ==
sizeof(
typename Base::__StorageType),
250 "BitUnion larger than its storage type.");
255 Base::__storage =
val;
262 operator const typename Base::__StorageType ()
const
264 return Base::__storage;
267 typename Base::__StorageType
270 Base::__storage =
val;
274 typename Base::__StorageType
277 Base::__storage = other;
278 return Base::__storage;
284 return Base::__storage <
base.__storage;
290 return Base::__storage ==
base.__storage;
310 #define __BitUnion(type, name) \
311 class BitfieldUnderlyingClasses##name : \
312 public BitfieldBackend::BitfieldTypes<type> \
315 typedef type __StorageType; \
316 friend BitfieldBackend::BitUnionBaseType< \
317 BitfieldBackend::BitUnionOperators< \
318 BitfieldUnderlyingClasses##name> >; \
319 friend BitfieldBackend::BitUnionBaseType< \
320 BitfieldUnderlyingClasses##name>; \
333 #define EndBitUnion(name) \
336 typedef BitfieldBackend::BitUnionOperators< \
337 BitfieldUnderlyingClasses##name> name;
344 #define __SubBitUnion(name, fieldType, ...) \
349 fieldType<__VA_ARGS__> __storage;
360 #define EndSubBitUnion(name) \
362 inline operator __StorageType () const \
363 { return __storage; } \
365 inline __StorageType operator = (const __StorageType & _storage) \
366 { return __storage = _storage;} \
375 #define SubBitUnion(name, first, last) \
376 __SubBitUnion(name, Bitfield, first, last)
384 #define SignedSubBitUnion(name, first, last) \
385 __SubBitUnion(name, SignedBitfield, first, last)
392 #define BitUnion(type, name) __BitUnion(type, name)
399 #define BitUnion64(name) __BitUnion(uint64_t, name)
400 #define BitUnion32(name) __BitUnion(uint32_t, name)
401 #define BitUnion16(name) __BitUnion(uint16_t, name)
402 #define BitUnion8(name) __BitUnion(uint8_t, name)
423 template <
typename T>
444 template <
typename T>
451 template <
typename T>
457 return hash<BitUnionBaseType<T> >::operator()(
val);
467 static inline std::ostream &
478 inline std::ostream &
486 inline std::ostream &
489 os << (
unsigned int)
t;
500 template <
typename T>
508 #endif // __BASE_BITUNION_HH__
BitUnionOperators(typename Base::__StorageType const &val)
bool operator==(Base const &base) const
void replaceBits(T &val, int first, int last, B bit_val)
A convenience function to replace bits first to last of val with bit_val in place.
bool operator<(Base const &base) const
Base::__StorageType operator=(BitUnionOperators const &other)
T< decltype(&Wrapper::setter)>::Storage Storage
uint64_t sext(uint64_t val)
Sign-extend an N-bit value to 64 bits.
int64_t getter(const Storage &storage) const
BitfieldTypeImpl()=default
TypeDeducer::Storage Storage
Type getter(const Storage &storage) const =delete
Type operator=(const Type val)
void setter(Storage &storage, uint64_t val)
void setter(Storage &storage, int64_t val)
void setter(Storage &storage, Type val)=delete
T< decltype(&Wrapper::setter)>::Type Type
BitUnionType< T >::__StorageType Type
uint64_t getter(const Storage &storage) const
Type operator=(const Type val)
Base::__StorageType operator=(typename Base::__StorageType const &val)
Type operator=(BitfieldType< Base > const &other)
Overload hash function for BasicBlockRange type.
static std::ostream & bitfieldBackendPrinter(std::ostream &os, const T &t)
std::ostream & operator<<(std::ostream &os, const BitUnionType< T > &bu)
A default << operator which casts a bitunion to its underlying type and passes it to BitfieldBackend:...
Type operator=(const Type val)
Type operator=(BitfieldROType< Base > const &other)=delete
BitUnionType< T >::__StorageType Type
Type operator=(BitfieldTypeImpl< Base > const &other)
Type operator=(BitfieldWOType< Base > const &other)
typename BitfieldBackend::BitUnionBaseType< T >::Type BitUnionBaseType
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17