ARM: Pragmatism, not purity

Yet another train getting across France-Spain border, yet another post.

In the last few weeks before the sabbatical I was working on bringing up AArch64 support for native code generation in Luau. Before that my interaction with this architecture was limited to occasional glance at a disassembly emitted by the compiler. Coming from x86 world and having often heard how ARM is a much cleaner architecture than x86, I expected smooth sailing and clean, simple and unambiguous mapping between instruction bytes and assembly text.

Well, I came away from this exercise being somewhat disillusioned. I think what I expected was a pure and clean mapping with separation of concerns, but instead there’s many quirks of the ISA that I haven’t really expected1. It’s still less messy than x64, and I don’t even disagree with the choices made - but a lot of them seem to eschew purity and instead attack the problem from a pragmatic angle, stated as “what useful instructions can we fit into a 32-bit encoding space”.

Here are a few notes, in no particular order, of things that surprised me.

Overall, none of these are deal-breakers and many are pretty easy to deal with - that said, I expected the A64 assembler to be much simpler than our X64 assembler (for the subset of instructions we need), and instead it’s going to end up with roughly the same amount of complexity3. It now feels like the real benefit that A64 ISA has is the fact that the instructions are all 4 bytes in size, which makes it much easier to implement wide frontends4 - coincidentally this of course seems to be where all the irregularities come from, as you effectively need to devise an encoding that makes it possible to unambiguously encode a large set of instructions and as much data as possible in some of them. From the perspective of writing an assembler or a disassembler, however, I’m not sure the gap is that wide otherwise…

  1. Note that I’ve had limited time to work with this ISA so I am likely missing a significant amount of information wrt history and reasoning. ↩

  2. This requires additional archetypes for our implementation that wants to be able to display disassembly on the fly while building the binary stream. ↩

  3. Neither implementation supports the full set of instructions, which is honestly a relief, for example considering that A64 has 96 instructions for memcpy-like operations, organized in 32 groups of 3, or the number of atomic-related instruction variants. ↩

  4. Keep in mind that I’m not a hardware engineer so who knows if this is true! I’m also omitting the simpler handling of multiple register widths, although A64 still supports 32/64 bit variants of most instructions that operate on 64-bit registers. ↩