[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 | |
---|
[60] | 23 | #ifdef _OPENMP |
---|
| 24 | #include <omp.h> |
---|
| 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]; |
---|
| 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) |
---|
[52] | 114 | |
---|
[60] | 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 |
---|
[52] | 173 | } |
---|
[1] | 174 | } |
---|
| 175 | |
---|
[52] | 176 | |
---|
| 177 | inline void internal_sc_cycle0(double duration) { |
---|
| 178 | // in default time units |
---|
| 179 | |
---|
[27] | 180 | #ifdef CONFIG_DEBUG |
---|
[52] | 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 | } |
---|
[1] | 185 | |
---|
[52] | 186 | if (duration < -1) { |
---|
| 187 | std::cerr << "Invalid duration.\n"; |
---|
| 188 | } |
---|
[1] | 189 | #endif |
---|
| 190 | |
---|
[59] | 191 | if (is_posted_write()) { |
---|
[60] | 192 | // update posted value to external signals |
---|
| 193 | #pragma omp parallel |
---|
[59] | 194 | update(); |
---|
| 195 | func_combinationals(); |
---|
[52] | 196 | } |
---|
| 197 | |
---|
[59] | 198 | internal_sc_cycle1((int) duration); |
---|
[52] | 199 | |
---|
| 200 | // don't need to do func_combinationals since 'unstable' flag is now false |
---|
| 201 | if (is_posted_write()) { |
---|
[60] | 202 | #pragma omp parallel |
---|
[52] | 203 | update(); |
---|
| 204 | func_combinationals(); |
---|
| 205 | } |
---|
[1] | 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__ */ |
---|
[52] | 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 | |
---|