2 ms·
This is more by chance than anything, but I think my correction addresses precisely that: the point is not to hoist the increment out of the loop. The point is
by loup-vaillant 14y ago
This is more by chance than anything, but I think my correction addresses precisely that: the point is not to hoist the increment out of the loop. The point is to hoist the member access. That way, you end up with only one write to memory, instead of a write and a read. (There is another member access in the condition of the loop, but I guess the compiler can optimize it.)
I explained that here: http://news.ycombinator.com/item?id=4540107 http://news.ycombinator.com/item?id=4540107 I did not get the Load Hit Store problem, but I did sense there was a problem with the repeated read access to memory.
By the way, it looks like your problem is a bit more subtle than the textbook Load Hit Store: you don't read the location you just wrote to. I guess the write access dirties more than one word (at least a cache line, maybe more).