Liste des Groupes | Revenir à c arch |
David Brown <david.brown@hesbynett.no> wrote:
I would agree with you there. For the same object code, newer CPUs (with the same ISA) are typically faster for a variety of reasons. There may be the odd regression, but it is hard to market a newer CPU if it is slower than the older ones!Of course the fine line between "smart code" and "smart-arse code" isI know of no example where hand optimized code does worse on a newer CPU.
somewhat subjective!
>
It also varies over time, and depends on the needs of the code.
Sometimes it makes sense to prioritise efficiency over readability - but
that is rare, and has been getting steadily rarer over the decades as
processors have been getting faster (disproportionally so for
inefficient code) and compilers have been getting better.
>
Often you get the most efficient results by writing code clearly and
simply so that the compiler can understand it better and good object
code. This is particularly true if you want the same source to be used
on different targets or different variants of a target - few people can
track the instruction scheduling and timings on multiple processors
better than a good compiler. (And the few people who /can/ do that
spend their time chatting in comp.arch instead of writing code...) When
you do hand-made micro-optimisations, these can work against the
compiler and give poorer results overall.
A newer CPU with bigger OoOe will effectively unroll your code and schedule
it even better.
It’s older lesser CPU’s where your hand optimized code might fail hard, and
I know of few examples of that. None actually.
This is especially the case
when code is moved around with inlining, constant propagation,
unrolling, link-time optimisation, etc.
>
Long ago, it was a different matter - then compilers needed more help to
get good results. And compilers are far from perfect - there are still
times when "smart" code or assembly-like C is needed (such as when
taking advantage of some vector and SIMD facilities).
Les messages affichés proviennent d'usenet.