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

Subversion Repositories zipcpu

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /zipcpu/trunk/bench
    from Rev 57 to Rev 58
    Reverse comparison

Rev 57 → Rev 58

/cpp/zippy_tb.cpp
73,9 → 73,10
unsigned long m_mem_size;
MEMSIM m_mem;
// QSPIFLASHSIM m_flash;
FILE *dbg_fp;
FILE *dbg_fp, *m_profile_fp;
bool dbg_flag, bomb, m_show_user_timers;
int m_cursor;
unsigned long m_last_instruction_tickcount;
 
ZIPPY_TB(void) : m_mem_size(1<<20), m_mem(m_mem_size) {
if (false) {
88,6 → 89,13
bomb = false;
m_cursor = 0;
m_show_user_timers = false;
 
m_last_instruction_tickcount = 0l;
if (true) {
m_profile_fp = fopen("pfile.bin","wb");
} else {
m_profile_fp = NULL;
}
}
 
void reset(void) {
393,9 → 401,9
(m_core->v__DOT__thecpu__DOT__opvalid_mem), //0
(!m_core->v__DOT__thecpu__DOT__clear_pipeline), //1
(m_core->v__DOT__thecpu__DOT__set_cond), //1
(!m_core->v__DOT__thecpu__DOT__mem_stalled), //1
(!mem_stalled()), //1
 
(m_core->v__DOT__thecpu__DOT__mem_stalled),
(mem_stalled()),
(m_core->v__DOT__thecpu__DOT__opvalid_mem),
(m_core->v__DOT__thecpu__DOT__master_ce),
(mem_pipe_stalled()),
483,8 → 491,10
mvprintw(ln-1,10,(m_core->v__DOT__thecpu__DOT__alu_wr)?"w":"V");
else if (m_core->v__DOT__thecpu__DOT__mem_valid)
mvprintw(ln-1,10,"v");
#ifdef OPT_ILLEGAL_INSTRUCTION
else if (m_core->v__DOT__thecpu__DOT__r_alu_illegal)
mvprintw(ln-1,10,"I");
#endif
// else if (m_core->v__DOT__thecpu__DOT__alu_illegal_op)
// mvprintw(ln-1,10,"i");
 
523,7 → 533,7
(m_core->v__DOT__thecpu__DOT__opvalid_mem)?"M":" ",
(m_core->v__DOT__thecpu__DOT__mem_ce)?"CE":" ",
(m_core->v__DOT__thecpu__DOT__mem_we)?"Wr ":"Rd ",
(m_core->v__DOT__thecpu__DOT__mem_stalled)?"PIPE":" ",
(mem_stalled())?"PIPE":" ",
(m_core->v__DOT__thecpu__DOT__mem_valid)?"V":" ",
zop_regstr[(m_core->v__DOT__thecpu__DOT__mem_wreg&0x1f)^0x10]);
}
936,6 → 946,18
alu_pc());
 
}
 
if ((m_core->v__DOT__thecpu__DOT__alu_pc_valid)
&&(!m_core->v__DOT__thecpu__DOT__clear_pipeline)) {
unsigned long iticks = m_tickcount - m_last_instruction_tickcount;
if (m_profile_fp) {
unsigned buf[2];
buf[0] = m_core->v__DOT__thecpu__DOT__alu_pc-1;
buf[1] = iticks;
fwrite(buf, sizeof(unsigned), 2, m_profile_fp);
}
m_last_instruction_tickcount = m_tickcount;
}
}
 
bool test_success(void) {
953,6 → 975,28
return m_core->v__DOT__thecpu__DOT__op_pc-1;
}
 
bool mem_busy(void) {
// return m_core->v__DOT__thecpu__DOT__mem_busy;
return m_core->v__DOT__thecpu__DOT__domem__DOT__cyc;
}
 
bool mem_stalled(void) {
bool a, b, c, d, wr_write_cc, wr_write_pc, op_gie;
 
wr_write_cc=((m_core->v__DOT__thecpu__DOT__wr_reg_id&0x0f)==0x0e);
wr_write_pc=((m_core->v__DOT__thecpu__DOT__wr_reg_id&0x0f)==0x0f);
op_gie = m_core->v__DOT__thecpu__DOT__op_gie;
 
a = m_core->v__DOT__thecpu__DOT__mem_pipe_stalled;
b = (m_core->v__DOT__thecpu__DOT__op_pipe)&&(mem_busy());
d = ((wr_write_pc)||(wr_write_cc));
c = ((m_core->v__DOT__thecpu__DOT__wr_reg_ce)
&&((m_core->v__DOT__thecpu__DOT__wr_reg_id&0x010)==op_gie)
&&d);
d =(m_core->v__DOT__thecpu__DOT__opvalid_mem)&&((a)||(b)||(c));
return ((!m_core->v__DOT__thecpu__DOT__master_ce)||(d));
}
 
unsigned alu_pc(void) {
/*
unsigned r = op_pc();
1252,16 → 1296,36
}
} else if (access(argv[argn], R_OK)==0) {
FILE *fp = fopen(argv[argn], "r");
int nr, nv = 0;
if (fp == NULL) {
printf("Cannot open %s\n", argv[argn]);
perror("O/S Err: ");
exit(-1);
} mptr += fread(&tb->m_mem[mptr], sizeof(ZIPI), tb->m_mem_size - mptr, fp);
} nr = fread(&tb->m_mem[mptr], sizeof(ZIPI), tb->m_mem_size - mptr, fp);
fclose(fp);
mptr+= nr;
if (nr == 0) {
printf("Could not read from %s, only read 0 words\n", argv[argn]);
perror("O/S Err?:");
exit(-2);
} for(int i=0; i<nr; i++) {
if (tb->m_mem[mptr-nr+i])
nv++;
} if (nv == 0) {
printf("Read nothing but zeros from %s\n", argv[argn]);
perror("O/S Err?:");
exit(-2);
}
} else {
fprintf(stderr, "No access to %s, or unknown arg\n", argv[argn]);
exit(-2);
}
}
}
 
 
assert(mptr > 0);
 
if (autorun) {
bool done = false;
 
/cpp/pdump.cpp
0,0 → 1,135
////////////////////////////////////////////////////////////////////////////////
//
// Filename: pdump.cpp
//
// Project: Zip CPU -- a small, lightweight, RISC CPU core
//
// Purpose: Disassemble machine code files onto the stdout file. Unlike
// the zdump program that is part of the assembler suite, this
// 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,
// at least in simulation, your time is being spent. It can also be used,
// after the fact, to get a trace of what instructions the CPU executed.
//
// Creator: Dan Gisselquist, Ph.D.
// Gisselquist Tecnology, LLC
//
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015, Gisselquist Technology, LLC
//
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// 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
// target there if the PDF file isn't present.) If not, see
// <http://www.gnu.org/licenses/> for a copy.
//
// License: GPL, v3, as defined and found on www.gnu.org,
// http://www.gnu.org/licenses/gpl.html
//
//
////////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
 
#include "zopcodes.h"
 
typedef struct { unsigned clks, addr; } ALT;
bool altcmp(const ALT &a, const ALT &b) {
return a.clks < b.clks;
}
 
void dump_file(const char *fn) {
const int NZIP = 4096;
char ln[NZIP];
ZIPI ibuf[NZIP];
FILE *fp, *pf;
int nr;
unsigned addr=0x08000, mina = -1, maxa = 0,
*pfcnt = NULL, *pfclk = NULL;
 
fp = fopen(fn, "r");
if (!fp)
return;
 
pf = fopen("pfile.bin","rb");
if (pf) {
ALT *pfalt;
unsigned buf[2], total_clks = 0;
while(2 == fread(buf, sizeof(unsigned), 2, pf)) {
if (mina > buf[0])
mina = buf[0];
if (maxa < buf[0])
maxa = buf[0];
}
 
addr = mina;
pfcnt = new unsigned[(maxa+2-mina)];
pfclk = new unsigned[(maxa+2-mina)];
pfalt = new ALT[(maxa+2-mina)];
unsigned ncnt = maxa+2-mina;
for(int i=0; i<(int)ncnt; i++)
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);
while((nr=fread(ibuf, sizeof(ZIPI), NZIP, fp))>0) {
for(int i=0; i<nr; i++) {
zipi_to_string(ibuf[i], ln);
// printf("%s\n", ln);
printf("%08x: (0x%08x %c%c%c%c) ", addr,
ibuf[i],
isgraph((ibuf[i]>>24)&0x0ff)?((ibuf[i]>>24)&0x0ff) : '.',
isgraph((ibuf[i]>>16)&0x0ff)?((ibuf[i]>>16)&0x0ff) : '.',
isgraph((ibuf[i]>> 8)&0x0ff)?((ibuf[i]>> 8)&0x0ff) : '.',
isgraph((ibuf[i] )&0x0ff)?((ibuf[i] )&0x0ff) : '.'
);
if (pfcnt)
printf("%8d %8d ", pfcnt[addr-mina], pfclk[addr-mina]);
printf("%s\n", ln);
 
addr++;
}
} fclose(fp);
}
 
int main(int argc, char **argv) {
for(int argn=1; argn<argc; argn++) {
if(access(argv[argn], R_OK)==0)
dump_file(argv[argn]);
}
 
return 0;
}
 
/cpp/Makefile
51,6 → 51,10
zippy_tb: $(RTLD)/cpudefs.h
$(CXX) $(FLAGS) $(INCS) $(SOURCES) $(LIBS) -o $@
 
pdump: pdump.cpp $(ZASM)/zopcodes.cpp $(ZASM)/zparser.cpp
pdump: $(ZASM)/zopcodes.h $(ZASM)/zparser.h testb.h twoc.cpp
$(CXX) $(FLAGS) $(INCS) pdump.cpp $(ZASM)/zopcodes.cpp $(ZASM)/zparser.cpp twoc.cpp -o $@
 
.PHONY: stest
stest: zippy_tb
./zippy_tb -s $(TESTF)

powered by: WebSVN 2.1.0

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