made it as a pipelined process except for data hazards
This commit is contained in:
parent
16be400268
commit
3f38e8f432
|
@ -8,7 +8,8 @@
|
||||||
"type": "java",
|
"type": "java",
|
||||||
"name": "Launch Current File",
|
"name": "Launch Current File",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mainClass": "${file}"
|
"mainClass": "${file}",
|
||||||
|
"args": ["assignment-4/src/configuration/config.xml", "assignment-4/src/hello.txt", "assignment-4/supporting_files/test_cases/evenorodd.out"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "java",
|
"type": "java",
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- WARNING: Eclipse auto-generated file.
|
||||||
|
Any modifications will be overwritten.
|
||||||
|
To include a user specific buildfile here, simply create one in the same
|
||||||
|
directory with the processing instruction <?eclipse.ant.import?>
|
||||||
|
as the first entry and export the buildfile again. --><project basedir="." default="build">
|
||||||
|
<property environment="env"/>
|
||||||
|
<property name="debuglevel" value="source,lines,vars"/>
|
||||||
|
<property name="target" value="1.8"/>
|
||||||
|
<property name="source" value="1.8"/>
|
||||||
|
<target name="init">
|
||||||
|
<mkdir dir="bin"/>
|
||||||
|
<copy includeemptydirs="false" todir="bin">
|
||||||
|
<fileset dir="src">
|
||||||
|
<exclude name="**/*.launch"/>
|
||||||
|
<exclude name="**/*.java"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
<target name="clean">
|
||||||
|
<delete dir="bin"/>
|
||||||
|
</target>
|
||||||
|
<target depends="clean" name="cleanall"/>
|
||||||
|
<target depends="build-subprojects,build-project" name="build"/>
|
||||||
|
<target name="build-subprojects"/>
|
||||||
|
<target depends="init" name="build-project">
|
||||||
|
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
|
||||||
|
<src path="src"/>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
<target name="make-jar" depends="build">
|
||||||
|
<mkdir dir="jars"/>
|
||||||
|
<jar destfile="jars/simulator.jar" basedir="bin">
|
||||||
|
<manifest>
|
||||||
|
<attribute name="Main-Class" value="main.Main"/>
|
||||||
|
</manifest>
|
||||||
|
</jar>
|
||||||
|
</target>
|
||||||
|
</project>
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||||
|
<Configuration>
|
||||||
|
<FunctionalUnits>
|
||||||
|
<ALU>
|
||||||
|
<Count>2</Count>
|
||||||
|
<Latency>1</Latency>
|
||||||
|
<ReciprocalOfThroughput>1</ReciprocalOfThroughput>
|
||||||
|
</ALU>
|
||||||
|
<Multiplier>
|
||||||
|
<Count>1</Count>
|
||||||
|
<Latency>4</Latency>
|
||||||
|
<ReciprocalOfThroughput>1</ReciprocalOfThroughput>
|
||||||
|
</Multiplier>
|
||||||
|
<Divider>
|
||||||
|
<Count>1</Count>
|
||||||
|
<Latency>10</Latency>
|
||||||
|
<ReciprocalOfThroughput>1</ReciprocalOfThroughput>
|
||||||
|
</Divider>
|
||||||
|
</FunctionalUnits>
|
||||||
|
|
||||||
|
<L1iCache>
|
||||||
|
<NumberOfLines>256</NumberOfLines>
|
||||||
|
<Latency>2</Latency>
|
||||||
|
<Associativity>4</Associativity>
|
||||||
|
<ReplacementPolicy>LRU</ReplacementPolicy>
|
||||||
|
</L1iCache>
|
||||||
|
|
||||||
|
<L1dCache>
|
||||||
|
<NumberOfLines>256</NumberOfLines>
|
||||||
|
<Latency>2</Latency>
|
||||||
|
<Associativity>4</Associativity>
|
||||||
|
<ReplacementPolicy>LRU</ReplacementPolicy>
|
||||||
|
</L1dCache>
|
||||||
|
|
||||||
|
<L2Cache>
|
||||||
|
<NumberOfLines>2048</NumberOfLines>
|
||||||
|
<Latency>10</Latency>
|
||||||
|
<Associativity>4</Associativity>
|
||||||
|
<ReplacementPolicy>LRU</ReplacementPolicy>
|
||||||
|
</L2Cache>
|
||||||
|
|
||||||
|
<MainMemoryLatency>40</MainMemoryLatency>
|
||||||
|
</Configuration>
|
|
@ -0,0 +1,2 @@
|
||||||
|
Number of instructions executed = 10
|
||||||
|
Number of cycles taken = 10
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- WARNING: Eclipse auto-generated file.
|
||||||
|
Any modifications will be overwritten.
|
||||||
|
To include a user specific buildfile here, simply create one in the same
|
||||||
|
directory with the processing instruction <?eclipse.ant.import?>
|
||||||
|
as the first entry and export the buildfile again. --><project basedir="." default="build">
|
||||||
|
<property environment="env"/>
|
||||||
|
<property name="debuglevel" value="source,lines,vars"/>
|
||||||
|
<property name="target" value="1.8"/>
|
||||||
|
<property name="source" value="1.8"/>
|
||||||
|
<target name="init">
|
||||||
|
<mkdir dir="bin"/>
|
||||||
|
<copy includeemptydirs="false" todir="bin">
|
||||||
|
<fileset dir="src">
|
||||||
|
<exclude name="**/*.launch"/>
|
||||||
|
<exclude name="**/*.java"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
<target name="clean">
|
||||||
|
<delete dir="bin"/>
|
||||||
|
</target>
|
||||||
|
<target depends="clean" name="cleanall"/>
|
||||||
|
<target depends="build-subprojects,build-project" name="build"/>
|
||||||
|
<target name="build-subprojects"/>
|
||||||
|
<target depends="init" name="build-project">
|
||||||
|
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
|
||||||
|
<src path="src"/>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
<target name="make-jar" depends="build">
|
||||||
|
<mkdir dir="jars"/>
|
||||||
|
<jar destfile="jars/simulator.jar" basedir="bin">
|
||||||
|
<manifest>
|
||||||
|
<attribute name="Main-Class" value="main.Main"/>
|
||||||
|
</manifest>
|
||||||
|
</jar>
|
||||||
|
</target>
|
||||||
|
</project>
|
|
@ -0,0 +1,2 @@
|
||||||
|
Number of instructions executed = 11
|
||||||
|
Number of cycles taken = 11
|
|
@ -3,7 +3,6 @@ import processor.Processor;
|
||||||
|
|
||||||
import generic.Instruction;
|
import generic.Instruction;
|
||||||
import generic.Instruction.OperationType;
|
import generic.Instruction.OperationType;
|
||||||
import generic.Simulator;
|
|
||||||
import generic.Operand.OperandType;
|
import generic.Operand.OperandType;
|
||||||
|
|
||||||
public class Execute {
|
public class Execute {
|
||||||
|
@ -109,10 +108,11 @@ public class Execute {
|
||||||
{
|
{
|
||||||
if(op1 == op2)
|
if(op1 == op2)
|
||||||
{
|
{
|
||||||
alu_result = cur_pc + imm;
|
|
||||||
EX_IF_Latch.setIF_enable(true);
|
EX_IF_Latch.setIF_enable(true);
|
||||||
|
alu_result = cur_pc + imm;
|
||||||
EX_IF_Latch.setPC(alu_result);
|
EX_IF_Latch.setPC(alu_result);
|
||||||
noma = true;
|
noma = true;
|
||||||
|
containingProcessor.getOFUnit().setProceed(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -136,9 +136,10 @@ public class Execute {
|
||||||
EX_IF_Latch.setIF_enable(true);
|
EX_IF_Latch.setIF_enable(true);
|
||||||
EX_IF_Latch.setPC(alu_result);
|
EX_IF_Latch.setPC(alu_result);
|
||||||
noma = true;
|
noma = true;
|
||||||
System.out.println("hello world");
|
containingProcessor.getOFUnit().setProceed(false);
|
||||||
|
// System.out.println("hello world");
|
||||||
}
|
}
|
||||||
System.out.println("hello world2");
|
// System.out.println("hello world2");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case bgt:
|
case bgt:
|
||||||
|
@ -154,7 +155,8 @@ public class Execute {
|
||||||
break;
|
break;
|
||||||
case end:
|
case end:
|
||||||
{
|
{
|
||||||
Simulator.setSimulationComplete(true);
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -169,7 +171,6 @@ public class Execute {
|
||||||
{
|
{
|
||||||
EX_MA_Latch.setMA_enable(true);
|
EX_MA_Latch.setMA_enable(true);
|
||||||
}
|
}
|
||||||
OF_EX_Latch.setEX_enable(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,19 +21,18 @@ public class InstructionFetch {
|
||||||
{
|
{
|
||||||
if(EX_IF_Latch.isIF_enable()){
|
if(EX_IF_Latch.isIF_enable()){
|
||||||
containingProcessor.getRegisterFile().setProgramCounter(EX_IF_Latch.getPC()-1);
|
containingProcessor.getRegisterFile().setProgramCounter(EX_IF_Latch.getPC()-1);
|
||||||
|
EX_IF_Latch.setIF_enable(false);
|
||||||
System.out.println("IF: PC set to " + EX_IF_Latch.getPC());
|
System.out.println("IF: PC set to " + EX_IF_Latch.getPC());
|
||||||
}
|
} // if EX_IF_Latch is enabled, set PC to EX_IF_Latch's PC and wait for next cycle (1 nop)
|
||||||
if(IF_EnableLatch.isIF_enable()|| EX_IF_Latch.isIF_enable())
|
else if(IF_EnableLatch.isIF_enable())
|
||||||
{
|
{
|
||||||
int currentPC = containingProcessor.getRegisterFile().getProgramCounter();
|
int currentPC = containingProcessor.getRegisterFile().getProgramCounter();
|
||||||
int newInstruction = containingProcessor.getMainMemory().getWord(currentPC);
|
int newInstruction = containingProcessor.getMainMemory().getWord(currentPC);
|
||||||
IF_OF_Latch.setInstruction(newInstruction);
|
IF_OF_Latch.setInstruction(newInstruction);
|
||||||
containingProcessor.getRegisterFile().setProgramCounter(currentPC + 1);
|
containingProcessor.getRegisterFile().setProgramCounter(currentPC + 1);
|
||||||
|
|
||||||
IF_EnableLatch.setIF_enable(false);
|
IF_EnableLatch.setIF_enable(true);
|
||||||
IF_OF_Latch.setOF_enable(true);
|
IF_OF_Latch.setOF_enable(true);
|
||||||
EX_IF_Latch.setIF_enable(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ public class MemoryAccess {
|
||||||
}
|
}
|
||||||
MA_RW_Latch.setInstruction(instruction);
|
MA_RW_Latch.setInstruction(instruction);
|
||||||
MA_RW_Latch.setRW_enable(true);
|
MA_RW_Latch.setRW_enable(true);
|
||||||
EX_MA_Latch.setMA_enable(false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,14 @@ public class OperandFetch {
|
||||||
IF_OF_LatchType IF_OF_Latch;
|
IF_OF_LatchType IF_OF_Latch;
|
||||||
OF_EX_LatchType OF_EX_Latch;
|
OF_EX_LatchType OF_EX_Latch;
|
||||||
static OperationType[] opTypes = OperationType.values();
|
static OperationType[] opTypes = OperationType.values();
|
||||||
|
boolean Proceed;
|
||||||
|
|
||||||
public OperandFetch(Processor containingProcessor, IF_OF_LatchType iF_OF_Latch, OF_EX_LatchType oF_EX_Latch)
|
public OperandFetch(Processor containingProcessor, IF_OF_LatchType iF_OF_Latch, OF_EX_LatchType oF_EX_Latch)
|
||||||
{
|
{
|
||||||
this.containingProcessor = containingProcessor;
|
this.containingProcessor = containingProcessor;
|
||||||
this.IF_OF_Latch = iF_OF_Latch;
|
this.IF_OF_Latch = iF_OF_Latch;
|
||||||
this.OF_EX_Latch = oF_EX_Latch;
|
this.OF_EX_Latch = oF_EX_Latch;
|
||||||
|
Proceed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int twoscompliment(String s) {
|
public static int twoscompliment(String s) {
|
||||||
|
@ -38,12 +40,12 @@ public class OperandFetch {
|
||||||
|
|
||||||
public void performOF()
|
public void performOF()
|
||||||
{
|
{
|
||||||
if(IF_OF_Latch.isOF_enable())
|
if(IF_OF_Latch.isOF_enable() && Proceed)
|
||||||
{
|
{
|
||||||
int instruction = IF_OF_Latch.getInstruction();
|
int instruction = IF_OF_Latch.getInstruction();
|
||||||
Instruction instr = new Instruction();
|
Instruction instr = new Instruction();
|
||||||
String bin_instr = Integer.toBinaryString(instruction);
|
String bin_instr = Integer.toBinaryString(instruction);
|
||||||
if (bin_instr.length() < 32) { // TODO: check if this is correct
|
if (bin_instr.length() < 32) {
|
||||||
int diff = 32 - bin_instr.length();
|
int diff = 32 - bin_instr.length();
|
||||||
String zeros = "";
|
String zeros = "";
|
||||||
for (int i = 0; i < diff; i++) {
|
for (int i = 0; i < diff; i++) {
|
||||||
|
@ -91,7 +93,7 @@ public class OperandFetch {
|
||||||
rs1.setValue(Integer.parseInt(bin_instr.substring(5, 10), 2));
|
rs1.setValue(Integer.parseInt(bin_instr.substring(5, 10), 2));
|
||||||
rd.setValue(Integer.parseInt(bin_instr.substring(10, 15), 2));
|
rd.setValue(Integer.parseInt(bin_instr.substring(10, 15), 2));
|
||||||
// check 15th bit to see if it is negative
|
// check 15th bit to see if it is negative
|
||||||
int imm = Integer.parseInt(bin_instr.substring(15, 32), 2); // TODO: 2's complement
|
int imm = Integer.parseInt(bin_instr.substring(15, 32), 2);
|
||||||
if (bin_instr.charAt(15)=='1'){
|
if (bin_instr.charAt(15)=='1'){
|
||||||
imm = -1*twoscompliment(bin_instr.substring(15, 32));
|
imm = -1*twoscompliment(bin_instr.substring(15, 32));
|
||||||
System.out.println(bin_instr);
|
System.out.println(bin_instr);
|
||||||
|
@ -118,7 +120,7 @@ public class OperandFetch {
|
||||||
|
|
||||||
instr.setDestinationOperand(rd);
|
instr.setDestinationOperand(rd);
|
||||||
|
|
||||||
int imm = Integer.parseInt(bin_instr.substring(10, 32), 2); // TODO: 2's complement
|
int imm = Integer.parseInt(bin_instr.substring(10, 32), 2);
|
||||||
if (bin_instr.charAt(10)=='1'){
|
if (bin_instr.charAt(10)=='1'){
|
||||||
imm = -1*twoscompliment(bin_instr.substring(10, 32));
|
imm = -1*twoscompliment(bin_instr.substring(10, 32));
|
||||||
System.out.println(bin_instr);
|
System.out.println(bin_instr);
|
||||||
|
@ -149,9 +151,18 @@ public class OperandFetch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IF_OF_Latch.setOF_enable(false);
|
|
||||||
OF_EX_Latch.setEX_enable(true);
|
OF_EX_Latch.setEX_enable(true);
|
||||||
}
|
}
|
||||||
|
else if (!Proceed) {
|
||||||
|
Proceed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProceed(boolean proceed) {
|
||||||
|
Proceed = proceed;
|
||||||
|
if (!Proceed) {
|
||||||
|
OF_EX_Latch.setEX_enable(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,6 @@ public class RegisterWrite {
|
||||||
containingProcessor.getRegisterFile().setValue(rd, alu_result);
|
containingProcessor.getRegisterFile().setValue(rd, alu_result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MA_RW_Latch.setRW_enable(false);
|
|
||||||
IF_EnableLatch.setIF_enable(true);
|
IF_EnableLatch.setIF_enable(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue