sc_time.cc (13247:4aafce81e7dd) sc_time.cc (13252:8814e5d87a48)
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"
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"
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()

--- 215 unchanged lines hidden (view full) ---

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()

--- 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
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();

--- 88 unchanged lines hidden (view full) ---

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();

--- 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
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);

--- 30 unchanged lines hidden (view full) ---

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);

--- 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.
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()

--- 45 unchanged lines hidden ---
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 ---