-1

This is a subject that I am not very knowledgable about and I was hoping to get a better understanding on the topic.

I was going through articles about Apple's transition to Apple Silicon and at some point I read "Apple is going to ship Rosetta 2, an emulation layer that lets you run old apps on new Macs."

As far as I know, an application is written in a high level language (e.g. C/C++,Java etc.). Then the compiler (let's assume interpreters don't exist for a moment) reads that code and translates it to assembly code. Then the assembler will convert assembly code to machine code which is readable by the processor.

My question is, assuming the above are correct, why is Rosetta 2 required since a CPU is supposed to translate high level code into readable machine code anyway? Why would developers need to "optimise" (or care on what processor their applications are run on) their applications since they are written (mostly) in high level language (which the processor can compile) ? I don't get why would programmers care if the CPU is supposed to handle compiling and assembling.

This question is probably rather trivial but I couldn't find what I was looking for just by reading about compilers or CPU architecture.

Paul R
  • 208,748
  • 37
  • 389
  • 560
alexandrosangeli
  • 262
  • 2
  • 13
  • 1
    Different CPU architectures are not compatible. Maybe (high-level language) developers don't care, but if not for emulation, software needs to be re-written to target the new ISA. That's why x86 is still around -- a lot of legacy software and tooling (compilers) which target x86 exist and are actively used. – ryanwebjackson Nov 30 '20 at 15:28
  • 1
    @ryanwebjackson So the engineers that do care about it are the ones that work on tools such as compilers? Because they have to target a specific ISA ? – alexandrosangeli Nov 30 '20 at 15:37
  • 1
    @ryanwebjackson: Rewritten is an overstatement for most apps, you can just **recompile**. But if you have custom x86-specific code, like manually vectorized SIMD loops using SSE / AVX, you'd have to port those to NEON / AArch64 SIMD. – Peter Cordes Nov 30 '20 at 23:59
  • @PeterCordes Fair enough, but there has to be a compiler that exists to target that ISA. Obviously Apple is going to support their own platform (yes, meaning compilers), but other than that the support remains to be seen. The big caveat is that the M1 is ARM based, which already has huge support in the marketplace. It would be a completely different story if it was a new ISA. – ryanwebjackson Dec 01 '20 at 03:37
  • It's possible that some programming languages or frameworks won't work as expected on day 1. See here for example: https://stackoverflow.com/questions/64899827/nodejs-on-apple-silicon-m1 – ryanwebjackson Dec 01 '20 at 03:52
  • 2
    @ryanwebjackson: Yeah exactly, the CPU itself is a fully standard AArch64 (with amazingly wide superscalar out-of-order execution, https://www.anandtech.com/show/16226/apple-silicon-m1-a14-deep-dive/2). There is zero issue here, major compilers like GCC and clang already optimize well for AArch64, and the MachO64 file format should be documented. The only issue with porting a full OS like GNU/Linux to it is drivers for proprietary hardware outside the CPU, like the screen. But to get a program running under MacOS, you can use the same OS interfaces as always to access the screen, files, etc. – Peter Cordes Dec 01 '20 at 04:03
  • Certainly Apple itself provides a working compiler toolchain that can target their platform, presumably cross-compiling from existing x86 Macs. – Peter Cordes Dec 01 '20 at 04:06

1 Answers1

4

a CPU is supposed to translate high level code into readable machine code anyway?

No, the CPU doesn't do that itself, it happens via software running on the CPU (JIT or ahead-of-time compiler).

For ahead-of-time compiler (e.g. normal C++ implementations), closed source software only ships x86 machine code, not source. So you can't just recompile it yourself. Open-source software is usually easily portable by recompiling.

Rewritten is an overstatement for most apps, most can just recompile.

But if you have custom x86-specific code, like manually vectorized SIMD loops using SSE / AVX intrinsics or hand-written asm, you'd have to port those to NEON / AArch64 SIMD.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Thanks for that. I guess tech blogs over-generalised this potential issue saying that "developers will have to...", and by that they included every kind of developer out there which is a real head-scratcher. Also didn't know that close source software only shipped CPU-specific machine code but it does make sense. P.S. by "readable machine code" I meant readable for the CPU if that makes any difference. – alexandrosangeli Dec 01 '20 at 21:16
  • @alexandrosangeli: Terminology: "machine-readable code" might express what you want to say. Or "executable machine code" would be another way to say it, although that's still redundant. "machine code" implies that a CPU can execute it, for people familiar with the term. And BTW, note that closed-source software in some other languages, like Java, still normally have to ship portable Java bytecode which only gets JIT-compiled to machine code on the fly by a JVM. But anything that's just a binary executable + libraries is normally just machine code. – Peter Cordes Dec 02 '20 at 03:11