OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [rtl/] [riverlib/] [core/] [bp_predic.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
-----------------------------------------------------------------------------
2
--! @file
3
--! @copyright Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
--! @author    Sergey Khabarov - sergeykhbr@gmail.com
5
--! @brief     Branch predictor.
6
--! @details   This module gives about 5% of performance improvement (CPI)
7
------------------------------------------------------------------------------
8
 
9
library ieee;
10
use ieee.std_logic_1164.all;
11
library commonlib;
12
use commonlib.types_common.all;
13
--! RIVER CPU specific library.
14
library riverlib;
15
--! RIVER CPU configuration constants.
16
use riverlib.river_cfg.all;
17
 
18
 
19
entity BranchPredictor is
20
  port (
21
    i_clk : in std_logic;                              -- CPU clock
22
    i_nrst : in std_logic;                             -- Reset. Active LOW.
23
    i_req_mem_fire : in std_logic;                     -- Memory request was accepted
24
    i_resp_mem_valid : in std_logic;                   -- Memory response from ICache is valid
25
    i_resp_mem_addr : in std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);-- Memory response address
26
    i_resp_mem_data : in std_logic_vector(31 downto 0);-- Memory response value
27
    i_f_predic_miss : in std_logic;                    -- Fetch modul detects deviation between predicted and valid pc.
28
    i_e_npc : in std_logic_vector(31 downto 0);        -- Valid instruction value awaited by 'Executor'
29
    i_ra : in std_logic_vector(RISCV_ARCH-1 downto 0); -- Return address register value
30
    o_npc_predict : out std_logic_vector(31 downto 0)  -- Predicted next instruction address
31
  );
32
end;
33
 
34
architecture arch_BranchPredictor of BranchPredictor is
35
 
36
  type RegistersType is record
37
      npc : std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
38
      resp_mem_addr : std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
39
      resp_mem_data : std_logic_vector(31 downto 0);
40
  end record;
41
 
42
  signal r, rin : RegistersType;
43
 
44
begin
45
 
46
  comb : process(i_nrst, i_req_mem_fire, i_resp_mem_valid, i_resp_mem_addr,
47
                 i_resp_mem_data, i_f_predic_miss, i_e_npc, i_ra, r)
48
    variable v : RegistersType;
49
    variable wb_tmp : std_logic_vector(31 downto 0);
50
    variable wb_npc : std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
51
    variable wb_jal_off : std_logic_vector(BUS_ADDR_WIDTH-1 downto 0);
52
  begin
53
 
54
    v := r;
55
 
56
    if i_resp_mem_valid = '1' then
57
        v.resp_mem_addr := i_resp_mem_addr;
58
        v.resp_mem_data := i_resp_mem_data;
59
    end if;
60
 
61
    wb_tmp := r.resp_mem_data;
62
    wb_npc := r.npc;
63
 
64
    wb_jal_off(BUS_ADDR_WIDTH-1 downto 20) := (others => wb_tmp(31));
65
    wb_jal_off(19 downto 12) := wb_tmp(19 downto 12);
66
    wb_jal_off(11) := wb_tmp(20);
67
    wb_jal_off(10 downto 1) := wb_tmp(30 downto 21);
68
    wb_jal_off(0) := '0';
69
 
70
    if i_f_predic_miss = '1' then
71
        wb_npc := i_e_npc;
72
    elsif wb_tmp = X"00008067" then
73
        -- ret pseudo-instruction: Dhry score 34816 -> 35136
74
        wb_npc := i_ra(BUS_ADDR_WIDTH-1 downto 0);
75
    --!elsif wb_tmp(6 downto 0) = "1101111" then
76
    --!    -- jal instruction: Dhry score 35136 -> 36992
77
    --!    wb_npc := i_resp_mem_addr + wb_jal_off;
78
    else
79
        wb_npc := r.npc + 2;
80
    end if;
81
 
82
 
83
    if i_req_mem_fire = '1' then
84
        v.npc := wb_npc;
85
    end if;
86
 
87
    if i_nrst = '0' then
88
        v.npc := RESET_VECTOR - 2;
89
        v.resp_mem_addr := RESET_VECTOR;
90
        v.resp_mem_data := (others => '0');
91
    end if;
92
 
93
    o_npc_predict <= wb_npc;
94
 
95
    rin <= v;
96
  end process;
97
 
98
  -- registers:
99
  regs : process(i_clk)
100
  begin
101
     if rising_edge(i_clk) then
102
        r <= rin;
103
     end if;
104
  end process;
105
 
106
end;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.