Skip to content

Commit

Permalink
run presumably done
Browse files Browse the repository at this point in the history
  • Loading branch information
hagary committed Nov 28, 2016
1 parent 96ce903 commit 3046d09
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 17 deletions.
85 changes: 70 additions & 15 deletions src/simulator/Simulator.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package simulator;

import instructions.Instruction;
import instructions.state;

import java.awt.Window.Type;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Writer;
import java.util.Scanner;

import memory.Cache;
Expand All @@ -15,8 +19,12 @@
import memory.WriteMissPolicy;
import registers.Register;
import registers.RegisterFile;
import tomasulo.Executer;
import tomasulo.InsQueue;
import tomasulo.Issuer;
import tomasulo.Op;
import tomasulo.ROB;
import tomasulo.ROBEntry;

public class Simulator {
private static MemoryHierarchy dataMem;
Expand All @@ -35,27 +43,74 @@ public static void main (String[]args){
run();
}
public static void preRun(){
//TODO initialize PC with startAddress
PC.setData(startAddress);
}
public static void run(){
short currInsAddr = 0;
short currInsAddr = PC.getData();
do
{
cyclesCount++;
/* TODO for loop pipeline-width times plus check there's a place
* in the InsQueue:
* 1. Read address value from PC
* 2. Read Instruction from instructionsMem
* 3. Update PC
* 4. If it's any kind of branch predict if needed and execute instantly
* 5. Enqueue the instruction in the InsQueue
* 6. Call Issuer to start issuing the instruction waiting at the head of the InsQueue
*/
while()

}while(! ROB.isEmpty());
/* ----------- COMMIT PHASE ------------*/
if(!ROB.isEmpty()){
Instruction ins = ROB.peek().getInstruction();
if(ins.getState() == state.WRITTEN){
if(Committer.canCommit(ins)){
Committer.commit(ins);
}
}
}
/* ----------- WRITE PHASE ------------*/
for (ROBEntry r : ROB.getROBTable()) {
Instruction ins = r.getInstruction();
if(ins.getState() == state.EXECUTED){
if(Writer.canWrite(ins)){
Writer.write(ins);
break; //to ensure on write only per cycle
}
}
}
/* ----------- EXECUTE PHASE ------------*/
for (ROBEntry r : ROB.getROBTable()) {
Instruction ins = r.getInstruction();
if(ins.getState() == state.ISSUED){
if(Executer.canExecute(ins)){
Executer.execute(ins);
}
}
}
/* ----------- ISSUE PHASE ------------*/
if(!insQueue.isEmpty()){
int p = Issuer.getPipelineWidth();
for (int i = 0; i < p; i++) {
Instruction ins = insQueue.peek();
if(Issuer.canIssue(ins)){
Issuer.issue(ins);
insQueue.dequeue();
}
else {
break; //We have to issue in order
}
}
}
/* ----------- FETCH PHASE ------------*/
while(!insQueue.isFull()) // TODO check PC less than end address
{
Word insWord = instructionsMem.readWord(PC.getData());
Instruction ins = Assembler.assemblyToInstruction(insWord.getData());
Op insOp = ins.getOP();
if( insOp == Op.JMP || insOp == Op.JALR || insOp == Op.RET){
short nextInstAddr = ins.execute(null);
PC.setData(nextInstAddr);
}
else {
PC.setData((short)(PC.getData() + 1));
insQueue.enqueue(ins);
}
}

}while(!ROB.isEmpty());
}

public static void userInput(){
Scanner sc=new Scanner(System.in);
System.out.println("-----MEMORY INPUT------");
Expand Down
4 changes: 2 additions & 2 deletions src/tomasulo/Executer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
public class Executer {


public boolean canExecute(Instruction i){
public static boolean canExecute(Instruction i){

if(i.getState()==state.ISSUED&&i.getRS().getQj()==null && i.getRS().getQk()==null)
return true;
else return false;
}

public void Execute(Instruction i){
public static void execute(Instruction i){
int x=i.getExCycles()-1;
i.setExCycles(x);
if(i.getExCycles()==0)
Expand Down

0 comments on commit 3046d09

Please sign in to comment.