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

Subversion Repositories dblclockfft

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /dblclockfft/trunk/bench/cpp
    from Rev 4 to Rev 5
    Reverse comparison

Rev 4 → Rev 5

/butterfly_tb.cpp
4,81 → 4,256
#include "Vbutterfly.h"
#include "verilated.h"
 
void tick(Vbutterfly *bfly) {
bfly->i_clk = 0;
bfly->eval();
bfly->i_clk = 1;
bfly->eval();
}
class BFLY_TB {
public:
Vbutterfly *m_bfly;
unsigned long m_left[64], m_right[64];
int m_addr, m_lastaux;
 
void reset(Vbutterfly *bfly) {
bfly->i_ce = 0;
bfly->i_rst = 1;
tick(bfly);
bfly->i_ce = 0;
bfly->i_rst = 0;
tick(bfly);
}
BFLY_TB(void) {
m_bfly = new Vbutterfly;
m_addr = 0;
}
 
void tick(void) {
m_lastaux = m_bfly->o_aux;
m_bfly->i_clk = 0;
m_bfly->eval();
m_bfly->i_clk = 1;
m_bfly->eval();
}
 
void reset(void) {
m_bfly->i_ce = 0;
m_bfly->i_aux = 1;
m_bfly->i_coef = 0l;
m_bfly->i_left = 0;
m_bfly->i_right = 0;
tick();
m_bfly->i_ce = 1;
m_bfly->i_aux = 1;
 
for(int i=0; i<40; i++)
tick();
m_bfly->i_aux = 0;
tick();
}
 
void test(const int n, const int k, const unsigned long cof,
const unsigned lft, const unsigned rht, const int aux) {
 
m_bfly->i_coef = cof & (~(-1l << 40));
m_bfly->i_left = lft;
m_bfly->i_right = rht;
m_bfly->i_aux = aux & 1;
 
tick();
 
if ((m_bfly->o_aux)&&(!m_lastaux))
printf("\n");
printf("n,k=%d,%3d: COEF=%010lx, LFT=%08x, RHT=%08x, A=%d, OLFT =%09lx, ORHT=%09lx, AUX=%d\n",
n,k,
m_bfly->i_coef & (~(-1l<<40)),
m_bfly->i_left,
m_bfly->i_right,
m_bfly->i_aux,
m_bfly->o_left,
m_bfly->o_right,
m_bfly->o_aux);
/*
printf("\tFI=%010lx",
((((long)m_bfly->v__DOT__r_aux_2)&1l)<<34)
|((((long)m_bfly->v__DOT__r_sum_r)&0x01ffffl)<<17)
|(((long)m_bfly->v__DOT__r_sum_i)&0x01ffffl));
printf("\tFO=%010lx SUMR=%05x SUMI=%05x A=%d",
m_bfly->v__DOT__fifo_read,
m_bfly->v__DOT__r_sum_r,
m_bfly->v__DOT__r_sum_i,
m_bfly->v__DOT__r_aux_2);
printf("\tML=%09lx, MR=%09lx, ",
m_left[ (m_addr-23)&(64-1)],
m_right[(m_addr-23)&(64-1)]);
*/
/*
printf("\tBLFTR=%10lx BLFTI=%10lx",
m_bfly->v__DOT__b_left_r & (~(-1l<<40)),
m_bfly->v__DOT__b_left_i & (~(-1l<<40)));
printf("\tMPYR=%10lx MPYI=%10lx",
m_bfly->v__DOT__mpy_r & (~(-1l<<40)),
m_bfly->v__DOT__mpy_i & (~(-1l<<40)));
printf("\n");
*/
 
if (m_left[(m_addr-23)&(64-1)] != m_bfly->o_left) {
fprintf(stderr, "WRONG O_LEFT!\n");
exit(-1);
}
 
if (m_right[(m_addr-23)&(64-1)] != m_bfly->o_right) {
fprintf(stderr, "WRONG O_RIGHT!\n");
exit(-1);
}
 
// Now, let's calculate an "expected" result ...
long rlft, ilft;
 
// Extract left and right values ...
rlft = (m_bfly->i_left >> 16) & 0x0ffff;
ilft = (m_bfly->i_left ) & 0x0ffff;
// Make certain they are properly sign extended ...
if (rlft & 0x8000) rlft |= (-1<<16);
if (ilft & 0x8000) ilft |= (-1<<16);
 
// Now repeat for the right hand value ...
long rrht, irht;
// Extract left and right values ...
rrht = (m_bfly->i_right >> 16) & 0x0ffff;
irht = (m_bfly->i_right ) & 0x0ffff;
// Make certain they are properly sign extended ...
if (rrht & 0x8000) rrht |= (-1<<16);
if (irht & 0x8000) irht |= (-1<<16);
 
 
// and again for the coefficients
long rcof, icof;
// Extract left and right values ...
rcof = (m_bfly->i_coef >> 20) & 0x0fffff;
icof = (m_bfly->i_coef ) & 0x0fffff;
// Make certain they are properly sign extended ...
if (rcof & 0x80000) rcof |= (-1<<20);
if (icof & 0x80000) icof |= (-1<<20);
 
 
// Now, let's do the butterfly ourselves ...
long sumi, sumr, difi, difr;
sumr = rlft + rrht;
sumi = ilft + irht;
difr = rlft - rrht;
difi = ilft - irht;
 
/*
printf("L=%5lx+%5lx,R=%5lx+%5lx,S=%5lx+%5lx,D=%5lx+%5lx, ",
rlft & 0x02ffffl,
ilft & 0x02ffffl,
rrht & 0x02ffffl,
irht & 0x02ffffl,
sumr & 0x02ffffl,
sumi & 0x02ffffl,
difr & 0x02ffffl,
difi & 0x02ffffl);
*/
long p1, p2, p3, mpyr, mpyi;
p1 = difr * rcof;
p2 = difi * icof;
p3 = (difr + difi) * (rcof + icof);
 
mpyr = p1-p2;
mpyi = p3-p1-p2;
 
/*
printf("RC=%lx, IC=%lx, ", rcof, icof);
printf("P1=%lx,P2=%lx,P3=%lx, ", p1,p2,p3);
printf("MPYr = %lx, ", mpyr);
printf("MPYi = %lx, ", mpyi);
*/
 
long o_left_r, o_left_i, o_right_r, o_right_i;
unsigned long o_left, o_right;
 
o_left_r = sumr & 0x01ffff; o_left_i = sumi & 0x01ffff;
o_left = (o_left_r << 17) | (o_left_i);
 
o_right_r = (mpyr>>18) & 0x01ffff;
o_right_i = (mpyi>>18) & 0x01ffff;
o_right = (o_right_r << 17) | (o_right_i);
/*
printf("oR_r = %lx, ", o_right_r);
printf("oR_i = %lx\n", o_right_i);
*/
 
m_left[ m_addr&(64-1)] = o_left;
m_right[m_addr&(64-1)] = o_right;
 
m_addr++;
}
};
 
