1. 15
    1. 5

      A shame about the title, since most of this advice is also good for x86-64 assembly being portable between Macs and *NIX systems. There’s more you need to if you want portable to include Windows, because the register usage is different on the Windows ABI and because the way of addressing global symbols can be different.

      I’m also curious about whether the Apple NEON extensions were upstreamed to clang: can you use them if you use LLVM’s assembler rather than the GNU one?

      1. 1

        Yes (do they even actually originate with Apple or have they been in LLVM from the beginning?):

        % echo 'eor.16b v2, v2, v0' | llvm-mc16 -show-encoding -triple aarch64-unknown-freebsd
                eor     v2.16b, v2.16b, v0.16b          // encoding: [0x42,0x1c,0x20,0x6e]
    2. 3

      it allows you to define the correct ELF symbol types outside of Apple’s toolchain:
      #ifdef __clang__

      No no no no! clang does not imply Apple, please not like this! >_<

      1. 2

        Better might be #ifdef __APPLE__.

    3. 1

      Isn’t the C ABI being materially different on Apple ARM64 platforms vs AArch64 EABI also something that needs to be considered?

      1. 1

        Not really? The biggest difference I know of is that variadic functions always take their parameters on the stack. Which matters only if calling variadic functions, which doesn’t happen often. Similarly, char is signed, not unsigned, which matters very, very little.

    4. 1

      “Portable” and “assembly language” are not two terms I would expect to see together.