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

Change-Id: Ic88c6834dfe980022e58a3d859ea53193a55bbb1
Reviewed-on: https://gem5-review.googlesource.com/c/12971
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>
This commit is contained in:
Gabe Black
2018-09-22 07:28:13 -07:00
parent 6ab054bf2f
commit ebe9b301ad
4 changed files with 118 additions and 34 deletions

View File

@@ -42,6 +42,7 @@ if env['USE_SYSTEMC']:
Source('scheduler.cc')
Source('sched_event.cc')
Source('sensitivity.cc')
Source('time.cc')
Source('sc_attr.cc')
Source('sc_event.cc')

View File

@@ -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 sc_core
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 @@ std::vector<SetInfo> toSet;
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 @@ sc_time::print(std::ostream &os) const
scaled /= 1000;
}
os << scaled << ' ' << TimeUnitNames[tu];
os << scaled << ' ' << sc_gem5::TimeUnitNames[tu];
}
}
@@ -427,8 +401,8 @@ sc_set_time_resolution(double d, sc_time_unit tu)
"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 @@ sc_set_time_resolution(double d, sc_time_unit tu)
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 @@ sc_set_default_time_unit(double d, sc_time_unit tu)
}
// 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");

64
src/systemc/core/time.cc Normal file
View File

@@ -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

44
src/systemc/core/time.hh Normal file
View File

@@ -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__