1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
| library ieee;
use ieee.std_logic_1164.all;
entity mult is
generic (
N : natural :=56
);
port (
a_in : in std_logic_vector(N-1 downto 0);
b_in : in std_logic_vector(N-1 downto 0);
y : out std_logic_vector(2*N-1 downto 0)
);
end mult;
architecture structural of mult is
type ab_type is
array(N-1 downto 0) of std_logic_vector(N-1 downto 0);
type c_type is
array(N-1 downto 0) of std_logic_vector(N downto 1);
type s_type is
array(N-1 downto 0) of std_logic_vector(N-1 downto 0);
--
signal ab : ab_type;
signal c : c_type;
signal s : s_type;
signal d : std_logic_vector(N+1 downto 1);
signal an : std_logic;
signal bn : std_logic;
signal sNm1Nm1 : std_logic;
--
component fa
port(
ain : in std_logic;
bin : in std_logic;
cin : in std_logic;
sout : out std_logic;
cout : out std_logic
);
end component;
begin
-- bit product
gen_ab_i:
for i in 0 to N-1 generate
gen_ab_j: for j in 0 to N-1 generate
g_abn_leftcol: if (i = N-1) and (j /= N-1) generate
ab(i)(j) <= a_in(i) and not (b_in(j));
end generate g_abn_leftcol;
g_anb_btmrow: if (i /= N-1) and (j = N-1) generate
ab(i)(j) <= not(a_in(i)) and b_in(j);
end generate g_anb_btmrow;
g_ab_btmleft: if (i = N-1) and (j = N-1) generate
ab(i)(j) <= a_in(i) and b_in(j);
end generate g_ab_btmleft;
g_ab_middle: if (i /= N-1) and (j /= N-1) generate
ab(i)(j) <= a_in(i) and b_in(j);
end generate g_ab_middle;
end generate gen_ab_j;
end generate gen_ab_i;
-- top row
gen_c_top_row:
for i in 0 to N-2 generate
c(i)(1) <= '0';
end generate gen_c_top_row;
gen_s_top_row:
for i in 0 to N-1 generate
s(i)(0) <= ab(i)(0);
end generate gen_s_top_row;
-- leftmost column
gen_s_left_col:
for j in 1 to N-1 generate
s(N-1)(j) <= ab(N-1)(j);
end generate gen_s_left_col;
-- full-adder matrix
gen_fa_i:
for i in 0 to N-2 generate
gen_fa_j:
for j in 1 to N-1 generate
u_fa : fa
port map (
ain => s(i+1)(j-1),
bin => ab(i)(j),
cin => c(i)(j),
sout => s(i)(j),
cout => c(i)(j+1)
);
end generate gen_fa_j;
end generate gen_fa_i;
-- special (N-1,N-1) fa
an <= not(a_in(N-1));
bn <= not(b_in(N-1));
u_fa_nm1sq : fa
port map (
ain => an,
bin => ab(N-1)(N-1),
cin => bn,
sout => sNm1Nm1,
cout => c(N-1)(N)
);
-- final stage adder
gen_fsa:
for i in 0 to N generate
gen_fsa_0:
if i = 0 generate
u_fa_fsa_0 : fa
port map (
ain => s(i)(N-1),
bin => b_in(N-1),
cin => a_in(N-1),
sout => y(i+N-1),
cout => d(1)
);
end generate gen_fsa_0;
gen_fsa_mid:
if i > 0 and i < N-1 generate
u_fa_fsa_mid : fa
port map (
ain => s(i)(N-1),
bin => d(i),
cin => c(i-1)(N),
sout => y(i+N-1),
cout => d(i+1)
);
end generate gen_fsa_mid;
gen_fsa_n : if i = N-1 generate
u_fa_fsa_n : fa
port map (
ain => sNm1Nm1,
bin => d(i),
cin => c(i-1)(N),
sout => y(i+N-1),
cout => d(i+1)
);
end generate gen_fsa_n;
gen_fsa_np1 : if i = N generate
u_fa_fsa_np1 : fa
port map (
ain => '1',
bin => d(i),
cin => c(i-1)(N),
sout => y(i+N-1),
cout => d(i+1)
);
end generate gen_fsa_np1;
end generate gen_fsa;
-- bottom row and output (lower half)
gen_out:
for j in 0 to N-2 generate
y(j) <= s(0)(j);
end generate gen_out;
end structural; |