On Fri, Dec 14, 2012 at 10:27:30PM +0100, Paulo Pinto wrote: > On Friday, 14 December 2012 at 20:33:33 UTC, H. S. Teoh wrote: [...] > >Yeah. If you want to squeeze out every last drop of juice your CPU's > >got to offer you, you could code directly in assembler, and no > >optimizing compiler, GC or no GC, will be able to beat that. > > > > I think it depends on what you're trying to achieve. > > If coding for resource constrained processors, or taking advantage of > special SIMD instructions, then I agree. > > On the other hand if you're targeting processors with multiple > execution units, instruction re-ordering, multiple cache levels, NUMA, > ..., then it is another game level trying to beat the compiler. And > when you win, it will be for a specific set of processor + motherboard > + memory combination.
Yeah, that too. Coding in assembler also requires the price of being tied to a specific version of a specific model of a specific brand of a specific vendor's CPU & motherboard. Like the OP stated, it may take you a few 100 years to produce your superior code, when what you write in 1 day with an optimizing compiler will probably perform close to or even match the handcrafted version, plus it has the advantage of being cross-platform. Not to mention, the CPUs of the old days were designed with assembly language or low-level languages in mind. The modern CPUs of today were designed with optimizing compilers in mind. The ease (or rather, difficulty) of hand-coding for modern CPUs is not mere happenstance. :-) > Usually the compiler is way better keeping track of all possible > instruction combinations for certain scenarios. > > Well this is just my opinion with my compiler design aficionado on, > some guys here might prove me wrong. [...] Well, I'm pretty sure that the difficulty (or rather impossibility) of solving the halting problem, which is equivalent to the difficulty of global optimization (cf. Kolmogorov complexity), means that there will always be cases where the compiler won't generate optimal code. However, it's an open question whether humans can beat the compiler at its own game. Just because we can *sometimes* solve specific instances of the halting problem (or come close) by special insight, doesn't mean that we'll always do better than the compiler in the general case. T -- Political correctness: socially-sanctioned hypocrisy.