PowerPC JIT compiler/runtime

Technical discussion for those interested in Supermodel development and Model 3 reverse engineering. Prospective contributors welcome.
Forum rules
Keep it classy!

  • No ROM requests or links.
  • Do not ask to be a play tester.
  • Do not ask about release dates.
  • No drama!

PowerPC JIT compiler/runtime

Postby TheOldDragon » Sat Aug 22, 2020 10:46 am

[I've created this topic based on @Bart's responses to a different discussion thread [running SuperModel on ARM]:

Bart wrote:That's really cool! It's great to know that Supermodel is confirmed to work on ARM. The Dolphin CPU core supports ARM so maybe one day if we borrow that or write our own JIT, performance will improve. Out of curiosity, what happens to the frame rate when you pause emulation (Alt+P)? It should continue rendering but without running the PowerPC.

and
Bart wrote:Supermodel on PowerPC would be awesome. It would be painful on a G4 but should work great on one of those beefy POWER9's. If we had our own JIT, we could write a PowerPC target that tried to emit code as close as possible to the original code. We would probably only have to intercept certain loads/stores and all the jump instructions, keeping 50% or more of the code largely unaltered. But I can't imagine a G4 class machine handling the rendering work.


Interesting. Is the PowerPC JIT compiler something that is sort of likely, or even being considered? Seems like a major undertaking / re-architecting?
Would the Dolphin sources be a good place to start? MAME?
TheOldDragon
 
Posts: 62
Joined: Sat May 30, 2020 5:39 am

Re: PowerPC JIT compiler/runtime

Postby Bart » Sat Aug 22, 2020 12:02 pm

In all honesty, not likely. I've always wanted to write a JIT but now, I'm not permitted to work on Supermodel, and other interests are taking up all my free time. But never say never!

I think when thinking about a PowerPC JIT, it could be done by writing a back-end for Dolphin or MAME's core. This would certainly be the straightforward way to go for running on modern POWER systems. But the original idea that was actually floated by R.Belmont years ago (who was running on Mac -- and this goes to show you how ancient Supermodel is, since this was back in the PowerPC Mac days) was a purpose-built JIT that tried to take advantage of the underlying PowerPC CPU by preserving as much of the code as possible.

You would have to recompile all instructions that touch memory (and there are a lot of those!) Maybe in some cases you can detect what memory address is being written, if it is loaded as a constant value in the same block of code. But realistically, this would actually be very hard to do optimally. The real win would come if you could reliably identify what region of memory a register was pointing to and track that program-wide. This isn't easy. I think commercial JITs like Apple's Rosetta and the pioneering FX!32 by DEC (x86 -> Alpha JIT) did stuff like this. It's really hard, though.

Otherwise, you're stuck with converting almost every load/store instruction into a call to Supermodel's memory handlers, which wouldn't gain much.
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Re: PowerPC JIT compiler/runtime

Postby Ian » Sat Aug 22, 2020 2:46 pm

Bart didn't you say Nik once swapped in dolphins PowerPc core to test the old sega rally polygon bug?

Personally I'd be leaning towards that solution than reinventing the wheel. I think the c code in supermodel is probably a lot more efficient than dolphins but only so far you can get with interpreted code
Ian
 
Posts: 2044
Joined: Tue Feb 23, 2016 9:23 am

Re: PowerPC JIT compiler/runtime

Postby TheOldDragon » Sat Aug 22, 2020 3:08 pm

Wow, thanks for the detailed reply. Sound like a large challenge, and given how well Supermodel works on current x86 hardware, I totally understand that it's a "nice to have" not a need.

So, if I understand correctly, the hypothetical options would be:

#1: write a new, dedicated, JIT interpreter/compiler that would work on PowerPC based systems, and directly pass through as much of the original PPC code as possible to the underlying CPU...
But, very difficult to implement, limited in re-use scope, and may not result in huge performance advantages; i.e. lots of pain for not much gain.

#2: write a backend to interface with the modified JIT code form Dolphin [or MAME] to do a much better/faster conversion of the supermodel PPC code to the underlying CPU architecture.
In my experience, RPCS3 works surprisingly well as a PlayStation 3 emulator. I'm assuming this uses a similar approach as Dolphin with a JIT compiler/interpreter for the conversion from the IBM Cell BBE CPU code?? [which I imagine is even more esoteric with the PPE and 7/8 SPEs]

#3: what about the possibility of integrating with a QEMU based backend, and using that for the CPU translation? XQEMU uses that approach for XBox / Chihero emulation, and they now have WIP versions working on the Switch...
I think WinUAE uses a similar approach for PPC emulation too.
TheOldDragon
 
Posts: 62
Joined: Sat May 30, 2020 5:39 am

Re: PowerPC JIT compiler/runtime

Postby Bart » Sat Aug 22, 2020 8:27 pm

Ian wrote:Bart didn't you say Nik once swapped in dolphins PowerPc core to test the old sega rally polygon bug?

Personally I'd be leaning towards that solution than reinventing the wheel. I think the c code in supermodel is probably a lot more efficient than dolphins but only so far you can get with interpreted code


Yeah, I do believe Nik got it working in Supermodel. Can't remember why it wasn't fully integrated and I never saw the source. It probably wouldn't be too hard but would be a multi-day project. I've looked at the Dolphin code before and it looks relatively straightforward except I'm not sure how it handles timing. As far as I can tell, the CPU emulator *is* the core loop. Supermodel's frame execution functions would probably have to be reworked.
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Re: PowerPC JIT compiler/runtime

Postby Bart » Sat Aug 22, 2020 8:39 pm

TheOldDragon wrote:#1: write a new, dedicated, JIT interpreter/compiler that would work on PowerPC based systems, and directly pass through as much of the original PPC code as possible to the underlying CPU...
But, very difficult to implement, limited in re-use scope, and may not result in huge performance advantages; i.e. lots of pain for not much gain.


That's what I believe -- but I'm not an expert at JITs by any means.

#2: write a backend to interface with the modified JIT code form Dolphin [or MAME] to do a much better/faster conversion of the supermodel PPC code to the underlying CPU architecture.


This is probably the best option.

#3: what about the possibility of integrating with a QEMU based backend, and using that for the CPU translation? XQEMU uses that approach for XBox / Chihero emulation, and they now have WIP versions working on the Switch...
I think WinUAE uses a similar approach for PPC emulation too.


I just took a look at the QEMU source and yes, this could be an option too. But there's a lot of infrastructure that would have to be pulled in. I think Dolphin's core is a lot more self-contained.
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada


Return to The Dark Room

Who is online

Users browsing this forum: No registered users and 1 guest