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

Subversion Repositories dblclockfft

[/] [dblclockfft/] [trunk/] [bench/] [cpp/] [fft_tb.cpp] - Diff between revs 19 and 23

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 19 Rev 23
Line 43... Line 43...
#include <math.h>
#include <math.h>
#include <fftw3.h>
#include <fftw3.h>
 
 
#include "verilated.h"
#include "verilated.h"
#include "Vfftmain.h"
#include "Vfftmain.h"
 
#include "twoc.h"
 
 
#define LGWIDTH 11
#define LGWIDTH 11
#define IWIDTH  16
#define IWIDTH  16
#define OWIDTH  22
#define OWIDTH  22
 
 
 
#define NFTLOG  8
#define FFTLEN  (1<<LGWIDTH)
#define FFTLEN  (1<<LGWIDTH)
 
 
class   FFT_TB {
class   FFT_TB {
public:
public:
        Vfftmain        *m_fft;
        Vfftmain        *m_fft;
        long            m_data[FFTLEN], m_log[4*FFTLEN];
        long            m_data[FFTLEN], m_log[NFTLOG*FFTLEN];
        int             m_iaddr, m_oaddr, m_ntest;
        int             m_iaddr, m_oaddr, m_ntest;
        FILE            *m_dumpfp;
        FILE            *m_dumpfp;
        fftw_plan       m_plan;
        fftw_plan       m_plan;
        double          *m_fft_buf;
        double          *m_fft_buf;
        bool            m_syncd;
        bool            m_syncd;
Line 92... Line 94...
                m_iaddr = m_oaddr = 0;
                m_iaddr = m_oaddr = 0;
                m_syncd = false;
                m_syncd = false;
        }
        }
 
 
        long    twos_complement(const long val, const int bits) {
        long    twos_complement(const long val, const int bits) {
                long    r;
                return sbits(val, bits);
 
 
                r = val & ((1l<<bits)-1);
 
                if (r & (1l << (bits-1)))
 
                        r |= (-1l << bits);
 
                return r;
 
        }
        }
 
 
        void    checkresults(void) {
        void    checkresults(void) {
                double  *dp, *sp; // Complex array
                double  *dp, *sp; // Complex array
                double  vout[FFTLEN*2];
                double  vout[FFTLEN*2];
                double  isq=0.0, osq = 0.0;
                double  isq=0.0, osq = 0.0;
                long    *lp;
                long    *lp;
 
 
                // Fill up our test array from the log array
                // Fill up our test array from the log array
                // printf("%3d : CHECK: %8d %5x\n", m_ntest, m_iaddr, m_iaddr);
                // printf("%3d : CHECK: %8d %5x\n", m_ntest, m_iaddr, m_iaddr);
                dp = m_fft_buf; lp = &m_log[(m_iaddr-FFTLEN*3)&((4*FFTLEN-1)&(-FFTLEN))];
                dp = m_fft_buf; lp = &m_log[(m_iaddr-FFTLEN*3)&((NFTLOG*FFTLEN-1)&(-FFTLEN))];
                for(int i=0; i<FFTLEN; i++) {
                for(int i=0; i<FFTLEN; i++) {
                        long    tv = *lp++;
                        long    tv = *lp++;
 
 
                        dp[0] = twos_complement(tv >> IWIDTH, IWIDTH);
                        dp[0] = sbits(tv >> IWIDTH, IWIDTH);
                        dp[1] = twos_complement(tv, IWIDTH);
                        dp[1] = sbits(tv, IWIDTH);
 
 
                        // printf("IN[%4d = %4x] = %9.1f %9.1f\n",
                        // printf("IN[%4d = %4x] = %9.1f %9.1f\n",
                                // i+((m_iaddr-FFTLEN*3)&((4*FFTLEN-1)&(-FFTLEN))),
                                // i+((m_iaddr-FFTLEN*3)&((4*FFTLEN-1)&(-FFTLEN))),
                                // i+((m_iaddr-FFTLEN*3)&((4*FFTLEN-1)&(-FFTLEN))),
                                // i+((m_iaddr-FFTLEN*3)&((4*FFTLEN-1)&(-FFTLEN))),
                                // dp[0], dp[1]);
                                // dp[0], dp[1]);
Line 136... Line 133...
                for(int i=0; i<FFTLEN; i++) {
                for(int i=0; i<FFTLEN; i++) {
                        long    tv = m_data[i];
                        long    tv = m_data[i];
 
 
                        // printf("OUT[%4d = %4x] = ", i, i);
                        // printf("OUT[%4d = %4x] = ", i, i);
                        // printf("%12lx = ", tv);
                        // printf("%12lx = ", tv);
                        *dp = twos_complement(tv >> OWIDTH, OWIDTH);
                        *dp = sbits(tv >> OWIDTH, OWIDTH);
                        // printf("%10.1f + ", *dp);
                        // printf("%10.1f + ", *dp);
                        osq += (*dp) * (*dp); dp++;
                        osq += (*dp) * (*dp); dp++;
                        *dp = twos_complement(tv, OWIDTH);
                        *dp = sbits(tv, OWIDTH);
                        // printf("%10.1f j", *dp);
                        // printf("%10.1f j", *dp);
                        osq += (*dp) * (*dp); dp++;
                        osq += (*dp) * (*dp); dp++;
                        // printf(" <-> %12.1f %12.1f\n", m_fft_buf[2*i], m_fft_buf[2*i+1]);
                        // printf(" <-> %12.1f %12.1f\n", m_fft_buf[2*i], m_fft_buf[2*i+1]);
                }
                }
 
 
Line 170... Line 167...
                printf("OSQ = %18.1f, ", osq);
                printf("OSQ = %18.1f, ", osq);
                printf("XISQ = %18.1f\n", xisq);
                printf("XISQ = %18.1f\n", xisq);
                if (xisq > 1.4 * FFTLEN/2) {
                if (xisq > 1.4 * FFTLEN/2) {
                        printf("TEST FAIL!!  Result is out of bounds from ");
                        printf("TEST FAIL!!  Result is out of bounds from ");
                        printf("expected result with FFTW3.\n");
                        printf("expected result with FFTW3.\n");
                        exit(-2);
                        // exit(-2);
                }
                }
                m_ntest++;
                m_ntest++;
        }
        }
 
 
        bool    test(int lft, int rht) {
        bool    test(int lft, int rht) {
                m_fft->i_ce    = 1;
                m_fft->i_ce    = 1;
                m_fft->i_rst   = 0;
                m_fft->i_rst   = 0;
                m_fft->i_left  = lft;
                m_fft->i_left  = lft;
                m_fft->i_right = rht;
                m_fft->i_right = rht;
 
 
                m_log[(m_iaddr++)&(4*FFTLEN-1)] = (long)lft;
                m_log[(m_iaddr++)&(NFTLOG*FFTLEN-1)] = (long)lft;
                m_log[(m_iaddr++)&(4*FFTLEN-1)] = (long)rht;
                m_log[(m_iaddr++)&(NFTLOG*FFTLEN-1)] = (long)rht;
 
 
                tick();
                tick();
 
 
                if (m_fft->o_sync) {
                if (m_fft->o_sync) {
                        m_oaddr &= (-1<<LGWIDTH);
                        m_oaddr &= (-1<<LGWIDTH);
                        m_syncd = true;
                        m_syncd = true;
                } else m_oaddr += 2;
                } else m_oaddr += 2;
 
 
                /*
                printf("%8x,%5d: %08x,%08x -> %011lx,%011lx"
                printf("%8x,%5d: %08x,%08x -> %011lx,%011lx"
                        // "\t%011lx,%011lx"
                        // "\t%011lx,%011lx"
                        "\t%011lx,%011lx"
                        // "\t%011lx,%011lx"
                        // "\t%06x,%06x"
                        // "\t%06x,%06x"
                        // "\t%06x,%06x"
                        // "\t%06x,%06x"
                        // "\t%011lx,%06x,%06x"
                        "\t%011lx,%06x,%06x"
                        "\t%011lx,%06x,%06x"
                        "\t%011lx,%06x,%06x"
                        "\t%06x,%06x,%06x,%06x"
                        " %s%s%s%s%s%s%s%s%s%s %s%s\n",
                        "\t%011lx,%011lx"
 
                        " %s%s%s%s%s%s%s%s%s%s%s %s%s\n",
                        m_iaddr, m_oaddr,
                        m_iaddr, m_oaddr,
                        lft, rht, m_fft->o_left, m_fft->o_right,
                        lft, rht, m_fft->o_left, m_fft->o_right,
                        // m_fft->v__DOT__stage_e2048__DOT__ib_a,
                        m_fft->v__DOT__w_e4,
                        // m_fft->v__DOT__stage_e2048__DOT__ib_b,
                        m_fft->v__DOT__w_o4,
                        // m_fft->v__DOT__stage_e512__DOT__ib_a,
                        // m_fft->v__DOT__stage_e512__DOT__ib_a,
                        // m_fft->v__DOT__stage_e512__DOT__ib_b,
                        // m_fft->v__DOT__stage_e512__DOT__ib_b,
                        // m_fft->v__DOT__stage_e256__DOT__ib_a,
                        // m_fft->v__DOT__stage_e256__DOT__ib_a,
                        // m_fft->v__DOT__stage_e256__DOT__ib_b,
                        // m_fft->v__DOT__stage_e256__DOT__ib_b,
                        // m_fft->v__DOT__stage_e128__DOT__ib_a,
                        // m_fft->v__DOT__stage_e128__DOT__ib_a,
                        // m_fft->v__DOT__stage_e128__DOT__ib_b,
                        // m_fft->v__DOT__stage_e128__DOT__ib_b,
                        // m_fft->v__DOT__stage_e64__DOT__ib_a,
                        // m_fft->v__DOT__stage_e64__DOT__ib_a,
                        // m_fft->v__DOT__stage_e64__DOT__ib_b,
                        // m_fft->v__DOT__stage_e64__DOT__ib_b,
                        // m_fft->v__DOT__stage_e32__DOT__ib_a,
                        // m_fft->v__DOT__stage_e32__DOT__ib_a,
                        // m_fft->v__DOT__stage_e32__DOT__ib_b,
                        // m_fft->v__DOT__stage_e32__DOT__ib_b,
                        // m_fft->v__DOT__stage_e16__DOT__ib_a,
                        // m_fft->v__DOT__stage_e16__DOT__ib_a,
                        // m_fft->v__DOT__stage_e16__DOT__ib_b,
                        // m_fft->v__DOT__stage_e16__DOT__ib_b,
                        // m_fft->v__DOT__stage_e8__DOT__ib_a,
                        // m_fft->v__DOT__stage_e8__DOT__ib_a,
                        // m_fft->v__DOT__stage_e8__DOT__ib_b,
                        // m_fft->v__DOT__stage_e8__DOT__ib_b,
                        // m_fft->v__DOT__stage_o8__DOT__ib_a,
                        // m_fft->v__DOT__stage_o8__DOT__ib_a,
                        // m_fft->v__DOT__stage_o8__DOT__ib_b,
                        // m_fft->v__DOT__stage_o8__DOT__ib_b,
                        // m_fft->v__DOT__stage_e4__DOT__sum_r,
                        // m_fft->v__DOT__stage_e4__DOT__sum_r,
                        // m_fft->v__DOT__stage_e4__DOT__sum_i,
                        // m_fft->v__DOT__stage_e4__DOT__sum_i,
                        // m_fft->v__DOT__stage_o4__DOT__sum_r,
                        // m_fft->v__DOT__stage_o4__DOT__sum_r,
                        // m_fft->v__DOT__stage_o4__DOT__sum_i,
                        // m_fft->v__DOT__stage_o4__DOT__sum_i,
                        m_fft->v__DOT__stage_e4__DOT__ob_a,
                        // m_fft->v__DOT__stage_e4__DOT__ob_a,
                        m_fft->v__DOT__stage_e4__DOT__ob_b_r,
                        // m_fft->v__DOT__stage_e4__DOT__ob_b_r,
                        m_fft->v__DOT__stage_e4__DOT__ob_b_i,
                        // m_fft->v__DOT__stage_e4__DOT__ob_b_i,
                        m_fft->v__DOT__stage_o4__DOT__ob_a,
                        m_fft->v__DOT__stage_o4__DOT__ob_a,
                        m_fft->v__DOT__stage_o4__DOT__ob_b_r,
                        m_fft->v__DOT__stage_o4__DOT__ob_b_r,
                        m_fft->v__DOT__stage_o4__DOT__ob_b_i,
                        m_fft->v__DOT__stage_o4__DOT__ob_b_i,
//                      m_fft->v__DOT__stage_2__DOT__out_0r,
                        m_fft->v__DOT__stage_2__DOT__o_out_0r,
//                      m_fft->v__DOT__stage_2__DOT__out_0i,
                        m_fft->v__DOT__stage_2__DOT__o_out_0i,
//                      m_fft->v__DOT__stage_2__DOT__out_1r,
                        m_fft->v__DOT__stage_2__DOT__o_out_1r,
//                      m_fft->v__DOT__stage_2__DOT__out_1i,
                        m_fft->v__DOT__stage_2__DOT__o_out_1i,
                        (m_fft->v__DOT__w_s2048)?"S":"-",
                        m_fft->v__DOT__br_o_left,
                        (m_fft->v__DOT__w_s1024)?"S":"-",
                        m_fft->v__DOT__br_o_right,
                        (m_fft->v__DOT__w_s512)?"S":"-",
                        (m_fft->v__DOT__w_s2048)?"S":"-",
                        (m_fft->v__DOT__w_s256)?"S":"-",
                        (m_fft->v__DOT__w_s1024)?"S":"-",
                        (m_fft->v__DOT__w_s128)?"S":"-",
                        (m_fft->v__DOT__w_s512)?"S":"-",
                        (m_fft->v__DOT__w_s64)?"S":"-",
                        (m_fft->v__DOT__w_s256)?"S":"-",
                        (m_fft->v__DOT__w_s32)?"S":"-",
                        (m_fft->v__DOT__w_s128)?"S":"-",
                        (m_fft->v__DOT__w_s16)?"S":"-",
                        (m_fft->v__DOT__w_s64)?"S":"-",
                        (m_fft->v__DOT__w_s8)?"S":"-",
                        (m_fft->v__DOT__w_s32)?"S":"-",
                        (m_fft->v__DOT__w_s4)?"S":"-",
                        (m_fft->v__DOT__w_s16)?"S":"-",
                //      (m_fft->v__DOT__w_s2)?"S":"-", // doesn't exist
                        (m_fft->v__DOT__w_s8)?"S":"-",
                        (m_fft->o_sync)?"\t(SYNC!)":"",
                        (m_fft->v__DOT__w_s4)?"S":"-",
                        (m_fft->o_left | m_fft->o_right)?"  (NZ)":"");
                        (m_fft->v__DOT__br_sync)?"S":((m_fft->v__DOT__r_br_started)?".":"x"),
                */
                        (m_fft->o_sync)?"\t(SYNC!)":"",
 
                        (m_fft->o_left | m_fft->o_right)?"  (NZ)":"");
 
 
                m_data[(m_oaddr  )&(FFTLEN-1)] = m_fft->o_left;
                m_data[(m_oaddr  )&(FFTLEN-1)] = m_fft->o_left;
                m_data[(m_oaddr+1)&(FFTLEN-1)] = m_fft->o_right;
                m_data[(m_oaddr+1)&(FFTLEN-1)] = m_fft->o_right;
 
 
                if ((m_syncd)&&((m_oaddr&(FFTLEN-1)) == FFTLEN-2)) {
                if ((m_syncd)&&((m_oaddr&(FFTLEN-1)) == FFTLEN-2)) {
Line 275... Line 274...
 
 
                return test(ilft, irht);
                return test(ilft, irht);
        }
        }
 
 
        double  rdata(int addr) {
        double  rdata(int addr) {
                long    ivl = m_data[addr & (FFTLEN-1)];
                return (double)sbits(m_data[addr&(FFTLEN-1)]>>OWIDTH, OWIDTH);
 
 
                ivl = twos_complement(ivl >> OWIDTH, OWIDTH);
 
                return (double)ivl;
 
        }
        }
 
 
        double  idata(int addr) {
        double  idata(int addr) {
                long    ivl = m_data[addr & (FFTLEN-1)];
                return (double)sbits(m_data[addr&(FFTLEN-1)], OWIDTH);
 
 
                ivl = twos_complement(ivl, OWIDTH);
 
                return (double)ivl;
 
        }
        }
 
 
        void    dump(FILE *fp) {
        void    dump(FILE *fp) {
                m_dumpfp = fp;
                m_dumpfp = fp;
        }
        }

powered by: WebSVN 2.1.0

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