Commit c055a86e authored by Alexander Shabarshin's avatar Alexander Shabarshin

even more stats

parent 4364329e
......@@ -101,19 +101,94 @@ original copyright:
#ifdef DEBUG_EXTRA
uint32_t minmemr,maxmemr,minmemw,maxmemw;
int stats[64];
#define STATS_NUM 64
unsigned int stats[STATS_NUM];
void init_stats(void)
{
for(int i=0;i<64;i++) stats[i]=0;
for(int i=0;i<STATS_NUM;i++) stats[i]=0;
minmemr = minmemw = ~0;
maxmemr = maxmemw = 0;
}
void print_stats(void)
{
for(int i=0;i<64;i++) if(stats[i]) printf("stats[%i] = %i\n",i,stats[i]);
printf("Memory Reading Area %x...%x\n",minmemr,maxmemr);
printf("\nInstructions stat:\n");
for(int i=0;i<STATS_NUM;i++)
{
if(stats[i])
{
switch(i)
{
case 0: printf("LUI = %u\n",stats[0]); break;
case 1: printf("AUIPC = %u\n",stats[1]); break;
case 2: printf("JAL = %u\n",stats[2]); break;
case 3: printf("JALR = %u\n",stats[3]); break;
case 4: printf("BEQ = %u\n",stats[4]); break;
case 5: printf("BNE = %u\n",stats[5]); break;
case 6: printf("BLT = %u\n",stats[6]); break;
case 7: printf("BGE = %u\n",stats[7]); break;
case 8: printf("BLTU = %u\n",stats[8]); break;
case 9: printf("BGEU = %u\n",stats[9]); break;
case 10: printf("LB = %u\n",stats[10]); break;
case 11: printf("LH = %u\n",stats[11]); break;
case 12: printf("LW = %u\n",stats[12]); break;
case 13: printf("LBU = %u\n",stats[13]); break;
case 14: printf("LHU = %u\n",stats[14]); break;
case 15: printf("SB = %u\n",stats[15]); break;
case 16: printf("SH = %u\n",stats[16]); break;
case 17: printf("SW = %u\n",stats[17]); break;
case 18: printf("ADDI = %u\n",stats[18]); break;
case 19: printf("SLTI = %u\n",stats[19]); break;
case 20: printf("SLTIU = %u\n",stats[20]); break;
case 21: printf("XORI = %u\n",stats[21]); break;
case 22: printf("ORI = %u\n",stats[22]); break;
case 23: printf("ANDI = %u\n",stats[23]); break;
case 24: printf("SLLI = %u\n",stats[24]); break;
case 25: printf("SRLI = %u\n",stats[25]); break;
case 26: printf("SRAI = %u\n",stats[26]); break;
case 27: printf("ADD = %u\n",stats[27]); break;
case 28: printf("SUB = %u\n",stats[28]); break;
case 29: printf("SLL = %u\n",stats[29]); break;
case 30: printf("SLT = %u\n",stats[30]); break;
case 31: printf("SLTU = %u\n",stats[31]); break;
case 32: printf("XOR = %u\n",stats[32]); break;
case 33: printf("SRL = %u\n",stats[33]); break;
case 34: printf("SRA = %u\n",stats[34]); break;
case 35: printf("OR = %u\n",stats[35]); break;
case 36: printf("AND = %u\n",stats[36]); break;
case 37: printf("FENCE = %u\n",stats[37]); break;
case 38: printf("FENCE.I = %u\n",stats[38]); break;
case 39: printf("ECALL = %u\n",stats[39]); break;
case 40: printf("EBREAK = %u\n",stats[40]); break;
case 41: printf("CSRRW = %u\n",stats[41]); break;
case 42: printf("CSRRS = %u\n",stats[42]); break;
case 43: printf("CSRRC = %u\n",stats[43]); break;
case 44: printf("CSRRWI = %u\n",stats[44]); break;
case 45: printf("CSRRSI = %u\n",stats[45]); break;
case 46: printf("CSRRCI = %u\n",stats[46]); break;
case 47: printf("NOP* = %u\n",stats[47]); break;
case 48: printf("MUL = %u\n",stats[48]); break;
case 49: printf("MULH = %u\n",stats[49]); break;
case 50: printf("MULHSU = %u\n",stats[50]); break;
case 51: printf("MULHU = %u\n",stats[51]); break;
case 52: printf("DIV = %u\n",stats[52]); break;
case 53: printf("DIVU = %u\n",stats[53]); break;
case 54: printf("REM = %u\n",stats[54]); break;
case 55: printf("REMU = %u\n",stats[55]); break;
case 56: printf("LR.W = %u\n",stats[56]); break;
case 57: printf("SC.W = %u\n",stats[57]); break;
case 58: printf("URET = %u\n",stats[58]); break;
case 59: printf("SRET = %u\n",stats[59]); break;
case 60: printf("MRET = %u\n",stats[60]); break;
case 61: printf("WFI = %u\n",stats[61]); break;
case 62: printf("SFENCE.VMA = %u\n",stats[62]); break;
default: printf("[%i] = %u\n",i,stats[i]);
}
}
}
printf("\nMemory Reading Area %x...%x\n",minmemr,maxmemr);
if(minmemw+1) printf("Memory Writing Area %x...%x\n",minmemw,maxmemw);
else printf("Memory Writing Area NONE\n");
}
......@@ -168,7 +243,9 @@ uint8_t priv = PRV_M; /* see PRV_x */
uint8_t fs; /* MSTATUS_FS value */
uint8_t mxl; /* MXL field in MISA register */
uint64_t insn_counter;
uint64_t jump_counter=0,backward_counter=0,forward_counter=0,true_counter=0,false_counter=0;
uint64_t insn_counter = 0;
int pending_exception; /* used during MMU exception handling */
uint32_t pending_tval;
......@@ -927,6 +1004,7 @@ static uint32_t mulhu32(uint32_t a, uint32_t b)
static void dump_regs()
{
printf("\nRegisters:\n");
printf("x0 zero: %08x\n", reg[0]);
printf("x1 ra: %08x\n", reg[1]);
printf("x2 sp: %08x\n", reg[2]);
......@@ -1010,6 +1088,9 @@ void execute_instruction()
if (rd != 0)
reg[rd] = pc + 4;
next_pc = (int32_t)(pc + imm);
if(next_pc > pc) forward_counter++;
else backward_counter++;
jump_counter++;
break;
case 0x67: /* jalr */
......@@ -1023,6 +1104,9 @@ void execute_instruction()
next_pc = (int32_t)(reg[rs1] + imm) & ~1;
if (rd != 0)
reg[rd] = val;
if(next_pc > pc) forward_counter++;
else backward_counter++;
jump_counter++;
break;
case 0x63: /* BRANCH */
......@@ -1077,8 +1161,12 @@ void execute_instruction()
((insn << (11 - 7)) & (1 << 11));
imm = (imm << 19) >> 19;
next_pc = (int32_t)(pc + imm);
if(next_pc > pc) forward_counter++;
else backward_counter++;
jump_counter++;
true_counter++;
break;
}
} else false_counter++;
break;
case 0x03: /* LOAD */
......@@ -1228,6 +1316,7 @@ void execute_instruction()
#ifdef DEBUG_EXTRA
dprintf(">>> ADDI\n");
stats[18]++;
if(rd==0 && rs1==0 && imm==0) stats[47]++; /* nop */
#endif
val = (int32_t)(reg[rs1] + imm);
break;
......@@ -1313,7 +1402,6 @@ void execute_instruction()
if (imm == 1) {
funct3 = (insn >> 12) & 7;
switch(funct3) {
case 0: /* mul */
#ifdef DEBUG_EXTRA
dprintf(">>> MUL\n");
......@@ -1321,7 +1409,6 @@ void execute_instruction()
#endif
val = (int32_t)((int32_t)val * (int32_t)val2);
break;
case 1: /* mulh */
#ifdef DEBUG_EXTRA
dprintf(">>> MULH\n");
......@@ -1329,7 +1416,6 @@ void execute_instruction()
#endif
val = (int32_t)mulh32(val, val2);
break;
case 2:/* mulhsu */
#ifdef DEBUG_EXTRA
dprintf(">>> MULHSU\n");
......@@ -1337,7 +1423,6 @@ void execute_instruction()
#endif
val = (int32_t)mulhsu32(val, val2);
break;
case 3:/* mulhu */
#ifdef DEBUG_EXTRA
dprintf(">>> MULHU\n");
......@@ -1345,7 +1430,6 @@ void execute_instruction()
#endif
val = (int32_t)mulhu32(val, val2);
break;
case 4:/* div */
#ifdef DEBUG_EXTRA
dprintf(">>> DIV\n");
......@@ -1353,7 +1437,6 @@ void execute_instruction()
#endif
val = div32(val, val2);
break;
case 5:/* divu */
#ifdef DEBUG_EXTRA
dprintf(">>> DIVU\n");
......@@ -1361,7 +1444,6 @@ void execute_instruction()
#endif
val = (int32_t)divu32(val, val2);
break;
case 6:/* rem */
#ifdef DEBUG_EXTRA
dprintf(">>> REM\n");
......@@ -1369,7 +1451,6 @@ void execute_instruction()
#endif
val = rem32(val, val2);
break;
case 7:/* remu */
#ifdef DEBUG_EXTRA
dprintf(">>> REMU\n");
......@@ -1377,7 +1458,6 @@ void execute_instruction()
#endif
val = (int32_t)remu32(val, val2);
break;
default:
raise_exception(CAUSE_ILLEGAL_INSTRUCTION, insn);
return;
......@@ -2049,9 +2129,10 @@ int main(int argc, char** argv)
#if 1
printf("\n");
printf(">>> Instruction count: %llu\n",(long long unsigned)insn_counter);
printf(">>> Execution time: %llu ns\n",(long long unsigned)ns2-ns1);
printf(">>> Instructions per second: %llu\n",(long long)insn_counter*1000000000LL/(ns2-ns1));
printf(">>> Instruction count: %llu (IPS=%llu)\n",(long long unsigned)insn_counter,(long long)insn_counter*1000000000LL/(ns2-ns1));
printf(">>> Jumps: %llu (%2.2lf%%) - %llu forwards, %llu backwards\n",(long long unsigned)jump_counter,jump_counter*100.0/insn_counter,(long long unsigned)forward_counter,(long long unsigned)backward_counter);
printf(">>> Branching T=%llu (%2.2lf%%) F=%llu (%2.2lf%%)\n",(long long unsigned)true_counter,true_counter*100.0/(true_counter+false_counter),(long long unsigned)false_counter,false_counter*100.0/(true_counter+false_counter));
printf("\n");
#endif
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment