1 | #ifdef SYSTEMC |
---|
2 | /* |
---|
3 | * $Id: Decod_genMealy.cpp 87 2008-05-15 19:23:42Z rosiere $ |
---|
4 | * |
---|
5 | * [ Description ] |
---|
6 | * |
---|
7 | */ |
---|
8 | |
---|
9 | #include "Behavioural/Core/Multi_Front_end/Front_end/Decod_unit/Decod/include/Decod.h" |
---|
10 | |
---|
11 | namespace morpheo { |
---|
12 | namespace behavioural { |
---|
13 | namespace core { |
---|
14 | namespace multi_front_end { |
---|
15 | namespace front_end { |
---|
16 | namespace decod_unit { |
---|
17 | namespace decod { |
---|
18 | |
---|
19 | |
---|
20 | #undef FUNCTION |
---|
21 | #define FUNCTION "Decod::genMealy" |
---|
22 | void Decod::genMealy (void) |
---|
23 | { |
---|
24 | log_printf(TRACE,Decod,FUNCTION,"Begin"); |
---|
25 | |
---|
26 | //----------------------------------- |
---|
27 | // Initialization |
---|
28 | //----------------------------------- |
---|
29 | Tcontrol_t context_event_val = false; |
---|
30 | Tcontrol_t ifetch_ack [_param->_nb_context][_param->_max_nb_inst_fetch]; |
---|
31 | for (uint32_t i=0; i<_param->_nb_context; i++) |
---|
32 | for (uint32_t j=0; j<_param->_nb_inst_fetch[i]; j++) |
---|
33 | ifetch_ack [i][j] = false; |
---|
34 | |
---|
35 | Tcontrol_t predict_val [_param->_nb_inst_decod]; |
---|
36 | Tcontrol_t decod_val [_param->_nb_inst_decod]; |
---|
37 | for (uint32_t i=0; i<_param->_nb_inst_decod; i++) |
---|
38 | { |
---|
39 | decod_val [i] = false; |
---|
40 | } |
---|
41 | |
---|
42 | Tcontrol_t can_continue [_param->_nb_context]; |
---|
43 | Tcontrol_t can_continue_next [_param->_nb_context]; |
---|
44 | |
---|
45 | for (uint32_t i=0; i<_param->_nb_context; i++) |
---|
46 | { |
---|
47 | internal_CONTEXT_HAVE_TRANSACTION [i] = false; |
---|
48 | internal_CONTEXT_ADDRESS_PREVIOUS [i] = reg_CONTEXT_ADDRESS_PREVIOUS [i]; |
---|
49 | internal_CONTEXT_IS_DELAY_SLOT [i] = reg_CONTEXT_IS_DELAY_SLOT [i]; |
---|
50 | |
---|
51 | can_continue [i] = PORT_READ(in_CONTEXT_DECOD_ENABLE [i]); |
---|
52 | can_continue_next [i] = PORT_READ(in_CONTEXT_DECOD_ENABLE [i]); |
---|
53 | } |
---|
54 | |
---|
55 | //----------------------------------- |
---|
56 | // Loop of decod |
---|
57 | //----------------------------------- |
---|
58 | // scan all decod "slot_out" |
---|
59 | log_printf(TRACE,Decod,FUNCTION,"KANE LIVE"); |
---|
60 | std::list<select_t>::iterator it=select.begin(); |
---|
61 | for (uint32_t i=0; i<_param->_nb_inst_decod; i++) |
---|
62 | { |
---|
63 | while ((it != select.end()) and // have a no scanned "slot_in" ? |
---|
64 | (decod_val [i] == false) and // have not a previous selected entry? |
---|
65 | (context_event_val == false)) // Have not a context_event (spr_access, exception, ...) |
---|
66 | { |
---|
67 | log_printf(TRACE,Decod,FUNCTION,"loop"); |
---|
68 | |
---|
69 | predict_val [i] = false; |
---|
70 | |
---|
71 | Tcontext_t x = it->_context ; |
---|
72 | uint32_t y = it->_inst_fetch; |
---|
73 | |
---|
74 | // Test if this instruction is valid |
---|
75 | if ((PORT_READ(in_IFETCH_VAL [x][y]) == 1) and // entry is valid |
---|
76 | (can_continue [x] == 1)) // context can decod instruction (have not a previous event) |
---|
77 | { |
---|
78 | can_continue [x] = can_continue_next [x]; |
---|
79 | |
---|
80 | decod_val [i] = true; // fetch_val and decod_enable |
---|
81 | ifetch_ack [x][y] = PORT_READ(in_DECOD_ACK [i]); // fetch_val and decod_enable and decod_ack |
---|
82 | |
---|
83 | Tgeneral_data_t addr = PORT_READ(in_IFETCH_ADDRESS [x])+y; |
---|
84 | |
---|
85 | _decod_instruction->_instruction = PORT_READ(in_IFETCH_INSTRUCTION [x][y]); |
---|
86 | _decod_instruction->_context_id = x; |
---|
87 | _decod_instruction->_address_previous = internal_CONTEXT_ADDRESS_PREVIOUS [x]; |
---|
88 | _decod_instruction->_address = addr; //Compute the current address |
---|
89 | _decod_instruction->_address_next = addr+1; |
---|
90 | _decod_instruction->_is_delay_slot = internal_CONTEXT_IS_DELAY_SLOT [x]; |
---|
91 | |
---|
92 | // Decod ! |
---|
93 | log_printf(TRACE,Decod,FUNCTION,"DECOD [%d]",i); |
---|
94 | log_printf(TRACE,Decod,FUNCTION," * context : %d",x); |
---|
95 | log_printf(TRACE,Decod,FUNCTION," * fetch : %d",y); |
---|
96 | log_printf(TRACE,Decod,FUNCTION," * address : %.8x",addr); |
---|
97 | log_printf(TRACE,Decod,FUNCTION," * is_delay_slot : %d",internal_CONTEXT_IS_DELAY_SLOT [x]); |
---|
98 | |
---|
99 | instruction_decod (_decod_instruction, _decod_param[x]); |
---|
100 | |
---|
101 | Ttype_t type = _decod_instruction->_type; |
---|
102 | |
---|
103 | if (_param->_have_port_context_id) |
---|
104 | PORT_WRITE(out_DECOD_CONTEXT_ID [i], x); |
---|
105 | if (_param->_have_port_depth) |
---|
106 | PORT_WRITE(out_DECOD_DEPTH [i], PORT_READ(in_CONTEXT_DEPTH [x])); |
---|
107 | PORT_WRITE(out_DECOD_TYPE [i], type); |
---|
108 | PORT_WRITE(out_DECOD_OPERATION [i], _decod_instruction->_operation ); |
---|
109 | PORT_WRITE(out_DECOD_IS_DELAY_SLOT [i], _decod_instruction->_is_delay_slot ); |
---|
110 | PORT_WRITE(out_DECOD_ADDRESS [i], addr); |
---|
111 | PORT_WRITE(out_DECOD_HAS_IMMEDIAT [i], _decod_instruction->_has_immediat ); |
---|
112 | PORT_WRITE(out_DECOD_IMMEDIAT [i], _decod_instruction->_immediat ); |
---|
113 | PORT_WRITE(out_DECOD_READ_RA [i], _decod_instruction->_read_ra ); |
---|
114 | PORT_WRITE(out_DECOD_NUM_REG_RA [i], _decod_instruction->_num_reg_ra ); |
---|
115 | PORT_WRITE(out_DECOD_READ_RB [i], _decod_instruction->_read_rb ); |
---|
116 | PORT_WRITE(out_DECOD_NUM_REG_RB [i], _decod_instruction->_num_reg_rb ); |
---|
117 | PORT_WRITE(out_DECOD_READ_RC [i], _decod_instruction->_read_rc ); |
---|
118 | PORT_WRITE(out_DECOD_NUM_REG_RC [i], _decod_instruction->_num_reg_rc ); |
---|
119 | PORT_WRITE(out_DECOD_WRITE_RD [i], _decod_instruction->_write_rd ); |
---|
120 | PORT_WRITE(out_DECOD_NUM_REG_RD [i], _decod_instruction->_num_reg_rd ); |
---|
121 | PORT_WRITE(out_DECOD_WRITE_RE [i], _decod_instruction->_write_re ); |
---|
122 | PORT_WRITE(out_DECOD_NUM_REG_RE [i], _decod_instruction->_num_reg_re ); |
---|
123 | PORT_WRITE(out_DECOD_EXCEPTION_USE [i], _decod_instruction->_exception_use ); |
---|
124 | |
---|
125 | if (type == TYPE_BRANCH) |
---|
126 | { |
---|
127 | log_printf(TRACE,Decod,FUNCTION," * type is branch"); |
---|
128 | |
---|
129 | predict_val [i] = ifetch_ack [x][y] // and decod_val [i] |
---|
130 | ; |
---|
131 | decod_val [i] &= PORT_READ(in_PREDICT_ACK [i]);// predict_ack and fetch_val and decod_enable |
---|
132 | ifetch_ack [x][y] &= PORT_READ(in_PREDICT_ACK [i]);// predict_ack and fetch_val and decod_enable and decod_ack |
---|
133 | |
---|
134 | if (_param->_have_port_context_id) |
---|
135 | PORT_WRITE(out_PREDICT_CONTEXT_ID [i],x); |
---|
136 | PORT_WRITE(out_PREDICT_MATCH_INST_IFETCH_PTR [i],y == ((_param->_have_port_inst_ifetch_ptr)?PORT_READ(in_IFETCH_INST_IFETCH_PTR [x]):0)); |
---|
137 | PORT_WRITE(out_PREDICT_BRANCH_STATE [i],PORT_READ(in_IFETCH_BRANCH_STATE [x])); |
---|
138 | if (_param->_have_port_branch_update_prediction_id) |
---|
139 | PORT_WRITE(out_PREDICT_BRANCH_UPDATE_PREDICTION_ID [i],PORT_READ(in_IFETCH_BRANCH_UPDATE_PREDICTION_ID [x])); |
---|
140 | PORT_WRITE(out_PREDICT_BRANCH_CONDITION [i],_decod_instruction->_branch_condition ); |
---|
141 | // PORT_WRITE(out_PREDICT_BRANCH_STACK_WRITE [i],_decod_instruction->_branch_stack_write); |
---|
142 | PORT_WRITE(out_PREDICT_BRANCH_DIRECTION [i],_decod_instruction->_branch_direction ); |
---|
143 | PORT_WRITE(out_PREDICT_ADDRESS_SRC [i],_decod_instruction->_address ); |
---|
144 | PORT_WRITE(out_PREDICT_ADDRESS_DEST [i],_decod_instruction->_address_next ); |
---|
145 | |
---|
146 | //can_continue_next [x] = PORT_READ(in_PREDICT_CAN_CONTINUE [i]); // can continue is set if direction is "not take" (also, continue is sequential order) |
---|
147 | can_continue_next [x] = false; // one branch per context |
---|
148 | } |
---|
149 | |
---|
150 | Tevent_type_t event_type = _decod_instruction->_event_type; |
---|
151 | if (event_type != EVENT_TYPE_NONE) |
---|
152 | { |
---|
153 | // speculative jump at the exception handler |
---|
154 | // if type = TYPE_BRANCH, also event_type == EVENT_TYPE_NONE |
---|
155 | context_event_val = ifetch_ack [x][y] // and decod_val [i] |
---|
156 | ; |
---|
157 | decod_val [i] &= PORT_READ(in_CONTEXT_EVENT_ACK);// context_event_ack and fetch_val and decod_enable |
---|
158 | ifetch_ack [x][y] &= PORT_READ(in_CONTEXT_EVENT_ACK);// context_event_ack and fetch_val and decod_enable and decod_ack |
---|
159 | |
---|
160 | if (_param->_have_port_context_id) |
---|
161 | PORT_WRITE(out_CONTEXT_EVENT_CONTEXT_ID , x); |
---|
162 | PORT_WRITE(out_CONTEXT_EVENT_TYPE , _decod_instruction->_event_type ); |
---|
163 | PORT_WRITE(out_CONTEXT_EVENT_IS_DELAY_SLOT, _decod_instruction->_is_delay_slot ); |
---|
164 | PORT_WRITE(out_CONTEXT_EVENT_ADDRESS , _decod_instruction->_address ); |
---|
165 | PORT_WRITE(out_CONTEXT_EVENT_ADDRESS_EPCR , _decod_instruction->_address_next ); |
---|
166 | } |
---|
167 | |
---|
168 | // fetch_ack = |
---|
169 | // ((event_type == EVENT_TYPE_NONE) or ((event_type != EVENT_TYPE_NONE) and context_event_ack)) and |
---|
170 | // ((type == TYPE_BRANCH ) or ((type != TYPE_BRANCH ) and predict_ack )) and |
---|
171 | // fetch_val and decod_ack and decod_enable and true (is decod_val) |
---|
172 | |
---|
173 | // To compute the "next previous" address |
---|
174 | Tcontrol_t have_transaction = ifetch_ack [x][y]; |
---|
175 | |
---|
176 | internal_CONTEXT_HAVE_TRANSACTION [x] |= have_transaction; |
---|
177 | if (have_transaction) |
---|
178 | { |
---|
179 | internal_CONTEXT_ADDRESS_PREVIOUS [x] = addr; |
---|
180 | internal_CONTEXT_IS_DELAY_SLOT [x] = (type == TYPE_BRANCH); // next is a delay slot if current have branch type |
---|
181 | } |
---|
182 | |
---|
183 | can_continue [x] &= have_transaction; // to have a in order decod !!! if a previous instruction can decod, also next instruction can't decod. |
---|
184 | } |
---|
185 | |
---|
186 | log_printf(TRACE,Decod,FUNCTION," - num_(decod, context, fetch) : %d %d %d",i, x, y); |
---|
187 | log_printf(TRACE,Decod,FUNCTION," - ifetch_ack : %d",ifetch_ack [x][y]); |
---|
188 | log_printf(TRACE,Decod,FUNCTION," - context_event_val : %d",context_event_val ); |
---|
189 | log_printf(TRACE,Decod,FUNCTION," - predict_val : %d",predict_val [i] ); |
---|
190 | log_printf(TRACE,Decod,FUNCTION," - decod_val : %d",decod_val [i] ); |
---|
191 | |
---|
192 | it ++; |
---|
193 | } |
---|
194 | } |
---|
195 | //----------------------------------- |
---|
196 | // Write output |
---|
197 | //----------------------------------- |
---|
198 | |
---|
199 | for (uint32_t i=0; i<_param->_nb_context; i++) |
---|
200 | for (uint32_t j=0; j<_param->_nb_inst_fetch[i]; j++) |
---|
201 | PORT_WRITE(out_IFETCH_ACK [i][j], ifetch_ack [i][j]); |
---|
202 | |
---|
203 | PORT_WRITE(out_CONTEXT_EVENT_VAL, context_event_val); |
---|
204 | |
---|
205 | for (uint32_t i=0; i<_param->_nb_inst_decod; i++) |
---|
206 | { |
---|
207 | PORT_WRITE(out_PREDICT_VAL [i], predict_val [i]); |
---|
208 | PORT_WRITE(out_DECOD_VAL [i], decod_val [i]); |
---|
209 | } |
---|
210 | |
---|
211 | log_printf(FUNC,Decod,FUNCTION,"End"); |
---|
212 | }; |
---|
213 | |
---|
214 | }; // end namespace decod |
---|
215 | }; // end namespace decod_unit |
---|
216 | }; // end namespace front_end |
---|
217 | }; // end namespace multi_front_end |
---|
218 | }; // end namespace core |
---|
219 | |
---|
220 | }; // end namespace behavioural |
---|
221 | }; // end namespace morpheo |
---|
222 | #endif |
---|