2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
6 use work.decode_types.all;
9 use work.insn_helpers.all;
16 complete_in : in std_ulogic;
17 stall_in : in std_ulogic;
18 stall_out : out std_ulogic;
20 stopped_out : out std_ulogic;
22 flush_in: in std_ulogic;
24 d_in : in Decode1ToDecode2Type;
26 e_out : out Decode2ToExecute1Type;
27 l_out : out Decode2ToLoadstore1Type;
29 r_in : in RegisterFileToDecode2Type;
30 r_out : out Decode2ToRegisterFileType;
32 c_in : in CrFileToDecode2Type;
33 c_out : out Decode2ToCrFileType
37 architecture behaviour of decode2 is
38 type reg_type is record
39 e : Decode2ToExecute1Type;
40 l : Decode2ToLoadstore1Type;
43 signal r, rin : reg_type;
45 type decode_input_reg_t is record
46 reg_valid : std_ulogic;
48 data : std_ulogic_vector(63 downto 0);
51 type decode_output_reg_t is record
52 reg_valid : std_ulogic;
56 function decode_input_reg_a (t : input_reg_a_t; insn_in : std_ulogic_vector(31 downto 0);
57 reg_data : std_ulogic_vector(63 downto 0);
58 ispr : gspr_index_t) return decode_input_reg_t is
60 if t = RA or (t = RA_OR_ZERO and insn_ra(insn_in) /= "00000") then
61 assert is_fast_spr(ispr) = '0' report "Decode A says GPR but ISPR says SPR:" &
62 to_hstring(ispr) severity failure;
63 return ('1', gpr_to_gspr(insn_ra(insn_in)), reg_data);
65 -- ISPR must be either a valid fast SPR number or all 0 for a slow SPR.
66 -- If it's all 0, we don't treat it as a dependency as slow SPRs
67 -- operations are single issue.
69 assert is_fast_spr(ispr) = '1' or ispr = "000000"
70 report "Decode A says SPR but ISPR is invalid:" &
71 to_hstring(ispr) severity failure;
72 return (is_fast_spr(ispr), ispr, reg_data);
74 return ('0', (others => '0'), (others => '0'));
78 function decode_input_reg_b (t : input_reg_b_t; insn_in : std_ulogic_vector(31 downto 0);
79 reg_data : std_ulogic_vector(63 downto 0);
80 ispr : gspr_index_t) return decode_input_reg_t is
84 assert is_fast_spr(ispr) = '0' report "Decode B says GPR but ISPR says SPR:" &
85 to_hstring(ispr) severity failure;
86 return ('1', gpr_to_gspr(insn_rb(insn_in)), reg_data);
88 return ('0', (others => '0'), std_ulogic_vector(resize(unsigned(insn_ui(insn_in)), 64)));
90 return ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_si(insn_in)), 64)));
92 return ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_si(insn_in)) & x"0000", 64)));
94 return ('0', (others => '0'), std_ulogic_vector(resize(unsigned(insn_si(insn_in)) & x"0000", 64)));
96 return ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_li(insn_in)) & "00", 64)));
98 return ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_bd(insn_in)) & "00", 64)));
100 return ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_ds(insn_in)) & "00", 64)));
102 return ('0', (others => '0'), x"FFFFFFFFFFFFFFFF");
104 return ('0', (others => '0'), x"00000000000000" & "00" & insn_in(1) & insn_in(15 downto 11));
106 return ('0', (others => '0'), x"00000000000000" & "000" & insn_in(15 downto 11));
108 -- ISPR must be either a valid fast SPR number or all 0 for a slow SPR.
109 -- If it's all 0, we don't treat it as a dependency as slow SPRs
110 -- operations are single issue.
111 assert is_fast_spr(ispr) = '1' or ispr = "000000"
112 report "Decode B says SPR but ISPR is invalid:" &
113 to_hstring(ispr) severity failure;
114 return (is_fast_spr(ispr), ispr, reg_data);
116 return ('0', (others => '0'), (others => '0'));
120 function decode_input_reg_c (t : input_reg_c_t; insn_in : std_ulogic_vector(31 downto 0);
121 reg_data : std_ulogic_vector(63 downto 0)) return decode_input_reg_t is
125 return ('1', gpr_to_gspr(insn_rs(insn_in)), reg_data);
127 return ('0', (others => '0'), (others => '0'));
131 function decode_output_reg (t : output_reg_a_t; insn_in : std_ulogic_vector(31 downto 0);
132 ispr : gspr_index_t) return decode_output_reg_t is
136 return ('1', gpr_to_gspr(insn_rt(insn_in)));
138 return ('1', gpr_to_gspr(insn_ra(insn_in)));
140 -- ISPR must be either a valid fast SPR number or all 0 for a slow SPR.
141 -- If it's all 0, we don't treat it as a dependency as slow SPRs
142 -- operations are single issue.
143 assert is_fast_spr(ispr) = '1' or ispr = "000000"
144 report "Decode B says SPR but ISPR is invalid:" &
145 to_hstring(ispr) severity failure;
146 return (is_fast_spr(ispr), ispr);
148 return ('0', "000000");
152 function decode_rc (t : rc_t; insn_in : std_ulogic_vector(31 downto 0)) return std_ulogic is
156 return insn_rc(insn_in);
164 -- For now, use "rc" in the decode table to decide whether oe exists.
165 -- This is not entirely correct architecturally: For mulhd and
166 -- mulhdu, the OE field is reserved. It remains to be seen what an
167 -- actual POWER9 does if we set it on those instructions, for now we
168 -- test that further down when assigning to the multiplier oe input.
170 function decode_oe (t : rc_t; insn_in : std_ulogic_vector(31 downto 0)) return std_ulogic is
174 return insn_oe(insn_in);
180 -- issue control signals
181 signal control_valid_in : std_ulogic;
182 signal control_valid_out : std_ulogic;
183 signal control_sgl_pipe : std_logic;
185 signal gpr_write_valid : std_ulogic;
186 signal gpr_write : gspr_index_t;
188 signal gpr_a_read_valid : std_ulogic;
189 signal gpr_a_read :gspr_index_t;
191 signal gpr_b_read_valid : std_ulogic;
192 signal gpr_b_read : gspr_index_t;
194 signal gpr_c_read_valid : std_ulogic;
195 signal gpr_c_read : gpr_index_t;
197 signal cr_write_valid : std_ulogic;
199 control_0: entity work.control
207 complete_in => complete_in,
208 valid_in => control_valid_in,
209 stall_in => stall_in,
210 flush_in => flush_in,
211 sgl_pipe_in => control_sgl_pipe,
212 stop_mark_in => d_in.stop_mark,
214 gpr_write_valid_in => gpr_write_valid,
215 gpr_write_in => gpr_write,
217 gpr_a_read_valid_in => gpr_a_read_valid,
218 gpr_a_read_in => gpr_a_read,
220 gpr_b_read_valid_in => gpr_b_read_valid,
221 gpr_b_read_in => gpr_b_read,
223 gpr_c_read_valid_in => gpr_c_read_valid,
224 gpr_c_read_in => gpr_c_read,
226 cr_read_in => d_in.decode.input_cr,
227 cr_write_in => cr_write_valid,
229 valid_out => control_valid_out,
230 stall_out => stall_out,
231 stopped_out => stopped_out
234 decode2_0: process(clk)
236 if rising_edge(clk) then
237 if rin.e.valid = '1' or rin.l.valid = '1' then
238 report "execute " & to_hstring(rin.e.nia);
244 r_out.read1_reg <= gpr_or_spr_to_gspr(insn_ra(d_in.insn), d_in.ispr1);
245 r_out.read2_reg <= gpr_or_spr_to_gspr(insn_rb(d_in.insn), d_in.ispr2);
246 r_out.read3_reg <= insn_rs(d_in.insn);
248 c_out.read <= d_in.decode.input_cr;
250 decode2_1: process(all)
251 variable v : reg_type;
252 variable mul_a : std_ulogic_vector(63 downto 0);
253 variable mul_b : std_ulogic_vector(63 downto 0);
254 variable decoded_reg_a : decode_input_reg_t;
255 variable decoded_reg_b : decode_input_reg_t;
256 variable decoded_reg_c : decode_input_reg_t;
257 variable decoded_reg_o : decode_output_reg_t;
258 variable length : std_ulogic_vector(3 downto 0);
262 v.e := Decode2ToExecute1Init;
263 v.l := Decode2ToLoadStore1Init;
265 mul_a := (others => '0');
266 mul_b := (others => '0');
268 --v.e.input_cr := d_in.decode.input_cr;
269 --v.e.output_cr := d_in.decode.output_cr;
271 decoded_reg_a := decode_input_reg_a (d_in.decode.input_reg_a, d_in.insn, r_in.read1_data, d_in.ispr1);
272 decoded_reg_b := decode_input_reg_b (d_in.decode.input_reg_b, d_in.insn, r_in.read2_data, d_in.ispr2);
273 decoded_reg_c := decode_input_reg_c (d_in.decode.input_reg_c, d_in.insn, r_in.read3_data);
274 decoded_reg_o := decode_output_reg (d_in.decode.output_reg_a, d_in.insn, d_in.ispr1);
276 r_out.read1_enable <= decoded_reg_a.reg_valid;
277 r_out.read2_enable <= decoded_reg_b.reg_valid;
278 r_out.read3_enable <= decoded_reg_c.reg_valid;
280 case d_in.decode.length is
295 v.e.insn_type := d_in.decode.insn_type;
296 v.e.read_reg1 := decoded_reg_a.reg;
297 v.e.read_data1 := decoded_reg_a.data;
298 v.e.read_reg2 := decoded_reg_b.reg;
299 v.e.read_data2 := decoded_reg_b.data;
300 v.e.read_data3 := decoded_reg_c.data;
301 v.e.write_reg := decoded_reg_o.reg;
302 v.e.rc := decode_rc(d_in.decode.rc, d_in.insn);
303 if not (d_in.decode.insn_type = OP_MUL_H32 or d_in.decode.insn_type = OP_MUL_H64) then
304 v.e.oe := decode_oe(d_in.decode.rc, d_in.insn);
306 v.e.cr := c_in.read_cr_data;
307 v.e.xerc := c_in.read_xerc_data;
308 v.e.invert_a := d_in.decode.invert_a;
309 v.e.invert_out := d_in.decode.invert_out;
310 v.e.input_carry := d_in.decode.input_carry;
311 v.e.output_carry := d_in.decode.output_carry;
312 v.e.is_32bit := d_in.decode.is_32bit;
313 v.e.is_signed := d_in.decode.is_signed;
314 if d_in.decode.lr = '1' then
315 v.e.lr := insn_lk(d_in.insn);
317 v.e.insn := d_in.insn;
318 v.e.data_len := length;
321 v.l.update_reg := gspr_to_gpr(decoded_reg_a.reg);
322 v.l.addr1 := decoded_reg_a.data;
323 v.l.addr2 := decoded_reg_b.data;
324 v.l.data := decoded_reg_c.data;
325 v.l.write_reg := gspr_to_gpr(decoded_reg_o.reg);
327 if d_in.decode.insn_type = OP_LOAD then
333 v.l.length := length;
334 v.l.byte_reverse := d_in.decode.byte_reverse;
335 v.l.sign_extend := d_in.decode.sign_extend;
336 v.l.update := d_in.decode.update;
337 v.l.xerc := c_in.read_xerc_data;
340 control_valid_in <= d_in.valid;
341 control_sgl_pipe <= d_in.decode.sgl_pipe;
343 gpr_write_valid <= decoded_reg_o.reg_valid;
344 gpr_write <= decoded_reg_o.reg;
346 gpr_a_read_valid <= decoded_reg_a.reg_valid;
347 gpr_a_read <= decoded_reg_a.reg;
349 gpr_b_read_valid <= decoded_reg_b.reg_valid;
350 gpr_b_read <= decoded_reg_b.reg;
352 gpr_c_read_valid <= decoded_reg_c.reg_valid;
353 gpr_c_read <= gspr_to_gpr(decoded_reg_c.reg);
355 cr_write_valid <= d_in.decode.output_cr or decode_rc(d_in.decode.rc, d_in.insn);
359 case d_in.decode.unit is
361 v.e.valid := control_valid_out;
363 v.l.valid := control_valid_out;
365 v.e.valid := control_valid_out;
366 v.e.insn_type := OP_ILLEGAL;
370 v.e := Decode2ToExecute1Init;
371 v.l := Decode2ToLoadStore1Init;
381 end architecture behaviour;