[Pre-RFC]: Inline assembly

I really like this! Some feedback:

  • Some architectures use special characters in register name, so it might be better to put register names in quotes: in("eax").
    • x86 uses st(1), st(2)
    • MIPS uses $0, $1
  • Figuring out a short name for some constraints is not trivial, it might be easier to just stick with the existing GCC single-letter contraints. In particular some constraints can be very complex:
    • (PowerPC) P: An immediate integer constant whose negation is a signed 16-bit constant.
  • Have you considered simply using a bare volatile instead of flags(volatile)? Additional flags can be added after that.
  • An asm! with no outputs is meaningless if the volatile flag isn’t specified. It should be a compile-time error for a non-volatile asm! to have no outputs. Previous discussion.
  • Template argument modifiers are absolutely required in practice. I make heavy use of them in my code (ARM64 assembly). I think that we can just reuse LLVM’s single-letter modifiers here since these are used in the format string: mov {0:w}, {1:x}
  • The RFC should specify the rules for the clobber list. I think we should follow LLVM here: a register can’t both be an output and clobbered. However it is fine for a register to be an input and clobbered. (This only applies to explicit register inputs/outputs).
  • I suggest adding an additional direction specification tmp to deal with temporary registers and clobbered inputs:
    • An input value may be specified, or _ can be used to indicate that the temporary register has no initial value.
    • This is equivalent to an inout (with initial value) or out (without initial value) where the output value is simply discarded after the asm!. This is how it is done is C but this is very unintuitive.
  • You might want to specify that, like format strings, you can escape braces with {{ and }}. This is needed for certain ARM instructions.

Regarding your questions:

9 Likes