Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/12971

Change subject: systemc: Move some constants out of sc_time.cc for other files to use.
......................................................................

systemc: Move some constants out of sc_time.cc for other files to use.

Change-Id: Ic88c6834dfe980022e58a3d859ea53193a55bbb1
---
M src/systemc/core/SConscript
M src/systemc/core/sc_time.cc
A src/systemc/core/time.cc
A src/systemc/core/time.hh
4 files changed, 118 insertions(+), 34 deletions(-)



diff --git a/src/systemc/core/SConscript b/src/systemc/core/SConscript
index 0aa5994..2303042 100644
--- a/src/systemc/core/SConscript
+++ b/src/systemc/core/SConscript
@@ -42,6 +42,7 @@
     Source('scheduler.cc')
     Source('sched_event.cc')
     Source('sensitivity.cc')
+    Source('time.cc')

     Source('sc_attr.cc')
     Source('sc_event.cc')
diff --git a/src/systemc/core/sc_time.cc b/src/systemc/core/sc_time.cc
index 0b8ad62..cb7cf46 100644
--- a/src/systemc/core/sc_time.cc
+++ b/src/systemc/core/sc_time.cc
@@ -35,6 +35,7 @@
 #include "python/pybind11/pybind.hh"
 #include "sim/core.hh"
 #include "systemc/core/python.hh"
+#include "systemc/core/time.hh"
 #include "systemc/ext/core/sc_main.hh"
 #include "systemc/ext/core/sc_time.hh"
 #include "systemc/ext/utils/sc_report_handler.hh"
@@ -45,33 +46,6 @@
 namespace
 {

-const char *TimeUnitNames[] = {
-    [SC_FS] = "fs",
-    [SC_PS] = "ps",
-    [SC_NS] = "ns",
-    [SC_US] = "us",
-    [SC_MS] = "ms",
-    [SC_SEC] = "s"
-};
-
-double TimeUnitScale[] = {
-    [SC_FS] = 1.0e-15,
-    [SC_PS] = 1.0e-12,
-    [SC_NS] = 1.0e-9,
-    [SC_US] = 1.0e-6,
-    [SC_MS] = 1.0e-3,
-    [SC_SEC] = 1.0
-};
-
-Tick TimeUnitFrequency[] = {
-    [SC_FS] = 1ULL * 1000 * 1000 * 1000 * 1000 * 1000,
-    [SC_PS] = 1ULL * 1000 * 1000 * 1000 * 1000,
-    [SC_NS] = 1ULL * 1000 * 1000 * 1000,
-    [SC_US] = 1ULL * 1000 * 1000,
-    [SC_MS] = 1ULL * 1000,
-    [SC_SEC] = 1ULL
-};
-
 bool timeFixed = false;
 bool pythonReady = false;

@@ -90,7 +64,7 @@
 void
 setWork(sc_time *time, double d, ::sc_core::sc_time_unit tu)
 {
-    double scale = TimeUnitScale[tu] * SimClock::Float::s;
+    double scale = sc_gem5::TimeUnitScale[tu] * SimClock::Float::s;
     // Accellera claims there is a linux bug, and that these next two
     // lines work around them.
     volatile double tmp = d * scale + 0.5;
@@ -322,7 +296,7 @@
             scaled /= 1000;
         }

-        os << scaled << ' ' << TimeUnitNames[tu];
+        os << scaled << ' ' << sc_gem5::TimeUnitNames[tu];
     }
 }

@@ -427,8 +401,8 @@
                 "sc_time object(s) constructed");
     }

-    double seconds = d * TimeUnitScale[tu];
-    if (seconds < TimeUnitScale[SC_FS]) {
+    double seconds = d * sc_gem5::TimeUnitScale[tu];
+    if (seconds < sc_gem5::TimeUnitScale[SC_FS]) {
         SC_REPORT_ERROR("(E514) set time resolution failed",
                 "value smaller than 1 fs");
     }
@@ -445,7 +419,8 @@
         tu = (sc_time_unit)(tu - 1);
     }

-    Tick ticks_per_second = TimeUnitFrequency[tu] / static_cast<Tick>(d);
+    Tick ticks_per_second =
+        sc_gem5::TimeUnitFrequency[tu] / static_cast<Tick>(d);
     setGlobalFrequency(ticks_per_second);
     specified = true;
 }
@@ -492,12 +467,12 @@
     }

     // Normalize d to seconds.
-    defaultUnit = d * TimeUnitScale[tu];
+    defaultUnit = d * sc_gem5::TimeUnitScale[tu];
     specified = true;

     double resolution = SimClock::Float::Hz;
     if (resolution == 0.0)
-        resolution = TimeUnitScale[SC_PS];
+        resolution = sc_gem5::TimeUnitScale[SC_PS];
     if (defaultUnit < resolution) {
         SC_REPORT_ERROR("(E515) set default time unit failed",
                 "value smaller than time resolution");
diff --git a/src/systemc/core/time.cc b/src/systemc/core/time.cc
new file mode 100644
index 0000000..4c90864
--- /dev/null
+++ b/src/systemc/core/time.cc
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2018 Google, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Gabe Black
+ */
+
+#include "systemc/core/time.hh"
+
+#include "systemc/ext/core/sc_time.hh"
+
+namespace sc_gem5
+{
+
+const char *TimeUnitNames[] = {
+    [::sc_core::SC_FS] = "fs",
+    [::sc_core::SC_PS] = "ps",
+    [::sc_core::SC_NS] = "ns",
+    [::sc_core::SC_US] = "us",
+    [::sc_core::SC_MS] = "ms",
+    [::sc_core::SC_SEC] = "s"
+};
+
+double TimeUnitScale[] = {
+    [::sc_core::SC_FS] = 1.0e-15,
+    [::sc_core::SC_PS] = 1.0e-12,
+    [::sc_core::SC_NS] = 1.0e-9,
+    [::sc_core::SC_US] = 1.0e-6,
+    [::sc_core::SC_MS] = 1.0e-3,
+    [::sc_core::SC_SEC] = 1.0
+};
+
+Tick TimeUnitFrequency[] = {
+    [::sc_core::SC_FS] = 1ULL * 1000 * 1000 * 1000 * 1000 * 1000,
+    [::sc_core::SC_PS] = 1ULL * 1000 * 1000 * 1000 * 1000,
+    [::sc_core::SC_NS] = 1ULL * 1000 * 1000 * 1000,
+    [::sc_core::SC_US] = 1ULL * 1000 * 1000,
+    [::sc_core::SC_MS] = 1ULL * 1000,
+    [::sc_core::SC_SEC] = 1ULL
+};
+
+} // namespace sc_gem5
diff --git a/src/systemc/core/time.hh b/src/systemc/core/time.hh
new file mode 100644
index 0000000..4357fbd
--- /dev/null
+++ b/src/systemc/core/time.hh
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2018 Google, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Gabe Black
+ */
+
+#ifndef __SYSTEMC_CORE_TIME_HH__
+#define __SYSTEMC_CORE_TIME_HH__
+
+#include "base/types.hh"
+
+namespace sc_gem5
+{
+
+extern const char *TimeUnitNames[];
+extern double TimeUnitScale[];
+extern Tick TimeUnitFrequency[];
+
+} // namespace sc_gem5
+
+#endif // __SYSTEMC_CORE_TIME_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12971
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: Ic88c6834dfe980022e58a3d859ea53193a55bbb1
Gerrit-Change-Number: 12971
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to