-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Moving WebAssembly inline assembly forward #136382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
My impression is that LLVM's support for wasm inline assembly is not comparable to support for other architecture:
So I would not recommend moving forward with stabilizing Wasm inline assembly without first getting a vibe check from the LLVM backend maintainers. Even if Rust people wanted to put in the work of fixing the bugs that affect Rust users, is there even enough upstream interest and maintainer bandwidth to review and merge that work? |
It's even worse than there being no GCC equivalent. There is a standard text format specified for wasm, but LLVM created an entirely different format for whatever reason which no other tool in existence works with. |
Sounds like this is nowhere close then. Our flags could probably still be improved but I guess that is about it.
Does LLVM provide equivalents for control flow or is it just a strict subset of WAT without S-expressions? We could very nearly handle wasm text->binary ourselves at least as well as LLVM could, if that wouldn't also require us doing the validation... |
If both are worth having then in theory there could be a |
The LLVM text format was chosen to match the existing assembly format support in LLVM. It reuses a lot of the existing infrastructure. It doesn't support any kind of nesting and looks more like the unfolded/linear form of wat, but that is largely because that is what llvm expects from an asm format. Doing this differently would be very hard I think. I don't think there are any plans to replace this format in LLVM and its use is fairly widespread now, admittedly a lot of it is in form of non-inline separate |
Is there a formal definition of the text format LLVM uses? There is for the official wasm text format. How hard would it be for rustc to convert the official text format (+ annotations for things like relocations) to the format LLVM uses? If we get another backend which supports wasm, I think it is unlikely that this other backend will exactly mirror LLVM's text format. Using the official text format is more likely and even if it doesn't, it should be a lot easier to convert a text format with a robust definition and an existing parser written in rust (wasmparser) to whichever format said backend uses than it would be to parse LLVM's custom text format. And if the other backend uses LLVM's custom text format after all it can reuse the same conversion code as we use for the LLVM backend. |
No, there is no formal definition that I know of. However, I don't think there are formal definitions of other assembly languages either. For example from the x86_64 asm docs https://docs.oracle.com/cd/E19253-01/817-5477/817-5477.pdf: "There is no standard assembly language for the x86 architecture." |
Unlike for x86 there is actually a standard text format for wasm, so there is much less of an excuse to use a poorly specified format. And I believe for arm at least the format for individual instructions is specified by Arm Limited, but I'm not sure if assembler directives are also specified by them. |
I think the important part is that the syntax including important directives realistically won't change in backwards incompatible ways. @sbc100 has said that there's no plans to replace this format and it has a fair amount of usage in separate |
x86 currently allows using the different syntaxes in module asm via Also, thanks for the insights here. |
I think that there are bunch of technical reasons why switching LLVM to use something like wat is a lot more complicated that it might appear. The LLVM assembly / disassembly infrastructure is all driven by the MC layer where a there is a lot shared code/infrastructure. Its not only used for inline assembly as an input and output format for several tools such as llvm-mc. Trying to use an assembly format that is different to all the other ones in LLVM would, I think, be a lot of work. The assembly formats used by LLVM are all based the idea of a linear stream of directives, labels and instructions. Trying to add an s-expression format like WAT would require a whole lot of new infrastructure and would prevent the WebAssembly sharing code with the other backends. It might not even be feasible at all. I think it would also result in the backend being harder to maintain for other LLVM developers. |
It makes sense that the LLVM syntax is pretty deeply ingrained, thanks for the clarification. Do you think we would run into any problems if we parsed WAT and converted it to LLVM's version on our end? (I am not sure whether your comment about s-expression vs linear applies specifically to thorough LLVM support or also a surface level transpilation like we would be attempting to do). If that is feasible then it seems advantageous for us, especially regarding the ability to support different backends. Separately, I wonder if whatever we wind up figuring out might also provide a better flow for assembling/linking standalone |
Personally I've felt that inline asm in wasm has fallen into one of two categories: (1) accessing fancy instructions or (2) accessing constructs outside of the compilation model. For (1) most of the need there is satisfied with compiler intrinsics (e.g. simd or To do (2) I believe it's required to work with the Personally I think it would be quite useful to use inline asm on wasm, I agree with the hesitation to stabilize exactly-what's-there as-is, and I don't think that a translation layer built into rustc is going to be all that simple. That being said I'd be happy to work/collaborate with folks on implementing/designing annotations for |
@bjorn3 did you have any loose idea about what relocations would look like in annotations? |
|
I'm opening this issue to consolidate some scattered discussion about what is needed to make inline assembly for Wasm work. This is tracked along with the other architectures at #93335. That thread notes:
So, for Wasm specifically:
in
,out
,lateout
,inout
,inlateout
) or options (pure
,nomem
,readonly
,preserves_flags
,noreturn
,nostack
,raw
)? We should probably rejectpreserves_flags
. I'm not sure iflateout
andinlateout
make sense.Cc @daxpedda @hanna-kruppe @alexcrichton @hoodmane @solomatov, I think you have all been involved in the wasm-inline-asm discussion in different places.
The text was updated successfully, but these errors were encountered: