29#ifndef __BASE_BITUNION_HH__
30#define __BASE_BITUNION_HH__
59 static_assert(std::is_empty_v<Base>,
"Bitfield base class must be empty.");
68 template<
typename C,
typename Type1,
typename Type2>
69 struct T<void (C::*)(Type1 &, Type2)>
111 return *
this = (
Type)other;
127 operator Type ()
const {
return Impl::operator
Type(); }
149 operator Type ()
const {
return Impl::operator
Type(); }
174namespace bitfield_backend
176 template<
class Storage,
int first,
int last>
179 static_assert(first >= last,
180 "Bitfield ranges must be specified as <msb, lsb>");
186 return bits(storage, first, last);
196 template<
class Storage,
int first,
int last>
199 static_assert(first >= last,
200 "Bitfield ranges must be specified as <msb, lsb>");
206 return sext<first - last + 1>(
bits(storage, first, last));
219 template<
class Storage>
224 template<
int first,
int last=first>
226 template<
int first,
int last=first>
229 template<
int first,
int last=first>
233 template<
int first,
int last=first>
236 template<
int first,
int last=first>
239 template<
int first,
int last=first>
250 template <
class Base>
253 static_assert(
sizeof(Base) ==
sizeof(
typename Base::__StorageType),
254 "BitUnion larger than its storage type.");
259 Base::__storage =
val;
267 operator const typename Base::__StorageType ()
const
269 return Base::__storage;
276 Base::__storage =
val;
321 Base::__storage +=
val;
328 Base::__storage -=
val;
335 Base::__storage *=
val;
342 Base::__storage /=
val;
349 Base::__storage %=
val;
356 Base::__storage &=
val;
363 Base::__storage |=
val;
370 Base::__storage ^=
val;
377 Base::__storage <<=
val;
384 Base::__storage >>=
val;
405#define __BitUnion(type, name) \
406 class BitfieldUnderlyingClasses##name : \
407 public gem5::bitfield_backend::BitfieldTypes<type> \
410 typedef type __StorageType; \
411 friend gem5::bitfield_backend::BitUnionBaseType< \
412 gem5::bitfield_backend::BitUnionOperators< \
413 BitfieldUnderlyingClasses##name> >; \
414 friend gem5::bitfield_backend::BitUnionBaseType< \
415 BitfieldUnderlyingClasses##name>; \
428#define EndBitUnion(name) \
431 typedef gem5::bitfield_backend::BitUnionOperators< \
432 BitfieldUnderlyingClasses##name> name;
439#define __SubBitUnion(name, fieldType, ...) \
444 fieldType<__VA_ARGS__> __storage;
455#define EndSubBitUnion(name) \
457 inline operator __StorageType () const \
458 { return __storage; } \
460 inline __StorageType operator = (const __StorageType & _storage) \
461 { return __storage = _storage;} \
470#define SubBitUnion(name, first, last) \
471 __SubBitUnion(name, Bitfield, first, last)
479#define SignedSubBitUnion(name, first, last) \
480 __SubBitUnion(name, SignedBitfield, first, last)
487#define BitUnion(type, name) __BitUnion(type, name)
494#define BitUnion64(name) __BitUnion(uint64_t, name)
495#define BitUnion32(name) __BitUnion(uint32_t, name)
496#define BitUnion16(name) __BitUnion(uint16_t, name)
497#define BitUnion8(name) __BitUnion(uint8_t, name)
521namespace bitfield_backend
542namespace bitfield_backend
545 static inline std::ostream &
556 inline std::ostream &
564 inline std::ostream &
567 os << (
unsigned int)
t;
617 template <
typename T>
618 struct hash<
gem5::BitUnionType<T>> :
public hash<gem5::BitUnionBaseType<T>>
623 return hash<gem5::BitUnionBaseType<T> >::operator()(val);
Type operator=(BitfieldROType< Base > const &other)=delete
BitfieldROType(const BitfieldROType &)=default
TypeDeducer::Storage Storage
Type operator=(const Type val)
BitfieldTypeImpl(const BitfieldTypeImpl &)=default
Type operator=(BitfieldTypeImpl< Base > const &other)
void setter(Storage &storage, Type val)=delete
Type getter(const Storage &storage) const =delete
BitfieldTypeImpl()=default
Type operator=(const Type val)
Type operator=(BitfieldType< Base > const &other)
BitfieldType(const BitfieldType &)=default
Type operator=(const Type val)
Type operator=(BitfieldWOType< Base > const &other)
BitfieldWOType(const BitfieldWOType &)=default
BitUnionOperators & operator++()
BitUnionOperators & operator^=(typename Base::__StorageType const &val)
BitUnionOperators & operator=(BitUnionOperators const &other)
BitUnionOperators operator--(int)
BitUnionOperators & operator&=(typename Base::__StorageType const &val)
BitUnionOperators & operator<<=(typename Base::__StorageType const &val)
BitUnionOperators & operator-=(typename Base::__StorageType const &val)
BitUnionOperators & operator--()
BitUnionOperators(typename Base::__StorageType const &val)
BitUnionOperators & operator>>=(typename Base::__StorageType const &val)
BitUnionOperators & operator%=(typename Base::__StorageType const &val)
BitUnionOperators & operator=(typename Base::__StorageType const &val)
BitUnionOperators & operator+=(typename Base::__StorageType const &val)
BitUnionOperators & operator|=(typename Base::__StorageType const &val)
BitUnionOperators(const BitUnionOperators &)=default
BitUnionOperators & operator*=(typename Base::__StorageType const &val)
BitUnionOperators & operator/=(typename Base::__StorageType const &val)
BitUnionOperators operator++(int)
BitUnionOperators()=default
int64_t getter(const Storage &storage) const
void setter(Storage &storage, int64_t val)
uint64_t getter(const Storage &storage) const
void setter(Storage &storage, uint64_t val)
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
constexpr uint64_t sext(uint64_t val)
Sign-extend an N-bit value to 64 bits.
constexpr void replaceBits(T &val, unsigned first, unsigned last, B bit_val)
A convenience function to replace bits first to last of val with bit_val in place.
typename bitfield_backend::BitUnionBaseType< T >::Type BitUnionBaseType
static std::ostream & bitfieldBackendPrinter(std::ostream &os, const T &t)
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
bool to_number(const std::string &value, Pixel &retval)
static std::ostream & operator<<(std::ostream &os, const DummyMatRegContainer &d)
Overload hash function for BasicBlockRange type.
T< decltype(&Wrapper::setter)>::Storage Storage
T< decltype(&Wrapper::setter)>::Type Type
static bool parse(const std::string &s, BitUnionType< T > &value)
static void show(std::ostream &os, const BitUnionType< T > &value)
static void show(std::ostream &os, const T &value)
BitUnionType< T >::__StorageType Type
BitUnionType< T >::__StorageType Type