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
19 complete_in : in std_ulogic;
20 stall_in : in std_ulogic;
21 stall_out : out std_ulogic;
23 stopped_out : out std_ulogic;
25 flush_in: in std_ulogic;
27 d_in : in Decode1ToDecode2Type;
29 e_out : out Decode2ToExecute1Type;
31 r_in : in RegisterFileToDecode2Type;
32 r_out : out Decode2ToRegisterFileType;
34 c_in : in CrFileToDecode2Type;
35 c_out : out Decode2ToCrFileType
39 architecture behaviour of decode2 is
40 type reg_type is record
41 e : Decode2ToExecute1Type;
44 signal r, rin : reg_type;
46 type decode_input_reg_t is record
47 reg_valid : std_ulogic;
49 data : std_ulogic_vector(63 downto 0);
52 type decode_output_reg_t is record
53 reg_valid : std_ulogic;
57 function decode_input_reg_a (t : input_reg_a_t; insn_in : std_ulogic_vector(31 downto 0);
58 reg_data : std_ulogic_vector(63 downto 0);
59 ispr : gspr_index_t) return decode_input_reg_t is
61 if t = RA or (t = RA_OR_ZERO and insn_ra(insn_in) /= "00000") then
62 assert is_fast_spr(ispr) = '0' report "Decode A says GPR but ISPR says SPR:" &
63 to_hstring(ispr) severity failure;
64 return ('1', gpr_to_gspr(insn_ra(insn_in)), reg_data);
66 -- ISPR must be either a valid fast SPR number or all 0 for a slow SPR.
67 -- If it's all 0, we don't treat it as a dependency as slow SPRs
68 -- operations are single issue.
70 assert is_fast_spr(ispr) = '1' or ispr = "000000"
71 report "Decode A says SPR but ISPR is invalid:" &
72 to_hstring(ispr) severity failure;
73 return (is_fast_spr(ispr), ispr, reg_data);
75 return ('0', (others => '0'), (others => '0'));
79 function decode_input_reg_b (t : input_reg_b_t; insn_in : std_ulogic_vector(31 downto 0);
80 reg_data : std_ulogic_vector(63 downto 0);
81 ispr : gspr_index_t) return decode_input_reg_t is
82 variable ret : decode_input_reg_t;
86 assert is_fast_spr(ispr) = '0' report "Decode B says GPR but ISPR says SPR:" &
87 to_hstring(ispr) severity failure;
88 ret := ('1', gpr_to_gspr(insn_rb(insn_in)), reg_data);
90 ret := ('0', (others => '0'), std_ulogic_vector(resize(unsigned(insn_ui(insn_in)), 64)));
92 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_si(insn_in)), 64)));
94 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_si(insn_in)) & x"0000", 64)));
96 ret := ('0', (others => '0'), std_ulogic_vector(resize(unsigned(insn_si(insn_in)) & x"0000", 64)));
98 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_li(insn_in)) & "00", 64)));
100 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_bd(insn_in)) & "00", 64)));
102 ret := ('0', (others => '0'), std_ulogic_vector(resize(signed(insn_ds(insn_in)) & "00", 64)));
104 ret := ('0', (others => '0'), x"FFFFFFFFFFFFFFFF");
106 ret := ('0', (others => '0'), x"00000000000000" & "00" & insn_in(1) & insn_in(15 downto 11));
108 ret := ('0', (others => '0'), x"00000000000000" & "000" & insn_in(15 downto 11));
110 -- ISPR must be either a valid fast SPR number or all 0 for a slow SPR.
111 -- If it's all 0, we don't treat it as a dependency as slow SPRs
112 -- operations are single issue.
113 assert is_fast_spr(ispr) = '1' or ispr = "000000"
114 report "Decode B says SPR but ISPR is invalid:" &
115 to_hstring(ispr) severity failure;
116 ret := (is_fast_spr(ispr), ispr, reg_data);
118 ret := ('0', (others => '0'), (others => '0'));
124 function decode_input_reg_c (t : input_reg_c_t; insn_in : std_ulogic_vector(31 downto 0);
125 reg_data : std_ulogic_vector(63 downto 0)) return decode_input_reg_t is
129 return ('1', gpr_to_gspr(insn_rs(insn_in)), reg_data);
131 return ('0', (others => '0'), (others => '0'));
135 function decode_output_reg (t : output_reg_a_t; insn_in : std_ulogic_vector(31 downto 0);
136 ispr : gspr_index_t) return decode_output_reg_t is
140 return ('1', gpr_to_gspr(insn_rt(insn_in)));
142 return ('1', gpr_to_gspr(insn_ra(insn_in)));
144 -- ISPR must be either a valid fast SPR number or all 0 for a slow SPR.
145 -- If it's all 0, we don't treat it as a dependency as slow SPRs
146 -- operations are single issue.
147 assert is_fast_spr(ispr) = '1' or ispr = "000000"
148 report "Decode B says SPR but ISPR is invalid:" &
149 to_hstring(ispr) severity failure;
150 return (is_fast_spr(ispr), ispr);
152 return ('0', "000000");
156 function decode_rc (t : rc_t; insn_in : std_ulogic_vector(31 downto 0)) return std_ulogic is
160 return insn_rc(insn_in);
168 -- For now, use "rc" in the decode table to decide whether oe exists.
169 -- This is not entirely correct architecturally: For mulhd and
170 -- mulhdu, the OE field is reserved. It remains to be seen what an
171 -- actual POWER9 does if we set it on those instructions, for now we
172 -- test that further down when assigning to the multiplier oe input.
174 function decode_oe (t : rc_t; insn_in : std_ulogic_vector(31 downto 0)) return std_ulogic is
178 return insn_oe(insn_in);
184 -- issue control signals
185 signal control_valid_in : std_ulogic;
186 signal control_valid_out : std_ulogic;
187 signal control_sgl_pipe : std_logic;
189 signal gpr_write_valid : std_ulogic;
190 signal gpr_write : gspr_index_t;
191 signal gpr_bypassable : std_ulogic;
193 signal gpr_a_read_valid : std_ulogic;
194 signal gpr_a_read :gspr_index_t;
195 signal gpr_a_bypass : std_ulogic;
197 signal gpr_b_read_valid : std_ulogic;
198 signal gpr_b_read : gspr_index_t;
199 signal gpr_b_bypass : std_ulogic;
201 signal gpr_c_read_valid : std_ulogic;
202 signal gpr_c_read : gpr_index_t;
203 signal gpr_c_bypass : std_ulogic;
205 signal cr_write_valid : std_ulogic;
207 control_0: entity work.control
215 complete_in => complete_in,
216 valid_in => control_valid_in,
217 stall_in => stall_in,
218 flush_in => flush_in,
219 sgl_pipe_in => control_sgl_pipe,
220 stop_mark_in => d_in.stop_mark,
222 gpr_write_valid_in => gpr_write_valid,
223 gpr_write_in => gpr_write,
224 gpr_bypassable => gpr_bypassable,
226 gpr_a_read_valid_in => gpr_a_read_valid,
227 gpr_a_read_in => gpr_a_read,
229 gpr_b_read_valid_in => gpr_b_read_valid,
230 gpr_b_read_in => gpr_b_read,
232 gpr_c_read_valid_in => gpr_c_read_valid,
233 gpr_c_read_in => gpr_c_read,
235 cr_read_in => d_in.decode.input_cr,
236 cr_write_in => cr_write_valid,
238 valid_out => control_valid_out,
239 stall_out => stall_out,
240 stopped_out => stopped_out,
242 gpr_bypass_a => gpr_a_bypass,
243 gpr_bypass_b => gpr_b_bypass,
244 gpr_bypass_c => gpr_c_bypass
247 decode2_0: process(clk)
249 if rising_edge(clk) then
250 if rin.e.valid = '1' then
251 report "execute " & to_hstring(rin.e.nia);
257 r_out.read1_reg <= gpr_or_spr_to_gspr(insn_ra(d_in.insn), d_in.ispr1);
258 r_out.read2_reg <= gpr_or_spr_to_gspr(insn_rb(d_in.insn), d_in.ispr2);
259 r_out.read3_reg <= insn_rs(d_in.insn);
261 c_out.read <= d_in.decode.input_cr;
263 decode2_1: process(all)
264 variable v : reg_type;
265 variable mul_a : std_ulogic_vector(63 downto 0);
266 variable mul_b : std_ulogic_vector(63 downto 0);
267 variable decoded_reg_a : decode_input_reg_t;
268 variable decoded_reg_b : decode_input_reg_t;
269 variable decoded_reg_c : decode_input_reg_t;
270 variable decoded_reg_o : decode_output_reg_t;
271 variable length : std_ulogic_vector(3 downto 0);
275 v.e := Decode2ToExecute1Init;
277 mul_a := (others => '0');
278 mul_b := (others => '0');
280 --v.e.input_cr := d_in.decode.input_cr;
281 --v.e.output_cr := d_in.decode.output_cr;
283 decoded_reg_a := decode_input_reg_a (d_in.decode.input_reg_a, d_in.insn, r_in.read1_data, d_in.ispr1);
284 decoded_reg_b := decode_input_reg_b (d_in.decode.input_reg_b, d_in.insn, r_in.read2_data, d_in.ispr2);
285 decoded_reg_c := decode_input_reg_c (d_in.decode.input_reg_c, d_in.insn, r_in.read3_data);
286 decoded_reg_o := decode_output_reg (d_in.decode.output_reg_a, d_in.insn, d_in.ispr1);
288 r_out.read1_enable <= decoded_reg_a.reg_valid;
289 r_out.read2_enable <= decoded_reg_b.reg_valid;
290 r_out.read3_enable <= decoded_reg_c.reg_valid;
292 case d_in.decode.length is
307 v.e.unit := d_in.decode.unit;
308 v.e.insn_type := d_in.decode.insn_type;
309 v.e.read_reg1 := decoded_reg_a.reg;
310 v.e.read_data1 := decoded_reg_a.data;
311 v.e.bypass_data1 := gpr_a_bypass;
312 v.e.read_reg2 := decoded_reg_b.reg;
313 v.e.read_data2 := decoded_reg_b.data;
314 v.e.bypass_data2 := gpr_b_bypass;
315 v.e.read_data3 := decoded_reg_c.data;
316 v.e.bypass_data3 := gpr_c_bypass;
317 v.e.write_reg := decoded_reg_o.reg;
318 v.e.rc := decode_rc(d_in.decode.rc, d_in.insn);
319 if not (d_in.decode.insn_type = OP_MUL_H32 or d_in.decode.insn_type = OP_MUL_H64) then
320 v.e.oe := decode_oe(d_in.decode.rc, d_in.insn);
322 v.e.cr := c_in.read_cr_data;
323 v.e.xerc := c_in.read_xerc_data;
324 v.e.invert_a := d_in.decode.invert_a;
325 v.e.invert_out := d_in.decode.invert_out;
326 v.e.input_carry := d_in.decode.input_carry;
327 v.e.output_carry := d_in.decode.output_carry;
328 v.e.is_32bit := d_in.decode.is_32bit;
329 v.e.is_signed := d_in.decode.is_signed;
330 if d_in.decode.lr = '1' then
331 v.e.lr := insn_lk(d_in.insn);
333 v.e.insn := d_in.insn;
334 v.e.data_len := length;
335 v.e.byte_reverse := d_in.decode.byte_reverse;
336 v.e.sign_extend := d_in.decode.sign_extend;
337 v.e.update := d_in.decode.update;
338 v.e.reserve := d_in.decode.reserve;
341 control_valid_in <= d_in.valid;
342 control_sgl_pipe <= d_in.decode.sgl_pipe;
344 gpr_write_valid <= decoded_reg_o.reg_valid;
345 gpr_write <= decoded_reg_o.reg;
346 gpr_bypassable <= '0';
347 if EX1_BYPASS and d_in.decode.unit = ALU then
348 gpr_bypassable <= '1';
351 gpr_a_read_valid <= decoded_reg_a.reg_valid;
352 gpr_a_read <= decoded_reg_a.reg;
354 gpr_b_read_valid <= decoded_reg_b.reg_valid;
355 gpr_b_read <= decoded_reg_b.reg;
357 gpr_c_read_valid <= decoded_reg_c.reg_valid;
358 gpr_c_read <= gspr_to_gpr(decoded_reg_c.reg);
360 cr_write_valid <= d_in.decode.output_cr or decode_rc(d_in.decode.rc, d_in.insn);
362 v.e.valid := control_valid_out;
363 if d_in.decode.unit = NONE then
364 v.e.insn_type := OP_ILLEGAL;
368 v.e := Decode2ToExecute1Init;
377 end architecture behaviour;