Re: Branch Prediction strange results

2008-11-12 Thread bearophile
Don: > Are you running it on a Pentium 4? Pentium 4 has *horrific* branch > misprediction (minimum 24 cycles, 45 uops). No other processor is nearly > as bad, eg it's 15 cycles on Core2; it was just 4 cycles on PMMX. Sorry, I am using a Core2 @ 2GHz. The fixed C code with timings: #include "std

Re: Branch Prediction strange results

2008-11-12 Thread Don
bearophile wrote: I have found an interesting small article about optimization, so I've tried the code in C and D, and I have found strange results (the D code shows timings opposite of the article). This is the article, look at the "Branch Prediction" section: http://www.ddj.com/184405848 The

Re: Branch Prediction strange results

2008-11-12 Thread bearophile
Kagamin: > this is incorrect Thank you for spotting the silly bug, I'll fix it now. (It seems it's more easy to leave bugs in such kind of code because it does nothing useful). But note that in both programs: #define FIRST static if (1) { So the first part only is run in both D and C code, not t

Re: Branch Prediction strange results

2008-11-12 Thread Kagamin
You didn't run your code, lol.

Re: Branch Prediction strange results

2008-11-12 Thread Kagamin
if (i % 4 == 1) { if (i % 4 == 0) { counter1++; } else { counter2++; } } else { if (i % 4 == 2) { counter3++; } else {

Branch Prediction strange results

2008-11-11 Thread bearophile
I have found an interesting small article about optimization, so I've tried the code in C and D, and I have found strange results (the D code shows timings opposite of the article). This is the article, look at the "Branch Prediction" section: http://www.ddj.com/184405848 The C code: http://code