35a36
> #include "sim/core.hh"
64a66,74
> Tick TimeUnitFrequency[] = {
> [SC_FS] = 1ULL * 1000 * 1000 * 1000 * 1000 * 1000,
> [SC_PS] = 1ULL * 1000 * 1000 * 1000 * 1000,
> [SC_NS] = 1ULL * 1000 * 1000 * 1000,
> [SC_US] = 1ULL * 1000 * 1000,
> [SC_MS] = 1ULL * 1000,
> [SC_SEC] = 1ULL
> };
>
83,84c93
< //XXX Assuming the time resolution is 1ps.
< double scale = TimeUnitScale[tu] / TimeUnitScale[SC_PS];
---
> double scale = TimeUnitScale[tu] * SimClock::Float::s;
103a113,125
> attemptToFixTime()
> {
> // Only fix time once.
> if (!timeFixed) {
> timeFixed = true;
>
> // If we've run, python is working and we haven't fixed time yet.
> if (pythonReady)
> fixTime();
> }
> }
>
> void
115,122c137,138
< // Only fix time once.
< if (!timeFixed) {
< timeFixed = true;
<
< // If we've run, python is working and we haven't fixed time yet.
< if (pythonReady)
< fixTime();
< }
---
> if (d != 0)
> attemptToFixTime();
158,159c174
< if (d != 0)
< set(this, d, tu);
---
> set(this, d, tu);
169,173c184,185
< //XXX Assuming the time resolution is 1ps.
< if (scale)
< set(this, d * defaultUnit, SC_SEC);
< else
< set(this, d, SC_PS);
---
> double scaler = scale ? defaultUnit : SimClock::Float::Hz;
> set(this, d * scaler, SC_SEC);
178,182c190,191
< //XXX Assuming the time resolution is 1ps.
< if (scale)
< set(this, static_cast<double>(v) * defaultUnit, SC_SEC);
< else
< set(this, static_cast<double>(v), SC_PS);
---
> double scaler = scale ? defaultUnit : SimClock::Float::Hz;
> set(this, static_cast<double>(v) * scaler, SC_SEC);
206,209c215
< double d = to_double();
< //XXX Assuming the time resolution is 1ps.
< double scale = TimeUnitScale[SC_PS] / TimeUnitScale[SC_SEC];
< return d * scale;
---
> return to_double() * SimClock::Float::Hz;
290,292c296,319
< //XXX Assuming the time resolution is 1ps.
< sc_time_unit tu = SC_PS;
< uint64_t scaled = val;
---
> Tick frequency = SimClock::Frequency;
>
> // Shrink the frequency by scaling down the time period, ie converting
> // it from cycles per second to cycles per millisecond, etc.
> sc_time_unit tu = SC_SEC;
> while (tu > 1 && (frequency % 1000 == 0)) {
> tu = (sc_time_unit)((int)tu - 1);
> frequency /= 1000;
> }
>
> // Convert the frequency into a period.
> Tick period;
> if (frequency > 1) {
> tu = (sc_time_unit)((int)tu - 1);
> period = 1000 / frequency;
> } else {
> period = frequency;
> }
>
> // Scale our integer value by the period.
> uint64_t scaled = val * period;
>
> // Shrink the scaled time value by increasing the size of the units
> // it's measured by, avoiding fractional parts.
304a332,333
> if (u)
> attemptToFixTime();
401,403c430,431
< // Normalize d to seconds.
< d *= TimeUnitScale[tu];
< if (d < TimeUnitScale[SC_FS]) {
---
> double seconds = d * TimeUnitScale[tu];
> if (seconds < TimeUnitScale[SC_FS]) {
407,410c435,448
< // Change d from a period to a frequency.
< d = 1 / d;
< // Convert to integer ticks.
< Tick ticks_per_second = static_cast<Tick>(d);
---
>
> if (seconds > defaultUnit) {
> SC_REPORT_WARNING(
> "(W516) default time unit changed to time resolution", "");
> defaultUnit = seconds;
> }
>
> // Get rid of fractional parts of d.
> while (d < 1.0 && tu > SC_FS) {
> d *= 1000;
> tu = (sc_time_unit)(tu - 1);
> }
>
> Tick ticks_per_second = TimeUnitFrequency[tu] / static_cast<Tick>(d);