Util: Migrate popcount32 to a header

This commit is contained in:
Jeffrey Pfau 2015-08-18 22:42:21 -07:00
parent 0cdc9ff328
commit 76663c41cd
3 changed files with 23 additions and 16 deletions

View File

@ -7,16 +7,12 @@
#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) \
{ \
DEBUGGER = 0; \
@ -51,7 +47,7 @@ static uint32_t _popcount32(unsigned bits) {
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) { \

View File

@ -12,11 +12,11 @@
#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 @@ uint32_t GBALoadMultiple(struct ARMCore* cpu, uint32_t address, int mask, enum L
int popcount = 0;
if (direction & LSM_D) {
offset = -4;
popcount = _popcount32(mask);
popcount = popcount32(mask);
address -= (popcount << 2) - 4;
}
@ -1196,7 +1196,7 @@ uint32_t GBAStoreMultiple(struct ARMCore* cpu, uint32_t address, int mask, enum
int popcount = 0;
if (direction & LSM_D) {
offset = -4;
popcount = _popcount32(mask);
popcount = popcount32(mask);
address -= (popcount << 2) - 4;
}
@ -1588,12 +1588,6 @@ void GBAMemoryDeserialize(struct GBAMemory* memory, const struct GBASerializedSt
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) {
if (gba->memory.rom != gba->pristineRom) {
return;

17
src/util/math.h Normal file
View File

@ -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