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