OpenCores
URL https://opencores.org/ocsvn/dblclockfft/dblclockfft/trunk

Subversion Repositories dblclockfft

[/] [dblclockfft/] [trunk/] [sw/] [fftgen.cpp] - Blame information for rev 15

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dgisselq
#include <stdio.h>
2
#include <stdlib.h>
3
#include <unistd.h>
4
#include <sys/stat.h>
5
#include <string.h>
6 14 dgisselq
#include <string>
7 2 dgisselq
#include <math.h>
8
#include <ctype.h>
9
#include <assert.h>
10
 
11
#define COREDIR "fft-core"
12
 
13
const char      cpyleft[] =
14
"///////////////////////////////////////////////////////////////////////////\n"
15
"//\n"
16
"// Copyright (C) 2015, Gisselquist Technology, LLC\n"
17
"//\n"
18
"// This program is free software (firmware): you can redistribute it and/or\n"
19
"// modify it under the terms of  the GNU General Public License as published\n"
20
"// by the Free Software Foundation, either version 3 of the License, or (at\n"
21
"// your option) any later version.\n"
22
"//\n"
23
"// This program is distributed in the hope that it will be useful, but WITHOUT\n"
24
"// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or\n"
25
"// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\n"
26
"// for more details.\n"
27
"//\n"
28
"// You should have received a copy of the GNU General Public License along\n"
29 5 dgisselq
"// with this program.  (It's in the $(ROOT)/doc directory, run make with no\n"
30
"// target there if the PDF file isn\'t present.)  If not, see\n"
31
"// <http://www.gnu.org/licenses/> for a copy.\n"
32
"//\n"
33 2 dgisselq
"// License:    GPL, v3, as defined and found on www.gnu.org,\n"
34
"//             http://www.gnu.org/licenses/gpl.html\n"
35
"//\n"
36
"//\n"
37
"///////////////////////////////////////////////////////////////////////////\n";
38 14 dgisselq
const char      prjname[] = "A Doubletime Pipelined FFT";
39 2 dgisselq
const char      creator[] =     "// Creator:    Dan Gisselquist, Ph.D.\n"
40
                                "//             Gisselquist Tecnology, LLC\n";
41
 
42
int     lgval(int vl) {
43
        int     lg;
44
 
45
        for(lg=1; (1<<lg) < vl; lg++)
46
                ;
47
        return lg;
48
}
49
 
50
int     nextlg(int vl) {
51
        int     r;
52
 
53
        for(r=1; r<vl; r<<=1)
54
                ;
55
        return r;
56
}
57
 
58 14 dgisselq
int     bflydelay(int nbits, int xtra) {
59 2 dgisselq
        int     cbits = nbits + xtra;
60 14 dgisselq
        int     delay;
61 2 dgisselq
        if (nbits+1<cbits)
62 5 dgisselq
                delay = nbits+4;
63 2 dgisselq
        else
64 5 dgisselq
                delay = cbits+3;
65 14 dgisselq
        return delay;
66 2 dgisselq
}
67
 
68 14 dgisselq
int     lgdelay(int nbits, int xtra) {
69
        // The butterfly code needs to compare a valid address, of this
70
        // many bits, with an address two greater.  This guarantees we
71
        // have enough bits for that comparison.  We'll also end up with
72
        // more storage space to look for these values, but without a 
73
        // redesign that's just what we'll deal with.
74
        return lgval(bflydelay(nbits, xtra)+3);
75
}
76
 
77 2 dgisselq
void    build_quarters(const char *fname) {
78
        FILE    *fp = fopen(fname, "w");
79
        if (NULL == fp) {
80
                fprintf(stderr, "Could not open \'%s\' for writing\n", fname);
81
                perror("O/S Err was:");
82
                return;
83
        }
84
 
85
        fprintf(fp,
86
"///////////////////////////////////////////////////////////////////////////\n"
87
"//\n"
88
"// Filename:   qtrstage.v\n"
89
"//             \n"
90
"// Project:    %s\n"
91
"//\n"
92 5 dgisselq
"// Purpose:    This file encapsulates the 4 point stage of a decimation in\n"
93
"//             frequency FFT.  This particular implementation is optimized\n"
94
"//             so that all of the multiplies are accomplished by additions\n"
95
"//             and multiplexers only.\n"
96
"//\n"
97 2 dgisselq
"//\n%s"
98
"//\n",
99
                prjname, creator);
100
        fprintf(fp, "%s", cpyleft);
101
 
102
        fprintf(fp,
103
"module\tqtrstage(i_clk, i_rst, i_ce, i_sync, i_data, o_data, o_sync);\n"
104 5 dgisselq
        "\tparameter    IWIDTH=16, OWIDTH=IWIDTH+1;\n"
105
        "\t// Parameters specific to the core that should be changed when this\n"
106
        "\t// core is built ... Note that the minimum LGSPAN is 2.  Smaller \n"
107
        "\t// spans must use the fftdoubles stage.\n"
108 15 dgisselq
        "\tparameter\tLGWIDTH=8, ODD=0, INVERSE=0,SHIFT=0,ROUND=1;\n"
109 5 dgisselq
        "\tinput\t                              i_clk, i_rst, i_ce, i_sync;\n"
110
        "\tinput\t      [(2*IWIDTH-1):0]        i_data;\n"
111
        "\toutput\treg  [(2*OWIDTH-1):0]        o_data;\n"
112
        "\toutput\treg                          o_sync;\n"
113 14 dgisselq
        "\t\n");
114
        fprintf(fp,
115 5 dgisselq
        "\treg\t        wait_for_sync;\n"
116
        "\treg\t[2:0]   pipeline;\n"
117 2 dgisselq
"\n"
118 5 dgisselq
        "\treg\t[(IWIDTH):0]    sum_r, sum_i, diff_r, diff_i;\n"
119 14 dgisselq
        "\twire\t[(IWIDTH):0]   n_diff_r, n_diff_i;\n"
120
        "\tassign n_diff_r = -diff_r;\n"
121 5 dgisselq
        "\tassign n_diff_i = -diff_i;\n"
122 2 dgisselq
"\n"
123 5 dgisselq
        "\treg\t[(2*OWIDTH-1):0]        ob_a;\n"
124
        "\twire\t[(2*OWIDTH-1):0]       ob_b;\n"
125
        "\treg\t[(OWIDTH-1):0]          ob_b_r, ob_b_i;\n"
126
        "\tassign       ob_b = { ob_b_r, ob_b_i };\n"
127 2 dgisselq
"\n"
128 5 dgisselq
        "\treg\t[(LGWIDTH-1):0]         iaddr;\n"
129
        "\treg\t[(2*IWIDTH-1):0]        imem;\n"
130 2 dgisselq
"\n"
131 5 dgisselq
        "\twire\tsigned\t[(IWIDTH-1):0]\timem_r, imem_i;\n"
132
        "\tassign\timem_r = imem[(2*IWIDTH-1):(IWIDTH)];\n"
133
        "\tassign\timem_i = imem[(IWIDTH-1):0];\n"
134 2 dgisselq
"\n"
135 5 dgisselq
        "\twire\tsigned\t[(IWIDTH-1):0]\ti_data_r, i_data_i;\n"
136
        "\tassign\ti_data_r = i_data[(2*IWIDTH-1):(IWIDTH)];\n"
137
        "\tassign\ti_data_i = i_data[(IWIDTH-1):0];\n"
138 2 dgisselq
"\n"
139 5 dgisselq
        "\treg  [(2*OWIDTH-1):0]        omem;\n"
140 14 dgisselq
"\n");
141
        fprintf(fp,
142 5 dgisselq
        "\twire [(IWIDTH-1):0]  rnd;\n"
143 9 dgisselq
        "\tgenerate\n"
144
        "\tif ((ROUND)&&((IWIDTH+1-OWIDTH-SHIFT)>0))\n"
145
                "\t\tassign rnd = { {(IWIDTH-1){1'b0}}, 1'b1 };\n"
146
        "\telse\n"
147
                "\t\tassign rnd = { {(IWIDTH){1'b0}}};\n"
148
        "\tendgenerate\n"
149 2 dgisselq
"\n"
150 5 dgisselq
        "\talways @(posedge i_clk)\n"
151
                "\t\tif (i_rst)\n"
152
                "\t\tbegin\n"
153
                        "\t\t\twait_for_sync <= 1'b1;\n"
154
                        "\t\t\tiaddr <= 0;\n"
155
                        "\t\t\tpipeline <= 3'b000;\n"
156
                "\t\tend\n"
157
                "\t\telse if ((i_ce)&&((~wait_for_sync)||(i_sync)))\n"
158
                "\t\tbegin\n"
159
                        "\t\t\t// Always\n"
160
                        "\t\t\timem <= i_data;\n"
161
                        "\t\t\tiaddr <= iaddr + 1;\n"
162
                        "\t\t\twait_for_sync <= 1'b0;\n"
163 2 dgisselq
"\n"
164 5 dgisselq
                        "\t\t\t// In sequence, clock = 0\n"
165
                        "\t\t\tif (iaddr[0])\n"
166
                        "\t\t\tbegin\n"
167
                                "\t\t\t\tsum_r  <= imem_r + i_data_r + rnd;\n"
168
                                "\t\t\t\tsum_i  <= imem_i + i_data_i + rnd;\n"
169
                                "\t\t\t\tdiff_r <= imem_r - i_data_r + rnd;\n"
170
                                "\t\t\t\tdiff_i <= imem_i - i_data_i + rnd;\n"
171 2 dgisselq
"\n"
172 5 dgisselq
                        "\t\t\t\tpipeline[2:0] <= { pipeline[1:0], 1'b1 };\n"
173
                        "\t\t\tend else\n"
174
                        "\t\t\t\tpipeline[2:0] <= { pipeline[1:0], 1'b0 };\n"
175 2 dgisselq
"\n"
176 5 dgisselq
                        "\t\t\t// In sequence, clock = 1\n"
177
                        "\t\t\tif (pipeline[1])\n"
178
                        "\t\t\tbegin\n"
179 9 dgisselq
"\t\t\t\tob_a <= { sum_r[(IWIDTH-SHIFT):(IWIDTH+1-OWIDTH-SHIFT)],\n"
180
        "\t\t\t\t\t\tsum_i[(IWIDTH-SHIFT):(IWIDTH+1-OWIDTH-SHIFT)] };\n"
181 5 dgisselq
                                "\t\t\t\t// on Even, W = e^{-j2pi 1/4 0} = 1\n"
182 9 dgisselq
                                "\t\t\t\tif (ODD == 0)\n"
183 5 dgisselq
                                "\t\t\t\tbegin\n"
184 2 dgisselq
"\t\t\t\t\tob_b_r <= diff_r[(IWIDTH-SHIFT):(IWIDTH+1-OWIDTH-SHIFT)];\n"
185
"\t\t\t\t\tob_b_i <= diff_i[(IWIDTH-SHIFT):(IWIDTH+1-OWIDTH-SHIFT)];\n"
186 9 dgisselq
// "\t\t\t\t\tob_b_r <=   { (OWIDTH) {1'b0} };\n"
187
// "\t\t\t\t\tob_b_i <=   { (OWIDTH) {1'b0} };\n"
188 14 dgisselq
                                "\t\t\t\tend else if (INVERSE==0) begin\n"
189 2 dgisselq
"\t\t\t\t\t// on Odd, W = e^{-j2pi 1/4} = -j\n"
190
"\t\t\t\t\tob_b_r <=   diff_i[(IWIDTH-SHIFT):(IWIDTH+1-OWIDTH-SHIFT)];\n"
191 14 dgisselq
"\t\t\t\t\tob_b_i <= n_diff_r[(IWIDTH-SHIFT):(IWIDTH+1-OWIDTH-SHIFT)];\n"
192 9 dgisselq
// "\t\t\t\t\tob_b_r <=   { (OWIDTH) {1'b0} };\n"
193
// "\t\t\t\t\tob_b_i <=   { (OWIDTH) {1'b0} };\n"
194 5 dgisselq
                                "\t\t\t\tend else begin\n"
195 2 dgisselq
"\t\t\t\t\t// on Odd, W = e^{j2pi 1/4} = j\n"
196
"\t\t\t\t\tob_b_r <= n_diff_i[(IWIDTH-SHIFT):(IWIDTH+1-OWIDTH-SHIFT)];\n"
197
"\t\t\t\t\tob_b_i <=   diff_r[(IWIDTH-SHIFT):(IWIDTH+1-OWIDTH-SHIFT)];\n"
198 9 dgisselq
// "\t\t\t\t\tob_b_r <=   { (OWIDTH) {1'b0} };\n"
199
// "\t\t\t\t\tob_b_i <=   { (OWIDTH) {1'b0} };\n"
200
 
201 5 dgisselq
                                "\t\t\t\tend\n"
202
                                "\t\t\t\t// (wire) ob_b <= { ob_b_r, ob_b_i };\n"
203
                        "\t\t\tend\n"
204
                        "\t\t\t// In sequence, clock = 2\n"
205
                        "\t\t\tif (pipeline[2])\n"
206
                        "\t\t\tbegin\n"
207
                                "\t\t\t\tomem <= ob_b;\n"
208
                                "\t\t\t\to_data <= ob_a;\n"
209
                        "\t\t\tend else\n"
210
                                "\t\t\t\to_data <= omem;\n"
211 6 dgisselq
                        "\t\t\t// Don\'t forget in the sync check that we are running\n"
212
                        "\t\t\t// at two clocks per sample.  Thus we need to\n"
213
                        "\t\t\t// produce a sync every 2^(LGWIDTH-1) clocks.\n"
214
                        "\t\t\to_sync <= &(~iaddr[(LGWIDTH-2):3]) && (iaddr[2:0] == 3'b100);\n"
215 5 dgisselq
                "\t\tend\n"
216 2 dgisselq
"endmodule\n");
217
}
218
 
219
void    build_dblstage(const char *fname) {
220
        FILE    *fp = fopen(fname, "w");
221
        if (NULL == fp) {
222
                fprintf(stderr, "Could not open \'%s\' for writing\n", fname);
223
                perror("O/S Err was:");
224
                return;
225
        }
226
 
227
        fprintf(fp,
228
"///////////////////////////////////////////////////////////////////////////\n"
229
"//\n"
230
"// Filename:   dblstage.v\n"
231
"//\n"
232
"// Project:    %s\n"
233
"//\n"
234
"// Purpose:    This is part of an FPGA implementation that will process\n"
235 5 dgisselq
"//             the final stage of a decimate-in-frequency FFT, running\n"
236
"//             through the data at two samples per clock.  If you notice\n"
237
"//             from the derivation of an FFT, the only time both even and\n"
238
"//             odd samples are used at the same time is in this stage.\n"
239
"//             Therefore, other than this stage and these twiddles, all of\n"
240
"//             the other stages can run two stages at a time at one sample\n"
241
"//             per clock.\n"
242 2 dgisselq
"//\n"
243
"//             In this implementation, the output is valid one clock after\n"
244
"//             the input is valid.  The output also accumulates one bit\n"
245
"//             above and beyond the number of bits in the input.\n"
246
"//             \n"
247
"//             i_clk   A system clock\n"
248 6 dgisselq
"//             i_rst   A synchronous reset\n"
249 2 dgisselq
"//             i_ce    Circuit enable--nothing happens unless this line is high\n"
250 6 dgisselq
"//             i_sync  A synchronization signal, high once per FFT at the start\n"
251 2 dgisselq
"//             i_left  The first (even) complex sample input.  The higher order\n"
252
"//                     bits contain the real portion, low order bits the\n"
253
"//                     imaginary portion, all in two\'s complement.\n"
254
"//             i_right The next (odd) complex sample input, same format as\n"
255
"//                     i_left.\n"
256
"//             o_left  The first (even) complex output.\n"
257
"//             o_right The next (odd) complex output.\n"
258 6 dgisselq
"//             o_sync  Output synchronization signal.\n"
259 2 dgisselq
"//\n%s"
260
"//\n", prjname, creator);
261
 
262
        fprintf(fp, "%s", cpyleft);
263
        fprintf(fp,
264 9 dgisselq
"module\tdblstage(i_clk, i_rst, i_ce, i_sync, i_left, i_right, o_left, o_right, o_sync);\n"
265 15 dgisselq
        "\tparameter\tIWIDTH=16,OWIDTH=IWIDTH+1, SHIFT=0;\n" //  ROUND=1
266 6 dgisselq
        "\tinput\t\ti_clk, i_rst, i_ce, i_sync;\n"
267 5 dgisselq
        "\tinput\t\t[(2*IWIDTH-1):0]\ti_left, i_right;\n"
268 6 dgisselq
        "\toutput\twire\t[(2*OWIDTH-1):0]\to_left, o_right;\n"
269
        "\toutput\treg\t\t\to_sync;\n"
270 2 dgisselq
"\n"
271 5 dgisselq
        "\twire\tsigned\t[(IWIDTH-1):0]\ti_in_0r, i_in_0i, i_in_1r, i_in_1i;\n"
272
        "\tassign\ti_in_0r = i_left[(2*IWIDTH-1):(IWIDTH)]; \n"
273
        "\tassign\ti_in_0i = i_left[(IWIDTH-1):0]; \n"
274
        "\tassign\ti_in_1r = i_right[(2*IWIDTH-1):(IWIDTH)]; \n"
275
        "\tassign\ti_in_1i = i_right[(IWIDTH-1):0]; \n"
276
        "\twire\t[(OWIDTH-1):0]\t\to_out_0r, o_out_0i,\n"
277
                                "\t\t\t\t\to_out_1r, o_out_1i;\n"
278 2 dgisselq
"\n"
279 15 dgisselq
"\n"
280
//      "\t// Handle a potential rounding situation, when IWIDTH=OWIDTH.\n"
281
//"\n"
282
//      "\twire\tsigned\t[(IWIDTH-1):0]\trnd;\n"
283
//"\n"
284
//      "\tgenerate\n"
285
//      "\tif ((ROUND==1)&&(IWIDTH==OWIDTH))\n"
286
//              "\t\tassign rnd = { {(IWIDTH-1){1'b0}}, 1'b1 };\n"
287
//      "\telse\n"
288
//              "\t\tassign rnd = { {(IWIDTH){1'b0}} };\n"
289
//      "\tendgenerate\n"
290
"\n"
291 5 dgisselq
        "\t// Don't forget that we accumulate a bit by adding two values\n"
292
        "\t// together. Therefore our intermediate value must have one more\n"
293
        "\t// bit than the two originals.\n"
294
        "\treg\t[IWIDTH:0]\tout_0r, out_0i, out_1r, out_1i;\n"
295 2 dgisselq
"\n"
296 6 dgisselq
        "\treg\twait_for_sync;\n"
297
"\n"
298 5 dgisselq
        "\talways @(posedge i_clk)\n"
299 6 dgisselq
                "\t\tif (i_rst)\n"
300
                        "\t\t\twait_for_sync <= 1'b1;\n"
301
                "\t\telse if ((i_ce)&&((~wait_for_sync)||(i_sync)))\n"
302 5 dgisselq
                "\t\tbegin\n"
303 6 dgisselq
                        "\t\t\twait_for_sync <= 1'b0;\n"
304
                        "\t\t\t//\n"
305 15 dgisselq
                        "\t\t\tout_0r <= i_in_0r + i_in_1r;\n"  // + rnd
306
                        "\t\t\tout_0i <= i_in_0i + i_in_1i;\n"  // + rnd
307 5 dgisselq
                        "\t\t\t//\n"
308 15 dgisselq
                        "\t\t\tout_1r <= i_in_0r - i_in_1r;\n"  // + rnd
309
                        "\t\t\tout_1i <= i_in_0i - i_in_1i;\n"  // + rnd
310 6 dgisselq
                        "\t\t\t//\n"
311
                        "\t\t\to_sync <= i_sync;\n"
312 5 dgisselq
                "\t\tend\n"
313 2 dgisselq
"\n"
314 5 dgisselq
        "\t// Now, if the master control program doesn't want to keep all of\n"
315
        "\t// our bits, we can shift down to OWIDTH bits here.\n"
316
        "\tassign\to_out_0r = out_0r[(IWIDTH-SHIFT):(IWIDTH+1-OWIDTH-SHIFT)];\n"
317
        "\tassign\to_out_0i = out_0i[(IWIDTH-SHIFT):(IWIDTH+1-OWIDTH-SHIFT)];\n"
318
        "\tassign\to_out_1r = out_1r[(IWIDTH-SHIFT):(IWIDTH+1-OWIDTH-SHIFT)];\n"
319
        "\tassign\to_out_1i = out_1i[(IWIDTH-SHIFT):(IWIDTH+1-OWIDTH-SHIFT)];\n"
320 2 dgisselq
"\n"
321 5 dgisselq
        "\tassign\to_left  = { o_out_0r, o_out_0i };\n"
322
        "\tassign\to_right = { o_out_1r, o_out_1i };\n"
323 2 dgisselq
"\n"
324
"endmodule\n");
325
        fclose(fp);
326
}
327
 
328
void    build_multiply(const char *fname) {
329
        FILE    *fp = fopen(fname, "w");
330
        if (NULL == fp) {
331
                fprintf(stderr, "Could not open \'%s\' for writing\n", fname);
332
                perror("O/S Err was:");
333
                return;
334
        }
335
 
336
        fprintf(fp,
337
"///////////////////////////////////////////////////////////////////////////\n"
338
"//\n"
339
"// Filename:   shiftaddmpy.v\n"
340
"//\n"
341
"// Project:    %s\n"
342
"//\n"
343
"// Purpose:    A portable shift and add multiply.\n"
344
"//\n"
345
"//             While both Xilinx and Altera will offer single clock \n"
346
"//             multiplies, this simple approach will multiply two numbers\n"
347
"//             on any architecture.  The result maintains the full width\n"
348
"//             of the multiply, there are no extra stuff bits, no rounding,\n"
349
"//             no shifted bits, etc.\n"
350
"//\n"
351
"//             Further, for those applications that can support it, this\n"
352
"//             multiply is pipelined and will produce one answer per clock.\n"
353
"//\n"
354
"//             For minimal processing delay, make the first parameter\n"
355
"//             the one with the least bits, so that AWIDTH <= BWIDTH.\n"
356
"//\n"
357
"//             The processing delay in this multiply is (AWIDTH+1) cycles.\n"
358
"//             That is, if the data is present on the input at clock t=0,\n"
359
"//             the result will be present on the output at time t=AWIDTH+1;\n"
360
"//\n"
361
"//\n%s"
362
"//\n", prjname, creator);
363
 
364
        fprintf(fp, "%s", cpyleft);
365
        fprintf(fp,
366
"module shiftaddmpy(i_clk, i_ce, i_a, i_b, o_r);\n"
367
        "\tparameter\tAWIDTH=16,BWIDTH=AWIDTH;\n"
368
        "\tinput\t\t\t\t\ti_clk, i_ce;\n"
369
        "\tinput\t\t[(AWIDTH-1):0]\t\ti_a;\n"
370
        "\tinput\t\t[(BWIDTH-1):0]\t\ti_b;\n"
371
        "\toutput\treg\t[(AWIDTH+BWIDTH-1):0]\to_r;\n"
372
"\n"
373
        "\treg\t[(AWIDTH-1):0]\tu_a;\n"
374
        "\treg\t[(BWIDTH-1):0]\tu_b;\n"
375
        "\treg\t\t\tsgn;\n"
376
"\n"
377
        "\treg\t[(AWIDTH-2):0]\t\tr_a[0:(AWIDTH-1)];\n"
378
        "\treg\t[(AWIDTH+BWIDTH-2):0]\tr_b[0:(AWIDTH-1)];\n"
379
        "\treg\t\t\t\tr_s[0:(AWIDTH-1)];\n"
380
        "\treg\t[(AWIDTH+BWIDTH-1):0]\tacc[0:(AWIDTH-1)];\n"
381
        "\tgenvar k;\n"
382
"\n"
383 5 dgisselq
        "\t// If we were forced to stay within two\'s complement arithmetic,\n"
384
        "\t// taking the absolute value here would require an additional bit.\n"
385
        "\t// However, because our results are now unsigned, we can stay\n"
386
        "\t// within the number of bits given (for now).\n"
387 2 dgisselq
        "\talways @(posedge i_clk)\n"
388
                "\t\tif (i_ce)\n"
389
                "\t\tbegin\n"
390
                        "\t\t\tu_a <= (i_a[AWIDTH-1])?(-i_a):(i_a);\n"
391
                        "\t\t\tu_b <= (i_b[BWIDTH-1])?(-i_b):(i_b);\n"
392
                        "\t\t\tsgn <= i_a[AWIDTH-1] ^ i_b[BWIDTH-1];\n"
393
                "\t\tend\n"
394
"\n"
395
        "\talways @(posedge i_clk)\n"
396
                "\t\tif (i_ce)\n"
397
                "\t\tbegin\n"
398
                        "\t\t\tacc[0] <= (u_a[0]) ? { {(AWIDTH){1'b0}}, u_b }\n"
399
                        "\t\t\t\t\t: {(AWIDTH+BWIDTH){1'b0}};\n"
400
                        "\t\t\tr_a[0] <= { u_a[(AWIDTH-1):1] };\n"
401
                        "\t\t\tr_b[0] <= { {(AWIDTH-1){1'b0}}, u_b };\n"
402
                        "\t\t\tr_s[0] <= sgn; // The final sign, needs to be preserved\n"
403
                "\t\tend\n"
404
"\n"
405
        "\tgenerate\n"
406
        "\talways @(posedge i_clk)\n"
407
        "\tif (i_ce)\n"
408
        "\tbegin\n"
409
                "\t\tfor(k=0; k<AWIDTH-1; k++)\n"
410
                "\t\tbegin\n"
411
                        "\t\t\tacc[k+1] <= acc[k] + ((r_a[k][0]) ? {r_b[k],1'b0}:0);\n"
412
                        "\t\t\tr_a[k+1] <= { 1'b0, r_a[k][(AWIDTH-2):1] };\n"
413
                        "\t\t\tr_b[k+1] <= { r_b[k][(AWIDTH+BWIDTH-3):0], 1'b0};\n"
414
                        "\t\t\tr_s[k+1] <= r_s[k];\n"
415
                "\t\tend\n"
416
        "\tend\n"
417
        "\tendgenerate\n"
418
"\n"
419
        "\talways @(posedge i_clk)\n"
420
                "\t\tif (i_ce)\n"
421
                        "\t\t\to_r <= (r_s[AWIDTH-1]) ? (-acc[AWIDTH-1]) : acc[AWIDTH-1];\n"
422
"\n"
423
"endmodule\n");
424
 
425
        fclose(fp);
426
}
427
 
