-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray_v_VCT.pl
executable file
·204 lines (187 loc) · 5.87 KB
/
array_v_VCT.pl
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/sh --# perl, to stop looping
eval 'exec /usr/local/bin/perl $0 ${1+"${@}"}'
if 0;
# Perl script to generate truncated array multiplier (Variable Correction)
# Last update: 08/23/02
use Getopt::Std;
# options are
# -x <bits> the number of x bits
# -y <bits> the number of y bits
# -z <bits> the number of output bits
# -k <int> number of columns to keep
# -m <string> module name
getopts('x:y:z:k:m:');
$XBITS=$opt_x;
$YBITS=$opt_y;
$ZBITS=$opt_z;
$K=$opt_k;
$MODULE=$opt_m;
if($XBITS<=0 || $YBITS<=0 || $ZBITS<=0 || $K<0){
print("Input parameters:\n");
print(" -x <bits> the number of x bits\n");
print(" -y <bits> the number of y bits\n");
print(" -z <bits> the number of output bits\n");
print(" -k <int> number of columns to keep\n");
print(" -m <string> module name (optional)\n");
exit(1);
}
if($ZBITS+$K>$XBITS+$YBITS) {
print("Error: z+k must be smaller than or equal to x+y\n\n");
exit(1);
}
$pp_label=1;
$ha_label=1;
$fa_label=1;
$cpa_label=1;
$sha_label=1;
$rfa_label=1;
$instcnt=1;
if(length($MODULE)==0){
printf("module VCTarray%s_%s_%s_%s (Z, X, Y);\n", $XBITS, $YBITS, $ZBITS, $K);
}
else{
printf("module $MODULE (Z, X, Y);\n", $XBITS, $YBITS, $ZBITS, $K);
}
printf("\t\n");
printf("\tinput [%s:0] Y;\n",$YBITS-1);
printf("\tinput [%s:0] X;\n",$XBITS-1);
printf("\toutput [%s:0] Z;\n",$ZBITS-1);
printf("\t\n\n");
for($y=0; $y < $YBITS ; $y++) {
printf("\twire [%s:0] P%s;\n", $XBITS-1, $y);
printf("\twire [%s:0] carry%s;\n", $XBITS-1, $y+1);
printf("\twire [%s:0] sum%s;\n", $XBITS-1, $y+1);
}
print "\n\n";
# calculation of which partial products have to be generated
if($XBITS<$ZBITS+$K){
$x_pp_size=$XBITS;
$h_pp_size=$K+$ZBITS-$XBITS;
}
else{
$x_pp_size=$ZBITS+$K;
$h_pp_size=2;
}
if($YBITS<$ZBITS+$K){
$y_pp_size=$YBITS;
}
else{
$y_pp_size=$ZBITS+$K-1;
}
print "\t// generate the partial products.\n";
for($y=$YBITS-$y_pp_size; $y < $YBITS ; $y++) {
for($x=$XBITS-1; $x >= $XBITS-$x_pp_size; $x--) {
if($x+$y>=$XBITS+$YBITS-$ZBITS-$K-1 && !($y==$YBITS-$y_pp_size && $x+$y==$XBITS+$YBITS-$ZBITS-$K-1)){
if($y>$YBITS-$y_pp_size && $x==$XBITS-1) {
printf ("\tand pp%s(sum%s[%s], X[%s], Y[%s]);\n", $pp_label, $y, $x, $x, $y);
$pp_label++;
}
elsif($y>$YBITS-$y_pp_size && $x+$y==$XBITS+$YBITS-$ZBITS-$K-1){
printf ("\tand pp%s(carry%s[%s], X[%s], Y[%s]);\n", $pp_label, $y, $x, $x, $y);
$pp_label++;
}
else {
printf ("\tand pp%s(P%s[%s], X[%s], Y[%s]);\n", $pp_label, $y, $x, $x, $y);
$pp_label++;
}
}
}
}
print "\n";
# Array Reduction
print "\t// Array Reduction\n";
for($y=$YBITS-$y_pp_size; $y < $YBITS ; $y++) {
for($x=$XBITS-2; $x >= $XBITS-$x_pp_size; $x--) {
if($x+$y>=$XBITS+$YBITS-$ZBITS-$K){
if($y==$YBITS-$y_pp_size+1){
if($x>=$XBITS+$YBITS-$ZBITS-$y-1){
printf("\thalf_adder HA%s(carry%s[%s],sum%s[%s],P%s[%s],P%s[%s]);\n",$ha_label,$y,$x,$y,$x,$y,$x,$y-1,$x+1);
$ha_label++;
}
else{
if($K>=2 && $x==0){
printf("\tassign carry%s[%s] = P%s[%s] | P%s[%s];\n",$y,$x,$y,$x,$y-1,$x+1);
}
else{
printf("\tspecialized_half_adder SHA%s(carry%s[%s],sum%s[%s],P%s[%s],P%s[%s]);\n",$sha_label,$y,$x,$y,$x,$y,$x,$y-1,$x+1);
$sha_label++;
}
}
}
if($y>$YBITS-$y_pp_size+1){
if($x==0 && $y<$YBITS-$h_pp_size+$K){
printf("\treduced_full_adder RFA%s(carry%s[%s],P%s[%s],sum%s[%s],carry%s[%s]);\n",$rfa_label,$y,$x,$y,$x,$y-1,$x+1,$y-1,$x);
$rfa_label++;
}
else{
printf("\tfull_adder FA%s(carry%s[%s],sum%s[%s],P%s[%s],sum%s[%s],carry%s[%s]);\n",$fa_label,$y,$x,$y,$x,$y,$x,$y-1,$x+1,$y-1,$x);
$fa_label++;
}
}
}
}
}
print "\n";
# Generate lower order product
print "\t// Generate lower product bits YBITS \n";
$Zpin=0;
if($ZBITS>$XBITS){
for($y=$YBITS-$ZBITS+$XBITS; $y < $YBITS ; $y++){
if($y==0){
printf("\tbuf b1(Z[0], P0[0]);\n");
$Zpin++;
}
else{
printf ("\tassign Z[%s] = sum%s[0];\n",$Zpin,$y);
$Zpin++;
}
}
}
print "\n";
# Generate higher order product
print "\t// Final Carry Propagate Addition\n";
print "\t// Generate higher product bits\n";
if($ZBITS>$XBITS){
$nhop=$XBITS;
}
else{
$nhop=$ZBITS;
}
if($XBITS-$ZBITS-$K>0){
$xstart=$XBITS-$ZBITS-$K;
}
else{
$xstart=0;
}
for($x=$xstart; $x < $XBITS ; $x++) {
if($x==$xstart) {
if($x==$XBITS-$nhop){
printf("\thalf_adder CPA%s(carry%s[%s],Z[%s],carry%s[%s],sum%s[%s]);\n",
$cpa_label,$YBITS,$x,$Zpin,$YBITS-1,$x,$YBITS-1,$x+1);
$cpa_label++;
$Zpin++;
}
else{
printf("\tassign carry%s[%s] = carry%s[%s] & sum%s[%s];\n",$YBITS,$x,$YBITS-1,$x,$YBITS-1,$x+1);
}
}
else{
if($x==$XBITS-2) {
printf("\tfull_adder CPA%s(Z[%s],Z[%s],carry%s[%s],carry%s[%s],sum%s[%s]);\n",$cpa_label,$Zpin+1,$Zpin,$YBITS-1,$x,$YBITS,$x-1,$YBITS-1,$x+1);
$cpa_label++;
$Zpin++;
}
else{
if($x>=$XBITS-$nhop && $x<$XBITS-2) {
printf("\tfull_adder CPA%s(carry%s[%s],Z[%s],carry%s[%s],carry%s[%s],sum%s[%s]);\n",$cpa_label,$YBITS,$x,$Zpin,$YBITS-1,$x,$YBITS,$x-1,$YBITS-1,$x+1);
$cpa_label++;
$Zpin++;
}
if($x<$XBITS-$nhop && $x>$xstart && $x<$XBITS-2){
printf("\treduced_full_adder CPA%s(carry%s[%s],carry%s[%s],carry%s[%s],sum%s[%s]);\n",$cpa_label,$YBITS,$x,$YBITS-1,$x,$YBITS,$x-1,$YBITS-1,$x+1);
$cpa_label++;
}
}
}
}
print "endmodule";