Author: Gerd Isenberg
Date: 05:51:21 09/02/02
Go up one level in this thread
On September 01, 2002 at 23:33:26, Robert Hyatt wrote:
>On September 01, 2002 at 20:46:55, Pham Hong Nguyen wrote:
>
>>The following article and discussion may be useful for you!
>>
>>http://www.codeguru.com/cpp_mfc/switch.html
>
>
>That is basically wrong.
>
>Compile a simple piece of code with gcc, using -O and you will see
>why.
>
>gcc creates a jump table of addresses for each case. It computes the
>entry to load and jumps to that. No compares and branches. Someone
>doesn't know how compilers do things. If you have really oddball case
>value, it might have to resort to that. But for the kinds of values
>we use in chess, no way...
In MSC there are at least one or two bound check compares before indexing the
table (even if there is no explicite default case). What about using a table of
function pointers, even with C++ member functions, specially if your case-code
already calls subroutines?
class CNode {
...
typedef BitBoard (CNode::*PTR_GETATTACK)(unsigned int sq) const;
static PTR_GETATTACK m_scPieceAtta[14]; // for each kind of piece
__forceinline BitBoard GetAttack(unsigned int sq, unsigned int piece) const {
return (this->*m_scPieceAtta[piece])(sq); }
...
};
CNode::PTR_GETATTACK CNode::m_scPieceAtta[14] =
{
AssertAttack, // no valid piece code
AssertAttack, // no valid piece code
WPawnAttacks,
BPawnAttacks,
....
};
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.