Bradley Wang has submitted this change and it was merged. ( https://gem5-review.googlesource.com/c/public/gem5/+/11870 )

Change subject: cpu: Add hash functionality for RegId class
......................................................................

cpu: Add hash functionality for RegId class

Having a hash function defined within the header will allow all
classes using RegId to use the class as a Key in a STL
unordered_map.

Change-Id: I32fd302a087c74e844dcbfce93fef9d0ed98d6bf
Signed-off-by: Bradley Wang <[email protected]>
Reviewed-on: https://gem5-review.googlesource.com/11870
Reviewed-by: Giacomo Travaglini <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
---
M src/cpu/reg_class.hh
1 file changed, 30 insertions(+), 0 deletions(-)

Approvals:
  Giacomo Travaglini: Looks good to me, approved
  Jason Lowe-Power: Looks good to me, approved



diff --git a/src/cpu/reg_class.hh b/src/cpu/reg_class.hh
index def275e..617d17e 100644
--- a/src/cpu/reg_class.hh
+++ b/src/cpu/reg_class.hh
@@ -82,6 +82,7 @@
     RegIndex regIdx;
     ElemIndex elemIdx;
     static constexpr size_t Scale = TheISA::NumVecElemPerVecReg;
+    friend struct std::hash<RegId>;
   public:
     RegId() {};
     RegId(RegClass reg_class, RegIndex reg_idx)
@@ -201,4 +202,33 @@
         return os << rid.className() << "{" << rid.index() << "}";
     }
 };
+
+namespace std
+{
+template<>
+struct hash<RegId>
+{
+    size_t operator()(const RegId& reg_id) const
+    {
+ // Extract unique integral values for the effective fields of a RegId.
+        const size_t flat_index = static_cast<size_t>(reg_id.flatIndex());
+        const size_t class_num = static_cast<size_t>(reg_id.regClass);
+
+ const size_t shifted_class_num = class_num << (sizeof(RegIndex) << 3);
+
+ // Concatenate the class_num to the end of the flat_index, in order to
+        // maximize information retained.
+        const size_t concatenated_hash = flat_index | shifted_class_num;
+
+        // If RegIndex is larger than size_t, then class_num will not be
+        // considered by this hash function, so we may wish to perform a
+        // different operation to include that information in the hash.
+        static_assert(sizeof(RegIndex) < sizeof(size_t),
+            "sizeof(RegIndex) should be less than sizeof(size_t)");
+
+        return concatenated_hash;
+    }
+};
+}
+
 #endif // __CPU__REG_CLASS_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/11870
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I32fd302a087c74e844dcbfce93fef9d0ed98d6bf
Gerrit-Change-Number: 11870
Gerrit-PatchSet: 5
Gerrit-Owner: Bradley Wang <[email protected]>
Gerrit-Reviewer: Bradley Wang <[email protected]>
Gerrit-Reviewer: Giacomo Gabrielli <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-CC: Andreas Sandberg <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to