Commit f2d772c9 authored by Christoph Gerum's avatar Christoph Gerum

Important fixes to templates blatt03

parent e94bda4b
......@@ -3,21 +3,36 @@ from m5.objects import *
import argparse
import sys
import pandas
import shlex
parser = argparse.ArgumentParser(description='Simulate benchmark')
# parser.add_argument('--type', help='CPU Type (one of: o3, minor, timing)')
parser.add_argument('--o3', help='use DerivO3Cpu instead of TimingSimpleCpu', action="store_true")
parser.add_argument('-c', help='binary to execute')
parser.add_argument('-w', help='width of pipeline')
parser.add_argument('-o', help='The options to pass to the binary, use " " around the entire string')
parser.add_argument('-b', choices=['local','tournament','gas','gas_speculative'], help='branch prediction')
parser.add_argument('-b', choices=['local','tournament','gas','gas_speculative','bht'], help='branch prediction')
args = parser.parse_args()
if args.o3:
CPU = DerivO3CPU
# width of pipeline configuration
width = 8 if args.w is None else args.w
CPU.decodeWidth = width # std: 8
CPU.commitWidth = width
CPU.fetchWidth = width
CPU.issueWidth = width
CPU.renameWidth = width
CPU.squashWidth = width
# CPU.wbWidth = width if (width > 8) else 8
CPU.fetchQueueSize = width
else:
CPU = TimingSimpleCPU
class L1Cache(BaseCache):
assoc = 2
hit_latency = 2
......@@ -28,18 +43,18 @@ class L1Cache(BaseCache):
is_top_level = True
if (args.b == 'local' org args.b == 'bht'):
if (args.b == 'local' or args.b == 'bht'):
CPU.branchPred = LocalBP(localPredictorSize=256,localCtrBits=2)
elif (args.b == 'gas'):
CPU.branchPred = GAsBP(localPredictorSize=256, globalHistorySize=8, localCtrBits=2, speculativeUpdate=False);
CPU.branchPred = GAsBP(localPredictorSize=256, globalHistorySize=3, localCtrBits=2, speculativeUpdate=False);
elif (args.b == 'gas_speculative'):
CPU.branchPred = GAsBP(localPredictorSize=256, globalHistorySize=8, localCtrBits=2, speculativeUpdate=True);
CPU.branchPred = GAsBP(localPredictorSize=256, globalHistorySize=3, localCtrBits=2, speculativeUpdate=True);
elif (args.b == "tournament"):
CPU.branchPred = TournamentBP(localPredictorSize=256,
globalPredictorSize=256,
choicePredictorSize=256)
else:
CPU.branchPred = GAsBP(localPredictorSize=256, globalHistorySize=8, localCtrBits=2, speculativeUpdate=False);
CPU.branchPred = GAsBP(localPredictorSize=256, globalHistorySize=3, localCtrBits=2, speculativeUpdate=False);
system = System()
......@@ -74,7 +89,10 @@ system.mem_ctrl.port = system.membus.master
process = LiveProcess()
process.cmd = [args.c] if not args.o else [args.c]+str.split(args.o)
process.cmd = shlex.split(args.c)
if args.o:
process.cmd += shlex.split(args.o)
print process.cmd
system.cpu.workload = process
system.cpu.createThreads()
......
......@@ -14,5 +14,5 @@ int main () {
j++;
} while( j < 3 );
i++;
} while( i < 1000 );
} while( i < 100000 );
}
......@@ -86,4 +86,4 @@ class GAsBP(BranchPredictor):
localCtrBits = Param.Unsigned(2, "Bits per counter")
speculativeUpdate = Param.Bool(False, "speculative update of GHR")
speculativeUpdateCounters = Param.Bool(False, "speculative update of counters")
squashHistory = Param.Bool(True, "Reset speculative global History register to its previous value when mispredictions are detected")
......@@ -33,39 +33,45 @@
#include "base/trace.hh"
#include "cpu/pred/GAsBP.hh"
#include "debug/Fetch.hh"
#include <math.h>
GAsBP::GAsBP(const GAsBPParams *params)
: BPredUnit(params),
localPredictorSize(params->localPredictorSize),
globalPredictorSize(params->globalPredictorSize),
globalHistorySize(params->globalHistorySize),
localCtrBits(params->localCtrBits),
speculativeUpdate(params->speculativeUpdate),
speculativeUpdateCounters(params->speculativeUpdateCounters)
speculativeUpdateCounters(params->speculativeUpdateCounters),
squashHistory(params->squashHistory)
{
if (!isPowerOf2(localPredictorSize)) {
fatal("Invalid local predictor size!\n");
}
// if (!isPowerOf2(globalPredictorSize)) {
// fatal("Invalid global history register size!\n");
// }
localPredictorSets = localPredictorSize / localCtrBits;
if (!isPowerOf2(localPredictorSets)) {
fatal("Invalid number of local predictor sets! Check localCtrBits.\n");
}
DPRINTF(Fetch, "global history size: %i\n", globalHistorySize);
globalPredictorSize = std::pow(2, globalHistorySize);
DPRINTF(Fetch, "global predictor size: %i\n", globalPredictorSize);
// Setup the index mask.
indexMask = localPredictorSets - 1;
DPRINTF(Fetch, "index mask: %#x\n", indexMask);
DPRINTF(Fetch, "local index mask: %#x\n", indexMask);
// Setup the global history register and mask
globalHistoryBits = 0;
globalHistoryBitsSpeculative = 0;
globalHistoryMask = globalPredictorSize - 1;
DPRINTF(Fetch, "global index mask: %i\n", globalHistoryMask);
// Setup the array of counters for the local predictor and the global history register.
localCtrs.resize(localPredictorSets);
for (unsigned i = 0; i < localPredictorSets; ++i)
......@@ -113,8 +119,7 @@ GAsBP::lookup(Addr branch_addr, void * &bp_history)
if (speculativeUpdate)
global_history_idx = globalHistoryBitsSpeculative;
DPRINTF(Fetch, "Looking up index %#x\n",
local_predictor_idx);
DPRINTF(Fetch, "Looking up index %#x, %#x\n", local_predictor_idx, global_history_idx);
counter_val = localCtrs[local_predictor_idx][global_history_idx].read();
......@@ -123,14 +128,16 @@ GAsBP::lookup(Addr branch_addr, void * &bp_history)
taken = getPrediction(counter_val);
// Spekulatives update des globalen History Registers
// Speculative update.
if (speculativeUpdate) {
if (taken) {
DPRINTF(Fetch, "Speculative update as taken.\n");
DPRINTF(Fetch, "Branch speculative updated as taken.\n");
//A2: Fall 1 vorhersage taken
} else {
DPRINTF(Fetch, "Speculative update as not taken.\n");
DPRINTF(Fetch, "Branch speculative updated as not taken.\n");
//A2: Fall 2 vorhersage not taken
}
globalHistoryBitsSpeculative &= globalHistoryMask;
}
......@@ -149,21 +156,24 @@ GAsBP::update(Addr branch_addr, bool taken, void *bp_history, bool squashed)
local_predictor_idx = getLocalIndex(branch_addr);
global_history_idx = globalHistoryBits;
DPRINTF(Fetch, "Looking up index %#x\n", local_predictor_idx);
DPRINTF(Fetch, "Updating index %#x, %#x\n", local_predictor_idx, global_history_idx);
if (taken) {
DPRINTF(Fetch, "Branch updated as taken.\n");
///A1: Update des Branch Predictors im Fall taken
//A1: Update des Branch Predictors im Fall taken
} else {
DPRINTF(Fetch, "Branch updated as not taken.\n");
///A1: Update des Branch Predictors im Fall not taken
//A1: Update des Branch Predictors im Fall not taken
}
globalHistoryBits &= globalHistoryMask;
if (squashed) {
DPRINTF(Fetch, "Squashed resetting speculative global history\n");
//A2 (bonus): Wie kann mit diesen Fehlvorhersagen umgegangen werden
if (squashed && squashHistory) {
DPRINTF(Fetch, "Squashed %i, %i\n",
globalHistoryBitsSpeculative,
globalHistoryBits);
//A2 (bonus): Wie kann mit diesen Fehlvorhersagen umgegangen werden
}
}
......
......@@ -114,7 +114,10 @@ class GAsBP : public BPredUnit
std::vector< std::vector<SatCounter> > localCtrs;
/** Size of the local predictor. */
unsigned localPredictorySize;
unsigned localPredictorSize;
/** Size of the global predictor. */
unsigned globalPredictorSize;
/** Size of the global history register. */
unsigned globalHistorySize;
......@@ -138,6 +141,9 @@ class GAsBP : public BPredUnit
/** constant to enable speculative update in counters */
bool speculativeUpdateCounters;
/** Reset speculative global History register to its previous value when mispredictions are detected*/
bool squashHistory;
};
#endif // __CPU_PRED_GAS_PRED_HH__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment