Decipher please ...

Discussion of chess software programming and technical issues.

Moderator: Ras

benstoker
Posts: 342
Joined: Tue Jan 19, 2010 2:05 am

Decipher please ...

Post by benstoker »

What does 'BSF' and 'BSR' stand for in the function and defintion below:

definition:

Code: Select all

static INLINE int BSR ( uint64 w )
{
        uint64 x;

asm ( "bsrq %1,%0\n": "=&r" ( x ) : "r" ( w ) );
        return x;
}

static INLINE int BSF ( uint64 w )
{
        uint64 x;

asm ( "bsfq %1,%0\n": "=&r" ( x ) : "r" ( w ) );
        return x;
}
function:

Code: Select all

static int WhiteKingDanger ( typePOS* POSITION, int WhiteKings )
{
        int e, RankWa, RankWb, RankWc, RankBa, RankBb, RankBc, v, tr = RANK ( WhiteKings );
        uint64 T, A = WhiteBishopitboardP & NotInFrontB[tr];
        typePAWNptr Z = PAWNptr[FILE ( WhiteKings ) ];
        T = A & Z.EDGE;
        RankWa = BSF ( T );

        if ( !T )
                RankWa = 0;

        RankWa >>= 3;

        T = A & Z.MIDDLE;

        RankWb = BSF ( T );

***
humble_programmer

Re: Decipher please ...

Post by humble_programmer »

"BSF" stands for "Bit Scan Forward" and will typically report the index of the lowest non-zero bit in a 32 or 64 bit value. "BSR" stands for "Bit Scan Reverse" and reports the highest non-zero bit in a 32 or 64 bit value. To use a simple 8-bit example, given the binary value 0010 1100, BSF would return "2" and BSR would return "5". The "zero" bit would be the right-most bit in the example above, so BSF is scanning "right to left" while BSR is scanning "left to right". Your mileage may vary...