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 --- 21 unchanged lines hidden (view full) --- 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" |
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 |
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{ |
67 double scale = sc_gem5::TimeUnitScale[tu] * SimClock::Float::s; |
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() --- 215 unchanged lines hidden (view full) --- 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 |
299 os << scaled << ' ' << sc_gem5::TimeUnitNames[tu]; |
300 } 301} 302 303sc_time 304sc_time::from_value(sc_dt::uint64 u) 305{ 306 if (u) 307 attemptToFixTime(); --- 88 unchanged lines hidden (view full) --- 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 |
404 double seconds = d * sc_gem5::TimeUnitScale[tu]; 405 if (seconds < sc_gem5::TimeUnitScale[SC_FS]) { |
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 |
422 Tick ticks_per_second = 423 sc_gem5::TimeUnitFrequency[tu] / static_cast<Tick>(d); |
424 setGlobalFrequency(ticks_per_second); 425 specified = true; 426} 427 428sc_time 429sc_get_time_resolution() 430{ 431 return sc_time::from_value(1); --- 30 unchanged lines hidden (view full) --- 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. |
470 defaultUnit = d * sc_gem5::TimeUnitScale[tu]; |
471 specified = true; 472 473 double resolution = SimClock::Float::Hz; 474 if (resolution == 0.0) |
475 resolution = sc_gem5::TimeUnitScale[SC_PS]; |
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() --- 45 unchanged lines hidden --- |