Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
advanced_computer_architecture
exercises
Commits
f2d772c9
Commit
f2d772c9
authored
May 13, 2016
by
Christoph Gerum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Important fixes to templates blatt03
parent
e94bda4b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
29 deletions
+63
-29
aufgaben/blatt03/BPConfig.py
aufgaben/blatt03/BPConfig.py
+25
-7
aufgaben/blatt03/branches/branches1.c
aufgaben/blatt03/branches/branches1.c
+1
-1
aufgaben/blatt03/branches/branches1.elf
aufgaben/blatt03/branches/branches1.elf
+0
-0
aufgaben/blatt03/gem5/src/cpu/pred/BranchPredictor.py
aufgaben/blatt03/gem5/src/cpu/pred/BranchPredictor.py
+1
-1
aufgaben/blatt03/gem5/src/cpu/pred/GAsBP.cc
aufgaben/blatt03/gem5/src/cpu/pred/GAsBP.cc
+29
-19
aufgaben/blatt03/gem5/src/cpu/pred/GAsBP.hh
aufgaben/blatt03/gem5/src/cpu/pred/GAsBP.hh
+7
-1
No files found.
aufgaben/blatt03/BPConfig.py
View file @
f2d772c9
...
...
@@ -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'
or
g
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
()
...
...
aufgaben/blatt03/branches/branches1.c
View file @
f2d772c9
...
...
@@ -14,5 +14,5 @@ int main () {
j
++
;
}
while
(
j
<
3
);
i
++
;
}
while
(
i
<
1000
);
}
while
(
i
<
1000
00
);
}
aufgaben/blatt03/branches/branches1.elf
View file @
f2d772c9
No preview for this file type
aufgaben/blatt03/gem5/src/cpu/pred/BranchPredictor.py
View file @
f2d772c9
...
...
@@ -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"
)
aufgaben/blatt03/gem5/src/cpu/pred/GAsBP.cc
View file @
f2d772c9
...
...
@@ -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
),
global
Predic
torSize
(
params
->
global
Predic
torSize
),
global
His
tor
y
Size
(
params
->
global
His
tor
y
Size
),
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
);
// Spe
k
ulative
s
update
des globalen History Registers
// Spe
c
ulative update
.
if
(
speculativeUpdate
)
{
if
(
taken
)
{
DPRINTF
(
Fetch
,
"
S
peculative update as taken.
\n
"
);
DPRINTF
(
Fetch
,
"
Branch s
peculative update
d
as taken.
\n
"
);
//A2: Fall 1 vorhersage taken
}
else
{
DPRINTF
(
Fetch
,
"
S
peculative update as not taken.
\n
"
);
DPRINTF
(
Fetch
,
"
Branch s
peculative update
d
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
}
}
...
...
aufgaben/blatt03/gem5/src/cpu/pred/GAsBP.hh
View file @
f2d772c9
...
...
@@ -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__
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment