4 ms·
Shouldn't gcc (or a similar helper tool) be able to understand the side effects of the asm instructions and automatically fill in all the clobber flags, instead
by 0x0 11y ago
Shouldn't gcc (or a similar helper tool) be able to understand the side effects of the asm instructions and automatically fill in all the clobber flags, instead of manually having to fill in all those crazy =r style markers? Is it not possible to code something that determines all affected registers for a given set of assembly opcodes?
- msbarnett 11y agoIt's certainly possible to do a lot better than GCC's inline assembly setup, which has proven time and again to be a usability disaster that positively encourages writing subtly buggy code. Microsoft's C compilers do a much better job with inline asm by being more conservative in how they allocate registers around the asm (https://msdn.microsoft.com/en-us/library/k1a8ss06.aspx https://msdn.microsoft.com/en-us/library/k1a8ss06.aspx). CodeWarrior's PPC compilers remain the ne plus ultra of inline assembly ergonomics, and it's a goddamn shame that LLVM has chosen (for pragmatic reasons) to follow GCC's mediocre lead rather than pursue something akin to it.
- userbinator 11y agoI think this stems from the same "lazy design" that made (G)AS' x86 syntax so very unpleasant to work with --- they just decided to make inline Asm literally dump strings out into the compiler's own Asm output, with some printf-like placeholders to be replaced with variable names/register assignments. There's a belief of "strict modularity" (i.e. compiler doesn't know at all about the inline Asm other than what the programmer tells it explicitly) which probably had some influences too, whereas MSVC et.al decided to spend a bit more effort on making things work in a more integrated fashion.
- cokernel_hacker 11y agoClang provides both GCC and MSVC style inline assembly.
- msbarnett 11y agoHoly crap, I was not aware of that. edit: this doesn't seem well-documented, if true. The Clang site mostly just talks about GCC compatibility, eg) http://clang.llvm.org/compatibility.html#inline-asm http://clang.llvm.org/compatibility.html#inline-asm
- pm215 11y agoOne major motivation for inline asm is wanting to use an insn which your toolchain doesn't know about (because it is too new, for instance). Inline also has to be able to handle cases like inline system call instructions -- in that case the clobbered registers are determined by the kernel syscall ABI, so it is impossible for a compiler to get them right by just looking at the asm insns.