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

Subversion Repositories dblclockfft

[/] [dblclockfft/] [trunk/] [bench/] [cpp/] [butterfly_tb.cpp] - Diff between revs 35 and 36

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

Rev 35 Rev 36
Line 2... Line 2...
//
//
// Filename:    butterfly_tb.cpp
// Filename:    butterfly_tb.cpp
//
//
// Project:     A Doubletime Pipelined FFT
// Project:     A Doubletime Pipelined FFT
//
//
// Purpose:     A test-bench for the butterfly.v subfile of the double
// Purpose:     A test-bench for the butterfly.v subfile of the generic
//              clocked FFT.  This file may be run autonomously.  If so,
//              pipelined FFT.  This file may be run autonomously.  If so,
//              the last line output will either read "SUCCESS" on success,
//      the last line output will either read "SUCCESS" on success, or some
//              or some other failure message otherwise.
//      other failure message otherwise.
//
//
//              This file depends upon verilator to both compile, run, and
//      This file depends upon verilator to both compile, run, and therefore
//              therefore test butterfly.v
//      test butterfly.v
//
//
// Creator:     Dan Gisselquist, Ph.D.
// Creator:     Dan Gisselquist, Ph.D.
//              Gisselquist Technology, LLC
//              Gisselquist Technology, LLC
//
//
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//
//
// Copyright (C) 2015, Gisselquist Technology, LLC
// Copyright (C) 2015,2018 Gisselquist Technology, LLC
//
//
// This program is free software (firmware): you can redistribute it and/or
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of  the GNU General Public License as published
// modify it under the terms of  the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
// your option) any later version.
Line 40... Line 40...
//
//
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdio.h>
#include <stdint.h>
#include <stdint.h>
 
 
#include "fftsize.h"
 
#include "Vbutterfly.h"
 
#include "verilated.h"
#include "verilated.h"
 
#include "verilated_vcd_c.h"
 
#include "Vbutterfly.h"
#include "twoc.h"
#include "twoc.h"
 
#include "fftsize.h"
 
 
 
#ifdef  NEW_VERILATOR
 
#define VVAR(A) butterfly__DOT__ ## A
 
#else
 
#define VVAR(A) v__DOT_ ## A
 
#endif
 
 
#define IWIDTH  TST_BUTTERFLY_IWIDTH
#define IWIDTH  TST_BUTTERFLY_IWIDTH
#define CWIDTH  TST_BUTTERFLY_CWIDTH
#define CWIDTH  TST_BUTTERFLY_CWIDTH
#define OWIDTH  TST_BUTTERFLY_OWIDTH
#define OWIDTH  TST_BUTTERFLY_OWIDTH
#define BFLYDELAY       TST_BUTTERFLY_MPYDELAY
#define BFLYDELAY       TST_BUTTERFLY_MPYDELAY
 
 
class   BFLY_TB {
class   BFLY_TB {
public:
public:
        Vbutterfly      *m_bfly;
        Vbutterfly      *m_bfly;
 
        VerilatedVcdC   *m_trace;
        unsigned long   m_left[64], m_right[64];
        unsigned long   m_left[64], m_right[64];
        bool            m_aux[64];
        bool            m_aux[64];
        int             m_addr, m_lastaux, m_offset;
        int             m_addr, m_lastaux, m_offset;
        bool            m_syncd, m_waiting_for_sync_input;
        bool            m_syncd, m_waiting_for_sync_input;
 
        uint64_t        m_tickcount;
 
 
        BFLY_TB(void) {
        BFLY_TB(void) {
 
                Verilated::traceEverOn(true);
 
                m_trace = NULL;
                m_bfly = new Vbutterfly;
                m_bfly = new Vbutterfly;
                m_addr = 0;
                m_addr = 0;
                m_syncd = 0;
                m_syncd = 0;
 
                m_tickcount = 0;
                m_waiting_for_sync_input = true;
                m_waiting_for_sync_input = true;
        }
        }
 
 
 
        void    opentrace(const char *vcdname) {
 
                if (!m_trace) {
 
                        m_trace = new VerilatedVcdC;
 
                        m_bfly->trace(m_trace, 99);
 
                        m_trace->open(vcdname);
 
                }
 
        }
 
 
 
        void    closetrace(void) {
 
                if (m_trace) {
 
                        m_trace->close();
 
                        delete  m_trace;
 
                        m_trace = NULL;
 
                }
 
        }
 
 
        void    tick(void) {
        void    tick(void) {
 
                m_tickcount++;
 
 
                m_lastaux = m_bfly->o_aux;
                m_lastaux = m_bfly->o_aux;
                m_bfly->i_clk = 0;
                m_bfly->i_clk = 0;
                m_bfly->eval();
                m_bfly->eval();
 
                if (m_trace) m_trace->dump((uint64_t)(10ul*m_tickcount-2));
                m_bfly->i_clk = 1;
                m_bfly->i_clk = 1;
                m_bfly->eval();
                m_bfly->eval();
 
                if (m_trace) m_trace->dump((uint64_t)(10ul*m_tickcount));
 
                m_bfly->i_clk = 0;
 
                m_bfly->eval();
 
                if (m_trace) {
 
                        m_trace->dump((uint64_t)(10ul*m_tickcount+5));
 
                        m_trace->flush();
 
                }
 
 
                if ((!m_syncd)&&(m_bfly->o_aux))
                if ((!m_syncd)&&(m_bfly->o_aux))
                        m_offset = m_addr;
                        m_offset = m_addr;
                m_syncd = (m_syncd) || (m_bfly->o_aux);
                m_syncd = (m_syncd) || (m_bfly->o_aux);
        }
        }
 
 
 
        void    cetick(void) {
 
                int     ce = m_bfly->i_ce, nkce;
 
 
 
                tick();
 
 
 
                nkce = (rand()&1);
 
#ifdef  FFT_CKPCE
 
                nkce += FFT_CKPCE;
 
#endif
 
 
 
                if ((ce)&&(nkce > 0)) {
 
                        m_bfly->i_ce = 0;
 
                        for(int kce=0; kce<nkce-1; kce++)
 
                                tick();
 
                }
 
 
 
                m_bfly->i_ce = ce;
 
        }
 
 
        void    reset(void) {
        void    reset(void) {
                m_bfly->i_ce    = 0;
                m_bfly->i_ce    = 0;
                m_bfly->i_rst   = 1;
                m_bfly->i_reset = 1;
                m_bfly->i_coef  = 0l;
                m_bfly->i_coef  = 0l;
                m_bfly->i_left  = 0;
                m_bfly->i_left  = 0;
                m_bfly->i_right = 0;
                m_bfly->i_right = 0;
                tick();
                tick();
                m_bfly->i_rst = 0;
                m_bfly->i_reset = 0;
                m_bfly->i_ce  = 1;
                m_bfly->i_ce  = 1;
                //
                //
                // Let's run a RESET test here, forcing the whole butterfly
                // Let's run a RESET test here, forcing the whole butterfly
                // to be filled with aux=1.  If the reset works right,
                // to be filled with aux=1.  If the reset works right,
                // we'll never get an aux=1 output.
                // we'll never get an aux=1 output.
                //
                //
                m_bfly->i_rst = 1;
                m_bfly->i_reset = 1;
                m_bfly->i_aux = 1;
                m_bfly->i_aux = 1;
                for(int i=0; i<200; i++) {
 
                        m_bfly->i_ce = 1;
                        m_bfly->i_ce = 1;
                        tick();
                for(int i=0; i<200; i++)
                }
                        cetick();
 
 
                // Now here's the RESET line, so let's see what the test does
                // Now here's the RESET line, so let's see what the test does
                m_bfly->i_rst = 1;
                m_bfly->i_reset = 1;
                m_bfly->i_ce  = 1;
                m_bfly->i_ce  = 1;
                m_bfly->i_aux = 1;
                m_bfly->i_aux = 1;
                tick();
                cetick();
                m_bfly->i_rst = 0;
                m_bfly->i_reset = 0;
                m_syncd = 0;
                m_syncd = 0;
 
 
                m_waiting_for_sync_input = true;
                m_waiting_for_sync_input = true;
        }
        }
 
 
Line 122... Line 178...
                        m_waiting_for_sync_input = false;
                        m_waiting_for_sync_input = false;
                        m_addr = 0;
                        m_addr = 0;
                }
                }
 
 
                m_bfly->i_ce = 1;
                m_bfly->i_ce = 1;
                tick();
                cetick();
 
 
                if ((m_bfly->o_aux)&&(!m_lastaux))
                if ((m_bfly->o_aux)&&(!m_lastaux))
                        printf("\n");
                        printf("\n");
                printf("n,k=%d,%3d: COEF=%010lx, LFT=%08x, RHT=%08x, A=%d, OLFT =%09lx, ORHT=%09lx, AUX=%d\n",
                printf("n,k=%d,%3d: COEF=%0*lx, LFT=%0*x, RHT=%0*x, A=%d, OLFT =%0*lx, ORHT=%0*lx, AUX=%d\n",
                        n,k,
                        n,k,
                        m_bfly->i_coef & (~(-1l<<40)),
                        (2*CWIDTH+3)/4, ubits(m_bfly->i_coef, 2*CWIDTH),
                        m_bfly->i_left,
                        (2*IWIDTH+3)/4, m_bfly->i_left,
                        m_bfly->i_right,
                        (2*IWIDTH+3)/4, m_bfly->i_right,
                        m_bfly->i_aux,
                        m_bfly->i_aux,
                        m_bfly->o_left,
                        (2*OWIDTH+3)/4, (long)m_bfly->o_left,
                        m_bfly->o_right,
                        (2*OWIDTH+3)/4, (long)m_bfly->o_right,
                        m_bfly->o_aux);
                        m_bfly->o_aux);
 
 
                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)) {
                        printf("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);
                                (long)m_bfly->o_left);
                        exit(-1);
                        exit(EXIT_FAILURE);
                }
                }
 
 
                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)) {
                        printf("WRONG O_RIGHT (%10lx(exp) != (%10lx(sut))!\n",
                        printf("WRONG O_RIGHT! (%lx(exp) != %lx(sut))\n",
                                m_right[(m_addr-m_offset)&(64-1)], m_bfly->o_right);
                                m_right[(m_addr-m_offset)&(64-1)],
                        exit(-1);
                                (long)m_bfly->o_right);
 
                        exit(EXIT_FAILURE);
                }
                }
 
 
                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)) {
                        printf("FAILED AUX CHANNEL TEST (i.e. the SYNC)\n");
                        printf("FAILED AUX CHANNEL TEST (i.e. the SYNC)\n");
                        exit(-1);
                        exit(EXIT_FAILURE);
                }
                }
 
 
                if ((m_addr > TST_BUTTERFLY_MPYDELAY+6)&&(!m_syncd)) {
                if ((m_addr > TST_BUTTERFLY_MPYDELAY+6)&&(!m_syncd)) {
                        printf("NO SYNC PULSE!\n");
                        printf("NO SYNC PULSE!\n");
                        // exit(-1);
                        exit(EXIT_FAILURE);
                }
                }
 
 
                // Now, let's calculate an "expected" result ...
                // Now, let's calculate an "expected" result ...
                long    rlft, ilft;
                long    rlft, ilft;
 
 
Line 239... Line 296...
 
 
                m_addr++;
                m_addr++;
        }
        }
};
};
 
 
 
