Asm blocks only allow identifiers to specify input/output #2334
Labels
use case
Describes a real use case that is difficult or impossible, but does not propose a solution.
Milestone
Currently, Zig only accepts identifiers as output/output parameters to asm blocks, which is very limiting compared to the range of options available in gcc/clang, and makes a range of x86 asm instructions unusable.
I see this is currently expected, per the syntax description:
LPAREN (MINUSRARROW TypeExpr / IDENTIFIER) RPAREN
I understand that the asm block syntax is in flux, but I believe widening the range of acceptable inputs/outputs is orthogonal to that effort.
As motivating examples:
in C I can have an asm block output directly to a struct field:
More subtly, in my operating system project, I have a need to save and restore floating point context, which is done with
fxsave
/fxrstor
on x86. Due to the way these are encoded and the way gcc/clang choose to implement them, you have to pass the value at the location where the context should be stored as opposed to a pointer. Take the following C code:Notice how I have to dereference the context inside the asm block, and the generated instruction then somehow gets a pointer to that value:
Compare that to the equivalent zig code, where I can't dereference that ctx:
In Zig, no matter what I try, the generated asm always tries to dump the floating point context onto the stack:
I hope this is at least somewhat clear, I don't fully understand why the
fp*
instructions behave this way, but I hope the struct example at least serves as a more approachable motivating example for why more expressiveness in asm input/outputs would be great to have.The text was updated successfully, but these errors were encountered: