[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( |
---|
[52] | 44 | method_process_list_t &transition_list, |
---|
| 45 | method_process_list_t &moore_list, |
---|
[60] | 46 | strong_component_list_t *mealy_list); |
---|
[52] | 47 | |
---|
[1] | 48 | extern void gen_scheduling_code_for_static_func( |
---|
[52] | 49 | method_process_list_t &transition_list, |
---|
| 50 | method_process_list_t &moore_list, |
---|
| 51 | ProcessDependencyList &mealy_list); |
---|
[1] | 52 | |
---|
[52] | 53 | extern 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 | |
---|
| 58 | extern char * gen_scheduling_code_for_dynamic_link( |
---|
| 59 | method_process_list_t &transition_list, |
---|
| 60 | method_process_list_t &moore_list, |
---|
[60] | 61 | strong_component_list_t *strongcomponents); |
---|
[52] | 62 | |
---|
[1] | 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 | |
---|
[52] | 70 | EXTERN void static_simulate_1_cycle(); |
---|
| 71 | EXTERN void static_mealy_generation(); |
---|
| 72 | EXTERN void quasistatic_simulate_1_cycle(); |
---|
| 73 | EXTERN void quasistatic_mealy_generation(); |
---|
[1] | 74 | |
---|
| 75 | /* internal functions */ |
---|
[52] | 76 | inline void switch_to_moore() INLINE; |
---|
| 77 | inline void internal_sc_cycle2() INLINE; |
---|
| 78 | inline void internal_sc_cycle1(int number_of_cycles) INLINE; |
---|
| 79 | inline void internal_sc_cycle0(double duration) INLINE; |
---|
[1] | 80 | |
---|
| 81 | /* ***************** */ |
---|
| 82 | /* inlined functions */ |
---|
| 83 | /* ***************** */ |
---|
| 84 | |
---|
[52] | 85 | inline void internal_sc_cycle2() { |
---|
[1] | 86 | #ifdef DUMP_STAGE |
---|
[60] | 87 | #pragma omp master |
---|
| 88 | { |
---|
| 89 | std::cerr << "begin of cycle #" << sc_simulation_time() << "\n"; |
---|
| 90 | } |
---|
[1] | 91 | #endif |
---|
[60] | 92 | |
---|
| 93 | func_simulate_1_cycle(); |
---|
| 94 | |
---|
| 95 | ++nb_cycles; |
---|
[1] | 96 | #ifdef DUMP_STAGE |
---|
[60] | 97 | #pragma omp master |
---|
| 98 | { |
---|
| 99 | std::cerr << "end of cycle\n"; |
---|
| 100 | } |
---|
[1] | 101 | #endif |
---|
| 102 | } |
---|
| 103 | |
---|
[60] | 104 | inline 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]; |
---|
[62] | 108 | extern unsigned int expected_globaltime; |
---|
| 109 | extern volatile unsigned int globaltime; |
---|
[63] | 110 | #ifdef _OPENMP |
---|
[60] | 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) |
---|
[62] | 113 | #pragma omp threadprivate (expected_globaltime) |
---|
[60] | 114 | #pragma omp shared (globaltime) |
---|
[62] | 115 | #endif |
---|
[60] | 116 | extern unsigned int num_omp_threads; |
---|
| 117 | |
---|
| 118 | |
---|
[63] | 119 | #ifdef _OPENMP |
---|
[60] | 120 | #pragma omp parallel |
---|
[62] | 121 | #endif |
---|
[60] | 122 | { |
---|
[62] | 123 | int cyclecount = number_of_cycles; |
---|
[60] | 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; |
---|
[63] | 128 | #ifdef _OPENMP |
---|
[60] | 129 | #pragma omp master |
---|
[62] | 130 | #endif |
---|
[60] | 131 | { |
---|
| 132 | globaltime = 0; |
---|
[63] | 133 | #ifdef _OPENMP |
---|
[60] | 134 | num_omp_threads = omp_get_num_threads(); |
---|
| 135 | #else |
---|
| 136 | num_omp_threads = 1; |
---|
| 137 | #endif |
---|
| 138 | } |
---|
| 139 | |
---|
[63] | 140 | #ifdef _OPENMP |
---|
[60] | 141 | #pragma omp barrier |
---|
[62] | 142 | #endif |
---|
| 143 | while (!(have_to_stop || cyclecount == 0)) { |
---|
| 144 | //while (!(have_to_stop || number_of_cycles == 0)) { |
---|
[63] | 145 | #ifdef _OPENMP |
---|
[60] | 146 | #pragma omp master |
---|
[62] | 147 | #endif |
---|
[60] | 148 | { |
---|
| 149 | trace_all(false); |
---|
| 150 | } |
---|
| 151 | internal_sc_cycle2(); |
---|
[63] | 152 | #ifdef _OPENMP |
---|
[60] | 153 | #pragma omp master |
---|
[62] | 154 | #endif |
---|
[60] | 155 | { |
---|
| 156 | trace_all(true); |
---|
| 157 | } |
---|
[62] | 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; |
---|
[60] | 160 | } |
---|
[63] | 161 | #ifdef _OPENMP |
---|
[60] | 162 | #pragma omp barrier |
---|
[62] | 163 | #endif |
---|
[60] | 164 | #if 0 |
---|
[63] | 165 | #ifdef _OPENMP |
---|
[60] | 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 |
---|
[52] | 186 | } |
---|
[1] | 187 | } |
---|
| 188 | |
---|
[52] | 189 | |
---|
| 190 | inline void internal_sc_cycle0(double duration) { |
---|
| 191 | // in default time units |
---|
| 192 | |
---|
[27] | 193 | #ifdef CONFIG_DEBUG |
---|
[52] | 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 | } |
---|
[1] | 198 | |
---|
[52] | 199 | if (duration < -1) { |
---|
| 200 | std::cerr << "Invalid duration.\n"; |
---|
| 201 | } |
---|
[1] | 202 | #endif |
---|
| 203 | |
---|
[59] | 204 | if (is_posted_write()) { |
---|
[60] | 205 | // update posted value to external signals |
---|
[63] | 206 | #ifdef _OPENMP |
---|
[60] | 207 | #pragma omp parallel |
---|
[62] | 208 | #endif |
---|
[59] | 209 | update(); |
---|
| 210 | func_combinationals(); |
---|
[52] | 211 | } |
---|
| 212 | |
---|
[59] | 213 | internal_sc_cycle1((int) duration); |
---|
[52] | 214 | |
---|
| 215 | // don't need to do func_combinationals since 'unstable' flag is now false |
---|
| 216 | if (is_posted_write()) { |
---|
[63] | 217 | #ifdef _OPENMP |
---|
[60] | 218 | #pragma omp parallel |
---|
[62] | 219 | #endif |
---|
[52] | 220 | update(); |
---|
| 221 | func_combinationals(); |
---|
| 222 | } |
---|
[1] | 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__ */ |
---|
[52] | 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 | |
---|