all repos — mgba @ 0308f136c7e195bd2e245dd3676d559b97595ceb

mGBA Game Boy Advance Emulator

GBA Memory: partially unroll loops for LDM/STM and add UNLIKELYs
Jeffrey Pfau jeffrey@endrift.com
Tue, 18 Nov 2014 04:29:16 -0800
commit

0308f136c7e195bd2e245dd3676d559b97595ceb

parent

d49df216b84b25f6612200116fc44c8ab325c90a

1 files changed, 46 insertions(+), 4 deletions(-)

jump to
M src/gba/gba-memory.csrc/gba/gba-memory.c

@@ -669,11 +669,32 @@ }

} #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; \ } \

@@ -757,9 +778,30 @@ return address | addressMisalign;

} #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; \