Gabe Black has submitted this change and it was merged. ( https://gem5-review.googlesource.com/c/public/gem5/+/13189 )

Change subject: systemc: Implement the sc_time_tuple class.
......................................................................

systemc: Implement the sc_time_tuple class.

This class is non-standard and is an implementation detail in
Accellera's implementation, but is referred to directly by the tests.
It does the same thing as the time printing function, so rather than
having duplicate code the printing function now uses the sc_time_tuple
class even though it was doing fine on its own already.

Change-Id: I69594ed0651f212ded6d979d60523bb3b0a789b1
Reviewed-on: https://gem5-review.googlesource.com/c/13189
Reviewed-by: Gabe Black <[email protected]>
Maintainer: Gabe Black <[email protected]>
---
M src/systemc/core/sc_time.cc
M src/systemc/ext/core/sc_time.hh
2 files changed, 42 insertions(+), 56 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved



diff --git a/src/systemc/core/sc_time.cc b/src/systemc/core/sc_time.cc
index cb7cf46..acc3c08 100644
--- a/src/systemc/core/sc_time.cc
+++ b/src/systemc/core/sc_time.cc
@@ -264,40 +264,7 @@
 void
 sc_time::print(std::ostream &os) const
 {
-    if (val == 0) {
-        os << "0 s";
-    } else {
-        Tick frequency = SimClock::Frequency;
-
- // Shrink the frequency by scaling down the time period, ie converting
-        // it from cycles per second to cycles per millisecond, etc.
-        sc_time_unit tu = SC_SEC;
-        while (tu > 1 && (frequency % 1000 == 0)) {
-            tu = (sc_time_unit)((int)tu - 1);
-            frequency /= 1000;
-        }
-
-        // Convert the frequency into a period.
-        Tick period;
-        if (frequency > 1) {
-            tu = (sc_time_unit)((int)tu - 1);
-            period = 1000 / frequency;
-        } else {
-            period = frequency;
-        }
-
-        // Scale our integer value by the period.
-        uint64_t scaled = val * period;
-
-        // Shrink the scaled time value by increasing the size of the units
-        // it's measured by, avoiding fractional parts.
-        while (tu < SC_SEC && (scaled % 1000) == 0) {
-            tu = (sc_time_unit)((int)tu + 1);
-            scaled /= 1000;
-        }
-
-        os << scaled << ' ' << sc_gem5::TimeUnitNames[tu];
-    }
+    os << sc_time_tuple(*this).to_string();
 }

 sc_time
@@ -485,44 +452,63 @@
     return sc_time(defaultUnit, SC_SEC);
 }

-sc_time_tuple::sc_time_tuple(const sc_time &)
+sc_time_tuple::sc_time_tuple(const sc_time &t) :
+    _value(), _unit(SC_SEC), _set(true)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    if (!t.value())
+        return;
+
+    Tick frequency = SimClock::Frequency;
+
+    // Shrink the frequency by scaling down the time period, ie converting
+    // it from cycles per second to cycles per millisecond, etc.
+    while (_unit > 1 && (frequency % 1000 == 0)) {
+        _unit = (sc_time_unit)((int)_unit - 1);
+        frequency /= 1000;
+    }
+
+    // Convert the frequency into a period.
+    Tick period;
+    if (frequency > 1) {
+        _unit = (sc_time_unit)((int)_unit - 1);
+        period = 1000 / frequency;
+    } else {
+        period = frequency;
+    }
+
+    // Scale our integer value by the period.
+    _value = t.value() * period;
+
+    // Shrink the scaled time value by increasing the size of the units
+    // it's measured by, avoiding fractional parts.
+    while (_unit < SC_SEC && (_value % 1000) == 0) {
+        _unit = (sc_time_unit)((int)_unit + 1);
+        _value /= 1000;
+    }
 }

 bool
 sc_time_tuple::has_value() const
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-    return false;
+    return _set;
 }

-sc_dt::uint64
-sc_time_tuple::value() const
-{
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-    return 0;
-}
+sc_dt::uint64 sc_time_tuple::value() const { return _value; }

 const char *
 sc_time_tuple::unit_symbol() const
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-    return "";
+    return sc_gem5::TimeUnitNames[_unit];
 }

-double
-sc_time_tuple::to_double() const
-{
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-    return 0.0;
-}
+double sc_time_tuple::to_double() const { return static_cast<double>(_value); }

 std::string
 sc_time_tuple::to_string() const
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-    return "";
+    std::ostringstream ss;
+    ss << _value << ' ' << unit_symbol();
+    return ss.str();
 }

 } // namespace sc_core
diff --git a/src/systemc/ext/core/sc_time.hh b/src/systemc/ext/core/sc_time.hh
index 0147555..0a31a65 100644
--- a/src/systemc/ext/core/sc_time.hh
+++ b/src/systemc/ext/core/sc_time.hh
@@ -113,7 +113,7 @@
 class sc_time_tuple
 {
   public:
-    sc_time_tuple() : _value(), _unit(SC_SEC), _offset(1) {}
+    sc_time_tuple() : _value(), _unit(SC_SEC), _set(false) {}
     sc_time_tuple(const sc_time &);

     bool has_value() const;
@@ -131,7 +131,7 @@
   private:
     sc_dt::uint64 _value;
     sc_time_unit _unit;
-    unsigned _offset;
+    bool _set;
 };

 } // namespace sc_core

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/13189
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: I69594ed0651f212ded6d979d60523bb3b0a789b1
Gerrit-Change-Number: 13189
Gerrit-PatchSet: 5
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: Matthias Jung <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to