8 ms·
Are there CPU manuals from Apple that explain how to optimize assembly code for their CPU and document any deviations from the ARM reference architecture?
by devit 6y ago
Are there CPU manuals from Apple that explain how to optimize assembly code for their CPU and document any deviations from the ARM reference architecture?
- VHRanger 6y agoSerious question, since I only have a little experience writing assembly: How would optimized M1 assembly differ from optimized ARM assembly in general? I imagine good ARM assembly code on a Gravitron2 or a Snapdragon chip would be similarly good on an M1 chip
- saagarjha 6y agoThere are always microarchitectural differences you can take advantage of, but Apple probably wants you to stick to the ISA as these things change in ways they don't want to document. Apple of course uses these things in the lower levels of their software, so if you're using their APIs you're getting this for free across OSes and CPUs.
- cataphract 6y agoThe costs of different operations differ between CPUs that implement the same instruction set. Compilers have costs tables for each processor family for when you target them (e.g. with -mtune)
- rsynnott 6y agoMicro-architectural differences. For instance, from the 386 to Pentium 3 (and on Athlon, I believe), shifting was cheap, due to the presence of a barrel shifter. This was dropped in the P4, and suddenly shifting was quite expensive (I think, though I’m not sure, that it may actually have come back in later P4s). That’s the sort of thing compiler writers need to know about.
- userbinator 6y agoThe P4 was quite an anomaly[1] in the history of x86, optimised for clock speed at the expense of many other things. All the subsequent generations went back to the norm, with the exception of the Atom series, and even that one is not as unusual as the P4. [1] Even the family/model/stepping designation has an oddity: the 486 was family 4, the Pentium was family 5, and then everything from the Pentium II/III up to the latest Core series, as well as the Atoms, uses family 6; but the P4 was family 15.
- mhh__ 6y agoIt really depends on the actual design of the processor. Some things like the instruction density and inlining heuristics translate from processor to processor, but the actual microarchitecture (rather than the ISA) determine what is "good" code from platform to platform e.g. Good instruction scheduling depends on how the CPU is designed.
- saagarjha 6y agoNone that are available externally, no.
- skohan 6y agoPresumably a lot of the optimizations they use for their own compilers would be upstreamed into LLVM, no?
- saagarjha 6y agoIt seems like many have not for a number of years. A14 is still not even listed in LLVM's list of aarch64 targets :/
- cozzyd 6y agoVery sad to hear, but unsurprising. That's what you get for not using a GPL compiler, I guess.
- mhh__ 6y agoIndeed, although it's worth saying that GNU were offered LLVM and said no, they have suffered from their own success because new developers and culture within programming is now post-GNU where people can't remember the environment that led to the GPL becoming popular.
- cozzyd 6y agoyes, and it's clearly something rms regrets: https://lists.gnu.org/archive/html/emacs-devel/2015-02/msg00594.html https://lists.gnu.org/archive/html/emacs-devel/2015-02/msg00... If rms had a sane way of reading e-mail, things might be different :).
- my123 6y agoIt takes them a while. Apple A13 is there in the Apple LLVM target list at https://github.com/apple/llvm-project/blob/master/llvm/lib/Target/AArch64/AArch64.td https://github.com/apple/llvm-project/blob/master/llvm/lib/T.... A14/M1 will come, but the question is when...
- fiddlerwoaroof 6y agoThis is the closest I could find: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms https://developer.apple.com/documentation/xcode/writing_arm6...
- saagarjha 6y agoAh yes, another documentation page that Apple found and ruined by "modernizing"…