scoreboard.c
stFunctionalUnit* scoreboard_getAvailableFU(stScoreboardCPU* a_pThis, opcode_t a_opcode) {
	size_t i = 0;
	switch (a_opcode) {
		case OPCODE_LD:
			for (i=0; i<a_pThis->pConfiguration->ld_nr_units; ++i) {
				if (a_pThis->pLD_FUs[i].Busy == false) {
					strcpy(a_pThis->instructionFUs[a_pThis->lastIssuedPC], a_pThis->pLD_FUs[i].fuName);
					a_pThis->pLD_FUs[i].time_left = a_pThis->pConfiguration->ld_delay;
					return &a_pThis->pLD_FUs[i];
				}
			}
			return NULL; /* Means no FU is available */
		case OPCODE_ST:
			for (i=0; i<a_pThis->pConfiguration->st_nr_units; ++i) {
				if (a_pThis->pST_FUs[i].Busy == false) {
					strcpy(a_pThis->instructionFUs[a_pThis->lastIssuedPC], a_pThis->pST_FUs[i].fuName);
					a_pThis->pST_FUs[i].time_left = a_pThis->pConfiguration->st_delay;
					return &a_pThis->pST_FUs[i];
				}
			}
			return NULL; /* Means no FU is available */
		case OPCODE_ADD:
			for (i=0; i<a_pThis->pConfiguration->add_nr_units; ++i) {
				if (a_pThis->pADD_FUs[i].Busy == false) {
					strcpy(a_pThis->instructionFUs[a_pThis->lastIssuedPC], a_pThis->pADD_FUs[i].fuName);
					a_pThis->pADD_FUs[i].time_left = a_pThis->pConfiguration->add_delay;
					return &a_pThis->pADD_FUs[i];
				}
			}
			return NULL; /* Means no FU is available */
		case OPCODE_SUB:
			for (i=0; i<a_pThis->pConfiguration->sub_nr_units; ++i) {
				if (a_pThis->pSUB_FUs[i].Busy == false) {
					strcpy(a_pThis->instructionFUs[a_pThis->lastIssuedPC], a_pThis->pSUB_FUs[i].fuName);
					a_pThis->pSUB_FUs[i].time_left = a_pThis->pConfiguration->sub_delay;
					return &a_pThis->pSUB_FUs[i];
				}
			}
			return NULL; /* Means no FU is available */
		case OPCODE_MULT:
			for (i=0; i<a_pThis->pConfiguration->mul_nr_units; ++i) {
				if (a_pThis->pMULT_FUs[i].Busy == false) {
					strcpy(a_pThis->instructionFUs[a_pThis->lastIssuedPC], a_pThis->pMULT_FUs[i].fuName);
					a_pThis->pMULT_FUs[i].time_left = a_pThis->pConfiguration->mul_delay;
					return &a_pThis->pMULT_FUs[i];
				}
			}
			return NULL; /* Means no FU is available */
		case OPCODE_DIV:
			for (i=0; i<a_pThis->pConfiguration->div_nr_units; ++i) {
				if (a_pThis->pDIV_FUs[i].Busy == false) {
					strcpy(a_pThis->instructionFUs[a_pThis->lastIssuedPC], a_pThis->pDIV_FUs[i].fuName);
					a_pThis->pDIV_FUs[i].time_left = a_pThis->pConfiguration->div_delay;
					return &a_pThis->pDIV_FUs[i];
				}
			}
			return NULL; /* Means no FU is available */
		default:
			return NULL;
	}
}
/* This function looks for an avaliabale Functional Unit based on the opcode
 * and returns the pointer to it, If there isn't avilable FU return NULL */
