source: sources/src/sc_time.h @ 60

Last change on this file since 60 was 60, checked in by meunier, 7 years ago
  • Intégration des modifications de Clément, qui a intégré la version parallélisée de systemcass faite par Manuel.
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#pragma omp threadprivate(nb_cycles)
46
47inline double sc_simulation_time() {
48    // in default time units
49    return (double) nb_cycles;
50}
51
52
53const sc_time & sc_time_stamp();
54
55
56
57class sc_time {
58
59    friend const sc_time & sc_time_stamp();
60    uint64 time;
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
69    uint64 value() const {
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
81};
82
83
84inline 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);
88}
89
90
91double 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;
114}
115
116
117double 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;
140}
141
142
143} // end of namespace sc_core
144
145
146#endif /* __SC_TIME_H__ */
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
Note: See TracBrowser for help on using the repository browser.