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

Subversion Repositories dblclockfft

[/] [dblclockfft/] [trunk/] [bench/] [cpp/] [bitreverse_tb.cpp] - Blame information for rev 41

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 41 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 36 dgisselq
//
3 41 dgisselq
// Filename:    bitreverse_tb.cpp
4 36 dgisselq
//
5
// Project:     A General Purpose Pipelined FFT Implementation
6
//
7
// Purpose:     A test-bench for the bitreversal stage of the pipelined
8
//              FFT.  This file may be run autonomously.  If so, the last line
9
//      output will either read "SUCCESS" on success, or some other failure
10
//      message otherwise.
11
//
12
//      This file depends upon verilator to both compile, run, and therefore
13
//      test either snglbrev.v or dblreverse.v--depending on whether or not the
14
//      FFT handles one or two inputs per clock respectively.
15
//
16
// Creator:     Dan Gisselquist, Ph.D.
17
//              Gisselquist Technology, LLC
18
//
19 41 dgisselq
////////////////////////////////////////////////////////////////////////////////
20 36 dgisselq
//
21
// Copyright (C) 2015,2018, Gisselquist Technology, LLC
22
//
23
// This program is free software (firmware): you can redistribute it and/or
24
// modify it under the terms of  the GNU General Public License as published
25
// by the Free Software Foundation, either version 3 of the License, or (at
26
// your option) any later version.
27
//
28
// This program is distributed in the hope that it will be useful, but WITHOUT
29
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
30
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
31
// for more details.
32
//
33
// You should have received a copy of the GNU General Public License along
34 41 dgisselq
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
35 36 dgisselq
// target there if the PDF file isn't present.)  If not, see
36
// <http://www.gnu.org/licenses/> for a copy.
37
//
38
// License:     GPL, v3, as defined and found on www.gnu.org,
39
//              http://www.gnu.org/licenses/gpl.html
40
//
41
//
42 41 dgisselq
////////////////////////////////////////////////////////////////////////////////
43 36 dgisselq
#include "verilated.h"
44
#include "verilated_vcd_c.h"
45
 
46
#include "fftsize.h"
47
#include "Vbitreverse.h"
48
 
49
#define FFTBITS TST_DBLREVERSE_LGSIZE
50
#define FFTSIZE (1<<(FFTBITS))
51
#define FFTMASK (FFTSIZE-1)
52
#define DATALEN (1<<(FFTBITS+1))
53
#define DATAMSK (DATALEN-1)
54
#define PAGEMSK (FFTSIZE)
55
 
56
#ifdef  NEW_VERILATOR
57
#define VVAR(A) bitreverse__DOT_ ## A
58
#else
59
#define VVAR(A) v__DOT_ ## A
60
#endif
61
 
62
typedef Vbitreverse     TSTCLASS;
63
 
64 41 dgisselq
#ifdef DBLCLKFFT
65
#define iaddr           VVAR(_iaddr)
66
#else
67 36 dgisselq
#define iaddr           VVAR(_wraddr)
68 41 dgisselq
#endif
69 36 dgisselq
#define in_reset        VVAR(_in_reset)
70
 
71
VerilatedVcdC   *trace = NULL;
72
uint64_t        m_tickcount = 0;
73
 
74
void    tick(TSTCLASS *brev) {
75
        m_tickcount++;
76
 
77
        brev->i_clk = 0;
78
        brev->eval();
79 41 dgisselq
        if (trace)      trace->dump((vluint64_t)(10ul*m_tickcount-2));
80 36 dgisselq
        brev->i_clk = 1;
81
        brev->eval();
82 41 dgisselq
        if (trace)      trace->dump((vluint64_t)(10ul*m_tickcount));
83 36 dgisselq
        brev->i_clk = 0;
84
        brev->eval();
85
        if (trace) {
86 41 dgisselq
                trace->dump((vluint64_t)(10ul*m_tickcount+5));
87 36 dgisselq
                trace->flush();
88
        }
89
 
90
        brev->i_ce = 0;
91
}
92
 
93
void    cetick(TSTCLASS *brev) {
94
        brev->i_ce = 1;
95
        tick(brev);
96
        if (rand()&1) {
97
                brev->i_ce = 1;
98
                tick(brev);
99
        }
100
}
101
 
