-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PPU LLVM arm64+macOS port #12115
PPU LLVM arm64+macOS port #12115
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just looking at the code style
rpcs3/util/vm_native.cpp
Outdated
@@ -135,7 +140,11 @@ namespace utils | |||
size += 0x10000; | |||
} | |||
|
|||
#ifdef __APPLE__ | |||
auto ptr = ::mmap(use_addr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE | MAP_JIT | c_map_noreserve, -1, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're using spaces instead of tabs, which is why it may appear as correct on your end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird that only these lines were wrong. I replaced with tabs it looks good now.
@Megamouse Not sure why GH is showing some of the indents, I checked in vim and Github and they are not there (see https://github.com/RPCS3/rpcs3/blob/91add25d9cc26ec74aa5eff785d8776197759b43/rpcs3/util/vm_native.cpp for example). Fixed the rest of the formatting, sorry. @Nekotekina I cherry-picked your commits and seems to work. |
Use naive function pointer on Apple arm64 because ASLR breaks asmjit. See BufferUtils.cpp comment for explanation on why this happens and how to fix if you want to use asmjit.
Tell Qt not to strip debug symbols when we're in debug or relwithdebinfo modes.
Force MachO on macOS to fix LLVM being unable to patch relocations during codegen. Adds Aarch64 NEON intrinsics for x86 intrinsics used by PPUTranslator/Recompiler.
Temporary hack to get things working by using 16k pages instead of 4k pages in VM emulation.
Fixes some intrinsics usage and patches usages of asmjit to properly emit absolute jmps so ASLR doesn't cause out of bounds rel jumps. Also patches the SPU recompiler to properly work on arm64 by telling LLVM to target arm64.
Fixes W^X on macOS aarch64 by setting all JIT mmap'd regions to default to RW mode. For both SPU and PPU execution threads, when initialization finishes we toggle to RX mode. This exploits Apple's per-thread setting for RW/RX to let us be technically compliant with the OS's W^X enforcement while not needing to actually separate the memory allocated for code/data.
Implements ppu_gateway for arm64 and patches LLVM initialization to use the correct triple. Adds some fixes for macOS W^X JIT restrictions when entering/exiting JITed code.
Strictly speaking, rpcs3 JIT -> C++ calls are not tail calls. If you call a function inside e.g. an L2 syscall, it will clobber LR on arm64 and subtly break returns in emulated code. Only JIT -> JIT "calls" should be tail.
Tag mmap calls with MAP_JIT to allow W^X on macOS. Fix mmap calls to existing mmap'd addresses that were tagged with MAP_JIT on macOS. Fix memory unmapping on 16K page machines with a hack to mark "unmapped" pages as RW.
e2e1365
to
9f9cb81
Compare
@Nekotekina Is there a blocker preventing this from being merged? |
Probably no, just needs some corrections. |
I can confirm this also fixes the ppu test on linux aarch64 (asahi) |
rpcs3/Emu/Cell/PPUTranslator.cpp
Outdated
#ifdef ARCH_X64 | ||
SetFpr(op.frd, m_ir->CreateXor(xormask, Call(GetType<s32>(), "llvm.x86.sse2.cvtsd2si", m_ir->CreateInsertElement(GetUndef<f64[2]>(), b, u64{0})))); | ||
#else | ||
SetFpr(op.frd, m_ir->CreateXor(xormask, Call(GetType<s32>(), "llvm.aarch64.neon.fcvtns.i32.f64", b))); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be dumb, but why are you calling the x86
instruction inside ifdef ARCH_X64
, and the aarch64
inside the else
. Shouldn't it be the opposite way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
X64 is not aarch64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It basically says "if ARCH_x64 (aka Intel x86_64), use SSE2; else, assume it's AArch64 (aka ARM64) and use Neon."
Fixes PPU LLVM recompiler to work for arm64 (only
ppu_thread.elf
works so far). Fixes virtual memory handling and W^X JIT restriction handling on macOS to work for Apple Silicon (lot of hacks 😢 ). Also fixes debug symbols on Mac.Potentially breaking changes:
x86_pshufb
renamed topshufb
Build:
You may get some MoltenVK errors in build, in that case install VulkanSDK and run this (replace the 1.3.204.1 with your actual version number):
Tested only on
ppu_thread.elf
, I tried with an actual game and something in SPU code will segfault. You may also get a PPU thread segfault the first time you runppu_thread.elf
after compiling, but it should go away if you run it again. I haven't been able to track down why yet.Major hacks:
unmapping memory is done by just telling the OS to swap it out and marking it RW, because of the 16K page issueMAP_JIT
tag is done bymunmap
and thenmmap
the same location, since Apple bansMAP_FIXED
+MAP_JIT
from overwriting existing mmap entries