5 ms·
Starts by saying how it's a huge myth that compilers generate better code than hand-made assembly... and ends with compiler-generated code, the author basically
by ramchip 16y ago
Starts by saying how it's a huge myth that compilers generate better code than hand-made assembly... and ends with compiler-generated code, the author basically saying "I think I could do better".
It was interesting to see what the compiler generated, though it won't be a big surprise to experienced C coders.
- JoachimSchipper 16y agoIf you read it slightly more charitably as saying "you need to know a thing or two about how computers work, even if you have a nice optimizing compiler", it makes sense.
- lbrandy 16y ago> Starts by saying how it's a huge myth that compilers generate better code than hand-made assembly... It's important to note that I never said this. I was simply trying to separate two versions of the same rule of thumb... I said that using a compiler, a smart low-level programmer can generate the assembly code he wants. This is not "hand-made" assembly, but this is not just the magic of an optimizing compiler, either.
- ramchip 16y agoI do see your point and I found it interesting (I've had to optimize filters in the past and used the same process of coding C and looking at the assembly), but how can "beating the compiler" be interpreted as anything but writing better code than the compiler?
- Retric 16y agoWriting optimized code generally involves looking at larger sections of the problem / code base and picking a different approach based on global conditions. So, when you and the compiler are booth looking at the same code base, but you find a better local approach based on a global condition you have beaten the compiler. Even if all you did was tell it about that condition.
- deleted 16y ago[deleted]
- smcl 16y agoTrue, but it's easy to forget that many people don't use compiler\architecture-specific extensions or pragmas (and probably don't even need to). I think the article provides a gentle nudge into the "think about what exactly you are telling the compiler" mindset for such people.
- JoachimSchipper 16y agoAlthough there's no need to venture into unportable extensions here - as I pointed out at http://lbrandy.com/blog/2010/06/you-cant-beat-a-good-compile/comment-page-1/#comment-26448 http://lbrandy.com/blog/2010/06/you-cant-beat-a-good-compile..., C99 has the "restrict" keyword.