summaryrefslogtreecommitdiff
path: root/src/systemc/core
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-07-19 16:53:27 -0700
committerGabe Black <gabeblack@google.com>2018-09-11 21:41:09 +0000
commitb7ab029883d8311756eefb54c706f83636bf7327 (patch)
tree6feec8c8d24cde79ae13170a449dd82b1e8b4b64 /src/systemc/core
parenta6c0e4623c6bb1077ca43c66663e039efb221bda (diff)
downloadgem5-b7ab029883d8311756eefb54c706f83636bf7327.tar.xz
systemc: Implement some of the basics of sc_time.
This is a very incomplete implementation, but is enough to unblock implementing some other dependent features. Change-Id: Ibd2f3476fe01389e277c6956d48337f551d14acd Reviewed-on: https://gem5-review.googlesource.com/12034 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/core')
-rw-r--r--src/systemc/core/sc_time.cc114
1 files changed, 74 insertions, 40 deletions
diff --git a/src/systemc/core/sc_time.cc b/src/systemc/core/sc_time.cc
index 167b37494..002121e88 100644
--- a/src/systemc/core/sc_time.cc
+++ b/src/systemc/core/sc_time.cc
@@ -33,19 +33,47 @@
namespace sc_core
{
-sc_time::sc_time()
+namespace
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
-sc_time::sc_time(double, sc_time_unit)
+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
+};
+
+} // anonymous namespace
+
+sc_time::sc_time() : val(0) {}
+
+sc_time::sc_time(double d, sc_time_unit tu)
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ val = 0;
+ if (d != 0) {
+ //XXX Assuming the time resolution is 1ps.
+ double scale = TimeUnitScale[tu] / TimeUnitScale[SC_PS];
+ // Accellera claims there is a linux bug, and that these next two
+ // lines work around them.
+ volatile double tmp = d * scale + 0.5;
+ val = static_cast<uint64_t>(tmp);
+ }
}
-sc_time::sc_time(const sc_time &)
+sc_time::sc_time(const sc_time &t)
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ val = t.val;
}
sc_time::sc_time(double, bool)
@@ -59,17 +87,16 @@ sc_time::sc_time(sc_dt::uint64, bool)
}
sc_time &
-sc_time::operator = (const sc_time &)
+sc_time::operator = (const sc_time &t)
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ val = t.val;
return *this;
}
sc_dt::uint64
sc_time::value() const
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return 0;
+ return val;
}
double
@@ -93,58 +120,52 @@ sc_time::to_string() const
}
bool
-sc_time::operator == (const sc_time &) const
+sc_time::operator == (const sc_time &t) const
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return true;
+ return val == t.val;
}
bool
-sc_time::operator != (const sc_time &) const
+sc_time::operator != (const sc_time &t) const
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return false;
+ return val != t.val;
}
bool
-sc_time::operator < (const sc_time &) const
+sc_time::operator < (const sc_time &t) const
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return false;
+ return val < t.val;
}
bool
-sc_time::operator <= (const sc_time &) const
+sc_time::operator <= (const sc_time &t) const
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return true;
+ return val <= t.val;
}
bool
-sc_time::operator > (const sc_time &) const
+sc_time::operator > (const sc_time &t) const
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return false;
+ return val > t.val;
}
bool
-sc_time::operator >= (const sc_time &) const
+sc_time::operator >= (const sc_time &t) const
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return true;
+ return val >= t.val;
}
sc_time &
-sc_time::operator += (const sc_time &)
+sc_time::operator += (const sc_time &t)
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ val += t.val;
return *this;
}
sc_time &
-sc_time::operator -= (const sc_time &)
+sc_time::operator -= (const sc_time &t)
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ val -= t.val;
return *this;
}
@@ -163,16 +184,29 @@ sc_time::operator /= (double)
}
void
-sc_time::print(std::ostream &) const
+sc_time::print(std::ostream &os) const
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ if (val == 0) {
+ os << "0 s";
+ } else {
+ //XXX Assuming the time resolution is 1ps.
+ sc_time_unit tu = SC_PS;
+ uint64_t scaled = val;
+ while (tu < SC_SEC && (scaled % 1000) == 0) {
+ tu = (sc_time_unit)((int)tu + 1);
+ scaled /= 1000;
+ }
+
+ os << scaled << ' ' << TimeUnitNames[tu];
+ }
}
sc_time
-sc_time::from_value(sc_dt::uint64)
+sc_time::from_value(sc_dt::uint64 u)
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return sc_time();
+ sc_time t;
+ t.val = u;
+ return t;
}
sc_time
@@ -232,9 +266,9 @@ operator / (const sc_time &, const sc_time &)
}
std::ostream &
-operator << (std::ostream &os, const sc_time &)
+operator << (std::ostream &os, const sc_time &t)
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ t.print(os);
return os;
}