Changeset 52 for sources/src/sc_time.h
- Timestamp:
- Jan 22, 2013, 4:23:22 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/src/sc_time.h
r4 r52 10 10 | | 11 11 \------------------------------------------------------------*/ 12 12 13 #ifndef __SC_TIME_H__ 13 14 #define __SC_TIME_H__ … … 18 19 namespace sc_core { 19 20 21 20 22 // ---------------------------------------------------------------------------- 21 23 // ENUM : sc_time_unit … … 24 26 // ---------------------------------------------------------------------------- 25 27 26 enum sc_time_unit 27 { 28 enum sc_time_unit { 28 29 SC_FS = 0, 29 30 SC_PS, … … 34 35 }; 35 36 36 // 37 37 38 class sc_time; 38 39 extern const sc_time SC_ZERO_TIME; … … 41 42 extern uint64_t nb_cycles; 42 43 43 inline double sc_simulation_time() // in default time units44 { 45 return (double)nb_cycles;44 inline double sc_simulation_time() { 45 // in default time units 46 return (double) nb_cycles; 46 47 } 47 48 48 const sc_time& sc_time_stamp ();49 49 50 // 51 class sc_time 52 { 53 friend const sc_time &sc_time_stamp (); 54 uint64_t time; 55 enum sc_time_unit unit; 56 public: 57 sc_time (double val, sc_time_unit tu); 58 sc_time (const sc_time& = SC_ZERO_TIME); 59 60 sc_time& operator= (const sc_time &); 61 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 ();} 66 const std::string to_string () const; 50 const sc_time & sc_time_stamp(); 51 52 53 54 class sc_time { 55 56 friend const sc_time & sc_time_stamp(); 57 uint64_t time; 58 enum sc_time_unit unit; 59 60 public: 61 sc_time(double val, sc_time_unit tu); 62 sc_time(const sc_time & = SC_ZERO_TIME); 63 64 sc_time & operator= (const sc_time &); 65 66 uint64_t value() const { 67 return time; 68 } 69 70 inline double to_double() const; 71 inline double to_seconds() const; 72 inline operator double() const { 73 return to_double(); 74 } 75 76 const std::string to_string() const; 77 67 78 }; 68 79 69 inline const sc_time& sc_time_stamp () // in default time units 70 { 71 SC_CURRENT_TIME.time = nb_cycles; 72 return SC_CURRENT_TIME;// = sc_time (nb_cycles, SC_NS); 80 81 inline const sc_time & sc_time_stamp() { 82 // in default time units 83 SC_CURRENT_TIME.time = nb_cycles; 84 return SC_CURRENT_TIME; // = sc_time (nb_cycles, SC_NS); 73 85 } 74 86 75 double 76 sc_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; 87 88 double sc_time::to_double() const { 89 double fact = 1; 90 switch (unit) { 91 case SC_FS: 92 fact = 1e-6; 93 break; 94 case SC_PS: 95 fact = 1e-3; 96 break; 97 case SC_NS: 98 fact = 1; 99 break; 100 case SC_US: 101 fact = 1e3; 102 break; 103 case SC_MS: 104 fact = 1e6; 105 break; 106 case SC_SEC: 107 fact = 1e9; 108 break; 109 } 110 return (double) time * fact; 88 111 } 89 112 90 double 91 sc_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; 113 114 double sc_time::to_seconds() const { 115 double fact = 1; 116 switch (unit) { 117 case SC_FS: 118 fact = 1e-15; 119 break; 120 case SC_PS: 121 fact = 1e-12; 122 break; 123 case SC_NS: 124 fact = 1e-9; 125 break; 126 case SC_US: 127 fact = 1e-6; 128 break; 129 case SC_MS: 130 fact = 1e-3; 131 break; 132 case SC_SEC: 133 fact = 1; 134 break; 135 } 136 return (double) time * fact; 103 137 } 138 104 139 105 140 } // end of namespace sc_core 106 141 142 107 143 #endif /* __SC_TIME_H__ */ 144 145 /* 146 # Local Variables: 147 # tab-width: 4; 148 # c-basic-offset: 4; 149 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 150 # indent-tabs-mode: nil; 151 # End: 152 # 153 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 154 */ 155
Note: See TracChangeset
for help on using the changeset viewer.