From 0308f136c7e195bd2e245dd3676d559b97595ceb Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 18 Nov 2014 04:29:16 -0800 Subject: [PATCH] GBA Memory: partially unroll loops for LDM/STM and add UNLIKELYs --- src/gba/gba-memory.c | 50 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/src/gba/gba-memory.c b/src/gba/gba-memory.c index ad359a413..fe5c65c7c 100644 --- a/src/gba/gba-memory.c +++ b/src/gba/gba-memory.c @@ -669,14 +669,35 @@ void GBAStore8(struct ARMCore* cpu, uint32_t address, int8_t value, int* cycleCo } #define LDM_LOOP(LDM) \ - for (i = 0; i < 16; ++i) { \ - if (mask & (1 << i)) { \ + for (i = 0; i < 16; i += 4) { \ + if (UNLIKELY(mask & (1 << i))) { \ LDM; \ waitstatesRegion = memory->waitstatesSeq32; \ cpu->gprs[i] = value; \ ++wait; \ address += 4; \ } \ + if (UNLIKELY(mask & (2 << i))) { \ + LDM; \ + waitstatesRegion = memory->waitstatesSeq32; \ + cpu->gprs[i + 1] = value; \ + ++wait; \ + address += 4; \ + } \ + if (UNLIKELY(mask & (4 << i))) { \ + LDM; \ + waitstatesRegion = memory->waitstatesSeq32; \ + cpu->gprs[i + 2] = value; \ + ++wait; \ + address += 4; \ + } \ + if (UNLIKELY(mask & (8 << i))) { \ + LDM; \ + waitstatesRegion = memory->waitstatesSeq32; \ + cpu->gprs[i + 3] = value; \ + ++wait; \ + address += 4; \ + } \ } uint32_t GBALoadMultiple(struct ARMCore* cpu, uint32_t address, int mask, enum LSMDirection direction, int* cycleCounter) { @@ -757,14 +778,35 @@ uint32_t GBALoadMultiple(struct ARMCore* cpu, uint32_t address, int mask, enum L } #define STM_LOOP(STM) \ - for (i = 0; i < 16; ++i) { \ - if (mask & (1 << i)) { \ + for (i = 0; i < 16; i += 4) { \ + if (UNLIKELY(mask & (1 << i))) { \ value = cpu->gprs[i]; \ STM; \ waitstatesRegion = memory->waitstatesSeq32; \ ++wait; \ address += 4; \ } \ + if (UNLIKELY(mask & (2 << i))) { \ + value = cpu->gprs[i + 1]; \ + STM; \ + waitstatesRegion = memory->waitstatesSeq32; \ + ++wait; \ + address += 4; \ + } \ + if (UNLIKELY(mask & (4 << i))) { \ + value = cpu->gprs[i + 2]; \ + STM; \ + waitstatesRegion = memory->waitstatesSeq32; \ + ++wait; \ + address += 4; \ + } \ + if (UNLIKELY(mask & (8 << i))) { \ + value = cpu->gprs[i + 3]; \ + STM; \ + waitstatesRegion = memory->waitstatesSeq32; \ + ++wait; \ + address += 4; \ + } \ } uint32_t GBAStoreMultiple(struct ARMCore* cpu, uint32_t address, int mask, enum LSMDirection direction, int* cycleCounter) {