PlayAgain 0105: rotate byte swaps in blocks (design J1 item 3). SPDX-License-Identifier: GPL-2.0-or-later Tree: vendor/dolphin (after 0104). What: region code swaps a 32-bit word in 11 wasm instructions since the fork's 0126, (rotl(x, 8) & 0x00ff00ff) | (rotr(x, 8) & 0xff00ff00); block modules kept the 21-instruction form so their bytes and cache keys stayed. Now blocks use it too. The block-cache key prefix becomes wasm-block-sha256-v2 (the key is a SHA-256 of the module bytes anyway, so new bytes never meet old modules; the version marks the emitter). The 16-bit swap is unchanged. Switch: ?blockbswap=0 (bit 19 of the cached-interpreter mask, DISABLE polarity, set by 0105-fork): the 21-instruction form and v1 keys, as before. --- a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp +++ b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp @@ -360,11 +360,20 @@ } }); +namespace +{ +inline bool DolphinWebHelperDisabled(u32 bit); // PlayAgain 0105: defined below +} + static std::array DolphinWeb_MakeWasmBlockCacheKey(std::span bytes) { - static constexpr std::string_view prefix = "wasm-block-sha256-v1:"; + // PlayAgain 0105: v2 for blocks emitted with rotate byte swaps (the key is the bytes' hash + // anyway; the version marks the emitter that made them). 1u << 19 is + // DOLPHIN_WEB_DISABLE_PA_BLOCK_ROTATE_BSWAP, defined below. + const std::string_view prefix = + DolphinWebHelperDisabled(1u << 19) ? "wasm-block-sha256-v1:" : "wasm-block-sha256-v2:"; static constexpr char hex[] = "0123456789abcdef"; - static_assert(prefix.size() + 64 + 1 == 86); + static_assert(std::string_view{"wasm-block-sha256-v2:"}.size() + 64 + 1 == 86); std::array digest{}; std::array key{}; @@ -436,6 +445,9 @@ constexpr u32 DOLPHIN_WEB_DISABLE_REGALLOC = 1u << 20; // §28by GPR regalloc / dead-store-skip (default-off) constexpr u32 DOLPHIN_WEB_DISABLE_SHORT_PREFIX = 1u << 21; // §28ca lower JIT min-prefix 4→2 (default-off) constexpr u32 DOLPHIN_WEB_DISABLE_COMPILE_THROTTLE = 1u << 22; // §28ce cap JIT compiles/slice (default-off) +// PlayAgain 0105: DISABLE polarity (default-on; ?blockbswap=0). Set: block modules swap bytes in +// the fork's 21-instruction form again (their bytes and cache keys as before 0105). +constexpr u32 DOLPHIN_WEB_DISABLE_PA_BLOCK_ROTATE_BSWAP = 1u << 19; // Inline exact FMA (TwoProduct + round-to-odd sum). Set: every FMA-family op // calls the `fma` import (the interpreter's NI_madd_msub) instead. constexpr u32 DOLPHIN_WEB_DISABLE_INLINE_FMA = 1u << 26; // 24 and 25: clear-rect (WebGPU) @@ -3808,9 +3820,10 @@ // Patch 0126: in region code, the byte swap in the form LLVM emits, // (rotl(x, 8) & 0x00ff00ff) | (rotr(x, 8) & 0xff00ff00), 11 wasm instructions // instead of 21. Blocks keep their bytes (and cache keys). +// PlayAgain 0105: blocks too (?blockbswap=0: the 21-instruction form, as before). void EmitBswap32FromLocal(std::vector& body, u32 local_index) { - if (s_wasm_fragment_relocs) + if (s_wasm_fragment_relocs || !DolphinWebHelperDisabled(DOLPHIN_WEB_DISABLE_PA_BLOCK_ROTATE_BSWAP)) { EmitLocalGet(body, local_index); EmitI32Const(body, 8);