2 use ieee.std_logic_1164.all;
9 PIPELINE_DEPTH : natural := 2
15 complete_in : in std_ulogic;
16 valid_in : in std_ulogic;
17 flush_in : in std_ulogic;
18 busy_in : in std_ulogic;
19 deferred : in std_ulogic;
20 sgl_pipe_in : in std_ulogic;
21 stop_mark_in : in std_ulogic;
23 gpr_write_valid_in : in std_ulogic;
24 gpr_write_in : in gspr_index_t;
25 gpr_bypassable : in std_ulogic;
27 update_gpr_write_valid : in std_ulogic;
28 update_gpr_write_reg : in gspr_index_t;
30 gpr_a_read_valid_in : in std_ulogic;
31 gpr_a_read_in : in gspr_index_t;
33 gpr_b_read_valid_in : in std_ulogic;
34 gpr_b_read_in : in gspr_index_t;
36 gpr_c_read_valid_in : in std_ulogic;
37 gpr_c_read_in : in gspr_index_t;
39 cr_read_in : in std_ulogic;
40 cr_write_in : in std_ulogic;
41 cr_bypassable : in std_ulogic;
43 valid_out : out std_ulogic;
44 stall_out : out std_ulogic;
45 stopped_out : out std_ulogic;
47 gpr_bypass_a : out std_ulogic;
48 gpr_bypass_b : out std_ulogic;
49 gpr_bypass_c : out std_ulogic;
50 cr_bypass : out std_ulogic
54 architecture rtl of control is
55 type state_type is (IDLE, WAIT_FOR_PREV_TO_COMPLETE, WAIT_FOR_CURR_TO_COMPLETE);
57 type reg_internal_type is record
59 outstanding : integer range -1 to PIPELINE_DEPTH+2;
61 constant reg_internal_init : reg_internal_type := (state => IDLE, outstanding => 0);
63 signal r_int, rin_int : reg_internal_type := reg_internal_init;
65 signal stall_a_out : std_ulogic;
66 signal stall_b_out : std_ulogic;
67 signal stall_c_out : std_ulogic;
68 signal cr_stall_out : std_ulogic;
70 signal gpr_write_valid : std_ulogic := '0';
71 signal cr_write_valid : std_ulogic := '0';
74 gpr_hazard0: entity work.gpr_hazard
76 PIPELINE_DEPTH => PIPELINE_DEPTH
82 complete_in => complete_in,
86 gpr_write_valid_in => gpr_write_valid,
87 gpr_write_in => gpr_write_in,
88 bypass_avail => gpr_bypassable,
89 gpr_read_valid_in => gpr_a_read_valid_in,
90 gpr_read_in => gpr_a_read_in,
92 ugpr_write_valid => update_gpr_write_valid,
93 ugpr_write_reg => update_gpr_write_reg,
95 stall_out => stall_a_out,
96 use_bypass => gpr_bypass_a
99 gpr_hazard1: entity work.gpr_hazard
101 PIPELINE_DEPTH => PIPELINE_DEPTH
106 deferred => deferred,
107 complete_in => complete_in,
108 flush_in => flush_in,
109 issuing => valid_out,
111 gpr_write_valid_in => gpr_write_valid,
112 gpr_write_in => gpr_write_in,
113 bypass_avail => gpr_bypassable,
114 gpr_read_valid_in => gpr_b_read_valid_in,
115 gpr_read_in => gpr_b_read_in,
117 ugpr_write_valid => update_gpr_write_valid,
118 ugpr_write_reg => update_gpr_write_reg,
120 stall_out => stall_b_out,
121 use_bypass => gpr_bypass_b
124 gpr_hazard2: entity work.gpr_hazard
126 PIPELINE_DEPTH => PIPELINE_DEPTH
131 deferred => deferred,
132 complete_in => complete_in,
133 flush_in => flush_in,
134 issuing => valid_out,
136 gpr_write_valid_in => gpr_write_valid,
137 gpr_write_in => gpr_write_in,
138 bypass_avail => gpr_bypassable,
139 gpr_read_valid_in => gpr_c_read_valid_in,
140 gpr_read_in => gpr_c_read_in,
142 ugpr_write_valid => update_gpr_write_valid,
143 ugpr_write_reg => update_gpr_write_reg,
145 stall_out => stall_c_out,
146 use_bypass => gpr_bypass_c
149 cr_hazard0: entity work.cr_hazard
151 PIPELINE_DEPTH => PIPELINE_DEPTH
156 deferred => deferred,
157 complete_in => complete_in,
158 flush_in => flush_in,
159 issuing => valid_out,
161 cr_read_in => cr_read_in,
162 cr_write_in => cr_write_valid,
163 bypassable => cr_bypassable,
165 stall_out => cr_stall_out,
166 use_bypass => cr_bypass
169 control0: process(clk)
171 if rising_edge(clk) then
172 assert rin_int.outstanding >= 0 and rin_int.outstanding <= (PIPELINE_DEPTH+1)
173 report "Outstanding bad " & integer'image(rin_int.outstanding) severity failure;
178 control1 : process(all)
179 variable v_int : reg_internal_type;
180 variable valid_tmp : std_ulogic;
181 variable stall_tmp : std_ulogic;
186 valid_tmp := valid_in and not flush_in;
189 if flush_in = '1' then
190 -- expect to see complete_in next cycle
191 v_int.outstanding := 1;
192 elsif complete_in = '1' then
193 v_int.outstanding := r_int.outstanding - 1;
197 v_int := reg_internal_init;
201 -- Handle debugger stop
203 if stop_mark_in = '1' and v_int.outstanding = 0 then
207 -- state machine to handle instructions that must be single
208 -- through the pipeline.
211 if valid_tmp = '1' then
212 if (sgl_pipe_in = '1') then
213 if v_int.outstanding /= 0 then
214 v_int.state := WAIT_FOR_PREV_TO_COMPLETE;
217 -- send insn out and wait on it to complete
218 v_int.state := WAIT_FOR_CURR_TO_COMPLETE;
221 -- let it go out if there are no GPR hazards
222 stall_tmp := stall_a_out or stall_b_out or stall_c_out or cr_stall_out;
226 when WAIT_FOR_PREV_TO_COMPLETE =>
227 if v_int.outstanding = 0 then
228 -- send insn out and wait on it to complete
229 v_int.state := WAIT_FOR_CURR_TO_COMPLETE;
234 when WAIT_FOR_CURR_TO_COMPLETE =>
235 if v_int.outstanding = 0 then
237 -- XXX Don't replicate this
238 if valid_tmp = '1' then
239 if (sgl_pipe_in = '1') then
240 if v_int.outstanding /= 0 then
241 v_int.state := WAIT_FOR_PREV_TO_COMPLETE;
244 -- send insn out and wait on it to complete
245 v_int.state := WAIT_FOR_CURR_TO_COMPLETE;
248 -- let it go out if there are no GPR hazards
249 stall_tmp := stall_a_out or stall_b_out or stall_c_out or cr_stall_out;
257 if stall_tmp = '1' then
261 if valid_tmp = '1' then
262 if deferred = '0' then
263 v_int.outstanding := v_int.outstanding + 1;
265 gpr_write_valid <= gpr_write_valid_in;
266 cr_write_valid <= cr_write_in;
268 gpr_write_valid <= '0';
269 cr_write_valid <= '0';
273 valid_out <= valid_tmp;
274 stall_out <= stall_tmp or deferred;