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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sim/] [verilator/] [pdump.cpp] - Diff between revs 204 and 209

Show entire file | Details | Blame | View Log

Rev 204 Rev 209
Line 1... Line 1...
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Filename:    pdump.cpp
// Filename:    pdump.cpp
//
//
// Project:     Zip CPU -- a small, lightweight, RISC CPU core
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
//
//
// Purpose:     Disassemble machine code files onto the stdout file.  Unlike
// Purpose:     Disassemble machine code files onto the stdout file.  Unlike
//              the zip-objdump program that is part of the binutils suite, this
//              the zip-objdump program that is part of the binutils suite, this
//      program takes the pfile.bin output of the bench test suite and adds
//      program takes the pfile.bin output of the bench test suite and adds
//      profiling information to the output.  It's useful for finding out where,
//      profiling information to the output.  It's useful for finding out where,
Line 27... Line 27...
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// for more details.
//
//
// You should have received a copy of the GNU General Public License along
// You should have received a copy of the GNU General Public License along
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
// target there if the PDF file isn't present.)  If not, see
// target there if the PDF file isn't present.)  If not, see
// <http://www.gnu.org/licenses/> for a copy.
// <http://www.gnu.org/licenses/> for a copy.
//
//
// 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 <algorithm>
#include <algorithm>
 
#include <map>
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <unistd.h>
#include <ctype.h>
#include <ctype.h>
 
 
#include "zipelf.h"
#include "zipelf.h"
Line 52... Line 55...
typedef struct  { unsigned clks, addr; } ALT;
typedef struct  { unsigned clks, addr; } ALT;
bool    altcmp(const ALT &a, const ALT &b) {
bool    altcmp(const ALT &a, const ALT &b) {
        return a.clks < b.clks;
        return a.clks < b.clks;
}
}
 
 
 
typedef struct { unsigned clks, hits, addr; } insn_stat;
 
 
 
typedef std::map<unsigned, insn_stat *> vcd_profile;
 
 
void    dump_file(const char *fn) {
void    dump_file(const char *fn) {
        const   int     NZIP = 4096;
        const   int     NZIP = 4096;
        char    lna[NZIP], lnb[NZIP];
        char    lna[NZIP], lnb[NZIP];
        FILE    *pf;
        FILE    *pf;
        unsigned        addr=0x0100000, mina = -1, maxa = 0,
        unsigned        addr=0x0100000;
                        *pfcnt = NULL, *pfclk = NULL;
        vcd_profile     vp;
 
 
        pf = fopen("pfile.bin","rb");
        pf = fopen("pfile.bin","rb");
        if (pf) {
        if (pf) {
                ALT     *pfalt;
                unsigned        buf[2];
                unsigned        buf[2], total_clks = 0;
 
                while(2 == fread(buf, sizeof(unsigned), 2, pf)) {
                while(2 == fread(buf, sizeof(unsigned), 2, pf)) {
                        if (mina > buf[0])
                        addr = buf[0];
                                mina = buf[0];
                        if (vp.count(addr)>0) {
                        if (maxa < buf[0])
                                vp[addr]->hits++;
                                maxa = buf[0];
                                vp[addr]->clks += buf[1];
                }
                        } else {
 
                                insn_stat       *is;
                addr = mina;
 
                pfcnt = new unsigned[(maxa+2-mina)];
                                is = new insn_stat;
                pfclk = new unsigned[(maxa+2-mina)];
                                is->hits = 1;
                pfalt = new ALT[(maxa+2-mina)];
                                is->clks = buf[1];
                unsigned ncnt = maxa+2-mina;
                                is->addr = addr;
                for(int i=0; i<(int)ncnt; i++)
                                vp[addr] = is;
                        pfcnt[i] = pfclk[i] = 0;
                        }
                for(int i=0; i<(int)ncnt; i++)
                }
                        pfalt[i].addr = pfalt[i].clks = 0;
 
 
 
                rewind(pf);
 
                while(2 == fread(buf, sizeof(unsigned), 2, pf)) {
 
                        pfcnt[buf[0]-addr]++;
 
                        pfclk[buf[0]-addr] += buf[1];
 
                        pfalt[buf[0]-addr].clks += buf[1];
 
                        pfalt[buf[0]-addr].addr = buf[0];
 
                        total_clks += buf[1];
 
 
 
                        printf("%08x\n", buf[0]);
 
                } fclose(pf);
 
 
 
                printf("%08x (%8d) total clocks\n", total_clks, total_clks);
 
 
 
                std::sort(&pfalt[0], &pfalt[ncnt], altcmp);
 
 
 
                for(int i=0; i<(int)ncnt; i++)
 
                        printf("%08x: %8d\n", pfalt[i].addr, pfalt[i].clks);
 
        }
        }
 
 
        printf("%s:\n", fn);
        printf("%s:\n", fn);
        if (iself(fn)) {
        if (iself(fn)) {
                ELFSECTION **secpp=NULL, *secp;
                ELFSECTION **secpp=NULL, *secp;
 
                double          cpi;
                unsigned entry;
                unsigned entry;
 
 
                elfread(fn, entry, secpp);
                elfread(fn, entry, secpp);
                for(int i=0; secpp[i]->m_len; i++) {
                for(int i=0; secpp[i]->m_len; i++) {
                        secp = secpp[i];
                        secp = secpp[i];
                        for(unsigned j=0; j<secp->m_len; j+=4) {
                        for(unsigned j=0; j<secp->m_len; j+=4) {
                                uint32_t        w, a;
                                uint32_t        w, a;
 
 
                                a = secp->m_start+(j<<2);
                                a = secp->m_vaddr+j;
                                w = buildword((const unsigned char *)&secp->m_data[(j<<2)]);
                                w = buildword((const unsigned char *)&secp->m_data[j]);
                                zipi_to_double_string(a, w, lna, lnb);
                                zipi_to_double_string(a, w, lna, lnb);
                                // printf("%s\n", ln);
                                // printf("%s\n", ln);
                                printf("%08x[%08x-%08x]: (0x%08x %c%c%c%c) ",
                                printf("%08x: (0x%08x %c%c%c%c) ", a, w,
                                        a, maxa, mina, w,
 
                                        isgraph((w>>24)&0x0ff)?((w>>24)&0x0ff) : '.',
                                        isgraph((w>>24)&0x0ff)?((w>>24)&0x0ff) : '.',
                                        isgraph((w>>16)&0x0ff)?((w>>16)&0x0ff) : '.',
                                        isgraph((w>>16)&0x0ff)?((w>>16)&0x0ff) : '.',
                                        isgraph((w>> 8)&0x0ff)?((w>> 8)&0x0ff) : '.',
                                        isgraph((w>> 8)&0x0ff)?((w>> 8)&0x0ff) : '.',
                                        isgraph((w    )&0x0ff)?((w    )&0x0ff) : '.'
                                        isgraph((w    )&0x0ff)?((w    )&0x0ff) : '.'
                                        );
                                        );
                                if ((a>=mina)&&(a<maxa)&&(pfcnt))
                                if (vp.count(a)>0) {
                                        printf("%8d %8d ", pfcnt[a-mina], pfclk[a-mina]);
                                        insn_stat *is = vp[a];
 
                                        cpi = is->clks / (double)is->hits;
 
 
 
                                        printf("%8d %8d %4.1f ", is->hits, is->clks, cpi);
 
                                } else
 
                                        printf("%23s", "");
 
 
                                printf("%s\n", lna);
                                printf("%s\n", lna);
                                if (lnb[0])
                                if (lnb[0])
                                        printf("-%24s%s\n", "", lnb);
                                        printf("-%50s%s\n", "", lnb);
                        }
                        }
                }
                }
        }
        }
}
}
 
 

powered by: WebSVN 2.1.0

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