improper datahazard
This commit is contained in:
parent
e8e0b9ab4a
commit
b06e33f8de
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Launch Current File",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "${file}",
|
||||||
|
"args": ["src/configuration/config.xml", "src/hello.txt", "supporting_files/test_cases/descending.out"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Launch Main",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "main.Main",
|
||||||
|
"projectName": "assignment-5_d93382a5"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
Number of instructions executed = 29
|
Number of instructions executed = 6
|
||||||
Number of cycles taken = 1169
|
Number of cycles taken = 252
|
||||||
Number of data hazards = 0
|
Number of data hazards = 7
|
||||||
Number of control hazards = 10
|
Number of control hazards = 0
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
Number of instructions executed = 277
|
Number of instructions executed = 263
|
||||||
Number of cycles taken = 11172
|
Number of cycles taken = 13761
|
||||||
Number of data hazards = 0
|
Number of data hazards = 203
|
||||||
Number of control hazards = 176
|
Number of control hazards = 164
|
||||||
|
|
|
@ -9,6 +9,7 @@ public class EX_MA_LatchType {
|
||||||
Operand op2;
|
Operand op2;
|
||||||
Instruction instruction;
|
Instruction instruction;
|
||||||
int aluResult;
|
int aluResult;
|
||||||
|
boolean MA_busy;
|
||||||
|
|
||||||
public EX_MA_LatchType()
|
public EX_MA_LatchType()
|
||||||
{
|
{
|
||||||
|
@ -47,4 +48,12 @@ public class EX_MA_LatchType {
|
||||||
MA_enable = mA_enable;
|
MA_enable = mA_enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMA_busy() {
|
||||||
|
return MA_busy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMA_busy(boolean mA_busy) {
|
||||||
|
MA_busy = mA_busy;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,13 @@ public class Execute implements Element{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(Event e) {
|
public void handleEvent(Event e) {
|
||||||
|
|
||||||
|
if(EX_MA_Latch.isMA_busy()){
|
||||||
|
e.setEventTime(e.getEventTime()+1);
|
||||||
|
Simulator.getEventQueue().addEvent(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int op1 = OF_EX_Latch.getOp1();
|
int op1 = OF_EX_Latch.getOp1();
|
||||||
int op2 = OF_EX_Latch.getOp2();
|
int op2 = OF_EX_Latch.getOp2();
|
||||||
int imm = OF_EX_Latch.getImm();
|
int imm = OF_EX_Latch.getImm();
|
||||||
|
|
|
@ -6,6 +6,7 @@ public class IF_OF_LatchType {
|
||||||
int instruction;
|
int instruction;
|
||||||
boolean IF_busy=false;
|
boolean IF_busy=false;
|
||||||
boolean IF_branching_busy=false;
|
boolean IF_branching_busy=false;
|
||||||
|
boolean OF_busy=false;
|
||||||
|
|
||||||
public IF_OF_LatchType()
|
public IF_OF_LatchType()
|
||||||
{
|
{
|
||||||
|
@ -43,4 +44,13 @@ public class IF_OF_LatchType {
|
||||||
public void setIF_branching_busy(boolean iF_branching_busy) {
|
public void setIF_branching_busy(boolean iF_branching_busy) {
|
||||||
IF_branching_busy = iF_branching_busy;
|
IF_branching_busy = iF_branching_busy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isOF_busy() {
|
||||||
|
return OF_busy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOF_busy(boolean oF_busy) {
|
||||||
|
OF_busy = oF_busy;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class InstructionFetch implements Element{
|
||||||
|
|
||||||
public void performIF()
|
public void performIF()
|
||||||
{
|
{
|
||||||
if(EX_IF_Latch.isIF_enable() && !IF_OF_Latch.isIF_branching_busy()){
|
if(EX_IF_Latch.isIF_enable() && !IF_OF_Latch.isIF_branching_busy() &&!IF_OF_Latch.isIF_busy()){
|
||||||
containingProcessor.getRegisterFile().setProgramCounter(EX_IF_Latch.getPC());
|
containingProcessor.getRegisterFile().setProgramCounter(EX_IF_Latch.getPC());
|
||||||
int currentPC = containingProcessor.getRegisterFile().getProgramCounter();
|
int currentPC = containingProcessor.getRegisterFile().getProgramCounter();
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ public class InstructionFetch implements Element{
|
||||||
currentPC
|
currentPC
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
System.out.println("H1");
|
||||||
IF_OF_Latch.setIF_branching_busy(true);
|
IF_OF_Latch.setIF_branching_busy(true);
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +49,7 @@ public class InstructionFetch implements Element{
|
||||||
} // if EX_IF_Latch is enabled, set PC to EX_IF_Latch's PC and wait for next cycle (1 nop)
|
} // if EX_IF_Latch is enabled, set PC to EX_IF_Latch's PC and wait for next cycle (1 nop)
|
||||||
else if(IF_EnableLatch.isIF_enable())
|
else if(IF_EnableLatch.isIF_enable())
|
||||||
{
|
{
|
||||||
|
if(!IF_EnableLatch.isFreeze()){
|
||||||
if(IF_OF_Latch.isIF_busy()){
|
if(IF_OF_Latch.isIF_busy()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -64,14 +66,25 @@ public class InstructionFetch implements Element{
|
||||||
currentPC
|
currentPC
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
System.out.println("H2");
|
||||||
IF_OF_Latch.setIF_busy(true);
|
IF_OF_Latch.setIF_busy(true);
|
||||||
IF_OF_Latch.setOF_enable(false);
|
IF_OF_Latch.setOF_enable(false);
|
||||||
|
}else{
|
||||||
|
IF_EnableLatch.setFreeze(false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(Event e) {
|
public void handleEvent(Event e) {
|
||||||
|
if(IF_OF_Latch.isOF_busy()|| IF_EnableLatch.isFreeze()){
|
||||||
|
e.setEventTime(Clock.getCurrentTime()+1);
|
||||||
|
Simulator.getEventQueue().addEvent(e);
|
||||||
|
IF_EnableLatch.setFreeze(false);
|
||||||
|
IF_OF_Latch.setOF_enable(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(IF_OF_Latch.isIF_branching_busy()){
|
if(IF_OF_Latch.isIF_branching_busy()){
|
||||||
IF_EnableLatch.setFreeze(false);
|
IF_EnableLatch.setFreeze(false);
|
||||||
IF_OF_Latch.setIF_branching_busy(false);
|
IF_OF_Latch.setIF_branching_busy(false);
|
||||||
|
@ -84,6 +97,7 @@ public class InstructionFetch implements Element{
|
||||||
containingProcessor.getRegisterFile().setProgramCounter(containingProcessor.getRegisterFile().getProgramCounter() + 1);
|
containingProcessor.getRegisterFile().setProgramCounter(containingProcessor.getRegisterFile().getProgramCounter() + 1);
|
||||||
IF_OF_Latch.setOF_enable(true);
|
IF_OF_Latch.setOF_enable(true);
|
||||||
IF_OF_Latch.setIF_busy(false);
|
IF_OF_Latch.setIF_busy(false);
|
||||||
|
IF_EnableLatch.setFreeze(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
package processor.pipeline;
|
package processor.pipeline;
|
||||||
|
|
||||||
|
import configuration.Configuration;
|
||||||
import generic.Element;
|
import generic.Element;
|
||||||
import generic.Event;
|
import generic.Event;
|
||||||
|
import generic.ExecutionCompleteEvent;
|
||||||
import generic.Instruction;
|
import generic.Instruction;
|
||||||
|
import generic.MemoryReadEvent;
|
||||||
|
import generic.MemoryResponseEvent;
|
||||||
|
import generic.MemoryWriteEvent;
|
||||||
|
import generic.Simulator;
|
||||||
|
import processor.Clock;
|
||||||
import processor.Processor;
|
import processor.Processor;
|
||||||
import generic.Instruction.OperationType;
|
import generic.Instruction.OperationType;
|
||||||
|
|
||||||
|
@ -20,25 +27,45 @@ public class MemoryAccess implements Element {
|
||||||
|
|
||||||
public void performMA()
|
public void performMA()
|
||||||
{
|
{
|
||||||
if(EX_MA_Latch.isMA_enable())
|
if(EX_MA_Latch.isMA_enable()&& !EX_MA_Latch.isMA_busy())
|
||||||
{
|
{
|
||||||
Instruction instruction = EX_MA_Latch.getInstruction();
|
Instruction instruction = EX_MA_Latch.getInstruction();
|
||||||
int alu_result = EX_MA_Latch.getALUResult();
|
int alu_result = EX_MA_Latch.getALUResult();
|
||||||
MA_RW_Latch.setALU_result(alu_result);
|
MA_RW_Latch.setALU_result(alu_result);
|
||||||
OperationType op_type = instruction.getOperationType();
|
OperationType op_type = instruction.getOperationType();
|
||||||
|
MA_RW_Latch.setInstruction(instruction);
|
||||||
|
MA_RW_Latch.setRW_enable(true);
|
||||||
if (op_type==OperationType.store)
|
if (op_type==OperationType.store)
|
||||||
{
|
{
|
||||||
int val_store = containingProcessor.getRegisterFile().getValue(
|
int val_store = containingProcessor.getRegisterFile().getValue(
|
||||||
instruction.getSourceOperand1().getValue());
|
instruction.getSourceOperand1().getValue());
|
||||||
containingProcessor.getMainMemory().setWord(alu_result, val_store);
|
// containingProcessor.getMainMemory().setWord(alu_result, val_store);
|
||||||
|
Simulator.getEventQueue().addEvent(
|
||||||
|
new MemoryWriteEvent(
|
||||||
|
Clock.getCurrentTime()+Configuration.mainMemoryLatency,
|
||||||
|
this,
|
||||||
|
containingProcessor.getMainMemory(),
|
||||||
|
alu_result,
|
||||||
|
val_store
|
||||||
|
)
|
||||||
|
);
|
||||||
|
EX_MA_Latch.setMA_busy(true);
|
||||||
|
MA_RW_Latch.setRW_enable(false);
|
||||||
}
|
}
|
||||||
else if (op_type==OperationType.load)
|
else if (op_type==OperationType.load)
|
||||||
{
|
{
|
||||||
int load_result = containingProcessor.getMainMemory().getWord(alu_result);
|
// int load_result = containingProcessor.getMainMemory().getWord(alu_result);
|
||||||
MA_RW_Latch.setLoad_result(load_result);
|
Simulator.getEventQueue().addEvent(
|
||||||
|
new MemoryReadEvent(
|
||||||
|
Clock.getCurrentTime()+Configuration.mainMemoryLatency,
|
||||||
|
this,
|
||||||
|
containingProcessor.getMainMemory(),
|
||||||
|
alu_result
|
||||||
|
)
|
||||||
|
);
|
||||||
|
EX_MA_Latch.setMA_busy(true);
|
||||||
|
MA_RW_Latch.setRW_enable(false);
|
||||||
}
|
}
|
||||||
MA_RW_Latch.setInstruction(instruction);
|
|
||||||
MA_RW_Latch.setRW_enable(true);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +73,17 @@ public class MemoryAccess implements Element {
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(Event e) {
|
public void handleEvent(Event e) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
if(e instanceof ExecutionCompleteEvent) {
|
||||||
|
// MemoryResponseEvent event = (MemoryResponseEvent) e;
|
||||||
|
// MA_RW_Latch.setLoad_result(event.getValue());
|
||||||
|
EX_MA_Latch.setMA_busy(false);
|
||||||
|
MA_RW_Latch.setRW_enable(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MemoryResponseEvent event=(MemoryResponseEvent) e;
|
||||||
|
MA_RW_Latch.setLoad_result(event.getValue());
|
||||||
|
EX_MA_Latch.setMA_busy(false);
|
||||||
|
MA_RW_Latch.setRW_enable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ public class OperandFetch {
|
||||||
queue.add(-1);
|
queue.add(-1);
|
||||||
queue.add(-1);
|
queue.add(-1);
|
||||||
queue.add(-1);
|
queue.add(-1);
|
||||||
|
// queue.add(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean checkdatahazard(int[] operands) {
|
boolean checkdatahazard(int[] operands) {
|
||||||
|
@ -72,9 +73,16 @@ public class OperandFetch {
|
||||||
OF_EX_Latch.setEX_enable(false);
|
OF_EX_Latch.setEX_enable(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(OF_EX_Latch.isEX_busy()) {
|
||||||
|
IF_OF_Latch.setOF_busy(true);
|
||||||
|
return;
|
||||||
|
}else{
|
||||||
|
IF_OF_Latch.setOF_busy(false);
|
||||||
|
}
|
||||||
|
|
||||||
int addtoqueue = -1;
|
int addtoqueue = -1;
|
||||||
boolean noDataHazard = true;
|
boolean noDataHazard = true;
|
||||||
if(IF_OF_Latch.isOF_enable() && Proceed)
|
if(IF_OF_Latch.isOF_enable() && Proceed && !IF_OF_Latch.isOF_busy())
|
||||||
{
|
{
|
||||||
int instruction = IF_OF_Latch.getInstruction();
|
int instruction = IF_OF_Latch.getInstruction();
|
||||||
Instruction instr = new Instruction();
|
Instruction instr = new Instruction();
|
||||||
|
@ -195,16 +203,18 @@ public class OperandFetch {
|
||||||
System.out.println("\n\nData Hazard - Interlock\n\n");
|
System.out.println("\n\nData Hazard - Interlock\n\n");
|
||||||
Statistics.setDatahazards(Statistics.getDatahazards() + 1);
|
Statistics.setDatahazards(Statistics.getDatahazards() + 1);
|
||||||
}
|
}
|
||||||
OF_EX_Latch.setEX_enable(true);
|
// OF_EX_Latch.setEX_enable(true);
|
||||||
|
updateQueue(addtoqueue);
|
||||||
}
|
}
|
||||||
else if (!Proceed) {
|
else if (!Proceed) {
|
||||||
// Proceed = true;
|
// Proceed = true;
|
||||||
|
// updateQueue(addtoqueue);
|
||||||
OF_EX_Latch.setEX_enable(false);
|
OF_EX_Latch.setEX_enable(false);
|
||||||
// System.out.println("\n\nControl Hazard - Interlock\n\n");
|
// System.out.println("\n\nControl Hazard - Interlock\n\n");
|
||||||
}else{
|
}else{
|
||||||
OF_EX_Latch.setEX_enable(false);
|
OF_EX_Latch.setEX_enable(false);
|
||||||
}
|
}
|
||||||
updateQueue(addtoqueue);
|
// updateQueue(addtoqueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setisEnd(boolean isEnd) {
|
public void setisEnd(boolean isEnd) {
|
||||||
|
|
Loading…
Reference in New Issue