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

Subversion Repositories dblclockfft

[/] [dblclockfft/] [trunk/] [bench/] [cpp/] [mpy_tb.cpp] - Diff between revs 30 and 36

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

Rev 30 Rev 36
Line 1... Line 1...
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//
//
// Filename:    mpy_tb.cpp
// Filename:    mpy_tb.cpp
//
//
// Project:     A Doubletime Pipelined FFT
// Project:     A General Purpose Pipelined FFT Implementation
//
//
// Purpose:     A test-bench for the shift and add shiftaddmpy.v subfile of
// Purpose:     A test-bench for the shift and add shiftaddmpy.v subfile of
//              the double clocked FFT.  This file may be run autonomously. 
//              the double clocked FFT.  This file may be run autonomously. 
//              If so, the last line output will either read "SUCCESS" on
//              If so, the last line output will either read "SUCCESS" on
//              success, or some other failure message otherwise.
//              success, or some other failure message otherwise.
Line 15... Line 15...
// 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 37... Line 37...
// License:     GPL, v3, as defined and found on www.gnu.org,
// License:     GPL, v3, as defined and found on www.gnu.org,
//              http://www.gnu.org/licenses/gpl.html
//              http://www.gnu.org/licenses/gpl.html
//
//
//
//
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
 
#include "verilated.h"
 
#include "verilated_vcd_c.h"
 
 
#include "fftsize.h"
#include "fftsize.h"
 
 
#ifdef  USE_OLD_MULTIPLY
#ifdef  USE_OLD_MULTIPLY
#include "Vshiftaddmpy.h"
#include "Vshiftaddmpy.h"
typedef Vshiftaddmpy    Vmpy;
typedef Vshiftaddmpy    Vmpy;
#define AW      TST_SHIFTADDMPY_AW
#define AW      TST_SHIFTADDMPY_AW
#define BW      TST_SHIFTADDMPY_BW
#define BW      TST_SHIFTADDMPY_BW
Line 52... Line 56...
#define AW      TST_LONGBIMPY_AW
#define AW      TST_LONGBIMPY_AW
#define BW      TST_LONGBIMPY_BW
#define BW      TST_LONGBIMPY_BW
#define DELAY   ((AW/2)+(AW&1)+2)
#define DELAY   ((AW/2)+(AW&1)+2)
#endif
#endif
 
 
#include "verilated.h"
 
#include "twoc.h"
#include "twoc.h"
 
 
class   MPYTB {
class   MPYTB {
public:
public:
        Vmpy    *mpy;
        Vmpy            *m_mpy;
 
        VerilatedVcdC   *m_trace;
        long    vals[32];
        long    vals[32];
        int     m_addr;
        int     m_addr;
 
        uint64_t        m_tickcount;
 
 
        MPYTB(void) {
        MPYTB(void) {
                mpy = new Vmpy;
                Verilated::traceEverOn(true);
 
                m_mpy = new Vmpy;
 
                m_tickcount = 0;
 
 
                for(int i=0; i<32; i++)
                for(int i=0; i<32; i++)
                        vals[i] = 0;
                        vals[i] = 0;
                m_addr = 0;
                m_addr = 0;
        }
        }
        ~MPYTB(void) {
        ~MPYTB(void) {
                delete mpy;
                closetrace();
 
                delete m_mpy;
 
        }
 
 
 
        void    opentrace(const char *vcdname) {
 
                if (!m_trace) {
 
                        m_trace = new VerilatedVcdC;
 
                        m_mpy->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) {
                mpy->i_clk = 0;
                m_tickcount++;
                mpy->eval();
 
                mpy->i_clk = 1;
                m_mpy->i_clk = 0;
                mpy->eval();
                m_mpy->eval();
 
                if (m_trace)    m_trace->dump((uint64_t)(10ul*m_tickcount-2));
 
                m_mpy->i_clk = 1;
 
                m_mpy->eval();
 
                if (m_trace)    m_trace->dump((uint64_t)(10ul*m_tickcount));
 
                m_mpy->i_clk = 0;
 
                m_mpy->eval();
 
                if (m_trace)    {
 
                        m_trace->dump((uint64_t)(10ul*m_tickcount+5));
 
                        m_trace->flush();
 
                }
 
        }
 
 
 
        void    cetick(void) {
 
                int     ce = m_mpy->i_ce, nkce;
 
 
 
                tick();
 
                nkce = (rand()&1);
 
#ifdef  FFT_CKPCE
 
                nkce += FFT_CKPCE;
 
#endif
 
                if ((ce)&&(nkce>0)) {
 
                        m_mpy->i_ce = 0;
 
                        for(int kce=1; kce<nkce; kce++)
 
                                tick();
 
                }
 
 
 
                m_mpy->i_ce = ce;
        }
        }
 
 
        void    reset(void) {
        void    reset(void) {
                mpy->i_clk = 0;
                m_mpy->i_clk = 0;
                mpy->i_ce = 1;
                m_mpy->i_ce = 1;
                mpy->i_a = 0;
                m_mpy->i_a_unsorted = 0;
                mpy->i_b = 0;
                m_mpy->i_b_unsorted = 0;
 
 
                for(int k=0; k<20; k++)
                for(int k=0; k<20; k++)
                        tick();
                        cetick();
        }
        }
 
 
        bool    test(const int ia, const int ib) {
        bool    test(const int ia, const int ib) {
                bool    success;
                bool    success;
                long    a, b, out;
                long    a, b, out;
 
 
                a = sbits(ia, AW);
                a = sbits(ia, AW);
                b = sbits(ib, BW);
                b = sbits(ib, BW);
                mpy->i_ce = 1;
                m_mpy->i_ce = 1;
                mpy->i_a = ubits(a, AW);
                m_mpy->i_a_unsorted = ubits(a, AW);
                mpy->i_b = ubits(b, BW);
                m_mpy->i_b_unsorted = ubits(b, BW);
 
 
                vals[m_addr&31] = a * b;
                vals[m_addr&31] = a * b;
 
 
                tick();
                cetick();
                if (rand()&1) {
 
                        mpy->i_ce = 0;
 
                        tick();
 
                }
 
 
 
                printf("k=%3d: A =%04x, B =%05x -> O = %9lx (ANS=%10lx)\n",
                printf("k=%3d: A =%0*x, B =%0*x -> O = %*lx (ANS=%*lx)\n",
                        m_addr, (int)ubits(a,AW), (int)ubits(b,BW),
                        m_addr, (AW+3)/4, (int)ubits(a,AW),
                        (long)mpy->o_r, ubits(vals[m_addr&31], AW+BW+4));
                        (BW+3)/4, (int)ubits(b,BW),
 
                        (AW+BW+3)/4, (long)m_mpy->o_r,
 
                        (AW+BW+7)/4, ubits(vals[m_addr&31], AW+BW+4));
 
 
                out = sbits(mpy->o_r, AW+BW);
                out = sbits(m_mpy->o_r, AW+BW);
 
 
                m_addr++;
                m_addr++;
 
 
                success = (m_addr < (DELAY+2))||(out == vals[(m_addr-DELAY)&31]);
                success = (m_addr < (DELAY+2))||(out == vals[(m_addr-DELAY)&31]);
                if (!success) {
                if (!success) {
Line 129... Line 178...
 
 
int     main(int argc, char **argv, char **envp) {
int     main(int argc, char **argv, char **envp) {
        Verilated::commandArgs(argc, argv);
        Verilated::commandArgs(argc, argv);
        MPYTB           *tb = new MPYTB;
        MPYTB           *tb = new MPYTB;
 
 
 
        tb->opentrace("mpy.vcd");
        tb->reset();
        tb->reset();
 
 
        for(int k=0; k<15; k++) {
        for(int k=0; k<15; k++) {
                int     a, b;
                int     a, b;
 
 
Line 147... Line 197...
                a = (1<<15);
                a = (1<<15);
                b = (1<<k);
                b = (1<<k);
                tb->test(a, b);
                tb->test(a, b);
        }
        }
 
 
        for(int k=0; k<2048; k++) {
        if (AW+BW <= 20) {
                int     a, b, out;
                // Exhaustive test
 
                for(int a=0; a< (1<<AW); a++)
 
                for(int b=0; b< (1<<BW); b++)
 
                        tb->test(a, b);
 
                printf("Exhaust complete\n");
 
        } else {
 
                // Pseudorandom test
 
                for(int k=0; k<2048; k++)
                tb->test(rand(), rand());
                tb->test(rand(), rand());
        }
        }
 
 
        delete  tb;
        delete  tb;
 
 

powered by: WebSVN 2.1.0

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