]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-rocon.git/blob - hw/lx-rocon_tumbl/lx_rocon_gprf_abd.vhd
Tumbl - disable GPRF forward if finish_wrb_mem_s is clock cycle cause.
[fpga/lx-cpu1/lx-rocon.git] / hw / lx-rocon_tumbl / lx_rocon_gprf_abd.vhd
1 library ieee;
2
3 use ieee.std_logic_1164.all;
4 use ieee.std_logic_arith.all;
5 use ieee.std_logic_unsigned.all;
6 use ieee.numeric_std.all;
7 use work.mbl_pkg.all;
8 use work.lx_rocon_pkg.all;
9
10 -- 32x32b General Puprose Registers for Tumbl Core
11 -- Uses 3 BRAMs
12
13 entity lx_rocon_gprf_abd is
14         port
15         (
16                 clk_i        :  in std_logic;
17                 rst_i        :  in std_logic;
18                 clken_i      :  in std_logic;
19                 gprf_finish_wrb_mem_i : in std_logic;
20
21                 --
22                 ID2GPRF_i    :  in ID2GPRF_Type;
23                 MEM_WRB_i    :  in WRB_Type;
24                 GPRF2EX_o    :  out GPRF2EX_Type
25         );
26 end entity lx_rocon_gprf_abd;
27
28 architecture rtl of lx_rocon_gprf_abd is
29
30         signal  rdix_rA_s    : std_logic_vector(4 downto 0);
31         signal  rdix_rB_s    : std_logic_vector(4 downto 0);
32         signal  rdix_rD_s    : std_logic_vector(4 downto 0);
33
34         signal  wre_rD_s     : std_logic;
35         signal  ena_rA_s     : std_logic;
36         signal  ena_rB_s     : std_logic;
37         signal  ena_rD_s     : std_logic;
38
39         signal  clken_s      : std_logic;
40
41         signal  wthru_rA_r   : std_logic;
42         signal  rA_DOA_s     : std_logic_vector(31 downto 0);
43         signal  rA_DOB_s     : std_logic_vector(31 downto 0);
44         signal  wthru_rB_r   : std_logic;
45         signal  rB_DOA_s     : std_logic_vector(31 downto 0);
46         signal  rB_DOB_s     : std_logic_vector(31 downto 0);
47         signal  wthru_rD_r   : std_logic;
48         signal  rD_DOA_s     : std_logic_vector(31 downto 0);
49         signal  rD_DOB_s     : std_logic_vector(31 downto 0);
50
51 begin
52
53         -- writeback if WRB_EX or WRB_MEM, but not when r0 involved
54         wre_rD_s <= '1' when ((MEM_WRB_i.wrb_Action /= NO_WRB) and
55                                                         (MEM_WRB_i.wrix_rD /= "00000")) else '0';
56
57         -- ports A should remain unchanged when clken_i is low, while also
58         -- reading from the same address as will be written to should be disabled
59         -- (setup for writeThru of data_rD)
60         ena_rA_s <= '1' when rst_i = '1' else clken_i when ((ID2GPRF_i.rdix_rA /= MEM_WRB_i.wrix_rD)) else '0';
61         ena_rB_s <= '1' when rst_i = '1' else clken_i when ((ID2GPRF_i.rdix_rB /= MEM_WRB_i.wrix_rD)) else '0';
62         ena_rD_s <= '1' when rst_i = '1' else clken_i when ((ID2GPRF_i.rdix_rD /= MEM_WRB_i.wrix_rD)) else '0';
63
64         -- make sure reset does it's job (writes 0 to R0 and resets the ports)
65         clken_s <= rst_i or clken_i;
66         rdix_rA_s <= (others => '0') when rst_i = '1' else ID2GPRF_i.rdix_rA;
67         rdix_rB_s <= (others => '0') when rst_i = '1' else ID2GPRF_i.rdix_rB;
68         rdix_rD_s <= (others => '0') when rst_i = '1' else ID2GPRF_i.rdix_rD;
69
70         GPRF2EX_o.data_rA <= rA_DOA_s when (wthru_rA_r = '0') else rA_DOB_s;
71         GPRF2EX_o.data_rB <= rB_DOA_s when (wthru_rB_r = '0') else rB_DOB_s;
72         GPRF2EX_o.data_rD <= rD_DOA_s when (wthru_rD_r = '0') else rD_DOB_s;    -- also for rD ???
73
74         I_rA: xilinx_dualport_bram
75         generic map
76         (
77                 byte_width    => 32,
78                 we_width      => 1,
79                 address_width => 5,
80                 port_a_type   => WRITE_FIRST,
81                 port_b_type   => WRITE_FIRST
82         )
83         port map
84         (
85                 clka   => clk_i,
86                 rsta   => rst_i,
87                 ena    => ena_rA_s,
88                 wea(0) => rst_i,
89                 addra  => rdix_rA_s,
90                 dina   => C_32_ZEROS,
91                 douta  => rA_DOA_s,
92                 -- Write-back
93                 clkb   => clk_i,
94                 rstb   => rst_i,
95                 enb    => clken_s,
96                 web(0) => wre_rD_s,
97                 addrb  => MEM_WRB_i.wrix_rD,
98                 dinb   => MEM_WRB_i.data_rD,
99                 doutb  => rA_DOB_s
100         );
101
102         I_rB: xilinx_dualport_bram
103         generic map
104         (
105                 byte_width    => 32,
106                 we_width      => 1,
107                 address_width => 5,
108                 port_a_type   => WRITE_FIRST,
109                 port_b_type   => WRITE_FIRST
110         )
111         port map
112         (
113                 clka   => clk_i,
114                 rsta   => rst_i,
115                 ena    => ena_rB_s,
116                 wea(0) => rst_i,
117                 addra  => rdix_rB_s,
118                 dina   => C_32_ZEROS,
119                 douta  => rB_DOA_s,
120                 -- Write-back
121                 clkb   => clk_i,
122                 rstb   => rst_i,
123                 enb    => clken_s,
124                 web(0) => wre_rD_s,
125                 addrb  => MEM_WRB_i.wrix_rD,
126                 dinb   => MEM_WRB_i.data_rD,
127                 doutb  => rB_DOB_s
128         );
129
130         I_rD: xilinx_dualport_bram
131         generic map
132         (
133                 byte_width    => 32,
134                 we_width      => 1,
135                 address_width => 5,
136                 port_a_type   => WRITE_FIRST,
137                 port_b_type   => WRITE_FIRST
138         )
139         port map
140         (
141                 clka   => clk_i,
142                 rsta   => rst_i,
143                 ena    => ena_rD_s,
144                 wea(0) => rst_i,
145                 addra  => rdix_rD_s,
146                 dina   => C_32_ZEROS,
147                 douta  => rD_DOA_s,
148                 -- Write-back
149                 clkb   => clk_i,
150                 rstb   => rst_i,
151                 enb    => clken_s,
152                 web(0) => wre_rD_s,
153                 addrb  => MEM_WRB_i.wrix_rD,
154                 dinb   => MEM_WRB_i.data_rD,
155                 doutb  => rD_DOB_s
156         );
157
158 p_regd:
159         process
160         begin
161                 wait until clk_i'event and clk_i = '1';
162                 if (clken_i = '1') then
163                         wthru_rA_r <= not ena_rA_s and not gprf_finish_wrb_mem_i;
164                         wthru_rB_r <= not ena_rB_s and not gprf_finish_wrb_mem_i;
165                         wthru_rD_r <= not ena_rD_s and not gprf_finish_wrb_mem_i;
166                 end if;
167         end process;
168
169 end architecture rtl;