1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * Authors: Gabe Black 28 */ 29 30#include <sstream> 31#include <vector> 32 33#include "base/logging.hh" 34#include "base/types.hh" 35#include "python/pybind11/pybind.hh" 36#include "sim/core.hh" 37#include "systemc/core/python.hh"
| 1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * Authors: Gabe Black 28 */ 29 30#include <sstream> 31#include <vector> 32 33#include "base/logging.hh" 34#include "base/types.hh" 35#include "python/pybind11/pybind.hh" 36#include "sim/core.hh" 37#include "systemc/core/python.hh"
|
| 38#include "systemc/core/time.hh"
|
38#include "systemc/ext/core/sc_main.hh" 39#include "systemc/ext/core/sc_time.hh" 40#include "systemc/ext/utils/sc_report_handler.hh" 41 42namespace sc_core 43{ 44 45namespace 46{ 47
| 39#include "systemc/ext/core/sc_main.hh" 40#include "systemc/ext/core/sc_time.hh" 41#include "systemc/ext/utils/sc_report_handler.hh" 42 43namespace sc_core 44{ 45 46namespace 47{ 48
|
48const char *TimeUnitNames[] = { 49 [SC_FS] = "fs", 50 [SC_PS] = "ps", 51 [SC_NS] = "ns", 52 [SC_US] = "us", 53 [SC_MS] = "ms", 54 [SC_SEC] = "s" 55}; 56 57double TimeUnitScale[] = { 58 [SC_FS] = 1.0e-15, 59 [SC_PS] = 1.0e-12, 60 [SC_NS] = 1.0e-9, 61 [SC_US] = 1.0e-6, 62 [SC_MS] = 1.0e-3, 63 [SC_SEC] = 1.0 64}; 65 66Tick TimeUnitFrequency[] = { 67 [SC_FS] = 1ULL * 1000 * 1000 * 1000 * 1000 * 1000, 68 [SC_PS] = 1ULL * 1000 * 1000 * 1000 * 1000, 69 [SC_NS] = 1ULL * 1000 * 1000 * 1000, 70 [SC_US] = 1ULL * 1000 * 1000, 71 [SC_MS] = 1ULL * 1000, 72 [SC_SEC] = 1ULL 73}; 74
| |
75bool timeFixed = false; 76bool pythonReady = false; 77 78struct SetInfo 79{ 80 SetInfo(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu) : 81 time(time), d(d), tu(tu) 82 {} 83 84 ::sc_core::sc_time *time; 85 double d; 86 ::sc_core::sc_time_unit tu; 87}; 88std::vector<SetInfo> toSet; 89 90void 91setWork(sc_time *time, double d, ::sc_core::sc_time_unit tu) 92{
| 49bool timeFixed = false; 50bool pythonReady = false; 51 52struct SetInfo 53{ 54 SetInfo(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu) : 55 time(time), d(d), tu(tu) 56 {} 57 58 ::sc_core::sc_time *time; 59 double d; 60 ::sc_core::sc_time_unit tu; 61}; 62std::vector<SetInfo> toSet; 63 64void 65setWork(sc_time *time, double d, ::sc_core::sc_time_unit tu) 66{
|
93 double scale = TimeUnitScale[tu] * SimClock::Float::s;
| 67 double scale = sc_gem5::TimeUnitScale[tu] * SimClock::Float::s;
|
94 // Accellera claims there is a linux bug, and that these next two 95 // lines work around them. 96 volatile double tmp = d * scale + 0.5; 97 *time = sc_time::from_value(static_cast<uint64_t>(tmp)); 98} 99 100void 101fixTime() 102{ 103 auto ticks = pybind11::module::import("m5.ticks"); 104 auto fix_global_frequency = ticks.attr("fixGlobalFrequency"); 105 fix_global_frequency(); 106 107 for (auto &t: toSet) 108 setWork(t.time, t.d, t.tu); 109 toSet.clear(); 110} 111 112void 113attemptToFixTime() 114{ 115 // Only fix time once. 116 if (!timeFixed) { 117 timeFixed = true; 118 119 // If we've run, python is working and we haven't fixed time yet. 120 if (pythonReady) 121 fixTime(); 122 } 123} 124 125void 126setGlobalFrequency(Tick ticks_per_second) 127{ 128 auto ticks = pybind11::module::import("m5.ticks"); 129 auto set_global_frequency = ticks.attr("setGlobalFrequency"); 130 set_global_frequency(ticks_per_second); 131 fixTime(); 132} 133 134void 135set(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu) 136{ 137 if (d != 0) 138 attemptToFixTime(); 139 if (pythonReady) { 140 // Time should be working. Set up this sc_time. 141 setWork(time, d, tu); 142 } else { 143 // Time isn't set up yet. Defer setting up this sc_time. 144 toSet.emplace_back(time, d, tu); 145 } 146} 147 148class TimeSetter : public ::sc_gem5::PythonReadyFunc 149{ 150 public: 151 TimeSetter() : ::sc_gem5::PythonReadyFunc() {} 152 153 void 154 run() override 155 { 156 // Record that we've run and python/pybind should be usable. 157 pythonReady = true; 158 159 // If time is already fixed, let python know. 160 if (timeFixed) 161 fixTime(); 162 } 163} timeSetter; 164 165double defaultUnit = 1.0e-9; 166 167} // anonymous namespace 168 169sc_time::sc_time() : val(0) {} 170 171sc_time::sc_time(double d, sc_time_unit tu) 172{ 173 val = 0; 174 set(this, d, tu); 175} 176 177sc_time::sc_time(const sc_time &t) 178{ 179 val = t.val; 180} 181 182sc_time::sc_time(double d, bool scale) 183{ 184 double scaler = scale ? defaultUnit : SimClock::Float::Hz; 185 set(this, d * scaler, SC_SEC); 186} 187 188sc_time::sc_time(sc_dt::uint64 v, bool scale) 189{ 190 double scaler = scale ? defaultUnit : SimClock::Float::Hz; 191 set(this, static_cast<double>(v) * scaler, SC_SEC); 192} 193 194sc_time & 195sc_time::operator = (const sc_time &t) 196{ 197 val = t.val; 198 return *this; 199} 200 201sc_dt::uint64 202sc_time::value() const 203{ 204 return val; 205} 206 207double 208sc_time::to_double() const 209{ 210 return static_cast<double>(val); 211} 212double 213sc_time::to_seconds() const 214{ 215 return to_double() * SimClock::Float::Hz; 216} 217 218const std::string 219sc_time::to_string() const 220{ 221 std::ostringstream ss; 222 print(ss); 223 return ss.str(); 224} 225 226bool 227sc_time::operator == (const sc_time &t) const 228{ 229 return val == t.val; 230} 231 232bool 233sc_time::operator != (const sc_time &t) const 234{ 235 return val != t.val; 236} 237 238bool 239sc_time::operator < (const sc_time &t) const 240{ 241 return val < t.val; 242} 243 244bool 245sc_time::operator <= (const sc_time &t) const 246{ 247 return val <= t.val; 248} 249 250bool 251sc_time::operator > (const sc_time &t) const 252{ 253 return val > t.val; 254} 255 256bool 257sc_time::operator >= (const sc_time &t) const 258{ 259 return val >= t.val; 260} 261 262sc_time & 263sc_time::operator += (const sc_time &t) 264{ 265 val += t.val; 266 return *this; 267} 268 269sc_time & 270sc_time::operator -= (const sc_time &t) 271{ 272 val -= t.val; 273 return *this; 274} 275 276sc_time & 277sc_time::operator *= (double d) 278{ 279 val = static_cast<int64_t>(static_cast<double>(val) * d + 0.5); 280 return *this; 281} 282 283sc_time & 284sc_time::operator /= (double d) 285{ 286 val = static_cast<int64_t>(static_cast<double>(val) / d + 0.5); 287 return *this; 288} 289 290void 291sc_time::print(std::ostream &os) const 292{ 293 if (val == 0) { 294 os << "0 s"; 295 } else { 296 Tick frequency = SimClock::Frequency; 297 298 // Shrink the frequency by scaling down the time period, ie converting 299 // it from cycles per second to cycles per millisecond, etc. 300 sc_time_unit tu = SC_SEC; 301 while (tu > 1 && (frequency % 1000 == 0)) { 302 tu = (sc_time_unit)((int)tu - 1); 303 frequency /= 1000; 304 } 305 306 // Convert the frequency into a period. 307 Tick period; 308 if (frequency > 1) { 309 tu = (sc_time_unit)((int)tu - 1); 310 period = 1000 / frequency; 311 } else { 312 period = frequency; 313 } 314 315 // Scale our integer value by the period. 316 uint64_t scaled = val * period; 317 318 // Shrink the scaled time value by increasing the size of the units 319 // it's measured by, avoiding fractional parts. 320 while (tu < SC_SEC && (scaled % 1000) == 0) { 321 tu = (sc_time_unit)((int)tu + 1); 322 scaled /= 1000; 323 } 324
| 68 // Accellera claims there is a linux bug, and that these next two 69 // lines work around them. 70 volatile double tmp = d * scale + 0.5; 71 *time = sc_time::from_value(static_cast<uint64_t>(tmp)); 72} 73 74void 75fixTime() 76{ 77 auto ticks = pybind11::module::import("m5.ticks"); 78 auto fix_global_frequency = ticks.attr("fixGlobalFrequency"); 79 fix_global_frequency(); 80 81 for (auto &t: toSet) 82 setWork(t.time, t.d, t.tu); 83 toSet.clear(); 84} 85 86void 87attemptToFixTime() 88{ 89 // Only fix time once. 90 if (!timeFixed) { 91 timeFixed = true; 92 93 // If we've run, python is working and we haven't fixed time yet. 94 if (pythonReady) 95 fixTime(); 96 } 97} 98 99void 100setGlobalFrequency(Tick ticks_per_second) 101{ 102 auto ticks = pybind11::module::import("m5.ticks"); 103 auto set_global_frequency = ticks.attr("setGlobalFrequency"); 104 set_global_frequency(ticks_per_second); 105 fixTime(); 106} 107 108void 109set(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu) 110{ 111 if (d != 0) 112 attemptToFixTime(); 113 if (pythonReady) { 114 // Time should be working. Set up this sc_time. 115 setWork(time, d, tu); 116 } else { 117 // Time isn't set up yet. Defer setting up this sc_time. 118 toSet.emplace_back(time, d, tu); 119 } 120} 121 122class TimeSetter : public ::sc_gem5::PythonReadyFunc 123{ 124 public: 125 TimeSetter() : ::sc_gem5::PythonReadyFunc() {} 126 127 void 128 run() override 129 { 130 // Record that we've run and python/pybind should be usable. 131 pythonReady = true; 132 133 // If time is already fixed, let python know. 134 if (timeFixed) 135 fixTime(); 136 } 137} timeSetter; 138 139double defaultUnit = 1.0e-9; 140 141} // anonymous namespace 142 143sc_time::sc_time() : val(0) {} 144 145sc_time::sc_time(double d, sc_time_unit tu) 146{ 147 val = 0; 148 set(this, d, tu); 149} 150 151sc_time::sc_time(const sc_time &t) 152{ 153 val = t.val; 154} 155 156sc_time::sc_time(double d, bool scale) 157{ 158 double scaler = scale ? defaultUnit : SimClock::Float::Hz; 159 set(this, d * scaler, SC_SEC); 160} 161 162sc_time::sc_time(sc_dt::uint64 v, bool scale) 163{ 164 double scaler = scale ? defaultUnit : SimClock::Float::Hz; 165 set(this, static_cast<double>(v) * scaler, SC_SEC); 166} 167 168sc_time & 169sc_time::operator = (const sc_time &t) 170{ 171 val = t.val; 172 return *this; 173} 174 175sc_dt::uint64 176sc_time::value() const 177{ 178 return val; 179} 180 181double 182sc_time::to_double() const 183{ 184 return static_cast<double>(val); 185} 186double 187sc_time::to_seconds() const 188{ 189 return to_double() * SimClock::Float::Hz; 190} 191 192const std::string 193sc_time::to_string() const 194{ 195 std::ostringstream ss; 196 print(ss); 197 return ss.str(); 198} 199 200bool 201sc_time::operator == (const sc_time &t) const 202{ 203 return val == t.val; 204} 205 206bool 207sc_time::operator != (const sc_time &t) const 208{ 209 return val != t.val; 210} 211 212bool 213sc_time::operator < (const sc_time &t) const 214{ 215 return val < t.val; 216} 217 218bool 219sc_time::operator <= (const sc_time &t) const 220{ 221 return val <= t.val; 222} 223 224bool 225sc_time::operator > (const sc_time &t) const 226{ 227 return val > t.val; 228} 229 230bool 231sc_time::operator >= (const sc_time &t) const 232{ 233 return val >= t.val; 234} 235 236sc_time & 237sc_time::operator += (const sc_time &t) 238{ 239 val += t.val; 240 return *this; 241} 242 243sc_time & 244sc_time::operator -= (const sc_time &t) 245{ 246 val -= t.val; 247 return *this; 248} 249 250sc_time & 251sc_time::operator *= (double d) 252{ 253 val = static_cast<int64_t>(static_cast<double>(val) * d + 0.5); 254 return *this; 255} 256 257sc_time & 258sc_time::operator /= (double d) 259{ 260 val = static_cast<int64_t>(static_cast<double>(val) / d + 0.5); 261 return *this; 262} 263 264void 265sc_time::print(std::ostream &os) const 266{ 267 if (val == 0) { 268 os << "0 s"; 269 } else { 270 Tick frequency = SimClock::Frequency; 271 272 // Shrink the frequency by scaling down the time period, ie converting 273 // it from cycles per second to cycles per millisecond, etc. 274 sc_time_unit tu = SC_SEC; 275 while (tu > 1 && (frequency % 1000 == 0)) { 276 tu = (sc_time_unit)((int)tu - 1); 277 frequency /= 1000; 278 } 279 280 // Convert the frequency into a period. 281 Tick period; 282 if (frequency > 1) { 283 tu = (sc_time_unit)((int)tu - 1); 284 period = 1000 / frequency; 285 } else { 286 period = frequency; 287 } 288 289 // Scale our integer value by the period. 290 uint64_t scaled = val * period; 291 292 // Shrink the scaled time value by increasing the size of the units 293 // it's measured by, avoiding fractional parts. 294 while (tu < SC_SEC && (scaled % 1000) == 0) { 295 tu = (sc_time_unit)((int)tu + 1); 296 scaled /= 1000; 297 } 298
|
325 os << scaled << ' ' << TimeUnitNames[tu];
| 299 os << scaled << ' ' << sc_gem5::TimeUnitNames[tu];
|
326 } 327} 328 329sc_time 330sc_time::from_value(sc_dt::uint64 u) 331{ 332 if (u) 333 attemptToFixTime(); 334 sc_time t; 335 t.val = u; 336 return t; 337} 338 339sc_time 340sc_time::from_seconds(double d) 341{ 342 sc_time t; 343 set(&t, d, SC_SEC); 344 return t; 345} 346 347sc_time 348sc_time::from_string(const char *str) 349{ 350 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 351 return sc_time(); 352} 353 354const sc_time 355operator + (const sc_time &a, const sc_time &b) 356{ 357 return sc_time::from_value(a.value() + b.value()); 358} 359 360const sc_time 361operator - (const sc_time &a, const sc_time &b) 362{ 363 return sc_time::from_value(a.value() - b.value()); 364} 365 366const sc_time 367operator * (const sc_time &t, double d) 368{ 369 volatile double tmp = static_cast<double>(t.value()) * d + 0.5; 370 return sc_time::from_value(static_cast<int64_t>(tmp)); 371} 372 373const sc_time 374operator * (double d, const sc_time &t) 375{ 376 volatile double tmp = d * static_cast<double>(t.value()) + 0.5; 377 return sc_time::from_value(static_cast<int64_t>(tmp)); 378} 379 380const sc_time 381operator / (const sc_time &t, double d) 382{ 383 volatile double tmp = static_cast<double>(t.value()) / d + 0.5; 384 return sc_time::from_value(static_cast<int64_t>(tmp)); 385} 386 387double 388operator / (const sc_time &t1, const sc_time &t2) 389{ 390 return t1.to_double() / t2.to_double(); 391} 392 393std::ostream & 394operator << (std::ostream &os, const sc_time &t) 395{ 396 t.print(os); 397 return os; 398} 399 400const sc_time SC_ZERO_TIME; 401 402void 403sc_set_time_resolution(double d, sc_time_unit tu) 404{ 405 if (d <= 0.0) { 406 SC_REPORT_ERROR("(E514) set time resolution failed", 407 "value not positive"); 408 } 409 double dummy; 410 if (modf(log10(d), &dummy) != 0.0) { 411 SC_REPORT_ERROR("(E514) set time resolution failed", 412 "value not a power of ten"); 413 } 414 if (sc_is_running()) { 415 SC_REPORT_ERROR("(E514) set time resolution failed", 416 "simulation running"); 417 } 418 static bool specified = false; 419 if (specified) { 420 SC_REPORT_ERROR("(E514) set time resolution failed", 421 "already specified"); 422 } 423 // This won't detect the timescale being fixed outside of systemc, but 424 // it's at least some protection. 425 if (timeFixed) { 426 SC_REPORT_ERROR("(E514) set time resolution failed", 427 "sc_time object(s) constructed"); 428 } 429
| 300 } 301} 302 303sc_time 304sc_time::from_value(sc_dt::uint64 u) 305{ 306 if (u) 307 attemptToFixTime(); 308 sc_time t; 309 t.val = u; 310 return t; 311} 312 313sc_time 314sc_time::from_seconds(double d) 315{ 316 sc_time t; 317 set(&t, d, SC_SEC); 318 return t; 319} 320 321sc_time 322sc_time::from_string(const char *str) 323{ 324 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 325 return sc_time(); 326} 327 328const sc_time 329operator + (const sc_time &a, const sc_time &b) 330{ 331 return sc_time::from_value(a.value() + b.value()); 332} 333 334const sc_time 335operator - (const sc_time &a, const sc_time &b) 336{ 337 return sc_time::from_value(a.value() - b.value()); 338} 339 340const sc_time 341operator * (const sc_time &t, double d) 342{ 343 volatile double tmp = static_cast<double>(t.value()) * d + 0.5; 344 return sc_time::from_value(static_cast<int64_t>(tmp)); 345} 346 347const sc_time 348operator * (double d, const sc_time &t) 349{ 350 volatile double tmp = d * static_cast<double>(t.value()) + 0.5; 351 return sc_time::from_value(static_cast<int64_t>(tmp)); 352} 353 354const sc_time 355operator / (const sc_time &t, double d) 356{ 357 volatile double tmp = static_cast<double>(t.value()) / d + 0.5; 358 return sc_time::from_value(static_cast<int64_t>(tmp)); 359} 360 361double 362operator / (const sc_time &t1, const sc_time &t2) 363{ 364 return t1.to_double() / t2.to_double(); 365} 366 367std::ostream & 368operator << (std::ostream &os, const sc_time &t) 369{ 370 t.print(os); 371 return os; 372} 373 374const sc_time SC_ZERO_TIME; 375 376void 377sc_set_time_resolution(double d, sc_time_unit tu) 378{ 379 if (d <= 0.0) { 380 SC_REPORT_ERROR("(E514) set time resolution failed", 381 "value not positive"); 382 } 383 double dummy; 384 if (modf(log10(d), &dummy) != 0.0) { 385 SC_REPORT_ERROR("(E514) set time resolution failed", 386 "value not a power of ten"); 387 } 388 if (sc_is_running()) { 389 SC_REPORT_ERROR("(E514) set time resolution failed", 390 "simulation running"); 391 } 392 static bool specified = false; 393 if (specified) { 394 SC_REPORT_ERROR("(E514) set time resolution failed", 395 "already specified"); 396 } 397 // This won't detect the timescale being fixed outside of systemc, but 398 // it's at least some protection. 399 if (timeFixed) { 400 SC_REPORT_ERROR("(E514) set time resolution failed", 401 "sc_time object(s) constructed"); 402 } 403
|
430 double seconds = d * TimeUnitScale[tu]; 431 if (seconds < TimeUnitScale[SC_FS]) {
| 404 double seconds = d * sc_gem5::TimeUnitScale[tu]; 405 if (seconds < sc_gem5::TimeUnitScale[SC_FS]) {
|
432 SC_REPORT_ERROR("(E514) set time resolution failed", 433 "value smaller than 1 fs"); 434 } 435 436 if (seconds > defaultUnit) { 437 SC_REPORT_WARNING( 438 "(W516) default time unit changed to time resolution", ""); 439 defaultUnit = seconds; 440 } 441 442 // Get rid of fractional parts of d. 443 while (d < 1.0 && tu > SC_FS) { 444 d *= 1000; 445 tu = (sc_time_unit)(tu - 1); 446 } 447
| 406 SC_REPORT_ERROR("(E514) set time resolution failed", 407 "value smaller than 1 fs"); 408 } 409 410 if (seconds > defaultUnit) { 411 SC_REPORT_WARNING( 412 "(W516) default time unit changed to time resolution", ""); 413 defaultUnit = seconds; 414 } 415 416 // Get rid of fractional parts of d. 417 while (d < 1.0 && tu > SC_FS) { 418 d *= 1000; 419 tu = (sc_time_unit)(tu - 1); 420 } 421
|
448 Tick ticks_per_second = TimeUnitFrequency[tu] / static_cast<Tick>(d);
| 422 Tick ticks_per_second = 423 sc_gem5::TimeUnitFrequency[tu] / static_cast<Tick>(d);
|
449 setGlobalFrequency(ticks_per_second); 450 specified = true; 451} 452 453sc_time 454sc_get_time_resolution() 455{ 456 return sc_time::from_value(1); 457} 458 459const sc_time & 460sc_max_time() 461{ 462 static const sc_time MaxScTime = sc_time::from_value(MaxTick); 463 return MaxScTime; 464} 465 466void 467sc_set_default_time_unit(double d, sc_time_unit tu) 468{ 469 if (d < 0.0) { 470 SC_REPORT_ERROR("(E515) set default time unit failed", 471 "value not positive"); 472 } 473 double dummy; 474 if (modf(log10(d), &dummy) != 0.0) { 475 SC_REPORT_ERROR("(E515) set default time unit failed", 476 "value not a power of ten"); 477 } 478 if (sc_is_running()) { 479 SC_REPORT_ERROR("(E515) set default time unit failed", 480 "simulation running"); 481 } 482 static bool specified = false; 483 if (specified) { 484 SC_REPORT_ERROR("(E515) set default time unit failed", 485 "already specified"); 486 } 487 // This won't detect the timescale being fixed outside of systemc, but 488 // it's at least some protection. 489 if (timeFixed) { 490 SC_REPORT_ERROR("(E515) set default time unit failed", 491 "sc_time object(s) constructed"); 492 } 493 494 // Normalize d to seconds.
| 424 setGlobalFrequency(ticks_per_second); 425 specified = true; 426} 427 428sc_time 429sc_get_time_resolution() 430{ 431 return sc_time::from_value(1); 432} 433 434const sc_time & 435sc_max_time() 436{ 437 static const sc_time MaxScTime = sc_time::from_value(MaxTick); 438 return MaxScTime; 439} 440 441void 442sc_set_default_time_unit(double d, sc_time_unit tu) 443{ 444 if (d < 0.0) { 445 SC_REPORT_ERROR("(E515) set default time unit failed", 446 "value not positive"); 447 } 448 double dummy; 449 if (modf(log10(d), &dummy) != 0.0) { 450 SC_REPORT_ERROR("(E515) set default time unit failed", 451 "value not a power of ten"); 452 } 453 if (sc_is_running()) { 454 SC_REPORT_ERROR("(E515) set default time unit failed", 455 "simulation running"); 456 } 457 static bool specified = false; 458 if (specified) { 459 SC_REPORT_ERROR("(E515) set default time unit failed", 460 "already specified"); 461 } 462 // This won't detect the timescale being fixed outside of systemc, but 463 // it's at least some protection. 464 if (timeFixed) { 465 SC_REPORT_ERROR("(E515) set default time unit failed", 466 "sc_time object(s) constructed"); 467 } 468 469 // Normalize d to seconds.
|
495 defaultUnit = d * TimeUnitScale[tu];
| 470 defaultUnit = d * sc_gem5::TimeUnitScale[tu];
|
496 specified = true; 497 498 double resolution = SimClock::Float::Hz; 499 if (resolution == 0.0)
| 471 specified = true; 472 473 double resolution = SimClock::Float::Hz; 474 if (resolution == 0.0)
|
500 resolution = TimeUnitScale[SC_PS];
| 475 resolution = sc_gem5::TimeUnitScale[SC_PS];
|
501 if (defaultUnit < resolution) { 502 SC_REPORT_ERROR("(E515) set default time unit failed", 503 "value smaller than time resolution"); 504 } 505} 506 507sc_time 508sc_get_default_time_unit() 509{ 510 return sc_time(defaultUnit, SC_SEC); 511} 512 513sc_time_tuple::sc_time_tuple(const sc_time &) 514{ 515 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 516} 517 518bool 519sc_time_tuple::has_value() const 520{ 521 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 522 return false; 523} 524 525sc_dt::uint64 526sc_time_tuple::value() const 527{ 528 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 529 return 0; 530} 531 532const char * 533sc_time_tuple::unit_symbol() const 534{ 535 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 536 return ""; 537} 538 539double 540sc_time_tuple::to_double() const 541{ 542 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 543 return 0.0; 544} 545 546std::string 547sc_time_tuple::to_string() const 548{ 549 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 550 return ""; 551} 552 553} // namespace sc_core
| 476 if (defaultUnit < resolution) { 477 SC_REPORT_ERROR("(E515) set default time unit failed", 478 "value smaller than time resolution"); 479 } 480} 481 482sc_time 483sc_get_default_time_unit() 484{ 485 return sc_time(defaultUnit, SC_SEC); 486} 487 488sc_time_tuple::sc_time_tuple(const sc_time &) 489{ 490 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 491} 492 493bool 494sc_time_tuple::has_value() const 495{ 496 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 497 return false; 498} 499 500sc_dt::uint64 501sc_time_tuple::value() const 502{ 503 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 504 return 0; 505} 506 507const char * 508sc_time_tuple::unit_symbol() const 509{ 510 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 511 return ""; 512} 513 514double 515sc_time_tuple::to_double() const 516{ 517 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 518 return 0.0; 519} 520 521std::string 522sc_time_tuple::to_string() const 523{ 524 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 525 return ""; 526} 527 528} // namespace sc_core
|