Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Transposition tables and the use of the operators "&" and "%"

Author: martin fierz

Date: 13:09:43 12/03/04

Go up one level in this thread


On December 03, 2004 at 15:55:25, Dieter Buerssner wrote:

>On December 03, 2004 at 13:36:15, Reinhard Scharnagl wrote:
>
>>I am convinced that a good compiler always will translate a "x % (2^n)" term
>>into "x & (2^n-1)", so it would be hard to program the difference. (Check it
>>with a disassembler).
>
>I doubt very much, that this optimization is possible in a typical chess engine
>(where the number of entries is given at run time, and even when forced to a
>power of 2, it will be hard for the compiler to figure this out). When the
>number of entries is a compile time constant, the compiler will have no problem
>to figure it out, of course.
>
>It won't make a difference in either case on typical PC hardware, where the
>memory accesses later are much slower, than the index calculation, even when
>done with modulo. Full 64 bit modulo might be a bit slower, because typically
>the compiler must use some support function for it, and cannot use the div
>instruction (because of "division by zero"). For 2^32 entries or less, using
>modulo on 32 bits of a 64 bit hashkey will work without any disadvantages, and
>will produce efficient code on x86.
>
>Regards,
>Dieter

i have always found & to be a surprisingly large amount faster than %, even when
using #defined power-of-2-constants. by surprisingly large i mean about 1%
overall for my checkers program IIRC. for such a small part of the program it
sure made a big difference! i tested this in different programs of mine (4 in a
row, checkers, chess), always with the same result - % is definitely slower than
&. perhaps my compiler's fault? i'm using MSVC.

cheers
  martin



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.