long gentestword(int w, int al, int ar) {
 
        unsigned long   lo, hi, r;
 
        hi  = ((unsigned long)(al&0x0c))<<(w-4);
 
        hi += (al&3)-2ul;
 
 
 
        lo  = ((unsigned long)(ar&0x0c))<<(w-4);
 
        lo += (ar&3)-2ul;
 
 
 
        r = (ubits(hi, w) << w) | (ubits(lo, w));
 
        return r;
 
}
 
 
int     main(int argc, char **argv, char **envp) {
int     main(int argc, char **argv, char **envp) {
        Verilated::commandArgs(argc, argv);
        Verilated::commandArgs(argc, argv);
        BFLY_TB *bfly = new BFLY_TB;
        BFLY_TB *bfly = new BFLY_TB;
        int16_t         ir0, ii0, lstr, lsti;
        int16_t         ir0, ii0, lstr, lsti;
        int32_t         sumr, sumi, difr, difi;
        int32_t         sumr, sumi, difr, difi;
        int32_t         smr, smi, dfr, dfi;
        int32_t         smr, smi, dfr, dfi;
        int             rnd = 0;
        int             rnd = 0;
 
 
        const int       TESTSZ = 256;
        const int       TESTSZ = 256;
 
 
 
        bfly->opentrace("butterfly.vcd");
 
 
        bfly->reset();
        bfly->reset();
 
 
 
// #define      ZEROTEST
 
#define ZEROTEST bfly->test(9,0,0x0000000000l,0x00000000,0x00000000, 0)
        // Test whether or not the aux channel starts clear, like its supposed to
        // Test whether or not the aux channel starts clear, like its supposed to
 
 
 
        bfly->test(9,0,0x4000000000l,0x000f0000,0x00000000, 1);
 
        ZEROTEST;
 
        ZEROTEST;
 
        bfly->test(9,0,0x4000000000l,0x00000000,0x000f0000, 0);
 
        ZEROTEST;
 
        ZEROTEST;
        bfly->test(9,0,0x4000000000l,0x000f0000,0x000f0000, 0);
        bfly->test(9,0,0x4000000000l,0x000f0000,0x000f0000, 0);
 
        ZEROTEST;
 
        ZEROTEST;
        bfly->test(9,1,0x4000000000l,0x000f0000,0xfff10000, 0);
        bfly->test(9,1,0x4000000000l,0x000f0000,0xfff10000, 0);
 
        ZEROTEST;
 
        ZEROTEST;
        bfly->test(9,2,0x4000000000l,0x0000000f,0x0000fff1, 0);
        bfly->test(9,2,0x4000000000l,0x0000000f,0x0000fff1, 0);
 
        ZEROTEST;
 
        ZEROTEST;
        bfly->test(9,3,0x4000000000l,0x0000000f,0x0000000f, 0);
        bfly->test(9,3,0x4000000000l,0x0000000f,0x0000000f, 0);
 
        ZEROTEST;
 
        ZEROTEST;
 
 
        bfly->test(9,0,0x4000000000l,0x7fff0000,0x7fff0000, 1);
        bfly->test(9,0,0x4000000000l,0x7fff0000,0x7fff0000, 1);
        bfly->test(9,1,0x4000000000l,0x7fff0000,0x80010000, 0);
        bfly->test(9,1,0x4000000000l,0x7fff0000,0x80010000, 0);
        bfly->test(9,2,0x4000000000l,0x00007fff,0x00008001, 0);
        bfly->test(9,2,0x4000000000l,0x00007fff,0x00008001, 0);
        bfly->test(9,3,0x4000000000l,0x00007fff,0x00007fff, 0);
        bfly->test(9,3,0x4000000000l,0x00007fff,0x00007fff, 0);
Line 335... Line 423...
                aux = ((k&(TESTSZ-1))==0);
                aux = ((k&(TESTSZ-1))==0);
 
 
                bfly->test(n,k, cof, lft, rht, aux);
                bfly->test(n,k, cof, lft, rht, aux);
        }
        }
 
 
 
        int     k = TESTSZ;
 
        // Exhaustively test
 
#if (4*IWIDTH+2*CWIDTH <= 24)
 
                for(int a=0; a<(1<<(2*IWIDTH)); a++)
 
                for(int b=0; b<(1<<(2*IWIDTH)); b++)
 
                for(int c=0; c<(1<<(2*CWIDTH)); c++)
 
                        bfly->test(0, k++, c, a, b, 0);
 
 
 
                printf("Exhaust complete\n");
 
#else
 
                for(int al=0; al<16; al++)
 
                for(int ar=0; ar<16; ar++)
 
                for(int bl=0; bl<16; bl++)
 
                for(int br=0; br<16; br++)
 
                for(int cl=0; cl<16; cl++)
 
                for(int cr=0; cr<16; cr++) {
 
                        long a = gentestword(IWIDTH, al, ar);
 
                        long b = gentestword(IWIDTH, bl, br);
 
                        long c = gentestword(CWIDTH, cl, cr);
 
                        bfly->test(0, k++, c, a, b, 0);
 
                }
 
                printf("Partial exhaust complete\n");
 
#endif
 
 
        delete  bfly;
        delete  bfly;
 
 
        printf("SUCCESS!\n");
        printf("SUCCESS!\n");
        exit(0);
        exit(0);
}
}

powered by: WebSVN 2.1.0

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