From 7fa7ff161fb7b9f653cf846c96279e5f8e21b491 Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:52:18 +0300 Subject: [PATCH] Add a read barrier after every label. --- PowerRecomp/recompiler.cpp | 4 ++++ PowerUtils/ppc_context.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/PowerRecomp/recompiler.cpp b/PowerRecomp/recompiler.cpp index 0269dbf..2beb739 100644 --- a/PowerRecomp/recompiler.cpp +++ b/PowerRecomp/recompiler.cpp @@ -1968,7 +1968,11 @@ bool Recompiler::Recompile(const Function& fn) while (base < end) { if (labels.contains(base)) + { println("loc_{:X}:", base); + // With a read barrier we prevent the compiler from doing unsafe code reordering. I wonder if we could do this better... + println("\t_ReadBarrier();"); + } if (switchTable == switchTables.end()) switchTable = switchTables.find(base); diff --git a/PowerUtils/ppc_context.h b/PowerUtils/ppc_context.h index a2a2382..e6d2b86 100644 --- a/PowerUtils/ppc_context.h +++ b/PowerUtils/ppc_context.h @@ -9,12 +9,12 @@ #include #include #include +#include #ifdef __clang__ #include #define PPC_NOINLINE __attribute__((noinline)) #else -#include #define __restrict__ __restrict #define __builtin_bswap16 _byteswap_ushort #define __builtin_bswap32 _byteswap_ulong