Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: speed question

Author: Dezhi Zhao

Date: 12:59:25 02/21/03

Go up one level in this thread


On February 21, 2003 at 13:31:50, Uri Blass wrote:

>On February 21, 2003 at 13:10:27, Dezhi Zhao wrote:
>
>>On February 21, 2003 at 12:48:45, Uri Blass wrote:
>>
>>>On February 21, 2003 at 11:15:24, Dezhi Zhao wrote:
>>>
>>>>On February 21, 2003 at 04:14:49, Uri Blass wrote:
>>>>
>>>>>On February 20, 2003 at 13:51:37, Filip Tvrzsky wrote:
>>>>>
>>>>>>On February 20, 2003 at 12:49:39, Uri Blass wrote:
>>>>>>
>>>>>>>
>>>>>>>I guess that you mean
>>>>>>>#define gen_dat_i_mpromote (gen_dat[i].m & (63 << 16))
>>>>>>>
>>>>>>>I guess that the laternative that I tried
>>>>>>>
>>>>>>>#define to(x) (((x)>>8)&255) was also bad
>>>>>>>and better was
>>>>>>>#define to(x) (((x)&255<<8)
>>>>>>>
>>>>>>>I guess that in that case I need to change some more code
>>>>>>>
>>>>>>>For example
>>>>>>>
>>>>>>>I have today some cases when I have
>>>>>>>switch(m.bits)
>>>>>>>case 1:
>>>>>>>case 17:
>>>>>>>...
>>>>>>>
>>>>>>>in that case I need to say case 1<<24 and in order not to have an ugly code
>>>>>>>I need to have more constants for 2^24,2^24*17,...
>>>>>>>
>>>>>>>I can use
>>>>>>>enum
>>>>>>>{
>>>>>>> bits1=16777216
>>>>>>> bits17=
>>>>>>>...
>>>>>>>}
>>>>>>>
>>>>>>>Uri
>>>>>>
>>>>>>#define to(x) (((x)>>8)&255) is definitely worse than #define to(x)
>>>>>>(((x)&255<<8) because in the first case the shifting is done in run-time and in
>>>>>>the second during compilation. Note also that the result of both macros is
>>>>>>different.
>>>>>
>>>>>Yes
>>>>>
>>>>>This is an important note.
>>>>>
>>>>>I did not do the mistake of assuming that they are the same but I see that I
>>>>>have problems.
>>>>>
>>>>>I cannot use my usual macros after that translate
>>>>>
>>>>>for example
>>>>>
>>>>>I had if (piece(m.b.to))=PAWN) in my code
>>>>>I cannot transalate it to
>>>>>if (piece(to(m))==PAWN)  because to(m) does not get something between 0 and 63
>>>>>after the change and it seem that I cannot do it faster in this case.
>>>>>
>>>>
>>>>you probabaly need another inline function or micro here:
>>>>
>>>>#define IsPawn(move) (piece(move.b.to) == PAWN)
>>>
>>>note that piece() is not a function and it is in my defines
>>>
>>>#define piece(square) ((info[square])&7)
>>>
>>>The point is that info[64] include for every square both the color and both the
>>>piece and the piece can be accesed by the array info[64] that is an array of
>>>int.
>>>
>>
>>nested macroes are OK.
>>
>>>>
>>>>If you are using VC, inline functions are prefered. You can easily browse these
>>>>inline fuctions. And the compiler does type checking that is certainly helpful.
>>>
>>>I do not see a function that I should inline in that case because there is no
>>>function in the code that I posted(only macros).
>>>
>>
>>You missed the point that a inline function is the same in effect as a macro.
>>A inline function _is_ a much better macro.
>
>Thanks for the advice.
>I use visual C++ but
>I saved the files in my project as .c
>I guess that inline functions mean that I need to change the .c to .cpp first

yes. a simple rename

>but the problem is that after that I do not know what to do and how to write
>inline functions.
>
>I need to see some example of a simple code that use inline function to do
>it(maybe I can do it by trying to add the word inline before the name of some
>functions but I do not like to guess here).
>
>I also do not know if I need to declare inline functions before using it
>(today I declare only part of the function that I use in a special file when
>functions are declared).
>
>Uri

An inline function is treated as a function in syntax. So you need to delare it
in header file. For these simple ones, you can put the function body direct
after delcaration.

here is an example:

// in the header file head.h

// make sure you have declared info before.
inline int piece(int square) { return info[square] & 7; };

// keyword inline is not necessary if you put these functions inside a header
file
inline int IsPawn(struct YourMoveStructName move)
{
    return piece(move.b.to) == PAWN;
};




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.