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 --- 19 unchanged lines hidden (view full) --- 28 */ 29 30#include "base/logging.hh" 31#include "systemc/ext/core/sc_time.hh" 32 33namespace sc_core 34{ 35 |
36namespace |
37{ |
38 |
39const char *TimeUnitNames[] = { 40 [SC_FS] = "fs", 41 [SC_PS] = "ps", 42 [SC_NS] = "ns", 43 [SC_US] = "us", 44 [SC_MS] = "ms", 45 [SC_SEC] = "s" 46}; 47 48double TimeUnitScale[] = { 49 [SC_FS] = 1.0e-15, 50 [SC_PS] = 1.0e-12, 51 [SC_NS] = 1.0e-9, 52 [SC_US] = 1.0e-6, 53 [SC_MS] = 1.0e-3, 54 [SC_SEC] = 1.0 55}; 56 57} // anonymous namespace 58 59sc_time::sc_time() : val(0) {} 60 61sc_time::sc_time(double d, sc_time_unit tu) |
62{ |
63 val = 0; 64 if (d != 0) { 65 //XXX Assuming the time resolution is 1ps. 66 double scale = TimeUnitScale[tu] / TimeUnitScale[SC_PS]; 67 // Accellera claims there is a linux bug, and that these next two 68 // lines work around them. 69 volatile double tmp = d * scale + 0.5; 70 val = static_cast<uint64_t>(tmp); 71 } |
72} 73 |
74sc_time::sc_time(const sc_time &t) |
75{ |
76 val = t.val; |
77} 78 79sc_time::sc_time(double, bool) 80{ 81 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 82} 83 84sc_time::sc_time(sc_dt::uint64, bool) 85{ 86 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 87} 88 89sc_time & |
90sc_time::operator = (const sc_time &t) |
91{ |
92 val = t.val; |
93 return *this; 94} 95 96sc_dt::uint64 97sc_time::value() const 98{ |
99 return val; |
100} 101 102double 103sc_time::to_double() const 104{ 105 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 106 return 0.0; 107} --- 7 unchanged lines hidden (view full) --- 115const std::string 116sc_time::to_string() const 117{ 118 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 119 return ""; 120} 121 122bool |
123sc_time::operator == (const sc_time &t) const |
124{ |
125 return val == t.val; |
126} 127 128bool |
129sc_time::operator != (const sc_time &t) const |
130{ |
131 return val != t.val; |
132} 133 134bool |
135sc_time::operator < (const sc_time &t) const |
136{ |
137 return val < t.val; |
138} 139 140bool |
141sc_time::operator <= (const sc_time &t) const |
142{ |
143 return val <= t.val; |
144} 145 146bool |
147sc_time::operator > (const sc_time &t) const |
148{ |
149 return val > t.val; |
150} 151 152bool |
153sc_time::operator >= (const sc_time &t) const |
154{ |
155 return val >= t.val; |
156} 157 158sc_time & |
159sc_time::operator += (const sc_time &t) |
160{ |
161 val += t.val; |
162 return *this; 163} 164 165sc_time & |
166sc_time::operator -= (const sc_time &t) |
167{ |
168 val -= t.val; |
169 return *this; 170} 171 172sc_time & 173sc_time::operator *= (double) 174{ 175 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 176 return *this; 177} 178 179sc_time & 180sc_time::operator /= (double) 181{ 182 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 183 return *this; 184} 185 186void |
187sc_time::print(std::ostream &os) const |
188{ |
189 if (val == 0) { 190 os << "0 s"; 191 } else { 192 //XXX Assuming the time resolution is 1ps. 193 sc_time_unit tu = SC_PS; 194 uint64_t scaled = val; 195 while (tu < SC_SEC && (scaled % 1000) == 0) { 196 tu = (sc_time_unit)((int)tu + 1); 197 scaled /= 1000; 198 } 199 200 os << scaled << ' ' << TimeUnitNames[tu]; 201 } |
202} 203 204sc_time |
205sc_time::from_value(sc_dt::uint64 u) |
206{ |
207 sc_time t; 208 t.val = u; 209 return t; |
210} 211 212sc_time 213sc_time::from_seconds(double) 214{ 215 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 216 return sc_time(); 217} --- 43 unchanged lines hidden (view full) --- 261double 262operator / (const sc_time &, const sc_time &) 263{ 264 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 265 return 0.0; 266} 267 268std::ostream & |
269operator << (std::ostream &os, const sc_time &t) |
270{ |
271 t.print(os); |
272 return os; 273} 274 275const sc_time SC_ZERO_TIME; 276 277void 278sc_set_time_resolution(double, sc_time_unit) 279{ --- 71 unchanged lines hidden --- |