2 use ieee.std_logic_1164.all;
6 PIPELINE_DEPTH : natural := 2
12 complete_in : in std_ulogic;
13 valid_in : in std_ulogic;
14 flush_in : in std_ulogic;
15 sgl_pipe_in : in std_ulogic;
16 stop_mark_in : in std_ulogic;
18 gpr_write_valid_in : in std_ulogic;
19 gpr_write_in : in std_ulogic_vector(4 downto 0);
21 gpr_a_read_valid_in : in std_ulogic;
22 gpr_a_read_in : in std_ulogic_vector(4 downto 0);
24 gpr_b_read_valid_in : in std_ulogic;
25 gpr_b_read_in : in std_ulogic_vector(4 downto 0);
27 gpr_c_read_valid_in : in std_ulogic;
28 gpr_c_read_in : in std_ulogic_vector(4 downto 0);
30 valid_out : out std_ulogic;
31 stall_out : out std_ulogic;
32 stopped_out : out std_ulogic
36 architecture rtl of control is
37 type state_type is (IDLE, WAIT_FOR_PREV_TO_COMPLETE, WAIT_FOR_CURR_TO_COMPLETE);
39 type reg_internal_type is record
41 outstanding : integer range -1 to PIPELINE_DEPTH+2; -- XXX ?
43 constant reg_internal_init : reg_internal_type := (state => IDLE, outstanding => 0);
45 signal r_int, rin_int : reg_internal_type := reg_internal_init;
47 signal stall_a_out, stall_b_out, stall_c_out : std_ulogic;
49 signal gpr_write_valid : std_ulogic := '0';
51 gpr_hazard0: entity work.gpr_hazard
58 gpr_write_valid_in => gpr_write_valid,
59 gpr_write_in => gpr_write_in,
60 gpr_read_valid_in => gpr_a_read_valid_in,
61 gpr_read_in => gpr_a_read_in,
63 stall_out => stall_a_out
66 gpr_hazard1: entity work.gpr_hazard
73 gpr_write_valid_in => gpr_write_valid,
74 gpr_write_in => gpr_write_in,
75 gpr_read_valid_in => gpr_b_read_valid_in,
76 gpr_read_in => gpr_b_read_in,
78 stall_out => stall_b_out
81 gpr_hazard2: entity work.gpr_hazard
88 gpr_write_valid_in => gpr_write_valid,
89 gpr_write_in => gpr_write_in,
90 gpr_read_valid_in => gpr_c_read_valid_in,
91 gpr_read_in => gpr_c_read_in,
93 stall_out => stall_c_out
96 control0: process(clk)
98 if rising_edge(clk) then
103 control1 : process(all)
104 variable v_int : reg_internal_type;
105 variable valid_tmp : std_ulogic;
106 variable stall_tmp : std_ulogic;
111 valid_tmp := valid_in and not flush_in;
114 if complete_in = '1' then
115 assert r_int.outstanding >= 0 and r_int.outstanding <= (PIPELINE_DEPTH+1) report "Outstanding bad " & integer'image(r_int.outstanding) severity failure;
116 v_int.outstanding := r_int.outstanding - 1;
119 -- Handle debugger stop
121 if stop_mark_in = '1' and v_int.outstanding = 0 then
125 -- state machine to handle instructions that must be single
126 -- through the pipeline.
129 if valid_tmp = '1' then
130 if (sgl_pipe_in = '1') then
131 if v_int.outstanding /= 0 then
132 v_int.state := WAIT_FOR_PREV_TO_COMPLETE;
135 -- send insn out and wait on it to complete
136 v_int.state := WAIT_FOR_CURR_TO_COMPLETE;
139 -- let it go out if there are no GPR hazards
140 stall_tmp := stall_a_out or stall_b_out or stall_c_out;
144 when WAIT_FOR_PREV_TO_COMPLETE =>
145 if v_int.outstanding = 0 then
146 -- send insn out and wait on it to complete
147 v_int.state := WAIT_FOR_CURR_TO_COMPLETE;
152 when WAIT_FOR_CURR_TO_COMPLETE =>
153 if v_int.outstanding = 0 then
155 -- XXX Don't replicate this
156 if valid_tmp = '1' then
157 if (sgl_pipe_in = '1') then
158 if v_int.outstanding /= 0 then
159 v_int.state := WAIT_FOR_PREV_TO_COMPLETE;
162 -- send insn out and wait on it to complete
163 v_int.state := WAIT_FOR_CURR_TO_COMPLETE;
166 -- let it go out if there are no GPR hazards
167 stall_tmp := stall_a_out or stall_b_out or stall_c_out;
175 if stall_tmp = '1' then
179 if valid_tmp = '1' then
180 v_int.outstanding := v_int.outstanding + 1;
181 gpr_write_valid <= gpr_write_valid_in;
183 gpr_write_valid <= '0';
188 v_int.outstanding := 0;
193 valid_out <= valid_tmp;
194 stall_out <= stall_tmp;