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 gpr_index_t;
39 cr_read_in : in std_ulogic;
40 cr_write_in : in std_ulogic;
42 valid_out : out std_ulogic;
43 stall_out : out std_ulogic;
44 stopped_out : out std_ulogic;
46 gpr_bypass_a : out std_ulogic;
47 gpr_bypass_b : out std_ulogic;
48 gpr_bypass_c : out std_ulogic
52 architecture rtl of control is
53 type state_type is (IDLE, WAIT_FOR_PREV_TO_COMPLETE, WAIT_FOR_CURR_TO_COMPLETE);
55 type reg_internal_type is record
57 outstanding : integer range -1 to PIPELINE_DEPTH+2;
59 constant reg_internal_init : reg_internal_type := (state => IDLE, outstanding => 0);
61 signal r_int, rin_int : reg_internal_type := reg_internal_init;
63 signal stall_a_out : std_ulogic;
64 signal stall_b_out : std_ulogic;
65 signal stall_c_out : std_ulogic;
66 signal cr_stall_out : std_ulogic;
68 signal gpr_write_valid : std_ulogic := '0';
69 signal cr_write_valid : std_ulogic := '0';
71 signal gpr_c_read_in_fmt : std_ulogic_vector(5 downto 0);
73 gpr_hazard0: entity work.gpr_hazard
75 PIPELINE_DEPTH => PIPELINE_DEPTH
81 complete_in => complete_in,
85 gpr_write_valid_in => gpr_write_valid,
86 gpr_write_in => gpr_write_in,
87 bypass_avail => gpr_bypassable,
88 gpr_read_valid_in => gpr_a_read_valid_in,
89 gpr_read_in => gpr_a_read_in,
91 ugpr_write_valid => update_gpr_write_valid,
92 ugpr_write_reg => update_gpr_write_reg,
94 stall_out => stall_a_out,
95 use_bypass => gpr_bypass_a
98 gpr_hazard1: entity work.gpr_hazard
100 PIPELINE_DEPTH => PIPELINE_DEPTH
105 deferred => deferred,
106 complete_in => complete_in,
107 flush_in => flush_in,
108 issuing => valid_out,
110 gpr_write_valid_in => gpr_write_valid,
111 gpr_write_in => gpr_write_in,
112 bypass_avail => gpr_bypassable,
113 gpr_read_valid_in => gpr_b_read_valid_in,
114 gpr_read_in => gpr_b_read_in,
116 ugpr_write_valid => update_gpr_write_valid,
117 ugpr_write_reg => update_gpr_write_reg,
119 stall_out => stall_b_out,
120 use_bypass => gpr_bypass_b
123 gpr_c_read_in_fmt <= "0" & gpr_c_read_in;
125 gpr_hazard2: entity work.gpr_hazard
127 PIPELINE_DEPTH => PIPELINE_DEPTH
132 deferred => deferred,
133 complete_in => complete_in,
134 flush_in => flush_in,
135 issuing => valid_out,
137 gpr_write_valid_in => gpr_write_valid,
138 gpr_write_in => gpr_write_in,
139 bypass_avail => gpr_bypassable,
140 gpr_read_valid_in => gpr_c_read_valid_in,
141 gpr_read_in => gpr_c_read_in_fmt,
143 ugpr_write_valid => update_gpr_write_valid,
144 ugpr_write_reg => update_gpr_write_reg,
146 stall_out => stall_c_out,
147 use_bypass => gpr_bypass_c
150 cr_hazard0: entity work.cr_hazard
152 PIPELINE_DEPTH => PIPELINE_DEPTH
157 deferred => deferred,
158 complete_in => complete_in,
159 flush_in => flush_in,
160 issuing => valid_out,
162 cr_read_in => cr_read_in,
163 cr_write_in => cr_write_valid,
165 stall_out => cr_stall_out
168 control0: process(clk)
170 if rising_edge(clk) then
171 assert rin_int.outstanding >= 0 and rin_int.outstanding <= (PIPELINE_DEPTH+1)
172 report "Outstanding bad " & integer'image(rin_int.outstanding) severity failure;
177 control1 : process(all)
178 variable v_int : reg_internal_type;
179 variable valid_tmp : std_ulogic;
180 variable stall_tmp : std_ulogic;
185 valid_tmp := valid_in and not flush_in;
188 if flush_in = '1' then
189 -- expect to see complete_in next cycle
190 v_int.outstanding := 1;
191 elsif complete_in = '1' then
192 v_int.outstanding := r_int.outstanding - 1;
196 v_int := reg_internal_init;
200 -- Handle debugger stop
202 if stop_mark_in = '1' and v_int.outstanding = 0 then
206 -- state machine to handle instructions that must be single
207 -- through the pipeline.
210 if valid_tmp = '1' then
211 if (sgl_pipe_in = '1') then
212 if v_int.outstanding /= 0 then
213 v_int.state := WAIT_FOR_PREV_TO_COMPLETE;
216 -- send insn out and wait on it to complete
217 v_int.state := WAIT_FOR_CURR_TO_COMPLETE;
220 -- let it go out if there are no GPR hazards
221 stall_tmp := stall_a_out or stall_b_out or stall_c_out or cr_stall_out;
225 when WAIT_FOR_PREV_TO_COMPLETE =>
226 if v_int.outstanding = 0 then
227 -- send insn out and wait on it to complete
228 v_int.state := WAIT_FOR_CURR_TO_COMPLETE;
233 when WAIT_FOR_CURR_TO_COMPLETE =>
234 if v_int.outstanding = 0 then
236 -- XXX Don't replicate this
237 if valid_tmp = '1' then
238 if (sgl_pipe_in = '1') then
239 if v_int.outstanding /= 0 then
240 v_int.state := WAIT_FOR_PREV_TO_COMPLETE;
243 -- send insn out and wait on it to complete
244 v_int.state := WAIT_FOR_CURR_TO_COMPLETE;
247 -- let it go out if there are no GPR hazards
248 stall_tmp := stall_a_out or stall_b_out or stall_c_out or cr_stall_out;
256 if stall_tmp = '1' then
260 if valid_tmp = '1' then
261 if deferred = '0' then
262 v_int.outstanding := v_int.outstanding + 1;
264 gpr_write_valid <= gpr_write_valid_in;
265 cr_write_valid <= cr_write_in;
267 gpr_write_valid <= '0';
268 cr_write_valid <= '0';
272 valid_out <= valid_tmp;
273 stall_out <= stall_tmp or deferred;