4 ms·
Hello, I am a programmer. I have little idea what modern day compilers are doing, or what the CPU, or the operating system is doing for that matter. Often, wa
by mmphosis 14y ago
Hello, I am a programmer.
I have little idea what modern day compilers are doing, or what the CPU, or the operating system is doing for that matter. Often, way too often, compilers fail, hardware fails, operating systems fail, lots of things fail. I am not going to read the millions of lines of code written by other programmers (in f-ing emacs no less) in the any number of differing complex beasts, the compilers. It seems crazy-making to me, that other programmers would create compilers that would use millions of possibilities of optimizing a single line of mine using hundreds of different optimization techniques based on a vast amount of academic research that I won't be spending years getting at. I do feel embarrassed, yes very icky, that I have little to no idea what a three-line loop will be compiled as, but bloat would be my guess. There is risk in going to great lengths of optimization or doing the dirtiest tricks. And if I don't want the compiler to do this, I have no idea how to stop this behavior, nor do I want to invest in the specific knowledge of the nuances any particular compiler. The compiler does not allow me easy access because the compiler itself is an overly complex piece of software written by other programmers. I could care less about how a compiler would make my code would look in assembly, on different processor architectures and different operating systems and in different assembly conventions. Transformation comes with how we as programmers write code, not in compiler-fu.
P.S. Oh, and by the way if I really wasn't using half of the code I wrote, I would throw the source code away.
- simias 14y agoYou seem to be saying that you're at the same time completely clueless about how programs get built and executed and yet you know better that the compiler what needs to be done. I've found that in the general case Compilers Know Better. It might not be true for very simple and limiter architecture such as small microcontrolers, but modern CPUs are so much complex and "quirky" that most of the time the compiler will beat you. These days I only use assembly for very low level stuff where I need complete control of the execution flow (dealing with cache invalidation, MMU etc...) or some very specific and aggressive optimisation (like implementing <string.h> in ASM). But hey, if you want to ditch C and write everything in ASM, be my guest (as long as we don't work together).
- wbl 14y agoThe reverse is actually true. On simple orthogonal architectures the compiler is much more able to take advantage of all the features, while on x86 there are many instructions a compiler will never generate because of limitations on when they can be used. A human can occasionally do better then the necessarily limited algorithm used for scheduling and instruction selection.
- simias 14y agoMy rationale was that it takes a much bigger knowledge base to optimize code for more complex architectures because of all the factors you have to take into account. On simple architectures it's often very straightforward and you can sometimes save CPU cycles/memory space by doing some refactoring the compiler can't/is not allowed to do. You can for instance "stash" certain important values in CPU registers across functions, disregarding the ABI to avoid pushing/popping the stack or moving stuff around in registers. Well, that's not a very good example because you can tell GCC to do exactly that, but it's not a standard C feature and the compiler cannot do that on its own across translation units. So it's one of those situations where you can "outsmart" the compiler, even if the compiler would probably tell you it's not fair game :)
- colanderman 14y agoIt's not orthogonal vs. crazy x86-y instruction sets, it's in-order vs. superscalar processing. The compiler knows the intimate details about each architecture's pipeline latency to a degree that most programmers don't.
- cliffbean 14y ago> I have little to no idea what a three-line loop will be compiled as, but bloat would be my guess. This is unfortunately too often true. Some compilers are tuned too much for looking good on artificial benchmarks, in which turning 3-line loops into thousands of instructions sometimes helps, even if it hurts on most real-world code. > And if I don't want the compiler to do this, I have no idea how to stop this behavior, nor do I want to invest in the specific knowledge of the nuances any particular compiler. The -O0 option, or its equivalent, is pretty easy to find in many compilers. If you're happy with the performance of your code without all those fancy techniques being applied, feel free to use it. Most people aren't ;-). > P.S. Oh, and by the way if I really wasn't using half of the code I wrote, I would throw the source code away. Only if you were aware of it ;-). I wish that compilers would focus a little more on helping me make my code better, rather than so much on magically making things better under the covers.
- JasonFruit 14y agoIf you want your compiler to do more to help you improve your source, you might like Go, which offers a lot of (sometimes unwelcome) mandatory suggestions that force you to do the right thing even when you don't want to. (Ada and Pascal do the same thing according to a very different philosophy.)
- rthomas6 14y agoI have come to love the strong typing of VHDL (very similar to Ada but for hardware design). After using it for a while, in my uninformed opinion, I think it can drastically reduce bugs because it assumes nothing and makes the programmer define exactly what they mean.
- ncallaway 14y agoEven better for him, -O0 is the default (for most compiler's I've worked with). You need to opt-in to optimizations most of the time.