URL
https://opencores.org/ocsvn/dblclockfft/dblclockfft/trunk
Subversion Repositories dblclockfft
[/] [dblclockfft/] [trunk/] [bench/] [cpp/] [mpy_tb.cpp] - Rev 4
Go to most recent revision | Compare with Previous | Blame | View Log
#include "Vshiftaddmpy.h" #include "verilated.h" class MPYTB { public: Vshiftaddmpy *mpy; long vals[32]; int m_addr; MPYTB(void) { mpy = new Vshiftaddmpy; for(int i=0; i<32; i++) vals[i] = 0; m_addr = 0; } ~MPYTB(void) { delete mpy; } void tick(void) { mpy->i_clk = 0; mpy->eval(); mpy->i_clk = 1; mpy->eval(); } void reset(void) { mpy->i_clk = 0; mpy->i_ce = 1; mpy->i_a = 0; mpy->i_b = 0; for(int k=0; k<20; k++) tick(); } bool test(const int ia, const int ib) { bool success; int a, b; long out; a = ia & 0x0ffff; b = ib & 0x0ffff; mpy->i_ce = 1; mpy->i_a = a & 0x0ffff; mpy->i_b = b & 0x0ffff; if (a&0x8000) a |= (-1 << 15); if (b&0x8000) b |= (-1 << 15); vals[m_addr&31] = (long)a * (long)b; tick(); printf("k=%3d: A =%06x, B =%06x, ANS =%10lx, S=%3d,%3d,%3d,%3d, O = %8x\n", m_addr, a & 0x0ffffff, b & 0x0ffffff, vals[m_addr&31] & (~(-1l<<40)), 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; if (out & (1<<31)) out |= (-1 << 31); m_addr++; success = (m_addr < 20)||(out == vals[(m_addr-18)&31]); if (!success) { fprintf(stderr, "WRONG ANSWER: %8lx != %8lx\n", vals[(m_addr-18)&0x01f], out); exit(-1); } return success; } }; int main(int argc, char **argv, char **envp) { Verilated::commandArgs(argc, argv); MPYTB *tb = new MPYTB; tb->reset(); for(int k=0; k<15; k++) { int a, b; a = (1<<k); b = 1; tb->test(a, b); } for(int k=0; k<15; k++) { int a, b, out; a = (1<<15); b = (1<<k); tb->test(a, b); } for(int k=0; k<200; k++) { int a, b, out; tb->test(rand(), rand()); } delete tb; printf("SUCCESS!\n"); exit(0); }
Go to most recent revision | Compare with Previous | Blame | View Log