Author: Russell Reagan
Date: 10:20:36 12/08/03
Go up one level in this thread
I think this is a difficult question to answer with a "best answer". Two things
you want to minimize when writing fast code are conditionals and array lookups.
Any of the three approaches you mention could be the fastest.
If the conditionals are easy for the cpu to predict, such as one that will
alternate true/false/true/false (like side to move), that might be the fastest.
I think one of the two following methods will be the fastest.
1. Single if-statements containing large portions of code, such as:
if ( sideToMove == white ) {
// Lots of code here, like a move generator for white
}
else {
// Lots of code here, like a move generator for black
}
That if-statement should be easy for the cpu to predict. You duplicate the same
code twice though, which isn't good for your instruction cache.
2. Pointer to color information structs, such as:
if ( board[ i + sideToMove->pawnForwardDirection ] == empty )
AddPawnMove(i, i + sideToMove->pawnForwardDirection);
There you save the if (sideToMove == white) { ... } else { ... } conditional.
This should be cache friendly and avoid conditionals. I would also prefer this
method because it avoids duplicating code, which is better from a design point
of view, regardless of whether it is slightly slower than another approach.
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.