source: sources/src/gen_code.h @ 63

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

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

File size: 7.0 KB
Line 
1/*------------------------------------------------------------\
2  |                                                             |
3  | Tool    :                  systemcass                       |
4  |                                                             |
5  | File    :                 gen_code.h                        |
6  |                                                             |
7  | Author  :                 Taktak Sami                       |
8  |                           Buchmann Richard                  |
9  |                                                             |
10  | Date    :                   09_07_2004                      |
11  |                                                             |
12  \------------------------------------------------------------*/
13#ifndef __GEN_CODE_H__
14#define __GEN_CODE_H__
15
16#include "internal.h"
17#include "global_functions.h"
18#include "graph.h"
19#include "sc_port.h"
20#include "sc_trace.h"
21#include "process_dependency.h"
22
23#ifdef _OPENMP
24    #include <omp.h>
25#endif
26
27//-------------------------------------------------------------------
28#ifdef __GNUC__
29#define INLINE __attribute__((always_inline))
30#else
31#define INLINE
32#endif
33
34//-------------------------------------------------------------------
35namespace sc_core {
36
37extern strong_component_list_t * strong;
38
39/* compile scheduling code to link dynamically later */
40extern void compile_code(const char * base_name, const char * cflags2 = "");
41
42/* generate a scheduling code */
43extern void  gen_scheduling_code_for_quasistatic_func(
44      method_process_list_t   &transition_list,
45      method_process_list_t   &moore_list,
46      strong_component_list_t *mealy_list);
47
48extern void  gen_scheduling_code_for_static_func(
49      method_process_list_t   &transition_list,
50      method_process_list_t   &moore_list,
51      ProcessDependencyList   &mealy_list);
52
53extern char * gen_scheduling_code_for_dynamic_link(
54      method_process_list_t   &transition_list,
55      method_process_list_t   &moore_list,
56      ProcessDependencyList   &mealy_list);
57
58extern char * gen_scheduling_code_for_dynamic_link(
59      method_process_list_t   &transition_list,
60      method_process_list_t   &moore_list,
61      strong_component_list_t *strongcomponents);
62
63/* function when any dynamic link is impossible */
64#ifdef __cplusplus
65#define EXTERN extern "C"
66#else
67#define EXTERN extern
68#endif
69
70EXTERN void static_simulate_1_cycle();
71EXTERN void static_mealy_generation();
72EXTERN void quasistatic_simulate_1_cycle();
73EXTERN void quasistatic_mealy_generation();
74
75/* internal functions */
76inline void switch_to_moore() INLINE;
77inline void internal_sc_cycle2() INLINE;
78inline void internal_sc_cycle1(int number_of_cycles) INLINE;
79inline void internal_sc_cycle0(double duration)  INLINE;
80
81/* ***************** */
82/* inlined functions */
83/* ***************** */
84
85inline void internal_sc_cycle2() {
86#ifdef DUMP_STAGE
87#pragma omp master
88    {
89        std::cerr << "begin of cycle #" << sc_simulation_time() << "\n";
90    }
91#endif
92
93        func_simulate_1_cycle();
94
95        ++nb_cycles;
96#ifdef DUMP_STAGE
97#pragma omp master
98    {
99        std::cerr << "end of cycle\n";
100    }
101#endif
102}
103
104inline void internal_sc_cycle1(int number_of_cycles) { 
105    extern unsigned long long busy_wait_f0, busy_wait_f1, busy_wait_up, busy_wait_ml;
106    extern unsigned long long last_wait_f0, last_wait_f1, last_wait_up, last_wait_ml;
107    extern unsigned int nb_func[2];
108    extern unsigned int expected_globaltime;
109    extern volatile unsigned int globaltime;
110#ifdef _OPENMP
111#pragma omp threadprivate (busy_wait_f0, busy_wait_f1, busy_wait_up, busy_wait_ml, nb_func)
112#pragma omp threadprivate (last_wait_f0, last_wait_f1, last_wait_up, last_wait_ml)
113#pragma omp threadprivate (expected_globaltime)
114#pragma omp shared (globaltime)
115#endif
116    extern unsigned int num_omp_threads;
117
118
119#ifdef _OPENMP
120#pragma omp parallel
121#endif
122    {
123        int cyclecount = number_of_cycles;
124        busy_wait_f0 = busy_wait_f1 = busy_wait_up = busy_wait_ml = total_assig = 0;
125        last_wait_f0 = last_wait_f1 = last_wait_up = last_wait_ml = 0;
126
127        expected_globaltime = 0;
128#ifdef _OPENMP
129#pragma omp master
130#endif
131        {
132            globaltime = 0;
133#ifdef _OPENMP
134            num_omp_threads = omp_get_num_threads();
135#else
136            num_omp_threads = 1;
137#endif
138        }
139
140#ifdef _OPENMP
141#pragma omp barrier
142#endif
143        while (!(have_to_stop || cyclecount == 0)) {
144        //while (!(have_to_stop || number_of_cycles == 0)) {
145#ifdef _OPENMP
146#pragma omp master
147#endif
148            {
149                trace_all(false);
150            }
151            internal_sc_cycle2();
152#ifdef _OPENMP
153#pragma omp master
154#endif
155            {
156                trace_all(true);
157            }
158            cyclecount = (number_of_cycles < 0) ? number_of_cycles : cyclecount - 1;
159            // number_of_cycles = (number_of_cycles < 0) ? number_of_cycles : number_of_cycles - 1;
160        }
161#ifdef _OPENMP
162#pragma omp barrier
163#endif
164#if 0
165#ifdef _OPENMP
166#pragma omp critical
167        {
168            std::cerr << "Thread " << omp_get_thread_num() << " busy_wait " <<
169                busy_wait_f0 << " " << busy_wait_up << " " <<
170                busy_wait_f1 << " " << busy_wait_ml << std::endl;
171        }
172#pragma omp critical
173        {
174            std::cerr << "Thread " << omp_get_thread_num() << " last_wait " <<
175                last_wait_f0 << " " << last_wait_up << " " <<
176                last_wait_f1 << " " << last_wait_ml << std::endl;
177        }
178#pragma omp critical
179        {
180            std::cerr << "Thread " << omp_get_thread_num() << " nfuncs "
181                << nb_func[0] << " " << nb_func[1] << " total_assig " <<
182                total_assig << std::endl;
183        }
184#endif
185#endif
186    }
187}
188
189
190inline void internal_sc_cycle0(double duration) {
191    // in default time units
192
193#ifdef CONFIG_DEBUG
194    // Check dynamic linkage
195    if ((func_combinationals == NULL) || (func_simulate_1_cycle == NULL)) {
196        std::cerr << "Main execution loop is not yet generated.\n";
197    }
198
199    if (duration < -1) {
200        std::cerr << "Invalid duration.\n";
201    }
202#endif
203
204    if (is_posted_write()) {
205        // update posted value to external signals             
206#ifdef _OPENMP
207#pragma omp parallel
208#endif
209        update();
210        func_combinationals();
211    }
212
213    internal_sc_cycle1((int) duration);
214
215    // don't need to do func_combinationals since 'unstable' flag is now false
216    if (is_posted_write()) {
217#ifdef _OPENMP
218#pragma omp parallel
219#endif
220        update();
221        func_combinationals();
222    }
223}
224
225//-------------------------------------------------------------------
226
227// sc_cycle is for internal purpose only.
228// sc_cycle is deprecated since 1.0
229//extern void sc_cycle( double duration );  // in default time units
230
231/* time_unit is worth a cycle in every cases */
232//extern void sc_cycle( double duration, sc_time_unit time_unit );
233
234} // end of sc_core namespace
235
236#endif /* __GEN_CODE_H__ */
237
238/*
239# Local Variables:
240# tab-width: 4;
241# c-basic-offset: 4;
242# c-file-offsets:((innamespace . 0)(inline-open . 0));
243# indent-tabs-mode: nil;
244# End:
245#
246# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
247*/
248
Note: See TracBrowser for help on using the repository browser.