base: Add some operators to the BitUnion types.
The operators it seems to need are ones which modify the BitUnion being operated on, vs ones which just use it to produce a new value. The later kind can be handled by converting the BitUnion into its underlying type and then applying the built in operators. Change-Id: I8aa08bf74d8ad88f4dfbb0031610c52ad412d03b Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/41515 Reviewed-by: Gabe Black <gabe.black@gmail.com> Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br> Maintainer: Gabe Black <gabe.black@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -260,35 +260,126 @@ namespace BitfieldBackend
|
||||
|
||||
BitUnionOperators() {}
|
||||
|
||||
//Conversion operators.
|
||||
operator const typename Base::__StorageType () const
|
||||
{
|
||||
return Base::__storage;
|
||||
}
|
||||
|
||||
typename Base::__StorageType
|
||||
//Basic assignment operators.
|
||||
BitUnionOperators &
|
||||
operator=(typename Base::__StorageType const &val)
|
||||
{
|
||||
Base::__storage = val;
|
||||
return val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
typename Base::__StorageType
|
||||
BitUnionOperators &
|
||||
operator=(BitUnionOperators const &other)
|
||||
{
|
||||
Base::__storage = other;
|
||||
return Base::__storage;
|
||||
return operator=(other.__storage);
|
||||
}
|
||||
|
||||
bool
|
||||
operator<(Base const &base) const
|
||||
//Increment and decrement operators.
|
||||
BitUnionOperators &
|
||||
operator++()
|
||||
{
|
||||
return Base::__storage < base.__storage;
|
||||
Base::__storage++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool
|
||||
operator==(Base const &base) const
|
||||
BitUnionOperators
|
||||
operator++(int)
|
||||
{
|
||||
return Base::__storage == base.__storage;
|
||||
BitUnionOperators ret = *this;
|
||||
operator++();
|
||||
return ret;
|
||||
}
|
||||
|
||||
BitUnionOperators &
|
||||
operator--()
|
||||
{
|
||||
Base::__storage--;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitUnionOperators
|
||||
operator--(int)
|
||||
{
|
||||
BitUnionOperators ret = *this;
|
||||
operator--();
|
||||
return ret;
|
||||
}
|
||||
|
||||
//Operation and assignment operators
|
||||
BitUnionOperators &
|
||||
operator+=(typename Base::__StorageType const &val)
|
||||
{
|
||||
Base::__storage += val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitUnionOperators &
|
||||
operator-=(typename Base::__StorageType const &val)
|
||||
{
|
||||
Base::__storage -= val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitUnionOperators &
|
||||
operator*=(typename Base::__StorageType const &val)
|
||||
{
|
||||
Base::__storage *= val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitUnionOperators &
|
||||
operator/=(typename Base::__StorageType const &val)
|
||||
{
|
||||
Base::__storage /= val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitUnionOperators &
|
||||
operator%=(typename Base::__StorageType const &val)
|
||||
{
|
||||
Base::__storage %= val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitUnionOperators &
|
||||
operator&=(typename Base::__StorageType const &val)
|
||||
{
|
||||
Base::__storage &= val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitUnionOperators &
|
||||
operator|=(typename Base::__StorageType const &val)
|
||||
{
|
||||
Base::__storage |= val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitUnionOperators &
|
||||
operator^=(typename Base::__StorageType const &val)
|
||||
{
|
||||
Base::__storage ^= val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitUnionOperators &
|
||||
operator<<=(typename Base::__StorageType const &val)
|
||||
{
|
||||
Base::__storage <<= val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitUnionOperators &
|
||||
operator>>=(typename Base::__StorageType const &val)
|
||||
{
|
||||
Base::__storage >>= val;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user