Don't Use Inline Assembly
gcc.gnu.org
Don't Use Inline Assembly
1–10 of 11 posts
Re: Don't Use Inline Assembly
#2Otherwise it really should not be done. It is extremely unlikely that it helps with performance problems. The article list the exceptions. Perhaps add interrupts to that, since you always want them to return as fast as possible. Not really needed on a higher level platforms though.
Re: Don't Use Inline Assembly
#3Re: Don't Use Inline Assembly
#4Re: Don't Use Inline Assembly
#5For example, let's say an operating system's kernel has a procedure to disable cache snooping on the CPU. There is no way the compiler can implicitly generate this for you, except if a special built-in function is provided. But built-in functions do not exist for every case, and not for every supported CPU architecture.
In this example, every architecture-specific code of the kernel shall implement an interface named disable_cache_snooping() wrapping an inline assembly statement, invoking the underlying (x86, arm, mips, sparc, riscv, etc.) CPU's special instructions to disable cache snooping.
Re: Don't Use Inline Assembly
#6Re: Don't Use Inline Assembly
#7It doesn't say what to do instead: use compiler intrinsics, if portable code won't do. Those get tailored for different target architectures automatically.
> B) To access CPU-specific instructions.
> It is possible that the reason gcc isn't generating the specific instruction you expected is that it is known to be slow, problematical, not supported on the processors you are compiling for, etc. But if there is a reason you need a specific instruction, gcc has builtins for many of the more useful ones. Using these in preference to inline asm allows gcc's optimizers to produce better code. However it is possible that an instruction is new enough or obscure enough that there is no builtin for it.
Re: Don't Use Inline Assembly
#8Re: Don't Use Inline Assembly
#9It's possible that in the future, with better compilers, the portable code will be actually faster. Even if not, having portable code is a huge plus.
Re: Don't Use Inline Assembly
#10It doesn't say what to do instead: use compiler intrinsics, if portable code won't do. Those get tailored for different target architectures automatically.
It does, but it calls it builtins instead > B) To access CPU-specific instructions. > It is possible that the reason gcc isn't generating the specific instruction you expected is that it is known to be slow, problematical, not supported on the processors you are compiling for, etc. But if there is a reason you need a specific instruction, gcc has builtins for many of the more useful ones. Using these in preference to…
A quiet "-mavx" to unlock these particular shackles fixes numerous performance failings.