3 ms·
Pros of asm goto: it's useful for introducing low overhead tracing and debugging abstractions. Tracepoints in the Linux kernel are one example [1]. It's also us
by lpage 7y ago
Pros of asm goto: it's useful for introducing low overhead tracing and debugging abstractions. Tracepoints in the Linux kernel are one example [1]. It's also used for implementing certain Meltdown/Spectre mitigations [2].
Cons of asm goto: as parent points out, asm blocks are largely opaque to the compiler, which stands in the way of optimization. Control flow analysis can't take into account internal jumps, and for GCC at least, every asm goto block gets flagged as volatile. That disables whole classes of optimization.
Unless you're relying on hardware-specific instructions that the compiler doesn't know about or expose as an intrinsic, there's always an alternative to asm goto. That said, those alternatives might prove more expensive than the loss of optimizations precluded by the use of asm goto [2].
The pros/cons of including asm goto in clang were discussed in [3].
[1] https://lists.llvm.org/pipermail/llvm-dev/2017-April/111748.html https://lists.llvm.org/pipermail/llvm-dev/2017-April/111748....
[2] https://lwn.net/Articles/748074/ https://lwn.net/Articles/748074/
[3] http://lists.llvm.org/pipermail/llvm-dev/2018-October/127239.html http://lists.llvm.org/pipermail/llvm-dev/2018-October/127239...