1 -- Floating-point unit for Microwatt
4 use ieee.std_logic_1164.all;
5 use ieee.numeric_std.all;
8 use work.insn_helpers.all;
9 use work.decode_types.all;
10 use work.crhelpers.all;
19 e_in : in Execute1toFPUType;
20 e_out : out FPUToExecute1Type;
22 w_out : out FPUToWritebackType
26 architecture behaviour of fpu is
28 type state_t is (IDLE,
31 type reg_type is record
34 instr_done : std_ulogic;
37 insn : std_ulogic_vector(31 downto 0);
38 dest_fpr : gspr_index_t;
42 single_prec : std_ulogic;
43 fpscr : std_ulogic_vector(31 downto 0);
44 b : std_ulogic_vector(63 downto 0);
45 writing_back : std_ulogic;
46 cr_result : std_ulogic_vector(3 downto 0);
47 cr_mask : std_ulogic_vector(7 downto 0);
50 signal r, rin : reg_type;
52 signal fp_result : std_ulogic_vector(63 downto 0);
57 if rising_edge(clk) then
63 r.fpscr <= (others => '0');
64 r.writing_back <= '0';
66 assert not (r.state /= IDLE and e_in.valid = '1') severity failure;
73 e_out.exception <= r.fpscr(FPSCR_FEX);
74 e_out.interrupt <= r.do_intr;
76 w_out.valid <= r.instr_done and not r.do_intr;
77 w_out.write_enable <= r.writing_back;
78 w_out.write_reg <= r.dest_fpr;
79 w_out.write_data <= fp_result;
80 w_out.write_cr_enable <= r.instr_done and r.rc;
81 w_out.write_cr_mask <= r.cr_mask;
82 w_out.write_cr_data <= r.cr_result & r.cr_result & r.cr_result & r.cr_result &
83 r.cr_result & r.cr_result & r.cr_result & r.cr_result;
86 variable v : reg_type;
87 variable illegal : std_ulogic;
88 variable j, k : integer;
89 variable flm : std_ulogic_vector(7 downto 0);
95 -- capture incoming instruction
96 if e_in.valid = '1' then
99 v.fe_mode := or (e_in.fe_mode);
100 v.dest_fpr := e_in.frt;
101 v.single_prec := e_in.single;
103 v.is_cmp := e_in.out_cr;
104 v.cr_mask := num_to_fxm(1);
108 v.writing_back := '0';
113 if e_in.valid = '1' then
114 case e_in.insn(5 downto 1) is
116 if e_in.insn(8) = '0' then
127 v.writing_back := '1';
128 case r.insn(20 downto 16) is
138 if r.insn(25) = '1' then
140 elsif r.insn(16) = '1' then
143 flm := r.insn(24 downto 17);
148 v.fpscr(k + 3 downto k) := r.b(k + 3 downto k);
157 -- Just enough to read FPSCR for now.
158 fp_result <= x"00000000" & r.fpscr;
160 v.fpscr(FPSCR_VX) := (or (v.fpscr(FPSCR_VXSNAN downto FPSCR_VXVC))) or
161 (or (v.fpscr(FPSCR_VXSOFT downto FPSCR_VXCVI)));
162 v.fpscr(FPSCR_FEX) := or (v.fpscr(FPSCR_VX downto FPSCR_XX) and
163 v.fpscr(FPSCR_VE downto FPSCR_XE));
165 v.cr_result := v.fpscr(FPSCR_FX downto FPSCR_OX);
168 if illegal = '1' then
171 v.writing_back := '0';
175 v.do_intr := v.instr_done and v.fpscr(FPSCR_FEX) and r.fe_mode;
176 if v.state /= IDLE or v.do_intr = '1' then
182 e_out.illegal <= illegal;
185 end architecture behaviour;