Commit abb4b1d1 authored by Alexander Shabarshin's avatar Alexander Shabarshin

5 top instructions

parent c055a86e
/* Modified by Shaos <me@shaos.net>
24-DEC-2018 - Find top 5 instructions in DEBUG_EXTRA mode
20-DEC-2018 - More statistical points
22-NOV-2018 - Added saving HEX file with copy of the code in DEBUG_OUTPUT mode
21-NOV-2018 - Some statistics added in DEBUG_EXTRA mode
......@@ -99,11 +100,20 @@ original copyright:
#define TRUE (-1)
#ifdef DEBUG_EXTRA
uint32_t minmemr,maxmemr,minmemw,maxmemw;
#define STATS_NUM 64
unsigned int stats[STATS_NUM];
unsigned int stats[STATS_NUM],top[5],itop[5];
char statnames[64][16] = { "LUI","AUIPC","JAL","JALR","BEQ","BNE","BLT","BGE",
"BLTU","BGEU","LB","LH","LW","LBU","LHU","SB","SH","SW","ADDI","SLTI","SLTIU",
"XORI","ORI","ANDI","SLLI","SRLI","SRAI","ADD","SUB","SLL","SLT","SLTU","XOR",
"SRL","SRA","OR","AND","FENCE","FENCE.I","ECALL","EBREAK","CSRRW","CSRRS",
"CSRRC","CSRRWI","CSRRSI","CSRRCI","LI*","MUL","MULH","MULHSU","MULHU","DIV",
"DIVU","REM","REMU","LR.W","SC.W","URET","SRET","MRET","WFI","SFENCE.VMA",""
};
void init_stats(void)
{
......@@ -112,86 +122,59 @@ void init_stats(void)
maxmemr = maxmemw = 0;
}
void print_stats(void)
void print_stats(uint64_t total)
{
printf("\nInstructions stat:\n");
printf("\nInstructions Stat:\n");
top[0] = top[1] = top[2] = top[3] = top[4] = stats[0];
itop[0] = itop[1] = itop[2] = itop[3] = itop[4] = 0;
for(int i=0;i<STATS_NUM;i++)
{
if(stats[i]>top[0])
{
top[4]=top[3];itop[4]=itop[3];
top[3]=top[2];itop[3]=itop[2];
top[2]=top[1];itop[2]=itop[1];
top[1]=top[0];itop[1]=itop[0];
top[0]=stats[i];itop[0]=i;
}
else if(stats[i]>top[1])
{
top[4]=top[3];itop[4]=itop[3];
top[3]=top[2];itop[3]=itop[2];
top[2]=top[1];itop[2]=itop[1];
top[1]=stats[i];itop[1]=i;
}
else if(stats[i]>top[2])
{
top[4]=top[3];itop[4]=itop[3];
top[3]=top[2];itop[3]=itop[2];
top[2]=stats[i];itop[2]=i;
}
else if(stats[i]>top[3])
{
top[4]=top[3];itop[4]=itop[3];
top[3]=stats[i];itop[3]=i;
}
else if(stats[i]>top[4])
{
top[4]=stats[i];itop[4]=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]);
}
if(i<63) printf("%s\t= %u\n",statnames[i],stats[i]);
else printf("[%i] = %u\n",i,stats[i]);
}
}
printf("\nFive Most Frequent:\n");
for(int j=0;j<5;j++)
{
printf("%i) %s\t= %u (%2.2lf%%)\n",j,statnames[itop[j]],top[j],top[j]*100.0/(double)total);
}
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");
}
#endif
#ifdef DEBUG_OUTPUT
......@@ -1316,7 +1299,7 @@ void execute_instruction()
#ifdef DEBUG_EXTRA
dprintf(">>> ADDI\n");
stats[18]++;
if(rd==0 && rs1==0 && imm==0) stats[47]++; /* nop */
if(rs1==0) stats[47]++; /* li */
#endif
val = (int32_t)(reg[rs1] + imm);
break;
......@@ -2124,7 +2107,7 @@ int main(int argc, char** argv)
#ifdef DEBUG_EXTRA
dump_regs();
print_stats();
print_stats(insn_counter);
#endif
#if 1
......
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