Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: CPP related question on double code (B/W)

Author: Reinhard Scharnagl

Date: 05:53:58 11/24/03

Go up one level in this thread


Hi Gerd,

>I keep all code common and use short (inlined) functions with formal color
>parameter for that purpose. When those functions are called and "expanded" with
>constant actual color parameter, the compiler should be able to optimize
>different constant inline incarnations of those functions in such a way that
>variable expressions got constant and conditional code becomes unconditional.
>
>E.g. if such functions is called with constant color parameter
>
>inline int getNextPawnTarget(int color /*0,1*/, int fromSquare)
>{
>      return fromSquare + 8 - color*16;
>}
>
>the generated code is either
>    fromSquare + 8;
>or  fromSquare - 8;
>
>inline BitBoard getPawnTargets(int color /*0,1*/, BitBoard from)
>{
>      if ( color == WHITE )
>         return from << 8;
>      else
>         return from >> 8;
>}
>
>Here constant color incarnation of the inlined skips the condition, code
>generation produces either at compile time
>
>    return from << 8;
>or
>    return from >> 8;

nice idea!

But it seems I have not made clear enough what my problem is. I have
explained in another answer above, that I try to _avoid_ _compiling_
the same *.C or *.CPP source code _twice_.

Thank you for answering.

Regards, Reinhard.



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.