/* * Description: * Moves an instruction from the execution stage to common data bus (if possible) * Inputs: * current_cycle: the cycle we are at * Returns: * None */ void execute_To_CDB(int current_cycle) { /* ECE552: YOUR CODE GOES HERE */ //First Check for completed store instructions that don't need access to CDB //Check if CDB is free afterwards to look for oldest completed instruction //Then check that the functional unit is allocated && //execute variable has been set && //current_cycle > tom_execute_cycle + LATENCY // Get the oldest instruction that fits the criteria above and give it access to the CDB /* ECE552 Assignment 3 - BEGIN CODE */ int i; for(i = 0; i < FU_INT_SIZE; i++){ if(fuINT[i] && fuINT[i]->tom_execute_cycle != 0 && fuINT[i]->tom_cdb_cycle == 0){ if(current_cycle > (fuINT[i]->tom_execute_cycle + FU_INT_LATENCY)){ if(!WRITES_CDB(fuINT[i]->op)){ removeFromRS(fuINT[i]); fuINT[i] = NULL; } } } } if(!commonDataBus){ //YES CDB is free instruction_t *oldest = NULL; int i; for(i = 0; i < FU_INT_SIZE; i++){ if(fuINT[i] && fuINT[i]->tom_execute_cycle != 0 && fuINT[i]->tom_cdb_cycle == 0){ if(current_cycle > (fuINT[i]->tom_execute_cycle + FU_INT_LATENCY)){ if(!oldest || fuINT[i]->index < oldest->index){ oldest = fuINT[i]; } } } } for(i = 0; i < FU_FP_SIZE; i++){ if(fuFP[i] && fuFP[i]->tom_execute_cycle != 0 && fuFP[i]->tom_cdb_cycle == 0 && current_cycle > (fuFP[i]->tom_execute_cycle + FU_FP_LATENCY)){ if(!oldest || fuFP[i]->index < oldest->index){ oldest = fuFP[i]; } } } //We have a candidate for the CDB //set the common data bus //set it's FU to NULL //set it's reservation station to NULL if(oldest){ commonDataBus = oldest; oldest->tom_cdb_cycle = current_cycle; removeFromRS(oldest); removeFromFU(oldest); } } /* ECE552 Assignment 3 - END CODE */ }
/* * Description: * Moves an instruction from the execution stage to common data bus (if possible) * Inputs: * current_cycle: the cycle we are at * Returns: * None */ void execute_To_CDB(int current_cycle) { /* ECE552 Assignment 4 - BEGIN CODE */ int i; for (i = 0; i < FU_INT_SIZE; i++) { if (fuINT[i] != NULL && fuINT[i]->tom_execute_cycle + FU_INT_LATENCY <= current_cycle) { insn_struct* currentINT = reservINT; insn_struct* prevINT = NULL; while (currentINT != NULL) { if (fuINT[i] == currentINT->insn) { if (prevINT == NULL) { /* is the head of list */ if (WRITES_CDB(currentINT->insn->op)) { commonDataBus = currentINT->insn; commonDataBus->tom_cdb_cycle = current_cycle; } reservINT = currentINT->next; currentINT->insn = NULL; free(currentINT); currentINT = NULL; break; } else { if (WRITES_CDB(currentINT->insn->op)) { commonDataBus = currentINT->insn; commonDataBus->tom_cdb_cycle = current_cycle; } prevINT->next = currentINT->next; currentINT->insn = NULL; free(currentINT); currentINT = NULL; prevINT = NULL; break; } } } } } for (i = 0; i < FU_FP_SIZE; i++) { if (fuFP[i] != NULL && fuFP[i]->tom_execute_cycle + FU_FP_LATENCY <= current_cycle) { insn_struct* currentFP = reservFP; insn_struct* prevFP = NULL; while (currentFP != NULL) { if (fuFP[i] == currentFP->insn) { if (prevFP == NULL) { /* is the head of list */ if (WRITES_CDB(currentFP->insn->op)) { commonDataBus = currentFP->insn; commonDataBus->tom_cdb_cycle = current_cycle; } reservFP = currentFP->next; currentFP->insn = NULL; free(currentFP); currentFP = NULL; break; } else { if (WRITES_CDB(currentFP->insn->op)) { commonDataBus = currentFP->insn; commonDataBus->tom_cdb_cycle = current_cycle; } prevFP->next = currentFP->next; currentFP->insn = NULL; free(currentFP); currentFP = NULL; prevFP = NULL; break; } } } } } /* ECE552 Assignment 4 - END CODE */ }