mirror of https://github.com/mgba-emu/mgba.git
Util: Migrate popcount32 to a header
This commit is contained in:
parent
0cdc9ff328
commit
76663c41cd
|
@ -7,16 +7,12 @@
|
||||||
|
|
||||||
#include "debugger.h"
|
#include "debugger.h"
|
||||||
|
|
||||||
|
#include "util/math.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static bool _checkWatchpoints(struct ARMDebugger* debugger, uint32_t address, struct DebuggerEntryInfo* info, int width);
|
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) \
|
#define FIND_DEBUGGER(DEBUGGER, CPU) \
|
||||||
{ \
|
{ \
|
||||||
DEBUGGER = 0; \
|
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) { \
|
static uint32_t ARMDebuggerShim_ ## NAME (struct ARMCore* cpu, uint32_t address, int mask, enum LSMDirection direction, int* cycleCounter) { \
|
||||||
struct ARMDebugger* debugger; \
|
struct ARMDebugger* debugger; \
|
||||||
FIND_DEBUGGER(debugger, cpu); \
|
FIND_DEBUGGER(debugger, cpu); \
|
||||||
uint32_t popcount = _popcount32(mask); \
|
uint32_t popcount = popcount32(mask); \
|
||||||
int offset = 4; \
|
int offset = 4; \
|
||||||
int base = address; \
|
int base = address; \
|
||||||
if (direction & LSM_D) { \
|
if (direction & LSM_D) { \
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
#include "gba/io.h"
|
#include "gba/io.h"
|
||||||
#include "gba/serialize.h"
|
#include "gba/serialize.h"
|
||||||
#include "gba/hle-bios.h"
|
#include "gba/hle-bios.h"
|
||||||
|
#include "util/math.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
|
|
||||||
#define IDLE_LOOP_THRESHOLD 10000
|
#define IDLE_LOOP_THRESHOLD 10000
|
||||||
|
|
||||||
static uint32_t _popcount32(unsigned bits);
|
|
||||||
static void _pristineCow(struct GBA* gba);
|
static void _pristineCow(struct GBA* gba);
|
||||||
static uint32_t _deadbeef[1] = { 0xE710B710 }; // Illegal instruction on both ARM and Thumb
|
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;
|
int popcount = 0;
|
||||||
if (direction & LSM_D) {
|
if (direction & LSM_D) {
|
||||||
offset = -4;
|
offset = -4;
|
||||||
popcount = _popcount32(mask);
|
popcount = popcount32(mask);
|
||||||
address -= (popcount << 2) - 4;
|
address -= (popcount << 2) - 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1196,7 +1196,7 @@ uint32_t GBAStoreMultiple(struct ARMCore* cpu, uint32_t address, int mask, enum
|
||||||
int popcount = 0;
|
int popcount = 0;
|
||||||
if (direction & LSM_D) {
|
if (direction & LSM_D) {
|
||||||
offset = -4;
|
offset = -4;
|
||||||
popcount = _popcount32(mask);
|
popcount = popcount32(mask);
|
||||||
address -= (popcount << 2) - 4;
|
address -= (popcount << 2) - 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1588,12 +1588,6 @@ void GBAMemoryDeserialize(struct GBAMemory* memory, const struct GBASerializedSt
|
||||||
memcpy(memory->iwram, state->iwram, SIZE_WORKING_IRAM);
|
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) {
|
void _pristineCow(struct GBA* gba) {
|
||||||
if (gba->memory.rom != gba->pristineRom) {
|
if (gba->memory.rom != gba->pristineRom) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue