Cleaned == and < operators in hei_operator_register.hpp
Change-Id: I87f57dbef04eb578db39aa86920189d99dca0968
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
diff --git a/src/register/hei_operator_register.hpp b/src/register/hei_operator_register.hpp
index a0d0f6c..02c9b1d 100644
--- a/src/register/hei_operator_register.hpp
+++ b/src/register/hei_operator_register.hpp
@@ -74,11 +74,13 @@
return &iv_result;
}
+ /** @brief Comparison operator. */
bool operator==(const NotRegister& r) const
{
- return r.iv_child == iv_child;
+ return iv_child == r.iv_child;
}
+ /** @brief Less-than operator. */
bool operator<(const NotRegister& r) const
{
return iv_child < r.iv_child;
@@ -119,11 +121,13 @@
return &iv_result;
}
+ /** @brief Comparison operator. */
bool operator==(const LeftShiftRegister& r) const
{
- return (r.iv_child == iv_child) && (r.iv_amount == iv_amount);
+ return (iv_child == r.iv_child) && (iv_amount == r.iv_amount);
}
+ /** @brief Less-than operator. */
bool operator<(const LeftShiftRegister& r) const
{
if (iv_child == r.iv_child)
@@ -167,11 +171,13 @@
return &iv_result;
}
+ /** @brief Comparison operator. */
bool operator==(const RightShiftRegister& r) const
{
- return (r.iv_child == iv_child) && (r.iv_amount == iv_amount);
+ return (iv_child == r.iv_child) && (iv_amount == r.iv_amount);
}
+ /** @brief Less-than operator. */
bool operator<(const RightShiftRegister& r) const
{
if (iv_child == r.iv_child)
@@ -217,11 +223,13 @@
return &iv_result;
}
+ /** @brief Comparison operator. */
bool operator==(const AndRegister& r) const
{
- return (r.iv_left == iv_left) && (r.iv_right == iv_right);
+ return (iv_left == r.iv_left) && (iv_right == r.iv_right);
}
+ /** @brief Less-than operator. */
bool operator<(const AndRegister& r) const
{
if (iv_left == r.iv_left)
@@ -267,11 +275,13 @@
return &iv_result;
}
+ /** @brief Comparison operator. */
bool operator==(const OrRegister& r) const
{
- return (r.iv_left == iv_left) && (r.iv_right == iv_right);
+ return (iv_left == r.iv_left) && (iv_right == r.iv_right);
}
+ /** @brief Less-than operator. */
bool operator<(const OrRegister& r) const
{
if (iv_left == r.iv_left)
@@ -312,9 +322,16 @@
return &iv_result;
}
+ /** @brief Comparison operator. */
bool operator==(const ConstantRegister& r) const
{
- return r.iv_result == iv_result;
+ return iv_result == r.iv_result;
+ }
+
+ /** @brief Less-than operator. */
+ bool operator<(const ConstantRegister& r) const
+ {
+ return iv_result < r.iv_result;
}
};
diff --git a/src/util/hei_bit_string.cpp b/src/util/hei_bit_string.cpp
index b1780ca..16713ec 100644
--- a/src/util/hei_bit_string.cpp
+++ b/src/util/hei_bit_string.cpp
@@ -284,6 +284,35 @@
//------------------------------------------------------------------------------
+bool BitString::operator<(const BitString& i_str) const
+{
+ // The two bit strings must be the same length. Otherwise, the comparison
+ // undefined (i.e. compare from the left vs. right).
+ HEI_ASSERT(getBitLen() == i_str.getBitLen());
+
+ for (uint64_t pos = 0; pos < getBitLen(); pos += UINT64_BIT_LEN)
+ {
+ uint64_t len = std::min(getBitLen() - pos, UINT64_BIT_LEN);
+
+ auto l_str = getFieldRight(pos, len);
+ auto r_str = i_str.getFieldRight(pos, len);
+
+ if (l_str < r_str)
+ {
+ return true;
+ }
+ // The loop can only continue if the values are equal.
+ else if (l_str > r_str)
+ {
+ return false;
+ }
+ }
+
+ return false;
+}
+
+//------------------------------------------------------------------------------
+
BitStringBuffer BitString::operator~() const
{
BitStringBuffer bsb(getBitLen());
diff --git a/src/util/hei_bit_string.hpp b/src/util/hei_bit_string.hpp
index 4b63906..0bb4d8c 100644
--- a/src/util/hei_bit_string.hpp
+++ b/src/util/hei_bit_string.hpp
@@ -333,6 +333,9 @@
return isEqual(i_str);
}
+ /** @brief Less-than operator */
+ bool operator<(const BitString& i_str) const;
+
/** @brief Bitwise NOT operator. */
BitStringBuffer operator~() const;