summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2024-05-22 23:44:38 +0300
committerOxore <oxore@protonmail.com>2024-05-22 23:44:38 +0300
commitda7bab98907a700d1e525ccafe8f623d0927a724 (patch)
treeb27773247c227003c8a68f7f7c3c2c1ac201bc19
parent71b89bc9ceb59f2603cf4b0635849269597a4823 (diff)
Optimize compile times by removing find_if usage
-rw-r--r--bus.cpp57
-rw-r--r--emulator.cpp25
-rw-r--r--m68k_debugging.cpp106
3 files changed, 95 insertions, 93 deletions
diff --git a/bus.cpp b/bus.cpp
index f9aab5f..ac18208 100644
--- a/bus.cpp
+++ b/bus.cpp
@@ -7,7 +7,6 @@
#include "vdp.hpp"
#include "io.hpp"
-#include <algorithm>
#include <cassert>
#include <cstdarg>
#include <cstdbool>
@@ -115,21 +114,21 @@ static inline bool ranges_overlap(
static inline void m68k_read_callback(const uint32_t address, const uint32_t size)
{
- const auto access_it = std::find_if(
- access_bkpts.begin(),
- access_bkpts.end(),
- [&](const Breakpoint& b) { return ranges_overlap(address, size, b.offset, b.length); });
- if (access_it != access_bkpts.end()) {
- printf("Access watchpoint @ 0x%08x\n", address);
- m68k_breakpoint_callback();
+ for (size_t bi = 0; bi < access_bkpts.size(); bi++) {
+ const auto& b = access_bkpts[bi];
+ if (ranges_overlap(address, size, b.offset, b.length)) {
+ printf("Access watchpoint @ 0x%08x\n", address);
+ m68k_breakpoint_callback();
+ break;
+ }
}
- const auto it = std::find_if(
- read_bkpts.begin(),
- read_bkpts.end(),
- [&](const Breakpoint& b) { return ranges_overlap(address, size, b.offset, b.length); });
- if (it != read_bkpts.end()) {
- printf("Read watchpoint @ 0x%08x\n", address);
- m68k_breakpoint_callback();
+ for (size_t bi = 0; bi < read_bkpts.size(); bi++) {
+ const auto& b = read_bkpts[bi];
+ if (ranges_overlap(address, size, b.offset, b.length)) {
+ printf("Read watchpoint @ 0x%08x\n", address);
+ m68k_breakpoint_callback();
+ break;
+ }
}
}
@@ -196,21 +195,21 @@ static inline void memory_write_concrete(
static inline void m68k_write_callback(const uint32_t address, const uint32_t size)
{
- const auto access_it = std::find_if(
- access_bkpts.begin(),
- access_bkpts.end(),
- [&](const Breakpoint& b) { return ranges_overlap(address, size, b.offset, b.length); });
- if (access_it != access_bkpts.end()) {
- printf("Access watchpoint @ 0x%08x\n", address);
- m68k_breakpoint_callback();
+ for (size_t bi = 0; bi < access_bkpts.size(); bi++) {
+ const auto& b = access_bkpts[bi];
+ if (ranges_overlap(address, size, b.offset, b.length)) {
+ printf("Access watchpoint @ 0x%08x\n", address);
+ m68k_breakpoint_callback();
+ break;
+ }
}
- const auto it = std::find_if(
- write_bkpts.begin(),
- write_bkpts.end(),
- [&](const Breakpoint& b) { return ranges_overlap(address, size, b.offset, b.length); });
- if (it != write_bkpts.end()) {
- printf("Write watchpoint @ 0x%08x\n", address);
- m68k_breakpoint_callback();
+ for (size_t bi = 0; bi < read_bkpts.size(); bi++) {
+ const auto& b = read_bkpts[bi];
+ if (ranges_overlap(address, size, b.offset, b.length)) {
+ printf("Write watchpoint @ 0x%08x\n", address);
+ m68k_breakpoint_callback();
+ break;
+ }
}
}
diff --git a/emulator.cpp b/emulator.cpp
index e3ac6bb..034fc57 100644
--- a/emulator.cpp
+++ b/emulator.cpp
@@ -25,7 +25,6 @@
#include "musashi-m68k/m68kcpu.h"
#include <arpa/inet.h>
-#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdint>
@@ -406,20 +405,18 @@ static void PrintInstructionTrace(const uint32_t pc)
int m68k_instr_callback(const int pc)
{
g_pc_backtrace.Push(pc);
- const auto it = std::find_if(
- code_bkpts.begin(),
- code_bkpts.end(),
- [&](const Breakpoint& b) { return b.offset == static_cast<uint32_t>(pc); });
- if (it != code_bkpts.end()) {
- g_m68k_debug.RaiseBreakpoint();
- m68k_end_timeslice();
- printf("Breakpoint @ 0x%08x\n", pc);
- g_pc_backtrace.Normalize();
- printf("PC backtrace (size=%zu):\n", g_pc_backtrace.Size());
- for (size_t i = 0; i < g_pc_backtrace.Size(); i++) {
- PrintInstructionTrace(g_pc_backtrace.buffer[i]);
+ for (size_t bi = 0; bi < code_bkpts.size(); bi++) {
+ if (code_bkpts[bi].offset == static_cast<uint32_t>(pc)) {
+ g_m68k_debug.RaiseBreakpoint();
+ m68k_end_timeslice();
+ printf("Breakpoint @ 0x%08x\n", pc);
+ g_pc_backtrace.Normalize();
+ printf("PC backtrace (size=%zu):\n", g_pc_backtrace.Size());
+ for (size_t i = 0; i < g_pc_backtrace.Size(); i++) {
+ PrintInstructionTrace(g_pc_backtrace.buffer[i]);
+ }
+ return 1;
}
- return 1;
}
if (DEBUG_TRACE_INSTRUCTIONS) {
PrintInstructionTrace(pc);
diff --git a/m68k_debugging.cpp b/m68k_debugging.cpp
index 5bae0d0..bcad0e2 100644
--- a/m68k_debugging.cpp
+++ b/m68k_debugging.cpp
@@ -6,7 +6,6 @@
#include "bus.hpp"
#include "utils.hpp"
-#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <vector>
@@ -158,38 +157,41 @@ void M68KDebuggingControl::SetBreakpoint(
switch (type) {
case BreakpointType::kSoftwareBreakpoint:
case BreakpointType::kHardwareBreakpoint: {
- const auto it = std::find_if(
- code_bkpts.begin(),
- code_bkpts.end(),
- [&](const Breakpoint& b) { return b.offset == address && b.length == length; });
- if (it == code_bkpts.end())
- code_bkpts.push_back(Breakpoint{address, length});
+ for (size_t bi = 0; bi < code_bkpts.size(); bi++) {
+ const auto& b = code_bkpts[bi];
+ if (b.offset == address && b.length == length) {
+ return;
+ }
+ }
+ code_bkpts.push_back(Breakpoint{address, length});
} break;
case BreakpointType::kWriteWatchpoint: {
- const auto it = std::find_if(
- write_bkpts.begin(),
- write_bkpts.end(),
- [&](const Breakpoint& b) { return b.offset == address && b.length == length; });
- if (it == write_bkpts.end())
- write_bkpts.push_back(Breakpoint{address, length});
+ for (size_t bi = 0; bi < write_bkpts.size(); bi++) {
+ const auto& b = write_bkpts[bi];
+ if (b.offset == address && b.length == length) {
+ return;
+ }
+ }
+ write_bkpts.push_back(Breakpoint{address, length});
} break;
case BreakpointType::kReadWatchpoint: {
- const auto it = std::find_if(
- read_bkpts.begin(),
- read_bkpts.end(),
- [&](const Breakpoint& b) { return b.offset == address && b.length == length; });
- if (it == read_bkpts.end())
- read_bkpts.push_back(Breakpoint{address, length});
+ for (size_t bi = 0; bi < read_bkpts.size(); bi++) {
+ const auto& b = read_bkpts[bi];
+ if (b.offset == address && b.length == length) {
+ return;
+ }
+ }
+ read_bkpts.push_back(Breakpoint{address, length});
} break;
case BreakpointType::kAccessWatchpoint: {
- const auto it = std::find_if(
- access_bkpts.begin(),
- access_bkpts.end(),
- [&](const Breakpoint& b) { return b.offset == address && b.length == length; });
- if (it == access_bkpts.end())
- access_bkpts.push_back(Breakpoint{address, length});
+ for (size_t bi = 0; bi < access_bkpts.size(); bi++) {
+ const auto& b = access_bkpts[bi];
+ if (b.offset == address && b.length == length) {
+ return;
+ }
+ }
+ access_bkpts.push_back(Breakpoint{address, length});
} break;
- break;
case BreakpointType::kUnsupported: {
UNREACHABLE;
} break;
@@ -205,36 +207,40 @@ void M68KDebuggingControl::RemoveBreakpoint(
switch (type) {
case BreakpointType::kSoftwareBreakpoint:
case BreakpointType::kHardwareBreakpoint: {
- const auto it = std::find_if(
- code_bkpts.begin(),
- code_bkpts.end(),
- [&](const Breakpoint& b) { return b.offset == address && b.length == length; });
- if (it != code_bkpts.end())
- code_bkpts.erase(it);
+ for (size_t bi = 0; bi < code_bkpts.size(); bi++) {
+ const auto& b = code_bkpts[bi];
+ if (b.offset == address && b.length == length) {
+ code_bkpts.erase(code_bkpts.begin() + bi);
+ break;
+ }
+ }
} break;
case BreakpointType::kWriteWatchpoint: {
- const auto it = std::find_if(
- write_bkpts.begin(),
- write_bkpts.end(),
- [&](const Breakpoint& b) { return b.offset == address && b.length == length; });
- if (it != write_bkpts.end())
- write_bkpts.erase(it);
+ for (size_t bi = 0; bi < write_bkpts.size(); bi++) {
+ const auto& b = write_bkpts[bi];
+ if (b.offset == address && b.length == length) {
+ write_bkpts.erase(write_bkpts.begin() + bi);
+ break;
+ }
+ }
} break;
case BreakpointType::kReadWatchpoint: {
- const auto it = std::find_if(
- read_bkpts.begin(),
- read_bkpts.end(),
- [&](const Breakpoint& b) { return b.offset == address && b.length == length; });
- if (it != read_bkpts.end())
- read_bkpts.erase(it);
+ for (size_t bi = 0; bi < read_bkpts.size(); bi++) {
+ const auto& b = read_bkpts[bi];
+ if (b.offset == address && b.length == length) {
+ read_bkpts.erase(read_bkpts.begin() + bi);
+ break;
+ }
+ }
} break;
case BreakpointType::kAccessWatchpoint: {
- const auto it = std::find_if(
- access_bkpts.begin(),
- access_bkpts.end(),
- [&](const Breakpoint& b) { return b.offset == address && b.length == length; });
- if (it != access_bkpts.end())
- access_bkpts.erase(it);
+ for (size_t bi = 0; bi < access_bkpts.size(); bi++) {
+ const auto& b = access_bkpts[bi];
+ if (b.offset == address && b.length == length) {
+ access_bkpts.erase(access_bkpts.begin() + bi);
+ break;
+ }
+ }
} break;
break;
case BreakpointType::kUnsupported: {