News for hackers. Stuff that matters.
Re:Intel i7 loop performance anomaly by cperciva on Tuesday December 03, 2013 @03:09PM (#6842821)
In general, if adding instructions makes a loop go faster, it's some sort of alignment issue.

Not necessarily. In the early days of the P6 core, I found a simple loop which would take either 4.0 or 5.33 cycles depending on the internal CPU state -- exactly the same code, but running with an iteration count of 10^6 would take either 4000000 cycles or 5333333 cycles.

I had the good fortune to talk to a member of the team which designed the P6 core, and we concluded that this was due to a quirk of the out-of-order scheduler: In order to reduce circuit depths, the mechanism for finding and dispatching runnable uops wouldn't always dispatch the earliest available uops, and so -- depending on how the incoming uops were aligned within an internal buffer -- the P6 core would sometimes take a stream of instructions which could be executed in-order without pipeline stalls and run them out-of-order with less ILP.

In short, OOO cores are weird and horribly complicated and completely untrustworthy where performance is concerned.

Re:Intel i7 loop performance anomaly by pron on Tuesday December 03, 2013 @05:13PM (#6843566)
> In short, OOO cores are weird and horribly complicated and completely untrustworthy where performance is concerned.

Yep. There's a great talk about this by Cliff Click, called A Crash Course in Modern Hardware[1] that I would recommend to everyone. I am no hardware expert, so that talk really enlightened me.

Regarding the issue at hand, I remember Doug Lea saying[2] that some new Intel processors may recognize a loop as the OSs idle loop and power down the core. That's why he computes random numbers in busy-wait loops.

[1] http://www.infoq.com/presentations/click-crash-course-modern...

[2] http://emergingtech.chariotsolutions.com/2013/04/phillyete-s...

Re:Intel i7 loop performance anomaly by scott_s on Tuesday December 03, 2013 @04:22PM (#6843281)
Your last sentence is so important, and was basically what I was thinking the entire time reading that post, that I want to repeat it: In short, OOO cores are weird and horribly complicated and completely untrustworthy where performance is concerned.
Re:Intel i7 loop performance anomaly by dman on Tuesday December 03, 2013 @03:12PM (#6842843)
With Atom switching to OOO are there any mainstream processors left that are in order ?
Re:Intel i7 loop performance anomaly by djcapelis on Tuesday December 03, 2013 @03:35PM (#6843001)
Mainstream desktop processors? Not really. But there's tons in the embedded and mobile worlds. (All the ARM A7 cores, for instance.)

In order comes back during strange times. Sun switched back to in-order for Niagara, for instance.

Re:Intel i7 loop performance anomaly by m_mueller on Tuesday December 03, 2013 @04:26PM (#6843304)
GPUs are generally in order as far as I know - it only does OOO optimization at compile time. In general I like high performance programming much more using CUDA than on CPU - the performance is usually much more predictable and as such the time investment tends to correlate pretty well with performance improvements.
Re:Intel i7 loop performance anomaly by seanmcdirmid on Tuesday December 03, 2013 @07:22PM (#6844202)
GPUs are not only out of order but extremely synchronous in general with a restricted memory model that prevents memory stalls. Not only that, but multiple cores share the same control unit, which is why coherent branching across the cores is such a big deal (they all have to branch the same way or both branches have to be executed...).
Re:Intel i7 loop performance anomaly by seanmcdirmid on Tuesday December 03, 2013 @09:44PM (#6844659)
Edit: I meant to say "GPUs are not only in order", they are definitely not out of order.
Re:Intel i7 loop performance anomaly by m_mueller on Wednesday December 04, 2013 @02:21AM (#6845510)
Coherent branching is also important on CPU to make use of your vector units, on GPU the payoff is just much higher. Furthermore you never have to do silly things like loop unrolling for vector unit optimization since you write all kernels as if they were executed scalar. Once coherent branching is not possible anymore you're usually dealing with random access over your data - even then the higher random access memory bandwidth can get you a speedup over one CPU socket, compared to dual socket you're about even.

Bottom line is you just have to think about GPUs in a slightly different way - they do have disadvantages (limited register/cache/memory per thread since you need so many of them), but things like branching aren't that big of a deal.

Re:Intel i7 loop performance anomaly by kevinnk on Tuesday December 03, 2013 @03:31PM (#6842965)
Many ARM processors are in order. Also Itanium.
Re:Intel i7 loop performance anomaly by scott_s on Tuesday December 03, 2013 @04:10PM (#6843213)
Itanium may be in order, but if we're going for ease-of-reasoning, seek your fortunes elsewhere. The memory model gave me fits.
Re:Intel i7 loop performance anomaly by jevinskie on Tuesday December 03, 2013 @10:12PM (#6844759)
The PS3's Cell processor is in-order (both the PowerPC cores and the SPU co-processor cores) but that is getting to be a decade old.
Re:Intel i7 loop performance anomaly by hrjet on Tuesday December 03, 2013 @08:32PM (#6844461)
The processor industry is a mess (especially x86). The micro-architectures are fine tuned for benchmarks, at the expense of clean and reliable design.