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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [bench/] [cpp/] [div_tb.cpp] - Diff between revs 77 and 147

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

Rev 77 Rev 147
Line 73... Line 73...
                                *str++ = ' ';
                                *str++ = ' ';
                } *str = '\0';
                } *str = '\0';
        }
        }
 
 
        void    tick(void) {
        void    tick(void) {
 
                bool    debug = false;
 
 
 
                if (debug) {
                char    outstr[2048], *s;
                char    outstr[2048], *s;
                sprintf(outstr, "Tick %4ld %s%s%s%s%s%s %2d", m_tickcount,
                        sprintf(outstr, "Tick %4ld %s%s%s%s%s%s %2d",
 
                                m_tickcount,
                        (m_core->o_busy)?"B":" ",
                        (m_core->o_busy)?"B":" ",
                        (m_core->o_valid)?"V":" ",
                        (m_core->o_valid)?"V":" ",
                        (m_core->i_wr)?"W":" ",
                        (m_core->i_wr)?"W":" ",
                        (m_core->v__DOT__pre_sign)?"+":" ",
                        (m_core->v__DOT__pre_sign)?"+":" ",
                        (m_core->v__DOT__r_sign)?"-":" ",
                        (m_core->v__DOT__r_sign)?"-":" ",
                        (m_core->v__DOT__r_z)?"Z":" ",
                        (m_core->v__DOT__r_z)?"Z":" ",
                        m_core->v__DOT__r_bit); s = &outstr[strlen(outstr)];
                                m_core->v__DOT__r_bit);
                sprintf(s, "%s\n%10s %40s",s, "Div",""); s = &s[strlen(s)];
                        s = &outstr[strlen(outstr)];
                bprint( s, 32, m_core->v__DOT__r_dividend);  s=&s[strlen(s)];
                        sprintf(s, "%s\n%10s %40s",s, "Div","");
 
                                s = &s[strlen(s)];
 
                        bprint( s, 32, m_core->v__DOT__r_dividend);
 
                                s=&s[strlen(s)];
                sprintf(s, "%s\n%10s ",s, "Div"); s = &s[strlen(s)];
                sprintf(s, "%s\n%10s ",s, "Div"); s = &s[strlen(s)];
                bprint( s, 64, m_core->v__DOT__r_divisor); s=&s[strlen(s)];
                        bprint( s, 64, m_core->v__DOT__r_divisor);
 
                                s=&s[strlen(s)];
                sprintf(s, "%s\n%10s %40s",s, "Q",""); s=&s[strlen(s)];
                sprintf(s, "%s\n%10s %40s",s, "Q",""); s=&s[strlen(s)];
                bprint( s, 32, m_core->o_quotient); s = &s[strlen(s)];
                bprint( s, 32, m_core->o_quotient); s = &s[strlen(s)];
                sprintf(s, "%s\n%10s %38s",s, "Diff",""); s=&s[strlen(s)];
                        sprintf(s, "%s\n%10s %38s",s, "Diff","");
 
                                s=&s[strlen(s)];
                bprint( s, 33, m_core->v__DOT__diff); s = &s[strlen(s)];
                bprint( s, 33, m_core->v__DOT__diff); s = &s[strlen(s)];
                strcat(s, "\n");
                strcat(s, "\n");
                puts(outstr);
                puts(outstr);
 
                }
                TESTB<Vdiv>::tick();
                TESTB<Vdiv>::tick();
        }
        }
 
 
        void    divs(int n, int d) {
        void    divs(int n, int d) {
 
                bool    dbg = false;
                int     ans;
                int     ans;
                ans = (d==0)?0:   (n / d);
                ans = (d==0)?0:   (n / d);
                assert(m_core->o_busy == 0);
                assert(m_core->o_busy == 0);
 
 
                m_core->i_rst = 0;
                m_core->i_rst = 0;
Line 120... Line 131...
 
 
                // while((!m_core->o_valid)&&(!m_core->o_err))
                // while((!m_core->o_valid)&&(!m_core->o_err))
                while(!m_core->o_valid)
                while(!m_core->o_valid)
                        tick();
                        tick();
 
 
 
                if (dbg) {
                printf("%s%s: %d / %d =? %d\n",
                printf("%s%s: %d / %d =? %d\n",
                        (m_core->o_valid)?"V":" ",
                        (m_core->o_valid)?"V":" ",
                        (m_core->o_err)?"E":" ",
                        (m_core->o_err)?"E":" ",
                        n, d, m_core->o_quotient);
                        n, d, m_core->o_quotient);
 
                }
                if ((m_core->o_err)||(d==0)) {
                if ((m_core->o_err)||(d==0)) {
                        if (d==0)
                        if (d==0)
                                assert(m_core->o_err);
                                assert(m_core->o_err);
                        else    assert(!m_core->o_err);
                        else    assert(!m_core->o_err);
                } else
                } else
                        assert(ans == (int)m_core->o_quotient);
                        assert(ans == (int)m_core->o_quotient);
        }
        }
 
 
        void    divu(unsigned n, unsigned d) {
        void    divu(unsigned n, unsigned d) {
 
                bool    dbg = false;
                unsigned        ans;
                unsigned        ans;
                ans = (d==0)?0:   (n / d);
                ans = (d==0)?0:   (n / d);
                assert(m_core->o_busy == 0);
                assert(m_core->o_busy == 0);
 
 
                m_core->i_rst = 0;
                m_core->i_rst = 0;
Line 156... Line 170...
                assert(m_core->o_valid == 0);
                assert(m_core->o_valid == 0);
 
 
                while(!m_core->o_valid)
                while(!m_core->o_valid)
                        tick();
                        tick();
 
 
 
                if (dbg) {
                printf("%s%s: %u / %u =? %d (Expecting %u)\n",
                printf("%s%s: %u / %u =? %d (Expecting %u)\n",
                        (m_core->o_valid)?"V":" ",
                        (m_core->o_valid)?"V":" ",
                        (m_core->o_err)?"E":" ",
                        (m_core->o_err)?"E":" ",
                        n, d, m_core->o_quotient, ans);
                        n, d, m_core->o_quotient, ans);
 
                }
                if ((m_core->o_err)||(d==0)) {
                if ((m_core->o_err)||(d==0)) {
                        if (d==0)
                        if (d==0)
                                assert(m_core->o_err);
                                assert(m_core->o_err);
                        else    assert(!m_core->o_err);
                        else    assert(!m_core->o_err);
                } else
                } else
Line 182... Line 198...
}
}
 
 
int     main(int argc, char **argv) {
int     main(int argc, char **argv) {
        Verilated::commandArgs(argc, argv);
        Verilated::commandArgs(argc, argv);
        DIV_TB  *tb = new DIV_TB();
        DIV_TB  *tb = new DIV_TB();
        int     rcode = 0;
        int     rcode = EXIT_SUCCESS;
 
 
        tb->reset();
        tb->reset();
        tb->divide(125,7);
        tb->divide(125,7);
        tb->tick();
        tb->tick();
        tb->divide(125,-7);
        tb->divide(125,-7);
Line 222... Line 238...
        tb->divide(rand(),rand()/2);
        tb->divide(rand(),rand()/2);
        tb->tick();
        tb->tick();
        tb->divide(rand(),rand()/2);
        tb->divide(rand(),rand()/2);
        */
        */
 
 
 
        printf("SUCCESS!\n");
        exit(rcode);
        exit(rcode);
}
}
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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