[88] | 1 | #ifdef SYSTEMC |
---|
| 2 | /* |
---|
| 3 | * $Id: Simulation_test_end.cpp 138 2010-05-12 17:34:01Z rosiere $ |
---|
| 4 | * |
---|
| 5 | * [ Description ] |
---|
| 6 | * |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "Behavioural/include/Simulation.h" |
---|
[113] | 10 | #include "Common/include/Systemc.h" |
---|
[124] | 11 | #include "Common/include/ErrorMorpheo.h" |
---|
[88] | 12 | |
---|
| 13 | namespace morpheo { |
---|
| 14 | namespace behavioural { |
---|
| 15 | |
---|
| 16 | bool simulation_test_end (void) |
---|
| 17 | { |
---|
[117] | 18 | msgInformation("##########[ cycle %.0f ]\n",static_cast<double>(simulation_cycle())); |
---|
[88] | 19 | |
---|
| 20 | // Test if a stop condition is activate |
---|
[110] | 21 | if ((_simulation_nb_cycle == 0) and |
---|
| 22 | (_simulation_nb_instruction == 0) |
---|
[88] | 23 | ) |
---|
| 24 | return false; |
---|
| 25 | |
---|
[110] | 26 | bool end_cycle; |
---|
| 27 | bool end_inst ; |
---|
[88] | 28 | |
---|
| 29 | if (_simulation_nb_cycle != 0) |
---|
[113] | 30 | end_cycle = (_simulation_nb_cycle <= simulation_cycle()); |
---|
[110] | 31 | else |
---|
| 32 | end_cycle = true; |
---|
[88] | 33 | |
---|
[110] | 34 | if (_simulation_nb_instruction != 0) |
---|
| 35 | { |
---|
| 36 | end_inst = true; |
---|
[138] | 37 | std::vector<double>::iterator it=_simulation_nb_instruction_commited.begin(); |
---|
[110] | 38 | |
---|
[138] | 39 | switch (_simulation_stop_type) |
---|
[110] | 40 | { |
---|
[138] | 41 | case ALL_THREAD : |
---|
| 42 | { |
---|
| 43 | double sum_inst = 0; |
---|
| 44 | |
---|
| 45 | // Scan all context and test if all can finish |
---|
| 46 | while (it!=_simulation_nb_instruction_commited.end()) |
---|
| 47 | { |
---|
| 48 | sum_inst += *it; |
---|
| 49 | it ++; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | // Stop if sum of all instruction is higher of "simulation_nb_instruction" |
---|
| 53 | end_inst &= (_simulation_nb_instruction <= sum_inst); |
---|
| 54 | |
---|
| 55 | break; |
---|
| 56 | } |
---|
| 57 | case EACH_THREAD_AND_CONTINUE : |
---|
| 58 | case EACH_THREAD_AND_STOP : |
---|
| 59 | { |
---|
| 60 | // Scan all context and test if all can finish |
---|
| 61 | while (end_inst and it!=_simulation_nb_instruction_commited.end()) |
---|
| 62 | { |
---|
| 63 | |
---|
| 64 | // Stop if all thread have executed more that "simulation_nb_instruction" instructions. |
---|
| 65 | end_inst &= (_simulation_nb_instruction <= *it); |
---|
| 66 | it ++; |
---|
| 67 | } |
---|
| 68 | break; |
---|
| 69 | } |
---|
[110] | 70 | } |
---|
| 71 | } |
---|
| 72 | else |
---|
| 73 | end_inst = true; |
---|
[88] | 74 | |
---|
[124] | 75 | if (end_cycle and _simulation_stop_exception) |
---|
| 76 | { |
---|
| 77 | throw ErrorMorpheo(_("Maximal cycles Reached")); |
---|
| 78 | return false; |
---|
| 79 | } |
---|
| 80 | else |
---|
| 81 | return end_cycle and end_inst; |
---|
[88] | 82 | } |
---|
| 83 | |
---|
| 84 | }; // end namespace behavioural |
---|
| 85 | }; // end namespace morpheo |
---|
| 86 | |
---|
| 87 | #endif |
---|