428
void    build_dblreverse(const char *fname) {
429
        FILE    *fp = fopen(fname, "w");
430
        if (NULL == fp) {
431
                fprintf(stderr, "Could not open \'%s\' for writing\n", fname);
432
                perror("O/S Err was:");
433
                return;
434
        }
435
 
436
        fprintf(fp,
437
"///////////////////////////////////////////////////////////////////////////\n"
438
"//\n"
439
"// Filename:   dblreverse.v\n"
440
"//\n"
441
"// Project:    %s\n"
442
"//\n"
443
"// Purpose:    This module bitreverses a pipelined FFT input.  Operation is\n"
444
"//             expected as follows:\n"
445
"//\n"
446
"//             i_clk   A running clock at whatever system speed is offered.\n"
447
"//             i_rst   A synchronous reset signal, that resets all internals\n"
448
"//             i_ce    If this is one, one input is consumed and an output\n"
449
"//                     is produced.\n"
450
"//             i_in_0, i_in_1\n"
451
"//                     Two inputs to be consumed, each of width WIDTH.\n"
452
"//             o_out_0, o_out_1\n"
453
"//                     Two of the bitreversed outputs, also of the same\n"
454
"//                     width, WIDTH.  Of course, there is a delay from the\n"
455
"//                     first input to the first output.  For this purpose,\n"
456
"//                     o_sync is present.\n"
457
"//             o_sync  This will be a 1'b1 for the first value in any block.\n"
458
"//                     Following a reset, this will only become 1'b1 once\n"
459
"//                     the data has been loaded and is now valid.  After that,\n"
460
"//                     all outputs will be valid.\n"
461
"//\n%s"
462
"//\n", prjname, creator);
463
        fprintf(fp, "%s", cpyleft);
464
        fprintf(fp,
465
"\n\n"
466
"//\n"
467
"// How do we do bit reversing at two smples per clock?  Can we separate out\n"
468
"// our work into eight memory banks, writing two banks at once and reading\n"
469
"// another two banks in the same clock?\n"
470
"//\n"
471
"//     mem[00xxx0] = s_0[n]\n"
472
"//     mem[00xxx1] = s_1[n]\n"
473
"//     o_0[n] = mem[10xxx0]\n"
474
"//     o_1[n] = mem[11xxx0]\n"
475
"//     ...\n"
476
"//     mem[01xxx0] = s_0[m]\n"
477
"//     mem[01xxx1] = s_1[m]\n"
478
"//     o_0[m] = mem[10xxx1]\n"
479
"//     o_1[m] = mem[11xxx1]\n"
480
"//     ...\n"
481
"//     mem[10xxx0] = s_0[n]\n"
482
"//     mem[10xxx1] = s_1[n]\n"
483
"//     o_0[n] = mem[00xxx0]\n"
484
"//     o_1[n] = mem[01xxx0]\n"
485
"//     ...\n"
486
"//     mem[11xxx0] = s_0[m]\n"
487
"//     mem[11xxx1] = s_1[m]\n"
488
"//     o_0[m] = mem[00xxx1]\n"
489
"//     o_1[m] = mem[01xxx1]\n"
490
"//     ...\n"
491
"//\n"
492 5 dgisselq
"//     The answer is that, yes we can but: we need to use four memory banks\n"
493
"//     to do it properly.  These four banks are defined by the two bits\n"
494
"//     that determine the top and bottom of the correct address.  Larger\n"
495
"//     FFT\'s would require more memories.\n"
496
"//\n"
497 2 dgisselq
"//\n");
498
        fprintf(fp,
499
"module dblreverse(i_clk, i_rst, i_ce, i_in_0, i_in_1,\n"
500 5 dgisselq
        "\t\to_out_0, o_out_1, o_sync);\n"
501
        "\tparameter\t\t\tLGSIZE=4, WIDTH=24;\n"
502
        "\tinput\t\t\t\ti_clk, i_rst, i_ce;\n"
503
        "\tinput\t\t[(2*WIDTH-1):0]\ti_in_0, i_in_1;\n"
504
        "\toutput\treg\t[(2*WIDTH-1):0]\to_out_0, o_out_1;\n"
505
        "\toutput\treg\t\t\to_sync;\n"
506 2 dgisselq
"\n"
507 5 dgisselq
        "\treg\tin_reset;\n"
508
        "\treg\t[(LGSIZE):0]\tiaddr;\n"
509
        "\treg\t[(2*WIDTH-1):0]\tmem_0e [0:((1<<(LGSIZE-1))-1)];\n"
510
        "\treg\t[(2*WIDTH-1):0]\tmem_0o [0:((1<<(LGSIZE-1))-1)];\n"
511
        "\treg\t[(2*WIDTH-1):0]\tmem_1e [0:((1<<(LGSIZE-1))-1)];\n"
512
        "\treg\t[(2*WIDTH-1):0]\tmem_1o [0:((1<<(LGSIZE-1))-1)];\n"
513 2 dgisselq
"\n"
514 5 dgisselq
        "\twire\t[(2*LGSIZE-1):0]       braddr;\n"
515
        "\tgenvar\tk;\n"
516
        "\tgenerate for(k=0; k<LGSIZE; k++)\n"
517
                "\t\tassign braddr[k] = iaddr[LGSIZE-1-k];\n"
518
        "\tendgenerate\n"
519 2 dgisselq
"\n"
520 5 dgisselq
        "\talways @(posedge i_clk)\n"
521
                "\t\tif (i_rst)\n"
522
                "\t\tbegin\n"
523
                        "\t\t\tiaddr <= 0;\n"
524
                        "\t\t\tin_reset <= 1'b1;\n"
525
                "\t\tend else if (i_ce)\n"
526
                "\t\tbegin\n"
527
                        "\t\t\tif (iaddr[(LGSIZE-1)])\n"
528
                        "\t\t\tbegin\n"
529
                                "\t\t\t\tmem_1e[{iaddr[LGSIZE],iaddr[(LGSIZE-2):1]}] <= i_in_0;\n"
530
                                "\t\t\t\tmem_1o[{iaddr[LGSIZE],iaddr[(LGSIZE-2):1]}] <= i_in_1;\n"
531
                        "\t\t\tend else begin\n"
532
                                "\t\t\t\tmem_0e[{iaddr[LGSIZE],iaddr[(LGSIZE-2):1]}] <= i_in_0;\n"
533
                                "\t\t\t\tmem_0o[{iaddr[LGSIZE],iaddr[(LGSIZE-2):1]}] <= i_in_1;\n"
534
                        "\t\t\tend\n"
535
                        "\t\t\tiaddr <= iaddr + 2;\n"
536
                        "\t\t\tif (&iaddr[(LGSIZE-1):1])\n"
537
                                "\t\t\t\tin_reset <= 1'b0;\n"
538
                        "\t\t\tif (in_reset)\n"
539
                        "\t\t\tbegin\n"
540
                                "\t\t\t\to_out_0 <= {(2*WIDTH){1'b0}};\n"
541
                                "\t\t\t\to_out_1 <= {(2*WIDTH){1'b0}};\n"
542
                                "\t\t\t\to_sync <= 1'b0;\n"
543
                        "\t\t\tend else\n"
544
                        "\t\t\tbegin\n"
545
                                "\t\t\t\tif (braddr[0])\n"
546
                                "\t\t\t\tbegin\n"
547 2 dgisselq
"\t\t\t\t\to_out_0 <= mem_0o[{~iaddr[LGSIZE],braddr[(LGSIZE-2):1]}];\n"
548
"\t\t\t\t\to_out_1 <= mem_1o[{~iaddr[LGSIZE],braddr[(LGSIZE-2):1]}];\n"
549 5 dgisselq
                                "\t\t\t\tend else begin\n"
550 2 dgisselq
"\t\t\t\t\to_out_0 <= mem_0e[{~iaddr[LGSIZE],braddr[(LGSIZE-2):1]}];\n"
551
"\t\t\t\t\to_out_1 <= mem_1e[{~iaddr[LGSIZE],braddr[(LGSIZE-2):1]}];\n"
552 5 dgisselq
                                "\t\t\t\tend\n"
553
                                "\t\t\t\to_sync <= ~(|iaddr[(LGSIZE-1):0]);\n"
554
                        "\t\t\tend\n"
555
                "\t\tend\n"
556 2 dgisselq
"\n"
557
"endmodule;\n");
558
 
559
        fclose(fp);
560
}
561
 
