This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] Fix istream::ignore + minor things


Paolo Carlini wrote:

Damour, James A wrote:

Would your ignore code benefit from using __builtin_expect (see example
below)?

- if (__n != numeric_limits<streamsize>::max())
+ if (__builtin_expect(__n !=
numeric_limits<streamsize>::max(),1))


Thanks for the suggestion. The evidence about the benefits of __builtin_expect is actually rather thin, however.

FWIW, in my experiments with gcc 3.2 on IPF, the gcc optimizer didn't seem to take any noticeable advantage of the hint. The same function (hand-coded strcmp) performed exactly the same without the hint as it did with it (regardless of whether the hint was right or wrong).

Intel C++ 8.0, on the other hand, seemed to be quite sensitive
to the hint. The same function performed up to 40% better with
the correct hint than with the wrong one. In cases where the
optimizer was able to correctly assign branch probabilities
without the presence of the hint it made little difference;
where it wasn't the hint was a big help.

Incidentally, in the optimized cases the code generated by icc
ran between 25% and 50% faster than the same code generated by
gcc.

The test program and the output generated by gcc -O3 and icc
-O3 are in the attached archive. The output from running the
test cases is here:

$ (g++ t.cpp -O3; n=0; while [ $n -ne 6 ]; do echo "### $n ###"; time ./a.out 1000000 $n; n=`expr $n + 1`; done)
### 0 ###


real    0m7.301s
user    0m7.216s
sys     0m0.005s
### 1 ###

real    0m8.616s
user    0m7.218s
sys     0m0.006s
### 2 ###

real    0m7.273s
user    0m7.201s
sys     0m0.001s
### 3 ###

real    0m8.428s
user    0m8.248s
sys     0m0.001s
### 4 ###

real    0m8.330s
user    0m8.237s
sys     0m0.005s
### 5 ###

real 0m8.288s
user 0m8.226s
sys 0m0.004s
$ (icc t.cpp -O3; n=0; while [ $n -ne 6 ]; do echo "### $n ###"; time ./a.out 1000000 $n; n=`expr $n + 1`; done)
### 0 ###


real    0m3.199s
user    0m3.108s
sys     0m0.002s
### 1 ###

real    0m4.172s
user    0m4.133s
sys     0m0.002s
### 2 ###

real    0m3.144s
user    0m3.115s
sys     0m0.002s
### 3 ###

real    0m7.293s
user    0m7.215s
sys     0m0.004s
### 4 ###

real    0m8.306s
user    0m8.261s
sys     0m0.002s
### 5 ###

real    0m6.268s
user    0m6.220s
sys     0m0.002s

Martin

Attachment: br-test.tar.gz
Description: GNU Zip compressed data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]