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 execute_bypass : in bypass_data_t;
42 log_out : out std_ulogic_vector(9 downto 0)
46 architecture behaviour of decode2 is
47 type reg_type is record
48 e : Decode2ToExecute1Type;
52 signal r, rin : reg_type;
54 signal deferred : std_ulogic;
56 type decode_input_reg_t is record
57 reg_valid : std_ulogic;
59 data : std_ulogic_vector(63 downto 0);
62 type decode_output_reg_t is record
63 reg_valid : std_ulogic;
67 function decode_input_reg_a (t : input_reg_a_t; insn_in : std_ulogic_vector(31 downto 0);
68 reg_data : std_ulogic_vector(63 downto 0);
70 instr_addr : std_ulogic_vector(63 downto 0))
71 return decode_input_reg_t is
73 if t = RA or (t = RA_OR_ZERO and insn_ra(insn_in) /= "00000") then
74 return ('1', gpr_to_gspr(insn_ra(insn_in)), reg_data);
76 -- ISPR must be either a valid fast SPR number or all 0 for a slow SPR.
77 -- If it's all 0, we don't treat it as a dependency as slow SPRs
78 -- operations are single issue.
80 assert is_fast_spr(ispr) = '1' or ispr = "0000000"
81 report "Decode A says SPR but ISPR is invalid:" &
82 to_hstring(ispr) severity failure;
83 return (is_fast_spr(ispr), ispr, reg_data);
85 return ('0', (others => '0'), instr_addr);
86 elsif HAS_FPU and t = FRA then
87 return ('1', fpr_to_gspr(insn_fra(insn_in)), reg_data);
89 return ('0', (others => '0'), (others => '0'));
93 function decode_input_reg_b (t : input_reg_b_t; insn_in : std_ulogic_vector(31 downto 0);
94 reg_data : std_ulogic_vector(63 downto 0);
95 ispr : gspr_index_t) return decode_input_reg_t is
96 variable ret : decode_input_reg_t;
100 ret := ('1', gpr_to_gspr(insn_rb(insn_in)), reg_data);
103 ret := ('1', fpr_to_gspr(insn_frb(insn_in)), reg_data);
105 ret := ('0', (others => '0'), (others => '0'));
108 ret := ('0', (others => '0'), std_ulogic_vector(resize(unsigned(insn_ui(insn_in)), 64)));
110 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_si(insn_in)), 64)));
112 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_si(insn_in)) & x"0000", 64)));
114 ret := ('0', (others => '0'), std_ulogic_vector(resize(unsigned(insn_si(insn_in)) & x"0000", 64)));
116 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_li(insn_in)) & "00", 64)));
118 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_bd(insn_in)) & "00", 64)));
120 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_ds(insn_in)) & "00", 64)));
122 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_dq(insn_in)) & "0000", 64)));
124 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_dx(insn_in)) & x"0004", 64)));
126 ret := ('0', (others => '0'), x"FFFFFFFFFFFFFFFF");
128 ret := ('0', (others => '0'), x"00000000000000" & "00" & insn_in(1) & insn_in(15 downto 11));
130 ret := ('0', (others => '0'), x"00000000000000" & "000" & insn_in(15 downto 11));
132 -- ISPR must be either a valid fast SPR number or all 0 for a slow SPR.
133 -- If it's all 0, we don't treat it as a dependency as slow SPRs
134 -- operations are single issue.
135 assert is_fast_spr(ispr) = '1' or ispr = "0000000"
136 report "Decode B says SPR but ISPR is invalid:" &
137 to_hstring(ispr) severity failure;
138 ret := (is_fast_spr(ispr), ispr, reg_data);
140 ret := ('0', (others => '0'), (others => '0'));
146 function decode_input_reg_c (t : input_reg_c_t; insn_in : std_ulogic_vector(31 downto 0);
147 reg_data : std_ulogic_vector(63 downto 0)) return decode_input_reg_t is
151 return ('1', gpr_to_gspr(insn_rs(insn_in)), reg_data);
153 return ('1', gpr_to_gspr(insn_rcreg(insn_in)), reg_data);
156 return ('1', fpr_to_gspr(insn_frt(insn_in)), reg_data);
158 return ('0', (others => '0'), (others => '0'));
162 return ('1', fpr_to_gspr(insn_frc(insn_in)), reg_data);
164 return ('0', (others => '0'), (others => '0'));
167 return ('0', (others => '0'), (others => '0'));
171 function decode_output_reg (t : output_reg_a_t; insn_in : std_ulogic_vector(31 downto 0);
172 ispr : gspr_index_t) return decode_output_reg_t is
176 return ('1', gpr_to_gspr(insn_rt(insn_in)));
178 return ('1', gpr_to_gspr(insn_ra(insn_in)));
181 return ('1', fpr_to_gspr(insn_frt(insn_in)));
183 return ('0', "0000000");
186 -- ISPR must be either a valid fast SPR number or all 0 for a slow SPR.
187 -- If it's all 0, we don't treat it as a dependency as slow SPRs
188 -- operations are single issue.
189 assert is_fast_spr(ispr) = '1' or ispr = "0000000"
190 report "Decode B says SPR but ISPR is invalid:" &
191 to_hstring(ispr) severity failure;
192 return (is_fast_spr(ispr), ispr);
194 return ('0', "0000000");
198 function decode_rc (t : rc_t; insn_in : std_ulogic_vector(31 downto 0)) return std_ulogic is
202 return insn_rc(insn_in);
210 -- For now, use "rc" in the decode table to decide whether oe exists.
211 -- This is not entirely correct architecturally: For mulhd and
212 -- mulhdu, the OE field is reserved. It remains to be seen what an
213 -- actual POWER9 does if we set it on those instructions, for now we
214 -- test that further down when assigning to the multiplier oe input.
216 function decode_oe (t : rc_t; insn_in : std_ulogic_vector(31 downto 0)) return std_ulogic is
220 return insn_oe(insn_in);
226 -- control signals that are derived from insn_type
227 type mux_select_array_t is array(insn_type_t) of std_ulogic_vector(2 downto 0);
229 constant result_select : mux_select_array_t := (
230 OP_AND => "001", -- logical_result
240 OP_RLC => "010", -- rotator_result
245 OP_EXTSWSLI => "010",
246 OP_MUL_L64 => "011", -- muldiv_result
252 OP_CNTZ => "100", -- countzero_result
253 OP_MFSPR => "101", -- spr_result
254 OP_B => "110", -- next_nia
257 OP_ADDG6S => "111", -- misc_result
263 others => "000" -- default to adder_result
266 constant subresult_select : mux_select_array_t := (
267 OP_MUL_L64 => "000", -- muldiv_result
273 OP_ADDG6S => "001", -- misc_result
282 -- issue control signals
283 signal control_valid_in : std_ulogic;
284 signal control_valid_out : std_ulogic;
285 signal control_stall_out : std_ulogic;
286 signal control_sgl_pipe : std_logic;
288 signal gpr_write_valid : std_ulogic;
289 signal gpr_write : gspr_index_t;
291 signal gpr_a_read_valid : std_ulogic;
292 signal gpr_a_read : gspr_index_t;
293 signal gpr_a_bypass : std_ulogic;
295 signal gpr_b_read_valid : std_ulogic;
296 signal gpr_b_read : gspr_index_t;
297 signal gpr_b_bypass : std_ulogic;
299 signal gpr_c_read_valid : std_ulogic;
300 signal gpr_c_read : gspr_index_t;
301 signal gpr_c_bypass : std_ulogic;
303 signal cr_write_valid : std_ulogic;
304 signal cr_bypass : std_ulogic;
305 signal cr_bypass_avail : std_ulogic;
307 signal instr_tag : instr_tag_t;
310 control_0: entity work.control
312 EX1_BYPASS => EX1_BYPASS,
319 complete_in => complete_in,
320 valid_in => control_valid_in,
321 repeated => r.repeat,
323 deferred => deferred,
324 flush_in => flush_in,
325 sgl_pipe_in => control_sgl_pipe,
326 stop_mark_in => d_in.stop_mark,
328 gpr_write_valid_in => gpr_write_valid,
329 gpr_write_in => gpr_write,
331 gpr_a_read_valid_in => gpr_a_read_valid,
332 gpr_a_read_in => gpr_a_read,
334 gpr_b_read_valid_in => gpr_b_read_valid,
335 gpr_b_read_in => gpr_b_read,
337 gpr_c_read_valid_in => gpr_c_read_valid,
338 gpr_c_read_in => gpr_c_read,
340 execute_next_tag => execute_bypass.tag,
342 cr_read_in => d_in.decode.input_cr,
343 cr_write_in => cr_write_valid,
344 cr_bypass => cr_bypass,
345 cr_bypassable => cr_bypass_avail,
347 valid_out => control_valid_out,
348 stall_out => control_stall_out,
349 stopped_out => stopped_out,
351 gpr_bypass_a => gpr_a_bypass,
352 gpr_bypass_b => gpr_b_bypass,
353 gpr_bypass_c => gpr_c_bypass,
355 instr_tag_out => instr_tag
358 deferred <= r.e.valid and busy_in;
360 decode2_0: process(clk)
362 if rising_edge(clk) then
363 if rst = '1' or flush_in = '1' or deferred = '0' then
364 if rin.e.valid = '1' then
365 report "execute " & to_hstring(rin.e.nia);
372 c_out.read <= d_in.decode.input_cr;
374 decode2_1: process(all)
375 variable v : reg_type;
376 variable mul_a : std_ulogic_vector(63 downto 0);
377 variable mul_b : std_ulogic_vector(63 downto 0);
378 variable decoded_reg_a : decode_input_reg_t;
379 variable decoded_reg_b : decode_input_reg_t;
380 variable decoded_reg_c : decode_input_reg_t;
381 variable decoded_reg_o : decode_output_reg_t;
382 variable length : std_ulogic_vector(3 downto 0);
383 variable op : insn_type_t;
387 v.e := Decode2ToExecute1Init;
389 mul_a := (others => '0');
390 mul_b := (others => '0');
392 --v.e.input_cr := d_in.decode.input_cr;
393 v.e.output_cr := d_in.decode.output_cr;
395 decoded_reg_a := decode_input_reg_a (d_in.decode.input_reg_a, d_in.insn, r_in.read1_data, d_in.ispr1,
397 decoded_reg_b := decode_input_reg_b (d_in.decode.input_reg_b, d_in.insn, r_in.read2_data, d_in.ispr2);
398 decoded_reg_c := decode_input_reg_c (d_in.decode.input_reg_c, d_in.insn, r_in.read3_data);
399 decoded_reg_o := decode_output_reg (d_in.decode.output_reg_a, d_in.insn, d_in.ispro);
401 if d_in.decode.lr = '1' then
402 v.e.lr := insn_lk(d_in.insn);
403 -- b and bc have even major opcodes; bcreg is considered absolute
404 v.e.br_abs := insn_aa(d_in.insn) or d_in.insn(26);
406 op := d_in.decode.insn_type;
408 if d_in.decode.repeat /= NONE then
410 v.e.second := r.repeat;
411 case d_in.decode.repeat is
413 -- do RS|1,RS for LE; RS,RS|1 for BE
414 if r.repeat = d_in.big_endian then
415 decoded_reg_c.reg(0) := '1';
418 -- do RT|1,RT for LE; RT,RT|1 for BE
419 if r.repeat = d_in.big_endian then
420 decoded_reg_o.reg(0) := '1';
423 -- update-form loads, 2nd instruction writes RA
424 if r.repeat = '1' then
425 decoded_reg_o.reg := decoded_reg_a.reg;
429 elsif v.e.lr = '1' and decoded_reg_a.reg_valid = '1' then
430 -- bcl/bclrl/bctarl that needs to write both CTR and LR has to be doubled
432 v.e.second := r.repeat;
433 -- first one does CTR, second does LR
434 decoded_reg_o.reg(0) := not r.repeat;
437 r_out.read1_enable <= decoded_reg_a.reg_valid and d_in.valid;
438 r_out.read1_reg <= decoded_reg_a.reg;
439 r_out.read2_enable <= decoded_reg_b.reg_valid and d_in.valid;
440 r_out.read2_reg <= decoded_reg_b.reg;
441 r_out.read3_enable <= decoded_reg_c.reg_valid and d_in.valid;
442 r_out.read3_reg <= decoded_reg_c.reg;
444 case d_in.decode.length is
459 v.e.unit := d_in.decode.unit;
460 v.e.fac := d_in.decode.facility;
461 v.e.instr_tag := instr_tag;
462 v.e.read_reg1 := decoded_reg_a.reg;
463 v.e.read_reg2 := decoded_reg_b.reg;
464 v.e.write_reg := decoded_reg_o.reg;
465 v.e.write_reg_enable := decoded_reg_o.reg_valid;
466 v.e.rc := decode_rc(d_in.decode.rc, d_in.insn);
467 if not (d_in.decode.insn_type = OP_MUL_H32 or d_in.decode.insn_type = OP_MUL_H64) then
468 v.e.oe := decode_oe(d_in.decode.rc, d_in.insn);
470 v.e.cr := c_in.read_cr_data;
471 v.e.bypass_cr := cr_bypass;
472 v.e.xerc := c_in.read_xerc_data;
473 v.e.invert_a := d_in.decode.invert_a;
476 v.e.invert_out := d_in.decode.invert_out;
477 v.e.input_carry := d_in.decode.input_carry;
478 v.e.output_carry := d_in.decode.output_carry;
479 v.e.is_32bit := d_in.decode.is_32bit;
480 v.e.is_signed := d_in.decode.is_signed;
481 v.e.insn := d_in.insn;
482 v.e.data_len := length;
483 v.e.byte_reverse := d_in.decode.byte_reverse;
484 v.e.sign_extend := d_in.decode.sign_extend;
485 v.e.update := d_in.decode.update;
486 v.e.reserve := d_in.decode.reserve;
487 v.e.br_pred := d_in.br_pred;
488 v.e.result_sel := result_select(op);
489 v.e.sub_select := subresult_select(op);
490 if op = OP_BC or op = OP_BCREG then
491 if d_in.insn(23) = '0' and r.repeat = '0' and
492 not (d_in.decode.insn_type = OP_BCREG and d_in.insn(10) = '0') then
493 -- decrement CTR if BO(2) = 0 and not bcctr
495 v.e.result_sel := "000"; -- select adder output
499 -- See if any of the operands can get their value via the bypass path.
502 v.e.read_data1 := execute_bypass.data;
504 v.e.read_data1 := decoded_reg_a.data;
508 v.e.read_data2 := execute_bypass.data;
510 v.e.read_data2 := decoded_reg_b.data;
514 v.e.read_data3 := execute_bypass.data;
516 v.e.read_data3 := decoded_reg_c.data;
520 control_valid_in <= d_in.valid;
521 control_sgl_pipe <= d_in.decode.sgl_pipe;
523 gpr_write_valid <= v.e.write_reg_enable;
524 gpr_write <= decoded_reg_o.reg;
526 gpr_a_read_valid <= decoded_reg_a.reg_valid;
527 gpr_a_read <= decoded_reg_a.reg;
529 gpr_b_read_valid <= decoded_reg_b.reg_valid;
530 gpr_b_read <= decoded_reg_b.reg;
532 gpr_c_read_valid <= decoded_reg_c.reg_valid;
533 gpr_c_read <= decoded_reg_c.reg;
535 cr_write_valid <= d_in.decode.output_cr or decode_rc(d_in.decode.rc, d_in.insn);
536 cr_bypass_avail <= '0';
537 if EX1_BYPASS and d_in.decode.unit = ALU then
538 cr_bypass_avail <= d_in.decode.output_cr;
541 v.e.valid := control_valid_out;
542 if control_valid_out = '1' then
543 v.repeat := v.e.repeat and not r.repeat;
546 stall_out <= control_stall_out or v.repeat;
548 if rst = '1' or flush_in = '1' then
549 v.e := Decode2ToExecute1Init;
560 d2_log: if LOG_LENGTH > 0 generate
561 signal log_data : std_ulogic_vector(9 downto 0);
563 dec2_log : process(clk)
565 if rising_edge(clk) then
566 log_data <= r.e.nia(5 downto 2) &
578 end architecture behaviour;