Computer Chess Club Archives


Search

Terms

Messages

Subject: Avoiding if ( expr ) and branch misprediction ?

Author: Chan Rasjid

Date: 09:45:10 01/19/06



When using bitboards, often we have arrays that require only indices 0 / 1.
eg if we have no underpromotions, then there is either 1/2 knights per color.
Sometimes ,in such situations, codes may be re-written without using the if ()
statement. But whether such simple tricks can avoid the cost of branch
misprediction ( I only have a vague idea about this ).

X[i] where i = 0 / 1;

1) if ( a & b ){
     j = X[1];
   }else{
     j = X[0];
   }
   //etc.. codes dependent on j.

2) Now without if() :-

   j = X[(a & b)!= 0];
   //etc.. codes dependent on j.

How (if ? ) can such a simple re-coding cause an improvement. Can there
be some situations related to the above with significanr misprediction
overheads ?

Thanks
Rasjid



This page took 0.01 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.