1 |
2 |
cvs |
/* stats.c -- Various statistics about instruction scheduling etc.
|
2 |
|
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
3 |
|
|
|
4 |
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
5 |
|
|
|
6 |
|
|
This program is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
9 |
|
|
(at your option) any later version.
|
10 |
|
|
|
11 |
|
|
This program is distributed in the hope that it will be useful,
|
12 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
|
|
GNU General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with this program; if not, write to the Free Software
|
18 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
19 |
|
|
|
20 |
|
|
#include <stdio.h>
|
21 |
|
|
#include <ctype.h>
|
22 |
|
|
#include <string.h>
|
23 |
|
|
|
24 |
|
|
#include "abstract.h"
|
25 |
|
|
#include "stats.h"
|
26 |
|
|
|
27 |
|
|
const char func_unit_str[30][30] = { "unknown", "arith", "shift", "compare",
|
28 |
|
|
"branch", "jump", "load", "store", "movimm", "move", "extend", "nop" };
|
29 |
|
|
|
30 |
|
|
struct dstats_entry dstats[DSTATS_LEN]; /* dependency stats */
|
31 |
|
|
struct sstats_entry sstats[SSTATS_LEN]; /* single stats */
|
32 |
|
|
struct fstats_entry fstats[FSTATS_LEN]; /* functional units stats */
|
33 |
|
|
struct mstats_entry mstats; /* misc units stats */
|
34 |
|
|
|
35 |
|
|
/* Dependency */
|
36 |
|
|
|
37 |
|
|
int check_depend()
|
38 |
|
|
{
|
39 |
|
|
debug("check_depend");
|
40 |
|
|
if (depend_operands(icomplet[0].dependdst, iqueue[0].dependsrc1) +
|
41 |
|
|
depend_operands(icomplet[0].dependdst, iqueue[0].dependsrc2))
|
42 |
|
|
return 1;
|
43 |
|
|
else
|
44 |
|
|
return 0;
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
void addsstats(char *item, int cnt_dynamic, int cnt_static)
|
48 |
|
|
{
|
49 |
|
|
int i = 0;
|
50 |
|
|
|
51 |
|
|
while(strcmp(sstats[i].insn, item) && (sstats[i].cnt_static > 0) &&
|
52 |
|
|
(sstats[i].cnt_static > 0) && (i < SSTATS_LEN))
|
53 |
|
|
i++;
|
54 |
|
|
|
55 |
|
|
if (i >= SSTATS_LEN - 1) return;
|
56 |
|
|
|
57 |
|
|
if (strcmp(sstats[i].insn, item) == 0) {
|
58 |
|
|
sstats[i].cnt_dynamic += cnt_dynamic;
|
59 |
|
|
sstats[i].cnt_static += cnt_static;
|
60 |
|
|
}
|
61 |
|
|
else {
|
62 |
|
|
strcpy(sstats[i].insn, item);
|
63 |
|
|
sstats[i].cnt_dynamic = cnt_dynamic;
|
64 |
|
|
sstats[i].cnt_static = cnt_static;
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
void adddstats(char *item1, char *item2, int cnt_dynamic, int depend)
|
69 |
|
|
{
|
70 |
|
|
int i = 0;
|
71 |
|
|
|
72 |
|
|
debug("adddstats start\n");
|
73 |
|
|
|
74 |
|
|
while((strcmp(dstats[i].insn1, item1) || strcmp(dstats[i].insn2, item2)) &&
|
75 |
|
|
(strlen(dstats[i].insn1)) &&
|
76 |
|
|
(i < DSTATS_LEN))
|
77 |
|
|
i++;
|
78 |
|
|
|
79 |
|
|
if (i >= DSTATS_LEN - 1) return;
|
80 |
|
|
|
81 |
|
|
if ((strcmp(dstats[i].insn1, item1) == 0) &&
|
82 |
|
|
(strcmp(dstats[i].insn2, item2) == 0)) {
|
83 |
|
|
dstats[i].cnt_dynamic += cnt_dynamic;
|
84 |
|
|
dstats[i].depend += depend;
|
85 |
|
|
}
|
86 |
|
|
else {
|
87 |
|
|
strcpy(dstats[i].insn1, item1);
|
88 |
|
|
strcpy(dstats[i].insn2, item2);
|
89 |
|
|
dstats[i].cnt_dynamic = cnt_dynamic;
|
90 |
|
|
dstats[i].depend = depend;
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
void addfstats(enum insn_type item1, enum insn_type item2, int cnt_dynamic, int depend)
|
95 |
|
|
{
|
96 |
|
|
int i = 0;
|
97 |
|
|
|
98 |
|
|
while(((fstats[i].insn1 != item1) || (fstats[i].insn2 != item2)) &&
|
99 |
|
|
(fstats[i].insn1 != unknown) &&
|
100 |
|
|
(i < FSTATS_LEN))
|
101 |
|
|
i++;
|
102 |
|
|
|
103 |
|
|
if (i >= FSTATS_LEN - 1) return;
|
104 |
|
|
|
105 |
|
|
if ((fstats[i].insn1 == item1) &&
|
106 |
|
|
(fstats[i].insn2 == item2)) {
|
107 |
|
|
fstats[i].cnt_dynamic += cnt_dynamic;
|
108 |
|
|
fstats[i].depend += depend;
|
109 |
|
|
}
|
110 |
|
|
else {
|
111 |
|
|
fstats[i].insn1 = item1;
|
112 |
|
|
fstats[i].insn2 = item2;
|
113 |
|
|
fstats[i].cnt_dynamic = cnt_dynamic;
|
114 |
|
|
fstats[i].depend = depend;
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
void initstats()
|
119 |
|
|
{
|
120 |
|
|
memset(sstats, 0, sizeof(sstats));
|
121 |
|
|
memset(dstats, 0, sizeof(dstats));
|
122 |
|
|
memset(fstats, 0, sizeof(fstats));
|
123 |
|
|
memset(&mstats, 0, sizeof(mstats));
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
void printstats()
|
127 |
|
|
{
|
128 |
|
|
int i, all = 0, dependall = 0;
|
129 |
|
|
|
130 |
|
|
for(i = 0; i < SSTATS_LEN; i++)
|
131 |
|
|
all += sstats[i].cnt_static;
|
132 |
|
|
|
133 |
|
|
for(i = 0; i < SSTATS_LEN; i++)
|
134 |
|
|
if (sstats[i].cnt_static)
|
135 |
|
|
printf(" %s\t\tused %6dx (%2d%%)\n", sstats[i].insn, sstats[i].cnt_static, (sstats[i].cnt_static * 100)/all);
|
136 |
|
|
|
137 |
|
|
printf("SUM: %d instructions (static, single stats)\n", all);
|
138 |
|
|
|
139 |
|
|
all = 0;
|
140 |
|
|
for(i = 0; i < SSTATS_LEN; i++)
|
141 |
|
|
all += sstats[i].cnt_dynamic;
|
142 |
|
|
|
143 |
|
|
for(i = 0; i < SSTATS_LEN; i++)
|
144 |
|
|
if (sstats[i].cnt_dynamic)
|
145 |
|
|
printf(" %s\t\tused %6dx (%2d%%)\n", sstats[i].insn, sstats[i].cnt_dynamic, (sstats[i].cnt_dynamic * 100)/all);
|
146 |
|
|
|
147 |
|
|
printf("SUM: %d instructions (dynamic, single stats)\n", all);
|
148 |
|
|
|
149 |
|
|
all = 0;
|
150 |
|
|
dependall = 0;
|
151 |
|
|
for(i = 0; i < DSTATS_LEN; i++) {
|
152 |
|
|
all += dstats[i].cnt_dynamic;
|
153 |
|
|
dependall += dstats[i].depend;
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
for(i = 0; i < DSTATS_LEN; i++)
|
157 |
|
|
if (dstats[i].cnt_dynamic) {
|
158 |
|
|
printf(" %s, %s ", dstats[i].insn1, dstats[i].insn2);
|
159 |
|
|
printf("\t\t\t%6dx (%2d%%)", dstats[i].cnt_dynamic, (dstats[i].cnt_dynamic * 100)/all);
|
160 |
|
|
printf(" depend: %3d%%\n", (dstats[i].depend * 100) / dstats[i].cnt_dynamic);
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
printf("SUM: %d instructions (dynamic, dependency stats) depend: %d%%\n", all, (dependall * 100) / all);
|
164 |
|
|
|
165 |
|
|
all = 0;
|
166 |
|
|
dependall = 0;
|
167 |
|
|
for(i = 0; i < FSTATS_LEN; i++) {
|
168 |
|
|
all += fstats[i].cnt_dynamic;
|
169 |
|
|
dependall += fstats[i].depend;
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
for(i = 0; i < FSTATS_LEN; i++)
|
173 |
|
|
if (fstats[i].cnt_dynamic) {
|
174 |
|
|
printf(" %s,", func_unit_str[fstats[i].insn1]);
|
175 |
|
|
printf(" %s", func_unit_str[fstats[i].insn2]);
|
176 |
|
|
printf("\t\t\t%6dx (%2d%%)", fstats[i].cnt_dynamic, (fstats[i].cnt_dynamic * 100)/all);
|
177 |
|
|
printf(" depend: %3d%%\n", (fstats[i].depend * 100) / fstats[i].cnt_dynamic);
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
printf("SUM: %d instructions (dynamic, functional units stats) depend: %d%%\n", all, (dependall * 100) / all);
|
181 |
|
|
printf("Byte ADD: %d instructions\n", mstats.byteadd);
|
182 |
|
|
printf("BEQZ: %d (%d%%) taken,", mstats.beqz.taken, (mstats.beqz.taken * 100) / (mstats.beqz.taken + mstats.beqz.nottaken));
|
183 |
|
|
printf(" %d (%d%%) not taken\n", mstats.beqz.nottaken, (mstats.beqz.nottaken * 100) / (mstats.beqz.taken + mstats.beqz.nottaken));
|
184 |
|
|
printf("BNEZ: %d (%d%%) taken,", mstats.bnez.taken, (mstats.bnez.taken * 100) / (mstats.bnez.taken + mstats.bnez.nottaken));
|
185 |
|
|
printf(" %d (%d%%) not taken\n", mstats.bnez.nottaken, (mstats.bnez.nottaken * 100) / (mstats.bnez.taken + mstats.bnez.nottaken));
|
186 |
|
|
printf("BPB: hit %d (correct %d%%), miss %d\n", mstats.bpb.hit, (mstats.bpb.correct * 100) / mstats.bpb.hit, mstats.bpb.miss);
|
187 |
|
|
printf("BTIC: hit %d(%d%%), miss %d\n", mstats.btic.hit, (mstats.btic.hit * 100) / (mstats.btic.hit + mstats.btic.miss), mstats.btic.miss);
|
188 |
|
|
}
|