Use better popcount than the GCC one...
Jeffrey Pfau jeffrey@endrift.com
Wed, 22 Oct 2014 22:01:11 -0700
1 files changed,
10 insertions(+),
2 deletions(-)
jump to
M
src/gba/gba-memory.c
→
src/gba/gba-memory.c
@@ -8,6 +8,8 @@ #include "gba-serialize.h"
#include "hle-bios.h" #include "util/memory.h" +static uint32_t _popcount32(unsigned bits); + static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t region); static void GBAMemoryServiceDMA(struct GBA* gba, int number, struct GBADMA* info);@@ -650,7 +652,7 @@ int offset = 4;
int popcount = 0; if (direction & LSM_D) { offset = -4; - popcount = __builtin_popcount(mask); + popcount = _popcount32(mask); address -= (popcount << 2) - 4; }@@ -754,7 +756,7 @@ int offset = 4;
int popcount = 0; if (direction & LSM_D) { offset = -4; - popcount = __builtin_popcount(mask); + popcount = _popcount32(mask); address -= (popcount << 2) - 4; }@@ -1143,3 +1145,9 @@ void GBAMemoryDeserialize(struct GBAMemory* memory, struct GBASerializedState* state) {
memcpy(memory->wram, state->wram, SIZE_WORKING_RAM); memcpy(memory->iwram, state->iwram, SIZE_WORKING_IRAM); } + +uint32_t _popcount32(unsigned bits) { + bits = bits - ((bits >> 1) & 0x55555555); + bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333); + return (((bits + (bits >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; +}