Author: Miguel A. Ballicora
Date: 06:04:05 01/21/02
Go up one level in this thread
On January 21, 2002 at 08:45:48, Georg v. Zimmermann wrote:
>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 ?
I am no expert on this, so let me risk an answer (so, I'll learn too):
1) It is for the same reason that a macro has to be in an .h file.
The compiler has to include as inline what it "sees", rather than what is has
been compiled somewhere else in another object file.
2) Maybe the compiler did not warn you because it "inlined" what you
have declared as a definition, which is, an empty function.
Regards,
Miguel
>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.