News for hackers. Stuff that matters.
Re:HelloSilicon – An introduction to assembly on Apple Silic... by TheBrokenRail on Sunday December 25, 2022 @01:58PM (#34129981)
So what's the difference between ARM and Apple Silicon?

It's a little odd seeing it treated as its own unique architecture (for instance with people specifically porting software or writing guides about Apple Silicon rather than ARM in general) when it's just ARM64. Which already has a lot of stuff already ported to it and is quite extensively documented.

Am I missing something? Did Apple do something crazy non-standard when making their chips which make them behave differently?

Re:HelloSilicon – An introduction to assembly on Apple Silic... by andsoitis on Sunday December 25, 2022 @02:05PM (#34130048)
Apple diverges from standard 64-bit ARM architecture in specific ways: https://developer.apple.com/documentation/xcode/writing-arm6...
Re:HelloSilicon – An introduction to assembly on Apple Silic... by sounds on Sunday December 25, 2022 @04:25PM (#34131482)
I mean, that page only describes ABI differences. I was thinking I would find ARM architecture differences in the silicon. I understand that the ABI is considered part of the specification for 64-bit ARM silicon.
Re:HelloSilicon – An introduction to assembly on Apple Silic... by masklinn on Sunday December 25, 2022 @05:13PM (#34132011)
> I mean, that page only describes ABI differences.

It explains how Apple constrains users, and thus the difference between general ARM and Apple Silicon. Which was the question.

> I was thinking I would find ARM architecture differences in the silicon.

Could you explain what you mean exactly? It's an ARM implementation so it has to implement the ISA.

Apple's implementation has a few interesting bits, like a TSO mode (for x86 emulation), and actually has custom ISA extensions (AMX, memory compression, APRR/GXF) which nobody else would be allowed according to Hector Martin.

Re:HelloSilicon – An introduction to assembly on Apple Silic... by throwme_123 on Sunday December 25, 2022 @07:17PM (#34133058)
> nobody else would be allowed according to Hector Martin

I'm not sure of the meaning here. Is it:

a. ISA extensions can't be called by any program not written by Apple? (including Asahi)

b. Nobody else but Apple has the right to have these ISA extensions, but when in Silicon, programmers can use them?

Re:HelloSilicon – An introduction to assembly on Apple Silic... by kzrdude on Sunday December 25, 2022 @07:51PM (#34133322)
It might be something like this?

c. Nobody else who licenses ARM would be allowed to add extensions to their implementation of the ISA in this way. Apple is more or less a founding member of ARM and has some other deal.

Re:HelloSilicon – An introduction to assembly on Apple Silic... by masklinn on Monday December 26, 2022 @05:49AM (#34136544)
Yes, though that's a different formulation of (2) really:

> Nobody else but Apple has the right to have these ISA extensions

Programmers "can" use Apple extensions because... they're extensions to the ISA, they're not documented but they can't really be blocked off unless they're ring0, and that would make them a lot less useful (the entire point of having extensions for matrix computation is to speed up matrix computations, which are not usually kernel work, and having to syscall to do them would waste the entire thing).

Re:HelloSilicon – An introduction to assembly on Apple Silic... by saagarjha on Monday December 26, 2022 @06:22AM (#34136742)
Apple exposes these behind APIs that hide these implementation details. Their own compilers never emit them. Nothing can stop you from embedding them into your binary yourself, of course, but this would be annoying to both you and Apple.
Re:HelloSilicon – An introduction to assembly on Apple Silic... by sounds on Monday December 26, 2022 @01:17AM (#34135175)
I replied to this post: "Apple diverges from standard 64-bit ARM architecture in specific ways"

I know about Apple Silicon's total store ordering mode and other matrix extensions.

When the poster wrote "Apple diverges from standard 64-bit ARM architecture in specific ways" I expected the link to have more information on the Apple Silicon, but found it was just ABI information.

See for yourself -

https://developer.apple.com/documentation/xcode/writing-arm6...

Re:HelloSilicon – An introduction to assembly on Apple Silic... by masklinn on Monday December 26, 2022 @05:51AM (#34136561)
> I know about Apple Silicon's total store ordering mode and other matrix extensions.

OK?

> When the poster wrote "Apple diverges from standard 64-bit ARM architecture in specific ways" I expected the link to have more information on the Apple Silicon, but found it was just ABI information.

Yees?

That's really no clearer.

The poster wrote that Apple diverges from "standard 64-bit ARM in specific ways", and extensions aside the ABI restrictions is those specific ways: they mean that you can't take random ARM64 assembly or machine code and run it on Apple Silicon without validation that the additional restrictions are respected.

Again, what did you mean exactly? Did you expect Apple Silicon to not implement ARM despite being an implementation of the ARM ISA?

Re:HelloSilicon – An introduction to assembly on Apple Silic... by kevin_thibedeau on Sunday December 25, 2022 @09:05PM (#34133754)
They have features to simplify x86 emulation like additional ALU flags.
Re:HelloSilicon – An introduction to assembly on Apple Silic... by sounds on Monday December 26, 2022 @01:17AM (#34135170)
I replied to this post: "Apple diverges from standard 64-bit ARM architecture in specific ways"

I know about Apple Silicon's total store ordering mode and other matrix extensions.

When the poster wrote "Apple diverges from standard 64-bit ARM architecture in specific ways" I expected the link to have more information on the Apple Silicon, but found it was just ABI information.

See for yourself -

https://developer.apple.com/documentation/xcode/writing-arm6...

Re:HelloSilicon – An introduction to assembly on Apple Silic... by fragmede on Sunday December 25, 2022 @02:06PM (#34130074)
The book assumes running Darwin/OS X, which has consequences specific to that, eg https://github.com/below/HelloSilicon#listing-9-1 but one of the biggest changes is the GPU attached to the arm core, resulting in non-native Apple-specific code. It may not affect the ARM CPU core directly, but if someone is running on Apple Silicon you can assume MPS support whereas you cannot do that for ARM64 targets.

It might also be worth reiterating that this book is, itself, a port from the original, more generic ARM version.

Re:HelloSilicon – An introduction to assembly on Apple Silic... by galad87 on Sunday December 25, 2022 @02:00PM (#34130004)
The differences are listed in the linked page.
Re:HelloSilicon – An introduction to assembly on Apple Silic... by jws on Sunday December 25, 2022 @02:07PM (#34130084)
The Apple ABI has requirements not present in the generic ARM.

https://developer.apple.com/documentation/xcode/writing-arm6...

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.
Re:HelloSilicon – An introduction to assembly on Apple Silic... by pjmlp on Sunday December 25, 2022 @02:51PM (#34130570)
Not all ARM chips are made alike, Apple Silicon is yet another variation.
Re:HelloSilicon – An introduction to assembly on Apple Silic... by moffkalast on Sunday December 25, 2022 @06:54PM (#34132890)
Sure, but the bottom line is can you compile something for ARM64 and have it work on it or not? Since people keep bringing it up I assume the answer is no.

And I suppose that's entirely typical, nothing says Apple as much as as making something as custom and incompatible as possible for literally no reason except ecosystem locking.

Re:HelloSilicon – An introduction to assembly on Apple Silic... by saagarjha on Sunday December 25, 2022 @09:37PM (#34133935)
The answer is yes.
Re:HelloSilicon – An introduction to assembly on Apple Silic... by moffkalast on Monday December 26, 2022 @06:38AM (#34136837)
Then why the ruckus?
Re:HelloSilicon – An introduction to assembly on Apple Silic... by dagmx on Monday December 26, 2022 @10:58AM (#34138694)
Because it’s a superset, and there’s specific characteristics to keep in mind that people have linked multiple times above