562 14 dgisselq
void    build_butterfly(const char *fname, int xtracbits) {
563 2 dgisselq
        FILE    *fp = fopen(fname, "w");
564
        if (NULL == fp) {
565
                fprintf(stderr, "Could not open \'%s\' for writing\n", fname);
566
                perror("O/S Err was:");
567
                return;
568
        }
569
 
570
        fprintf(fp,
571
"///////////////////////////////////////////////////////////////////////////\n"
572
"//\n"
573
"// Filename:   butterfly.v\n"
574
"//\n"
575
"// Project:    %s\n"
576
"//\n"
577
"// Purpose:    This routine caculates a butterfly for a decimation\n"
578
"//             in frequency version of an FFT.  Specifically, given\n"
579
"//             complex Left and Right values together with a \n"
580
"//             coefficient, the output of this routine is given\n"
581
"//             by:\n"
582
"//\n"
583
"//             L' = L + R\n"
584
"//             R' = (L - R)*C\n"
585
"//\n"
586
"//             The rest of the junk below handles timing (mostly),\n"
587
"//             to make certain that L' and R' reach the output at\n"
588
"//             the same clock.  Further, just to make certain\n"
589
"//             that is the case, an 'aux' input exists.  This\n"
590
"//             aux value will come out of this routine synchronized\n"
591
"//             to the values it came in with.  (i.e., both L', R',\n"
592
"//             and aux all have the same delay.)  Hence, a caller\n"
593
"//             of this routine may set aux on the first input with\n"
594
"//             valid data, and then wait to see aux set on the output\n"
595
"//             to know when to find the first output with valid data.\n"
596
"//\n"
597
"//             All bits are preserved until the very last clock,\n"
598
"//             where any more bits than OWIDTH will be quietly\n"
599
"//             discarded.\n"
600
"//\n"
601
"//             This design features no overflow checking.\n"
602
"// \n"
603
"// Notes:\n"
604
"//             CORDIC:\n"
605
"//             Much as we would like, we can't use a cordic here.\n"
606
"//             The goal is to accomplish an FFT, as defined, and a\n"
607
"//             CORDIC places a scale factor onto the data.  Removing\n"
608
"//             the scale factor would cost a two multiplies, which\n"
609
"//             is precisely what we are trying to avoid.\n"
610
"//\n"
611
"//\n"
612
"//             3-MULTIPLIES:\n"
613
"//             It should also be possible to do this with three \n"
614
"//             multiplies and an extra two addition cycles.  \n"
615
"//\n"
616
"//             We want\n"
617
"//                     R+I = (a + jb) * (c + jd)\n"
618
"//                     R+I = (ac-bd) + j(ad+bc)\n"
619
"//             We multiply\n"
620
"//                     P1 = ac\n"
621
"//                     P2 = bd\n"
622
"//                     P3 = (a+b)(c+d)\n"
623
"//             Then \n"
624
"//                     R+I=(P1-P2)+j(P3-P2-P1)\n"
625
"//\n"
626
"//             WIDTHS:\n"
627
"//             On multiplying an X width number by an\n"
628
"//             Y width number, X>Y, the result should be (X+Y)\n"
629
"//             bits, right?\n"
630
"//             -2^(X-1) <= a <= 2^(X-1) - 1\n"
631
"//             -2^(Y-1) <= b <= 2^(Y-1) - 1\n"
632
"//             (2^(Y-1)-1)*(-2^(X-1)) <= ab <= 2^(X-1)2^(Y-1)\n"
633
"//             -2^(X+Y-2)+2^(X-1) <= ab <= 2^(X+Y-2) <= 2^(X+Y-1) - 1\n"
634
"//             -2^(X+Y-1) <= ab <= 2^(X+Y-1)-1\n"
635
"//             YUP!  But just barely.  Do this and you'll really want\n"
636
"//             to drop a bit, although you will risk overflow in so\n"
637
"//             doing.\n"
638
"//\n%s"
639
"//\n", prjname, creator);
640
        fprintf(fp, "%s", cpyleft);
641
 
642
        fprintf(fp,
643 6 dgisselq
"module\tbutterfly(i_clk, i_rst, i_ce, i_coef, i_left, i_right, i_aux,\n"
644 5 dgisselq
                "\t\to_left, o_right, o_aux);\n"
645
        "\t// Public changeable parameters ...\n"
646 14 dgisselq
        "\tparameter IWIDTH=%d,CWIDTH=IWIDTH+%d,OWIDTH=IWIDTH+1;\n"
647 5 dgisselq
        "\t// Parameters specific to the core that should not be changed.\n"
648 14 dgisselq
        "\tparameter    MPYDELAY=%d'd%d, // (IWIDTH+1 < CWIDTH)?(IWIDTH+4):(CWIDTH+3),\n"
649 15 dgisselq
                        "\t\t\tSHIFT=0, ROUND=1;\n"
650 5 dgisselq
        "\t// The LGDELAY should be the base two log of the MPYDELAY.  If\n"
651
        "\t// this value is fractional, then round up to the nearest\n"
652
        "\t// integer: LGDELAY=ceil(log(MPYDELAY)/log(2));\n"
653 14 dgisselq
        "\tparameter\tLGDELAY=%d;\n"
654 6 dgisselq
        "\tinput\t\ti_clk, i_rst, i_ce;\n"
655 5 dgisselq
        "\tinput\t\t[(2*CWIDTH-1):0] i_coef;\n"
656
        "\tinput\t\t[(2*IWIDTH-1):0] i_left, i_right;\n"
657
        "\tinput\t\ti_aux;\n"
658
        "\toutput\twire [(2*OWIDTH-1):0] o_left, o_right;\n"
659
        "\toutput\twire o_aux;\n"
660 14 dgisselq
        "\n", 16, xtracbits, lgdelay(16,xtracbits),
661
        bflydelay(16, xtracbits), lgdelay(16,xtracbits));
662
        fprintf(fp,
663 5 dgisselq
        "\twire\t[(OWIDTH-1):0] o_left_r, o_left_i, o_right_r, o_right_i;\n"
664 2 dgisselq
"\n"
665 5 dgisselq
        "\treg\t[(2*IWIDTH-1):0]\tr_left, r_right;\n"
666
        "\treg\t\t\t\tr_aux, r_aux_2;\n"
667
        "\treg\t[(2*CWIDTH-1):0]\tr_coef, r_coef_2;\n"
668
        "\twire\tsigned\t[(CWIDTH-1):0]\tr_coef_r, r_coef_i;\n"
669
        "\tassign\tr_coef_r  = r_coef_2[ (2*CWIDTH-1):(CWIDTH)];\n"
670
        "\tassign\tr_coef_i  = r_coef_2[ (  CWIDTH-1):0];\n"
671
        "\twire\tsigned\t[(IWIDTH-1):0]\tr_left_r, r_left_i, r_right_r, r_right_i;\n"
672
        "\tassign\tr_left_r  = r_left[ (2*IWIDTH-1):(IWIDTH)];\n"
673
        "\tassign\tr_left_i  = r_left[ (IWIDTH-1):0];\n"
674
        "\tassign\tr_right_r = r_right[(2*IWIDTH-1):(IWIDTH)];\n"
675
        "\tassign\tr_right_i = r_right[(IWIDTH-1):0];\n"
676 2 dgisselq
"\n"
677 5 dgisselq
        "\treg\tsigned\t[(IWIDTH):0]\tr_sum_r, r_sum_i, r_dif_r, r_dif_i;\n"
678 2 dgisselq
"\n"
679 5 dgisselq
        "\treg  [(LGDELAY-1):0] fifo_addr;\n"
680
        "\twire [(LGDELAY-1):0] fifo_read_addr;\n"
681 6 dgisselq
        "\tassign\tfifo_read_addr = fifo_addr - MPYDELAY;\n"
682 5 dgisselq
        "\treg  [(2*IWIDTH+2):0]        fifo_left [ 0:((1<<LGDELAY)-1)];\n"
683 6 dgisselq
        "\treg\t\t\t\tovalid;\n"
684 5 dgisselq
"\n");
685
        fprintf(fp,
686
        "\t// Set up the input to the multiply\n"
687 2 dgisselq
        "\talways @(posedge i_clk)\n"
688
                "\t\tif (i_ce)\n"
689
                "\t\tbegin\n"
690
                        "\t\t\t// One clock just latches the inputs\n"
691
                        "\t\t\tr_left <= i_left;        // No change in # of bits\n"
692
                        "\t\t\tr_right <= i_right;\n"
693
                        "\t\t\tr_aux <= i_aux;\n"
694
                        "\t\t\tr_coef  <= i_coef;\n"
695
                        "\t\t\t// Next clock adds/subtracts\n"
696
                        "\t\t\tr_sum_r <= r_left_r + r_right_r; // Now IWIDTH+1 bits\n"
697
                        "\t\t\tr_sum_i <= r_left_i + r_right_i;\n"
698
                        "\t\t\tr_dif_r <= r_left_r - r_right_r;\n"
699
                        "\t\t\tr_dif_i <= r_left_i - r_right_i;\n"
700
                        "\t\t\t// Other inputs are simply delayed on second clock\n"
701
                        "\t\t\tr_aux_2 <= r_aux;\n"
702
                        "\t\t\tr_coef_2<= r_coef;\n"
703
        "\t\tend\n"
704 5 dgisselq
"\n");
705
        fprintf(fp,
706
        "\t// Don\'t forget to record the even side, since it doesn\'t need\n"
707
        "\t// to be multiplied, but yet we still need the results in sync\n"
708
        "\t// with the answer when it is ready.\n"
709 2 dgisselq
        "\talways @(posedge i_clk)\n"
710 6 dgisselq
                "\t\tif (i_rst)\n"
711 2 dgisselq
                "\t\tbegin\n"
712 6 dgisselq
                        "\t\t\tfifo_addr <= 0;\n"
713
                        "\t\t\tovalid <= 1'b0;\n"
714
                "\t\tend else if (i_ce)\n"
715
                "\t\tbegin\n"
716 2 dgisselq
                        "\t\t\t// Need to delay the sum side--nothing else happens\n"
717
                        "\t\t\t// to it, but it needs to stay synchronized with the\n"
718
                        "\t\t\t// right side.\n"
719
                        "\t\t\tfifo_left[fifo_addr] <= { r_aux_2, r_sum_r, r_sum_i };\n"
720
                        "\t\t\tfifo_addr <= fifo_addr + 1;\n"
721 14 dgisselq
"\n"
722
                        "\t\t\tovalid <= (ovalid) || (fifo_addr > (MPYDELAY+1));\n"
723 2 dgisselq
                "\t\tend\n"
724
"\n"
725 5 dgisselq
        "\twire\tsigned\t[(CWIDTH-1):0] ir_coef_r, ir_coef_i;\n"
726
        "\tassign\tir_coef_r = r_coef_2[(2*CWIDTH-1):CWIDTH];\n"
727
        "\tassign\tir_coef_i = r_coef_2[(CWIDTH-1):0];\n"
728
        "\twire\tsigned\t[((IWIDTH+2)+(CWIDTH+1)-1):0]\tp_one, p_two, p_three;\n"
729 2 dgisselq
"\n"
730 5 dgisselq
"\n");
731
        fprintf(fp,
732
        "\t// Multiply output is always a width of the sum of the widths of\n"
733
        "\t// the two inputs.  ALWAYS.  This is independent of the number of\n"
734
        "\t// bits in p_one, p_two, or p_three.  These values needed to \n"
735
        "\t// accumulate a bit (or two) each.  However, this approach to a\n"
736
        "\t// three multiply complex multiply cannot increase the total\n"
737
        "\t// number of bits in our final output.  We\'ll take care of\n"
738
        "\t// dropping back down to the proper width, OWIDTH, in our routine\n"
739
        "\t// below.\n"
740 2 dgisselq
"\n"
741 5 dgisselq
"\n");
742
        fprintf(fp,
743
        "\t// We accomplish here \"Karatsuba\" multiplication.  That is,\n"
744
        "\t// by doing three multiplies we accomplish the work of four.\n"
745
        "\t// Let\'s prove to ourselves that this works ... We wish to\n"
746
        "\t// multiply: (a+jb) * (c+jd), where a+jb is given by\n"
747
        "\t//\ta + jb = r_dif_r + j r_dif_i, and\n"
748
        "\t//\tc + jd = ir_coef_r + j ir_coef_i.\n"
749
        "\t// We do this by calculating the intermediate products P1, P2,\n"
750
        "\t// and P3 as\n"
751
        "\t//\tP1 = ac\n"
752
        "\t//\tP2 = bd\n"
753
        "\t//\tP3 = (a + b) * (c + d)\n"
754
        "\t// and then complete our final answer with\n"
755
        "\t//\tac - bd = P1 - P2 (this checks)\n"
756
        "\t//\tad + bc = P3 - P2 - P1\n"
757
        "\t//\t        = (ac + bc + ad + bd) - bd - ac\n"
758
        "\t//\t        = bc + ad (this checks)\n"
759 2 dgisselq
"\n"
760 5 dgisselq
"\n");
761
        fprintf(fp,
762
        "\t// This should really be based upon an IF, such as in\n"
763
        "\t// if (IWIDTH < CWIDTH) then ...\n"
764
        "\t// However, this is the only (other) way I know to do it.\n"
765 2 dgisselq
        "\tgenerate\n"
766
        "\tif (CWIDTH < IWIDTH+1)\n"
767
        "\tbegin\n"
768
                "\t\t// We need to pad these first two multiplies by an extra\n"
769 5 dgisselq
                "\t\t// bit just to keep them aligned with the third,\n"
770
                "\t\t// simpler, multiply.\n"
771 2 dgisselq
                "\t\tshiftaddmpy #(CWIDTH+1,IWIDTH+2) p1(i_clk, i_ce,\n"
772
                                "\t\t\t\t{ir_coef_r[CWIDTH-1],ir_coef_r},\n"
773
                                "\t\t\t\t{r_dif_r[IWIDTH],r_dif_r}, p_one);\n"
774
                "\t\tshiftaddmpy #(CWIDTH+1,IWIDTH+2) p2(i_clk, i_ce,\n"
775 5 dgisselq
                                "\t\t\t\t{ir_coef_i[CWIDTH-1],ir_coef_i},\n"
776 2 dgisselq
                                "\t\t\t\t{r_dif_i[IWIDTH],r_dif_i}, p_two);\n"
777
                "\t\tshiftaddmpy #(CWIDTH+1,IWIDTH+2) p3(i_clk, i_ce,\n"
778 5 dgisselq
                        "\t\t\t\tir_coef_i+ir_coef_r,\n"
779
                        "\t\t\t\tr_dif_r + r_dif_i,\n"
780
                        "\t\t\t\tp_three);\n"
781 2 dgisselq
        "\tend else begin\n"
782
                "\t\tshiftaddmpy #(IWIDTH+2,CWIDTH+1) p1a(i_clk, i_ce,\n"
783
                                "\t\t\t\t{r_dif_r[IWIDTH],r_dif_r},\n"
784
                                "\t\t\t\t{ir_coef_r[CWIDTH-1],ir_coef_r}, p_one);\n"
785
                "\t\tshiftaddmpy #(IWIDTH+2,CWIDTH+1) p2a(i_clk, i_ce,\n"
786
                                "\t\t\t\t{r_dif_i[IWIDTH], r_dif_i},\n"
787 5 dgisselq
                                "\t\t\t\t{ir_coef_i[CWIDTH-1],ir_coef_i}, p_two);\n"
788 2 dgisselq
                "\t\tshiftaddmpy #(IWIDTH+2,CWIDTH+1) p3a(i_clk, i_ce,\n"
789
                                "\t\t\t\tr_dif_r+r_dif_i,\n"
790
                                "\t\t\t\tir_coef_i+ir_coef_r,\n"
791
                                "\t\t\t\tp_three);\n"
792
        "\tend\n"
793
        "\tendgenerate\n"
794 5 dgisselq
"\n");
795
        fprintf(fp,
796
        "\t// These values are held in memory and delayed during the\n"
797
        "\t// multiply.  Here, we recover them.  During the multiply,\n"
798
        "\t// values were multiplied by 2^(CWIDTH-2)*exp{-j*2*pi*...},\n"
799
        "\t// therefore, the left_x values need to be right shifted by\n"
800
        "\t// CWIDTH-2 as well.  The additional bits come from a sign\n"
801
        "\t// extension.\n"
802 2 dgisselq
        "\twire aux;\n"
803 5 dgisselq
        "\twire\tsigned\t[(IWIDTH+CWIDTH):0]    fifo_i, fifo_r;\n"
804
        "\treg\t\t[(2*IWIDTH+2):0]      fifo_read;\n"
805
        "\tassign\tfifo_r = { {2{fifo_read[2*(IWIDTH+1)-1]}}, fifo_read[(2*(IWIDTH+1)-1):(IWIDTH+1)], {(CWIDTH-2){1'b0}} };\n"
806
        "\tassign\tfifo_i = { {2{fifo_read[(IWIDTH+1)-1]}}, fifo_read[((IWIDTH+1)-1):0], {(CWIDTH-2){1'b0}} };\n"
807
        "\tassign\taux = fifo_read[2*IWIDTH+2];\n"
808 2 dgisselq
"\n"
809
"\n"
810 5 dgisselq
        "\treg\tsigned\t[(CWIDTH+IWIDTH+3-1):0] b_left_r, b_left_i,\n"
811
                        "\t\t\t\t\t\tb_right_r, b_right_i;\n"
812
        "\treg\tsigned\t[(CWIDTH+IWIDTH+3-1):0] mpy_r, mpy_i;\n"
813
        "\treg\tsigned\t[(CWIDTH+IWIDTH+3-1):0] rnd;\n"
814
        "\tgenerate\n"
815 15 dgisselq
        "\tif ((ROUND==0)||(CWIDTH+IWIDTH-OWIDTH-SHIFT<1))\n"
816 5 dgisselq
                "\t\tassign rnd = ({(CWIDTH+IWIDTH+3){1'b0}});\n"
817
        "\telse\n"
818 15 dgisselq
                "\t\tassign rnd = ({ {(OWIDTH+4+SHIFT){1'b0}},1'b1,\n"
819
                "\t\t\t\t{((IWIDTH+CWIDTH+3)-(OWIDTH+SHIFT+5)){1'b0}} });\n"
820 5 dgisselq
        "\tendgenerate\n"
821
"\n");
822
        fprintf(fp,
823 2 dgisselq
        "\talways @(posedge i_clk)\n"
824
                "\t\tif (i_ce)\n"
825
                "\t\tbegin\n"
826
                        "\t\t\t// First clock, recover all values\n"
827
                        "\t\t\tfifo_read <= fifo_left[fifo_read_addr];\n"
828
                        "\t\t\t// These values are IWIDTH+CWIDTH+3 bits wide\n"
829 5 dgisselq
                        "\t\t\t// although they only need to be (IWIDTH+1)\n"
830
                        "\t\t\t// + (CWIDTH) bits wide.  (We\'ve got two\n"
831
                        "\t\t\t// extra bits we need to get rid of.)\n"
832 2 dgisselq
                        "\t\t\tmpy_r <= p_one - p_two;\n"
833
                        "\t\t\tmpy_i <= p_three - p_one - p_two;\n"
834
"\n"
835
                        "\t\t\t// Second clock, round and latch for final clock\n"
836
                        "\t\t\tb_right_r <= mpy_r + rnd;\n"
837
                        "\t\t\tb_right_i <= mpy_i + rnd;\n"
838 5 dgisselq
                        "\t\t\tb_left_r <= { {2{fifo_r[(IWIDTH+CWIDTH)]}},fifo_r } + rnd;\n"
839
                        "\t\t\tb_left_i <= { {2{fifo_i[(IWIDTH+CWIDTH)]}},fifo_i } + rnd;\n"
840 6 dgisselq
                        "\t\t\to_aux <= aux & ovalid;\n"
841 2 dgisselq
                "\t\tend\n"
842 5 dgisselq
"\n");
843
        fprintf(fp,
844 2 dgisselq
        "\t// Final clock--clock and remove unnecessary bits.\n"
845 5 dgisselq
        "\t// We have (IWIDTH+CWIDTH+3) bits here, we need to drop down to\n"
846
        "\t// OWIDTH, and SHIFT by SHIFT bits in the process.  The trick is\n"
847
        "\t// that we don\'t need (IWIDTH+CWIDTH+3) bits.  We\'ve accumulated\n"
848
        "\t// them, but the actual values will never fill all these bits.\n"
849
        "\t// In particular, we only need:\n"
850
        "\t//\t IWIDTH bits for the input\n"
851
        "\t//\t     +1 bit for the add/subtract\n"
852
        "\t//\t+CWIDTH bits for the coefficient multiply\n"
853
        "\t//\t     +1 bit for the add/subtract in the complex multiply\n"
854
        "\t//\t ------\n"
855
        "\t//\t (IWIDTH+CWIDTH+2) bits at full precision.\n"
856
        "\t//\n"
857
        "\t// However, the coefficient multiply multiplied by a maximum value\n"
858
        "\t// of 2^(CWIDTH-2).  Thus, we only have\n"
859
        "\t//\t   IWIDTH bits for the input\n"
860
        "\t//\t       +1 bit for the add/subtract\n"
861
        "\t//\t+CWIDTH-2 bits for the coefficient multiply\n"
862
        "\t//\t       +1 (optional) bit for the add/subtract in the cpx mpy.\n"
863
        "\t//\t -------- ... multiply.  (This last bit may be shifted out.)\n"
864
        "\t//\t (IWIDTH+CWIDTH) valid output bits. \n"
865
        "\t// Now, if the user wants to keep any extras of these (via OWIDTH),\n"
866
        "\t// or if he wishes to arbitrarily shift some of these off (via\n"
867
        "\t// SHIFT) we accomplish that here.\n"
868
        "\tassign o_left_r  = b_left_r[ (CWIDTH+IWIDTH-1-SHIFT-1):(CWIDTH+IWIDTH-OWIDTH-SHIFT-1)];\n"
869
        "\tassign o_left_i  = b_left_i[ (CWIDTH+IWIDTH-1-SHIFT-1):(CWIDTH+IWIDTH-OWIDTH-SHIFT-1)];\n"
870
        "\tassign o_right_r = b_right_r[(CWIDTH+IWIDTH-1-SHIFT-1):(CWIDTH+IWIDTH-OWIDTH-SHIFT-1)];\n"
871
        "\tassign o_right_i = b_right_i[(CWIDTH+IWIDTH-1-SHIFT-1):(CWIDTH+IWIDTH-OWIDTH-SHIFT-1)];\n"
872 2 dgisselq
"\n"
873 5 dgisselq
        "\t// As a final step, we pack our outputs into two packed two\'s\n"
874
        "\t// complement numbers per output word, so that each output word\n"
875
        "\t// has (2*OWIDTH) bits in it, with the top half being the real\n"
876
        "\t// portion and the bottom half being the imaginary portion.\n"
877 2 dgisselq
        "\tassign       o_left = { o_left_r, o_left_i };\n"
878
        "\tassign       o_right= { o_right_r,o_right_i};\n"
879
"\n"
880
"endmodule\n");
881
        fclose(fp);
882
}
883
 
