Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: fastest memory layout

Author: Tony Werten

Date: 08:25:13 10/01/04

Go up one level in this thread


On October 01, 2004 at 10:07:10, Robert Hyatt wrote:

>On October 01, 2004 at 01:10:39, Tony Werten wrote:
>
>>Hi all,
>>
>>I have a simple question on wich I thought I had an answer, but I'm starting to
>>doubt. However, since the memory requirements of my program are still getting
>>bigger very fast, I'm not sure what is to blame, and switching back and forth
>>takes too much time.
>>
>>Question:
>>
>>What is faster ?
>>
>>struct
>>{
>>   move  current_move[MAXPLY],hashmove[MAXPLY],killers[MAXPLY];
>>
>>   moves movelist[3000]
>>   // etc
>>
>>} TREE
>>
>>or
>>
>>struct
>>{
>>   move  current_move,hashmove,killers;
>>   // etc
>>
>>} SEARCHDATA
>>
>>struct
>>{
>>   SEARCHDATA data[MAXPLY];
>>
>>   moves movelist[3000]
>>   //
>>
>>} TREE
>>
>>ie In the second case, all data from current ply should be close in memory and I
>>can locally use a SEARCHDATA* wich would be pointing to
>> &tree.data[currentply], and have less adresscalculation.
>>
>>I always thought the 2nd should be fastest. Is that so ?
>>
>>Tony
>
>The way to answer this is to study temporal locality for the variables.
>Variables that are used close together in terms of time should be close together
>in memory.  In the above I really don't see why they would be any different,
>since the memory layout should be the same if I am looking at it correctly.

In that case I'm not understanding it correctly i guess.

In the first case I would expect the memory to look like

current_move[0]
current_move[1]
current_move[..]
current_move[MAXPLY]
hashmove[0]
hashmove[1]
hashmove[..]
hashmove[MAXPLY]

while in the second case I would expect it to be

current_move[0]
hashmove[0]
killers[0]
current_move[1]
hashmove[1]
killers[1]
current_move[..]
hashmove[..]
killers[..]

Tony


> IE
>the current_move, hash_move and killer_move arrays are adjacent in memory in
>either, followed by the movelist.  It might be minimally faster to make a
>structure with a single hash_move, killer_move and current_move in it, and use
>that to define an array.  Then the data for each ply would be in adjacent memory
>words and get pre-fetched properly.



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.