Compare commits

..

No commits in common. "a97b8f3feb1072095dea5c4e0a230fe807b6923a" and "f242de6bc829f9096e7bfbc88d04980ccd5ccb17" have entirely different histories.

13 changed files with 58 additions and 199 deletions

View File

@ -1,18 +0,0 @@
.data
n:x5x5x5
59
.text
main:
load %x0, $n, %x3
addi %x4, 2, %x4
forloop:
div %x3, %x4, %x6
beq %x31, %x7, nonprime
addi %x4, 1, %x4
blt %x4, %x3, forloop
prime:
addi %x5, 1, %x5
end
nonprime:
subi %x5, 1, %x5
end

@ -1 +0,0 @@
Subproject commit f483ee2c38c1a35be3533c9433f7375235295d10

Binary file not shown.

Binary file not shown.

View File

@ -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>

View File

@ -1,4 +1,4 @@
Number of instructions executed = 340
Number of cycles taken = 15080
Number of data hazards = 373
Number of control hazards = 166
Number of instructions executed = 6
Number of cycles taken = 252
Number of data hazards = 7
Number of control hazards = 0

Binary file not shown.

View File

@ -1,4 +1,4 @@
Number of instructions executed = 365
Number of cycles taken = 15815
Number of data hazards = 393
Number of control hazards = 176
Number of instructions executed = 263
Number of cycles taken = 13761
Number of data hazards = 203
Number of control hazards = 164

View File

