4 ms·
> ...if you want to absolutely wring the last clock cycle out of a hot path, you usually need good microarchitectural knowledge... Could starting with compiler
by i336_ 9y ago
> ...if you want to absolutely wring the last clock cycle out of a hot path, you usually need good microarchitectural knowledge...
Could starting with compiler output for a given problem be a good idea for new programmers?
For example, I might take a complex problem I want to solve and then implement a series of solutions in multiple high-level(-ish) languages like C, FORTRAN, or even possibly Haskell. Once the implementations are correct, I get all languages to output assembly, and then spend a while pouring over the output, possibly doing some further iteration on the high-level source code in the process.
My thinking here is that, the compiler is basically a gigantic database+graph of "use this instruction in this scenario" and a crazy complicated state machine to direct operations throughout the graph. Way too complex to read through... but I can make a compiler tell me the 90th-percentile+-most-relevant instructions to use by simply writing my program in that compiler's language.
Obviously, the standard caveats about compilers producing terrible output apply - I'd never recommend treating compiler output as normative or "good for educational use", just a decent startpoint - and something to have no qualms about surpassing.
- innocenat 9y agoI would not entirely agree. Some of the current optimizations are so advanced and specific for each particular bit of code that it might not good to generalize from those output. I remember ICC generating different (but similar) code for each Intel CPU generation. I suppose it has to do with the decoder limitation (4-1-1-1, 4-2, 2-2, etc.) and exhausting execution port usage, but I never bother to confirm this. It gets very complex after a while.
- i336_ 9y agoOkay. My question was along the lines of "is this a sane default or am I wandering into a minefield," your answer is pretty much what I was looking for. > Some of the current optimizations are so advanced and specific for each particular bit of code that it might not good to generalize from those output. If only it were possible for the compiler to concisely describe its "workings-out". I imagine compilers can generate trace information, but it's probably pages long. > I remember ICC generating different (but similar) code for each Intel CPU generation. I suppose it has to do with the decoder limitation (4-1-1-1, 4-2, 2-2, etc.) and exhausting execution port usage... That's amazing. Definitely keeping that in mind, thanks!