News for hackers. Stuff that matters.
Re:Intel i7 loop performance anomaly by xemdetia on Tuesday December 03, 2013 @02:17PM (#6842417)
I know this may be silly to suggest but isn't this just a processor pipelining problem? I feel like it's extremely likely that the loop with the extra call just lets the processor carry on better than a variable that it has to forcibly reload and store (to be compliant with volatile).

My assembly is a little rusty but I would just assume that the processor is blocking on memory and the waits just add up.

Re:Intel i7 loop performance anomaly by djcapelis on Tuesday December 03, 2013 @02:59PM (#6842748)
I don't think this should be the case on the type of out of order superscalar pipeline that this core has, as far as I'm aware of it. If there's a bind on waiting for memory an instruction should sit in a reservation station until its data comes in and that should take the same amount of time in either case. (In addition, with trivial accesses like this, it is highly likely a prefetcher would predict the access and have it fetched from cache in time. Though perhaps prefetch behavior works better in the longer loop?)

My intuition is that this is more likely to be behavior related to the trace cache and rayiner's comment points out several good suggestions on what might be happening here.

On the other hand, given the likely difference in how these instructions may be represented in the trace cache, there may also be interactions between the order and groups of instructions dispatched from the trace cache and that may change how things occupy different slots in reservation stations. Which may change the amount of instruction level parallelism in the loop. It doesn't seem likely, but it may be the case.

Re:Intel i7 loop performance anomaly by Tuna-Fish on Tuesday December 03, 2013 @03:54PM (#6843121)
Trace cache shouldn't be the issue because the loop is simply executing too slowly. Even with very pessimistic alignment, HSW should get well more than one instruction per clock from that loop.

The culprit is probably store-to-load forwarding. Memory ops cannot wait until the coast is clear like data ops do because the addresses are not known early enough in the pipeline, so they are dispatched well before it's even known that there will be a store-to-load hit. The system to maintain the memory model is very complex, not well understood outside Intel, and might conceivably include optimistic optimizations. In such cases, it's completely feasible that issuing another store in the pipeline might reduce the amount of work that is rolled back and needs to be redone.

Re:Intel i7 loop performance anomaly by rayiner on Tuesday December 03, 2013 @06:47PM (#6844054)
> Even with very pessimistic alignment, HSW should get well more than one instruction per clock from that loop.

Why? In Haswell, a store needs an AGU (ports 2, 3, or 7) and the store data unit (port 4). Even with perfect store-load forwarding, you can only write one value per cycle into the store buffer.

Re:Intel i7 loop performance anomaly by Tuna-Fish on Wednesday December 04, 2013 @01:01AM (#6845292)
Instruction per clock, not iteration per clock. Each iteration of the tight loop takes 6 cycles there.