This function looks for an avaliabale Functional Unit based on the opcode
and returns the pointer to it, If there isn't avilable FU return NULL
This function looks for an avaliabale Functional Unit based on the opcode and returns the pointer to it If there isn ' t avilable FU return NULL
stFunctionalUnit* scoreboard_getAvailableFU(stScoreboardCPU* a_pThis, opcode_t a_opcode) {
	size_t i = 0;
	switch (a_opcode) {
		case OPCODE_LD:
			for (i=0; i<a_pThis->pConfiguration->ld_nr_units; ++i) {
				if (a_pThis->pLD_FUs[i].Busy == false) {
					strcpy(a_pThis->instructionFUs[a_pThis->lastIssuedPC], a_pThis->pLD_FUs[i].fuName);
					a_pThis->pLD_FUs[i].time_left = a_pThis->pConfiguration->ld_delay;
					return &a_pThis->pLD_FUs[i];
				}
			}
			return NULL; 
		case OPCODE_ST:
			for (i=0; i<a_pThis->pConfiguration->st_nr_units; ++i) {
				if (a_pThis->pST_FUs[i].Busy == false) {
					strcpy(a_pThis->instructionFUs[a_pThis->lastIssuedPC], a_pThis->pST_FUs[i].fuName);
					a_pThis->pST_FUs[i].time_left = a_pThis->pConfiguration->st_delay;
					return &a_pThis->pST_FUs[i];
				}
			}
			return NULL; 
		case OPCODE_ADD:
			for (i=0; i<a_pThis->pConfiguration->add_nr_units; ++i) {
				if (a_pThis->pADD_FUs[i].Busy == false) {
					strcpy(a_pThis->instructionFUs[a_pThis->lastIssuedPC], a_pThis->pADD_FUs[i].fuName);
					a_pThis->pADD_FUs[i].time_left = a_pThis->pConfiguration->add_delay;
					return &a_pThis->pADD_FUs[i];
				}
			}
			return NULL; 
		case OPCODE_SUB:
			for (i=0; i<a_pThis->pConfiguration->sub_nr_units; ++i) {
				if (a_pThis->pSUB_FUs[i].Busy == false) {
					strcpy(a_pThis->instructionFUs[a_pThis->lastIssuedPC], a_pThis->pSUB_FUs[i].fuName);
					a_pThis->pSUB_FUs[i].time_left = a_pThis->pConfiguration->sub_delay;
					return &a_pThis->pSUB_FUs[i];
				}
			}
			return NULL; 
		case OPCODE_MULT:
			for (i=0; i<a_pThis->pConfiguration->mul_nr_units; ++i) {
				if (a_pThis->pMULT_FUs[i].Busy == false) {
					strcpy(a_pThis->instructionFUs[a_pThis->lastIssuedPC], a_pThis->pMULT_FUs[i].fuName);
					a_pThis->pMULT_FUs[i].time_left = a_pThis->pConfiguration->mul_delay;
					return &a_pThis->pMULT_FUs[i];
				}
			}
			return NULL; 
		case OPCODE_DIV:
			for (i=0; i<a_pThis->pConfiguration->div_nr_units; ++i) {
				if (a_pThis->pDIV_FUs[i].Busy == false) {
					strcpy(a_pThis->instructionFUs[a_pThis->lastIssuedPC], a_pThis->pDIV_FUs[i].fuName);
					a_pThis->pDIV_FUs[i].time_left = a_pThis->pConfiguration->div_delay;
					return &a_pThis->pDIV_FUs[i];
				}
			}
			return NULL; 
		default:
			return NULL;
	}
}
stFunctionalUnit * scoreboard_getAvailableFU ( stScoreboardCPU * a_pThis , opcode_t a_opcode ) { size_t i = 0 ; switch ( a_opcode ) { case OPCODE_LD : for ( i = 0 ; i < a_pThis -> pConfiguration -> ld_nr_units ; ++ i ) { if ( a_pThis -> pLD_FUs [ i ] . Busy == false ) { strcpy ( a_pThis -> instructionFUs [ a_pThis -> lastIssuedPC ] , a_pThis -> pLD_FUs [ i ] . fuName ) ; a_pThis -> pLD_FUs [ i ] . time_left = a_pThis -> pConfiguration -> ld_delay ; return & a_pThis -> pLD_FUs [ i ] ; } } return NULL ; case OPCODE_ST : for ( i = 0 ; i < a_pThis -> pConfiguration -> st_nr_units ; ++ i ) { if ( a_pThis -> pST_FUs [ i ] . Busy == false ) { strcpy ( a_pThis -> instructionFUs [ a_pThis -> lastIssuedPC ] , a_pThis -> pST_FUs [ i ] . fuName ) ; a_pThis -> pST_FUs [ i ] . time_left = a_pThis -> pConfiguration -> st_delay ; return & a_pThis -> pST_FUs [ i ] ; } } return NULL ; case OPCODE_ADD : for ( i = 0 ; i < a_pThis -> pConfiguration -> add_nr_units ; ++ i ) { if ( a_pThis -> pADD_FUs [ i ] . Busy == false ) { strcpy ( a_pThis -> instructionFUs [ a_pThis -> lastIssuedPC ] , a_pThis -> pADD_FUs [ i ] . fuName ) ; a_pThis -> pADD_FUs [ i ] . time_left = a_pThis -> pConfiguration -> add_delay ; return & a_pThis -> pADD_FUs [ i ] ; } } return NULL ; case OPCODE_SUB : for ( i = 0 ; i < a_pThis -> pConfiguration -> sub_nr_units ; ++ i ) { if ( a_pThis -> pSUB_FUs [ i ] . Busy == false ) { strcpy ( a_pThis -> instructionFUs [ a_pThis -> lastIssuedPC ] , a_pThis -> pSUB_FUs [ i ] . fuName ) ; a_pThis -> pSUB_FUs [ i ] . time_left = a_pThis -> pConfiguration -> sub_delay ; return & a_pThis -> pSUB_FUs [ i ] ; } } return NULL ; case OPCODE_MULT : for ( i = 0 ; i < a_pThis -> pConfiguration -> mul_nr_units ; ++ i ) { if ( a_pThis -> pMULT_FUs [ i ] . Busy == false ) { strcpy ( a_pThis -> instructionFUs [ a_pThis -> lastIssuedPC ] , a_pThis -> pMULT_FUs [ i ] . fuName ) ; a_pThis -> pMULT_FUs [ i ] . time_left = a_pThis -> pConfiguration -> mul_delay ; return & a_pThis -> pMULT_FUs [ i ] ; } } return NULL ; case OPCODE_DIV : for ( i = 0 ; i < a_pThis -> pConfiguration -> div_nr_units ; ++ i ) { if ( a_pThis -> pDIV_FUs [ i ] . Busy == false ) { strcpy ( a_pThis -> instructionFUs [ a_pThis -> lastIssuedPC ] , a_pThis -> pDIV_FUs [ i ] . fuName ) ; a_pThis -> pDIV_FUs [ i ] . time_left = a_pThis -> pConfiguration -> div_delay ; return & a_pThis -> pDIV_FUs [ i ] ; } } return NULL ; default : return NULL ; } }
This function looks for an avaliabale Functional Unit based on the opcode
 and returns the pointer to it, If there isn't avilable FU return NULL
This function looks for an avaliabale Functional Unit based on the opcode and returns the pointer to it If there isn ' t avilable FU return NULL
/* Means no FU is available */ /* Means no FU is available */ /* Means no FU is available */ /* Means no FU is available */ /* Means no FU is available */ /* Means no FU is available */