Deleted Added
sdiff udiff text old ( 13335:299a16ef8e3c ) new ( 13410:a03275d35b40 )
full compact
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

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

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 <cmath>
31#include <cstring>
32#include <sstream>
33#include <vector>
34
35#include "base/types.hh"
36#include "sim/core.hh"
37#include "systemc/core/time.hh"
38#include "systemc/ext/core/messages.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
49void
50set(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu)
51{
52 if (d != 0)
53 fixClockFrequency();
54
55 double scale = sc_gem5::TimeUnitScale[tu] * SimClock::Float::s;
56 // Accellera claims there is a linux bug, and that these next two
57 // lines work around them.
58 volatile double tmp = d * scale + 0.5;
59 *time = sc_time::from_value(static_cast<uint64_t>(tmp));
60}
61
62double defaultUnit = 1.0e-9;
63
64} // anonymous namespace
65
66sc_time::sc_time() : val(0) {}
67
68sc_time::sc_time(double d, sc_time_unit tu)
69{

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

207{
208 os << sc_time_tuple(*this).to_string();
209}
210
211sc_time
212sc_time::from_value(sc_dt::uint64 u)
213{
214 if (u)
215 fixClockFrequency();
216 sc_time t;
217 t.val = u;
218 return t;
219}
220
221sc_time
222sc_time::from_seconds(double d)
223{

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

306 SC_REPORT_ERROR(SC_ID_SET_TIME_RESOLUTION_, "simulation running");
307
308 static bool specified = false;
309 if (specified)
310 SC_REPORT_ERROR(SC_ID_SET_TIME_RESOLUTION_, "already specified");
311
312 // This won't detect the timescale being fixed outside of systemc, but
313 // it's at least some protection.
314 if (clockFrequencyFixed()) {
315 SC_REPORT_ERROR(SC_ID_SET_TIME_RESOLUTION_,
316 "sc_time object(s) constructed");
317 }
318
319 double seconds = d * sc_gem5::TimeUnitScale[tu];
320 if (seconds < sc_gem5::TimeUnitScale[SC_FS])
321 SC_REPORT_ERROR(SC_ID_SET_TIME_RESOLUTION_, "value smaller than 1 fs");
322

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

328 // Get rid of fractional parts of d.
329 while (d < 1.0 && tu > SC_FS) {
330 d *= 1000;
331 tu = (sc_time_unit)(tu - 1);
332 }
333
334 Tick ticks_per_second =
335 sc_gem5::TimeUnitFrequency[tu] / static_cast<Tick>(d);
336 setClockFrequency(ticks_per_second);
337 specified = true;
338}
339
340sc_time
341sc_get_time_resolution()
342{
343 return sc_time::from_value(1);
344}

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

365 SC_REPORT_ERROR(SC_ID_SET_DEFAULT_TIME_UNIT_, "simulation running");
366
367 static bool specified = false;
368 if (specified) {
369 SC_REPORT_ERROR(SC_ID_SET_DEFAULT_TIME_UNIT_, "already specified");
370 }
371 // This won't detect the timescale being fixed outside of systemc, but
372 // it's at least some protection.
373 if (clockFrequencyFixed()) {
374 SC_REPORT_ERROR(SC_ID_SET_DEFAULT_TIME_UNIT_,
375 "sc_time object(s) constructed");
376 }
377
378 // Normalize d to seconds.
379 defaultUnit = d * sc_gem5::TimeUnitScale[tu];
380 specified = true;
381

--- 75 unchanged lines hidden ---