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 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 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 "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 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 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 "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} 81double 82sc_time::to_seconds() const 83{ 84 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 85 return 0.0; 86} 87 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} 108double 109sc_time::to_seconds() const 110{ 111 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 112 return 0.0; 113} 114 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} 184 185sc_time 186sc_time::from_string(const char *str) 187{ 188 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 189 return sc_time(); 190} 191 192const sc_time 193operator + (const sc_time &, const sc_time &) 194{ 195 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 196 return sc_time(); 197} 198 199const sc_time 200operator - (const sc_time &, const sc_time &) 201{ 202 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 203 return sc_time(); 204} 205 206const sc_time 207operator * (const sc_time &, double) 208{ 209 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 210 return sc_time(); 211} 212 213const sc_time 214operator * (double, const sc_time &) 215{ 216 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 217 return sc_time(); 218} 219 220const sc_time 221operator / (const sc_time &, double) 222{ 223 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 224 return sc_time(); 225} 226 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} 218 219sc_time 220sc_time::from_string(const char *str) 221{ 222 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 223 return sc_time(); 224} 225 226const sc_time 227operator + (const sc_time &, const sc_time &) 228{ 229 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 230 return sc_time(); 231} 232 233const sc_time 234operator - (const sc_time &, const sc_time &) 235{ 236 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 237 return sc_time(); 238} 239 240const sc_time 241operator * (const sc_time &, double) 242{ 243 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 244 return sc_time(); 245} 246 247const sc_time 248operator * (double, const sc_time &) 249{ 250 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 251 return sc_time(); 252} 253 254const sc_time 255operator / (const sc_time &, double) 256{ 257 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 258 return sc_time(); 259} 260 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{ 246 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 247} 248 249sc_time 250sc_get_time_resolution() 251{ 252 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 253 return sc_time(); 254} 255 256const sc_time & 257sc_max_time() 258{ 259 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 260 return *(const sc_time *)nullptr; 261} 262 263void 264sc_set_default_time_unit(double, sc_time_unit) 265{ 266 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 267} 268 269sc_time 270sc_get_default_time_unit() 271{ 272 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 273 return *(sc_time *)nullptr; 274} 275 276sc_time_tuple::sc_time_tuple(const sc_time &) 277{ 278 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 279} 280 281bool 282sc_time_tuple::has_value() const 283{ 284 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 285 return false; 286} 287 288sc_dt::uint64 289sc_time_tuple::value() const 290{ 291 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 292 return 0; 293} 294 295const char * 296sc_time_tuple::unit_symbol() const 297{ 298 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 299 return ""; 300} 301 302double 303sc_time_tuple::to_double() const 304{ 305 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 306 return 0.0; 307} 308 309std::string 310sc_time_tuple::to_string() const 311{ 312 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 313 return ""; 314} 315 316} // namespace sc_core
| 272 return os; 273} 274 275const sc_time SC_ZERO_TIME; 276 277void 278sc_set_time_resolution(double, sc_time_unit) 279{ 280 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 281} 282 283sc_time 284sc_get_time_resolution() 285{ 286 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 287 return sc_time(); 288} 289 290const sc_time & 291sc_max_time() 292{ 293 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 294 return *(const sc_time *)nullptr; 295} 296 297void 298sc_set_default_time_unit(double, sc_time_unit) 299{ 300 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 301} 302 303sc_time 304sc_get_default_time_unit() 305{ 306 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 307 return *(sc_time *)nullptr; 308} 309 310sc_time_tuple::sc_time_tuple(const sc_time &) 311{ 312 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 313} 314 315bool 316sc_time_tuple::has_value() const 317{ 318 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 319 return false; 320} 321 322sc_dt::uint64 323sc_time_tuple::value() const 324{ 325 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 326 return 0; 327} 328 329const char * 330sc_time_tuple::unit_symbol() const 331{ 332 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 333 return ""; 334} 335 336double 337sc_time_tuple::to_double() const 338{ 339 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 340 return 0.0; 341} 342 343std::string 344sc_time_tuple::to_string() const 345{ 346 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 347 return ""; 348} 349 350} // namespace sc_core
|