4 ms·
That indicates that you swallowed a piece of dogma at some point and didn't think it through. The argument of "the compiler can make faster code than any progr
by buzzybee 10y ago
That indicates that you swallowed a piece of dogma at some point and didn't think it through.
The argument of "the compiler can make faster code than any programmer's assembly code" - which I think is what you are repeating here - is discussing whether writing an entire application in assembly will give great wins. It doesn't do so today because the compilers are much, much better at finding performance wins over a large, sprawling program; it's a poor use of coding time to attempt otherwise. It is inner loop code that is the concern of everyone writing low-level optimizations today, and inner loop code is a special beast. It can be attacked by writing C tuned around the compiler's optimizer, by writing inline assembly, or by writing a specialized compiler that compiles the optimal code path on demand according to some set of parameters.
C written for an general-purpose optimizer understands that a certain assembly-code result is wanted, and it understands that the compiler has a limited ability to analyze the code and produce that result. It's not the same as any other hand-written C, because it deliberately arranges scenarios that the optimizer can pick up on. It uses just-so orderings of statements that are mathematically transitive but will optimize differently in practice. It sets up usages of undefined behavior that are known to be used by the optimizer. It uses extensions specific to the compiler, if they lead to faster generated code. This is a nasty black art and optimizing falls towards this practice because it still ends up being more convenient than writing the assembly, for a variety of reasons - more fluidity in the larger context of the codebase, a safer fallback if the optimization fails, more portable.
Inline assembly is a hard break with the rest of the program, but for the most inner of inner loop code, the additional power over the details of execution continues to make a substantial difference.
Specialized compilation is gradually becoming more practiced for very demanding numeric applications and one can find the occasional paper or tool published about it. It's obviously more work than writing a single optimization once, but it has the benefit of being a potentially reusable abstraction.
- user5994461 10y ago> The argument of "the compiler can make faster code than any programmer's assembly code" - which I think is what you are repeating here WTF. I have never said that. I wasn't talking about the code generated by the compiler. I even wrote a message to clarify that I talk about handwritten code, not about code generated by a compiler.
- bogomipz 10y ago>" It is inner loop code that is the concern of everyone writing low-level optimizations today, and inner loop code is a special beast." Can you elaborate? Are you are talking about nested loops and quadratic run times?