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

Subversion Repositories dblclockfft

[/] [dblclockfft/] [trunk/] [bench/] [cpp/] [mpy_tb.cpp] - Blame information for rev 4

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 dgisselq
#include "Vshiftaddmpy.h"
2
#include "verilated.h"
3
 
4
class   MPYTB {
5
public:
6
        Vshiftaddmpy    *mpy;
7
        long    vals[32];
8
        int     m_addr;
9
 
10
        MPYTB(void) {
11
                mpy = new Vshiftaddmpy;
12
 
13
                for(int i=0; i<32; i++)
14
                        vals[i] = 0;
15
                m_addr = 0;
16
        }
17
        ~MPYTB(void) {
18
                delete mpy;
19
        }
20
 
21
        void    tick(void) {
22
                mpy->i_clk = 0;
23
                mpy->eval();
24
                mpy->i_clk = 1;
25
                mpy->eval();
26
        }
27
 
28
        void    reset(void) {
29
                mpy->i_clk = 0;
30
                mpy->i_ce = 1;
31
                mpy->i_a = 0;
32
                mpy->i_b = 0;
33
 
34
                for(int k=0; k<20; k++)
35
                        tick();
36
        }
37
 
38
        bool    test(const int ia, const int ib) {
39
                bool    success;
40
                int     a, b;
41
                long    out;
42
 
43
                a = ia & 0x0ffff;
44
                b = ib & 0x0ffff;
45
                mpy->i_ce = 1;
46
                mpy->i_a = a & 0x0ffff;
47
                mpy->i_b = b & 0x0ffff;
48
 
49
                if (a&0x8000) a |= (-1 << 15);
50
                if (b&0x8000) b |= (-1 << 15);
51
 
52
                vals[m_addr&31] = (long)a * (long)b;
53
 
54
                tick();
55
 
56
                printf("k=%3d: A =%06x, B =%06x, ANS =%10lx, S=%3d,%3d,%3d,%3d, O = %8x\n",
57
                        m_addr, a & 0x0ffffff, b & 0x0ffffff,
58
                        vals[m_addr&31] & (~(-1l<<40)),
59
                        mpy->v__DOT__sgn,
60
                        mpy->v__DOT__r_s[0],
61
                        mpy->v__DOT__r_s[1],
62
                        mpy->v__DOT__r_s[2],
63
                        mpy->o_r);
64
 
65
                out = mpy->o_r;
66
                if (out & (1<<31)) out |= (-1 << 31);
67
 
68
                m_addr++;
69
 
70
                success = (m_addr < 20)||(out == vals[(m_addr-18)&31]);
71
                if (!success) {
72
                        fprintf(stderr, "WRONG ANSWER: %8lx != %8lx\n", vals[(m_addr-18)&0x01f], out);
73
                        exit(-1);
74
                }
75
 
76
                return success;
77
        }
78
};
79
 
80
int     main(int argc, char **argv, char **envp) {
81
        Verilated::commandArgs(argc, argv);
82
        MPYTB           *tb = new MPYTB;
83
 
84
        tb->reset();
85
 
86
        for(int k=0; k<15; k++) {
87
                int     a, b;
88
 
89
                a = (1<<k);
90
                b = 1;
91
                tb->test(a, b);
92
        }
93
 
94
        for(int k=0; k<15; k++) {
95
                int     a, b, out;
96
 
97
                a = (1<<15);
98
                b = (1<<k);
99
                tb->test(a, b);
100
        }
101
 
102
        for(int k=0; k<200; k++) {
103
                int     a, b, out;
104
 
105
                tb->test(rand(), rand());
106
        }
107
 
108
        delete  tb;
109
 
110 4 dgisselq
        printf("SUCCESS!\n");
111 3 dgisselq
        exit(0);
112
}

powered by: WebSVN 2.1.0

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