Computer Chess Club Archives


Search

Terms

Messages

Subject: FirstBit() in assembler

Author: David Rasmussen

Date: 05:48:13 01/13/02


Even though I try to keep my program extremely portable and ANSI/ISO C++
compliant, except for the parts that can't be, I would like to see how much
faster my program would be with an inline assembler version of my FirstBit()
function for use in VC++ (jeez, when will 64-bit processors be common...).

My board setup is a1=0,...,h8=63. For some reason, I can't get it to work.

int FirstBit(BitBoard bitboard)
{
 __asm {
        bsr     edx, dword ptr bitboard
        mov     eax, 0
        jnz     l1
        bsr     edx, dword ptr bitboard+4
        mov     eax, 32
        jnz     l1
        mov     edx, -1
  l1:   add     eax, edx
        sub     eax, 1
       }
}

This is written from me head, as I have deleted what I previously did, so I
haven't even tried to compile this, but you get the idea. The problem was that
for some bitboards, it returned the correct value, but for some other bitboards,
bsr just returned some weird wrong number, which made the entire function return
some weird wrong number. What's the problem?

And another question: Last time I checked, Crafty had the same board layout
(a1=0, h8=63), but it's inline assembler function does something weird which I
can't understand at all. It checks the upper part of the bitboard first, even
though this is a _firstbit_ function. I'm puzzled... Maybe it's because I was so
drunk last night.

/David



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