7 ms·
Optimization algorithms will lead the result to a local minima, while missing a global minima. I think this is the one of the huge differences between humans a
by userbinator 12y ago
Optimization algorithms will lead the result to a local minima, while missing a global minima.
I think this is the one of the huge differences between humans and compilers that leads to suboptimal code - the compiler is completely unaware of what the programmer intended in the HLL source, so the best it can do is to generate code which it "knows" is the fastest way to implement exactly those statements; on the other hand, if you are a human writing an algorithm in Asm, you probably have things like instruction selection and register allocation already in mind and are willing to slightly change the "semantics" of your algorithm if it results in e.g. a better use of registers or the possibility to use a faster/smaller instruction.
In other words, the compiler starts with something horribly unoptimised but following the semantics of the source language, and tries to make that as fast/small as it can while still maintaining the same semantics - and so this is the "local minima" it can reach. The human starts with a concept of an algorithm and its intended result, and everything in-between is flexible, so this is a more "global" view of the problem of code generation. The human isn't restricted by the semantics of the HLL, but can fully express the intended algorithm by exploiting the full capabilities of the processor.
- WalterBright 12y agoThe human also knows things that the compiler doesn't - such as which branches of the code are speed critical and which aren't. This matters for things like where precious registers get allocated.