sc_time.cc (12927:6be191c20575) | sc_time.cc (12983:fb1f462ae89e) |
---|---|
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 | 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 |
36sc_time::sc_time() | 36namespace |
37{ | 37{ |
38 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 39} | |
40 | 38 |
41sc_time::sc_time(double, sc_time_unit) | 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) |
42{ | 62{ |
43 warn("%s not implemented.\n", __PRETTY_FUNCTION__); | 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 } |
44} 45 | 72} 73 |
46sc_time::sc_time(const sc_time &) | 74sc_time::sc_time(const sc_time &t) |
47{ | 75{ |
48 warn("%s not implemented.\n", __PRETTY_FUNCTION__); | 76 val = t.val; |
49} 50 51sc_time::sc_time(double, bool) 52{ 53 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 54} 55 56sc_time::sc_time(sc_dt::uint64, bool) 57{ 58 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 59} 60 61sc_time & | 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 & |
62sc_time::operator = (const sc_time &) | 90sc_time::operator = (const sc_time &t) |
63{ | 91{ |
64 warn("%s not implemented.\n", __PRETTY_FUNCTION__); | 92 val = t.val; |
65 return *this; 66} 67 68sc_dt::uint64 69sc_time::value() const 70{ | 93 return *this; 94} 95 96sc_dt::uint64 97sc_time::value() const 98{ |
71 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 72 return 0; | 99 return val; |
73} 74 75double 76sc_time::to_double() const 77{ 78 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 79 return 0.0; 80} --- 7 unchanged lines hidden (view full) --- 88const std::string 89sc_time::to_string() const 90{ 91 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 92 return ""; 93} 94 95bool | 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 |
96sc_time::operator == (const sc_time &) const | 123sc_time::operator == (const sc_time &t) const |
97{ | 124{ |
98 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 99 return true; | 125 return val == t.val; |
100} 101 102bool | 126} 127 128bool |
103sc_time::operator != (const sc_time &) const | 129sc_time::operator != (const sc_time &t) const |
104{ | 130{ |
105 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 106 return false; | 131 return val != t.val; |
107} 108 109bool | 132} 133 134bool |
110sc_time::operator < (const sc_time &) const | 135sc_time::operator < (const sc_time &t) const |
111{ | 136{ |
112 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 113 return false; | 137 return val < t.val; |
114} 115 116bool | 138} 139 140bool |
117sc_time::operator <= (const sc_time &) const | 141sc_time::operator <= (const sc_time &t) const |
118{ | 142{ |
119 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 120 return true; | 143 return val <= t.val; |
121} 122 123bool | 144} 145 146bool |
124sc_time::operator > (const sc_time &) const | 147sc_time::operator > (const sc_time &t) const |
125{ | 148{ |
126 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 127 return false; | 149 return val > t.val; |
128} 129 130bool | 150} 151 152bool |
131sc_time::operator >= (const sc_time &) const | 153sc_time::operator >= (const sc_time &t) const |
132{ | 154{ |
133 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 134 return true; | 155 return val >= t.val; |
135} 136 137sc_time & | 156} 157 158sc_time & |
138sc_time::operator += (const sc_time &) | 159sc_time::operator += (const sc_time &t) |
139{ | 160{ |
140 warn("%s not implemented.\n", __PRETTY_FUNCTION__); | 161 val += t.val; |
141 return *this; 142} 143 144sc_time & | 162 return *this; 163} 164 165sc_time & |
145sc_time::operator -= (const sc_time &) | 166sc_time::operator -= (const sc_time &t) |
146{ | 167{ |
147 warn("%s not implemented.\n", __PRETTY_FUNCTION__); | 168 val -= t.val; |
148 return *this; 149} 150 151sc_time & 152sc_time::operator *= (double) 153{ 154 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 155 return *this; 156} 157 158sc_time & 159sc_time::operator /= (double) 160{ 161 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 162 return *this; 163} 164 165void | 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 |
166sc_time::print(std::ostream &) const | 187sc_time::print(std::ostream &os) const |
167{ | 188{ |
168 warn("%s not implemented.\n", __PRETTY_FUNCTION__); | 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 } |
169} 170 171sc_time | 202} 203 204sc_time |
172sc_time::from_value(sc_dt::uint64) | 205sc_time::from_value(sc_dt::uint64 u) |
173{ | 206{ |
174 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 175 return sc_time(); | 207 sc_time t; 208 t.val = u; 209 return t; |
176} 177 178sc_time 179sc_time::from_seconds(double) 180{ 181 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 182 return sc_time(); 183} --- 43 unchanged lines hidden (view full) --- 227double 228operator / (const sc_time &, const sc_time &) 229{ 230 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 231 return 0.0; 232} 233 234std::ostream & | 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 & |
235operator << (std::ostream &os, const sc_time &) | 269operator << (std::ostream &os, const sc_time &t) |
236{ | 270{ |
237 warn("%s not implemented.\n", __PRETTY_FUNCTION__); | 271 t.print(os); |
238 return os; 239} 240 241const sc_time SC_ZERO_TIME; 242 243void 244sc_set_time_resolution(double, sc_time_unit) 245{ --- 71 unchanged lines hidden --- | 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 --- |