Author: Georg v. Zimmermann
Date: 05:45:48 01/21/02
Hi,
this time I dont need help ;-). I am just curious why the compiler made my life
so difficult till I got it to work.
Last Friday I decided to use the neat __asm code posted here for finding a bit:
/* Function: firstSquare
* Input: None
* Output: A square
* Purpose: Used to get the lowest square that is set in a bitboard.
*/
#ifdef _win32_
#pragma warning( disable : 4035 ) // no return value warning
#endif
inline int firstSquare (qword a)
{
// bitboard must NOT be empty !
__asm {
bsf eax, dword ptr a+4
add eax, 32
bsf eax, dword ptr a
}
}
#ifdef _win32_
#pragma warning( default : 4035 )
#endif
It works well ! Then I thought: while I am it, lets __inline this code. I tried
inlining it by just adding the __inline keyword in the header file, which
failed.
Then I looked at crafty source and saw that in crafty all this _asm code is in a
header file. So I put it in a header file as well. First question: why does
MSVC need _asm in a .h file and not only the function declaration for it to get
inlined ?
After compiling without errors my program didnt respond anymore after startup.
After a couple of hours I found out that that was caused by the following
function into which firstSquare() gets inlined :
/*
* Function: removeAttacks
* Input: A color and a bitboard of squares
* Output: None.
* Purpose: Decrements the attacks array on squares that a piece attacks
*
*/
void boardStruct::removeAttacks(color c, piece p, square sq)
{
bitboard bb;
if (p == PAWN)
bb = pawnAttacksFrom(c, sq);
else
bb = attacksFrom(p, sq);
while (bb.hasBits())
{
sq = firstSquare(bb.data); // <==========
bb.unsetSquare(sq);
attacks[c][sq]--;
}
}
So my other question is why on earth doesnt the compiler warn me here ?
Georg
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.