Hi All, I was recently re-exposed to the madness that is our current inline assembly support. I’d like to improve it.
What we currently have hasn’t changed much since it was first implemented, it’s not much more than a thin wrapper over the inline ASM support LLVM has. The restrictions are largely undocumented, and largely unchecked, resulting in crashes in the compiler.
I personally have a little bit of experience with inline ASM, as it’s used in Ramp, but not a huge amount, so I’d like to get some input from the community about it. I aim to write (and probably implement) and RFC for inline ASM, but no guarantees. Here’s some initial ideas:
- Syntax remains mostly the same as it is now. There’s not really much wrong with the syntax and keeping it (mostly) the same means less burden for users if/when inline ASM is changed.
- Allow named parameters. GCC supports this, in a parameter declaration, you can use
[foo]to provide a name to a parameter that can then be used as
%[foo]in the ASM template.
- A well-defined template format. Currently we use the same template format as LLVM, to support the above idea we’d need to expand on it anyway, but defining our own format, even if it doesn’t actually change anything, means we’re not tied to LLVM.
- Only general constraints. At least at first. Most of the time, memory (
m) and register (
r) are enough. There’s a few other constraint types that are usable across platforms and can be useful, but having a relatively small number of constraints makes it easier to check them ahead-of-time. Maybe allow for specific register constraints though, since they might be useful enough.
- Well-defined requirements for constraints. It’s pretty unclear what you can and can’t do with various constraints in the current set-up.
What do people have to add? I’d like to keep it as simple as is reasonably possible, but otherwise I’m mostly interested in what people are using inline ASM for, or would like to use it for, so I can get a handle on what really needs to be there and what should be checked and what should be left up to user to handle.