2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
6 use work.decode_types.all;
9 use work.crhelpers.all;
10 use work.insn_helpers.all;
11 use work.ppc_fx_insns.all;
15 SIM : boolean := false
21 flush_out : out std_ulogic;
23 e_in : in Decode2ToExecute1Type;
26 f_out : out Execute1ToFetch1Type;
28 e_out : out Execute1ToExecute2Type;
30 terminate_out : out std_ulogic
34 architecture behaviour of execute1 is
35 type reg_type is record
36 --f : Execute1ToFetch1Type;
37 e : Execute1ToExecute2Type;
40 signal r, rin : reg_type;
42 signal ctrl: ctrl_t := (carry => '0', others => (others => '0'));
43 signal ctrl_tmp: ctrl_t := (carry => '0', others => (others => '0'));
45 function decode_input_carry (carry_sel : carry_in_t; ca_in : std_ulogic) return std_ulogic is
57 execute1_0: process(clk)
59 if rising_edge(clk) then
65 execute1_1: process(all)
66 variable v : reg_type;
67 variable a_inv : std_ulogic_vector(63 downto 0);
68 variable result : std_ulogic_vector(63 downto 0);
69 variable newcrf : std_ulogic_vector(3 downto 0);
70 variable result_with_carry : std_ulogic_vector(64 downto 0);
71 variable result_en : integer;
72 variable crnum : integer;
73 variable scrnum : integer;
74 variable lo, hi : integer;
75 variable sh, mb, me : std_ulogic_vector(5 downto 0);
76 variable sh32, mb32, me32 : std_ulogic_vector(4 downto 0);
77 variable bo, bi : std_ulogic_vector(4 downto 0);
78 variable bf, bfa : std_ulogic_vector(2 downto 0);
79 variable l : std_ulogic;
81 result := (others => '0');
82 result_with_carry := (others => '0');
86 v.e := Execute1ToExecute2Init;
87 --v.f := Execute1ToFetch1TypeInit;
90 -- FIXME: run at 512MHz not core freq
91 ctrl_tmp.tb <= std_ulogic_vector(unsigned(ctrl.tb) + 1);
94 f_out <= Execute1ToFetch1TypeInit;
96 if e_in.valid = '1' then
99 v.e.write_reg := e_in.write_reg;
101 case_0: case e_in.insn_type is
104 terminate_out <= '1';
109 if e_in.invert_a = '0' then
110 a_inv := e_in.read_data1;
112 a_inv := not e_in.read_data1;
114 result_with_carry := ppc_adde(a_inv, e_in.read_data2, decode_input_carry(e_in.input_carry, ctrl.carry));
115 result := result_with_carry(63 downto 0);
116 if e_in.output_carry then
117 ctrl_tmp.carry <= result_with_carry(64);
121 result := ppc_and(e_in.read_data3, e_in.read_data2);
124 result := ppc_andc(e_in.read_data3, e_in.read_data2);
127 f_out.redirect <= '1';
128 if (insn_aa(e_in.insn)) then
129 f_out.redirect_nia <= std_ulogic_vector(signed(e_in.read_data2));
131 f_out.redirect_nia <= std_ulogic_vector(signed(e_in.nia) + signed(e_in.read_data2));
134 bo := insn_bo(e_in.insn);
135 bi := insn_bi(e_in.insn);
136 if bo(4-2) = '0' then
137 ctrl_tmp.ctr <= std_ulogic_vector(unsigned(ctrl.ctr) - 1);
139 if ppc_bc_taken(bo, bi, e_in.cr, ctrl.ctr) = 1 then
140 f_out.redirect <= '1';
141 if (insn_aa(e_in.insn)) then
142 f_out.redirect_nia <= std_ulogic_vector(signed(e_in.read_data2));
144 f_out.redirect_nia <= std_ulogic_vector(signed(e_in.nia) + signed(e_in.read_data2));
148 -- bits 10 and 6 distinguish between bclr, bcctr and bctar
149 bo := insn_bo(e_in.insn);
150 bi := insn_bi(e_in.insn);
151 if bo(4-2) = '0' and e_in.insn(10) = '0' then
152 ctrl_tmp.ctr <= std_ulogic_vector(unsigned(ctrl.ctr) - 1);
154 if ppc_bc_taken(bo, bi, e_in.cr, ctrl.ctr) = 1 then
155 f_out.redirect <= '1';
156 if e_in.insn(10) = '0' then
157 f_out.redirect_nia <= ctrl.lr(63 downto 2) & "00";
159 f_out.redirect_nia <= ctrl.ctr(63 downto 2) & "00";
163 result := ppc_cmpb(e_in.read_data3, e_in.read_data2);
166 bf := insn_bf(e_in.insn);
167 l := insn_l(e_in.insn);
168 v.e.write_cr_enable := '1';
169 crnum := to_integer(unsigned(bf));
170 v.e.write_cr_mask := num_to_fxm(crnum);
174 v.e.write_cr_data(hi downto lo) := ppc_cmp(l, e_in.read_data1, e_in.read_data2);
177 bf := insn_bf(e_in.insn);
178 l := insn_l(e_in.insn);
179 v.e.write_cr_enable := '1';
180 crnum := to_integer(unsigned(bf));
181 v.e.write_cr_mask := num_to_fxm(crnum);
185 v.e.write_cr_data(hi downto lo) := ppc_cmpl(l, e_in.read_data1, e_in.read_data2);
188 result := ppc_cntlzw(e_in.read_data3);
191 result := ppc_cnttzw(e_in.read_data3);
194 result := ppc_cntlzd(e_in.read_data3);
197 result := ppc_cnttzd(e_in.read_data3);
200 result := ppc_extsb(e_in.read_data3);
203 result := ppc_extsh(e_in.read_data3);
206 result := ppc_extsw(e_in.read_data3);
209 result := ppc_eqv(e_in.read_data3, e_in.read_data2);
212 crnum := to_integer(unsigned(insn_bc(e_in.insn)));
213 if e_in.cr(31-crnum) = '1' then
214 result := e_in.read_data1;
216 result := e_in.read_data2;
220 bf := insn_bf(e_in.insn);
221 bfa := insn_bfa(e_in.insn);
222 v.e.write_cr_enable := '1';
223 crnum := to_integer(unsigned(bf));
224 scrnum := to_integer(unsigned(bfa));
225 v.e.write_cr_mask := num_to_fxm(crnum);
230 newcrf := e_in.cr(hi downto lo);
236 v.e.write_cr_data(hi downto lo) := newcrf;
239 if std_match(e_in.insn(20 downto 11), "0100100000") then
242 elsif std_match(e_in.insn(20 downto 11), "0100000000") then
245 elsif std_match(e_in.insn(20 downto 11), "0110001000") then
250 if e_in.insn(20) = '0' then
252 result := x"00000000" & e_in.cr;
255 crnum := fxm_to_num(insn_fxm(e_in.insn));
256 result := (others => '0');
261 result(hi downto lo) := e_in.cr(hi downto lo);
267 v.e.write_cr_enable := '1';
268 if e_in.insn(20) = '0' then
270 v.e.write_cr_mask := insn_fxm(e_in.insn);
272 -- mtocrf: We require one hot priority encoding here
273 crnum := fxm_to_num(insn_fxm(e_in.insn));
274 v.e.write_cr_mask := num_to_fxm(crnum);
276 v.e.write_cr_data := e_in.read_data3(31 downto 0);
278 if std_match(e_in.insn(20 downto 11), "0100100000") then
279 ctrl_tmp.ctr <= e_in.read_data3;
280 elsif std_match(e_in.insn(20 downto 11), "0100000000") then
281 ctrl_tmp.lr <= e_in.read_data3;
284 result := ppc_nand(e_in.read_data3, e_in.read_data2);
287 result := ppc_neg(e_in.read_data1);
290 result := ppc_nor(e_in.read_data3, e_in.read_data2);
293 result := ppc_or(e_in.read_data3, e_in.read_data2);
296 result := ppc_orc(e_in.read_data3, e_in.read_data2);
299 result := ppc_popcntb(e_in.read_data3);
302 result := ppc_popcntw(e_in.read_data3);
305 result := ppc_popcntd(e_in.read_data3);
308 result := ppc_prtyd(e_in.read_data3);
311 result := ppc_prtyw(e_in.read_data3);
314 -- note rldcl mb field and rldcr me field are in the same place
315 mb := insn_mb(e_in.insn);
316 if e_in.insn(1) = '0' then
317 result := ppc_rldcl(e_in.read_data3, e_in.read_data2, mb);
319 result := ppc_rldcr(e_in.read_data3, e_in.read_data2, mb);
323 sh := insn_sh(e_in.insn);
324 mb := insn_mb(e_in.insn);
325 result := ppc_rldicl(e_in.read_data3, sh, mb);
328 sh := insn_sh(e_in.insn);
329 me := insn_me(e_in.insn);
330 result := ppc_rldicr(e_in.read_data3, sh, me);
333 mb32 := insn_mb32(e_in.insn);
334 me32 := insn_me32(e_in.insn);
335 result := ppc_rlwnm(e_in.read_data3, e_in.read_data2, mb32, me32);
338 sh32 := insn_sh32(e_in.insn);
339 mb32 := insn_mb32(e_in.insn);
340 me32 := insn_me32(e_in.insn);
341 result := ppc_rlwinm(e_in.read_data3, sh32, mb32, me32);
344 sh := insn_sh(e_in.insn);
345 mb := insn_mb(e_in.insn);
346 result := ppc_rldic(e_in.read_data3, sh, mb);
349 sh := insn_sh(e_in.insn);
350 mb := insn_mb(e_in.insn);
351 result := ppc_rldimi(e_in.read_data1, e_in.read_data3, sh, mb);
354 sh32 := insn_sh32(e_in.insn);
355 mb32 := insn_mb32(e_in.insn);
356 me32 := insn_me32(e_in.insn);
357 result := ppc_rlwimi(e_in.read_data1, e_in.read_data3, sh32, mb32, me32);
360 result := ppc_sld(e_in.read_data3, e_in.read_data2);
363 result := ppc_slw(e_in.read_data3, e_in.read_data2);
366 result_with_carry := ppc_sraw(e_in.read_data3, e_in.read_data2);
367 result := result_with_carry(63 downto 0);
368 ctrl_tmp.carry <= result_with_carry(64);
371 sh := '0' & insn_sh32(e_in.insn);
372 result_with_carry := ppc_srawi(e_in.read_data3, sh);
373 result := result_with_carry(63 downto 0);
374 ctrl_tmp.carry <= result_with_carry(64);
377 result_with_carry := ppc_srad(e_in.read_data3, e_in.read_data2);
378 result := result_with_carry(63 downto 0);
379 ctrl_tmp.carry <= result_with_carry(64);
382 sh := insn_sh(e_in.insn);
383 result_with_carry := ppc_sradi(e_in.read_data3, sh);
384 result := result_with_carry(63 downto 0);
385 ctrl_tmp.carry <= result_with_carry(64);
388 result := ppc_srd(e_in.read_data3, e_in.read_data2);
391 result := ppc_srw(e_in.read_data3, e_in.read_data2);
394 result := ppc_xor(e_in.read_data3, e_in.read_data2);
397 when OP_SIM_CONFIG =>
398 -- bit 0 was used to select the microwatt console, which
399 -- we no longer support.
401 result := x"0000000000000000";
403 result := x"0000000000000000";
408 -- Keep our test cases happy for now, ignore trap instructions
409 report "OP_TDI FIXME";
412 terminate_out <= '1';
416 if e_in.lr = '1' then
417 ctrl_tmp.lr <= std_ulogic_vector(unsigned(e_in.nia) + 4);
420 if result_en = 1 then
421 v.e.write_data := result;
422 v.e.write_enable := '1';
433 flush_out <= f_out.redirect;
435 end architecture behaviour;