#define sh2_icount sh2->icount
+#ifdef SH2_STATS
+static SH2 sh2_stats;
+static unsigned int op_refs[0x10000];
+# define LRN 1
+# define LRM 2
+# define LRNM (LRN|LRM)
+# define rlog(rnm) { \
+ int op = opcode; \
+ if ((rnm) & LRN) { \
+ op &= ~0x0f00; \
+ sh2_stats.r[Rn]++; \
+ } \
+ if ((rnm) & LRM) { \
+ op &= ~0x00f0; \
+ sh2_stats.r[Rm]++; \
+ } \
+ op_refs[op]++; \
+}
+# define rlog1(x) sh2_stats.r[x]++
+# define rlog2(x1,x2) sh2_stats.r[x1]++; sh2_stats.r[x2]++
+#else
+# define rlog(x)
+# define rlog1(...)
+# define rlog2(...)
+#endif
+
#include "sh2.c"
#ifndef DRC_SH2
#endif
+#ifdef SH2_STATS
+#include <stdio.h>
+#include <string.h>
+#include "sh2dasm.h"
+
+void sh2_dump_stats(void)
+{
+ static const char *rnames[] = {
+ "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7",
+ "R8", "R9", "R10", "R11", "R12", "R13", "R14", "SP",
+ "PC", "", "PR", "SR", "GBR", "VBR", "MACH", "MACL"
+ };
+ long long total;
+ char buff[64];
+ int u, i;
+
+ // dump reg usage
+ total = 0;
+ for (i = 0; i < 24; i++)
+ total += sh2_stats.r[i];
+
+ for (i = 0; i < 24; i++) {
+ if (i == 16 || i == 17 || i == 19)
+ continue;
+ printf("r %6.3f%% %-4s %9d\n", (double)sh2_stats.r[i] * 100.0 / total,
+ rnames[i], sh2_stats.r[i]);
+ }
+
+ memset(&sh2_stats, 0, sizeof(sh2_stats));
+
+ // dump ops
+ printf("\n");
+ total = 0;
+ for (i = 0; i < 0x10000; i++)
+ total += op_refs[i];
+
+ for (u = 0; u < 16; u++) {
+ int max = 0, op = 0;
+ for (i = 0; i < 0x10000; i++) {
+ if (op_refs[i] > max) {
+ max = op_refs[i];
+ op = i;
+ }
+ }
+ DasmSH2(buff, 0, op);
+ printf("i %6.3f%% %9d %s\n", (double)op_refs[op] * 100.0 / total,
+ op_refs[op], buff);
+ op_refs[op] = 0;
+ }
+ memset(op_refs, 0, sizeof(op_refs));
+}
+#endif
+