Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Branchless code

Author: Robert Hyatt

Date: 18:40:36 11/18/02

Go up one level in this thread


On November 18, 2002 at 20:50:36, Russell Reagan wrote:

>On November 18, 2002 at 20:40:20, Pham Hong Nguyen wrote:
>
>>Don't use if - else ;)
>
>So, for example, if I was going to generate pawn moves, it would be better to
>have a lookup table of pawn directions for each side and a single function,
>rather than to have two seperate functions (GenWhitePawnMoves() and
>GenBlackPawnMoves, for example)?
>
>int directions[] = { 8, -8 };
>void GenPawnMoves() {
>    int direction = directions[side_to_move;
>    // generate moves...
>}
>
>So the above would be preferable to somehthing like:
>
>
>void GenWhitePawnMoves() {
>    int direction = 8;
>    // generate moves...
>}
>
>void GenBlackPawnMoves() {
>    int direction = -8;
>    // generate moves...
>}
>
>void GenPawnMoves() {
>    if (side_to_move == WHITE)
>        GenWhitePawnMoves();
>    else
>        GenBlackPawnMoveS();
>}
>
>Is that correct?


It is way not clear.  A memory read is so much worse than a mis-predicted
branch it isn't funny.  We are talking hundreds of clocks rather than dozens.

So it is going to depend on whether the data is in cache or not, which means
how long ago it was referenced, what has been referenced since, etc...




This page took 0 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.