@ -1,6 +1,5 @@
package processor;
import processor.memorysystem.Cache;
import processor.memorysystem.MainMemory;
import processor.pipeline.EX_IF_LatchType;
import processor.pipeline.EX_MA_LatchType;
@ -32,8 +31,6 @@ public class Processor {
Execute EXUnit;
MemoryAccess MAUnit;
RegisterWrite RWUnit;
Cache l1iCache;
Cache l1dCache;
public Processor()
{
@ -46,9 +43,6 @@ public class Processor {
EX_MA_Latch = new EX_MA_LatchType();
EX_IF_Latch = new EX_IF_LatchType();
MA_RW_Latch = new MA_RW_LatchType();
l1iCache = new Cache(this, 0, 16);
l1dCache = new Cache(this, 0, 16);
IFUnit = new InstructionFetch(this, IF_EnableLatch, IF_OF_Latch, EX_IF_Latch);
OFUnit = new OperandFetch(this, IF_OF_Latch, OF_EX_Latch, IF_EnableLatch);
@ -100,12 +94,4 @@ public class Processor {
return RWUnit;
}
public Cache getL1iCache() {
return l1iCache;
}
public Cache getL1dCache() {
return l1dCache;
}
}

View File

@ -1,119 +0,0 @@
package processor.memorysystem;
import generic.*;
import processor.*;
import configuration.Configuration;
public class Cache implements Element {
boolean isPresent = true;
public int latency;
Processor containingProcessor;
int cache_size, miss_addr, line_size;
CacheLine[] cach;
int[] index;
public Cache(Processor containingProcessor, int latency, int cacheSize) {
this.latency = latency;
this.cache_size = cacheSize;
this.line_size = (int) (Math.log(this.cache_size / 8) / Math.log(2));
this.containingProcessor = containingProcessor;
this.cach = new CacheLine[cache_size / 8];
for (int i = 0; i < cache_size / 8; i++)
this.cach[i] = new CacheLine();
}
private int[] getindextag(int addr){
String a = Integer.toBinaryString(addr);
for (int i = 0; i < 32 - a.length(); i++)
a = "0" + a;
int add_tag = Integer.parseInt(a.substring(0, a.length() - line_size), 2);
int temp_ind;
String ind = "0";
if (line_size == 0)
temp_ind = 0;
else
for (int i = 0; i < line_size; i++)
ind = ind + "1";
temp_ind = addr & Integer.parseInt(ind, 2);
return new int[]{temp_ind, add_tag};
}
public int cacheRead(int address) {
int index, tag;
int[] temp = getindextag(address);
index = temp[0];
tag = temp[1];
if (tag == cach[index].tag[0]) {
cach[index].least_recently_used = 1;
isPresent = true;
return cach[index].data[0];
} else if (tag == cach[index].tag[1]) {
cach[index].least_recently_used = 0;
isPresent = true;
return cach[index].data[1];
} else {
isPresent = false;
return -1;
}
}
public void WritetoCache(int address, int value) {
int index, tag;
int[] temp = getindextag(address);
index = temp[0];
tag = temp[1];
cach[index].setValue(tag, value);
}
@Override
public void handleEvent(Event source_event) {
if (source_event.getEventType() == Event.EventType.MemoryRead) {
System.out.println("handle event cache memory read");
MemoryReadEvent handle_event = (MemoryReadEvent) source_event;
int data = cacheRead(handle_event.getAddressToReadFrom());
if (isPresent == true) {
Simulator.getEventQueue().addEvent(
new MemoryResponseEvent(
Clock.getCurrentTime() + this.latency,
this,
handle_event.getRequestingElement(),
data));
} else {
handle_event.setEventTime(Clock.getCurrentTime() + Configuration.mainMemoryLatency + 1);
this.miss_addr = handle_event.getAddressToReadFrom();
Simulator.getEventQueue().addEvent(handle_event);
Simulator.getEventQueue().addEvent(
new MemoryReadEvent(
Clock.getCurrentTime() + Configuration.mainMemoryLatency,
this,
containingProcessor.getMainMemory(),
this.miss_addr)
);
}
}
else if (source_event.getEventType() == Event.EventType.MemoryWrite) {
MemoryWriteEvent handle_event = (MemoryWriteEvent) source_event;
WritetoCache(handle_event.getAddressToWriteTo(), handle_event.getValue());
containingProcessor.getMainMemory().setWord(handle_event.getAddressToWriteTo(), handle_event.getValue());
Simulator.getEventQueue().addEvent(
new ExecutionCompleteEvent(
Clock.getCurrentTime() + Configuration.mainMemoryLatency,
containingProcessor.getMainMemory(),
handle_event.getRequestingElement()));
}
else if (source_event.getEventType() == Event.EventType.MemoryResponse) {
MemoryResponseEvent handle_event = (MemoryResponseEvent) source_event;
WritetoCache(this.miss_addr, handle_event.getValue());
}
}
}

View File

@ -1,30 +0,0 @@
package processor.memorysystem;
public class CacheLine{
int[] tag = new int[2];
int[] data = new int[2];
int least_recently_used = 0;
public CacheLine() {
this.tag[0] = -1;
this.tag[1] = -1;
}
public void setValue(int tag, int value) {
if(tag == this.tag[0]) {
this.data[0] = value;
this.least_recently_used = 1;
}
else if(tag == this.tag[1]) {
this.data[1] = value;
this.least_recently_used = 0;
}
else {
this.tag[this.least_recently_used] = tag;
this.data[this.least_recently_used] = value;
this.least_recently_used = 1- this.least_recently_used;
}
}
}

View File

@ -1,5 +1,6 @@
package processor.pipeline;
import configuration.Configuration;
import generic.Element;
import generic.Event;
import generic.MemoryReadEvent;
@ -32,13 +33,13 @@ public class InstructionFetch implements Element{
Simulator.getEventQueue().addEvent(
new MemoryReadEvent(
Clock.getCurrentTime() + containingProcessor.getL1iCache().latency,
Clock.getCurrentTime()+Configuration.mainMemoryLatency,
this,
containingProcessor.getL1iCache(),
containingProcessor.getMainMemory(),
currentPC
)
);
// System.out.println("H1");
System.out.println("H1");
IF_OF_Latch.setIF_branching_busy(true);
@ -57,9 +58,9 @@ public class InstructionFetch implements Element{
Simulator.getEventQueue().addEvent(
new MemoryReadEvent(
Clock.getCurrentTime()+ containingProcessor.getL1iCache().latency,
Clock.getCurrentTime()+ Configuration.mainMemoryLatency,
this,
containingProcessor.getL1iCache(),
containingProcessor.getMainMemory(),
currentPC
)
);

View File

@ -1,5 +1,6 @@
package processor.pipeline;
import configuration.Configuration;
import generic.Element;
import generic.Event;
import generic.ExecutionCompleteEvent;
@ -40,9 +41,9 @@ public class MemoryAccess implements Element {
instruction.getSourceOperand1().getValue());
Simulator.getEventQueue().addEvent(
new MemoryWriteEvent(
Clock.getCurrentTime()+containingProcessor.getL1dCache().latency,
Clock.getCurrentTime()+Configuration.mainMemoryLatency,
this,
containingProcessor.getL1dCache(),
containingProcessor.getMainMemory(),
alu_result,
val_store
)
@ -54,9 +55,9 @@ public class MemoryAccess implements Element {
{
Simulator.getEventQueue().addEvent(
new MemoryReadEvent(
Clock.getCurrentTime()+containingProcessor.getL1dCache().latency,
Clock.getCurrentTime()+Configuration.mainMemoryLatency,
this,
containingProcessor.getL1dCache(),
containingProcessor.getMainMemory(),
alu_result
)
);