-
Notifications
You must be signed in to change notification settings - Fork 1
/
Forward_unit.vhd
66 lines (61 loc) · 2.43 KB
/
Forward_unit.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use work.RISC_V_package.all;
entity Forward_unit is
port (
uins_ex : in Instruction_format;
-- Memread_ex : in std_logic;
RegWrite_mem : in std_logic;
RegWrite_wb : in std_logic;
rd_wb : in std_logic_vector(4 downto 0);
rd_mem : in std_logic_vector(4 downto 0);
rd_ex : in std_logic_vector(4 downto 0);
rs1_ex : in std_logic_vector(4 downto 0);
rs2_ex : in std_logic_vector(4 downto 0);
--rs1_id : in std_logic_vector(4 downto 0);
--rs2_id : in std_logic_vector(4 downto 0);
forwardRS1 : out std_logic_vector(1 downto 0);
forwardRS2 : out std_logic_vector(1 downto 0)
--enable_pipeline :out std_logic
);
end Forward_unit;
architecture structural of Forward_unit is
begin
-- FORWARD RS1
process(RegWrite_wb, RegWrite_mem ,rd_wb, rd_mem, rs1_ex, uins_ex)
begin
if (uins_ex = R or uins_ex = S or uins_ex = B or uins_ex = I) then -- Forward except J and U type
-- FORWARD ALU RESULTS
if (rd_mem = rs1_ex) and (RegWrite_mem='1') and (rd_mem /= "00000")then
forwardRS1 <= "01";
-- FORWARD MEM DATA
elsif (rd_wb = rs1_ex) and (RegWrite_wb='1') and (rd_wb /= "00000")
-- elsif (rd_wb = rs1_ex) and (rd_wb /= "00000")
and not ((rd_mem = rs1_ex) and (RegWrite_mem='1') and (rd_wb /= "00000"))then
forwardRS1 <= "10";
else
forwardRS1 <= "00";
end if;
end if;
end process;
-- FORWARD RS2
process(RegWrite_wb, RegWrite_mem ,rd_wb, rd_mem, rs2_ex, uins_ex)
begin
if (uins_ex = R or uins_ex = S or uins_ex = B) then -- Forward except J and U and I type
-- FORWARD ALU RESULTS
if (rd_mem = rs2_ex) and (RegWrite_mem='1') and (rd_mem /= "00000") then
forwardRS2 <= "01";
-- FORWARD MEM DATA
elsif (rd_wb = rs2_ex) and (RegWrite_wb='1') and (rd_wb /= "00000")
-- elsif (rd_wb = rs2_ex) and (rd_wb /= "00000")
and not ((rd_mem = rs2_ex) and (RegWrite_mem='1') and (rd_mem /= "00000"))then
forwardRS2 <= "10";
else
forwardRS2 <= "00";
end if;
else
forwardRS2 <= "00";
end if;
end process;
end structural;