even odd.out is working
This commit is contained in:
parent
3f38e8f432
commit
783e72c4ed
|
@ -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,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>
|
|
@ -45,7 +45,7 @@ public class Processor {
|
|||
MA_RW_Latch = new MA_RW_LatchType();
|
||||
|
||||
IFUnit = new InstructionFetch(this, IF_EnableLatch, IF_OF_Latch, EX_IF_Latch);
|
||||
OFUnit = new OperandFetch(this, IF_OF_Latch, OF_EX_Latch);
|
||||
OFUnit = new OperandFetch(this, IF_OF_Latch, OF_EX_Latch, IF_EnableLatch);
|
||||
EXUnit = new Execute(this, OF_EX_Latch, EX_MA_Latch, EX_IF_Latch);
|
||||
MAUnit = new MemoryAccess(this, EX_MA_Latch, MA_RW_Latch);
|
||||
RWUnit = new RegisterWrite(this, MA_RW_Latch, IF_EnableLatch);
|
||||
|
|
|
@ -3,10 +3,12 @@ package processor.pipeline;
|
|||
public class IF_EnableLatchType {
|
||||
|
||||
boolean IF_enable;
|
||||
boolean freeze;
|
||||
|
||||
public IF_EnableLatchType()
|
||||
{
|
||||
IF_enable = true;
|
||||
freeze = false;
|
||||
}
|
||||
|
||||
public boolean isIF_enable() {
|
||||
|
@ -17,4 +19,12 @@ public class IF_EnableLatchType {
|
|||
IF_enable = iF_enable;
|
||||
}
|
||||
|
||||
public boolean isFreeze() {
|
||||
return freeze;
|
||||
}
|
||||
|
||||
public void setFreeze(boolean freeze) {
|
||||
this.freeze = freeze;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class InstructionFetch {
|
|||
}
|
||||
|
||||
public void performIF()
|
||||
{
|
||||
{ if(!IF_EnableLatch.isFreeze()){
|
||||
if(EX_IF_Latch.isIF_enable()){
|
||||
containingProcessor.getRegisterFile().setProgramCounter(EX_IF_Latch.getPC()-1);
|
||||
EX_IF_Latch.setIF_enable(false);
|
||||
|
@ -34,6 +34,9 @@ public class InstructionFetch {
|
|||
IF_EnableLatch.setIF_enable(true);
|
||||
IF_OF_Latch.setOF_enable(true);
|
||||
}
|
||||
}else{
|
||||
IF_EnableLatch.setFreeze(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package processor.pipeline;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import generic.Instruction;
|
||||
import processor.Processor;
|
||||
|
@ -12,15 +14,38 @@ public class OperandFetch {
|
|||
Processor containingProcessor;
|
||||
IF_OF_LatchType IF_OF_Latch;
|
||||
OF_EX_LatchType OF_EX_Latch;
|
||||
IF_EnableLatchType IF_EnableLatch;
|
||||
static OperationType[] opTypes = OperationType.values();
|
||||
boolean Proceed;
|
||||
Queue<Integer> queue;
|
||||
boolean isEnd;
|
||||
|
||||
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, IF_EnableLatchType iF_EnableLatch)
|
||||
{
|
||||
this.containingProcessor = containingProcessor;
|
||||
this.IF_OF_Latch = iF_OF_Latch;
|
||||
this.OF_EX_Latch = oF_EX_Latch;
|
||||
this.IF_EnableLatch = iF_EnableLatch;
|
||||
isEnd = false;
|
||||
Proceed = true;
|
||||
queue = new LinkedList<>();
|
||||
queue.add(-1);
|
||||
queue.add(-1);
|
||||
queue.add(-1);
|
||||
}
|
||||
|
||||
boolean checkdatahazard(int[] operands) {
|
||||
for(int i=0;i<operands.length;i++) {
|
||||
if(queue.contains(operands[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void updateQueue(int operand) {
|
||||
queue.poll();
|
||||
queue.add(operand);
|
||||
}
|
||||
|
||||
public static int twoscompliment(String s) {
|
||||
|
@ -40,6 +65,14 @@ public class OperandFetch {
|
|||
|
||||
public void performOF()
|
||||
{
|
||||
if(isEnd){
|
||||
IF_EnableLatch.setIF_enable(false);
|
||||
IF_OF_Latch.setOF_enable(false);
|
||||
OF_EX_Latch.setEX_enable(false);
|
||||
return;
|
||||
}
|
||||
int addtoqueue = -1;
|
||||
boolean noDataHazard = true;
|
||||
if(IF_OF_Latch.isOF_enable() && Proceed)
|
||||
{
|
||||
int instruction = IF_OF_Latch.getInstruction();
|
||||
|
@ -76,7 +109,10 @@ public class OperandFetch {
|
|||
|
||||
int op1 = containingProcessor.getRegisterFile().getValue(rs1.getValue());
|
||||
int op2 = containingProcessor.getRegisterFile().getValue(rs2.getValue());
|
||||
|
||||
if (checkdatahazard(new int[] { rs1.getValue(), rs2.getValue() })) {
|
||||
noDataHazard = false;
|
||||
}else{
|
||||
addtoqueue = rd.getValue();
|
||||
OF_EX_Latch.setInstruction(instr);
|
||||
OF_EX_Latch.setOp1(op1);
|
||||
OF_EX_Latch.setOp2(op2);
|
||||
|
@ -84,6 +120,7 @@ public class OperandFetch {
|
|||
instr.setSourceOperand1(rs1);
|
||||
instr.setSourceOperand2(rs2);
|
||||
}
|
||||
}
|
||||
else if (Arrays.stream(R2I_type_operators).anyMatch(x -> x == opcode)) {
|
||||
Operand rs1 = new Operand();
|
||||
Operand rd = new Operand();
|
||||
|
@ -100,18 +137,25 @@ public class OperandFetch {
|
|||
}
|
||||
int op1 = containingProcessor.getRegisterFile().getValue(rs1.getValue());
|
||||
int op2 = containingProcessor.getRegisterFile().getValue(rd.getValue());
|
||||
System.out.println("imm: " + imm);
|
||||
// System.out.println("imm: " + imm);
|
||||
|
||||
if (checkdatahazard(new int[] { rs1.getValue() })) {
|
||||
noDataHazard = false;
|
||||
}else{
|
||||
if(opcode <= 22) { // > 21 means it is a branch instruction so no need to update queue
|
||||
addtoqueue = rd.getValue();
|
||||
}
|
||||
OF_EX_Latch.setInstruction(instr);
|
||||
OF_EX_Latch.setImm(imm);
|
||||
OF_EX_Latch.setOp1(op1);
|
||||
OF_EX_Latch.setOp2(op2);
|
||||
|
||||
System.out.println("op1: " + op1);
|
||||
System.out.println("op2: " + rd);
|
||||
instr.setDestinationOperand(rd);
|
||||
instr.setSourceOperand1(rs1);
|
||||
}
|
||||
// if(opcode == 22){
|
||||
|
||||
// }
|
||||
}
|
||||
else if (Arrays.stream(R1I_type_operators).anyMatch(x -> x == opcode)) {
|
||||
if(opcode != 24){
|
||||
Operand rd = new Operand();
|
||||
|
@ -125,11 +169,16 @@ public class OperandFetch {
|
|||
imm = -1*twoscompliment(bin_instr.substring(10, 32));
|
||||
System.out.println(bin_instr);
|
||||
}
|
||||
System.out.println("imm: " + imm);
|
||||
// if (checkdatahazard(new int[] { rd.getValue() })) {
|
||||
// noDataHazard = false;
|
||||
// }else{
|
||||
containingProcessor.getRegisterFile().setProgramCounter(containingProcessor.getRegisterFile().getProgramCounter()-1);
|
||||
OF_EX_Latch.setInstruction(instr);
|
||||
OF_EX_Latch.setImm(imm);
|
||||
isEnd = true;
|
||||
// }
|
||||
}
|
||||
else{
|
||||
else{ // opcode == 24 jmp
|
||||
Operand op = new Operand();
|
||||
String imm = bin_instr.substring(10, 32);
|
||||
int imm_val = Integer.parseInt(imm, 2);
|
||||
|
@ -146,16 +195,26 @@ public class OperandFetch {
|
|||
op.setValue(Integer.parseInt(bin_instr.substring(5, 10), 2));
|
||||
instr.setSourceOperand1(op);
|
||||
}
|
||||
if (checkdatahazard(new int[] { op.getValue() })) {
|
||||
noDataHazard = false;
|
||||
}else{
|
||||
OF_EX_Latch.setInstruction(instr);
|
||||
OF_EX_Latch.setImm(imm_val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OF_EX_Latch.setEX_enable(true);
|
||||
OF_EX_Latch.setEX_enable(noDataHazard);
|
||||
if(!noDataHazard){
|
||||
IF_EnableLatch.setFreeze(true);
|
||||
System.out.println("\n\nData Hazard - Interlock\n\n");
|
||||
}
|
||||
}
|
||||
else if (!Proceed) {
|
||||
Proceed = true;
|
||||
System.out.println("\n\nControl Hazard - Interlock\n\n");
|
||||
}
|
||||
updateQueue(addtoqueue);
|
||||
}
|
||||
|
||||
public void setProceed(boolean proceed) {
|
||||
|
|
|
@ -24,7 +24,7 @@ public class RegisterWrite {
|
|||
Instruction instruction = MA_RW_Latch.getInstruction();
|
||||
OperationType op_type = instruction.getOperationType();
|
||||
int alu_result = MA_RW_Latch.getALU_result();
|
||||
|
||||
boolean proceed = true;
|
||||
if (op_type==OperationType.load)
|
||||
{
|
||||
int load_result = MA_RW_Latch.getLoad_result();
|
||||
|
@ -34,6 +34,7 @@ public class RegisterWrite {
|
|||
else if (op_type==OperationType.end)
|
||||
{
|
||||
Simulator.setSimulationComplete(true);
|
||||
proceed = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -44,8 +45,19 @@ public class RegisterWrite {
|
|||
containingProcessor.getRegisterFile().setValue(rd, alu_result);
|
||||
}
|
||||
}
|
||||
IF_EnableLatch.setIF_enable(proceed);
|
||||
}else{
|
||||
try{
|
||||
if(MA_RW_Latch.getInstruction().getOperationType() == OperationType.end){
|
||||
IF_EnableLatch.setIF_enable(false);
|
||||
}
|
||||
else{
|
||||
IF_EnableLatch.setIF_enable(true);
|
||||
}
|
||||
} catch(Exception e){
|
||||
IF_EnableLatch.setIF_enable(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue