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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_46/] [or1ksim/] [cpu/] [common/] [stats.c] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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 30 lampret
 
27 2 cvs
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 6 lampret
struct cachestats_entry ic_stats;       /* instruction cache stats */
35
struct cachestats_entry dc_stats;       /* data cache stats */
36
struct raw_stats raw_stats;             /* RAW hazard stats */
37 2 cvs
 
38
/* Dependency */
39
 
40
int check_depend()
41
{
42
        debug("check_depend");
43
        if (depend_operands(icomplet[0].dependdst, iqueue[0].dependsrc1) +
44
            depend_operands(icomplet[0].dependdst, iqueue[0].dependsrc2))
45
                return 1;
46
        else
47
                return 0;
48
}
49
 
50
void addsstats(char *item, int cnt_dynamic, int cnt_static)
51
{
52
        int i = 0;
53
 
54
        while(strcmp(sstats[i].insn, item) && (sstats[i].cnt_static > 0) &&
55
              (sstats[i].cnt_static > 0) && (i < SSTATS_LEN))
56
                i++;
57
 
58
        if (i >= SSTATS_LEN - 1) return;
59
 
60
        if (strcmp(sstats[i].insn, item) == 0) {
61
                sstats[i].cnt_dynamic += cnt_dynamic;
62
                sstats[i].cnt_static += cnt_static;
63
        }
64
        else {
65
                strcpy(sstats[i].insn, item);
66
                sstats[i].cnt_dynamic = cnt_dynamic;
67
                sstats[i].cnt_static = cnt_static;
68
        }
69
}
70
 
71
void adddstats(char *item1, char *item2, int cnt_dynamic, int depend)
72
{
73
        int i = 0;
74
 
75
        debug("adddstats start\n");
76
 
77
        while((strcmp(dstats[i].insn1, item1) || strcmp(dstats[i].insn2, item2)) &&
78
              (strlen(dstats[i].insn1)) &&
79
              (i < DSTATS_LEN))
80
                i++;
81
 
82
        if (i >= DSTATS_LEN - 1) return;
83
 
84
        if ((strcmp(dstats[i].insn1, item1) == 0) &&
85
            (strcmp(dstats[i].insn2, item2) == 0)) {
86
                dstats[i].cnt_dynamic += cnt_dynamic;
87
                dstats[i].depend += depend;
88
        }
89
        else {
90
                strcpy(dstats[i].insn1, item1);
91
                strcpy(dstats[i].insn2, item2);
92
                dstats[i].cnt_dynamic = cnt_dynamic;
93
                dstats[i].depend = depend;
94
        }
95
}
96
 
97
void addfstats(enum insn_type item1, enum insn_type item2, int cnt_dynamic, int depend)
98
{
99
        int i = 0;
100
 
101
        while(((fstats[i].insn1 != item1) || (fstats[i].insn2 != item2)) &&
102
              (fstats[i].insn1 != unknown) &&
103
              (i < FSTATS_LEN))
104
                i++;
105
 
106
        if (i >= FSTATS_LEN - 1) return;
107
 
108
        if ((fstats[i].insn1 == item1) &&
109
            (fstats[i].insn2 == item2)) {
110
                fstats[i].cnt_dynamic += cnt_dynamic;
111
                fstats[i].depend += depend;
112
        }
113
        else {
114
                fstats[i].insn1 = item1;
115
                fstats[i].insn2 = item2;
116
                fstats[i].cnt_dynamic = cnt_dynamic;
117
                fstats[i].depend = depend;
118
        }
119
}
120
 
121
void initstats()
122
{
123
        memset(sstats, 0, sizeof(sstats));
124
        memset(dstats, 0, sizeof(dstats));
125
        memset(fstats, 0, sizeof(fstats));
126
        memset(&mstats, 0, sizeof(mstats));
127 6 lampret
        memset(&ic_stats, 0, sizeof(ic_stats));
128
        memset(&dc_stats, 0, sizeof(dc_stats));
129
        memset(&raw_stats, 0, sizeof(raw_stats));
130 2 cvs
}
131
 
132 6 lampret
void printstats(int which)
133 2 cvs
{
134
        int i, all = 0, dependall = 0;
135
 
136
        for(i = 0; i < SSTATS_LEN; i++)
137
                all += sstats[i].cnt_static;
138
 
139
        for(i = 0; i < SSTATS_LEN; i++)
140 6 lampret
                if (sstats[i].cnt_static && (which == 1))
141 2 cvs
                        printf(" %s\t\tused %6dx (%2d%%)\n", sstats[i].insn, sstats[i].cnt_static, (sstats[i].cnt_static * 100)/all);
142
 
143
        printf("SUM: %d instructions (static, single stats)\n", all);
144 6 lampret
 
145 2 cvs
        all = 0;
146 6 lampret
 
147 2 cvs
        for(i = 0; i < SSTATS_LEN; i++)
148
                all += sstats[i].cnt_dynamic;
149
 
150
        for(i = 0; i < SSTATS_LEN; i++)
151 6 lampret
                if (sstats[i].cnt_dynamic && (which == 2))
152 2 cvs
                        printf(" %s\t\tused %6dx (%2d%%)\n", sstats[i].insn, sstats[i].cnt_dynamic, (sstats[i].cnt_dynamic * 100)/all);
153
 
154
        printf("SUM: %d instructions (dynamic, single stats)\n", all);
155
 
156
        all = 0;
157
        dependall = 0;
158
        for(i = 0; i < DSTATS_LEN; i++) {
159
                all += dstats[i].cnt_dynamic;
160
                dependall += dstats[i].depend;
161
        }
162
 
163
        for(i = 0; i < DSTATS_LEN; i++)
164 6 lampret
                if (dstats[i].cnt_dynamic && (which == 3)) {
165 2 cvs
                        printf(" %s, %s ", dstats[i].insn1, dstats[i].insn2);
166
                        printf("\t\t\t%6dx (%2d%%)", dstats[i].cnt_dynamic, (dstats[i].cnt_dynamic * 100)/all);
167
                        printf("   depend: %3d%%\n", (dstats[i].depend * 100) / dstats[i].cnt_dynamic);
168
                }
169
 
170
        printf("SUM: %d instructions (dynamic, dependency stats)  depend: %d%%\n", all, (dependall * 100) / all);
171
 
172
        all = 0;
173
        dependall = 0;
174
        for(i = 0; i < FSTATS_LEN; i++) {
175
                all += fstats[i].cnt_dynamic;
176
                dependall += fstats[i].depend;
177
        }
178
 
179
        for(i = 0; i < FSTATS_LEN; i++)
180 6 lampret
                if (fstats[i].cnt_dynamic && (which == 4)) {
181 2 cvs
                        printf(" %s,", func_unit_str[fstats[i].insn1]);
182
                        printf(" %s", func_unit_str[fstats[i].insn2]);
183
                        printf("\t\t\t%6dx (%2d%%)", fstats[i].cnt_dynamic, (fstats[i].cnt_dynamic * 100)/all);
184
                        printf("   depend: %3d%%\n", (fstats[i].depend * 100) / fstats[i].cnt_dynamic);
185
                }
186
 
187 6 lampret
        for(i = 0; (i < RAW_RANGE) && (which == 5); i++)
188
                printf(" Register set and reused in %d. cycle: %d cases\n", i, raw_stats.range[i]);
189
 
190 30 lampret
        printf("SUM: %d instructions (dynamic, functional units stats)  depend: %d%%\n", all, (dependall * 100) / SD(all));
191 2 cvs
        printf("Byte ADD: %d instructions\n", mstats.byteadd);
192 30 lampret
        printf("bnf: %d (%d%%) taken,", mstats.beqz.taken, (mstats.beqz.taken * 100) / SD(mstats.beqz.taken + mstats.beqz.nottaken));
193
        printf(" %d (%d%%) not taken,", mstats.beqz.nottaken, (mstats.beqz.nottaken * 100) / SD(mstats.beqz.taken + mstats.beqz.nottaken));
194
        printf(" %d (%d%%) forward,", mstats.beqz.forward, (mstats.beqz.forward * 100) / SD(mstats.beqz.forward + mstats.beqz.backward));
195
        printf(" %d (%d%%) backward\n", mstats.beqz.backward, (mstats.beqz.backward * 100) / SD(mstats.beqz.forward + mstats.beqz.backward));
196
        printf("bf: %d (%d%%) taken,", mstats.bnez.taken, (mstats.bnez.taken * 100) / SD(mstats.bnez.taken + mstats.bnez.nottaken));
197
        printf(" %d (%d%%) not taken,", mstats.bnez.nottaken, (mstats.bnez.nottaken * 100) / SD(mstats.bnez.taken + mstats.bnez.nottaken));
198
        printf(" %d (%d%%) forward,", mstats.bnez.forward, (mstats.bnez.forward * 100) / SD(mstats.bnez.forward + mstats.bnez.backward));
199
        printf(" %d (%d%%) backward\n", mstats.bnez.backward, (mstats.bnez.backward * 100) / SD(mstats.bnez.forward + mstats.bnez.backward));
200
        printf("StaticBP bnf: correct %d%% (forward)\n", (mstats.sbp_bnf.correct * 100) / SD(mstats.sbp_bnf.all));
201
        printf("StaticBP bf: correct %d%% (backward)\n", (mstats.sbp_bf.correct * 100) / SD(mstats.sbp_bf.all));
202
        printf("BPB: hit %d (correct %d%%), miss %d\n", mstats.bpb.hit, (mstats.bpb.correct * 100) / SD(mstats.bpb.hit), mstats.bpb.miss);
203
        printf("BTIC: hit %d(%d%%), miss %d\n", mstats.btic.hit, (mstats.btic.hit * 100) / SD(mstats.btic.hit + mstats.btic.miss), mstats.btic.miss);
204
        printf("IC read:  hit %d(%d%%), miss %d\n", ic_stats.readhit, (ic_stats.readhit * 100) / SD(ic_stats.readhit + ic_stats.readmiss), ic_stats.readmiss);
205
        printf("DC read:  hit %d(%d%%), miss %d\n", dc_stats.readhit, (dc_stats.readhit * 100) / SD(dc_stats.readhit + dc_stats.readmiss), dc_stats.readmiss);
206
        printf("DC write: hit %d(%d%%), miss %d\n", dc_stats.writehit, (dc_stats.writehit * 100) / SD(dc_stats.writehit + dc_stats.writemiss), dc_stats.writemiss);
207 2 cvs
}

powered by: WebSVN 2.1.0

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