X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cpu%2Fsh2%2Fmame%2Fsh2pico.c;h=d78831600e6a5625ba66022d07f903c073a4b53d;hb=ed4402a7dfd12dbbf34c547b438a671ae8114197;hp=fe5b7d7f559f621a7c4b40c2e10d425dfa091f35;hpb=679af8a3f466a2a4a20f58e4181a231fb73e9836;p=picodrive.git diff --git a/cpu/sh2/mame/sh2pico.c b/cpu/sh2/mame/sh2pico.c index fe5b7d7..d788316 100644 --- a/cpu/sh2/mame/sh2pico.c +++ b/cpu/sh2/mame/sh2pico.c @@ -8,12 +8,12 @@ typedef unsigned int UINT32; typedef unsigned short UINT16; typedef unsigned char UINT8; -#define RB(a) p32x_sh2_read8(a,sh2->is_slave) -#define RW(a) p32x_sh2_read16(a,sh2->is_slave) -#define RL(a) p32x_sh2_read32(a,sh2->is_slave) -#define WB(a,d) p32x_sh2_write8(a,d,sh2->is_slave) -#define WW(a,d) p32x_sh2_write16(a,d,sh2->is_slave) -#define WL(a,d) p32x_sh2_write32(a,d,sh2->is_slave) +#define RB(a) p32x_sh2_read8(a,sh2) +#define RW(a) p32x_sh2_read16(a,sh2) +#define RL(a) p32x_sh2_read32(a,sh2) +#define WB(a,d) p32x_sh2_write8(a,d,sh2) +#define WW(a,d) p32x_sh2_write16(a,d,sh2) +#define WL(a,d) p32x_sh2_write32(a,d,sh2) // some stuff from sh2comn.h #define T 0x00000001 @@ -31,18 +31,45 @@ typedef unsigned char UINT8; #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_TMP +#ifndef DRC_SH2 -void sh2_execute(SH2 *sh2_, int cycles) +int sh2_execute(SH2 *sh2_, int cycles) { sh2 = sh2_; - sh2->cycles_aim += cycles; - sh2->icount = cycles = sh2->cycles_aim - sh2->cycles_done; + sh2->icount = cycles; if (sh2->icount <= 0) - return; + return cycles; + + sh2->cycles_timeslice = cycles; do { @@ -83,25 +110,32 @@ void sh2_execute(SH2 *sh2_, int cycles) default: op1111(opcode); break; } - if (sh2->test_irq && !sh2->delay) + sh2->icount--; + + if (sh2->test_irq && !sh2->delay && sh2->pending_level > ((sh2->sr >> 4) & 0x0f)) { - if (sh2->pending_irl > sh2->pending_int_irq) - sh2_irl_irq(sh2, sh2->pending_irl); - else - sh2_internal_irq(sh2, sh2->pending_int_irq, sh2->pending_int_vector); + int level = sh2->pending_level; + int vector = sh2->irq_callback(sh2, level); + sh2_do_irq(sh2, level, vector); sh2->test_irq = 0; } - sh2->icount--; + } while (sh2->icount > 0 || sh2->delay); /* can't interrupt before delay */ - sh2->cycles_done += cycles - sh2->icount; + return sh2->cycles_timeslice - sh2->icount; } -#else // DRC_TMP +#else // DRC_SH2 -// tmp -void __attribute__((regparm(2))) sh2_do_op(SH2 *sh2_, int opcode) +#ifdef __i386__ +#define REGPARM(x) __attribute__((regparm(x))) +#else +#define REGPARM(x) +#endif + +// drc debug +void REGPARM(2) sh2_do_op(SH2 *sh2_, int opcode) { sh2 = sh2_; sh2->pc += 2; @@ -125,16 +159,60 @@ void __attribute__((regparm(2))) sh2_do_op(SH2 *sh2_, int opcode) case 14<<12: op1110(opcode); break; default: op1111(opcode); break; } +} - if (sh2->test_irq) - { - if (sh2->pending_irl > sh2->pending_int_irq) - sh2_irl_irq(sh2, sh2->pending_irl); - else - sh2_internal_irq(sh2, sh2->pending_int_irq, sh2->pending_int_vector); - sh2->test_irq = 0; +#endif + +#ifdef SH2_STATS +#include +#include +#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