[1] | 1 | /*------------------------------------------------------------\ |
---|
| 2 | | | |
---|
| 3 | | Tool : systemcass | |
---|
| 4 | | | |
---|
| 5 | | File : sc_time.h | |
---|
| 6 | | | |
---|
| 7 | | Author : Buchmann Richard | |
---|
| 8 | | | |
---|
| 9 | | Date : 09_07_2004 | |
---|
| 10 | | | |
---|
| 11 | \------------------------------------------------------------*/ |
---|
[52] | 12 | |
---|
[1] | 13 | #ifndef __SC_TIME_H__ |
---|
| 14 | #define __SC_TIME_H__ |
---|
| 15 | |
---|
| 16 | #include <string> |
---|
[59] | 17 | //#include <stdint.h> |
---|
[1] | 18 | |
---|
[59] | 19 | #include "sc_nbdefs.h" |
---|
| 20 | |
---|
[1] | 21 | namespace sc_core { |
---|
| 22 | |
---|
[52] | 23 | |
---|
[1] | 24 | // ---------------------------------------------------------------------------- |
---|
| 25 | // ENUM : sc_time_unit |
---|
| 26 | // |
---|
| 27 | // Enumeration of time units. |
---|
| 28 | // ---------------------------------------------------------------------------- |
---|
| 29 | |
---|
[52] | 30 | enum sc_time_unit { |
---|
[1] | 31 | SC_FS = 0, |
---|
| 32 | SC_PS, |
---|
| 33 | SC_NS, |
---|
| 34 | SC_US, |
---|
| 35 | SC_MS, |
---|
| 36 | SC_SEC |
---|
| 37 | }; |
---|
| 38 | |
---|
[52] | 39 | |
---|
[1] | 40 | class sc_time; |
---|
| 41 | extern const sc_time SC_ZERO_TIME; |
---|
| 42 | extern sc_time SC_CURRENT_TIME; |
---|
| 43 | |
---|
[59] | 44 | extern uint64 nb_cycles; |
---|
[60] | 45 | #pragma omp threadprivate(nb_cycles) |
---|
[1] | 46 | |
---|
[52] | 47 | inline double sc_simulation_time() { |
---|
| 48 | // in default time units |
---|
| 49 | return (double) nb_cycles; |
---|
[1] | 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
[52] | 53 | const sc_time & sc_time_stamp(); |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | class sc_time { |
---|
| 58 | |
---|
| 59 | friend const sc_time & sc_time_stamp(); |
---|
[59] | 60 | uint64 time; |
---|
[52] | 61 | enum sc_time_unit unit; |
---|
| 62 | |
---|
| 63 | public: |
---|
| 64 | sc_time(double val, sc_time_unit tu); |
---|
| 65 | sc_time(const sc_time & = SC_ZERO_TIME); |
---|
| 66 | |
---|
| 67 | sc_time & operator= (const sc_time &); |
---|
| 68 | |
---|
[59] | 69 | uint64 value() const { |
---|
[52] | 70 | return time; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | inline double to_double() const; |
---|
| 74 | inline double to_seconds() const; |
---|
| 75 | inline operator double() const { |
---|
| 76 | return to_double(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | const std::string to_string() const; |
---|
| 80 | |
---|
[1] | 81 | }; |
---|
| 82 | |
---|
[52] | 83 | |
---|
| 84 | inline const sc_time & sc_time_stamp() { |
---|
| 85 | // in default time units |
---|
| 86 | SC_CURRENT_TIME.time = nb_cycles; |
---|
| 87 | return SC_CURRENT_TIME; // = sc_time (nb_cycles, SC_NS); |
---|
[1] | 88 | } |
---|
| 89 | |
---|
[52] | 90 | |
---|
| 91 | double sc_time::to_double() const { |
---|
| 92 | double fact = 1; |
---|
| 93 | switch (unit) { |
---|
| 94 | case SC_FS: |
---|
| 95 | fact = 1e-6; |
---|
| 96 | break; |
---|
| 97 | case SC_PS: |
---|
| 98 | fact = 1e-3; |
---|
| 99 | break; |
---|
| 100 | case SC_NS: |
---|
| 101 | fact = 1; |
---|
| 102 | break; |
---|
| 103 | case SC_US: |
---|
| 104 | fact = 1e3; |
---|
| 105 | break; |
---|
| 106 | case SC_MS: |
---|
| 107 | fact = 1e6; |
---|
| 108 | break; |
---|
| 109 | case SC_SEC: |
---|
| 110 | fact = 1e9; |
---|
| 111 | break; |
---|
| 112 | } |
---|
| 113 | return (double) time * fact; |
---|
[4] | 114 | } |
---|
| 115 | |
---|
[52] | 116 | |
---|
| 117 | double sc_time::to_seconds() const { |
---|
| 118 | double fact = 1; |
---|
| 119 | switch (unit) { |
---|
| 120 | case SC_FS: |
---|
| 121 | fact = 1e-15; |
---|
| 122 | break; |
---|
| 123 | case SC_PS: |
---|
| 124 | fact = 1e-12; |
---|
| 125 | break; |
---|
| 126 | case SC_NS: |
---|
| 127 | fact = 1e-9; |
---|
| 128 | break; |
---|
| 129 | case SC_US: |
---|
| 130 | fact = 1e-6; |
---|
| 131 | break; |
---|
| 132 | case SC_MS: |
---|
| 133 | fact = 1e-3; |
---|
| 134 | break; |
---|
| 135 | case SC_SEC: |
---|
| 136 | fact = 1; |
---|
| 137 | break; |
---|
| 138 | } |
---|
| 139 | return (double) time * fact; |
---|
[4] | 140 | } |
---|
| 141 | |
---|
[52] | 142 | |
---|
[1] | 143 | } // end of namespace sc_core |
---|
| 144 | |
---|
[52] | 145 | |
---|
[1] | 146 | #endif /* __SC_TIME_H__ */ |
---|
[52] | 147 | |
---|
| 148 | /* |
---|
| 149 | # Local Variables: |
---|
| 150 | # tab-width: 4; |
---|
| 151 | # c-basic-offset: 4; |
---|
| 152 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 153 | # indent-tabs-mode: nil; |
---|
| 154 | # End: |
---|
| 155 | # |
---|
| 156 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 157 | */ |
---|
| 158 | |
---|