What's the cause of the increase in unportable assembly code which targets the 64-bit ARM ISA in Apple’s ARM-based computers?

Writing portable ARM64 assembly
Apr 13, 2023
An unfortunate side effect of the rising popularity of Apple’s ARM-based computers is an increase in unportable assembly code which targets the 64-bit ARM ISA. This is because developers are writing these bits of assembly code to speed up their programs when run on Apple’s ARM-based computers, without considering the other 64-bit ARM devices out there, such as SBCs and servers running Linux or BSD.

The good news is that it is very easy to write assembly which targets Apple’s computers as well as the other 64-bit ARM devices running operating systems other than Darwin. It just requires being aware of a few differences between the Mach-O and ELF ABIs, as well as knowing what Apple-specific syntax extensions to avoid. By following the guidance in this blog, you will be able to write assembly code which is portable between Apple’s toolchain, the official ARM assembly toolchain, and the GNU toolchain.
The main cause of the increase in unportable ARM64 assembly code targeting Apple's ARM-based computers is **developers optimizing for Apple's specific platform without considering the broader ARM64 ecosystem**. 

Here's a breakdown:

* **Focus on Performance:** Developers are motivated to improve performance on Apple's ARM-based Macs. Using assembly code allows them to gain a performance edge by directly manipulating the processor's instructions.
* **Lack of Awareness:** Some developers might not be aware of the differences between Apple's ARM64 implementation and the wider ARM64 ecosystem. This leads them to use Apple-specific syntax extensions or rely on platform-specific optimizations that are incompatible with other ARM64 platforms.
* **Lack of Standardization:** While the ARM64 instruction set architecture is standardized, there are differences in how operating systems and toolchains implement it. Apple's Darwin operating system and its toolchain have specific features and conventions that are not present on other ARM64 platforms.

**The article highlights the importance of writing portable ARM64 assembly code:**

* **Increased Code Reusability:** Portable code can be used across different ARM64 platforms, reducing development time and effort.
* **Wider Applicability:** Code can be used on a broader range of ARM64 devices, expanding the reach of applications.
* **Improved Maintainability:** Portable code is easier to maintain and update, as it doesn't require platform-specific modifications.

By understanding the differences between Apple's ARM64 implementation and other ARM64 platforms and following best practices for writing portable assembly code, developers can create code that is both efficient and widely applicable. 
