Skip to content

Commit 7cd3fd2

Browse files
committed
Set default generic value and fixed bugs in the one and two bit predictors
1 parent 77e32fa commit 7cd3fd2

File tree

4 files changed

+9
-22
lines changed

4 files changed

+9
-22
lines changed

src/branch_prediction/bp_1bit_predictor.vhd

+4-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ architecture arch of bp_1bit_predictor is
2424

2525
signal bht_table : bht_element_type;
2626
signal prediction_internal : std_logic := '0';
27-
signal state : std_logic := NotTaken;
2827

2928
begin
3029
prediction <= prediction_internal;
@@ -33,23 +32,20 @@ begin
3332
variable idx : integer;
3433
begin
3534
if reset = '1' then
36-
state <= NotTaken;
3735
for i in 0 to 2 ** BHT_BITS loop
38-
bht_table(i) <= '0';
36+
bht_table(i) <= NotTaken;
3937
end loop;
4038
elsif rising_edge(clock) then
4139
if update = '1' then
4240
idx := to_integer(unsigned(previous_pc(BHT_BITS + 1 downto 2)));
43-
case state is
41+
case bht_table(idx) is
4442
when NotTaken =>
4543
if prediction_incorrect = '1' then
46-
state <= Taken;
47-
bht_table(idx) <= NotTaken;
44+
bht_table(idx) <= Taken;
4845
end if;
4946
when Taken =>
5047
if prediction_incorrect = '1' then
51-
state <= NotTaken;
52-
bht_table(idx) <= Taken;
48+
bht_table(idx) <= NotTaken;
5349
end if;
5450
when others =>
5551
null;

src/branch_prediction/bp_2bit_predictor.vhd

+2-10
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ architecture arch of bp_2bit_predictor is
2525
constant NotTaken1 : std_logic_vector(1 downto 0) := "11";
2626

2727
signal bht_table : bht_element_type;
28-
signal prediction_internal : std_logic := '0';
29-
signal state : std_logic_vector(1 downto 0) := NotTaken1;
28+
signal prediction_internal : std_logic := '0';
3029

3130
begin
3231
prediction <= prediction_internal;
@@ -35,38 +34,31 @@ begin
3534
variable idx : integer;
3635
begin
3736
if reset = '1' then
38-
state <= NotTaken1;
3937
for i in 0 to 2 ** BHT_BITS loop
4038
bht_table(i) <= NotTaken1;
4139
end loop;
4240
elsif rising_edge(clock) then
4341
if update = '1' then
4442
idx := to_integer(unsigned(previous_pc(BHT_BITS + 1 downto 2)));
45-
case state is
43+
case bht_table(idx) is
4644
when NotTaken0 =>
4745
if prediction_incorrect = '1' then
48-
state <= Taken1;
4946
bht_table(idx) <= Taken1;
5047
else
51-
state <= NotTaken1;
5248
bht_table(idx) <= NotTaken1;
5349
end if;
5450
when NotTaken1 =>
5551
if prediction_incorrect = '1' then
56-
state <= NotTaken0;
5752
bht_table(idx) <= NotTaken0;
5853
end if;
5954
when Taken0 =>
6055
if prediction_incorrect = '1' then
61-
state <= NotTaken1;
6256
bht_table(idx) <= NotTaken1;
6357
else
64-
state <= Taken1;
6558
bht_table(idx) <= Taken1;
6659
end if;
6760
when Taken1 =>
6861
if prediction_incorrect = '1' then
69-
state <= Taken0;
7062
bht_table(idx) <= Taken0;
7163
end if;
7264
when others =>

src/branch_prediction/branch_prediction.vhd

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package branch_prediction is
44
constant DEFAULT_BHT_BITS : integer := 12;
55

66
component bp_2bit_predictor is
7-
generic(BHT_BITS : integer);
7+
generic(BHT_BITS : integer := DEFAULT_BHT_BITS);
88
port(
99
clock : in std_logic;
1010
reset : in std_logic;
@@ -18,7 +18,7 @@ package branch_prediction is
1818
end component bp_2bit_predictor;
1919

2020
component bp_1bit_predictor is
21-
generic(BHT_BITS : integer);
21+
generic(BHT_BITS : integer := DEFAULT_BHT_BITS);
2222
port(
2323
clock : in std_logic;
2424
reset : in std_logic;

src/processor.vhd

+1-2
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ begin
289289

290290
if_pc_plus_four <= std_logic_vector(unsigned(pc) + 4);
291291

292-
branch_predictor : bp_2bit_predictor
293-
generic map(BHT_BITS => DEFAULT_BHT_BITS)
292+
branch_predictor : bp_1bit_predictor
294293
port map(clock => clock,
295294
reset => reset,
296295
pc => pc,

0 commit comments

Comments
 (0)