source: sources/src/sc_time.h @ 65

Last change on this file since 65 was 63, checked in by bouyer, 5 years ago

Remplace USE_OPENMP with _OPENMP, the latter is automagically defined
by the compiler.

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