News for hackers. Stuff that matters.
Re:Apple CPU tricks: memory reordering, JavaScript support, ... by muststopmyths on Friday November 27, 2020 @07:25PM (#25233905)
>8/ Another "magic" trick is how their "Swift" programming language uses "reference counting" instead of the "garbage collection" in Android. They did something in their CPU to double the speed of reference counting.

What the hell does that even mean ?

Disregarding the nonsensical attribution of magic to Swift vs Java, if "reference counting" on translated x86 code is faster, then I suppose M1 does "lock add / cmpxchng" or whatever faster than X86.

I would love to know how. Other than just as a side-effect of a SoC, UMA architecture.

Re:Apple CPU tricks: memory reordering, JavaScript support, ... by ksherlock on Friday November 27, 2020 @08:29PM (#25234305)
Maybe this: https://twitter.com/Catfish_Man/status/1326238434235568128

fun fact: retaining and releasing an NSObject takes ~30 nanoseconds on current gen Intel, and ~6.5 nanoseconds on an M1

...

Weaker memory model makes acquire-release atomics possible to implement much more efficiently, in exchange for not hiding some classes of multithreading bugs

Re:Apple CPU tricks: memory reordering, JavaScript support, ... by muststopmyths on Friday November 27, 2020 @09:42PM (#25234738)
I guess I understand the ARM behavior, but both this thread and the original one talk about x86 retain/release being faster on M1 as well.

That's the part I'd love someone knowledgeable to explain.

Re:Apple CPU tricks: memory reordering, JavaScript support, ... by dathinab on Friday November 27, 2020 @08:28PM (#25234294)
> What the hell does that even mean ?

> double the speed of reference counting

The simplest low latency system memory making atomics faster in some contexts (faster cache write back/fetch).

Then atomic operations (using Aquire/Release) are theoretically faster on ARM due to the weak memory ordering (I'm not sure if this does help for translated x86 code).

Potentially other reasons can include:

- maybe optimized fetch add/sub instructions (or more precise the ARM instructions used by fetch add/sub functions in higher level languages)

- maybe tweaks to the coherence protocol

- maybe specialized optimizations in the pipelineing

All in all it means Apple focused on making sure fetch add/sub are fast (most likely as this is what is normally used for Rc).

Re:Apple CPU tricks: memory reordering, JavaScript support, ... by annilt on Friday November 27, 2020 @08:29PM (#25234302)
I think it says refcounting twice faster for swift on M1 compared to swift on x86.

It is possible because if you don’t have TSO(total store order), you can employ atomic operations without waiting/flushing previous items in the CPU’s store buffer

Re:Apple CPU tricks: memory reordering, JavaScript support, ... by gpderetta on Saturday November 28, 2020 @05:25AM (#25236751)
But apparently they are faster even in TSO mode.

Maybe they aggressively speculate around them.