Changeset 4 for sources/src/sc_time.h


Ignore:
Timestamp:
Mar 10, 2008, 12:37:25 PM (16 years ago)
Author:
nipo
Message:

Towards SystemC-2.2 LRM:

  • Implement sc_time with units
  • Have a systemc header with no namespace pollution
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sources/src/sc_time.h

    r1 r4  
    1313#define __SC_TIME_H__
    1414
    15 #include <iostream>
    1615#include <string>
    17 #include "sc_nbdefs.h"
    18 #include "internal_ext.h"
     16#include <stdint.h>
    1917
    2018namespace sc_core {
     
    4139extern sc_time SC_CURRENT_TIME;
    4240
    43 extern uint64 nb_cycles;
     41extern uint64_t nb_cycles;
    4442
    4543inline double sc_simulation_time()   // in default time units
     
    5452{
    5553  friend const sc_time &sc_time_stamp ();
    56   long long int time;
     54  uint64_t time;
     55  enum sc_time_unit unit;
    5756public:
    58 //  sc_time (); LRM 2.1
    5957  sc_time (double val, sc_time_unit tu);
    6058  sc_time (const sc_time& = SC_ZERO_TIME);
     
    6260  sc_time& operator= (const sc_time &);
    6361 
    64   /*sc_dt::*/uint64 value     () const { return (/*sc_dt::*/uint64) time;}
    65   double        to_double () const { return time * 1000;}
    66   double        to_seconds() const { return time / (double)1000000000;};
    67   operator      double    () const { return to_double ();};
     62  uint64_t      value     () const { return time;}
     63  inline double        to_double () const;
     64  inline double        to_seconds() const;
     65  inline operator      double    () const { return to_double ();}
    6866  const std::string to_string () const;
    6967};
     
    7573}
    7674
     75double
     76sc_time::to_double () const
     77{
     78        double fact = 1;
     79        switch(unit) {
     80        case SC_FS: fact = 1e-6; break;
     81        case SC_PS: fact = 1e-3; break;
     82        case SC_NS: fact = 1; break;
     83        case SC_US: fact = 1e3; break;
     84        case SC_MS: fact = 1e6; break;
     85        case SC_SEC: fact = 1e9; break;
     86        }
     87        return (double)time * fact;
     88}
     89
     90double
     91sc_time::to_seconds() const
     92{
     93        double fact = 1;
     94        switch(unit) {
     95        case SC_FS: fact = 1e-15; break;
     96        case SC_PS: fact = 1e-12; break;
     97        case SC_NS: fact = 1e-9; break;
     98        case SC_US: fact = 1e-6; break;
     99        case SC_MS: fact = 1e-3; break;
     100        case SC_SEC: fact = 1; break;
     101        }
     102        return (double)time * fact;
     103}
     104
    77105} // end of namespace sc_core
    78106
    79 using sc_core::sc_simulation_time;
    80 using sc_core::sc_time;
    81 using sc_core::sc_time_stamp;
    82 
    83107#endif /* __SC_TIME_H__ */
Note: See TracChangeset for help on using the changeset viewer.