-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitsList.java
More file actions
108 lines (104 loc) · 3.9 KB
/
UnitsList.java
File metadata and controls
108 lines (104 loc) · 3.9 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package scoreboard;
import java.util.Hashtable;
import java.util.logging.Logger;
/**
*
* @author lovelinanand
*/
public class UnitsList {
private static final Logger LOGGER = Logger.getGlobal();
private Hashtable<String, Unit> unitsTable;
private final int cacheMiss;
public UnitsList(int cacheMiss){
this.cacheMiss = cacheMiss;
this.unitsTable = new Hashtable<String, Unit>();
this.createAlU();
this.createMUL();
this.createDiv();
this.createLD();
}
public void addUnit(String unitName, Unit unit){
this.unitsTable.put(unitName, unit);
}
private void createAlU(){
Unit ALU = new Unit("ALU", "pipelined", 1,new String[] {"ADD", "SUB"});
this.addUnit("ALU", ALU);
}
private void createDiv(){
Unit DIV = new Unit("DIV", "unpipelined", 8,new String[] {"DIV"});
this.addUnit("DIV", DIV);
}
private void createMUL(){
Unit MUL = new Unit("MUL", "pipelined", 4,new String[] {"MUL"});
this.addUnit("MUL", MUL);
}
private void createLD(){
Unit LD = new Unit("LOAD", "pipelinedVariable", 2,new String[] {"LDH","LDM","ST"});
LD.setCacheMissPenalty(this.cacheMiss);
this.addUnit("LOAD", LD);
}
public Unit getUnitByOperation(String operation){
Unit targetUnit = null;
for(String key : this.unitsTable.keySet()){
Unit tmpUnit = this.unitsTable.get(key);
if(tmpUnit.doesSupportOpt(operation)){
targetUnit = tmpUnit;
break;
}
}
return targetUnit;
}
public Unit getUnitByInstruction(Instructions inst){
Unit targetUnit;
String operation = inst.getOperation();
targetUnit = this.getUnitByOperation(operation);
return targetUnit;
}
public boolean canIssue(Instructions inst){
boolean canIssue = false;
Unit targetUnit = this.getUnitByInstruction(inst);
if(targetUnit == null){
System.out.println("Cannot find suitable functional unit for operation "+ inst);
System.exit(1);
}
if(targetUnit.isFree()){
canIssue = true;
}
return canIssue;
}
public void issue(Instructions inst){
if(this.canIssue(inst)){
Unit targetUnit = this.getUnitByInstruction(inst);
if(targetUnit == null){
LOGGER.warning(inst + " cannot find target instruction");
System.exit(0);
}
targetUnit.issue(inst);
}else{
LOGGER.warning(inst + " Issuing not issuable instruction");
}
}
public void advanceClock(RegisterList rTable){
for(String key : this.unitsTable.keySet()){
Unit targetUnit = this.unitsTable.get(key);
targetUnit.advanceClock(rTable);
}
}
public void dump(){
String leftAlignFormat = "| %-7s | %-9s | %-61s |%n";
System.out.println("Function Unit Status");
System.out.format("+---------+-----------+---------------------------------------------------------------+%n");
System.out.format("| FU Name | Status | Instruction(s) |%n");
System.out.format("+---------+-----------+---------------------------------------------------------------+%n");
for(String key : this.unitsTable.keySet()){
Unit targetUnit = this.unitsTable.get(key);
System.out.format(leftAlignFormat, targetUnit.name, targetUnit.getStatusString(), targetUnit.getProcessingInstructions());
}
System.out.format("+---------+-----------+---------------------------------------------------------------+%n");
}
}