source: sources/src/sc_time.h @ 59

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