While in most cases its not necessarily, recently I have taken to reading the generated assembly of my C code every so often, when I'm curious as to the kinds of optimizations my compiler is making. Especially for low level code or functions which are called many times.
- Checking if a change to the C code has any impact on the generated code.
- Checking if the same expression used twice is optimized into one, or if assigning a variable makes a difference.
- Check for changes which may bloat-generated code-size.
Now this is not a perfect method by any means, its possible that some difference in the generated output is a red-herring, because of all sorts of internal logic & thresholds within the compiler, but its still interesting at times.
At this point while looking at the assembly I can lookup each command, but not really read the assembly (amd64 as it happens).
So my question is, has anyone found it useful to learn a certain amount of assembly to write better C code? (or at least get more insights into their code).
- If so, how much is useful to know?
- What kinds of issues did it help you resolve?
Note, the danger here is that one writes C code targeting the assembly which is very specific to the developers own system - any advantage may be lost on a different compiler or architecture, taking that into account, Im still interested in other developers experience