Line 40... |
Line 40... |
//
|
//
|
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <stdint.h>
|
#include <stdint.h>
|
|
|
|
#include "fftsize.h"
|
#include "Vbutterfly.h"
|
#include "Vbutterfly.h"
|
#include "verilated.h"
|
#include "verilated.h"
|
#include "twoc.h"
|
#include "twoc.h"
|
|
|
|
#define IWIDTH TST_BUTTERFLY_IWIDTH
|
|
#define CWIDTH TST_BUTTERFLY_CWIDTH
|
|
#define OWIDTH TST_BUTTERFLY_OWIDTH
|
|
#define BFLYDELAY TST_BUTTERFLY_MPYDELAY
|
|
|
class BFLY_TB {
|
class BFLY_TB {
|
public:
|
public:
|
Vbutterfly *m_bfly;
|
Vbutterfly *m_bfly;
|
unsigned long m_left[64], m_right[64];
|
unsigned long m_left[64], m_right[64];
|
Line 107... |
Line 112... |
}
|
}
|
|
|
void test(const int n, const int k, const unsigned long cof,
|
void test(const int n, const int k, const unsigned long cof,
|
const unsigned lft, const unsigned rht, const int aux) {
|
const unsigned lft, const unsigned rht, const int aux) {
|
|
|
m_bfly->i_coef = cof & (~(-1l << 40));
|
m_bfly->i_coef = ubits(cof, 2*TST_BUTTERFLY_CWIDTH);
|
m_bfly->i_left = lft;
|
m_bfly->i_left = ubits(lft, 2*TST_BUTTERFLY_IWIDTH);
|
m_bfly->i_right = rht;
|
m_bfly->i_right = ubits(rht, 2*TST_BUTTERFLY_IWIDTH);
|
m_bfly->i_aux = aux & 1;
|
m_bfly->i_aux = aux & 1;
|
if ((m_waiting_for_sync_input)&&(aux&1)) {
|
if ((m_waiting_for_sync_input)&&(aux&1)) {
|
m_waiting_for_sync_input = false;
|
m_waiting_for_sync_input = false;
|
m_addr = 0;
|
m_addr = 0;
|
}
|
}
|
Line 155... |
Line 160... |
m_bfly->v__DOT__mpy_i & (~(-1l<<40)));
|
m_bfly->v__DOT__mpy_i & (~(-1l<<40)));
|
printf("\n");
|
printf("\n");
|
*/
|
*/
|
|
|
if ((m_syncd)&&(m_left[(m_addr-m_offset)&(64-1)] != m_bfly->o_left)) {
|
if ((m_syncd)&&(m_left[(m_addr-m_offset)&(64-1)] != m_bfly->o_left)) {
|
fprintf(stderr, "WRONG O_LEFT! (%lx(exp) != %lx(sut))\n",
|
printf("WRONG O_LEFT! (%lx(exp) != %lx(sut))\n",
|
m_left[(m_addr-m_offset)&(64-1)],
|
m_left[(m_addr-m_offset)&(64-1)],
|
m_bfly->o_left);
|
m_bfly->o_left);
|
exit(-1);
|
exit(-1);
|
}
|
}
|
|
|
if ((m_syncd)&&(m_right[(m_addr-m_offset)&(64-1)] != m_bfly->o_right)) {
|
if ((m_syncd)&&(m_right[(m_addr-m_offset)&(64-1)] != m_bfly->o_right)) {
|
fprintf(stderr, "WRONG O_RIGHT (%lx(exp) != (%lx(sut))!\n",
|
printf("WRONG O_RIGHT (%10lx(exp) != (%10lx(sut))!\n",
|
m_right[(m_addr-m_offset)&(64-1)], m_bfly->o_right);
|
m_right[(m_addr-m_offset)&(64-1)], m_bfly->o_right);
|
exit(-1);
|
exit(-1);
|
}
|
}
|
|
|
if ((m_syncd)&&(m_aux[(m_addr-m_offset)&(64-1)] != m_bfly->o_aux)) {
|
if ((m_syncd)&&(m_aux[(m_addr-m_offset)&(64-1)] != m_bfly->o_aux)) {
|
fprintf(stderr, "FAILED AUX CHANNEL TEST (i.e. the SYNC)\n");
|
printf("FAILED AUX CHANNEL TEST (i.e. the SYNC)\n");
|
exit(-1);
|
exit(-1);
|
}
|
}
|
|
|
if ((m_addr > 28)&&(!m_syncd)) {
|
if ((m_addr > TST_BUTTERFLY_MPYDELAY+6)&&(!m_syncd)) {
|
fprintf(stderr, "NO SYNC PULSE!\n");
|
printf("NO SYNC PULSE!\n");
|
exit(-1);
|
// exit(-1);
|
}
|
}
|
|
|
// Now, let's calculate an "expected" result ...
|
// Now, let's calculate an "expected" result ...
|
long rlft, ilft;
|
long rlft, ilft;
|
|
|
// Extract left and right values ...
|
// Extract left and right values ...
|
rlft = sbits(m_bfly->i_left >> 16, 16);
|
rlft = sbits(m_bfly->i_left >> IWIDTH, IWIDTH);
|
ilft = sbits(m_bfly->i_left , 16);
|
ilft = sbits(m_bfly->i_left , IWIDTH);
|
|
|
// Now repeat for the right hand value ...
|
// Now repeat for the right hand value ...
|
long rrht, irht;
|
long rrht, irht;
|
// Extract left and right values ...
|
// Extract left and right values ...
|
rrht = sbits(m_bfly->i_right >> 16, 16);
|
rrht = sbits(m_bfly->i_right >> IWIDTH, IWIDTH);
|
irht = sbits(m_bfly->i_right , 16);
|
irht = sbits(m_bfly->i_right , IWIDTH);
|
|
|
// and again for the coefficients
|
// and again for the coefficients
|
long rcof, icof;
|
long rcof, icof;
|
// Extract left and right values ...
|
// Extract left and right values ...
|
rcof = sbits(m_bfly->i_coef >> 20, 20);
|
rcof = sbits(m_bfly->i_coef >> CWIDTH, CWIDTH);
|
icof = sbits(m_bfly->i_coef , 20);
|
icof = sbits(m_bfly->i_coef , CWIDTH);
|
|
|
// Now, let's do the butterfly ourselves ...
|
// Now, let's do the butterfly ourselves ...
|
long sumi, sumr, difi, difr;
|
long sumi, sumr, difi, difr;
|
sumr = rlft + rrht;
|
sumr = rlft + rrht;
|
sumi = ilft + irht;
|
sumi = ilft + irht;
|
Line 219... |
Line 224... |
long p1, p2, p3, mpyr, mpyi;
|
long p1, p2, p3, mpyr, mpyi;
|
p1 = difr * rcof;
|
p1 = difr * rcof;
|
p2 = difi * icof;
|
p2 = difi * icof;
|
p3 = (difr + difi) * (rcof + icof);
|
p3 = (difr + difi) * (rcof + icof);
|
|
|
mpyr = p1-p2 + (1<<17);
|
mpyr = p1-p2;
|
mpyi = p3-p1-p2 + (1<<17);
|
mpyi = p3-p1-p2;
|
|
|
|
mpyr = rndbits(mpyr, (IWIDTH+2)+(CWIDTH+1), OWIDTH+4);
|
|
mpyi = rndbits(mpyi, (IWIDTH+2)+(CWIDTH+1), OWIDTH+4);
|
|
|
/*
|
/*
|
printf("RC=%lx, IC=%lx, ", rcof, icof);
|
printf("RC=%lx, IC=%lx, ", rcof, icof);
|
printf("P1=%lx,P2=%lx,P3=%lx, ", p1,p2,p3);
|
printf("P1=%lx,P2=%lx,P3=%lx, ", p1,p2,p3);
|
printf("MPYr = %lx, ", mpyr);
|
printf("MPYr = %lx, ", mpyr);
|
Line 232... |
Line 240... |
*/
|
*/
|
|
|
long o_left_r, o_left_i, o_right_r, o_right_i;
|
long o_left_r, o_left_i, o_right_r, o_right_i;
|
unsigned long o_left, o_right;
|
unsigned long o_left, o_right;
|
|
|
o_left_r = sumr & 0x01ffff; o_left_i = sumi & 0x01ffff;
|
o_left_r = rndbits(sumr<<(CWIDTH-2), CWIDTH+IWIDTH+3, OWIDTH+4);
|
o_left = (o_left_r << 17) | (o_left_i);
|
o_left_r = ubits(o_left_r, OWIDTH);
|
|
o_left_i = rndbits(sumi<<(CWIDTH-2), CWIDTH+IWIDTH+3, OWIDTH+4);
|
o_right_r = (mpyr>>18) & 0x01ffff;
|
o_left_i = ubits(o_left_i, OWIDTH);
|
o_right_i = (mpyi>>18) & 0x01ffff;
|
o_left = (o_left_r << OWIDTH) | (o_left_i);
|
o_right = (o_right_r << 17) | (o_right_i);
|
|
|
o_right_r = ubits(mpyr, OWIDTH);
|
|
o_right_i = ubits(mpyi, OWIDTH);
|
|
o_right = (o_right_r << OWIDTH) | (o_right_i);
|
/*
|
/*
|
printf("oR_r = %lx, ", o_right_r);
|
printf("oR_r = %lx, ", o_right_r);
|
printf("oR_i = %lx\n", o_right_i);
|
printf("oR_i = %lx\n", o_right_i);
|
*/
|
*/
|
|
|