sc_time.cc revision 13177
112837Sgabeblack@google.com/* 212837Sgabeblack@google.com * Copyright 2018 Google, Inc. 312837Sgabeblack@google.com * 412837Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512837Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612837Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812837Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012837Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112837Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212837Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312837Sgabeblack@google.com * this software without specific prior written permission. 1412837Sgabeblack@google.com * 1512837Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612837Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712837Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812837Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912837Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012837Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112837Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212837Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312837Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412837Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512837Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612837Sgabeblack@google.com * 2712837Sgabeblack@google.com * Authors: Gabe Black 2812837Sgabeblack@google.com */ 2912837Sgabeblack@google.com 3013177Sgabeblack@google.com#include <sstream> 3113039Sgabeblack@google.com#include <vector> 3213039Sgabeblack@google.com 3312837Sgabeblack@google.com#include "base/logging.hh" 3412989Sgabeblack@google.com#include "base/types.hh" 3512986Sgabeblack@google.com#include "python/pybind11/pybind.hh" 3613039Sgabeblack@google.com#include "systemc/core/python.hh" 3713149Sgabeblack@google.com#include "systemc/ext/core/sc_main.hh" 3812837Sgabeblack@google.com#include "systemc/ext/core/sc_time.hh" 3913149Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh" 4012837Sgabeblack@google.com 4112837Sgabeblack@google.comnamespace sc_core 4212837Sgabeblack@google.com{ 4312837Sgabeblack@google.com 4412983Sgabeblack@google.comnamespace 4512837Sgabeblack@google.com{ 4612983Sgabeblack@google.com 4712983Sgabeblack@google.comconst char *TimeUnitNames[] = { 4812983Sgabeblack@google.com [SC_FS] = "fs", 4912983Sgabeblack@google.com [SC_PS] = "ps", 5012983Sgabeblack@google.com [SC_NS] = "ns", 5112983Sgabeblack@google.com [SC_US] = "us", 5212983Sgabeblack@google.com [SC_MS] = "ms", 5312983Sgabeblack@google.com [SC_SEC] = "s" 5412983Sgabeblack@google.com}; 5512983Sgabeblack@google.com 5612983Sgabeblack@google.comdouble TimeUnitScale[] = { 5712983Sgabeblack@google.com [SC_FS] = 1.0e-15, 5812983Sgabeblack@google.com [SC_PS] = 1.0e-12, 5912983Sgabeblack@google.com [SC_NS] = 1.0e-9, 6012983Sgabeblack@google.com [SC_US] = 1.0e-6, 6112983Sgabeblack@google.com [SC_MS] = 1.0e-3, 6212983Sgabeblack@google.com [SC_SEC] = 1.0 6312983Sgabeblack@google.com}; 6412983Sgabeblack@google.com 6513039Sgabeblack@google.combool timeFixed = false; 6613039Sgabeblack@google.combool pythonReady = false; 6713039Sgabeblack@google.com 6813039Sgabeblack@google.comstruct SetInfo 6913039Sgabeblack@google.com{ 7013039Sgabeblack@google.com SetInfo(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu) : 7113039Sgabeblack@google.com time(time), d(d), tu(tu) 7213039Sgabeblack@google.com {} 7313039Sgabeblack@google.com 7413039Sgabeblack@google.com ::sc_core::sc_time *time; 7513039Sgabeblack@google.com double d; 7613039Sgabeblack@google.com ::sc_core::sc_time_unit tu; 7713039Sgabeblack@google.com}; 7813039Sgabeblack@google.comstd::vector<SetInfo> toSet; 7913039Sgabeblack@google.com 8012986Sgabeblack@google.comvoid 8113039Sgabeblack@google.comsetWork(sc_time *time, double d, ::sc_core::sc_time_unit tu) 8212986Sgabeblack@google.com{ 8313039Sgabeblack@google.com //XXX Assuming the time resolution is 1ps. 8413039Sgabeblack@google.com double scale = TimeUnitScale[tu] / TimeUnitScale[SC_PS]; 8513039Sgabeblack@google.com // Accellera claims there is a linux bug, and that these next two 8613039Sgabeblack@google.com // lines work around them. 8713039Sgabeblack@google.com volatile double tmp = d * scale + 0.5; 8813039Sgabeblack@google.com *time = sc_time::from_value(static_cast<uint64_t>(tmp)); 8913039Sgabeblack@google.com} 9012986Sgabeblack@google.com 9113039Sgabeblack@google.comvoid 9213039Sgabeblack@google.comfixTime() 9313039Sgabeblack@google.com{ 9412986Sgabeblack@google.com auto ticks = pybind11::module::import("m5.ticks"); 9512986Sgabeblack@google.com auto fix_global_frequency = ticks.attr("fixGlobalFrequency"); 9612986Sgabeblack@google.com fix_global_frequency(); 9713039Sgabeblack@google.com 9813039Sgabeblack@google.com for (auto &t: toSet) 9913039Sgabeblack@google.com setWork(t.time, t.d, t.tu); 10013039Sgabeblack@google.com toSet.clear(); 10112986Sgabeblack@google.com} 10212986Sgabeblack@google.com 10313039Sgabeblack@google.comvoid 10413149Sgabeblack@google.comsetGlobalFrequency(Tick ticks_per_second) 10513149Sgabeblack@google.com{ 10613149Sgabeblack@google.com auto ticks = pybind11::module::import("m5.ticks"); 10713149Sgabeblack@google.com auto set_global_frequency = ticks.attr("setGlobalFrequency"); 10813149Sgabeblack@google.com set_global_frequency(ticks_per_second); 10913149Sgabeblack@google.com fixTime(); 11013149Sgabeblack@google.com} 11113149Sgabeblack@google.com 11213149Sgabeblack@google.comvoid 11313039Sgabeblack@google.comset(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu) 11413039Sgabeblack@google.com{ 11513039Sgabeblack@google.com // Only fix time once. 11613039Sgabeblack@google.com if (!timeFixed) { 11713039Sgabeblack@google.com timeFixed = true; 11813039Sgabeblack@google.com 11913039Sgabeblack@google.com // If we've run, python is working and we haven't fixed time yet. 12013039Sgabeblack@google.com if (pythonReady) 12113039Sgabeblack@google.com fixTime(); 12213039Sgabeblack@google.com } 12313039Sgabeblack@google.com if (pythonReady) { 12413039Sgabeblack@google.com // Time should be working. Set up this sc_time. 12513039Sgabeblack@google.com setWork(time, d, tu); 12613039Sgabeblack@google.com } else { 12713039Sgabeblack@google.com // Time isn't set up yet. Defer setting up this sc_time. 12813039Sgabeblack@google.com toSet.emplace_back(time, d, tu); 12913039Sgabeblack@google.com } 13013039Sgabeblack@google.com} 13113039Sgabeblack@google.com 13213039Sgabeblack@google.comclass TimeSetter : public ::sc_gem5::PythonReadyFunc 13313039Sgabeblack@google.com{ 13413039Sgabeblack@google.com public: 13513039Sgabeblack@google.com TimeSetter() : ::sc_gem5::PythonReadyFunc() {} 13613039Sgabeblack@google.com 13713039Sgabeblack@google.com void 13813039Sgabeblack@google.com run() override 13913039Sgabeblack@google.com { 14013039Sgabeblack@google.com // Record that we've run and python/pybind should be usable. 14113039Sgabeblack@google.com pythonReady = true; 14213039Sgabeblack@google.com 14313039Sgabeblack@google.com // If time is already fixed, let python know. 14413039Sgabeblack@google.com if (timeFixed) 14513039Sgabeblack@google.com fixTime(); 14613039Sgabeblack@google.com } 14713039Sgabeblack@google.com} timeSetter; 14813039Sgabeblack@google.com 14913124Sgabeblack@google.comdouble defaultUnit = 1.0e-9; 15013124Sgabeblack@google.com 15112983Sgabeblack@google.com} // anonymous namespace 15212983Sgabeblack@google.com 15312983Sgabeblack@google.comsc_time::sc_time() : val(0) {} 15412983Sgabeblack@google.com 15512983Sgabeblack@google.comsc_time::sc_time(double d, sc_time_unit tu) 15612983Sgabeblack@google.com{ 15712983Sgabeblack@google.com val = 0; 15813039Sgabeblack@google.com if (d != 0) 15913039Sgabeblack@google.com set(this, d, tu); 16012837Sgabeblack@google.com} 16112837Sgabeblack@google.com 16212983Sgabeblack@google.comsc_time::sc_time(const sc_time &t) 16312837Sgabeblack@google.com{ 16412983Sgabeblack@google.com val = t.val; 16512837Sgabeblack@google.com} 16612837Sgabeblack@google.com 16713057Sgabeblack@google.comsc_time::sc_time(double d, bool scale) 16812925Sgabeblack@google.com{ 16913124Sgabeblack@google.com //XXX Assuming the time resolution is 1ps. 17013124Sgabeblack@google.com if (scale) 17113124Sgabeblack@google.com set(this, d * defaultUnit, SC_SEC); 17213124Sgabeblack@google.com else 17313124Sgabeblack@google.com set(this, d, SC_PS); 17412925Sgabeblack@google.com} 17512925Sgabeblack@google.com 17613057Sgabeblack@google.comsc_time::sc_time(sc_dt::uint64 v, bool scale) 17712925Sgabeblack@google.com{ 17813124Sgabeblack@google.com //XXX Assuming the time resolution is 1ps. 17913124Sgabeblack@google.com if (scale) 18013124Sgabeblack@google.com set(this, static_cast<double>(v) * defaultUnit, SC_SEC); 18113124Sgabeblack@google.com else 18213124Sgabeblack@google.com set(this, static_cast<double>(v), SC_PS); 18312925Sgabeblack@google.com} 18412925Sgabeblack@google.com 18512837Sgabeblack@google.comsc_time & 18612983Sgabeblack@google.comsc_time::operator = (const sc_time &t) 18712837Sgabeblack@google.com{ 18812983Sgabeblack@google.com val = t.val; 18912837Sgabeblack@google.com return *this; 19012837Sgabeblack@google.com} 19112837Sgabeblack@google.com 19212837Sgabeblack@google.comsc_dt::uint64 19312837Sgabeblack@google.comsc_time::value() const 19412837Sgabeblack@google.com{ 19512983Sgabeblack@google.com return val; 19612837Sgabeblack@google.com} 19712837Sgabeblack@google.com 19812837Sgabeblack@google.comdouble 19912837Sgabeblack@google.comsc_time::to_double() const 20012837Sgabeblack@google.com{ 20113040Sgabeblack@google.com return static_cast<double>(val); 20212837Sgabeblack@google.com} 20312837Sgabeblack@google.comdouble 20412837Sgabeblack@google.comsc_time::to_seconds() const 20512837Sgabeblack@google.com{ 20613057Sgabeblack@google.com double d = to_double(); 20713057Sgabeblack@google.com //XXX Assuming the time resolution is 1ps. 20813057Sgabeblack@google.com double scale = TimeUnitScale[SC_PS] / TimeUnitScale[SC_SEC]; 20913057Sgabeblack@google.com return d * scale; 21012837Sgabeblack@google.com} 21112837Sgabeblack@google.com 21212837Sgabeblack@google.comconst std::string 21312837Sgabeblack@google.comsc_time::to_string() const 21412837Sgabeblack@google.com{ 21513177Sgabeblack@google.com std::ostringstream ss; 21613177Sgabeblack@google.com print(ss); 21713177Sgabeblack@google.com return ss.str(); 21812837Sgabeblack@google.com} 21912837Sgabeblack@google.com 22012837Sgabeblack@google.combool 22112983Sgabeblack@google.comsc_time::operator == (const sc_time &t) const 22212837Sgabeblack@google.com{ 22312983Sgabeblack@google.com return val == t.val; 22412837Sgabeblack@google.com} 22512837Sgabeblack@google.com 22612837Sgabeblack@google.combool 22712983Sgabeblack@google.comsc_time::operator != (const sc_time &t) const 22812837Sgabeblack@google.com{ 22912983Sgabeblack@google.com return val != t.val; 23012837Sgabeblack@google.com} 23112837Sgabeblack@google.com 23212837Sgabeblack@google.combool 23312983Sgabeblack@google.comsc_time::operator < (const sc_time &t) const 23412837Sgabeblack@google.com{ 23512983Sgabeblack@google.com return val < t.val; 23612837Sgabeblack@google.com} 23712837Sgabeblack@google.com 23812837Sgabeblack@google.combool 23912983Sgabeblack@google.comsc_time::operator <= (const sc_time &t) const 24012837Sgabeblack@google.com{ 24112983Sgabeblack@google.com return val <= t.val; 24212837Sgabeblack@google.com} 24312837Sgabeblack@google.com 24412837Sgabeblack@google.combool 24512983Sgabeblack@google.comsc_time::operator > (const sc_time &t) const 24612837Sgabeblack@google.com{ 24712983Sgabeblack@google.com return val > t.val; 24812837Sgabeblack@google.com} 24912837Sgabeblack@google.com 25012837Sgabeblack@google.combool 25112983Sgabeblack@google.comsc_time::operator >= (const sc_time &t) const 25212837Sgabeblack@google.com{ 25312983Sgabeblack@google.com return val >= t.val; 25412837Sgabeblack@google.com} 25512837Sgabeblack@google.com 25612837Sgabeblack@google.comsc_time & 25712983Sgabeblack@google.comsc_time::operator += (const sc_time &t) 25812837Sgabeblack@google.com{ 25912983Sgabeblack@google.com val += t.val; 26012837Sgabeblack@google.com return *this; 26112837Sgabeblack@google.com} 26212837Sgabeblack@google.com 26312837Sgabeblack@google.comsc_time & 26412983Sgabeblack@google.comsc_time::operator -= (const sc_time &t) 26512837Sgabeblack@google.com{ 26612983Sgabeblack@google.com val -= t.val; 26712837Sgabeblack@google.com return *this; 26812837Sgabeblack@google.com} 26912837Sgabeblack@google.com 27012837Sgabeblack@google.comsc_time & 27113040Sgabeblack@google.comsc_time::operator *= (double d) 27212837Sgabeblack@google.com{ 27313040Sgabeblack@google.com val = static_cast<int64_t>(static_cast<double>(val) * d + 0.5); 27412837Sgabeblack@google.com return *this; 27512837Sgabeblack@google.com} 27612837Sgabeblack@google.com 27712837Sgabeblack@google.comsc_time & 27813040Sgabeblack@google.comsc_time::operator /= (double d) 27912837Sgabeblack@google.com{ 28013040Sgabeblack@google.com val = static_cast<int64_t>(static_cast<double>(val) / d + 0.5); 28112837Sgabeblack@google.com return *this; 28212837Sgabeblack@google.com} 28312837Sgabeblack@google.com 28412837Sgabeblack@google.comvoid 28512983Sgabeblack@google.comsc_time::print(std::ostream &os) const 28612837Sgabeblack@google.com{ 28712983Sgabeblack@google.com if (val == 0) { 28812983Sgabeblack@google.com os << "0 s"; 28912983Sgabeblack@google.com } else { 29012983Sgabeblack@google.com //XXX Assuming the time resolution is 1ps. 29112983Sgabeblack@google.com sc_time_unit tu = SC_PS; 29212983Sgabeblack@google.com uint64_t scaled = val; 29312983Sgabeblack@google.com while (tu < SC_SEC && (scaled % 1000) == 0) { 29412983Sgabeblack@google.com tu = (sc_time_unit)((int)tu + 1); 29512983Sgabeblack@google.com scaled /= 1000; 29612983Sgabeblack@google.com } 29712983Sgabeblack@google.com 29812983Sgabeblack@google.com os << scaled << ' ' << TimeUnitNames[tu]; 29912983Sgabeblack@google.com } 30012837Sgabeblack@google.com} 30112837Sgabeblack@google.com 30212923Sgabeblack@google.comsc_time 30312983Sgabeblack@google.comsc_time::from_value(sc_dt::uint64 u) 30412923Sgabeblack@google.com{ 30512983Sgabeblack@google.com sc_time t; 30612983Sgabeblack@google.com t.val = u; 30712983Sgabeblack@google.com return t; 30812923Sgabeblack@google.com} 30912923Sgabeblack@google.com 31012923Sgabeblack@google.comsc_time 31113057Sgabeblack@google.comsc_time::from_seconds(double d) 31212923Sgabeblack@google.com{ 31313057Sgabeblack@google.com sc_time t; 31413057Sgabeblack@google.com set(&t, d, SC_SEC); 31513057Sgabeblack@google.com return t; 31612923Sgabeblack@google.com} 31712923Sgabeblack@google.com 31812923Sgabeblack@google.comsc_time 31912923Sgabeblack@google.comsc_time::from_string(const char *str) 32012923Sgabeblack@google.com{ 32112923Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 32212923Sgabeblack@google.com return sc_time(); 32312923Sgabeblack@google.com} 32412923Sgabeblack@google.com 32512837Sgabeblack@google.comconst sc_time 32612989Sgabeblack@google.comoperator + (const sc_time &a, const sc_time &b) 32712837Sgabeblack@google.com{ 32812989Sgabeblack@google.com return sc_time::from_value(a.value() + b.value()); 32912837Sgabeblack@google.com} 33012837Sgabeblack@google.com 33112837Sgabeblack@google.comconst sc_time 33212989Sgabeblack@google.comoperator - (const sc_time &a, const sc_time &b) 33312837Sgabeblack@google.com{ 33412989Sgabeblack@google.com return sc_time::from_value(a.value() - b.value()); 33512837Sgabeblack@google.com} 33612837Sgabeblack@google.com 33712837Sgabeblack@google.comconst sc_time 33813040Sgabeblack@google.comoperator * (const sc_time &t, double d) 33912837Sgabeblack@google.com{ 34013040Sgabeblack@google.com volatile double tmp = static_cast<double>(t.value()) * d + 0.5; 34113040Sgabeblack@google.com return sc_time::from_value(static_cast<int64_t>(tmp)); 34212837Sgabeblack@google.com} 34312837Sgabeblack@google.com 34412837Sgabeblack@google.comconst sc_time 34513040Sgabeblack@google.comoperator * (double d, const sc_time &t) 34612837Sgabeblack@google.com{ 34713040Sgabeblack@google.com volatile double tmp = d * static_cast<double>(t.value()) + 0.5; 34813040Sgabeblack@google.com return sc_time::from_value(static_cast<int64_t>(tmp)); 34912837Sgabeblack@google.com} 35012837Sgabeblack@google.com 35112837Sgabeblack@google.comconst sc_time 35213040Sgabeblack@google.comoperator / (const sc_time &t, double d) 35312837Sgabeblack@google.com{ 35413040Sgabeblack@google.com volatile double tmp = static_cast<double>(t.value()) / d + 0.5; 35513040Sgabeblack@google.com return sc_time::from_value(static_cast<int64_t>(tmp)); 35612837Sgabeblack@google.com} 35712837Sgabeblack@google.com 35812837Sgabeblack@google.comdouble 35913040Sgabeblack@google.comoperator / (const sc_time &t1, const sc_time &t2) 36012837Sgabeblack@google.com{ 36113040Sgabeblack@google.com return t1.to_double() / t2.to_double(); 36212837Sgabeblack@google.com} 36312837Sgabeblack@google.com 36412837Sgabeblack@google.comstd::ostream & 36512983Sgabeblack@google.comoperator << (std::ostream &os, const sc_time &t) 36612837Sgabeblack@google.com{ 36712983Sgabeblack@google.com t.print(os); 36812837Sgabeblack@google.com return os; 36912837Sgabeblack@google.com} 37012837Sgabeblack@google.com 37112837Sgabeblack@google.comconst sc_time SC_ZERO_TIME; 37212837Sgabeblack@google.com 37312837Sgabeblack@google.comvoid 37413149Sgabeblack@google.comsc_set_time_resolution(double d, sc_time_unit tu) 37512837Sgabeblack@google.com{ 37613151Sgabeblack@google.com if (d <= 0.0) { 37713149Sgabeblack@google.com SC_REPORT_ERROR("(E514) set time resolution failed", 37813149Sgabeblack@google.com "value not positive"); 37913149Sgabeblack@google.com } 38013149Sgabeblack@google.com double dummy; 38113149Sgabeblack@google.com if (modf(log10(d), &dummy) != 0.0) { 38213149Sgabeblack@google.com SC_REPORT_ERROR("(E514) set time resolution failed", 38313149Sgabeblack@google.com "value not a power of ten"); 38413149Sgabeblack@google.com } 38513149Sgabeblack@google.com if (sc_is_running()) { 38613149Sgabeblack@google.com SC_REPORT_ERROR("(E514) set time resolution failed", 38713149Sgabeblack@google.com "simulation running"); 38813149Sgabeblack@google.com } 38913149Sgabeblack@google.com static bool specified = false; 39013149Sgabeblack@google.com if (specified) { 39113149Sgabeblack@google.com SC_REPORT_ERROR("(E514) set time resolution failed", 39213149Sgabeblack@google.com "already specified"); 39313149Sgabeblack@google.com } 39413149Sgabeblack@google.com // This won't detect the timescale being fixed outside of systemc, but 39513149Sgabeblack@google.com // it's at least some protection. 39613149Sgabeblack@google.com if (timeFixed) { 39713149Sgabeblack@google.com SC_REPORT_ERROR("(E514) set time resolution failed", 39813149Sgabeblack@google.com "sc_time object(s) constructed"); 39913149Sgabeblack@google.com } 40013149Sgabeblack@google.com 40113149Sgabeblack@google.com // Normalize d to seconds. 40213149Sgabeblack@google.com d *= TimeUnitScale[tu]; 40313149Sgabeblack@google.com if (d < TimeUnitScale[SC_FS]) { 40413149Sgabeblack@google.com SC_REPORT_ERROR("(E514) set time resolution failed", 40513149Sgabeblack@google.com "value smaller than 1 fs"); 40613149Sgabeblack@google.com } 40713149Sgabeblack@google.com // Change d from a period to a frequency. 40813149Sgabeblack@google.com d = 1 / d; 40913149Sgabeblack@google.com // Convert to integer ticks. 41013149Sgabeblack@google.com Tick ticks_per_second = static_cast<Tick>(d); 41113149Sgabeblack@google.com setGlobalFrequency(ticks_per_second); 41213149Sgabeblack@google.com specified = true; 41312837Sgabeblack@google.com} 41412837Sgabeblack@google.com 41512837Sgabeblack@google.comsc_time 41612837Sgabeblack@google.comsc_get_time_resolution() 41712837Sgabeblack@google.com{ 41813149Sgabeblack@google.com return sc_time::from_value(1); 41912837Sgabeblack@google.com} 42012837Sgabeblack@google.com 42112837Sgabeblack@google.comconst sc_time & 42212837Sgabeblack@google.comsc_max_time() 42312837Sgabeblack@google.com{ 42412989Sgabeblack@google.com static const sc_time MaxScTime = sc_time::from_value(MaxTick); 42512989Sgabeblack@google.com return MaxScTime; 42612837Sgabeblack@google.com} 42712837Sgabeblack@google.com 42812916Sgabeblack@google.comvoid 42913124Sgabeblack@google.comsc_set_default_time_unit(double d, sc_time_unit tu) 43012916Sgabeblack@google.com{ 43113151Sgabeblack@google.com if (d < 0.0) { 43213151Sgabeblack@google.com SC_REPORT_ERROR("(E515) set default time unit failed", 43313151Sgabeblack@google.com "value not positive"); 43413151Sgabeblack@google.com } 43513151Sgabeblack@google.com double dummy; 43613151Sgabeblack@google.com if (modf(log10(d), &dummy) != 0.0) { 43713151Sgabeblack@google.com SC_REPORT_ERROR("(E515) set default time unit failed", 43813151Sgabeblack@google.com "value not a power of ten"); 43913151Sgabeblack@google.com } 44013151Sgabeblack@google.com if (sc_is_running()) { 44113151Sgabeblack@google.com SC_REPORT_ERROR("(E515) set default time unit failed", 44213151Sgabeblack@google.com "simulation running"); 44313151Sgabeblack@google.com } 44413151Sgabeblack@google.com static bool specified = false; 44513151Sgabeblack@google.com if (specified) { 44613151Sgabeblack@google.com SC_REPORT_ERROR("(E515) set default time unit failed", 44713151Sgabeblack@google.com "already specified"); 44813151Sgabeblack@google.com } 44913151Sgabeblack@google.com // This won't detect the timescale being fixed outside of systemc, but 45013151Sgabeblack@google.com // it's at least some protection. 45113151Sgabeblack@google.com if (timeFixed) { 45213151Sgabeblack@google.com SC_REPORT_ERROR("(E515) set default time unit failed", 45313151Sgabeblack@google.com "sc_time object(s) constructed"); 45413151Sgabeblack@google.com } 45513151Sgabeblack@google.com 45613151Sgabeblack@google.com // Normalize d to seconds. 45713124Sgabeblack@google.com defaultUnit = d * TimeUnitScale[tu]; 45813151Sgabeblack@google.com specified = true; 45912916Sgabeblack@google.com} 46012916Sgabeblack@google.com 46112916Sgabeblack@google.comsc_time 46212916Sgabeblack@google.comsc_get_default_time_unit() 46312916Sgabeblack@google.com{ 46413124Sgabeblack@google.com return sc_time(defaultUnit, SC_SEC); 46512916Sgabeblack@google.com} 46612916Sgabeblack@google.com 46712927Sgabeblack@google.comsc_time_tuple::sc_time_tuple(const sc_time &) 46812927Sgabeblack@google.com{ 46912927Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 47012927Sgabeblack@google.com} 47112927Sgabeblack@google.com 47212927Sgabeblack@google.combool 47312927Sgabeblack@google.comsc_time_tuple::has_value() const 47412927Sgabeblack@google.com{ 47512927Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 47612927Sgabeblack@google.com return false; 47712927Sgabeblack@google.com} 47812927Sgabeblack@google.com 47912927Sgabeblack@google.comsc_dt::uint64 48012927Sgabeblack@google.comsc_time_tuple::value() const 48112927Sgabeblack@google.com{ 48212927Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 48312927Sgabeblack@google.com return 0; 48412927Sgabeblack@google.com} 48512927Sgabeblack@google.com 48612927Sgabeblack@google.comconst char * 48712927Sgabeblack@google.comsc_time_tuple::unit_symbol() const 48812927Sgabeblack@google.com{ 48912927Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 49012927Sgabeblack@google.com return ""; 49112927Sgabeblack@google.com} 49212927Sgabeblack@google.com 49312927Sgabeblack@google.comdouble 49412927Sgabeblack@google.comsc_time_tuple::to_double() const 49512927Sgabeblack@google.com{ 49612927Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 49712927Sgabeblack@google.com return 0.0; 49812927Sgabeblack@google.com} 49912927Sgabeblack@google.com 50012927Sgabeblack@google.comstd::string 50112927Sgabeblack@google.comsc_time_tuple::to_string() const 50212927Sgabeblack@google.com{ 50312927Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 50412927Sgabeblack@google.com return ""; 50512927Sgabeblack@google.com} 50612927Sgabeblack@google.com 50712837Sgabeblack@google.com} // namespace sc_core 508