2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
7 use work.decode_types.all;
8 use work.crhelpers.all;
14 d_in : in Decode2ToDividerType;
15 d_out : out DividerToWritebackType
19 architecture behaviour of divider is
20 signal dend : std_ulogic_vector(128 downto 0);
21 signal div : unsigned(63 downto 0);
22 signal quot : std_ulogic_vector(63 downto 0);
23 signal result : std_ulogic_vector(63 downto 0);
24 signal sresult : std_ulogic_vector(63 downto 0);
25 signal qbit : std_ulogic;
26 signal running : std_ulogic;
27 signal signcheck : std_ulogic;
28 signal count : unsigned(6 downto 0);
29 signal neg_result : std_ulogic;
30 signal is_modulus : std_ulogic;
31 signal is_32bit : std_ulogic;
32 signal extended : std_ulogic;
33 signal is_signed : std_ulogic;
34 signal rc : std_ulogic;
35 signal write_reg : std_ulogic_vector(4 downto 0);
36 signal overflow : std_ulogic;
37 signal did_ovf : std_ulogic;
40 divider_0: process(clk)
42 if rising_edge(clk) then
44 dend <= (others => '0');
45 div <= (others => '0');
46 quot <= (others => '0');
49 elsif d_in.valid = '1' then
50 if d_in.is_extended = '1' and not (d_in.is_signed = '1' and d_in.dividend(63) = '1') then
51 dend <= '0' & d_in.dividend & x"0000000000000000";
53 dend <= '0' & x"0000000000000000" & d_in.dividend;
55 div <= unsigned(d_in.divisor);
56 quot <= (others => '0');
57 write_reg <= d_in.write_reg;
59 is_modulus <= d_in.is_modulus;
60 extended <= d_in.is_extended;
61 is_32bit <= d_in.is_32bit;
62 is_signed <= d_in.is_signed;
67 signcheck <= d_in.is_signed and (d_in.dividend(63) or d_in.divisor(63));
68 elsif signcheck = '1' then
70 neg_result <= dend(63) xor (div(63) and not is_modulus);
71 if dend(63) = '1' then
72 if extended = '1' then
73 dend <= '0' & std_ulogic_vector(- signed(dend(63 downto 0))) & x"0000000000000000";
75 dend <= '0' & x"0000000000000000" & std_ulogic_vector(- signed(dend(63 downto 0)));
79 div <= unsigned(- signed(div));
81 elsif running = '1' then
82 if count = "0111111" then
86 if dend(128) = '1' or unsigned(dend(127 downto 64)) >= div then
87 dend <= std_ulogic_vector(unsigned(dend(127 downto 64)) - div) &
88 dend(63 downto 0) & '0';
89 quot <= quot(62 downto 0) & '1';
91 elsif dend(128 downto 57) = x"000000000000000000" and count(6 downto 3) /= "0111" then
92 -- consume 8 bits of zeroes in one cycle
93 dend <= dend(120 downto 0) & x"00";
94 quot <= quot(55 downto 0) & x"00";
97 dend <= dend(127 downto 0) & '0';
98 quot <= quot(62 downto 0) & '0';
107 divider_1: process(all)
109 d_out <= DividerToWritebackInit;
110 d_out.write_reg_nr <= write_reg;
112 if is_modulus = '1' then
113 result <= dend(128 downto 65);
117 if neg_result = '1' then
118 sresult <= std_ulogic_vector(- signed(result));
123 if is_32bit = '0' then
124 did_ovf <= overflow or (is_signed and (sresult(63) xor neg_result));
125 elsif is_signed = '1' then
127 (sresult(63 downto 31) /= x"00000000" & '0' and
128 sresult(63 downto 31) /= x"ffffffff" & '1') then
132 did_ovf <= overflow or (or (sresult(63 downto 32)));
134 if did_ovf = '1' then
135 d_out.write_reg_data <= (others => '0');
136 elsif (is_32bit = '1') and (is_modulus = '0') then
137 -- 32-bit divisions set the top 32 bits of the result to 0
138 d_out.write_reg_data <= x"00000000" & sresult(31 downto 0);
140 d_out.write_reg_data <= sresult;
143 if count = "1000000" then
145 d_out.write_reg_enable <= '1';
147 d_out.write_cr_enable <= '1';
148 d_out.write_cr_mask <= num_to_fxm(0);
149 if (did_ovf = '1') or (or (sresult) = '0') then
150 d_out.write_cr_data <= x"20000000";
151 elsif (sresult(63) = '1') and not ((is_32bit = '1') and (is_modulus = '0')) then
152 d_out.write_cr_data <= x"80000000";
154 d_out.write_cr_data <= x"40000000";
160 end architecture behaviour;