sc_time.cc revision 13151
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 3013039Sgabeblack@google.com#include <vector> 3113039Sgabeblack@google.com 3212837Sgabeblack@google.com#include "base/logging.hh" 3312989Sgabeblack@google.com#include "base/types.hh" 3412986Sgabeblack@google.com#include "python/pybind11/pybind.hh" 3513039Sgabeblack@google.com#include "systemc/core/python.hh" 3613149Sgabeblack@google.com#include "systemc/ext/core/sc_main.hh" 3712837Sgabeblack@google.com#include "systemc/ext/core/sc_time.hh" 3813149Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh" 3912837Sgabeblack@google.com 4012837Sgabeblack@google.comnamespace sc_core 4112837Sgabeblack@google.com{ 4212837Sgabeblack@google.com 4312983Sgabeblack@google.comnamespace 4412837Sgabeblack@google.com{ 4512983Sgabeblack@google.com 4612983Sgabeblack@google.comconst char *TimeUnitNames[] = { 4712983Sgabeblack@google.com [SC_FS] = "fs", 4812983Sgabeblack@google.com [SC_PS] = "ps", 4912983Sgabeblack@google.com [SC_NS] = "ns", 5012983Sgabeblack@google.com [SC_US] = "us", 5112983Sgabeblack@google.com [SC_MS] = "ms", 5212983Sgabeblack@google.com [SC_SEC] = "s" 5312983Sgabeblack@google.com}; 5412983Sgabeblack@google.com 5512983Sgabeblack@google.comdouble TimeUnitScale[] = { 5612983Sgabeblack@google.com [SC_FS] = 1.0e-15, 5712983Sgabeblack@google.com [SC_PS] = 1.0e-12, 5812983Sgabeblack@google.com [SC_NS] = 1.0e-9, 5912983Sgabeblack@google.com [SC_US] = 1.0e-6, 6012983Sgabeblack@google.com [SC_MS] = 1.0e-3, 6112983Sgabeblack@google.com [SC_SEC] = 1.0 6212983Sgabeblack@google.com}; 6312983Sgabeblack@google.com 6413039Sgabeblack@google.combool timeFixed = false; 6513039Sgabeblack@google.combool pythonReady = false; 6613039Sgabeblack@google.com 6713039Sgabeblack@google.comstruct SetInfo 6813039Sgabeblack@google.com{ 6913039Sgabeblack@google.com SetInfo(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu) : 7013039Sgabeblack@google.com time(time), d(d), tu(tu) 7113039Sgabeblack@google.com {} 7213039Sgabeblack@google.com 7313039Sgabeblack@google.com ::sc_core::sc_time *time; 7413039Sgabeblack@google.com double d; 7513039Sgabeblack@google.com ::sc_core::sc_time_unit tu; 7613039Sgabeblack@google.com}; 7713039Sgabeblack@google.comstd::vector<SetInfo> toSet; 7813039Sgabeblack@google.com 7912986Sgabeblack@google.comvoid 8013039Sgabeblack@google.comsetWork(sc_time *time, double d, ::sc_core::sc_time_unit tu) 8112986Sgabeblack@google.com{ 8213039Sgabeblack@google.com //XXX Assuming the time resolution is 1ps. 8313039Sgabeblack@google.com double scale = TimeUnitScale[tu] / TimeUnitScale[SC_PS]; 8413039Sgabeblack@google.com // Accellera claims there is a linux bug, and that these next two 8513039Sgabeblack@google.com // lines work around them. 8613039Sgabeblack@google.com volatile double tmp = d * scale + 0.5; 8713039Sgabeblack@google.com *time = sc_time::from_value(static_cast<uint64_t>(tmp)); 8813039Sgabeblack@google.com} 8912986Sgabeblack@google.com 9013039Sgabeblack@google.comvoid 9113039Sgabeblack@google.comfixTime() 9213039Sgabeblack@google.com{ 9312986Sgabeblack@google.com auto ticks = pybind11::module::import("m5.ticks"); 9412986Sgabeblack@google.com auto fix_global_frequency = ticks.attr("fixGlobalFrequency"); 9512986Sgabeblack@google.com fix_global_frequency(); 9613039Sgabeblack@google.com 9713039Sgabeblack@google.com for (auto &t: toSet) 9813039Sgabeblack@google.com setWork(t.time, t.d, t.tu); 9913039Sgabeblack@google.com toSet.clear(); 10012986Sgabeblack@google.com} 10112986Sgabeblack@google.com 10213039Sgabeblack@google.comvoid 10313149Sgabeblack@google.comsetGlobalFrequency(Tick ticks_per_second) 10413149Sgabeblack@google.com{ 10513149Sgabeblack@google.com auto ticks = pybind11::module::import("m5.ticks"); 10613149Sgabeblack@google.com auto set_global_frequency = ticks.attr("setGlobalFrequency"); 10713149Sgabeblack@google.com set_global_frequency(ticks_per_second); 10813149Sgabeblack@google.com fixTime(); 10913149Sgabeblack@google.com} 11013149Sgabeblack@google.com 11113149Sgabeblack@google.comvoid 11213039Sgabeblack@google.comset(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu) 11313039Sgabeblack@google.com{ 11413039Sgabeblack@google.com // Only fix time once. 11513039Sgabeblack@google.com if (!timeFixed) { 11613039Sgabeblack@google.com timeFixed = true; 11713039Sgabeblack@google.com 11813039Sgabeblack@google.com // If we've run, python is working and we haven't fixed time yet. 11913039Sgabeblack@google.com if (pythonReady) 12013039Sgabeblack@google.com fixTime(); 12113039Sgabeblack@google.com } 12213039Sgabeblack@google.com if (pythonReady) { 12313039Sgabeblack@google.com // Time should be working. Set up this sc_time. 12413039Sgabeblack@google.com setWork(time, d, tu); 12513039Sgabeblack@google.com } else { 12613039Sgabeblack@google.com // Time isn't set up yet. Defer setting up this sc_time. 12713039Sgabeblack@google.com toSet.emplace_back(time, d, tu); 12813039Sgabeblack@google.com } 12913039Sgabeblack@google.com} 13013039Sgabeblack@google.com 13113039Sgabeblack@google.comclass TimeSetter : public ::sc_gem5::PythonReadyFunc 13213039Sgabeblack@google.com{ 13313039Sgabeblack@google.com public: 13413039Sgabeblack@google.com TimeSetter() : ::sc_gem5::PythonReadyFunc() {} 13513039Sgabeblack@google.com 13613039Sgabeblack@google.com void 13713039Sgabeblack@google.com run() override 13813039Sgabeblack@google.com { 13913039Sgabeblack@google.com // Record that we've run and python/pybind should be usable. 14013039Sgabeblack@google.com pythonReady = true; 14113039Sgabeblack@google.com 14213039Sgabeblack@google.com // If time is already fixed, let python know. 14313039Sgabeblack@google.com if (timeFixed) 14413039Sgabeblack@google.com fixTime(); 14513039Sgabeblack@google.com } 14613039Sgabeblack@google.com} timeSetter; 14713039Sgabeblack@google.com 14813124Sgabeblack@google.comdouble defaultUnit = 1.0e-9; 14913124Sgabeblack@google.com 15012983Sgabeblack@google.com} // anonymous namespace 15112983Sgabeblack@google.com 15212983Sgabeblack@google.comsc_time::sc_time() : val(0) {} 15312983Sgabeblack@google.com 15412983Sgabeblack@google.comsc_time::sc_time(double d, sc_time_unit tu) 15512983Sgabeblack@google.com{ 15612983Sgabeblack@google.com val = 0; 15713039Sgabeblack@google.com if (d != 0) 15813039Sgabeblack@google.com set(this, d, tu); 15912837Sgabeblack@google.com} 16012837Sgabeblack@google.com 16112983Sgabeblack@google.comsc_time::sc_time(const sc_time &t) 16212837Sgabeblack@google.com{ 16312983Sgabeblack@google.com val = t.val; 16412837Sgabeblack@google.com} 16512837Sgabeblack@google.com 16613057Sgabeblack@google.comsc_time::sc_time(double d, bool scale) 16712925Sgabeblack@google.com{ 16813124Sgabeblack@google.com //XXX Assuming the time resolution is 1ps. 16913124Sgabeblack@google.com if (scale) 17013124Sgabeblack@google.com set(this, d * defaultUnit, SC_SEC); 17113124Sgabeblack@google.com else 17213124Sgabeblack@google.com set(this, d, SC_PS); 17312925Sgabeblack@google.com} 17412925Sgabeblack@google.com 17513057Sgabeblack@google.comsc_time::sc_time(sc_dt::uint64 v, bool scale) 17612925Sgabeblack@google.com{ 17713124Sgabeblack@google.com //XXX Assuming the time resolution is 1ps. 17813124Sgabeblack@google.com if (scale) 17913124Sgabeblack@google.com set(this, static_cast<double>(v) * defaultUnit, SC_SEC); 18013124Sgabeblack@google.com else 18113124Sgabeblack@google.com set(this, static_cast<double>(v), SC_PS); 18212925Sgabeblack@google.com} 18312925Sgabeblack@google.com 18412837Sgabeblack@google.comsc_time & 18512983Sgabeblack@google.comsc_time::operator = (const sc_time &t) 18612837Sgabeblack@google.com{ 18712983Sgabeblack@google.com val = t.val; 18812837Sgabeblack@google.com return *this; 18912837Sgabeblack@google.com} 19012837Sgabeblack@google.com 19112837Sgabeblack@google.comsc_dt::uint64 19212837Sgabeblack@google.comsc_time::value() const 19312837Sgabeblack@google.com{ 19412983Sgabeblack@google.com return val; 19512837Sgabeblack@google.com} 19612837Sgabeblack@google.com 19712837Sgabeblack@google.comdouble 19812837Sgabeblack@google.comsc_time::to_double() const 19912837Sgabeblack@google.com{ 20013040Sgabeblack@google.com return static_cast<double>(val); 20112837Sgabeblack@google.com} 20212837Sgabeblack@google.comdouble 20312837Sgabeblack@google.comsc_time::to_seconds() const 20412837Sgabeblack@google.com{ 20513057Sgabeblack@google.com double d = to_double(); 20613057Sgabeblack@google.com //XXX Assuming the time resolution is 1ps. 20713057Sgabeblack@google.com double scale = TimeUnitScale[SC_PS] / TimeUnitScale[SC_SEC]; 20813057Sgabeblack@google.com return d * scale; 20912837Sgabeblack@google.com} 21012837Sgabeblack@google.com 21112837Sgabeblack@google.comconst std::string 21212837Sgabeblack@google.comsc_time::to_string() const 21312837Sgabeblack@google.com{ 21412837Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 21512837Sgabeblack@google.com return ""; 21612837Sgabeblack@google.com} 21712837Sgabeblack@google.com 21812837Sgabeblack@google.combool 21912983Sgabeblack@google.comsc_time::operator == (const sc_time &t) const 22012837Sgabeblack@google.com{ 22112983Sgabeblack@google.com return val == t.val; 22212837Sgabeblack@google.com} 22312837Sgabeblack@google.com 22412837Sgabeblack@google.combool 22512983Sgabeblack@google.comsc_time::operator != (const sc_time &t) const 22612837Sgabeblack@google.com{ 22712983Sgabeblack@google.com return val != t.val; 22812837Sgabeblack@google.com} 22912837Sgabeblack@google.com 23012837Sgabeblack@google.combool 23112983Sgabeblack@google.comsc_time::operator < (const sc_time &t) const 23212837Sgabeblack@google.com{ 23312983Sgabeblack@google.com return val < t.val; 23412837Sgabeblack@google.com} 23512837Sgabeblack@google.com 23612837Sgabeblack@google.combool 23712983Sgabeblack@google.comsc_time::operator <= (const sc_time &t) const 23812837Sgabeblack@google.com{ 23912983Sgabeblack@google.com return val <= t.val; 24012837Sgabeblack@google.com} 24112837Sgabeblack@google.com 24212837Sgabeblack@google.combool 24312983Sgabeblack@google.comsc_time::operator > (const sc_time &t) const 24412837Sgabeblack@google.com{ 24512983Sgabeblack@google.com return val > t.val; 24612837Sgabeblack@google.com} 24712837Sgabeblack@google.com 24812837Sgabeblack@google.combool 24912983Sgabeblack@google.comsc_time::operator >= (const sc_time &t) const 25012837Sgabeblack@google.com{ 25112983Sgabeblack@google.com return val >= t.val; 25212837Sgabeblack@google.com} 25312837Sgabeblack@google.com 25412837Sgabeblack@google.comsc_time & 25512983Sgabeblack@google.comsc_time::operator += (const sc_time &t) 25612837Sgabeblack@google.com{ 25712983Sgabeblack@google.com val += t.val; 25812837Sgabeblack@google.com return *this; 25912837Sgabeblack@google.com} 26012837Sgabeblack@google.com 26112837Sgabeblack@google.comsc_time & 26212983Sgabeblack@google.comsc_time::operator -= (const sc_time &t) 26312837Sgabeblack@google.com{ 26412983Sgabeblack@google.com val -= t.val; 26512837Sgabeblack@google.com return *this; 26612837Sgabeblack@google.com} 26712837Sgabeblack@google.com 26812837Sgabeblack@google.comsc_time & 26913040Sgabeblack@google.comsc_time::operator *= (double d) 27012837Sgabeblack@google.com{ 27113040Sgabeblack@google.com val = static_cast<int64_t>(static_cast<double>(val) * d + 0.5); 27212837Sgabeblack@google.com return *this; 27312837Sgabeblack@google.com} 27412837Sgabeblack@google.com 27512837Sgabeblack@google.comsc_time & 27613040Sgabeblack@google.comsc_time::operator /= (double d) 27712837Sgabeblack@google.com{ 27813040Sgabeblack@google.com val = static_cast<int64_t>(static_cast<double>(val) / d + 0.5); 27912837Sgabeblack@google.com return *this; 28012837Sgabeblack@google.com} 28112837Sgabeblack@google.com 28212837Sgabeblack@google.comvoid 28312983Sgabeblack@google.comsc_time::print(std::ostream &os) const 28412837Sgabeblack@google.com{ 28512983Sgabeblack@google.com if (val == 0) { 28612983Sgabeblack@google.com os << "0 s"; 28712983Sgabeblack@google.com } else { 28812983Sgabeblack@google.com //XXX Assuming the time resolution is 1ps. 28912983Sgabeblack@google.com sc_time_unit tu = SC_PS; 29012983Sgabeblack@google.com uint64_t scaled = val; 29112983Sgabeblack@google.com while (tu < SC_SEC && (scaled % 1000) == 0) { 29212983Sgabeblack@google.com tu = (sc_time_unit)((int)tu + 1); 29312983Sgabeblack@google.com scaled /= 1000; 29412983Sgabeblack@google.com } 29512983Sgabeblack@google.com 29612983Sgabeblack@google.com os << scaled << ' ' << TimeUnitNames[tu]; 29712983Sgabeblack@google.com } 29812837Sgabeblack@google.com} 29912837Sgabeblack@google.com 30012923Sgabeblack@google.comsc_time 30112983Sgabeblack@google.comsc_time::from_value(sc_dt::uint64 u) 30212923Sgabeblack@google.com{ 30312983Sgabeblack@google.com sc_time t; 30412983Sgabeblack@google.com t.val = u; 30512983Sgabeblack@google.com return t; 30612923Sgabeblack@google.com} 30712923Sgabeblack@google.com 30812923Sgabeblack@google.comsc_time 30913057Sgabeblack@google.comsc_time::from_seconds(double d) 31012923Sgabeblack@google.com{ 31113057Sgabeblack@google.com sc_time t; 31213057Sgabeblack@google.com set(&t, d, SC_SEC); 31313057Sgabeblack@google.com return t; 31412923Sgabeblack@google.com} 31512923Sgabeblack@google.com 31612923Sgabeblack@google.comsc_time 31712923Sgabeblack@google.comsc_time::from_string(const char *str) 31812923Sgabeblack@google.com{ 31912923Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 32012923Sgabeblack@google.com return sc_time(); 32112923Sgabeblack@google.com} 32212923Sgabeblack@google.com 32312837Sgabeblack@google.comconst sc_time 32412989Sgabeblack@google.comoperator + (const sc_time &a, const sc_time &b) 32512837Sgabeblack@google.com{ 32612989Sgabeblack@google.com return sc_time::from_value(a.value() + b.value()); 32712837Sgabeblack@google.com} 32812837Sgabeblack@google.com 32912837Sgabeblack@google.comconst sc_time 33012989Sgabeblack@google.comoperator - (const sc_time &a, const sc_time &b) 33112837Sgabeblack@google.com{ 33212989Sgabeblack@google.com return sc_time::from_value(a.value() - b.value()); 33312837Sgabeblack@google.com} 33412837Sgabeblack@google.com 33512837Sgabeblack@google.comconst sc_time 33613040Sgabeblack@google.comoperator * (const sc_time &t, double d) 33712837Sgabeblack@google.com{ 33813040Sgabeblack@google.com volatile double tmp = static_cast<double>(t.value()) * d + 0.5; 33913040Sgabeblack@google.com return sc_time::from_value(static_cast<int64_t>(tmp)); 34012837Sgabeblack@google.com} 34112837Sgabeblack@google.com 34212837Sgabeblack@google.comconst sc_time 34313040Sgabeblack@google.comoperator * (double d, const sc_time &t) 34412837Sgabeblack@google.com{ 34513040Sgabeblack@google.com volatile double tmp = d * static_cast<double>(t.value()) + 0.5; 34613040Sgabeblack@google.com return sc_time::from_value(static_cast<int64_t>(tmp)); 34712837Sgabeblack@google.com} 34812837Sgabeblack@google.com 34912837Sgabeblack@google.comconst sc_time 35013040Sgabeblack@google.comoperator / (const sc_time &t, double d) 35112837Sgabeblack@google.com{ 35213040Sgabeblack@google.com volatile double tmp = static_cast<double>(t.value()) / d + 0.5; 35313040Sgabeblack@google.com return sc_time::from_value(static_cast<int64_t>(tmp)); 35412837Sgabeblack@google.com} 35512837Sgabeblack@google.com 35612837Sgabeblack@google.comdouble 35713040Sgabeblack@google.comoperator / (const sc_time &t1, const sc_time &t2) 35812837Sgabeblack@google.com{ 35913040Sgabeblack@google.com return t1.to_double() / t2.to_double(); 36012837Sgabeblack@google.com} 36112837Sgabeblack@google.com 36212837Sgabeblack@google.comstd::ostream & 36312983Sgabeblack@google.comoperator << (std::ostream &os, const sc_time &t) 36412837Sgabeblack@google.com{ 36512983Sgabeblack@google.com t.print(os); 36612837Sgabeblack@google.com return os; 36712837Sgabeblack@google.com} 36812837Sgabeblack@google.com 36912837Sgabeblack@google.comconst sc_time SC_ZERO_TIME; 37012837Sgabeblack@google.com 37112837Sgabeblack@google.comvoid 37213149Sgabeblack@google.comsc_set_time_resolution(double d, sc_time_unit tu) 37312837Sgabeblack@google.com{ 37413151Sgabeblack@google.com if (d <= 0.0) { 37513149Sgabeblack@google.com SC_REPORT_ERROR("(E514) set time resolution failed", 37613149Sgabeblack@google.com "value not positive"); 37713149Sgabeblack@google.com } 37813149Sgabeblack@google.com double dummy; 37913149Sgabeblack@google.com if (modf(log10(d), &dummy) != 0.0) { 38013149Sgabeblack@google.com SC_REPORT_ERROR("(E514) set time resolution failed", 38113149Sgabeblack@google.com "value not a power of ten"); 38213149Sgabeblack@google.com } 38313149Sgabeblack@google.com if (sc_is_running()) { 38413149Sgabeblack@google.com SC_REPORT_ERROR("(E514) set time resolution failed", 38513149Sgabeblack@google.com "simulation running"); 38613149Sgabeblack@google.com } 38713149Sgabeblack@google.com static bool specified = false; 38813149Sgabeblack@google.com if (specified) { 38913149Sgabeblack@google.com SC_REPORT_ERROR("(E514) set time resolution failed", 39013149Sgabeblack@google.com "already specified"); 39113149Sgabeblack@google.com } 39213149Sgabeblack@google.com // This won't detect the timescale being fixed outside of systemc, but 39313149Sgabeblack@google.com // it's at least some protection. 39413149Sgabeblack@google.com if (timeFixed) { 39513149Sgabeblack@google.com SC_REPORT_ERROR("(E514) set time resolution failed", 39613149Sgabeblack@google.com "sc_time object(s) constructed"); 39713149Sgabeblack@google.com } 39813149Sgabeblack@google.com 39913149Sgabeblack@google.com // Normalize d to seconds. 40013149Sgabeblack@google.com d *= TimeUnitScale[tu]; 40113149Sgabeblack@google.com if (d < TimeUnitScale[SC_FS]) { 40213149Sgabeblack@google.com SC_REPORT_ERROR("(E514) set time resolution failed", 40313149Sgabeblack@google.com "value smaller than 1 fs"); 40413149Sgabeblack@google.com } 40513149Sgabeblack@google.com // Change d from a period to a frequency. 40613149Sgabeblack@google.com d = 1 / d; 40713149Sgabeblack@google.com // Convert to integer ticks. 40813149Sgabeblack@google.com Tick ticks_per_second = static_cast<Tick>(d); 40913149Sgabeblack@google.com setGlobalFrequency(ticks_per_second); 41013149Sgabeblack@google.com specified = true; 41112837Sgabeblack@google.com} 41212837Sgabeblack@google.com 41312837Sgabeblack@google.comsc_time 41412837Sgabeblack@google.comsc_get_time_resolution() 41512837Sgabeblack@google.com{ 41613149Sgabeblack@google.com return sc_time::from_value(1); 41712837Sgabeblack@google.com} 41812837Sgabeblack@google.com 41912837Sgabeblack@google.comconst sc_time & 42012837Sgabeblack@google.comsc_max_time() 42112837Sgabeblack@google.com{ 42212989Sgabeblack@google.com static const sc_time MaxScTime = sc_time::from_value(MaxTick); 42312989Sgabeblack@google.com return MaxScTime; 42412837Sgabeblack@google.com} 42512837Sgabeblack@google.com 42612916Sgabeblack@google.comvoid 42713124Sgabeblack@google.comsc_set_default_time_unit(double d, sc_time_unit tu) 42812916Sgabeblack@google.com{ 42913151Sgabeblack@google.com if (d < 0.0) { 43013151Sgabeblack@google.com SC_REPORT_ERROR("(E515) set default time unit failed", 43113151Sgabeblack@google.com "value not positive"); 43213151Sgabeblack@google.com } 43313151Sgabeblack@google.com double dummy; 43413151Sgabeblack@google.com if (modf(log10(d), &dummy) != 0.0) { 43513151Sgabeblack@google.com SC_REPORT_ERROR("(E515) set default time unit failed", 43613151Sgabeblack@google.com "value not a power of ten"); 43713151Sgabeblack@google.com } 43813151Sgabeblack@google.com if (sc_is_running()) { 43913151Sgabeblack@google.com SC_REPORT_ERROR("(E515) set default time unit failed", 44013151Sgabeblack@google.com "simulation running"); 44113151Sgabeblack@google.com } 44213151Sgabeblack@google.com static bool specified = false; 44313151Sgabeblack@google.com if (specified) { 44413151Sgabeblack@google.com SC_REPORT_ERROR("(E515) set default time unit failed", 44513151Sgabeblack@google.com "already specified"); 44613151Sgabeblack@google.com } 44713151Sgabeblack@google.com // This won't detect the timescale being fixed outside of systemc, but 44813151Sgabeblack@google.com // it's at least some protection. 44913151Sgabeblack@google.com if (timeFixed) { 45013151Sgabeblack@google.com SC_REPORT_ERROR("(E515) set default time unit failed", 45113151Sgabeblack@google.com "sc_time object(s) constructed"); 45213151Sgabeblack@google.com } 45313151Sgabeblack@google.com 45413151Sgabeblack@google.com // Normalize d to seconds. 45513124Sgabeblack@google.com defaultUnit = d * TimeUnitScale[tu]; 45613151Sgabeblack@google.com specified = true; 45712916Sgabeblack@google.com} 45812916Sgabeblack@google.com 45912916Sgabeblack@google.comsc_time 46012916Sgabeblack@google.comsc_get_default_time_unit() 46112916Sgabeblack@google.com{ 46213124Sgabeblack@google.com return sc_time(defaultUnit, SC_SEC); 46312916Sgabeblack@google.com} 46412916Sgabeblack@google.com 46512927Sgabeblack@google.comsc_time_tuple::sc_time_tuple(const sc_time &) 46612927Sgabeblack@google.com{ 46712927Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 46812927Sgabeblack@google.com} 46912927Sgabeblack@google.com 47012927Sgabeblack@google.combool 47112927Sgabeblack@google.comsc_time_tuple::has_value() const 47212927Sgabeblack@google.com{ 47312927Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 47412927Sgabeblack@google.com return false; 47512927Sgabeblack@google.com} 47612927Sgabeblack@google.com 47712927Sgabeblack@google.comsc_dt::uint64 47812927Sgabeblack@google.comsc_time_tuple::value() const 47912927Sgabeblack@google.com{ 48012927Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 48112927Sgabeblack@google.com return 0; 48212927Sgabeblack@google.com} 48312927Sgabeblack@google.com 48412927Sgabeblack@google.comconst char * 48512927Sgabeblack@google.comsc_time_tuple::unit_symbol() const 48612927Sgabeblack@google.com{ 48712927Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 48812927Sgabeblack@google.com return ""; 48912927Sgabeblack@google.com} 49012927Sgabeblack@google.com 49112927Sgabeblack@google.comdouble 49212927Sgabeblack@google.comsc_time_tuple::to_double() const 49312927Sgabeblack@google.com{ 49412927Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 49512927Sgabeblack@google.com return 0.0; 49612927Sgabeblack@google.com} 49712927Sgabeblack@google.com 49812927Sgabeblack@google.comstd::string 49912927Sgabeblack@google.comsc_time_tuple::to_string() const 50012927Sgabeblack@google.com{ 50112927Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 50212927Sgabeblack@google.com return ""; 50312927Sgabeblack@google.com} 50412927Sgabeblack@google.com 50512837Sgabeblack@google.com} // namespace sc_core 506