Author: James Robertson
Date: 15:40:08 01/03/99
Go up one level in this thread
[snip] >Actually, you don't need BSF/BSR instructions here. You can >use exactly the same trick that Robert Hyatt used in Crafty >source - use the fact that A&(A-1) clears least significant >bit. In Crafty 16.3 source there is in-line assembly stuff >for VC++ as well as C function. Function that counts bits is >just 2 loops, first handles lower half of 64-bit bitboard, >and second handles upper half: > > mov ecx, low_part_of_the_bitboard > xor eax, eax > test ecx, ecx > jz end_of_loop1 >loop1: > lea edx, [ecx-1] > inc eax > and ecx, edx > jnz loop1 >end_of_loop1: > mov ecx,high_part_of_the_bitboard > test ecx, ecx > jz end_of_loop2 >loop2: > lea edx, [ecx-1] > inc eax > and ecx, edx > jnz loop2 >end_of_loop: > ret > >I will not be surpised if that function will be faster even >on x86 processors that have fast BSF/BSR. Even if it's >slightly slower, it has the benefit that it's portable - >it will work reasonable well on *any* x86 compatible, be it >AMD, Cyrix, IDT, etc. > >Eugene I have several questions about x86 processors: Is xor eax,eax faster than mov eax,0 Also, is inc eax faster than add eax,1 ? Thanks! James
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.