Author: Flemming Rodler
Date: 19:45:31 04/20/00
Go up one level in this thread
>
>Hopefully this helps (and works! :) :
>
>#define firstone(b) \
>({ int __value; long long int __arg = (b); \
> asm ("bsfl %1,%0\n\t" \
> "jnz 1f\n\t" \
> "bsfl 4+%1,%0\n\t"\
> "jz 2f\n\t" \
> "addl $32,%0\n\t" \
> "jmp 1f\n\t" \
> "2:\n\t" \
> "movl $64,%0\n\t" \
> "1:\n\t" \
> : "=r" (__value) \
> : "o" (__arg) ); \
> __value; })
>
>best wishes,
>Andrzej Nagorko
I have now tested the above code some more and compared it to the table lookup
method (slightly modified) found in Crafty 17.10.
The slightly modifyed version looks like:
int FirstOne(BITBOARD arg1) {
if (arg1>>48)
return (first_ones[arg1>>48]);
if ((arg1>>32))
return (first_ones[(arg1>>32)]+16);
if ((arg1>>16))
return (first_ones[(arg1>>16)]+32);
return (first_ones[arg1]+48);
}
I have removed all the &65535 from the code. They are not necessary since the
function will return if what is in front is not zero. It gives a marginal
speedup (0.03 seconds on 4M iterations). The table first_ones is a lookup table
that returns the position of the first bit in a 16 bit word.
I tested as follows:
1) 4M entries in table is filled with values where a random bit is set.
2) Each of the above functions are in turn called once for each table entry.
Here are the timings on a AMD K6-2 350Mhz:
FirstOne: 0.4200 seconds. (with the %65536: 0.4500 seconds).
firstone: 0.5700 seconds.
Personally I think that these small differences do not matter in a chess
program since most programs only seach below 200000 nodes per second and the
above timings are for 4*2^20 calls to the functions. If a program searching
200000 nodes per second calls FirstOne 2 times per node on average then only 4%
of the execution time of the search is spent in this function.
I hope you will find this info useful. At least I think it was useful for me to
perform these tests.
/Flemming
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.