Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: a question about speed difference that I do not understand

Author: Gareth McCaughan

Date: 12:48:05 12/06/01

Go up one level in this thread


On December 05, 2001 at 13:36:21, Ed Schröder wrote:

>>>You could try to decrease the
>>>
>>>int direction[64][64];
>>>
>>>by one, thus:
>>>
>>>int direction[63][64];
>>>
>>>The result might be the compiler doesn't have to do an expensive multiply
>>>(*65) but is able to do a simple shift-left bits instruction (SHL 6) which
>>>shift left the bytes 6 times, thus a multiply by 64.
>>
>>I do not understand. Why would a compiler want to multiply by 65 in the first
>>place? Isn't 64 in both cases as determined by the second index?
>
>char xxx[0] defines 1 byte.
>char xxx[10] defines 11 bytes.

As others have pointed out, this isn't so. A couple of other
remarks:

  - Multiplying by 65 is just a shift and an add, so it's
    not necessarily much slower than multiplying by 64.

  - In some applications (mostly with larger arrays than this)
    "alignment" can be *bad* news because of collisions in the
    cache. Don't always assume, as some people have apparently
    done in this discussion, that it's always fastest to make
    every size in your program as big a power of 2 as possible!

--
g



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.