source: sources/src/gen_code.h @ 61

Last change on this file since 61 was 61, checked in by meunier, 7 years ago
  • Fixing include of openmp (still not functional as regarding of the compilation)
File size: 6.8 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 USE_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#pragma omp threadprivate (busy_wait_f0, busy_wait_f1, busy_wait_up, busy_wait_ml, nb_func)
109#pragma omp threadprivate (last_wait_f0, last_wait_f1, last_wait_up, last_wait_ml)
110    extern unsigned int expected_globaltime;
111    extern volatile unsigned int globaltime;
112#pragma omp shared (globaltime)
113#pragma omp threadprivate (expected_globaltime)
114
115    extern unsigned int num_omp_threads;
116
117
118#pragma omp parallel
119    {
120//        int cyclecount = number_of_cycles;
121        busy_wait_f0 = busy_wait_f1 = busy_wait_up = busy_wait_ml = total_assig = 0;
122        last_wait_f0 = last_wait_f1 = last_wait_up = last_wait_ml = 0;
123
124        expected_globaltime = 0;
125#pragma omp master
126        {
127            globaltime = 0;
128#ifdef _OPENMP
129            num_omp_threads = omp_get_num_threads();
130#else
131            num_omp_threads = 1;
132#endif
133        }
134
135#pragma omp barrier
136        // while (!((have_to_stop) | (cyclecount == 0))) {
137        while (!((have_to_stop) || (number_of_cycles == 0))) {
138#pragma omp master
139            {
140                trace_all(false);
141            }
142            internal_sc_cycle2();
143#pragma omp master
144            {
145                trace_all(true);
146            }
147            // cyclecount = (number_of_cycles < 0) ? number_of_cycles : cyclecount - 1;
148            number_of_cycles = (number_of_cycles < 0) ? number_of_cycles : number_of_cycles - 1;
149        }
150#pragma omp barrier
151#if 0
152#ifdef _OPENMP
153#pragma omp critical
154        {
155            std::cerr << "Thread " << omp_get_thread_num() << " busy_wait " <<
156                busy_wait_f0 << " " << busy_wait_up << " " <<
157                busy_wait_f1 << " " << busy_wait_ml << std::endl;
158        }
159#pragma omp critical
160        {
161            std::cerr << "Thread " << omp_get_thread_num() << " last_wait " <<
162                last_wait_f0 << " " << last_wait_up << " " <<
163                last_wait_f1 << " " << last_wait_ml << std::endl;
164        }
165#pragma omp critical
166        {
167            std::cerr << "Thread " << omp_get_thread_num() << " nfuncs "
168                << nb_func[0] << " " << nb_func[1] << " total_assig " <<
169                total_assig << std::endl;
170        }
171#endif
172#endif
173    }
174}
175
176
177inline void internal_sc_cycle0(double duration) {
178    // in default time units
179
180#ifdef CONFIG_DEBUG
181    // Check dynamic linkage
182    if ((func_combinationals == NULL) || (func_simulate_1_cycle == NULL)) {
183        std::cerr << "Main execution loop is not yet generated.\n";
184    }
185
186    if (duration < -1) {
187        std::cerr << "Invalid duration.\n";
188    }
189#endif
190
191    if (is_posted_write()) {
192        // update posted value to external signals             
193#pragma omp parallel
194        update();
195        func_combinationals();
196    }
197
198    internal_sc_cycle1((int) duration);
199
200    // don't need to do func_combinationals since 'unstable' flag is now false
201    if (is_posted_write()) {
202#pragma omp parallel
203        update();
204        func_combinationals();
205    }
206}
207
208//-------------------------------------------------------------------
209
210// sc_cycle is for internal purpose only.
211// sc_cycle is deprecated since 1.0
212//extern void sc_cycle( double duration );  // in default time units
213
214/* time_unit is worth a cycle in every cases */
215//extern void sc_cycle( double duration, sc_time_unit time_unit );
216
217} // end of sc_core namespace
218
219#endif /* __GEN_CODE_H__ */
220
221/*
222# Local Variables:
223# tab-width: 4;
224# c-basic-offset: 4;
225# c-file-offsets:((innamespace . 0)(inline-open . 0));
226# indent-tabs-mode: nil;
227# End:
228#
229# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
230*/
231
Note: See TracBrowser for help on using the repository browser.