Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: LSB and POPCOUNT optimization

Author: Tim Foden

Date: 14:10:46 06/20/02

Go up one level in this thread


I have tested this routine (find bit and remove it) in Green Light, but it
appears to be slower than the current routine I am using.  I guess this must be
because the BSF and BTR instructions are slow on my Athlon XP 1.46Gz.  It may
also be because, for instance, when generating moves for white, most of the
pieces will be in the low DWORD, and most of the moves will be made to the low
DWORD, so I think that in general my routine will correctly predict the branch,
and will take the short route through the code.

I tested in the initial chess position, and a recent middlegame position posted
in CCC ([d] 4r1k1/qp1r1p2/2pb1Bp1/p6p/2PP1n1R/1P3P2/P4P2/2Q2K1R w)

Your routine:

Green Light Chess
Version 2.18i
Copyright (c) 2000, 2001, 2002 by Tim Foden; All Rights Reserved.
Logging output to file "glc218i.log"
Information: Failed to open file: glc218i.eval
-- Default evaluation values will be used.
Hash table size is 6.0MB (65536, 131072)
Opening book "carlos.book" contains 51062 nodes (file version 2)
*** Processing INI file: glc218i.ini
 Edwards directory set to: e:\temp\chess\tablebases\edwards\tbgen
*** INI file processing complete.
>perf
hash 0x3f923f9a8098633e
>20 moves: Na3 Nc3 Nf3 Nh3 a3 b3 c3 d3 e3 f3 g3 h3 a4 b4 c4 d4 e4 f4 g4 h4
Generate moves:
Iterations:        1000000  Time: 0.711
Iterations/sec:  1406469.8  Moves/sec: 28129395.2
Generate, make, unmake moves:
Iterations:        1000000  Time: 3.305
Iterations/sec:   302571.9  Moves/sec: 6051437.2
>perf
hash 0x3f923f9a8098633eh3 a3 b3 c3
>d3 e3 f3 g3 h3 a4 b4 c4 d4 e4 f4 g4 h4
Generate moves:
Iterations:        1000000  Time: 0.701
Iterations/sec:  1426533.5  Moves/sec: 28530670.5
Generate, make, unmake moves:
Iterations:        1000000  Time: 3.315
Iterations/sec:   301659.1  Moves/sec: 6033182.5
>fen 4r1k1/qp1r1p2/2pb1Bp1/p6p/2PP1n1R/1P3P2/P4P2/2Q2K1R w
hash 0xd83b11571aa43bb8
>
   abcdefgh      White to play
  +--------+
 8|░ ░ r k |8    ---- ------- -------
 7|qp r p ░|7
 6|░ pb░Bp |6
 5|p░ ░ ░ p|5
 4|░ PP░n░R|4
 3| P ░ P ░|3
 2|P ░ ░P░ |2
 1| ░Q░ K R|1
  +--------+
   abcdefgh

>perf
hash 0xd83b11571aa43bb84 Be5 Bg5 Be7 Bg7 Bd8
>Qa3 Qc3 Qe3 Ke1 Kg1 Ke2 Kg2 a3 b4 c5 d5 a4
Generate moves:
Iterations:        1000000  Time: 0.851
Iterations/sec:  1175088.1  Moves/sec: 39952996.5
Generate, make, unmake moves:
Iterations:        1000000  Time: 5.188
Iterations/sec:   192752.5  Moves/sec: 6553585.2
>perf
hash 0xd83b11571aa43bb8
>34 moves: Rxh5 Rxf4 Qxf4 Be5 Bg5 Be7 Bg7 Bd8 Bh8 Rg1 R1h2 R1h3 R4h2 R4h3 Rg4 Qa
1 Qb1 Qd1 Qe1 Qb2 Qc2 Qd2 Qa3 Qc3 Qe3 Ke1 Kg1 Ke2 Kg2 a3 b4 c5 d5 a4
Generate moves:
Iterations:        1000000  Time: 0.851
Iterations/sec:  1175088.1  Moves/sec: 39952996.5
Generate, make, unmake moves:
Iterations:        1000000  Time: 5.177
Iterations/sec:   193162.1  Moves/sec: 6567510.1
>


