summaryrefslogtreecommitdiff
path: root/src/base/bitunion.hh
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2015-01-07 00:31:46 -0800
committerGabe Black <gabeblack@google.com>2015-01-07 00:31:46 -0800
commit86dea86987ef61192deca4d2f1a980893f50e092 (patch)
tree7681649cfe2f9d0cb464dc2252e657c1acb7e3d7 /src/base/bitunion.hh
parentd0284544ec339808c2273ced3ebc566cad285a4a (diff)
downloadgem5-86dea86987ef61192deca4d2f1a980893f50e092.tar.xz
base: Fix assigning between identical bitfields.
If two bitfields are of the same type, also implying that they have the same first and last bit positions, the existing implementation would copy the entire bitfield. That includes the __data member which is shared among all the bitfields, effectively overwritting the entire bitunion. This change also adjusts the write only signed bitfield assignment operator to be like the unsigned version, using "using" instead of implementing it again and calling down to the underlying implementation.
Diffstat (limited to 'src/base/bitunion.hh')
-rw-r--r--src/base/bitunion.hh31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/base/bitunion.hh b/src/base/bitunion.hh
index 190c1a5e1..c4b67b073 100644
--- a/src/base/bitunion.hh
+++ b/src/base/bitunion.hh
@@ -100,6 +100,12 @@ namespace BitfieldBackend
this->setBits(first, last, _data);
return _data;
}
+
+ uint64_t
+ operator=(Bitfield<first, last> const & other)
+ {
+ return *this = (uint64_t)other;
+ }
};
//A class which specializes the above so that it can only be read
@@ -113,6 +119,9 @@ namespace BitfieldBackend
private:
uint64_t
operator=(const uint64_t _data);
+
+ uint64_t
+ operator=(const Bitfield<first, last>& other);
};
//Similar to the above, but only allows writing.
@@ -150,6 +159,12 @@ namespace BitfieldBackend
this->setBits(first, last, _data);
return _data;
}
+
+ int64_t
+ operator=(SignedBitfield<first, last> const & other)
+ {
+ return *this = (int64_t)other;
+ }
};
//A class which specializes the above so that it can only be read
@@ -163,6 +178,9 @@ namespace BitfieldBackend
private:
int64_t
operator=(const int64_t _data);
+
+ int64_t
+ operator=(const SignedBitfield<first, last>& other);
};
//Similar to the above, but only allows writing.
@@ -173,11 +191,7 @@ namespace BitfieldBackend
operator const int64_t () const;
public:
- int64_t operator=(const int64_t _data)
- {
- *((SignedBitfield<first, last> *)this) = _data;
- return _data;
- }
+ using SignedBitfield<first, last>::operator=;
};
};
@@ -215,6 +229,13 @@ namespace BitfieldBackend
return _data;
}
+ Type
+ operator=(BitUnionOperators const & other)
+ {
+ Base::__data = other;
+ return Base::__data;
+ }
+
bool
operator<(Base const & base) const
{