Line 43... |
Line 43... |
#include <stdint.h>
|
#include <stdint.h>
|
|
|
#include "Vbutterfly.h"
|
#include "Vbutterfly.h"
|
#include "verilated.h"
|
#include "verilated.h"
|
|
|
|
long sbits(const long val, const int bits) {
|
|
long r;
|
|
|
|
r = val & ((1l<<bits)-1);
|
|
if (r & (1l << (bits-1)))
|
|
r |= (-1l << bits);
|
|
return r;
|
|
}
|
|
|
|
unsigned long ubits(const long val, const int bits) {
|
|
long r;
|
|
|
|
r = val & ((1l<<bits)-1);
|
|
return r;
|
|
}
|
|
|
|
|
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];
|
bool m_aux[64];
|
bool m_aux[64];
|
Line 144... |
Line 161... |
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!\n");
|
fprintf(stderr, "WRONG O_LEFT! (%lx(exp) != %lx(sut)\n",
|
|
m_left[(m_addr-m_offset)&(64-1)],
|
|
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!\n");
|
fprintf(stderr, "WRONG O_RIGHT!\n");
|
Line 167... |
Line 186... |
|
|
// 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 = (m_bfly->i_left >> 16) & 0x0ffff;
|
rlft = sbits(m_bfly->i_left >> 16, 16);
|
ilft = (m_bfly->i_left ) & 0x0ffff;
|
ilft = sbits(m_bfly->i_left , 16);
|
// 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 ...
|
// Now repeat for the right hand value ...
|
long rrht, irht;
|
long rrht, irht;
|
// Extract left and right values ...
|
// Extract left and right values ...
|
rrht = (m_bfly->i_right >> 16) & 0x0ffff;
|
rrht = sbits(m_bfly->i_right >> 16, 16);
|
irht = (m_bfly->i_right ) & 0x0ffff;
|
irht = sbits(m_bfly->i_right , 16);
|
// Make certain they are properly sign extended ...
|
|
if (rrht & 0x8000) rrht |= (-1<<16);
|
|
if (irht & 0x8000) irht |= (-1<<16);
|
|
|
|
|
|
// 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 = (m_bfly->i_coef >> 20) & 0x0fffff;
|
rcof = sbits(m_bfly->i_coef >> 20, 20);
|
icof = (m_bfly->i_coef ) & 0x0fffff;
|
icof = sbits(m_bfly->i_coef , 20);
|
// 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 ...
|
// 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 216... |
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;
|
mpyr = p1-p2 + (1<<17);
|
mpyi = p3-p1-p2;
|
mpyi = p3-p1-p2 + (1<<17);
|
|
|
/*
|
/*
|
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);
|