1 |
8 |
riedelx |
-- http://www.cs.umbc.edu/help/VHDL/samples/samples.shtml
|
2 |
|
|
-- mul32c.vhdl parallel multiply 32 bit x 32 bit to get 64 bit unsigned product
|
3 |
|
|
-- uses add32 component and fadd component, includes carry save
|
4 |
|
|
-- uses VHDL 'generate' to have less statements
|
5 |
|
|
|
6 |
|
|
library IEEE;
|
7 |
|
|
use IEEE.std_logic_1164.all;
|
8 |
|
|
|
9 |
|
|
entity add32csa is -- one stage of carry save adder for multiplier
|
10 |
|
|
port(
|
11 |
|
|
b : in std_logic; -- a multiplier bit
|
12 |
|
|
a : in std_logic_vector(31 downto 0); -- multiplicand
|
13 |
|
|
sum_in : in std_logic_vector(31 downto 0); -- sums from previous stage
|
14 |
|
|
cin : in std_logic_vector(31 downto 0); -- carrys from previous stage
|
15 |
|
|
sum_out : out std_logic_vector(31 downto 0); -- sums to next stage
|
16 |
|
|
cout : out std_logic_vector(31 downto 0)); -- carrys to next stage
|
17 |
|
|
end add32csa;
|
18 |
|
|
|
19 |
|
|
architecture circuits of add32csa is
|
20 |
|
|
signal zero : std_logic_vector(31 downto 0) := X"00000000";
|
21 |
|
|
signal aa : std_logic_vector(31 downto 0) := X"00000000";
|
22 |
|
|
component fadd -- duplicates entity port
|
23 |
|
|
port(a : in std_logic;
|
24 |
|
|
b : in std_logic;
|
25 |
|
|
cin : in std_logic;
|
26 |
|
|
s : out std_logic;
|
27 |
|
|
cout : out std_logic);
|
28 |
|
|
end component fadd;
|
29 |
|
|
begin -- circuits of add32csa
|
30 |
|
|
aa <= a when b='1' else zero after 1 ns;
|
31 |
|
|
stage: for I in 0 to 31 generate
|
32 |
|
|
sta: fadd port map(aa(I), sum_in(I), cin(I) , sum_out(I), cout(I));
|
33 |
|
|
end generate stage;
|
34 |
|
|
end architecture circuits; -- of add32csa
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
library IEEE;
|
38 |
|
|
use IEEE.std_logic_1164.all;
|
39 |
|
|
|
40 |
|
|
entity mul32c is -- 32 x 32 = 64 bit unsigned product multiplier
|
41 |
|
|
port(a : in std_logic_vector(31 downto 0); -- multiplicand
|
42 |
|
|
b : in std_logic_vector(31 downto 0); -- multiplier
|
43 |
|
|
prod : out std_logic_vector(63 downto 0)); -- product
|
44 |
|
|
end mul32c;
|
45 |
|
|
|
46 |
|
|
architecture circuits of mul32c is
|
47 |
|
|
signal zero : std_logic_vector(31 downto 0) := X"00000000";
|
48 |
|
|
signal nc1 : std_logic;
|
49 |
|
|
type arr32 is array(0 to 31) of std_logic_vector(31 downto 0);
|
50 |
|
|
signal s : arr32; -- partial sums
|
51 |
|
|
signal c : arr32; -- partial carries
|
52 |
|
|
signal ss : arr32; -- shifted sums
|
53 |
|
|
|
54 |
|
|
component add32csa is -- duplicate entity port
|
55 |
|
|
port(b : in std_logic;
|
56 |
|
|
a : in std_logic_vector(31 downto 0);
|
57 |
|
|
sum_in : in std_logic_vector(31 downto 0);
|
58 |
|
|
cin : in std_logic_vector(31 downto 0);
|
59 |
|
|
sum_out : out std_logic_vector(31 downto 0);
|
60 |
|
|
cout : out std_logic_vector(31 downto 0));
|
61 |
|
|
end component add32csa;
|
62 |
|
|
component add32 -- duplicate entity port
|
63 |
|
|
port(a : in std_logic_vector(31 downto 0);
|
64 |
|
|
b : in std_logic_vector(31 downto 0);
|
65 |
|
|
cin : in std_logic;
|
66 |
|
|
sum : out std_logic_vector(31 downto 0);
|
67 |
|
|
cout : out std_logic);
|
68 |
|
|
end component add32;
|
69 |
|
|
begin -- circuits of mul32c
|
70 |
|
|
st0: add32csa port map(b(0), a, zero , zero, s(0), c(0)); -- CSA stage
|
71 |
|
|
ss(0) <= '0'&s(0)(31 downto 1) after 1 ns;
|
72 |
|
|
prod(0) <= s(0)(0) after 1 ns;
|
73 |
|
|
|
74 |
|
|
stage: for I in 1 to 31 generate
|
75 |
|
|
st: add32csa port map(b(I), a, ss(I-1) , c(I-1), s(I), c(I)); -- CSA stage
|
76 |
|
|
ss(I) <= '0'&s(I)(31 downto 1) after 1 ns;
|
77 |
|
|
prod(I) <= s(I)(0) after 1 ns;
|
78 |
|
|
end generate stage;
|
79 |
|
|
|
80 |
|
|
add: add32 port map(ss(31), c(31), '0' , prod(63 downto 32), nc1); -- adder
|
81 |
|
|
end architecture circuits; -- of mul32c
|
82 |
|
|
|