Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: A question about varaibles that I should give to functions in C++

Author: Uri Blass

Date: 01:39:31 08/02/04

Go up one level in this thread


On August 02, 2004 at 03:30:56, Gerd Isenberg wrote:

><snip>
>
>>I am afraid that it is going to do the program slower.
>
>Yes, you have to access such member variables via a pointer, which is passed to
>none static member functions as "this" pointer. But that's most often only
>negligible overhead. E.g. with AMD64 (fastcall) and 16 gp registers it is likely
>that a "this"-pointer to the object containing search variables in a recursive
>search routine is kept in rcx (64-bit mode) or ecx (32-bit mode has only 8 gp
>registers).
>
>Accessing a member variable in x86 assembly is done via  [ecx+offsetOfVariable]
>instead of the global access via [addressOfVariable].
>If offsetOfVariable is less than 128 bytes, it is coded as byte offset, and
>instructions are therefore up to three or even four (offset 0) bytes shorter.
>One reason to keep often used class or struct data members at the beginning of a
>struct, of course considering alignment and padding issues.

I do not understand much about speed optimizations.

I do not care about doing the program as fast as possible and I only care not to
do it slower because of classes.

This is the reason that I prefer varaibles that are not used often in classes.
varaibles that are used often also may mean more changes to the code in order
not to have them as global varaibles in case that they are used in many places
of the code.

I use hply not only in makemove but also in the code that check repetition and
sometimes in the search code when I want to look at the history to decide about
extensions so replacing this global varaible by something else does not seems to
me very simple.

You are probably right that putting hply in another class is only a negligible
overhead but the problem is not only speed and the problem that as first step I
prefer to do a smaller step than the step you suggest later in your post
and I only want to replace time varaibles by struct and do it correctly and
after I test that everything works I may consider doing it for more varaibles
and arrays.
hply is only one global varaible and I have a lot of other global varaibles and
arrays.

>
>>
>>hply is used in every node unlike time varaibles.
>>I can robably use a function get_hply that will get hply from the GameControl
>>object and not use it as global varaible but I am afraid that it is going to do
>>the program slower if I do it everytime that I need hply.
>>
>>Another point is that I do not want to do too big changes in the code and I
>>prefer to change it more slowly.
>>
>>I first want to get rid of global varaibles that are rarely used and maybe later
>>I will think about getting rid of global varaibles that are used more often like
>>hply.
>>
>>Uri
>
>A first step might be to replace several globals by global structures (class is
>synonym for struct, except struct has default access modifier public, while
>class has privat) or static class members. Keeping in mind what logically
>belongs together, considering possible later to implement multi threading
>search.
>
>Gerd

I think that first step should be to replace only some global varaibles by one
structure or one class and static class members and only if it works correctly
to continue to do it for another structure.

I may later replace a file with big class by some files with smaller classes if
it is better(I understand that you suggest to have some classes for the time
related varaibles but it seems to me a bigger change relative to one class of
time relative varaibles).

Uri



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.