12 comments

[ 4.8 ms ] story [ 37.7 ms ] thread
Thank you for sharing this.
Lots of good stuff there. Caches(including i-cache and d-cache), volatile(and how it gets mis-construed), pointer-aliasing, float to int overhead, alloca. I don't think I've seen so much good performance stuff in a single place.
Does this have second part ? (I saw "1" at first page in headline). I am asking because I am in love with this . Thank you so much
Chapter 14 is twenty-four carat gold. Would love to see optimize.com as a dedicated site with Rosetta Code-style ports of optimization recipes across languages, platforms ;)

Quick link to grab all five manuals:

http://www.agner.org/optimize/optimization_manuals.zip

> Chapter 14 is twenty-four carat gold

Maybe, but the bounds-checking optimisation [14.2] just looks dangerous. If you end up with an erroneous 'int' index of -1 then the original code will error out, whereas the new code will interpret it as 2^32 - 1. This is a perfectly valid index in an array of 2^32 values. This optimisation just isn't equivalent if INT_MAX < size <= UINT_MAX.

Am I missing something?

(comment deleted)
size is a const int that holds a positive value so you won't ever have INT_MAX < size.
Yes, and the compiler knows that as well. GCC even merges the two versions because they're equivalent[0]

My point is, if size is dynamic, this is a dangerous optimisation.

[0] http://goo.gl/4Ev8as

Anyone who is interested in maximizing the output of computer hardware should read this. 100% of times I've been able to significantly speed up a piece of C++ code, I did it by using a technique from this document. Cannot recommend highly enough.