| 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 | //------------------------------------------------------------------- |
|---|
| 35 | namespace sc_core { |
|---|
| 36 | |
|---|
| 37 | extern strong_component_list_t * strong; |
|---|
| 38 | |
|---|
| 39 | /* compile scheduling code to link dynamically later */ |
|---|
| 40 | extern void compile_code(const char * base_name, const char * cflags2 = ""); |
|---|
| 41 | |
|---|
| 42 | /* generate a scheduling code */ |
|---|
| 43 | extern 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 | extern void gen_scheduling_code_for_static_func( |
|---|
| 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); |
|---|
| 59 | |
|---|
| 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, |
|---|
| 68 | strong_component_list_t *strongcomponents); |
|---|
| 69 | |
|---|
| 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 | |
|---|
| 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(); |
|---|
| 81 | |
|---|
| 82 | /* internal functions */ |
|---|
| 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; |
|---|
| 87 | |
|---|
| 88 | /* ***************** */ |
|---|
| 89 | /* inlined functions */ |
|---|
| 90 | /* ***************** */ |
|---|
| 91 | |
|---|
| 92 | inline void internal_sc_cycle2() { |
|---|
| 93 | #ifdef DUMP_STAGE |
|---|
| 94 | #pragma omp master |
|---|
| 95 | { |
|---|
| 96 | std::cerr << "begin of cycle #" << sc_simulation_time () << "\n"; |
|---|
| 97 | } |
|---|
| 98 | #endif |
|---|
| 99 | |
|---|
| 100 | func_simulate_1_cycle (); |
|---|
| 101 | |
|---|
| 102 | ++nb_cycles; |
|---|
| 103 | #ifdef DUMP_STAGE |
|---|
| 104 | #pragma omp master |
|---|
| 105 | { |
|---|
| 106 | std::cerr << "end of cycle\n"; |
|---|
| 107 | } |
|---|
| 108 | #endif |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 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]; |
|---|
| 118 | #ifdef _OPENMP |
|---|
| 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) |
|---|
| 121 | #endif |
|---|
| 122 | extern unsigned int expected_globaltime; |
|---|
| 123 | extern volatile unsigned int globaltime; |
|---|
| 124 | #ifdef _OPENMP |
|---|
| 125 | #pragma omp threadprivate (expected_globaltime) |
|---|
| 126 | #pragma omp shared (globaltime) |
|---|
| 127 | #endif |
|---|
| 128 | |
|---|
| 129 | extern unsigned int num_omp_threads; |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | #ifdef _OPENMP |
|---|
| 133 | #pragma omp parallel |
|---|
| 134 | #endif |
|---|
| 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; |
|---|
| 139 | |
|---|
| 140 | expected_globaltime = 0; |
|---|
| 141 | #ifdef _OPENMP |
|---|
| 142 | #pragma omp master |
|---|
| 143 | #endif |
|---|
| 144 | { |
|---|
| 145 | globaltime = 0; |
|---|
| 146 | #ifdef _OPENMP |
|---|
| 147 | num_omp_threads = omp_get_num_threads(); |
|---|
| 148 | #else |
|---|
| 149 | num_omp_threads = 1; |
|---|
| 150 | #endif |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | #ifdef _OPENMP |
|---|
| 154 | #pragma omp barrier |
|---|
| 155 | #endif |
|---|
| 156 | while (!((have_to_stop) | (cyclecount == 0))) { |
|---|
| 157 | #ifdef _OPENMP |
|---|
| 158 | #pragma omp master |
|---|
| 159 | #endif |
|---|
| 160 | { |
|---|
| 161 | trace_all (false); |
|---|
| 162 | } |
|---|
| 163 | internal_sc_cycle2 (); |
|---|
| 164 | #ifdef _OPENMP |
|---|
| 165 | #pragma omp master |
|---|
| 166 | #endif |
|---|
| 167 | { |
|---|
| 168 | trace_all (true); |
|---|
| 169 | } |
|---|
| 170 | cyclecount = (number_of_cycles<0)?number_of_cycles:cyclecount-1; |
|---|
| 171 | } |
|---|
| 172 | #ifdef _OPENMP |
|---|
| 173 | #pragma omp barrier |
|---|
| 174 | #pragma omp critical |
|---|
| 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 | } |
|---|
| 180 | #pragma omp critical |
|---|
| 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 | } |
|---|
| 186 | #pragma omp critical |
|---|
| 187 | { |
|---|
| 188 | std::cerr << "Thread " << omp_get_thread_num() << " nfuncs " |
|---|
| 189 | << nb_func[0] << " " << nb_func[1] << " total_assig " << |
|---|
| 190 | total_assig << std::endl; |
|---|
| 191 | } |
|---|
| 192 | #endif // _OPENMP |
|---|
| 193 | } |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | inline void internal_sc_cycle0(double duration) { |
|---|
| 198 | // in default time units |
|---|
| 199 | |
|---|
| 200 | #ifdef CONFIG_DEBUG |
|---|
| 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 | } |
|---|
| 205 | |
|---|
| 206 | if (duration < -1) { |
|---|
| 207 | std::cerr << "Invalid duration.\n"; |
|---|
| 208 | } |
|---|
| 209 | #endif |
|---|
| 210 | |
|---|
| 211 | if (is_posted_write()) { |
|---|
| 212 | // update posted value to external signals |
|---|
| 213 | #ifdef _OPENMP |
|---|
| 214 | #pragma omp parallel |
|---|
| 215 | #endif // _OPENMP |
|---|
| 216 | update (); |
|---|
| 217 | func_combinationals (); |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | internal_sc_cycle1 ((int)duration); |
|---|
| 221 | |
|---|
| 222 | // don't need to do func_combinationals since 'unstable' flag is now false |
|---|
| 223 | if (is_posted_write ()) { |
|---|
| 224 | #ifdef _OPENMP |
|---|
| 225 | #pragma omp parallel |
|---|
| 226 | #endif // _OPENMP |
|---|
| 227 | update (); |
|---|
| 228 | func_combinationals (); |
|---|
| 229 | } |
|---|
| 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__ */ |
|---|
| 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 | |
|---|