int main(int argc, char **argv, char **envp) {
Verilated::commandArgs(argc, argv);
Vbutterfly *bfly = new Vbutterfly;
BFLY_TB *bfly = new BFLY_TB;
int16_t ir0, ii0, lstr, lsti;
int32_t sumr, sumi, difr, difi;
int32_t smr, smi, dfr, dfi;
int rnd = 0;
 
reset(bfly);
const int TESTSZ = 256;
 
for(int k=0; k<270; k++) {
int32_t or0, oi0, or1, oi1;
bfly->reset();
 
bfly->i_ce = 1;
bfly->i_sync = ((k&0x0ff)==0);
// Let's pick some random values, ...
ir0 = rand(); if (ir0&4) ir0 = -ir0;
ii0 = rand(); if (ii0&2) ii0 = -ii0;
bfly->test(9,0,0x4000000000l,0x7fff0000,0x7fff0000, 1);
bfly->test(9,1,0x4000000000l,0x7fff0000,0x80010000, 0);
bfly->test(9,2,0x4000000000l,0x00007fff,0x00008001, 0);
bfly->test(9,3,0x4000000000l,0x00007fff,0x00007fff, 0);
 
bfly->i_data = ((ir0&0x0ffff) << 16) | (ii0 & 0x0ffff);
tick(bfly);
bfly->test(8,0,0x4000000000l,0x80010000,0x80010000, 1);
bfly->test(8,1,0x4000000000l,0x00008001,0x00008001, 0);
 
printf("k=%3d: COEF=%08x, LFT=%08x, RHT=%08x, AUX=%d, OLFT =%09lx, ORHT=%09lx, AUX=%d\n",
k, bfly->i_coef, bfly->i_left, bfly->i_right, bfly->i_aux,
bfly->o_left, bfly->o_right, bfly->o_sync);
bfly->test(9,0,0x4000000000l,0x40000000,0xc0000000, 1);
bfly->test(9,1,0x4000000000l,0x40000000,0x40000000, 0);
bfly->test(9,2,0x4000000000l,0x00004000,0x0000c000, 0);
bfly->test(9,3,0x4000000000l,0x00004000,0x00004000, 0);
 
or0 = (bfly->o_data >> 17) & 0x01ffff;
oi0 = bfly->o_data & 0x01ffff;
if (or0 & 0x010000) or0 |= (-1<<16);
if (oi0 & 0x010000) oi0 |= (-1<<16);
bfly->test(9,0,0x4000000000l,0x20000000,0xe0000000, 1);
bfly->test(9,1,0x4000000000l,0x20000000,0x20000000, 0);
bfly->test(9,2,0x4000000000l,0x00002000,0x0000e000, 0);
bfly->test(9,3,0x4000000000l,0x00002000,0x00002000, 0);
 
if (k>3) {
/*
printf("\tOR0 = %6x, OI0 = %6x, SUM = %6x + %6x, DIF = %6x + %6x\n",
or0, oi0, sumr, sumi, difr, difi);
*/
if (0==(k&1)) {
if (or0 != sumr) {fprintf(stderr, "FAIL 1\n"); exit(-1);}
if (oi0 != sumi) {fprintf(stderr, "FAIL 2\n"); exit(-1);}
} else if (1==(k&1)) {
if (or0 != difr) {fprintf(stderr, "FAIL 3\n"); exit(-1);}
if (oi0 != difi) {fprintf(stderr, "FAIL 4\n"); exit(-1);}
}
}
bfly->test(9,0,0x4000000000l,0x00080000,0xfff80000, 1);
bfly->test(9,1,0x4000000000l,0x00080000,0x00080000, 0);
bfly->test(9,2,0x4000000000l,0x00000008,0x0000fff8, 0);
bfly->test(9,3,0x4000000000l,0x00000008,0x00000008, 0);
 
if (((4==(k&0x0ff))?1:0) != bfly->o_sync) { fprintf(stderr, "BAD O-SYNC\n"); exit(-1); }
bfly->test(9,0,0x4000000000l,0x00010000,0xffff0000, 1);
bfly->test(9,1,0x4000000000l,0x00010000,0x00010000, 0);
bfly->test(9,2,0x4000000000l,0x00000001,0x0000ffff, 0);
bfly->test(9,3,0x4000000000l,0x00000001,0x00000001, 0);
 
if (1 == (k&1)) {
sumr = smr; sumi = smi; difr=dfr, difi= dfi;
for(int n=0; n<4; n++) for(int k=0; k<TESTSZ; k++) {
long iv, rv;
unsigned long lft, rht, cof;
double c, s, W;
bool inv = 1;
int aux;
 
smr = lstr + ir0 + rnd;
smi = lsti + ii0 + rnd;
W = ((inv)?-1:1) * 2.0 * M_PI * (2*k) / TESTSZ * 64;
c = cos(W); s = sin(W);
rv = (long)((double)(1l<<(16-2-n))*c+0.5);
iv = (long)((double)(1l<<(16-2-n))*s+0.5);
 
dfr = lstr - ir0 + rnd;
dfi = lsti - ii0 + rnd;
}
rv = (rv << 16) | (iv & (~(-1<<16)));
lft = rv;
 
lstr = ir0;
lsti = ii0;
W = ((inv)?-1:1) * 2.0 * M_PI * (2*k+1) / TESTSZ * 64;
c = cos(W); s = sin(W);
rv = (long)((double)(1l<<(16-2-n))*c+0.5);
iv = (long)((double)(1l<<(16-2-n))*s+0.5);
 
rv = (rv << 16) | (iv & (~(-1<<16)));
rht = rv;
 
 
// Switch the sign of W
W = ((inv)?1:-1) * 2.0 * M_PI * (2*k) / TESTSZ;
c = cos(W); s = sin(W);
rv = (long)((double)(1l<<(20-2))*c+0.5); // Keep 20-2 bits for
iv = (long)((double)(1l<<(20-2))*s+0.5); // coefficients
 
rv = (rv << 20) | (iv & (~(-1<<20)));
cof = rv;
 
aux = ((k&(TESTSZ-1))==0);
 
bfly->test(n,k, cof, lft, rht, aux);
}
 
delete bfly;
/Makefile
1,4 → 1,4
all: mpy_tb dblrev_tb dblstage_tb qtrstage_tb
all: mpy_tb dblrev_tb dblstage_tb qtrstage_tb test
 
OBJDR:= ../../sw/fft-core/obj_dir
VINC := -I/usr/share/verilator/include -I$(OBJDR)/
6,6 → 6,7
DBLRV:= $(OBJDR)/Vdblreverse__ALL.a
DBLSG:= $(OBJDR)/Vdblstage__ALL.a
QTRSG:= $(OBJDR)/Vqtrstage__ALL.a
BFLYL:= $(OBJDR)/Vbutterfly__ALL.a
VERILATOR_ROOT := /usr/share/verilator
 
mpy_tb: mpy_tb.cpp $(MPYLB)
20,6 → 21,18
qtrstage_tb: qtrstage_tb.cpp $(QTRSG)
g++ -g $(VINC) $< $(QTRSG) $(VERILATOR_ROOT)/include/verilated.cpp -o $@
 
butterfly_tb: butterfly_tb.cpp $(BFLYL)
g++ -g $(VINC) $< $(BFLYL) $(VERILATOR_ROOT)/include/verilated.cpp -o $@
 
.PHONY: test
test: mpy_tb dblrev_tb dblstage_tb qtrstage_tb butterfly_tb
./mpy_tb
./dblrev_tb
./dblstage_tb
./qtrstage_tb
./butterfly_tb
 
.PHONY: clean
clean:
rm mpy_tb dblrev_tb dblstage_tb qtrstage_tb
 

powered by: WebSVN 2.1.0

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