News for hackers. Stuff that matters.
Re:HelloSilicon – An introduction to assembly on Apple Silic... by saagarjha on Sunday December 25, 2022 @02:50PM (#34130558)
TL;DR it's AAPCS, with a handful of changes that are generally not relevant to most people. The one I would point out is that the frame pointer must always point to something valid; in other words, don't use -fomit-frame-pointer on Apple silicon. (Don't use it elsewhere either, but that's a separate discussion.)
Re:HelloSilicon – An introduction to assembly on Apple Silic... by messe on Sunday December 25, 2022 @03:41PM (#34131013)
> in other words, don't use -fomit-frame-pointer on Apple silicon. (Don't use it elsewhere either, but that's a separate discussion.)

Getting into that separate discussion, I think there's really only one good use case for -fomit-frame-pointer and that's on 32-bit x86, which has only 8 general purpose registers (EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI); one of which is the stack pointer (ESP), the other of which is the frame pointer (EBP). Meaning that by default a quarter of the available registers are unavailable to you[1]. With -fomit-frame-pointer, you go from having 6 to 7 free registers. This can have a decent impact on performance; there's a reason you'll see it in old gentoo CFLAGS discussions.

x86_64 added R8-R15 registers (as well as RIP-relative addressing), and implementations do a hell of lot of renaming internally, meaning that the gain from using -fomit-frame-pointer is minimal these days.

[1]: This is in fact even worse when using position independent code, as EBX is used quite often as a hidden GOT argument, leaving you with only 5 useful registers.

Re:HelloSilicon – An introduction to assembly on Apple Silic... by stephencanon on Sunday December 25, 2022 @03:04PM (#34130708)
Technically it has to point to _a_ valid frame, but it doesn’t have to be the active function’s frame. So it’s safe to omit setting up a normal call frame, you just aren’t supposed to use it as a GPR.
Re:HelloSilicon – An introduction to assembly on Apple Silic... by stephencanon on Sunday December 25, 2022 @03:05PM (#34130717)
I.e. don’t do what a former coworker did (on x86) and use both the stack pointer and frame pointer registers as index registers for your FFT implementation.
Re:HelloSilicon – An introduction to assembly on Apple Silic... by saagarjha on Sunday December 25, 2022 @04:57PM (#34131836)
lmao
Re:HelloSilicon – An introduction to assembly on Apple Silic... by stephencanon on Sunday December 25, 2022 @05:21PM (#34132092)
When you only have a few GPR names, this sort of thing starts to look tempting. IIRC it was about a 10% perf win, but we didn’t ship it.