Everyone Says Assembly Is Untyped—Everyone Is Wrong - gingerBill

16 Likes

Putting aside the smug ton, I like the solution he had for the problem.

I like that the register constraints are using Odin types, including vector types. Zig could use some improvement here. The "inout " syntax isn’t so clear in Odin though.

But I also abused Zig stringy ASM in the past for great success, like emitting PTX intrinsics or KVX assembly. Thoses aren’t Tier1 target for Zig and I don’t imagine they could receive such first class handling of their ISA.

The RexCode library providing full knowledge of how to encode/decode instructions is pretty cool. But I believe it’s mostly vibecoded, not that it matters IMO, for something so repetitive.

4 Likes

I’ve been waiting for something like this for what feels like ages.
The idea feels similar in spirit to parse inline assembly syntax according to a set of dialects; integrate inline assembly more closely with the zig language · Issue #10761 · ziglang/zig · GitHub, so I think it’s fair to say that it’s realistic Zig may get something comparable.

You can still assemble any instruction you like yourself without relying on the compiler

const code linksection(".text") = my_x86_64_assembler("xor rax, rax") catch @compileError("...");
2 Likes

For some reason, I don’t find this option very compelling in a discussion about the ergonomic of inline assembly.

It wasn’t a way saying it’s impossible to have a Zig version of this, but rather that Odin have it easy given they only support a few targets

1 Like

Sure, Odin doesn’t support as many ISAs as Zig, but

  1. The amount isn’t as big as it might seem at first (when you look at the output of zig targets, quite a few of the targets are just subvariants.
    And when you look at the isa subdirectory of rexcode you see most of these merged (for example there’s 1 directory for all supported x86 targets; zig targets lists these as 3; or there’s 1 directory for RISC-V while zig targets lists these as 4 even if rexcode doesn’t support the Big Endian versions (like the Linux kernel) while Zig does).
    Sure, it’s still less than Zig, but not as extreme one might think at first.
  2. At the end of the day, Zig needs an assembler for all of its targets anyways to target it. So developing the assembler information library first (which imo is always a good design principle) would essentially create Zig’s “rexcode” library.
5 Likes