scoreboard.c
void scoreboard_writeResults(stScoreboardCPU* a_pThis) {
	bool isReadyToWriteResult = true;
	int relatedPC = 0;
	size_t i = 0, j = 0;
	for (i=0; i<NUM_OF_REGISTERS; ++i) {
		if (a_pThis->registerResultStatus[i] != NULL) { /* Check for active FUs */
			stFunctionalUnit* currFU = a_pThis->registerResultStatus[i];
			relatedPC = currFU->relatedPC;
			if (a_pThis->instructionStatus[EXECUTE_END_STAGE_IDX][relatedPC] != a_pThis->cycle) { /* Check that we are not writing back in the same cycle as the executuin */
				if (currFU->Busy && (currFU->time_left == 0)) { /* Check that execution finished */
					isReadyToWriteResult = true;
					for (j=0; j<NUM_OF_REGISTERS; ++j) {
						if ((i != j) && (((currFU->Fi == currFU->Fj) && currFU->Rj) ||((currFU->Fi == currFU->Fk) && currFU->Rk))) { /* Check the WriteResults conditions */
							isReadyToWriteResult = false;
							break;
						}
					}
					if (isReadyToWriteResult) { /* Perform the WriteResults and update all the other FUs who wait for the data to be written */
						for (j=0; j<NUM_OF_REGISTERS; ++j) {
							if (a_pThis->registerResultStatus[j] != NULL) {
								if (currFU == a_pThis->registerResultStatus[j]->Qj) {
									a_pThis->registerResultStatus[j]->Rj = true;
									a_pThis->registerResultStatus[j]->Qj = NULL;
								}
								if (currFU == a_pThis->registerResultStatus[j]->Qk) {
									a_pThis->registerResultStatus[j]->Rk = true;
									a_pThis->registerResultStatus[j]->Qk = NULL;
								}
							}
						}
						if (currFU->m_op != OPCODE_ST) { /* If it is store command we are not writing back to register */
							a_pThis->Register[currFU->Fi] = currFU->tempRegister;
						}
						currFU->Busy = false;
						a_pThis->registerResultStatus[i] = NULL;
						a_pThis->instructionStatus[WRITE_RESULT_STAGE_IDX][relatedPC] = a_pThis->cycle;
					}
				}
			}
		}
	}
}
/* This function performs the Write results stage of the scorecoard.
 * It stalls until there is no WAR hazrad with previous instructions */
This function performs the Write results stage of the scorecoard.
It stalls until there is no WAR hazrad with previous instructions
This function performs the Write results stage of the scorecoard . It stalls until there is no WAR hazrad with previous instructions
void scoreboard_writeResults(stScoreboardCPU* a_pThis) {
	bool isReadyToWriteResult = true;
	int relatedPC = 0;
	size_t i = 0, j = 0;
	for (i=0; i<NUM_OF_REGISTERS; ++i) {
		if (a_pThis->registerResultStatus[i] != NULL) { 
			stFunctionalUnit* currFU = a_pThis->registerResultStatus[i];
			relatedPC = currFU->relatedPC;
			if (a_pThis->instructionStatus[EXECUTE_END_STAGE_IDX][relatedPC] != a_pThis->cycle) { 
				if (currFU->Busy && (currFU->time_left == 0)) { 
					isReadyToWriteResult = true;
					for (j=0; j<NUM_OF_REGISTERS; ++j) {
						if ((i != j) && (((currFU->Fi == currFU->Fj) && currFU->Rj) ||((currFU->Fi == currFU->Fk) && currFU->Rk))) { 
							isReadyToWriteResult = false;
							break;
						}
					}
					if (isReadyToWriteResult) { 
						for (j=0; j<NUM_OF_REGISTERS; ++j) {
							if (a_pThis->registerResultStatus[j] != NULL) {
								if (currFU == a_pThis->registerResultStatus[j]->Qj) {
									a_pThis->registerResultStatus[j]->Rj = true;
									a_pThis->registerResultStatus[j]->Qj = NULL;
								}
								if (currFU == a_pThis->registerResultStatus[j]->Qk) {
									a_pThis->registerResultStatus[j]->Rk = true;
									a_pThis->registerResultStatus[j]->Qk = NULL;
								}
							}
						}
						if (currFU->m_op != OPCODE_ST) { 
							a_pThis->Register[currFU->Fi] = currFU->tempRegister;
						}
						currFU->Busy = false;
						a_pThis->registerResultStatus[i] = NULL;
						a_pThis->instructionStatus[WRITE_RESULT_STAGE_IDX][relatedPC] = a_pThis->cycle;
					}
				}
			}
		}
	}
}
void scoreboard_writeResults ( stScoreboardCPU * a_pThis ) { bool isReadyToWriteResult = true ; int relatedPC = 0 ; size_t i = 0 , j = 0 ; for ( i = 0 ; i < NUM_OF_REGISTERS ; ++ i ) { if ( a_pThis -> registerResultStatus [ i ] != NULL ) { stFunctionalUnit * currFU = a_pThis -> registerResultStatus [ i ] ; relatedPC = currFU -> relatedPC ; if ( a_pThis -> instructionStatus [ EXECUTE_END_STAGE_IDX ] [ relatedPC ] != a_pThis -> cycle ) { if ( currFU -> Busy && ( currFU -> time_left == 0 ) ) { isReadyToWriteResult = true ; for ( j = 0 ; j < NUM_OF_REGISTERS ; ++ j ) { if ( ( i != j ) && ( ( ( currFU -> Fi == currFU -> Fj ) && currFU -> Rj ) || ( ( currFU -> Fi == currFU -> Fk ) && currFU -> Rk ) ) ) { isReadyToWriteResult = false ; break ; } } if ( isReadyToWriteResult ) { for ( j = 0 ; j < NUM_OF_REGISTERS ; ++ j ) { if ( a_pThis -> registerResultStatus [ j ] != NULL ) { if ( currFU == a_pThis -> registerResultStatus [ j ] -> Qj ) { a_pThis -> registerResultStatus [ j ] -> Rj = true ; a_pThis -> registerResultStatus [ j ] -> Qj = NULL ; } if ( currFU == a_pThis -> registerResultStatus [ j ] -> Qk ) { a_pThis -> registerResultStatus [ j ] -> Rk = true ; a_pThis -> registerResultStatus [ j ] -> Qk = NULL ; } } } if ( currFU -> m_op != OPCODE_ST ) { a_pThis -> Register [ currFU -> Fi ] = currFU -> tempRegister ; } currFU -> Busy = false ; a_pThis -> registerResultStatus [ i ] = NULL ; a_pThis -> instructionStatus [ WRITE_RESULT_STAGE_IDX ] [ relatedPC ] = a_pThis -> cycle ; } } } } } }
This function performs the Write results stage of the scorecoard.
This function performs the Write results stage of the scorecoard .
/* Check for active FUs */ /* Check that we are not writing back in the same cycle as the executuin */ /* Check that execution finished */ /* Check the WriteResults conditions */ /* Perform the WriteResults and update all the other FUs who wait for the data to be written */ /* If it is store command we are not writing back to register */