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 --- 14 unchanged lines hidden (view full) --- 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 "base/logging.hh" |
31#include "python/pybind11/pybind.hh" |
32#include "systemc/ext/core/sc_time.hh" 33 34namespace sc_core 35{ 36 37namespace 38{ 39 --- 10 unchanged lines hidden (view full) --- 50 [SC_FS] = 1.0e-15, 51 [SC_PS] = 1.0e-12, 52 [SC_NS] = 1.0e-9, 53 [SC_US] = 1.0e-6, 54 [SC_MS] = 1.0e-3, 55 [SC_SEC] = 1.0 56}; 57 |
58void 59fixTimeResolution() 60{ 61 static bool fixed = false; 62 if (fixed) 63 return; 64 65 auto ticks = pybind11::module::import("m5.ticks"); 66 auto fix_global_frequency = ticks.attr("fixGlobalFrequency"); 67 fix_global_frequency(); 68 fixed = true; 69} 70 |
71} // anonymous namespace 72 73sc_time::sc_time() : val(0) {} 74 75sc_time::sc_time(double d, sc_time_unit tu) 76{ 77 val = 0; 78 if (d != 0) { |
79 fixTimeResolution(); |
80 //XXX Assuming the time resolution is 1ps. 81 double scale = TimeUnitScale[tu] / TimeUnitScale[SC_PS]; 82 // Accellera claims there is a linux bug, and that these next two 83 // lines work around them. 84 volatile double tmp = d * scale + 0.5; 85 val = static_cast<uint64_t>(tmp); 86 } 87} --- 278 unchanged lines hidden --- |