On 09/12/2007 09:23 PM, Rik van Riel wrote:
Talib Alim wrote:
I am looking for something to read for optimizing my code on i386 and
MIPS arch. Any pointers will be appreciated.
Nowadays CPU cores tend to be really fast, while RAM is
ludicrously slow in comparison.
This means that instead of code optimizations, the large
gains tend to come from optimizing data structures, mostly
to avoid cache misses and false sharing on SMP systems.
Which is annoying since it means that assembly language programming really
is quite useless these days but note it's also very true.
The compiler will do the mechanical stuff such as laying out loops and jumps
on suitable boundaries and will in fact usually be much better then you at
doing things like avoiding pipeline stalls -- since that's just the kind of
annoying book-keeping computers are quite by design much better in then humans.
A cache miss dwarves anything in comparison: memory is _that_ slow. And that
principle is no different on different CPUs so that optimisation these days
only makes any sense on a fairly high algorithmic and (data) structural
level. That is, you get annoying bogosoties like actually calculating
something sometimes maybe being faster than using a lookup table, since the
table poisons the data cache.
Then, since cache effects are system-global effects, they're also hard to
measure: if you just measure your own code, it may be perfectly fast if it
all fits in the CPU caches during the test but if your code or data is
bigger than an alternative, it may end being slower in practice since there
is more to pull into cache, and more other things that are thrown _out_ by
it meaning those then take so much longer.
Assembly still has a place in extremely local, short sequences sometimes if
only because you don't want to have to guess what the compiler is going to
do but otherwise, its time really is 99% past.
Unless you're a compiler writer...
Rene.
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