3 ms·
Nice article. One thing that wasn't clear to me in your explanation is that you're sorting a list of pointers to objects. To sort that list you're comparing tw
by gridspy 13y ago
Nice article.
One thing that wasn't clear to me in your explanation is that you're sorting a list of pointers to objects. To sort that list you're comparing two of the objects themselves.
// follows pointer to access *ob_item[i]
IF_LESS_THAN(ob_item[i], pivot)
So the point of __builtin_prefetch is to deference this pointer in advance and so avoid the latency of the 12 million reads scattered all over memory. Nice.
Another useful thing to do here is to see if you can find a "streaming operator" to dismiss *ob_item[i] and ob_item[i] from cache after the comparison. They won't be needed again for a while.
Another good article on this optimisation (mentioned by OP)
http://scripts.mit.edu/~birge/blog/accelerating-code-using-gccs-prefetch-extension/ http://scripts.mit.edu/~birge/blog/accelerating-code-using-g...