My current routine:

Green Light Chess
Version 2.18i
Copyright (c) 2000, 2001, 2002 by Tim Foden; All Rights Reserved.
Logging output to file "glc218i.log"
Information: Failed to open file: glc218i.eval
-- Default evaluation values will be used.
Hash table size is 6.0MB (65536, 131072)
Opening book "carlos.book" contains 51062 nodes (file version 2)
*** Processing INI file: glc218i.ini
 Edwards directory set to: e:\temp\chess\tablebases\edwards\tbgen
*** INI file processing complete.
>perf
hash 0x3f923f9a8098633e
>20 moves: Na3 Nc3 Nf3 Nh3 a3 b3 c3 d3 e3 f3 g3 h3 a4 b4 c4 d4 e4 f4 g4 h4
Generate moves:
Iterations:        1000000  Time: 0.801
Iterations/sec:  1248439.5  Moves/sec: 24968789.0
Generate, make, unmake moves:
Iterations:        1000000  Time: 3.395
Iterations/sec:   294550.8  Moves/sec: 5891016.2
>perf
hash 0x3f923f9a8098633e
>20 moves: Na3 Nc3 Nf3 Nh3 a3 b3 c3 d3 e3 f3 g3 h3 a4 b4 c4 d4 e4 f4 g4 h4
Generate moves:
Iterations:        1000000  Time: 0.801
Iterations/sec:  1248439.5  Moves/sec: 24968789.0
Generate, make, unmake moves:
Iterations:        1000000  Time: 3.405
Iterations/sec:   293685.8  Moves/sec: 5873715.1
>fen 4r1k1/qp1r1p2/2pb1Bp1/p6p/2PP1n1R/1P3P2/P4P2/2Q2K1R w
hash 0xd83b11571aa43bb8
>
   abcdefgh      White to play
  +--------+
 8|░ ░ r k |8    ---- ------- -------
 7|qp r p ░|7
 6|░ pb░Bp |6
 5|p░ ░ ░ p|5
 4|░ PP░n░R|4
 3| P ░ P ░|3
 2|P ░ ░P░ |2
 1| ░Q░ K R|1
  +--------+
   abcdefgh

>perf
hash 0xd83b11571aa43bb84 Be5 Bg5 Be7
>Bg7 Bd8 Bh8 Rg1 R1h2 R1h3 R4h2 R4h3 Rg4 Qa1 Qb1 Qd1 Qe1 Qb2 Qc2 Qd2 Qa3 Qc3 Qe3
 Ke1 Kg1 Ke2 Kg2 a3 b4 c5 d5 a4
Generate moves:
Iterations:        1000000  Time: 0.921
Iterations/sec:  1085776.3  Moves/sec: 36916395.2
Generate, make, unmake moves:
Iterations:        1000000  Time: 5.218
Iterations/sec:   191644.3  Moves/sec: 6515906.5
>perf
hash 0xd83b11571aa43bb8
>Rg1 R1h2 R1h3 R4h2 R4h3 Rg4 Qa1 Qb1 Qd1 Qe1 Qb2 Qc2 Qd2 Qa3 Qc3 Qe3 Ke1 Kg1 Ke2
 Kg2 a3 b4 c5 d5 a4
Generate moves:
Iterations:        1000000  Time: 0.921
Iterations/sec:  1085776.3  Moves/sec: 36916395.2
Generate, make, unmake moves:
Iterations:        1000000  Time: 5.217
Iterations/sec:   191681.0  Moves/sec: 6517155.5
>

Cheers, Tim.

BTW, here is the code from my current routine :)

inline Square	BitScanForwardRemove( UINT64& bitmap )
{
	__asm
	{
		mov		ebx, [bitmap]
		mov		edx, 1

		bsf		ecx, [ebx]
		mov		eax, 0
		jnz		found

		bsf		ecx, [ebx + 4]
		mov		eax, 32
		lea		ebx, [ebx + 4]
		jnz		found

		mov		eax, XX
		jmp		done

	found:
		shl		edx, cl
		add		eax, ecx
		xor		[ebx], edx

	done:
	}

	// value returned in eax
}


Cheers, Tim.



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.