Computer Chess Club Archives


Search

Terms

Messages

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

Author: Ed Schröder

Date: 11:16:40 12/05/01

Go up one level in this thread


On December 05, 2001 at 13:43:28, Uri Blass wrote:

>On December 05, 2001 at 13:36:21, Ed Schröder wrote:
>
>>On December 05, 2001 at 13:04:49, Miguel A. Ballicora wrote:
>>
>>>On December 05, 2001 at 12:42:07, Ed Schröder wrote:
>>>
>>>>On December 05, 2001 at 06:46:07, Severi Salminen wrote:
>>>>
>>>>>>>#define color(target) (((info[target])>>3)&3)
>>>>>>>
>>>>>>>
>>>>>>>my data.c file includes
>>>>>>>
>>>>>>>int info[64];
>>>>>>>int side;
>>>>>>>int direction[64][64];
>>>>>>>int kingsquare[2];
>>>>>>>int pin[64];
>>>>>>>
>>>>>>
>>>>>>Perhaps the data types could be a reason for some microscopic effects. If the
>>>>>>variable "side" is for instance of type "short", the compiler has to zero-extend
>>>>>>the variable to word-size before indexing (because of the array access).
>>>>>
>>>>>But as you can see the variables are all ints. So no type conversions needed. I
>>>>>believe there is just some stupid alignment thing happening or something and
>>>>>that's why the program slows down a bit. I'd use side instead of color(sq) and
>>>>>hopefully the speedup will show up later.
>>>>>
>>>>>Severi
>>>>
>>>>
>>>>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.
>
>It is not what I have in my C  book but maybe my C book is not correct(it
>assumes also that int is 2 bytes when I know that int is 4 bytes)
>
>It is claimed there that if you define
>int my_array[10];
>then it means that you get 10 varaibles of 2 bytes and I understand that
>my_array[10] is not defined.
>
>Uri


The book and your compiler might be in conflict. Usually "int" is seen as
32-bits whereas "short int" is 16-bits. In most compilers this is the default
setting. But you must find out yourself and test your compiler, it is crucial
if speed is an issue, which is true for a chess program as 16-bit sucks.

Also check your compilers default setting regarding the "sign". That is how
the compiler will interprete the sign bit when you define variables. Example:

char x=255;

if (x < 0) { do something }      // option-1
 else { do something else }      // option-2

Most compilers are set to interprete variable "x" as a signed value and thus
will follow option-1. However if your compiler is set to "unsigned" as default
then the instruction will take option-2.

It is a common and mean trap in C++, the smallest mistake will cause all kind
of crazy crashes or unpredictable strange results. Its most easy way to avoid
this problem, just always include the sign status when you define a new variable
or a new area.

unsigned char x;
signed int y;

Ed



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.