-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreservation_stations.c
More file actions
116 lines (100 loc) · 3.09 KB
/
reservation_stations.c
File metadata and controls
116 lines (100 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef RESERVATION_STATIONS_C_INCLUDED
#define RESERVATION_STATIONS_C_INCLUDED
#include "definitions.h"
Res_Station * ResStations;
static int last_given_resStation = 0;
void initializeResStations()
{
for(int i=0; i<num_of_reservation_stations; i++)
{
ResStations[i].isFree = true;
ResStations[i].isWaiting = false;
ResStations[i].isIssuedInTheSameCycle = false;
}
}
Res_Station* get_free_res_station()
{
static int i = 0;
for(; i<=num_of_reservation_stations; i++)
{
if(i == num_of_reservation_stations)
i = 0;
if(ResStations[i].isFree == true)
{
ResStations[i].isFree = false;
return &ResStations[i];
}
}
//return NULL;
}
bool there_are_free_res_stations()
{
for(int i=0; i<num_of_reservation_stations; i++)
if(ResStations[i].isFree == true)
return true;
return false;
}
bool res_station_is_executing()
{
for(int i=0; i<num_of_reservation_stations; i++)
if(ResStations[i].isFree == false)
return true;
return false;
}
void print_res_station()
{
for(int i =0; i<num_of_reservation_stations; i++)
if(ResStations[i].isFree == false)
fprintf(stderr, "Print the ResStations[i] values.");
}
void update_res_stations()
{
//For all reservation stations
for(int i=0; i<num_of_reservation_stations; i++)
{
//If it is free then go to the next reservation station
if(ResStations[i].isFree == true || ResStations[i].isIssuedInTheSameCycle == true)
continue;
//If reservation station is not free and not waiting
ResStations[i].cycles_remaining--;
if(ResStations[i].cycles_remaining <= 0)
{
if(there_are_free_broadcasts())
{
//TODO Here start the problems
broadcast_result(&ResStations[i].cmd.instr, execute_ASMinstr(&ResStations[i].cmd));
ResStations[i].isFree = true;
//TODO WTF?
free_functional_unit(ResStations[i].cmd);
free_registers(ResStations[i].cmd);
}
else
{
ResStations[i].stalls_before_wb++;
ResStations[i].printInfo->stalls_wb++;
}
}
}
for(int i=0; i<num_of_reservation_stations; i++)
{
if(ResStations[i].isWaiting == false || ResStations[i].isIssuedInTheSameCycle == true)
continue;
if(there_are_free_registers(ResStations[i].cmd) && there_are_free_functional_units(ResStations[i].cmd))
{
get_functional_unit(ResStations[i].cmd);
acquire_registers(ResStations[i].cmd);
ResStations[i].isWaiting = true;
}
else
{
ResStations[i].stalls_before_ex++;
ResStations[i].printInfo->stalls_ex++;
}
}
for(int i=0; i<num_of_reservation_stations; i++)
{
if(ResStations[i].isIssuedInTheSameCycle == true)
ResStations[i].isIssuedInTheSameCycle = false;
}
}
#endif // RESERVATION_STATIONS_C_INCLUDED