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 os << sc_time_tuple(*this).to_string(); |
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 |
455sc_time_tuple::sc_time_tuple(const sc_time &t) : 456 _value(), _unit(SC_SEC), _set(true) |
457{ |
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 } |
488} 489 490bool 491sc_time_tuple::has_value() const 492{ |
493 return _set; |
494} 495 |
496sc_dt::uint64 sc_time_tuple::value() const { return _value; } |
497 498const char * 499sc_time_tuple::unit_symbol() const 500{ |
501 return sc_gem5::TimeUnitNames[_unit]; |
502} 503 |
504double sc_time_tuple::to_double() const { return static_cast<double>(_value); } |
505 506std::string 507sc_time_tuple::to_string() const 508{ |
509 std::ostringstream ss; 510 ss << _value << ' ' << unit_symbol(); 511 return ss.str(); |
512} 513 514} // namespace sc_core |