Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/41999 )

Change subject: arch,cpu: Separate printing and serialization of VecPredReg.
......................................................................

arch,cpu: Separate printing and serialization of VecPredReg.

This is equivalent to what was done with VecReg recently.

Change-Id: I8e28c9796bf5cabd35a6bf5b89e55efcf9324d92
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/41999
Reviewed-by: Gabe Black <[email protected]>
Maintainer: Gabe Black <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/arch/generic/vec_pred_reg.hh
M src/cpu/o3/regfile.hh
M src/cpu/simple_thread.hh
3 files changed, 37 insertions(+), 29 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/arch/generic/vec_pred_reg.hh b/src/arch/generic/vec_pred_reg.hh
index d156ba0..3e248b4 100644
--- a/src/arch/generic/vec_pred_reg.hh
+++ b/src/arch/generic/vec_pred_reg.hh
@@ -42,6 +42,7 @@

 #include "arch/generic/vec_reg.hh"
 #include "base/cprintf.hh"
+#include "sim/serialize_handlers.hh"

 template <size_t NumBits, bool Packed>
 class VecPredRegContainer;
@@ -152,18 +153,13 @@
     friend std::ostream&
     operator<<(std::ostream& os, const MyClass& p)
     {
-        // 0-sized is not allowed
-        os << '[' << p.container[0];
-        for (int i = 0; i < p.NUM_BITS; ++i) {
-            os << " " << (p.container[i] ? 1 : 0);
-        }
-        os << ']';
+        // Size must be greater than 0.
+        for (int i = 0; i < NUM_BITS; i++)
+            ccprintf(os, "%s%d", i ? " " : "[", (int)p.container[i]);
+        ccprintf(os, "]");
         return os;
     }

-    /// Returns a string representation of the register content.
-    const std::string print() const { return csprintf("%s", *this); }
-
     /// Returns true if the first active element of the register is true.
     /// @param mask Input mask used to filter the predicates to be tested.
/// @param actual_num_elems Actual number of vector elements considered for
@@ -326,18 +322,18 @@
         }
     }

-    /// Returns a string representation of the register content.
-    const std::string print() const { return csprintf("%s", *this); }
-
     friend std::ostream&
-    operator<<(std::ostream& os, const MyClass& v)
+    operator<<(std::ostream& os, const MyClass& p)
     {
-        for (auto b: v.container) {
-            os << csprintf("%d", b);
-        }
+        // Size must be greater than 0.
+        for (int i = 0; i < NumBits; i++)
+            ccprintf(os, "%s%d", i ? " " : "[", (int)p.container[i]);
+        ccprintf(os, "]");
         return os;
     }

+    friend ShowParam<VecPredRegContainer<NumBits, Packed>>;
+
     /// Create a view of this container.
     ///
/// If NumElems is provided, the size of the container is bounds-checked,
@@ -371,17 +367,29 @@
     /// @}
 };

-/// Helper functions used for serialization/de-serialization
 template <size_t NumBits, bool Packed>
-inline bool
-to_number(const std::string& value, VecPredRegContainer<NumBits, Packed>& p)
+struct ParseParam<VecPredRegContainer<NumBits, Packed>>
 {
-    int i = 0;
-    for (const auto& c: value) {
-        p[i] = (c == '1');
+    static bool
+ parse(const std::string &s, VecPredRegContainer<NumBits, Packed> &value)
+    {
+        int i = 0;
+        for (const auto& c: s)
+            value[i++] = (c == '1');
+        return true;
     }
-    return true;
-}
+};
+
+template <size_t NumBits, bool Packed>
+struct ShowParam<VecPredRegContainer<NumBits, Packed>>
+{
+    static void
+ show(std::ostream &os, const VecPredRegContainer<NumBits, Packed> &value)
+    {
+        for (auto b: value.container)
+            ccprintf(os, "%d", b);
+    }
+};

/// Dummy type aliases and constants for architectures that do not implement
 /// vector predicate registers.
diff --git a/src/cpu/o3/regfile.hh b/src/cpu/o3/regfile.hh
index d30f577..8b45d61 100644
--- a/src/cpu/o3/regfile.hh
+++ b/src/cpu/o3/regfile.hh
@@ -239,7 +239,7 @@

         DPRINTF(IEW, "RegFile: Access to predicate register %i, has "
                 "data %s\n", int(phys_reg->index()),
-                vecPredRegFile[phys_reg->index()].print());
+                vecPredRegFile[phys_reg->index()]);

         return vecPredRegFile[phys_reg->index()];
     }
@@ -323,7 +323,7 @@
         assert(phys_reg->isVecPredPhysReg());

         DPRINTF(IEW, "RegFile: Setting predicate register %i to %s\n",
-                int(phys_reg->index()), val.print());
+                int(phys_reg->index()), val);

         vecPredRegFile[phys_reg->index()] = val;
     }
diff --git a/src/cpu/simple_thread.hh b/src/cpu/simple_thread.hh
index e192ff1..83820ef 100644
--- a/src/cpu/simple_thread.hh
+++ b/src/cpu/simple_thread.hh
@@ -330,7 +330,7 @@
         const TheISA::VecPredRegContainer& regVal =
             readVecPredRegFlat(flatIndex);
         DPRINTF(VecPredRegs, "Reading predicate reg %d (%d) as %s.\n",
-                reg.index(), flatIndex, regVal.print());
+                reg.index(), flatIndex, regVal);
         return regVal;
     }

@@ -343,7 +343,7 @@
             getWritableVecPredRegFlat(flatIndex);
         DPRINTF(VecPredRegs,
                 "Reading predicate reg %d (%d) as %s for modify.\n",
-                reg.index(), flatIndex, regVal.print());
+                reg.index(), flatIndex, regVal);
         return regVal;
     }

@@ -410,7 +410,7 @@
         assert(flatIndex < vecPredRegs.size());
         setVecPredRegFlat(flatIndex, val);
         DPRINTF(VecPredRegs, "Setting predicate reg %d (%d) to %s.\n",
-                reg.index(), flatIndex, val.print());
+                reg.index(), flatIndex, val);
     }

     void

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/41999
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: I8e28c9796bf5cabd35a6bf5b89e55efcf9324d92
Gerrit-Change-Number: 41999
Gerrit-PatchSet: 10
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to