884
void    build_stage(const char *fname, int stage, bool odd, int nbits, bool inv, int xtra) {
885
        FILE    *fstage = fopen(fname, "w");
886
        int     cbits = nbits + xtra;
887
 
888
        if ((cbits * 2) >= sizeof(long long)*8) {
889
                fprintf(stderr, "ERROR: CMEM Coefficient precision requested overflows long long data type.\n");
890
                exit(-1);
891
        }
892
 
893
        if (fstage == NULL) {
894
                fprintf(stderr, "ERROR: Could not open %s for writing!\n", fname);
895
                perror("O/S Err was:");
896
                fprintf(stderr, "Attempting to continue, but this file will be missing.\n");
897
                return;
898
        }
899
 
900
        fprintf(fstage,
901
"////////////////////////////////////////////////////////////////////////////\n"
902
"//\n"
903
"// Filename:   %sfftstage_%c%d.v\n"
904
"//\n"
905
"// Project:    %s\n"
906
"//\n"
907
"// Purpose:    This file is (almost) a Verilog source file.  It is meant to\n"
908
"//             be used by a FFT core compiler to generate FFTs which may be\n"
909
"//             used as part of an FFT core.  Specifically, this file \n"
910
"//             encapsulates the options of an FFT-stage.  For any 2^N length\n"
911
"//             FFT, there shall be (N-1) of these stages.  \n"
912
"//\n%s"
913
"//\n",
914
                (inv)?"i":"", (odd)?'o':'e', stage*2, prjname, creator);
915
        fprintf(fstage, "%s", cpyleft);
916
        fprintf(fstage, "module\t%sfftstage_%c%d(i_clk, i_rst, i_ce, i_sync, i_data, o_data, o_sync);\n",
917
                (inv)?"i":"", (odd)?'o':'e', stage*2);
918
        // These parameter values are useless at this point--they are to be
919
        // replaced by the parameter values in the calling program.  Only
920
        // problem is, the CWIDTH needs to match exactly!
921
        fprintf(fstage, "\tparameter\tIWIDTH=%d,CWIDTH=%d,OWIDTH=%d;\n",
922
                nbits, cbits, nbits+1);
923
        fprintf(fstage,
924
"\t// Parameters specific to the core that should be changed when this\n"
925
"\t// core is built ... Note that the minimum LGSPAN (the base two log\n"
926
"\t// of the span, or the base two log of the current FFT size) is 3.\n"
927
"\t// Smaller spans (i.e. the span of 2) must use the dblstage module.\n"
928 6 dgisselq
"\tparameter\tLGWIDTH=11, LGSPAN=9, LGBDLY=5, BFLYSHIFT=0;\n");
929 2 dgisselq
        fprintf(fstage,
930
"\tinput                                        i_clk, i_rst, i_ce, i_sync;\n"
931
"\tinput                [(2*IWIDTH-1):0]        i_data;\n"
932
"\toutput       reg     [(2*OWIDTH-1):0]        o_data;\n"
933
"\toutput       reg                             o_sync;\n"
934
"\n"
935
"\treg  wait_for_sync;\n"
936
"\treg  [(2*IWIDTH-1):0]        ib_a, ib_b;\n"
937
"\treg  [(2*CWIDTH-1):0]        ib_c;\n"
938 8 dgisselq
"\treg  ib_sync;\n"
939 2 dgisselq
"\n"
940
"\treg  b_started;\n"
941
"\twire ob_sync;\n"
942
"\twire [(2*OWIDTH-1):0]        ob_a, ob_b;\n");
943
        fprintf(fstage,
944
"\n"
945
"\t// %scmem is defined as an array of real and complex values,\n"
946
"\t// where the top CWIDTH bits are the real value and the bottom\n"
947
"\t// CWIDTH bits are the imaginary value.\n"
948
"\t//\n"
949
"\t// cmem[i] = { (2^(CWIDTH-2)) * cos(2*pi*i/(2^LGWIDTH)),\n"
950
"\t//           (2^(CWIDTH-2)) * sin(2*pi*i/(2^LGWIDTH)) };\n"
951
"\t//\n"
952
"\treg  [(2*CWIDTH-1):0]        %scmem [0:((1<<LGSPAN)-1)];\n"
953
"\tinitial\t$readmemh(\"%scmem_%c%d.hex\",%scmem);\n\n",
954
                (inv)?"i":"", (inv)?"i":"",
955
                (inv)?"i":"", (odd)?'o':'e',stage<<1,
956
                (inv)?"i":"");
957
        {
958
                FILE    *cmem;
959
 
960 14 dgisselq
                {
961
                        char    *memfile, *ptr;
962
 
963
                        memfile = new char[strlen(fname)+128];
964
                        strcpy(memfile, fname);
965
                        if ((NULL != (ptr = strrchr(memfile, '/')))&&(ptr>memfile)) {
966
                                ptr++;
967
                                sprintf(ptr, "%scmem_%c%d.hex", (inv)?"i":"", (odd)?'o':'e', stage*2);
968
                        } else {
969
                                sprintf(memfile, "%s/%scmem_%c%d.hex",
970
                                        COREDIR, (inv)?"i":"",
971
                                        (odd)?'o':'e', stage*2);
972
                        }
973
                        // strcpy(&memfile[strlen(memfile)-2], ".hex");
974
                        cmem = fopen(memfile, "w");
975
                        if (NULL == cmem) {
976
                                fprintf(stderr, "Could not open/write \'%s\' with FFT coefficients.\n", memfile);
977
                                perror("Err from O/S:");
978
                                exit(-2);
979
                        }
980
 
981
                        delete[] memfile;
982 2 dgisselq
                }
983
                // fprintf(cmem, "// CBITS = %d, inv = %s\n", cbits, (inv)?"true":"false");
984
                for(int i=0; i<stage/2; i++) {
985
                        int k = 2*i+odd;
986 9 dgisselq
                        double  W = ((inv)?1:-1)*2.0*M_PI*k/(double)(2*stage);
987 2 dgisselq
                        double  c, s;
988
                        long long ic, is, vl;
989
 
990
                        c = cos(W); s = sin(W);
991
                        ic = (long long)((double)((1ll<<(cbits-2)) * c + 0.5));
992
                        is = (long long)((double)((1ll<<(cbits-2)) * s + 0.5));
993
                        vl = (ic & (~(-1ll << (cbits))));
994
                        vl <<= (cbits);
995
                        vl |= (is & (~(-1ll << (cbits))));
996
                        fprintf(cmem, "%0*llx\n", ((cbits*2+3)/4), vl);
997
                        /*
998
                        fprintf(cmem, "%0*llx\t\t// %f+j%f -> %llx +j%llx\n",
999
                                ((cbits*2+3)/4), vl, c, s,
1000
                                ic & (~(-1ll<<(((cbits+3)/4)*4))),
1001
                                is & (~(-1ll<<(((cbits+3)/4)*4))));
1002
                        */
1003
                } fclose(cmem);
1004
        }
1005
 
1006
        fprintf(fstage,
1007 6 dgisselq
"\treg  [(LGWIDTH-2):0]         iaddr;\n"
1008 2 dgisselq
"\treg  [(2*IWIDTH-1):0]        imem    [0:((1<<LGSPAN)-1)];\n"
1009
"\n"
1010 8 dgisselq
"\treg  [LGSPAN:0]              oB;\n"
1011 2 dgisselq
"\treg  [(2*OWIDTH-1):0]        omem    [0:((1<<LGSPAN)-1)];\n"
1012
"\n"
1013
"\talways @(posedge i_clk)\n"
1014
        "\t\tif (i_rst)\n"
1015
        "\t\tbegin\n"
1016
                "\t\t\twait_for_sync <= 1'b1;\n"
1017
                "\t\t\tiaddr <= 0;\n"
1018
                "\t\t\toB <= 0;\n"
1019 8 dgisselq
                "\t\t\tib_sync   <= 1'b0;\n"
1020
                "\t\t\to_sync    <= 1'b0;\n"
1021
                "\t\t\tb_started <= 1'b0;\n"
1022 2 dgisselq
        "\t\tend\n"
1023
        "\t\telse if ((i_ce)&&((~wait_for_sync)||(i_sync)))\n"
1024
        "\t\tbegin\n"
1025
                "\t\t\t//\n"
1026
                "\t\t\t// First step: Record what we\'re not ready to use yet\n"
1027
                "\t\t\t//\n"
1028
                "\t\t\timem[iaddr[(LGSPAN-1):0]] <= i_data;\n"
1029
                "\t\t\tiaddr <= iaddr + 1;\n"
1030
                "\t\t\twait_for_sync <= 1'b0;\n"
1031
"\n"
1032
                "\t\t\t//\n"
1033
                "\t\t\t// Now, we have all the inputs, so let\'s feed the\n"
1034
                "\t\t\t// butterfly\n"
1035
                "\t\t\t//\n"
1036 6 dgisselq
                "\t\t\tif (iaddr[LGSPAN])\n"
1037 2 dgisselq
                "\t\t\tbegin\n"
1038
                        "\t\t\t\t// One input from memory, ...\n"
1039
                        "\t\t\t\tib_a <= imem[iaddr[(LGSPAN-1):0]];\n"
1040
                        "\t\t\t\t// One input clocked in from the top\n"
1041
                        "\t\t\t\tib_b <= i_data;\n"
1042
                        "\t\t\t\t// Set the sync to true on the very first\n"
1043
                        "\t\t\t\t// valid input in, and hence on the very\n"
1044
                        "\t\t\t\t// first valid data out per FFT.\n"
1045 6 dgisselq
                        "\t\t\t\tib_sync <= (iaddr==(1<<(LGSPAN)));\n"
1046 2 dgisselq
                        "\t\t\t\tib_c <= %scmem[iaddr[(LGSPAN-1):0]];\n"
1047 8 dgisselq
                "\t\t\tend else begin\n"
1048
                        "\t\t\t\t// Just to make debugging easier, let\'s\n"
1049
                        "\t\t\t\t// clear these registers.  That\'ll make\n"
1050
                        "\t\t\t\t// the transition easier to watch.\n"
1051
                        "\t\t\t\tib_a <= {(2*IWIDTH){1'b0}};\n"
1052
                        "\t\t\t\tib_b <= {(2*IWIDTH){1'b0}};\n"
1053
                        "\t\t\t\tib_sync <= 1'b0;\n"
1054
                "\t\t\tend\n"
1055 2 dgisselq
"\n"
1056
                "\t\t\t//\n"
1057
                "\t\t\t// Next step: recover the outputs from the butterfly\n"
1058
                "\t\t\t//\n"
1059 8 dgisselq
                "\t\t\tif ((ob_sync||b_started)&&(~oB[LGSPAN]))\n"
1060 2 dgisselq
                "\t\t\tbegin // A butterfly output is available\n"
1061
                        "\t\t\t\tb_started <= 1'b1;\n"
1062 8 dgisselq
                        "\t\t\t\tomem[oB[(LGSPAN-1):0]] <= ob_b;\n"
1063 2 dgisselq
                        "\t\t\t\toB <= oB+1;\n"
1064
"\n"
1065 6 dgisselq
                        "\t\t\t\to_sync <= (ob_sync);\n"
1066 2 dgisselq
                        "\t\t\t\to_data <= ob_a;\n"
1067
                "\t\t\tend else if (b_started)\n"
1068
                "\t\t\tbegin // and keep outputting once you start--at a rate\n"
1069
                "\t\t\t// of one guaranteed output per clock that has i_ce set.\n"
1070 8 dgisselq
                        "\t\t\t\to_data <= omem[oB[(LGSPAN-1):0]];\n"
1071 2 dgisselq
                        "\t\t\t\toB <= oB + 1;\n"
1072
                        "\t\t\t\to_sync <= 1'b0;\n"
1073
                "\t\t\tend else\n"
1074
                        "\t\t\t\to_sync <= 1'b0;\n"
1075
        "\t\tend\n"
1076 5 dgisselq
"\n", (inv)?"i":"");
1077
        fprintf(fstage,
1078 2 dgisselq
"\tbutterfly #(.IWIDTH(IWIDTH),.CWIDTH(CWIDTH),.OWIDTH(OWIDTH),\n"
1079 5 dgisselq
"\t\t\t.MPYDELAY(%d\'d%d),.LGDELAY(LGBDLY),.SHIFT(BFLYSHIFT))\n"
1080 8 dgisselq
"\t\tbfly(i_clk, i_rst, i_ce, ib_c,\n"
1081 2 dgisselq
"\t\t\tib_a, ib_b, ib_sync, ob_a, ob_b, ob_sync);\n"
1082
"endmodule;\n",
1083 14 dgisselq
        lgdelay(nbits, xtra), bflydelay(nbits, xtra));
1084 2 dgisselq
}
1085
 
