sc_time.cc (13252:8814e5d87a48) sc_time.cc (13263:bcd6d8140486)
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

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

259{
260 val = static_cast<int64_t>(static_cast<double>(val) / d + 0.5);
261 return *this;
262}
263
264void
265sc_time::print(std::ostream &os) const
266{
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

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

259{
260 val = static_cast<int64_t>(static_cast<double>(val) / d + 0.5);
261 return *this;
262}
263
264void
265sc_time::print(std::ostream &os) const
266{
267 if (val == 0) {
268 os << "0 s";
269 } else {
270 Tick frequency = SimClock::Frequency;
271
272 // Shrink the frequency by scaling down the time period, ie converting
273 // it from cycles per second to cycles per millisecond, etc.
274 sc_time_unit tu = SC_SEC;
275 while (tu > 1 && (frequency % 1000 == 0)) {
276 tu = (sc_time_unit)((int)tu - 1);
277 frequency /= 1000;
278 }
279
280 // Convert the frequency into a period.
281 Tick period;
282 if (frequency > 1) {
283 tu = (sc_time_unit)((int)tu - 1);
284 period = 1000 / frequency;
285 } else {
286 period = frequency;
287 }
288
289 // Scale our integer value by the period.
290 uint64_t scaled = val * period;
291
292 // Shrink the scaled time value by increasing the size of the units
293 // it's measured by, avoiding fractional parts.
294 while (tu < SC_SEC && (scaled % 1000) == 0) {
295 tu = (sc_time_unit)((int)tu + 1);
296 scaled /= 1000;
297 }
298
299 os << scaled << ' ' << sc_gem5::TimeUnitNames[tu];
300 }
267 os << sc_time_tuple(*this).to_string();
301}
302
303sc_time
304sc_time::from_value(sc_dt::uint64 u)
305{
306 if (u)
307 attemptToFixTime();
308 sc_time t;

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

480}
481
482sc_time
483sc_get_default_time_unit()
484{
485 return sc_time(defaultUnit, SC_SEC);
486}
487
268}
269
270sc_time
271sc_time::from_value(sc_dt::uint64 u)
272{
273 if (u)
274 attemptToFixTime();
275 sc_time t;

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

447}
448
449sc_time
450sc_get_default_time_unit()
451{
452 return sc_time(defaultUnit, SC_SEC);
453}
454
488sc_time_tuple::sc_time_tuple(const sc_time &)
455sc_time_tuple::sc_time_tuple(const sc_time &t) :
456 _value(), _unit(SC_SEC), _set(true)
489{
457{
490 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
458 if (!t.value())
459 return;
460
461 Tick frequency = SimClock::Frequency;
462
463 // Shrink the frequency by scaling down the time period, ie converting
464 // it from cycles per second to cycles per millisecond, etc.
465 while (_unit > 1 && (frequency % 1000 == 0)) {
466 _unit = (sc_time_unit)((int)_unit - 1);
467 frequency /= 1000;
468 }
469
470 // Convert the frequency into a period.
471 Tick period;
472 if (frequency > 1) {
473 _unit = (sc_time_unit)((int)_unit - 1);
474 period = 1000 / frequency;
475 } else {
476 period = frequency;
477 }
478
479 // Scale our integer value by the period.
480 _value = t.value() * period;
481
482 // Shrink the scaled time value by increasing the size of the units
483 // it's measured by, avoiding fractional parts.
484 while (_unit < SC_SEC && (_value % 1000) == 0) {
485 _unit = (sc_time_unit)((int)_unit + 1);
486 _value /= 1000;
487 }
491}
492
493bool
494sc_time_tuple::has_value() const
495{
488}
489
490bool
491sc_time_tuple::has_value() const
492{
496 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
497 return false;
493 return _set;
498}
499
494}
495
500sc_dt::uint64
501sc_time_tuple::value() const
502{
503 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
504 return 0;
505}
496sc_dt::uint64 sc_time_tuple::value() const { return _value; }
506
507const char *
508sc_time_tuple::unit_symbol() const
509{
497
498const char *
499sc_time_tuple::unit_symbol() const
500{
510 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
511 return "";
501 return sc_gem5::TimeUnitNames[_unit];
512}
513
502}
503
514double
515sc_time_tuple::to_double() const
516{
517 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
518 return 0.0;
519}
504double sc_time_tuple::to_double() const { return static_cast<double>(_value); }
520
521std::string
522sc_time_tuple::to_string() const
523{
505
506std::string
507sc_time_tuple::to_string() const
508{
524 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
525 return "";
509 std::ostringstream ss;
510 ss << _value << ' ' << unit_symbol();
511 return ss.str();
526}
527
528} // namespace sc_core
512}
513
514} // namespace sc_core