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;
13 EX1_BYPASS : boolean := true;
14 HAS_FPU : boolean := true;
15 -- Non-zero to enable log data collection
16 LOG_LENGTH : natural := 0
22 complete_in : in instr_tag_t;
23 busy_in : in std_ulogic;
24 stall_out : out std_ulogic;
26 stopped_out : out std_ulogic;
28 flush_in: in std_ulogic;
30 d_in : in Decode1ToDecode2Type;
32 e_out : out Decode2ToExecute1Type;
34 r_in : in RegisterFileToDecode2Type;
35 r_out : out Decode2ToRegisterFileType;
37 c_in : in CrFileToDecode2Type;
38 c_out : out Decode2ToCrFileType;
40 log_out : out std_ulogic_vector(9 downto 0)
44 architecture behaviour of decode2 is
45 type reg_type is record
46 e : Decode2ToExecute1Type;
50 signal r, rin : reg_type;
52 signal deferred : std_ulogic;
54 type decode_input_reg_t is record
55 reg_valid : std_ulogic;
57 data : std_ulogic_vector(63 downto 0);
60 type decode_output_reg_t is record
61 reg_valid : std_ulogic;
65 function decode_input_reg_a (t : input_reg_a_t; insn_in : std_ulogic_vector(31 downto 0);
66 reg_data : std_ulogic_vector(63 downto 0);
68 instr_addr : std_ulogic_vector(63 downto 0))
69 return decode_input_reg_t is
71 if t = RA or (t = RA_OR_ZERO and insn_ra(insn_in) /= "00000") then
72 return ('1', gpr_to_gspr(insn_ra(insn_in)), reg_data);
74 -- ISPR must be either a valid fast SPR number or all 0 for a slow SPR.
75 -- If it's all 0, we don't treat it as a dependency as slow SPRs
76 -- operations are single issue.
78 assert is_fast_spr(ispr) = '1' or ispr = "0000000"
79 report "Decode A says SPR but ISPR is invalid:" &
80 to_hstring(ispr) severity failure;
81 return (is_fast_spr(ispr), ispr, reg_data);
83 return ('0', (others => '0'), instr_addr);
84 elsif HAS_FPU and t = FRA then
85 return ('1', fpr_to_gspr(insn_fra(insn_in)), reg_data);
87 return ('0', (others => '0'), (others => '0'));
91 function decode_input_reg_b (t : input_reg_b_t; insn_in : std_ulogic_vector(31 downto 0);
92 reg_data : std_ulogic_vector(63 downto 0);
93 ispr : gspr_index_t) return decode_input_reg_t is
94 variable ret : decode_input_reg_t;
98 ret := ('1', gpr_to_gspr(insn_rb(insn_in)), reg_data);
101 ret := ('1', fpr_to_gspr(insn_frb(insn_in)), reg_data);
103 ret := ('0', (others => '0'), (others => '0'));
106 ret := ('0', (others => '0'), std_ulogic_vector(resize(unsigned(insn_ui(insn_in)), 64)));
108 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_si(insn_in)), 64)));
110 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_si(insn_in)) & x"0000", 64)));
112 ret := ('0', (others => '0'), std_ulogic_vector(resize(unsigned(insn_si(insn_in)) & x"0000", 64)));
114 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_li(insn_in)) & "00", 64)));
116 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_bd(insn_in)) & "00", 64)));
118 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_ds(insn_in)) & "00", 64)));
120 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_dq(insn_in)) & "0000", 64)));
122 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_dx(insn_in)) & x"0004", 64)));
124 ret := ('0', (others => '0'), x"FFFFFFFFFFFFFFFF");
126 ret := ('0', (others => '0'), x"00000000000000" & "00" & insn_in(1) & insn_in(15 downto 11));
128 ret := ('0', (others => '0'), x"00000000000000" & "000" & insn_in(15 downto 11));
130 -- ISPR must be either a valid fast SPR number or all 0 for a slow SPR.
131 -- If it's all 0, we don't treat it as a dependency as slow SPRs
132 -- operations are single issue.
133 assert is_fast_spr(ispr) = '1' or ispr = "0000000"
134 report "Decode B says SPR but ISPR is invalid:" &
135 to_hstring(ispr) severity failure;
136 ret := (is_fast_spr(ispr), ispr, reg_data);
138 ret := ('0', (others => '0'), (others => '0'));
144 function decode_input_reg_c (t : input_reg_c_t; insn_in : std_ulogic_vector(31 downto 0);
145 reg_data : std_ulogic_vector(63 downto 0)) return decode_input_reg_t is
149 return ('1', gpr_to_gspr(insn_rs(insn_in)), reg_data);
151 return ('1', gpr_to_gspr(insn_rcreg(insn_in)), reg_data);
154 return ('1', fpr_to_gspr(insn_frt(insn_in)), reg_data);
156 return ('0', (others => '0'), (others => '0'));
160 return ('1', fpr_to_gspr(insn_frc(insn_in)), reg_data);
162 return ('0', (others => '0'), (others => '0'));
165 return ('0', (others => '0'), (others => '0'));
169 function decode_output_reg (t : output_reg_a_t; insn_in : std_ulogic_vector(31 downto 0);
170 ispr : gspr_index_t) return decode_output_reg_t is
174 return ('1', gpr_to_gspr(insn_rt(insn_in)));
176 return ('1', gpr_to_gspr(insn_ra(insn_in)));
179 return ('1', fpr_to_gspr(insn_frt(insn_in)));
181 return ('0', "0000000");
184 -- ISPR must be either a valid fast SPR number or all 0 for a slow SPR.
185 -- If it's all 0, we don't treat it as a dependency as slow SPRs
186 -- operations are single issue.
187 assert is_fast_spr(ispr) = '1' or ispr = "0000000"
188 report "Decode B says SPR but ISPR is invalid:" &
189 to_hstring(ispr) severity failure;
190 return (is_fast_spr(ispr), ispr);
192 return ('0', "0000000");
196 function decode_rc (t : rc_t; insn_in : std_ulogic_vector(31 downto 0)) return std_ulogic is
200 return insn_rc(insn_in);
208 -- For now, use "rc" in the decode table to decide whether oe exists.
209 -- This is not entirely correct architecturally: For mulhd and
210 -- mulhdu, the OE field is reserved. It remains to be seen what an
211 -- actual POWER9 does if we set it on those instructions, for now we
212 -- test that further down when assigning to the multiplier oe input.
214 function decode_oe (t : rc_t; insn_in : std_ulogic_vector(31 downto 0)) return std_ulogic is
218 return insn_oe(insn_in);
224 -- control signals that are derived from insn_type
225 type mux_select_array_t is array(insn_type_t) of std_ulogic_vector(2 downto 0);
227 constant result_select : mux_select_array_t := (
228 OP_AND => "001", -- logical_result
238 OP_RLC => "010", -- rotator_result
243 OP_EXTSWSLI => "010",
244 OP_MUL_L64 => "011", -- muldiv_result
250 OP_CNTZ => "100", -- countzero_result
251 OP_MFSPR => "101", -- spr_result
252 OP_B => "110", -- next_nia
255 OP_ADDG6S => "111", -- misc_result
261 others => "000" -- default to adder_result
264 constant subresult_select : mux_select_array_t := (
265 OP_MUL_L64 => "000", -- muldiv_result
271 OP_ADDG6S => "001", -- misc_result
280 -- issue control signals
281 signal control_valid_in : std_ulogic;
282 signal control_valid_out : std_ulogic;
283 signal control_stall_out : std_ulogic;
284 signal control_sgl_pipe : std_logic;
286 signal gpr_write_valid : std_ulogic;
287 signal gpr_write : gspr_index_t;
288 signal gpr_bypassable : std_ulogic;
290 signal gpr_a_read_valid : std_ulogic;
291 signal gpr_a_read :gspr_index_t;
292 signal gpr_a_bypass : std_ulogic;
294 signal gpr_b_read_valid : std_ulogic;
295 signal gpr_b_read : gspr_index_t;
296 signal gpr_b_bypass : std_ulogic;
298 signal gpr_c_read_valid : std_ulogic;
299 signal gpr_c_read : gspr_index_t;
300 signal gpr_c_bypass : std_ulogic;
302 signal cr_write_valid : std_ulogic;
303 signal cr_bypass : std_ulogic;
304 signal cr_bypass_avail : std_ulogic;
306 signal instr_tag : instr_tag_t;
309 control_0: entity work.control
317 complete_in => complete_in,
318 valid_in => control_valid_in,
319 repeated => r.repeat,
321 deferred => deferred,
322 flush_in => flush_in,
323 sgl_pipe_in => control_sgl_pipe,
324 stop_mark_in => d_in.stop_mark,
326 gpr_write_valid_in => gpr_write_valid,
327 gpr_write_in => gpr_write,
328 gpr_bypassable => gpr_bypassable,
330 gpr_a_read_valid_in => gpr_a_read_valid,
331 gpr_a_read_in => gpr_a_read,
333 gpr_b_read_valid_in => gpr_b_read_valid,
334 gpr_b_read_in => gpr_b_read,
336 gpr_c_read_valid_in => gpr_c_read_valid,
337 gpr_c_read_in => gpr_c_read,
339 cr_read_in => d_in.decode.input_cr,
340 cr_write_in => cr_write_valid,
341 cr_bypass => cr_bypass,
342 cr_bypassable => cr_bypass_avail,
344 valid_out => control_valid_out,
345 stall_out => control_stall_out,
346 stopped_out => stopped_out,
348 gpr_bypass_a => gpr_a_bypass,
349 gpr_bypass_b => gpr_b_bypass,
350 gpr_bypass_c => gpr_c_bypass,
352 instr_tag_out => instr_tag
355 deferred <= r.e.valid and busy_in;
357 decode2_0: process(clk)
359 if rising_edge(clk) then
360 if rst = '1' or flush_in = '1' or deferred = '0' then
361 if rin.e.valid = '1' then
362 report "execute " & to_hstring(rin.e.nia);
369 c_out.read <= d_in.decode.input_cr;
371 decode2_1: process(all)
372 variable v : reg_type;
373 variable mul_a : std_ulogic_vector(63 downto 0);
374 variable mul_b : std_ulogic_vector(63 downto 0);
375 variable decoded_reg_a : decode_input_reg_t;
376 variable decoded_reg_b : decode_input_reg_t;
377 variable decoded_reg_c : decode_input_reg_t;
378 variable decoded_reg_o : decode_output_reg_t;
379 variable length : std_ulogic_vector(3 downto 0);
380 variable op : insn_type_t;
384 v.e := Decode2ToExecute1Init;
386 mul_a := (others => '0');
387 mul_b := (others => '0');
389 --v.e.input_cr := d_in.decode.input_cr;
390 v.e.output_cr := d_in.decode.output_cr;
392 decoded_reg_a := decode_input_reg_a (d_in.decode.input_reg_a, d_in.insn, r_in.read1_data, d_in.ispr1,
394 decoded_reg_b := decode_input_reg_b (d_in.decode.input_reg_b, d_in.insn, r_in.read2_data, d_in.ispr2);
395 decoded_reg_c := decode_input_reg_c (d_in.decode.input_reg_c, d_in.insn, r_in.read3_data);
396 decoded_reg_o := decode_output_reg (d_in.decode.output_reg_a, d_in.insn, d_in.ispro);
398 if d_in.decode.lr = '1' then
399 v.e.lr := insn_lk(d_in.insn);
400 -- b and bc have even major opcodes; bcreg is considered absolute
401 v.e.br_abs := insn_aa(d_in.insn) or d_in.insn(26);
403 op := d_in.decode.insn_type;
405 if d_in.decode.repeat /= NONE then
407 v.e.second := r.repeat;
408 case d_in.decode.repeat is
410 -- do RS|1,RS for LE; RS,RS|1 for BE
411 if r.repeat = d_in.big_endian then
412 decoded_reg_c.reg(0) := '1';
415 -- do RT|1,RT for LE; RT,RT|1 for BE
416 if r.repeat = d_in.big_endian then
417 decoded_reg_o.reg(0) := '1';
420 -- update-form loads, 2nd instruction writes RA
421 if r.repeat = '1' then
422 decoded_reg_o.reg := decoded_reg_a.reg;
426 elsif v.e.lr = '1' and decoded_reg_a.reg_valid = '1' then
427 -- bcl/bclrl/bctarl that needs to write both CTR and LR has to be doubled
429 v.e.second := r.repeat;
430 -- first one does CTR, second does LR
431 decoded_reg_o.reg(0) := not r.repeat;
434 r_out.read1_enable <= decoded_reg_a.reg_valid and d_in.valid;
435 r_out.read1_reg <= decoded_reg_a.reg;
436 r_out.read2_enable <= decoded_reg_b.reg_valid and d_in.valid;
437 r_out.read2_reg <= decoded_reg_b.reg;
438 r_out.read3_enable <= decoded_reg_c.reg_valid and d_in.valid;
439 r_out.read3_reg <= decoded_reg_c.reg;
441 case d_in.decode.length is
456 v.e.unit := d_in.decode.unit;
457 v.e.fac := d_in.decode.facility;
458 v.e.instr_tag := instr_tag;
459 v.e.read_reg1 := decoded_reg_a.reg;
460 v.e.read_data1 := decoded_reg_a.data;
461 v.e.bypass_data1 := gpr_a_bypass;
462 v.e.read_reg2 := decoded_reg_b.reg;
463 v.e.read_data2 := decoded_reg_b.data;
464 v.e.bypass_data2 := gpr_b_bypass;
465 v.e.read_data3 := decoded_reg_c.data;
466 v.e.bypass_data3 := gpr_c_bypass;
467 v.e.write_reg := decoded_reg_o.reg;
468 v.e.write_reg_enable := decoded_reg_o.reg_valid;
469 v.e.rc := decode_rc(d_in.decode.rc, d_in.insn);
470 if not (d_in.decode.insn_type = OP_MUL_H32 or d_in.decode.insn_type = OP_MUL_H64) then
471 v.e.oe := decode_oe(d_in.decode.rc, d_in.insn);
473 v.e.cr := c_in.read_cr_data;
474 v.e.bypass_cr := cr_bypass;
475 v.e.xerc := c_in.read_xerc_data;
476 v.e.invert_a := d_in.decode.invert_a;
479 v.e.invert_out := d_in.decode.invert_out;
480 v.e.input_carry := d_in.decode.input_carry;
481 v.e.output_carry := d_in.decode.output_carry;
482 v.e.is_32bit := d_in.decode.is_32bit;
483 v.e.is_signed := d_in.decode.is_signed;
484 v.e.insn := d_in.insn;
485 v.e.data_len := length;
486 v.e.byte_reverse := d_in.decode.byte_reverse;
487 v.e.sign_extend := d_in.decode.sign_extend;
488 v.e.update := d_in.decode.update;
489 v.e.reserve := d_in.decode.reserve;
490 v.e.br_pred := d_in.br_pred;
491 v.e.result_sel := result_select(op);
492 v.e.sub_select := subresult_select(op);
493 if op = OP_BC or op = OP_BCREG then
494 if d_in.insn(23) = '0' and r.repeat = '0' and
495 not (d_in.decode.insn_type = OP_BCREG and d_in.insn(10) = '0') then
496 -- decrement CTR if BO(2) = 0 and not bcctr
498 v.e.result_sel := "000"; -- select adder output
503 control_valid_in <= d_in.valid;
504 control_sgl_pipe <= d_in.decode.sgl_pipe;
506 gpr_write_valid <= v.e.write_reg_enable;
507 gpr_write <= decoded_reg_o.reg;
508 gpr_bypassable <= '0';
509 if EX1_BYPASS and d_in.decode.unit = ALU then
510 gpr_bypassable <= '1';
513 gpr_a_read_valid <= decoded_reg_a.reg_valid;
514 gpr_a_read <= decoded_reg_a.reg;
516 gpr_b_read_valid <= decoded_reg_b.reg_valid;
517 gpr_b_read <= decoded_reg_b.reg;
519 gpr_c_read_valid <= decoded_reg_c.reg_valid;
520 gpr_c_read <= decoded_reg_c.reg;
522 cr_write_valid <= d_in.decode.output_cr or decode_rc(d_in.decode.rc, d_in.insn);
523 cr_bypass_avail <= '0';
524 if EX1_BYPASS and d_in.decode.unit = ALU then
525 cr_bypass_avail <= d_in.decode.output_cr;
528 v.e.valid := control_valid_out;
529 if control_valid_out = '1' then
530 v.repeat := v.e.repeat and not r.repeat;
533 stall_out <= control_stall_out or v.repeat;
535 if rst = '1' or flush_in = '1' then
536 v.e := Decode2ToExecute1Init;
547 d2_log: if LOG_LENGTH > 0 generate
548 signal log_data : std_ulogic_vector(9 downto 0);
550 dec2_log : process(clk)
552 if rising_edge(clk) then
553 log_data <= r.e.nia(5 downto 2) &
565 end architecture behaviour;