4 ms·
You 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
by simias 14y ago
You 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.