1 -------------------------------------------------------------------------------
3 -- Project: <Floating Point Unit Core>
5 -- Description: multiplication entity for the multiplication unit
6 -------------------------------------------------------------------------------
8 -- 100101011010011100100
9 -- 110000111011100100000
10 -- 100000111011000101101
11 -- 100010111100101111001
12 -- 110000111011101101001
13 -- 010000001011101001010
14 -- 110100111001001100001
15 -- 110111010000001100111
16 -- 110110111110001011101
17 -- 101110110010111101000
18 -- 100000010111000000000
20 -- Author: Jidan Al-eryani
25 -- This source file may be used and distributed without
26 -- restriction provided that this copyright statement is not
27 -- removed from the file and that any derivative work contains
28 -- the original copyright notice and the associated disclaimer.
30 -- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY
31 -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 -- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33 -- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR
34 -- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35 -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37 -- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 -- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39 -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
41 -- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 -- POSSIBILITY OF SUCH DAMAGE.
46 use ieee.std_logic_1164.all;
47 use ieee.std_logic_unsigned.all;
55 fracta_i : in std_logic_vector(FRAC_WIDTH downto 0); -- hidden(1) & fraction(23)
56 fractb_i : in std_logic_vector(FRAC_WIDTH downto 0);
57 signa_i : in std_logic;
58 signb_i : in std_logic;
59 start_i : in std_logic;
60 fract_o : out std_logic_vector(2*FRAC_WIDTH+1 downto 0);
61 sign_o : out std_logic;
62 ready_o : out std_logic
66 architecture rtl of mul_24 is
70 signal s_fracta_i, s_fractb_i : std_logic_vector(FRAC_WIDTH downto 0);
71 signal s_signa_i, s_signb_i, s_sign_o : std_logic;
72 signal s_fract_o: std_logic_vector(2*FRAC_WIDTH+1 downto 0);
73 signal s_start_i, s_ready_o : std_logic;
75 signal a_h, a_l, b_h, b_l : std_logic_vector(11 downto 0);
76 signal a_h_h, a_h_l, b_h_h, b_h_l, a_l_h, a_l_l, b_l_h, b_l_l : std_logic_vector(5 downto 0);
78 type op_6 is array (7 downto 0) of std_logic_vector(5 downto 0);
79 type prod_6 is array (3 downto 0) of op_6;
81 type prod_48 is array (4 downto 0) of std_logic_vector(47 downto 0);
82 type sum_24 is array (3 downto 0) of std_logic_vector(23 downto 0);
84 type a is array (3 downto 0) of std_logic_vector(23 downto 0);
85 type prod_24 is array (3 downto 0) of a;
89 signal prod_a_b : prod_48;
91 signal count : integer range 0 to 4;
94 type t_state is (waiting,busy);
95 signal s_state : t_state;
97 signal prod2 : prod_24;
104 if rising_edge(clk_i) then
105 s_fracta_i <= fracta_i;
106 s_fractb_i <= fractb_i;
116 -- if rising_edge(clk_i) then
117 fract_o <= s_fract_o;
127 if rising_edge(clk_i) then
128 if s_start_i ='1' then
131 elsif count=4 and s_state=busy then
135 elsif s_state=busy then
144 s_sign_o <= s_signa_i xor s_signb_i;
147 -- A = A_h x 2^N + A_l , B = B_h x 2^N + B_l
148 -- A x B = A_hxB_hx2^2N + (A_h xB_l + A_lxB_h)2^N + A_lxB_l
149 a_h <= s_fracta_i(23 downto 12);
150 a_l <= s_fracta_i(11 downto 0);
151 b_h <= s_fractb_i(23 downto 12);
152 b_l <= s_fractb_i(11 downto 0);
156 a_h_h <= a_h(11 downto 6);
157 a_h_l <= a_h(5 downto 0);
158 b_h_h <= b_h(11 downto 6);
159 b_h_l <= b_h(5 downto 0);
161 a_l_h <= a_l(11 downto 6);
162 a_l_l <= a_l(5 downto 0);
163 b_l_h <= b_l(11 downto 6);
164 b_l_l <= b_l(5 downto 0);
167 prod(0)(0) <= a_h_h; prod(0)(1) <= b_h_h;
168 prod(0)(2) <= a_h_h; prod(0)(3) <= b_h_l;
169 prod(0)(4) <= a_h_l; prod(0)(5) <= b_h_h;
170 prod(0)(6) <= a_h_l; prod(0)(7) <= b_h_l;
173 prod(1)(0) <= a_h_h; prod(1)(1) <= b_l_h;
174 prod(1)(2) <= a_h_h; prod(1)(3) <= b_l_l;
175 prod(1)(4) <= a_h_l; prod(1)(5) <= b_l_h;
176 prod(1)(6) <= a_h_l; prod(1)(7) <= b_l_l;
178 prod(2)(0) <= a_l_h; prod(2)(1) <= b_h_h;
179 prod(2)(2) <= a_l_h; prod(2)(3) <= b_h_l;
180 prod(2)(4) <= a_l_l; prod(2)(5) <= b_h_h;
181 prod(2)(6) <= a_l_l; prod(2)(7) <= b_h_l;
183 prod(3)(0) <= a_l_h; prod(3)(1) <= b_l_h;
184 prod(3)(2) <= a_l_h; prod(3)(3) <= b_l_l;
185 prod(3)(4) <= a_l_l; prod(3)(5) <= b_l_h;
186 prod(3)(6) <= a_l_l; prod(3)(7) <= b_l_l;
192 if rising_edge(clk_i) then
194 prod2(count)(0) <= (prod(count)(0)*prod(count)(1))&"000000000000";
195 prod2(count)(1) <= "000000"&(prod(count)(2)*prod(count)(3))&"000000";
196 prod2(count)(2) <= "000000"&(prod(count)(4)*prod(count)(5))&"000000";
197 prod2(count)(3) <= "000000000000"&(prod(count)(6)*prod(count)(7));
206 if rising_edge(clk_i) then
207 if count > 0 and s_state=busy then
208 sum(count-1) <= prod2(count-1)(0) + prod2(count-1)(1) + prod2(count-1)(2) + prod2(count-1)(3);
218 prod_a_b(0) <= sum(0)&"000000000000000000000000";
219 prod_a_b(1) <= "000000000000"&sum(1)&"000000000000";
220 prod_a_b(2) <= "000000000000"&sum(2)&"000000000000";
221 prod_a_b(3) <= "000000000000000000000000"&sum(3);
223 prod_a_b(4) <= prod_a_b(0) + prod_a_b(1) + prod_a_b(2) + prod_a_b(3);
225 s_fract_o <= prod_a_b(4);