Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: cache optimization

Author: Robert Hyatt

Date: 08:22:02 06/08/01

Go up one level in this thread


On June 07, 2001 at 14:39:15, Johan Melin wrote:

>On June 07, 2001 at 05:10:26, martin fierz wrote:
>
>>hi,
>>
>>this is from an earlier post of bob hyatt:
>>
>>>That is a basic optimization strategy...  variables used close together in
>>>time should be close together in memory to take advantage of 32-byte line
>>>fills in cache.
>>
>>is this somthing which everybody is doing? is it worth the trouble to move
>>around variable declarations? if this is optimized, how much performance
>>gain can you expect compared to random variable placing?
>>are there any other strategies to optimize a program for good cache performance?
>>and how do you measure this, if ordering the variables in one function causes
>>that function to be 1% faster & the overall program 0.01% or something? just
>>so i can try it in one function for starters...
>
>Small, local variables in a function do not have cache problems.
>The problem is when you have large tables with data. Then you need to worry
>about how the data is organized.
>
>/Johan Melin

But they _do_.  If you put 8 "small local variables" together in memory,
whenever one is referenced the other 7 will be brought into cache at the same
time.  When you use them, you use a cache cycle rather than a memory cycle.
That basically means that the first variable costs you a memory cycle, the
other 7 cost you nothing whatsoever to use.

Small savings add up over millions of repetitions...


>
>>here's another observation i made: i have a P4 [i know... no need to tell me
>>that it's a bad choice :-)] desktop and a P3 laptop. i tried bobs recommendation
>>to use char and short arrays for small variables (like my
>>"lastbit" array), and on the P3 this was indeed faster - on the P4 it was
>>slower though. is this to be expected?
>>
>>cheers
>>  martin



This page took 0.01 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.