1086
void    usage(void) {
1087
        fprintf(stderr,
1088
"USAGE:\tfftgen [-f <size>] [-d dir] [-c cbits] [-n nbits] [-m mxbits] [-s01]\n"
1089
// "\tfftgen -i\n"
1090
"\t-c <cbits>\tCauses all internal complex coefficients to be\n"
1091
"\t\tlonger than the corresponding data bits, to help avoid\n"
1092
"\t\tcoefficient truncation errors.\n"
1093
"\t-d <dir>\tPlaces all of the generated verilog files into <dir>.\n"
1094
"\t-f <size>\tSets the size of the FFT as the number of complex\n"
1095
"\t\tsamples input to the transform.\n"
1096
"\t-n <nbits>\tSets the number of bits in the twos complement input\n"
1097
"\t\tto the FFT routine.\n"
1098
"\t-m <mxbits>\tSets the maximum bit width that the FFT should ever\n"
1099
"\t\tproduce.  Internal values greater than this value will be\n"
1100
"\t\ttruncated to this value.\n"
1101
"\t-s\tSkip the final bit reversal stage.  This is useful in\n"
1102
"\t\talgorithms that need to apply a filter without needing to do\n"
1103
"\t\tbin shifting, as these algorithms can, with this option, just\n"
1104
"\t\tmultiply by a bit reversed correlation sequence and then\n"
1105
"\t\tinverse FFT the (still bit reversed) result.\n"
1106
"\t-S\tInclude the final bit reversal stage (default).\n"
1107
"\t-0\tA forward FFT (default), meaning that the coefficients are\n"
1108
"\t\tgiven by e^{-j 2 pi k/N n }.\n"
1109
"\t-1\tAn inverse FFT, meaning that the coefficients are\n"
1110
"\t\tgiven by e^{ j 2 pi k/N n }.\n");
1111
}
1112
 
