Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS450 assignment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Paul Cha
CS450 assignment
Commits
799577d1
Commit
799577d1
authored
4 years ago
by
pcha
Browse files
Options
Downloads
Patches
Plain Diff
partial implementation of loop termination predictor
parent
fc27ae8b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
simplesim-3.0/bpred.c
+58
-1
58 additions, 1 deletion
simplesim-3.0/bpred.c
simplesim-3.0/bpred.h
+51
-0
51 additions, 0 deletions
simplesim-3.0/bpred.h
with
109 additions
and
1 deletion
simplesim-3.0/bpred.c
+
58
−
1
View file @
799577d1
...
...
@@ -263,6 +263,45 @@ bpred_dir_create (
return
pred_dir
;
}
/* create a loop termination predictor */
struct
ltpred_t
*
/* loop termination predictory instance */
ltpred_create
(
unsigned
int
ltb_sets
,
/* number of sets in BTB */
unsigned
int
ltb_assoc
)
/* BTB associativity */
{
struct
ltpred_t
*
pred
;
if
(
!
(
pred
=
calloc
(
1
,
sizeof
(
struct
ltpred_t
))))
fatal
(
"out of virtual memory"
);
/* allocate BTB */
if
(
!
ltb_sets
||
(
ltb_sets
&
(
ltb_sets
-
1
))
!=
0
)
fatal
(
"number of LTB sets must be non-zero and a power of two"
);
if
(
!
ltb_assoc
||
(
ltb_assoc
&
(
ltb_assoc
-
1
))
!=
0
)
fatal
(
"LTB associativity must be non-zero and a power of two"
);
if
(
!
(
pred
->
ltb
.
ltb_data
=
calloc
(
ltb_sets
*
ltb_assoc
,
sizeof
(
struct
ltpred_ltb_ent_t
))))
fatal
(
"cannot allocate LTB"
);
pred
->
ltb
.
sets
=
ltb_sets
;
pred
->
ltb
.
assoc
=
ltb_assoc
;
int
i
;
if
(
pred
->
ltb
.
assoc
>
1
)
for
(
i
=
0
;
i
<
(
pred
->
ltb
.
assoc
*
pred
->
ltb
.
sets
);
i
++
)
{
if
(
i
%
pred
->
ltb
.
assoc
!=
pred
->
ltb
.
assoc
-
1
)
pred
->
ltb
.
ltb_data
[
i
].
next
=
&
pred
->
ltb
.
ltb_data
[
i
+
1
];
else
pred
->
ltb
.
ltb_data
[
i
].
next
=
NULL
;
if
(
i
%
pred
->
ltb
.
assoc
!=
pred
->
ltb
.
assoc
-
1
)
pred
->
ltb
.
ltb_data
[
i
+
1
].
prev
=
&
pred
->
ltb
.
ltb_data
[
i
];
}
return
pred
;
}
/* print branch direction predictor configuration */
void
bpred_dir_config
(
...
...
@@ -716,6 +755,24 @@ bpred_lookup(struct bpred_t *pred, /* branch predictor instance */
}
}
md_addr_t
ltpred_lookup
(
struct
ltpred_t
*
ltpred
,
/* branch predictor instance */
md_addr_t
baddr
)
/* branch address */
{
}
void
ltpred_update
(
struct
ltpred_t
*
ltpred
,
/* loop termination predictor instance */
md_addr_t
baddr
,
counter_t
spec_cnt
,
counter_t
nspec_cnt
,
counter_t
trip_cnt
,
int
conf_bif
)
{
}
/* Speculative execution can corrupt the ret-addr stack. So for each
* lookup we return the top-of-stack (TOS) at that point; a mispredicted
* branch, as part of its recovery, restores the TOS using this value --
...
...
@@ -854,7 +911,7 @@ bpred_update(struct bpred_t *pred, /* branch predictor instance */
for
(
i
=
index
;
i
<
(
index
+
pred
->
btb
.
assoc
)
;
i
++
)
{
if
(
pred
->
btb
.
btb_data
[
i
].
addr
==
baddr
)
{
{
/* match */
assert
(
!
pbtb
);
pbtb
=
&
pred
->
btb
.
btb_data
[
i
];
...
...
This diff is collapsed.
Click to expand it.
simplesim-3.0/bpred.h
+
51
−
0
View file @
799577d1
...
...
@@ -186,6 +186,42 @@ struct bpred_update_t {
}
dir
;
};
/* an entry in a BTB */
struct
ltpred_ltb_ent_t
{
md_addr_t
addr
;
/* address of branch being tracked */
counter_t
spec_cnt
;
/* speculative iteration count */
counter_t
nspec_cnt
;
/* non-speculative iteration count */
counter_t
trip_cnt
;
/* loop trip count */
int
conf_bit
;
/* confidence bit */
struct
ltpred_ltb_ent_t
*
prev
,
*
next
;
/* lru chaining pointers */
};
/* branch predictor def */
struct
ltpred_t
{
struct
{
int
sets
;
/* num LTB sets */
int
assoc
;
/* LTB associativity */
struct
ltpred_ltb_ent_t
*
ltb_data
;
/* LTB addr-prediction table */
}
ltb
;
/* stats */
// TODO: modify stats below
// counter_t addr_hits; /* num correct addr-predictions */
// counter_t dir_hits; /* num correct dir-predictions (incl addr) */
// counter_t used_ras; /* num RAS predictions used */
// counter_t used_bimod; /* num bimodal predictions used (BPredComb) */
// counter_t used_2lev; /* num 2-level predictions used (BPredComb) */
// counter_t jr_hits; /* num correct addr-predictions for JR's */
// counter_t jr_seen; /* num JR's seen */
// counter_t jr_non_ras_hits; /* num correct addr-preds for non-RAS JR's */
// counter_t jr_non_ras_seen; /* num non-RAS JR's seen */
counter_t
misses
;
/* num incorrect predictions */
counter_t
lookups
;
/* num lookups */
// counter_t retstack_pops; /* number of times a value was popped */
// counter_t retstack_pushes; /* number of times a value was pushed */
// counter_t ras_hits; /* num correct return-address predictions */
};
/* create a branch predictor */
struct
bpred_t
*
/* branch predictory instance */
bpred_create
(
enum
bpred_class
class
,
/* type of predictor to create */
...
...
@@ -208,6 +244,11 @@ bpred_dir_create (
unsigned
int
shift_width
,
/* history register width */
unsigned
int
xor
);
/* history xor address flag */
struct
ltpred_t
*
/* loop termination predictory instance */
ltpred_create
(
unsigned
int
ltb_sets
,
/* number of sets in BTB */
unsigned
int
ltb_assoc
);
/* BTB associativity */
/* print branch predictor configuration */
void
bpred_config
(
struct
bpred_t
*
pred
,
/* branch predictor instance */
...
...
@@ -272,7 +313,17 @@ bpred_update(struct bpred_t *pred, /* branch predictor instance */
enum
md_opcode
op
,
/* opcode of instruction */
struct
bpred_update_t
*
dir_update_ptr
);
/* pred state pointer */
md_addr_t
ltpred_lookup
(
struct
ltpred_t
*
ltpred
,
/* branch predictor instance */
md_addr_t
baddr
);
/* branch address */
void
ltpred_update
(
struct
ltpred_t
*
ltpred
,
/* loop termination predictor instance */
md_addr_t
baddr
,
counter_t
spec_cnt
,
counter_t
nspec_cnt
,
counter_t
trip_cnt
,
int
conf_bif
)
#ifdef foo0
/* OBSOLETE */
/* dump branch predictor state (for debug) */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment