Author: Gerd Isenberg
Date: 04:10:36 11/24/03
Go up one level in this thread
On November 24, 2003 at 06:01:30, Reinhard Scharnagl wrote: >Hello, > >I want to use the same source file (using different macros) >twice to compile a move generator for the black and white >side. How could this be done CPP _conform_? > >This attempt is for to avoid double (redundant) source code >and its change management synchronizing. > >I hope that there are some experts with matching experiences >on that. > >Regards, Reinhard. Hi Reinhard, Sorry i'm not an macro expert. 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; Cheers, Gerd
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.