1113
// Features still needed:
1114
//      Interactivity.
1115
//      Some number of maximum bits, beyond which we won't accumulate any more.
1116
//      Obviously, the build_stage above.
1117
//      Copying the files of interest into the fft-core directory, from
1118
//              whatever directory this file is run out of.
1119
int main(int argc, char **argv) {
1120
        int     fftsize = -1, lgsize = -1;
1121
        int     nbitsin = 16, xtracbits = 4;
1122
        int     nbitsout, maxbitsout = -1;
1123
        bool    bitreverse = true, inverse=false, interactive = false,
1124
                verbose_flag = false;
1125
        FILE    *vmain;
1126 14 dgisselq
        std::string     coredir = "fft-core", cmdline = "";
1127 2 dgisselq
 
1128
        if (argc <= 1)
1129
                usage();
1130
 
1131 14 dgisselq
        cmdline = argv[0];
1132 2 dgisselq
        for(int argn=1; argn<argc; argn++) {
1133 14 dgisselq
                cmdline += " ";
1134
                cmdline += argv[argn];
1135
        }
1136
 
1137
        for(int argn=1; argn<argc; argn++) {
1138 2 dgisselq
                if ('-' == argv[argn][0]) {
1139
                        for(int j=1; (argv[argn][j])&&(j<100); j++) {
1140
                                switch(argv[argn][j]) {
1141
                                        case '0':
1142
                                                inverse = false;
1143
                                                break;
1144
                                        case '1':
1145
                                                inverse = true;
1146
                                                break;
1147
                                        case 'c':
1148
                                                if (argn+1 >= argc) {
1149
                                                        printf("No extra number of coefficient bits given\n");
1150
                                                        usage(); exit(-1);
1151
                                                }
1152
                                                xtracbits = atoi(argv[++argn]);
1153
                                                j+= 200;
1154
                                                break;
1155
                                        case 'd':
1156
                                                if (argn+1 >= argc) {
1157
                                                        printf("No extra number of coefficient bits given\n");
1158
                                                        usage(); exit(-1);
1159
                                                }
1160 14 dgisselq
                                                coredir = argv[++argn];
1161 2 dgisselq
                                                j += 200;
1162
                                                break;
1163
                                        case 'f':
1164
                                                if (argn+1 >= argc) {
1165
                                                        printf("No FFT Size given\n");
1166
                                                        usage(); exit(-1);
1167
                                                }
1168
                                                fftsize = atoi(argv[++argn]);
1169
                                                { int sln = strlen(argv[argn]);
1170
                                                if (!isdigit(argv[argn][sln-1])){
1171
                                                        switch(argv[argn][sln-1]) {
1172
                                                        case 'k': case 'K':
1173
                                                                fftsize <<= 10;
1174
                                                                break;
1175
                                                        case 'm': case 'M':
1176
                                                                fftsize <<= 20;
1177
                                                                break;
1178
                                                        case 'g': case 'G':
1179
                                                                fftsize <<= 30;
1180
                                                                break;
1181
                                                        default:
1182
                                                                printf("Unknown FFT size, %s\n", argv[argn]);
1183
                                                                exit(-1);
1184
                                                        }
1185
                                                }}
1186
                                                j += 200;
1187
                                                break;
1188
                                        case 'h':
1189
                                                usage();
1190
                                                exit(0);
1191
                                                break;
1192
                                        case 'i':
1193
                                                interactive = true;
1194
                                                break;
1195
                                        case 'm':
1196
                                                if (argn+1 >= argc) {
1197
                                                        printf("No maximum output bit value given\n");
1198
                                                        exit(-1);
1199
                                                }
1200
                                                maxbitsout = atoi(argv[++argn]);
1201
                                                j += 200;
1202
                                                break;
1203
                                        case 'n':
1204
                                                if (argn+1 >= argc) {
1205
                                                        printf("No input bit size given\n");
1206
                                                        exit(-1);
1207
                                                }
1208
                                                nbitsin = atoi(argv[++argn]);
1209
                                                j += 200;
1210
                                                break;
1211
                                        case 'S':
1212
                                                bitreverse = true;
1213
                                                break;
1214
                                        case 's':
1215
                                                bitreverse = false;
1216
                                                break;
1217
                                        case 'v':
1218
                                                verbose_flag = true;
1219
                                                break;
1220
                                        default:
1221
                                                printf("Unknown argument, -%c\n", argv[argn][j]);
1222
                                                usage();
1223
                                                exit(-1);
1224
                                }
1225
                        }
1226
                } else {
1227
                        printf("Unrecognized argument, %s\n", argv[argn]);
1228
                        usage();
1229
                        exit(-1);
1230
                }
1231
        }
1232
 
1233
        if ((lgsize < 0)&&(fftsize > 1)) {
1234
                for(lgsize=1; (1<<lgsize) < fftsize; lgsize++)
1235
                        ;
1236
        }
1237
 
1238
        if ((fftsize <= 0)||(nbitsin < 1)||(nbitsin>48)) {
1239
                printf("INVALID PARAMETERS!!!!\n");
1240
                exit(-1);
1241
        }
1242
 
1243
 
1244
        if (nextlg(fftsize) != fftsize) {
1245
                fprintf(stderr, "ERR: FFTSize (%d) *must* be a power of two\n",
1246
                                fftsize);
1247
                exit(-1);
1248
        } else if (fftsize < 2) {
1249
                fprintf(stderr, "ERR: Minimum FFTSize is 2, not %d\n",
1250
                                fftsize);
1251
                if (fftsize == 1) {
1252
                        fprintf(stderr, "You do realize that a 1 point FFT makes very little sense\n");
1253
                        fprintf(stderr, "in an FFT operation that handles two samples per clock?\n");
1254
                        fprintf(stderr, "If you really need to do an FFT of this size, the output\n");
1255
                        fprintf(stderr, "can be connected straight to the input.\n");
1256
                } else {
1257
                        fprintf(stderr, "Indeed, a size of %d doesn\'t make much sense to me at all.\n", fftsize);
1258
                        fprintf(stderr, "Is such an operation even defined?\n");
1259
                }
1260
                exit(-1);
1261
        }
1262
 
1263
        // Calculate how many output bits we'll have, and what the log
1264
        // based two size of our FFT is.
1265
        {
1266
                int     tmp_size = fftsize;
1267
 
1268
                // The first stage always accumulates one bit, regardless
1269
                // of whether you need to or not.
1270
                nbitsout = nbitsin + 1;
1271
                tmp_size >>= 1;
1272
 
1273
                while(tmp_size > 4) {
1274
                        nbitsout += 1;
1275
                        tmp_size >>= 2;
1276
                }
1277
 
1278
                if (tmp_size > 1)
1279
                        nbitsout ++;
1280
 
1281
                if (fftsize <= 2)
1282
                        bitreverse = false;
1283
        } if ((maxbitsout > 0)&&(nbitsout > maxbitsout))
1284
                nbitsout = maxbitsout;
1285
 
1286
 
1287
        {
1288
                struct stat     sbuf;
1289 14 dgisselq
                if (lstat(coredir.c_str(), &sbuf)==0) {
1290 2 dgisselq
                        if (!S_ISDIR(sbuf.st_mode)) {
1291 14 dgisselq
                                fprintf(stderr, "\'%s\' already exists, and is not a directory!\n", coredir.c_str());
1292 2 dgisselq
                                fprintf(stderr, "I will stop now, lest I overwrite something you care about.\n");
1293
                                fprintf(stderr, "To try again, please remove this file.\n");
1294
                                exit(-1);
1295
                        }
1296
                } else
1297 14 dgisselq
                        mkdir(coredir.c_str(), 0755);
1298
                if (access(coredir.c_str(), X_OK|W_OK) != 0) {
1299
                        fprintf(stderr, "I have no access to the directory \'%s\'.\n", coredir.c_str());
1300 2 dgisselq
                        exit(-1);
1301
                }
1302
        }
1303
 
1304 14 dgisselq
        {
1305
                std::string     fname_string;
1306
 
1307
                fname_string = coredir;
1308
                fname_string += "/";
1309
                if (inverse) fname_string += "i";
1310
                fname_string += "fftmain.v";
1311
 
1312
                vmain = fopen(fname_string.c_str(), "w");
1313
                if (NULL == vmain) {
1314
                        fprintf(stderr, "Could not open \'%s\' for writing\n", fname_string.c_str());
1315
                        perror("Err from O/S:");
1316
                        exit(-1);
1317
                }
1318 2 dgisselq
        }
1319
 
1320
        fprintf(vmain, "/////////////////////////////////////////////////////////////////////////////\n");
1321
        fprintf(vmain, "//\n");
1322
        fprintf(vmain, "// Filename:    %sfftmain.v\n", (inverse)?"i":"");
1323
        fprintf(vmain, "//\n");
1324
        fprintf(vmain, "// Project:     %s\n", prjname);
1325
        fprintf(vmain, "//\n");
1326
        fprintf(vmain, "// Purpose:     This is the main module in the Doubletime FPGA FFT project.\n");
1327
        fprintf(vmain, "//              As such, all other modules are subordinate to this one.\n");
1328
        fprintf(vmain, "//              (I have been reading too much legalese this week ...)\n");
1329
        fprintf(vmain, "//              This module accomplish a fixed size Complex FFT on %d data\n", fftsize);
1330
        fprintf(vmain, "//              points.  The FFT is fully pipelined, and accepts as inputs\n");
1331
        fprintf(vmain, "//              two complex two\'s complement samples per clock.\n");
1332
        fprintf(vmain, "//\n");
1333
        fprintf(vmain, "// Parameters:\n");
1334
        fprintf(vmain, "//      i_clk\tThe clock.  All operations are synchronous with this clock.\n");
1335
        fprintf(vmain, "//\ti_rst\tSynchronous reset, active high.  Setting this line will\n");
1336
        fprintf(vmain, "//\t\t\tforce the reset of all of the internals to this routine.\n");
1337
        fprintf(vmain, "//\t\t\tFurther, following a reset, the o_sync line will go\n");
1338
        fprintf(vmain, "//\t\t\thigh the same time the first output sample is valid.\n");
1339
        fprintf(vmain, "//      i_ce\tA clock enable line.  If this line is set, this module\n");
1340
        fprintf(vmain, "//\t\t\twill accept two complex values as inputs, and produce\n");
1341
        fprintf(vmain, "//\t\t\ttwo (possibly empty) complex values as outputs.\n");
1342
        fprintf(vmain, "//\t\ti_left\tThe first of two complex input samples.  This value\n");
1343
        fprintf(vmain, "//\t\t\tis split into two two\'s complement numbers, of \n");
1344
        fprintf(vmain, "//\t\t\t%d bits each, with the real portion in the high\n", nbitsin);
1345
        fprintf(vmain, "//\t\t\torder bits, and the imaginary portion taking the\n");
1346
        fprintf(vmain, "//\t\t\tbottom %d bits.\n", nbitsin);
1347
        fprintf(vmain, "//\t\ti_right\tThis is the same thing as i_left, only this is the\n");
1348
        fprintf(vmain, "//\t\t\tsecond of two such samples.  Hence, i_left would\n");
1349
        fprintf(vmain, "//\t\t\tcontain input sample zero, i_right would contain\n");
1350
        fprintf(vmain, "//\t\t\tsample one.  On the next clock i_left would contain\n");
1351
        fprintf(vmain, "//\t\t\tinput sample two, i_right number three and so forth.\n");
1352
        fprintf(vmain, "//\t\to_left\tThe first of two output samples, of the same\n");
1353
        fprintf(vmain, "//\t\t\tformat as i_left, only having %d bits for each of\n", nbitsout);
1354
        fprintf(vmain, "//\t\t\tthe real and imaginary components, leading to %d\n", nbitsout*2);
1355
        fprintf(vmain, "//\t\t\tbits total.\n");
1356
        fprintf(vmain, "//\t\to_right\tThe second of two output samples produced each clock.\n");
1357
        fprintf(vmain, "//\t\t\tThis has the same format as o_left.\n");
1358
        fprintf(vmain, "//\t\to_sync\tA one bit output indicating the first valid sample\n");
1359
        fprintf(vmain, "//\t\t\tproduced by this FFT following a reset.  Ever after,\n");
1360
        fprintf(vmain, "//\t\t\tthis will indicate the first sample of an FFT frame.\n");
1361
        fprintf(vmain, "//\n");
1362 14 dgisselq
        fprintf(vmain, "// Arguments:\tThis file was computer generated using the\n");
1363
        fprintf(vmain, "//\t\tfollowing command line:\n");
1364
        fprintf(vmain, "//\n");
1365
        fprintf(vmain, "//\t\t%% %s\n", cmdline.c_str());
1366
        fprintf(vmain, "//\n");
1367 2 dgisselq
        fprintf(vmain, "%s", creator);
1368
        fprintf(vmain, "//\n");
1369
        fprintf(vmain, "%s", cpyleft);
1370
 
1371
 
1372
        fprintf(vmain, "//\n");
1373
        fprintf(vmain, "//\n");
1374
        fprintf(vmain, "module %sfftmain(i_clk, i_rst, i_ce,\n", (inverse)?"i":"");
1375
        fprintf(vmain, "\t\ti_left, i_right,\n");
1376
        fprintf(vmain, "\t\to_left, o_right, o_sync);\n");
1377
        fprintf(vmain, "\tparameter\tIWIDTH=%d, OWIDTH=%d, LGWIDTH=%d;\n", nbitsin, nbitsout, lgsize);
1378
        assert(lgsize > 0);
1379
        fprintf(vmain, "\tinput\t\ti_clk, i_rst, i_ce;\n");
1380
        fprintf(vmain, "\tinput\t\t[(2*IWIDTH-1):0]\ti_left, i_right;\n");
1381
        fprintf(vmain, "\toutput\treg\t[(2*OWIDTH-1):0]\to_left, o_right;\n");
1382
        fprintf(vmain, "\toutput\treg\t\t\to_sync;\n");
1383
        fprintf(vmain, "\n\n");
1384
 
1385
        fprintf(vmain, "\t// Outputs of the FFT, ready for bit reversal.\n");
1386
        fprintf(vmain, "\twire\t[(2*OWIDTH-1):0]\tbr_left, br_right;\n");
1387
        fprintf(vmain, "\n\n");
1388
 
1389
        int     tmp_size = fftsize, lgtmp = lgsize;
1390
        if (fftsize == 2) {
1391
                if (bitreverse) {
1392
                        fprintf(vmain, "\treg\tbr_start;\n");
1393
                        fprintf(vmain, "\talways @(posedge i_clk)\n");
1394
                        fprintf(vmain, "\t\tif (i_rst)\n");
1395
                        fprintf(vmain, "\t\t\tbr_start <= 1'b0;\n");
1396
                        fprintf(vmain, "\t\telse if (i_ce)\n");
1397
                        fprintf(vmain, "\t\t\tbr_start <= 1'b1;\n");
1398
                }
1399
                fprintf(vmain, "\n\n");
1400 6 dgisselq
                fprintf(vmain, "\tdblstage\t#(IWIDTH)\tstage_2(i_clk, i_rst, i_ce,\n");
1401
                fprintf(vmain, "\t\t\t(~i_rst), i_left, i_right, br_left, br_right);\n");
1402 2 dgisselq
                fprintf(vmain, "\n\n");
1403
        } else {
1404
                int     nbits = nbitsin, dropbit=0;
1405
                // Always do a first stage
1406
                fprintf(vmain, "\n\n");
1407
                fprintf(vmain, "\twire\t\tw_s%d, w_os%d;\n", fftsize, fftsize);
1408
                fprintf(vmain, "\twire\t[(2*IWIDTH+1):0]\tw_e%d, w_o%d;\n", fftsize, fftsize);
1409
                fprintf(vmain, "\t%sfftstage_e%d\t#(IWIDTH,IWIDTH+%d,IWIDTH+1,%d,%d,%d,0)\tstage_e%d(i_clk, i_rst, i_ce,\n",
1410
                        (inverse)?"i":"", fftsize,
1411
                        xtracbits,
1412
                        lgsize, lgtmp-2, lgdelay(nbits,xtracbits),
1413
                        fftsize);
1414
                fprintf(vmain, "\t\t\t(~i_rst), i_left, w_e%d, w_s%d);\n", fftsize, fftsize);
1415
                fprintf(vmain, "\t%sfftstage_o%d\t#(IWIDTH,IWIDTH+%d,IWIDTH+1,%d,%d,%d,0)\tstage_o%d(i_clk, i_rst, i_ce,\n",
1416
                        (inverse)?"i":"", fftsize,
1417
                        xtracbits,
1418
                        lgsize, lgtmp-2, lgdelay(nbits,xtracbits),
1419
                        fftsize);
1420 9 dgisselq
                fprintf(vmain, "\t\t\t(~i_rst), i_right, w_o%d, w_os%d);\n", fftsize, fftsize);
1421 2 dgisselq
                fprintf(vmain, "\n\n");
1422
 
1423 14 dgisselq
                {
1424
                        std::string     fname;
1425
                        char    numstr[12];
1426 2 dgisselq
 
1427 14 dgisselq
                        fname = coredir + "/";
1428
                        if (inverse) fname += "i";
1429
                        fname += "fftstage_e";
1430
                        sprintf(numstr, "%d", fftsize);
1431
                        fname += numstr;
1432
                        fname += ".v";
1433
                        build_stage(fname.c_str(), fftsize/2, 0, nbits, inverse, xtracbits);     // Even stage
1434
 
1435
                        fname = coredir + "/";
1436
                        if (inverse) fname += "i";
1437
                        fname += "fftstage_o";
1438
                        sprintf(numstr, "%d", fftsize);
1439
                        fname += numstr;
1440
                        fname += ".v";
1441
                        build_stage(fname.c_str(), fftsize/2, 1, nbits, inverse, xtracbits);    // Odd  stage
1442
                }
1443
 
1444 2 dgisselq
                nbits += 1;     // New number of input bits
1445
                tmp_size >>= 1; lgtmp--;
1446
                dropbit = 0;
1447
                fprintf(vmain, "\n\n");
1448
                while(tmp_size >= 8) {
1449
                        int     obits = nbits+((dropbit)?0:1);
1450
 
1451
                        if ((maxbitsout > 0)&&(obits > maxbitsout))
1452
                                obits = maxbitsout;
1453
 
1454
                        fprintf(vmain, "\twire\t\tw_s%d, w_os%d;\n", tmp_size, tmp_size);
1455
                        fprintf(vmain, "\twire\t[%d:0]\tw_e%d, w_o%d;\n", 2*obits-1, tmp_size, tmp_size);
1456
                        fprintf(vmain, "\t%sfftstage_e%d\t#(%d,%d,%d,%d,%d,%d,%d)\tstage_e%d(i_clk, i_rst, i_ce,\n",
1457
                                (inverse)?"i":"", tmp_size,
1458
                                nbits, nbits+xtracbits, obits,
1459 9 dgisselq
                                lgsize, lgtmp-2, lgdelay(nbits,xtracbits), (dropbit)?0:0,
1460 2 dgisselq
                                tmp_size);
1461
                        fprintf(vmain, "\t\t\t\t\t\tw_s%d, w_e%d, w_e%d, w_s%d);\n", tmp_size<<1, tmp_size<<1, tmp_size, tmp_size);
1462
                        fprintf(vmain, "\t%sfftstage_o%d\t#(%d,%d,%d,%d,%d,%d,%d)\tstage_o%d(i_clk, i_rst, i_ce,\n",
1463
                                (inverse)?"i":"", tmp_size,
1464
                                nbits, nbits+xtracbits, obits,
1465 9 dgisselq
                                lgsize, lgtmp-2, lgdelay(nbits,xtracbits), (dropbit)?0:0,
1466 2 dgisselq
                                tmp_size);
1467
                        fprintf(vmain, "\t\t\t\t\t\tw_s%d, w_o%d, w_o%d, w_os%d);\n", tmp_size<<1, tmp_size<<1, tmp_size, tmp_size);
1468
                        fprintf(vmain, "\n\n");
1469
 
1470 14 dgisselq
                        {
1471
                                std::string     fname;
1472
                                char            numstr[12];
1473 2 dgisselq
 
1474 14 dgisselq
                                fname = coredir + "/";
1475
                                if (inverse) fname += "i";
1476
                                fname += "fftstage_e";
1477
                                sprintf(numstr, "%d", tmp_size);
1478
                                fname += numstr;
1479
                                fname += ".v";
1480
                                build_stage(fname.c_str(), tmp_size/2, 0, nbits, inverse, xtracbits);    // Even stage
1481 2 dgisselq
 
1482 14 dgisselq
                                fname = coredir + "/";
1483
                                if (inverse) fname += "i";
1484
                                fname += "fftstage_o";
1485
                                sprintf(numstr, "%d", tmp_size);
1486
                                fname += numstr;
1487
                                fname += ".v";
1488
                                build_stage(fname.c_str(), tmp_size/2, 1, nbits, inverse, xtracbits);   // Odd  stage
1489
                        }
1490
 
1491
 
1492 2 dgisselq
                        dropbit ^= 1;
1493
                        nbits = obits;
1494
                        tmp_size >>= 1; lgtmp--;
1495
                }
1496
 
1497
                if (tmp_size == 4) {
1498
                        int     obits = nbits+((dropbit)?0:1);
1499
 
1500
                        if ((maxbitsout > 0)&&(obits > maxbitsout))
1501
                                obits = maxbitsout;
1502
 
1503
                        fprintf(vmain, "\twire\t\tw_s4, w_os4;\n");
1504
                        fprintf(vmain, "\twire\t[%d:0]\tw_e4, w_o4;\n", 2*obits-1);
1505
                        fprintf(vmain, "\tqtrstage\t#(%d,%d,%d,0,%d,%d)\tstage_e4(i_clk, i_rst, i_ce,\n",
1506 9 dgisselq
                                nbits, obits, lgsize, (inverse)?1:0, (dropbit)?0:0);
1507 6 dgisselq
                        fprintf(vmain, "\t\t\t\t\t\tw_s8, w_e8, w_e4, w_s4);\n");
1508 2 dgisselq
                        fprintf(vmain, "\tqtrstage\t#(%d,%d,%d,1,%d,%d)\tstage_o4(i_clk, i_rst, i_ce,\n",
1509 9 dgisselq
                                nbits, obits, lgsize, (inverse)?1:0, (dropbit)?0:0);
1510 6 dgisselq
                        fprintf(vmain, "\t\t\t\t\t\tw_s8, w_o8, w_o4, w_os4);\n");
1511 2 dgisselq
                        dropbit ^= 1;
1512
                        nbits = obits;
1513
                        tmp_size >>= 1; lgtmp--;
1514
                }
1515
 
1516
                {
1517
                        int obits = nbits+((dropbit)?0:1);
1518
                        if (obits > nbitsout)
1519
                                obits = nbitsout;
1520
                        if ((maxbitsout>0)&&(obits > maxbitsout))
1521
                                obits = maxbitsout;
1522
                        fprintf(vmain, "\twire\t\tw_s2;\n");
1523
                        fprintf(vmain, "\twire\t[%d:0]\tw_e2, w_o2;\n", 2*obits-1);
1524 9 dgisselq
                        fprintf(vmain, "\tdblstage\t#(%d,%d,%d)\tstage_2(i_clk, i_rst, i_ce,\n", nbits, obits,(dropbit)?0:1);
1525 6 dgisselq
                        fprintf(vmain, "\t\t\t\t\tw_s4, w_e4, w_o4, w_e2, w_o2, w_s2);\n");
1526 2 dgisselq
 
1527
                        fprintf(vmain, "\n\n");
1528
                        nbits = obits;
1529
                }
1530
 
1531
                fprintf(vmain, "\t// Prepare for a (potential) bit-reverse stage.\n");
1532
                fprintf(vmain, "\tassign\tbr_left  = w_e2;\n");
1533
                fprintf(vmain, "\tassign\tbr_right = w_o2;\n");
1534
                fprintf(vmain, "\n");
1535
                if (bitreverse) {
1536
                        fprintf(vmain, "\twire\tbr_start;\n");
1537
                        fprintf(vmain, "\treg\tr_br_started;\n");
1538
                        fprintf(vmain, "\t// A delay of one clock here is perfect, as it matches the delay in\n");
1539
                        fprintf(vmain, "\t// our dblstage.\n");
1540
                        fprintf(vmain, "\talways @(posedge i_clk)\n");
1541
                        fprintf(vmain, "\t\tif (i_rst)\n");
1542
                        fprintf(vmain, "\t\t\tr_br_started <= 1'b0;\n");
1543
                        fprintf(vmain, "\t\telse\n");
1544
                        fprintf(vmain, "\t\t\tr_br_started <= r_br_started || w_s4;\n");
1545
                        fprintf(vmain, "\tassign\tbr_start = r_br_started;\n");
1546
                }
1547
        }
1548
 
1549
        fprintf(vmain, "\n");
1550
        fprintf(vmain, "\t// Now for the bit-reversal stage.\n");
1551
        fprintf(vmain, "\twire\tbr_sync;\n");
1552
        fprintf(vmain, "\twire\t[(2*OWIDTH-1):0]\tbr_o_left, br_o_right;\n");
1553
        if (bitreverse) {
1554
                fprintf(vmain, "\tdblreverse\t#(%d,%d)\trevstage(i_clk, i_rst,\n", lgsize, nbitsout);
1555
                fprintf(vmain, "\t\t\t(i_ce & br_start), br_left, br_right,\n");
1556
                fprintf(vmain, "\t\t\tbr_o_left, br_o_right, br_sync);\n");
1557
        } else {
1558
                fprintf(vmain, "\tassign\tbr_o_left  = br_left;\n");
1559
                fprintf(vmain, "\tassign\tbr_o_right = br_right;\n");
1560
                fprintf(vmain, "\tassign\tbr_sync    = w_s2;\n");
1561
        }
1562
 
1563
        fprintf(vmain, "\n\n");
1564
        fprintf(vmain, "\t// Last clock: Register our outputs, we\'re done.\n");
1565
        fprintf(vmain, "\talways @(posedge i_clk)\n");
1566
        fprintf(vmain, "\t\tbegin\n");
1567
        fprintf(vmain, "\t\t\to_left  <= br_o_left;\n");
1568
        fprintf(vmain, "\t\t\to_right <= br_o_right;\n");
1569
        fprintf(vmain, "\t\t\to_sync  <= br_sync;\n");
1570
        fprintf(vmain, "\t\tend\n");
1571
        fprintf(vmain, "\n\n");
1572
        fprintf(vmain, "endmodule\n");
1573
        fclose(vmain);
1574
 
1575 14 dgisselq
        {
1576
                std::string     fname;
1577 2 dgisselq
 
1578 14 dgisselq
                fname = coredir + "/butterfly.v";
1579
                build_butterfly(fname.c_str(), xtracbits);
1580 2 dgisselq
 
1581 14 dgisselq
                fname = coredir + "/shiftaddmpy.v";
1582
                build_multiply(fname.c_str());
1583 2 dgisselq
 
1584 14 dgisselq
                fname = coredir + "/qtrstage.v";
1585
                build_quarters(fname.c_str());
1586 2 dgisselq
 
1587 14 dgisselq
                fname = coredir + "/dblstage.v";
1588
                build_dblstage(fname.c_str());
1589
 
1590
                if (bitreverse) {
1591
                        fname = coredir + "/dblreverse.v";
1592
                        build_dblreverse(fname.c_str());
1593
                }
1594 2 dgisselq
        }
1595
}
1596
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.