Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: question about speed in hash tables

Author: Robert Hyatt

Date: 08:51:30 10/17/02

Go up one level in this thread


On October 17, 2002 at 10:54:15, Uri Blass wrote:

>On October 17, 2002 at 10:12:26, Robert Hyatt wrote:
>
>>On October 17, 2002 at 06:20:11, Uri Blass wrote:
>>
>>>Today my repetition detection is not done based on hash tables and I plan to do
>>>it faster by hash tables.
>>>
>>>After every makemove I calculate the new hash key for the hash tables
>>>but I do not have an array of all the hash keys and I use a global varaible
>>>__int64 zob to have the hash key.
>>>
>>>
>>>
>>>I plan to add an array zobkey[max_plies_of_game] for hash keys
>>>My question is what is faster:
>>>
>>>1)Doing all the calculation on zob and after finishing them to do
>>>zobkey[hply]=zob;
>>>2)Doing all the calculations on zobkey[hply]
>>
>>I can't imagine it would matter at all, if zob is a local variable.
>
>In movei zob is a global varaible because I use it both in makemove
>and in the search for order of moves that is in another file of the project.
>
>I did not have the array zobkey[hply] and had to use zob in both files.
>
>I do not see a reason that I need to change it to a local varaible.

You need to study compilers and optimization a bit.  If you update a global
variable, then the compiler is _forced_ to write the result to that global
variable
before that procedure exits.  If you write to a local variable, the compiler can
notice
that after you write to it, you don't read it again before the procedure exits,
and it can
avoid doing that store completely.

If you do as you suggested and update a global and then copy it elsewhere, that
is
going to be two memory operations, and they are hellishly slow.  On the PC, you
don't
care about the number of _instructions_.  You worry about the number of memory
reads and writes.  That is the killer.





>
>>>
>>>I guess that I am going to choose 1 because it is more simple and I guess that
>>>the difference in speed is less than 0.1% but I am interested to know what is
>>>faster.
>>>
>>>Doing all the calculations on zobkey[hply] seems to have one less arithmetic
>>>calculation but more array calls.
>>
>>Not to a compiler.  You load x[y] into a register and you only reference the
>>register
>>after that.
>>
>
>I do not use the word register in movei because
>I assume that the compiler knows better than me to decide to put varaibles in
>the registers.
>
>Uri

That is exactly what I was talking about, letting the compiler make the
decision.
But when you update a global variable, the compiler can't do anything about
avoiding
it.




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.