102
void    reset(TSTCLASS *brev) {
103
        brev->i_ce  = 0;
104
        brev->i_reset = 1;
105
        tick(brev);
106
        brev->i_ce  = 0;
107
        brev->i_reset = 0;
108
        tick(brev);
109
}
110
 
111
unsigned long   bitrev(const int nbits, const unsigned long vl) {
112
        unsigned long   r = 0;
113
        unsigned long   val = vl;
114
 
115
        for(int k=0; k<nbits; k++) {
116
                r <<= 1;
117
                r |= (val & 1);
118
                val >>= 1;
119
        }
120
 
121
        return r;
122
}
123
 
124 41 dgisselq
#ifdef  DBLCLKFFT
125
#define BREVMASK        (FFTMASK>>1)
126
#define BREVBITS        (FFTBITS-1)
127
#else
128
#define BREVMASK        FFTMASK
129
#define BREVBITS        FFTBITS
130
#endif
131
 
132 36 dgisselq
int     main(int argc, char **argv, char **envp) {
133
        Verilated::commandArgs(argc, argv);
134
        Verilated::traceEverOn(true);
135
        TSTCLASS        *brev = new TSTCLASS;
136
        int syncd = 0;
137
        unsigned long   datastore[DATALEN], dataidx=0;
138
        const   int     BREV_OFFSET = 0;
139
 
140
        trace = new VerilatedVcdC;
141
        brev->trace(trace, 99);
142
        trace->open("bitreverse_tb.vcd");
143
 
144
        reset(brev);
145
 
146
        printf("FFTSIZE = %08x\n", FFTSIZE);
147
        printf("FFTMASK = %08x\n", FFTMASK);
148
        printf("DATALEN = %08x\n", DATALEN);
149
        printf("DATAMSK = %08x\n", DATAMSK);
150
 
151
        for(int k=0; k<4*(FFTSIZE); k++) {
152
                brev->i_ce = 1;
153
#ifdef  DBLCLKFFT
154
                brev->i_in_0 = 2*k;
155
                brev->i_in_1 = 2*k+1;
156
                datastore[(dataidx++)&(DATAMSK)] = brev->i_in_0;
157
                datastore[(dataidx++)&(DATAMSK)] = brev->i_in_1;
158
#else
159
                brev->i_in = k;
160
                datastore[(dataidx++)&(DATAMSK)] = brev->i_in;
161
#endif
162
                tick(brev);
163
 
164 41 dgisselq
#ifdef  DBLCLKFFT
165
                printf("k=%3d: IN = %6lx,%6lx OUT = %6lx,%6lx SYNC = %d\t(%2x) %d\n",
166
                        k, brev->i_in_0, brev->i_in_1,
167
                        brev->o_out_0, brev->o_out_1, brev->o_sync,
168
                        brev->iaddr, brev->in_reset);
169
#else
170 36 dgisselq
                printf("k=%3d: IN = %6lx, OUT = %6lx, SYNC = %d\t(%2x) %d\n",
171
                        k, brev->i_in, brev->o_out, brev->o_sync,
172
                        brev->iaddr, brev->in_reset);
173 41 dgisselq
#endif
174 36 dgisselq
 
175 41 dgisselq
                if ((k>BREV_OFFSET)&&((BREV_OFFSET==(k&BREVMASK))?1:0) != brev->o_sync) {
176 36 dgisselq
                        fprintf(stdout, "FAIL, BAD SYNC (k = %d > %d)\n", k, BREV_OFFSET);
177
                        exit(EXIT_FAILURE);
178
                } else if (brev->o_sync) {
179
                        syncd = 1;
180
                }
181 41 dgisselq
#ifdef  DBLCLKFFT
182
                if ((syncd)&&((brev->o_out_0&BREVMASK) != bitrev(FFTBITS, k+1-BREV_OFFSET))) {
183
                        fprintf(stdout, "FAIL: BITREV.0 of k (%2x) = %2lx, not %2lx\n",
184
                                k, brev->o_out_0, bitrev(FFTBITS, (k+1-BREV_OFFSET)));
185
                        // exit(EXIT_FAILURE);
186
                }
187
#else
188 36 dgisselq
                if ((syncd)&&((brev->o_out&FFTMASK) != bitrev(FFTBITS, k-BREV_OFFSET))) {
189
                        fprintf(stdout, "FAIL: BITREV.0 of k (%2x) = %2lx, not %2lx\n",
190
                                k, brev->o_out, bitrev(FFTBITS, (k-BREV_OFFSET)));
191
                        exit(EXIT_FAILURE);
192
                }
193 41 dgisselq
#endif
194 36 dgisselq
        }
195
 
196
        for(int k=0; k<4*(FFTSIZE); k++) {
197
                brev->i_ce = 1;
198
#ifdef  DBLCLKFFT
199
                brev->i_in_0 = rand() & 0x0ffffff;
200
                brev->i_in_1 = rand() & 0x0ffffff;
201
                datastore[(dataidx++)&(DATAMSK)] = brev->i_in_0;
202
                datastore[(dataidx++)&(DATAMSK)] = brev->i_in_1;
203
#else
204
                brev->i_in = rand() & 0x0ffffff;
205
                datastore[(dataidx++)&(DATAMSK)] = brev->i_in;
206
#endif
207
                tick(brev);
208
 
209
#ifdef  DBLCLKFFT
210
                printf("k=%3d: IN = %6lx : %6lx, OUT = %6lx : %6lx, SYNC = %d\n",
211
                        k, brev->i_in_0, brev->i_in_1,
212
                        brev->o_out_0, brev->o_out_1, brev->o_sync);
213
#else
214
                printf("k=%3d: IN = %6lx, OUT = %6lx, SYNC = %d\n",
215
                        k, brev->i_in, brev->o_out, brev->o_sync);
216
#endif
217
 
218
                if (brev->o_sync)
219
                        syncd = 1;
220
#ifdef  DBLCLKFFT
221
                if ((syncd)&&(brev->o_out_0 != datastore[(((dataidx-2-FFTSIZE)&PAGEMSK) + bitrev(FFTBITS, (dataidx-FFTSIZE-2)&FFTMASK))])) {
222
                        fprintf(stdout, "FAIL: BITREV.0 of k (%2x) = %2lx, not %2lx (expected %lx -> %lx)\n",
223
                                k, brev->o_out_0,
224
                                datastore[(((dataidx-2-FFTSIZE)&PAGEMSK)
225
                                        + bitrev(FFTBITS, (dataidx-FFTSIZE-2)&FFTMASK))],
226
                                (dataidx-2)&DATAMSK,
227
                                (((dataidx-2)&PAGEMSK)
228
                                        + bitrev(FFTBITS, (dataidx-FFTSIZE-2)&FFTMASK)));
229
                        // exit(-1);
230
                }
231
 
232
                if ((syncd)&&(brev->o_out_1 != datastore[(((dataidx-2-FFTSIZE)&PAGEMSK) + bitrev(FFTBITS, (dataidx-FFTSIZE-1)&FFTMASK))])) {
233
                        fprintf(stdout, "FAIL: BITREV.1 of k (%2x) = %2lx, not %2lx (expected %lx)\n",
234
                                k, brev->o_out_1,
235
                                datastore[(((dataidx-2-FFTSIZE)&PAGEMSK)
236
                                        + bitrev(FFTBITS, (dataidx-FFTSIZE-1)&FFTMASK))],
237
                                (((dataidx-1)&PAGEMSK)
238
                                        + bitrev(FFTBITS, (dataidx-FFTSIZE-1)&FFTMASK)));
239
                        // exit(-1);
240
                }
241
#else
242
                if ((syncd)&&(brev->o_out != datastore[
243
                                (((dataidx-1-FFTSIZE)&PAGEMSK)
244
                                + bitrev(FFTBITS,
245
                                        (dataidx-FFTSIZE-1)&FFTMASK))])) {
246
                        fprintf(stdout, "FAIL: BITREV.0 of k (%2x) = %2lx, not %2lx (expected %lx -> %lx)\n",
247
                                k, brev->o_out,
248
                                datastore[(((dataidx-1-FFTSIZE)&PAGEMSK)
249
                                        + bitrev(FFTBITS, (dataidx-FFTSIZE-1)&FFTMASK))],
250
                                (dataidx-2)&DATAMSK,
251
                                (((dataidx-2)&PAGEMSK)
252
                                        + bitrev(FFTBITS, (dataidx-FFTSIZE-1)&FFTMASK)));
253
                        exit(EXIT_FAILURE);
254
                }
255
#endif
256
        }
257
 
258
        delete  brev;
259
 
260
        printf("SUCCESS!\n");
261
        exit(0);
262
}

powered by: WebSVN 2.1.0

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