Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kainrzog

macrumors newbie
Original poster
Nov 24, 2020
8
2
Could anyone point me to some more detailed technical specs (meaning: not marketing) on how Rosetta 2 actually works?

Does such a document even exist?

I'm wondering, because some pseudo-technical docs that I've read state that Rosetta 2 is based on ahead of time compilation, so in theory macOS should take the amd64 binary, recompile it to aarch64, and run the compiled binary instead of the original one.

That's not what I've experienced though. My experiments indicate something else: when I compile on an amd64 macOS a trivial application that allocates a small memory buffer, and I start writing amd64 instructions directly into the buffer, then I set executable rights on the allocated memory region and I run the buffer, it runs without problems on an ARM macOS. That means it can't be an ahead of time compilation, it needs to be some kind of amd64 instruction emulation. Or something else that works similarly.
 

bobmans

macrumors 6502a
Feb 7, 2020
598
1,751
Sadly I can't find any technical details other than this but from what I've read it tries translating everything it can ahead of time and translates what can't be done ahead of time on the fly.
 
  • Like
Reactions: wyrdness

Kainrzog

macrumors newbie
Original poster
Nov 24, 2020
8
2
Thanks. Yeah, I've seen this document. I just had hopes there will be more info about it, I'm really interested in how R2 is implemented.
 

leman

macrumors Core
Oct 14, 2008
19,521
19,675
It supports both AOT and JIT compilation. I don't think that Apple has disclosed any details on how it actually works. I suppose they mark executable pages with the architecture tag and when code in a x86-64 page is executed for the first time, Rosetta compiler kicks in. For applications on disk, they can cache the transpiration results or even do it during installation.

You could make some fun experiments using your simple code generator, like measuring the execution start latency and checking how modifying the code in the buffer affects it.
 
  • Like
Reactions: Kainrzog
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.