Gabriel B. has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/67672?usp=email )

Change subject: mem-ruby: Add NodeID<->MachineID conversion funcs to MachineID
......................................................................

mem-ruby: Add NodeID<->MachineID conversion funcs to MachineID

This is a convenience function that enables convertion from global
NodeID to MachineID and vice-versa. If the provided node ID does not
convert to a machine ID (e.g., this is a switch), an error is
triggered.

Change-Id: I345d9de92f44638ed0908f3f7a889db01c60ba7b
---
M src/mem/ruby/common/MachineID.hh
1 file changed, 38 insertions(+), 0 deletions(-)



diff --git a/src/mem/ruby/common/MachineID.hh b/src/mem/ruby/common/MachineID.hh
index 949e59c..bda3ca7 100644
--- a/src/mem/ruby/common/MachineID.hh
+++ b/src/mem/ruby/common/MachineID.hh
@@ -67,6 +67,30 @@
     NodeID getNum() const { return num; }

     bool isValid() const { return type != MachineType_NUM; }
+
+    NodeID toGlobalNodeID() const {
+        return MachineType_base_number(getType()) + getNum();
+    }
+
+    static MachineID fromGlobalNodeID(NodeID id) {
+ // inverse of toGlobalNodeID. Retrieves the global nodeID interval that + // the argument belongs to, i.e., it's machine type. Then compute the + // ofset of the argument in that interval, i.e., the version of that
+        // machine.
+        auto baseID = 0;
+        auto machineTypeEnd = static_cast<int>(MachineType_NUM);
+        gem5_assert(machineTypeEnd > 0);
+        for (int mt = 0; mt < machineTypeEnd; mt++) {
+            auto mtNext = static_cast<MachineType>(mt+1);
+            auto nextBaseID = MachineType_base_number(mtNext);
+            if (id <= nextBaseID) {
+                return {static_cast<MachineType>(mt), id - baseID};
+            }
+            baseID = nextBaseID;
+        }
+        throw std::runtime_error(
+            "Invalid NodeID for conversion to  MachineID");
+    }
 };

 inline std::string

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

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I345d9de92f44638ed0908f3f7a889db01c60ba7b
Gerrit-Change-Number: 67672
Gerrit-PatchSet: 1
Gerrit-Owner: Gabriel B. <gabriel.bus...@arteris.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org

Reply via email to