Skip to content

PS2 games in the browser: static recompilation to WebAssembly with a native runtime

C++

GS and GIF trace switches are read once, not on every register write

Samir Nuri1d771ff90950
diff --git a/runtime/src/gs/gif.cpp b/runtime/src/gs/gif.cpp
index ea48474..cdac09b 100644
--- a/runtime/src/gs/gif.cpp
+++ b/runtime/src/gs/gif.cpp
@@ -200,7 +200,8 @@ void write(std::uint32_t a, std::uint32_t v) {
void set_path3_masked(bool masked) {
g_stat = (g_stat & ~2u) | (masked ? 2u : 0u);
- if (std::getenv("PS2_TRACE_PATH3")) std::fprintf(stderr, "[gif] path3 %s\n", masked ? "masked" : "unmasked");
+ static const bool trace = std::getenv("PS2_TRACE_PATH3") != nullptr;
+ if (trace) std::fprintf(stderr, "[gif] path3 %s\n", masked ? "masked" : "unmasked");
}
}
diff --git a/runtime/src/gs/gs.cpp b/runtime/src/gs/gs.cpp
index 9f7e1e9..907e575 100644
--- a/runtime/src/gs/gs.cpp
+++ b/runtime/src/gs/gs.cpp
@@ -638,7 +638,8 @@ void signal(std::uint32_t reg, std::uint64_t value) {
void write_packed(std::uint32_t reg, const Reg128 &q) {
State &s = g_state;
- if (const char *seq = std::getenv("PS2_TRACE_GSSEQ")) {
+ static const char *const seq = std::getenv("PS2_TRACE_GSSEQ");
+ if (seq) [[unlikely]] {
static std::uint64_t n = 0, start = std::strtoull(seq, nullptr, 10);
if (++n >= start && n < start + 100000) std::fprintf(stderr, "[gs] w %02X %016llX\n", reg, static_cast<unsigned long long>(q.d[0]));
}