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

Subversion Repositories dblclockfft

[/] [dblclockfft/] [trunk/] [bench/] [cpp/] [mpy_tb.cpp] - Diff between revs 6 and 29

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

Rev 6 Rev 29
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 "fftsize.h"
 
#ifdef  USE_OLD_MULTIPLY
#include "Vshiftaddmpy.h"
#include "Vshiftaddmpy.h"
 
typedef Vshiftaddmpy    Vmpy;
 
#define AW      TST_SHIFTADDMPY_AW
 
#define BW      TST_SHIFTADDMPY_BW
 
#define DELAY   (TST_SHIFTADDMPY_AW+2)
 
#else
 
#include "Vlongbimpy.h"
 
typedef Vlongbimpy      Vmpy;
 
#define AW      TST_LONGBIMPY_AW
 
#define BW      TST_LONGBIMPY_BW
 
#define DELAY   ((AW/2)+(AW&1)+2)
 
#endif
 
 
#include "verilated.h"
#include "verilated.h"
 
#include "twoc.h"
 
 
class   MPYTB {
class   MPYTB {
public:
public:
        Vshiftaddmpy    *mpy;
        Vmpy    *mpy;
        long    vals[32];
        long    vals[32];
        int     m_addr;
        int     m_addr;
 
 
        MPYTB(void) {
        MPYTB(void) {
                mpy = new Vshiftaddmpy;
                mpy = new Vmpy;
 
 
                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;
        }
        }
Line 76... Line 91...
                        tick();
                        tick();
        }
        }
 
 
        bool    test(const int ia, const int ib) {
        bool    test(const int ia, const int ib) {
                bool    success;
                bool    success;
                int     a, b;
                long    a, b, out;
                long    out;
 
 
 
                a = ia & 0x0ffff;
                a = sbits(ia, AW);
                b = ib & 0x0ffff;
                b = sbits(ib, BW);
                mpy->i_ce = 1;
                mpy->i_ce = 1;
                mpy->i_a = a & 0x0ffff;
                mpy->i_a = ubits(a, AW);
                mpy->i_b = b & 0x0ffff;
                mpy->i_b = ubits(b, BW);
 
 
                if (a&0x8000) a |= (-1 << 15);
 
                if (b&0x8000) b |= (-1 << 15);
 
 
 
                vals[m_addr&31] = (long)a * (long)b;
                vals[m_addr&31] = a * b;
 
 
                tick();
                tick();
 
                if (rand()&1) {
 
                        mpy->i_ce = 0;
 
                        tick();
 
                }
 
 
                printf("k=%3d: A =%06x, B =%06x, ANS =%10lx, S=%3d,%3d,%3d,%3d, O = %8x\n",
                printf("k=%3d: A =%04x, B =%05x -> O = %9lx (ANS=%10lx)\n",
                        m_addr, a & 0x0ffffff, b & 0x0ffffff,
                        m_addr, (int)ubits(a,AW), (int)ubits(b,BW),
                        vals[m_addr&31] & (~(-1l<<40)),
                        (long)mpy->o_r, ubits(vals[m_addr&31], AW+BW+4));
                        mpy->v__DOT__sgn,
 
                        mpy->v__DOT__r_s[0],
 
                        mpy->v__DOT__r_s[1],
 
                        mpy->v__DOT__r_s[2],
 
                        mpy->o_r);
 
 
 
                out = mpy->o_r;
                out = sbits(mpy->o_r, AW+BW);
                if (out & (1<<31)) out |= (-1 << 31);
 
 
 
                m_addr++;
                m_addr++;
 
 
                success = (m_addr < 20)||(out == vals[(m_addr-18)&31]);
                success = (m_addr < (DELAY+2))||(out == vals[(m_addr-DELAY)&31]);
                if (!success) {
                if (!success) {
                        fprintf(stderr, "WRONG ANSWER: %8lx != %8lx\n", vals[(m_addr-18)&0x01f], out);
                        printf("WRONG ANSWER: %8lx (exp) != %8lx (sut)\n", vals[(m_addr-DELAY)&0x01f], out);
                        exit(-1);
                        exit(-1);
                }
                }
 
 
                return success;
                return success;
        }
        }
Line 138... Line 147...
                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<200; k++) {
        for(int k=0; k<2048; k++) {
                int     a, b, out;
                int     a, b, out;
 
 
                tb->test(rand(), rand());
                tb->test(rand(), rand());
        }
        }
 
 

powered by: WebSVN 2.1.0

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