From 8f5f2dd5a70f47322614eda6f97304808447199c Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 10 Jan 2015 03:51:44 +0200 Subject: some random improvements --- plugins/gpulib/gpu.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'plugins/gpulib') diff --git a/plugins/gpulib/gpu.c b/plugins/gpulib/gpu.c index 337e27a..c9b05d4 100644 --- a/plugins/gpulib/gpu.c +++ b/plugins/gpulib/gpu.c @@ -13,8 +13,16 @@ #include "gpu.h" #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#ifdef __GNUC__ #define unlikely(x) __builtin_expect((x), 0) +#define preload __builtin_prefetch #define noinline __attribute__((noinline)) +#else +#define unlikely(x) +#define preload(...) +#define noinline +#error huh +#endif #define gpu_log(fmt, ...) \ printf("%d:%03d: " fmt, *gpu.state.frame_count, *gpu.state.hcnt, ##__VA_ARGS__) @@ -518,6 +526,8 @@ long GPUdmaChain(uint32_t *rambase, uint32_t start_addr) int len, left, count; long cpu_cycles = 0; + preload(rambase + (start_addr & 0x1fffff) / 4); + if (unlikely(gpu.cmd_len > 0)) flush_cmd_buffer(); @@ -537,6 +547,8 @@ long GPUdmaChain(uint32_t *rambase, uint32_t start_addr) list = rambase + (addr & 0x1fffff) / 4; len = list[0] >> 24; addr = list[0] & 0xffffff; + preload(rambase + (addr & 0x1fffff) / 4); + cpu_cycles += 10; if (len > 0) cpu_cycles += 5 + len; -- cgit v1.2.3 From 09159d99cd07a084d8643f87c6c23e86c79060ff Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 10 Jan 2015 21:54:34 +0200 Subject: gpulib: use more conservative loop detection the old one was causing too many cache misses --- plugins/gpulib/gpu.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'plugins/gpulib') diff --git a/plugins/gpulib/gpu.c b/plugins/gpulib/gpu.c index c9b05d4..0e6fe63 100644 --- a/plugins/gpulib/gpu.c +++ b/plugins/gpulib/gpu.c @@ -521,7 +521,7 @@ void GPUwriteData(uint32_t data) long GPUdmaChain(uint32_t *rambase, uint32_t start_addr) { - uint32_t addr, *list; + uint32_t addr, *list, ld_addr = 0; uint32_t *llist_entry = NULL; int len, left, count; long cpu_cycles = 0; @@ -542,7 +542,7 @@ long GPUdmaChain(uint32_t *rambase, uint32_t start_addr) log_io("gpu_dma_chain\n"); addr = start_addr & 0xffffff; - for (count = 0; addr != 0xffffff; count++) + for (count = 0; (addr & 0x800000) == 0; count++) { list = rambase + (addr & 0x1fffff) / 4; len = list[0] >> 24; @@ -555,28 +555,37 @@ long GPUdmaChain(uint32_t *rambase, uint32_t start_addr) log_io(".chain %08x #%d\n", (list - rambase) * 4, len); - // loop detection marker - // (bit23 set causes DMA error on real machine, so - // unlikely to be ever set by the game) - list[0] |= 0x800000; - if (len) { left = do_cmd_buffer(list + 1, len); if (left) log_anomaly("GPUdmaChain: discarded %d/%d words\n", left, len); } - if (addr & 0x800000) - break; + #define LD_THRESHOLD (8*1024) + if (count >= LD_THRESHOLD) { + if (count == LD_THRESHOLD) { + ld_addr = addr; + continue; + } + + // loop detection marker + // (bit23 set causes DMA error on real machine, so + // unlikely to be ever set by the game) + list[0] |= 0x800000; + } } - // remove loop detection markers - addr = start_addr & 0x1fffff; - while (count-- > 0) { - list = rambase + addr / 4; - addr = list[0] & 0x1fffff; - list[0] &= ~0x800000; + if (ld_addr != 0) { + // remove loop detection markers + count -= LD_THRESHOLD + 2; + addr = ld_addr & 0x1fffff; + while (count-- > 0) { + list = rambase + addr / 4; + addr = list[0] & 0x1fffff; + list[0] &= ~0x800000; + } } + if (llist_entry) *llist_entry &= ~0x800000; -- cgit v1.2.3