all repos — mgba @ 76663c41cdceab9fd4277c0d0e2a0c462167e3d7

mGBA Game Boy Advance Emulator

Util: Migrate popcount32 to a header
Jeffrey Pfau jeffrey@endrift.com
Tue, 18 Aug 2015 22:42:21 -0700
commit

76663c41cdceab9fd4277c0d0e2a0c462167e3d7

parent

0cdc9ff32887e57767fac74ea12c8616025583bd

3 files changed, 23 insertions(+), 16 deletions(-)

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

@@ -7,15 +7,11 @@ #include "memory-debugger.h"

#include "debugger.h" +#include "util/math.h" + #include <string.h> static bool _checkWatchpoints(struct ARMDebugger* debugger, uint32_t address, struct DebuggerEntryInfo* info, int width); - -static uint32_t _popcount32(unsigned bits) { - bits = bits - ((bits >> 1) & 0x55555555); - bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333); - return (((bits + (bits >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; -} #define FIND_DEBUGGER(DEBUGGER, CPU) \ { \

@@ -51,7 +47,7 @@ #define CREATE_MULTIPLE_WATCHPOINT_SHIM(NAME) \

static uint32_t ARMDebuggerShim_ ## NAME (struct ARMCore* cpu, uint32_t address, int mask, enum LSMDirection direction, int* cycleCounter) { \ struct ARMDebugger* debugger; \ FIND_DEBUGGER(debugger, cpu); \ - uint32_t popcount = _popcount32(mask); \ + uint32_t popcount = popcount32(mask); \ int offset = 4; \ int base = address; \ if (direction & LSM_D) { \
M src/gba/memory.csrc/gba/memory.c

@@ -12,11 +12,11 @@ #include "gba/hardware.h"

#include "gba/io.h" #include "gba/serialize.h" #include "gba/hle-bios.h" +#include "util/math.h" #include "util/memory.h" #define IDLE_LOOP_THRESHOLD 10000 -static uint32_t _popcount32(unsigned bits); static void _pristineCow(struct GBA* gba); static uint32_t _deadbeef[1] = { 0xE710B710 }; // Illegal instruction on both ARM and Thumb

@@ -1083,7 +1083,7 @@ int offset = 4;

int popcount = 0; if (direction & LSM_D) { offset = -4; - popcount = _popcount32(mask); + popcount = popcount32(mask); address -= (popcount << 2) - 4; }

@@ -1196,7 +1196,7 @@ int offset = 4;

int popcount = 0; if (direction & LSM_D) { offset = -4; - popcount = _popcount32(mask); + popcount = popcount32(mask); address -= (popcount << 2) - 4; }

@@ -1586,12 +1586,6 @@

void GBAMemoryDeserialize(struct GBAMemory* memory, const 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; } void _pristineCow(struct GBA* gba) {
A src/util/math.h

@@ -0,0 +1,17 @@

+/* Copyright (c) 2013-2015 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef UTIL_MATH_H +#define UTIL_MATH_H + +#include "util/common.h" + +static inline uint32_t popcount32(unsigned bits) { + bits = bits - ((bits >> 1) & 0x55555555); + bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333); + return (((bits + (bits >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; +} + +#endif