Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: question about errors when I change my C code to C++

Author: Gareth McCaughan

Date: 14:58:00 02/25/03

Go up one level in this thread


On February 25, 2003 at 03:49:43, Uri Blass wrote:

> I can give you a simple example of a speed improvement that I can make
>
> I have in my program the following
> #define dsee(target,side) ((directsee[(target)]>>((side)<<4))&65535)
>
> side can get only 2 numbers LIGHT and DARK.
>
> It may be better if I change it to
>
> #define dsee(target,LIGHT)=((directsee[(target)]&65535)
> #define dsee(target,DARK)=((directsee[(target)]>>16)&65535)
>
> The last thing can be done faster by
>
> #define dsee(target,DARK)=((directsee[(target)])&65535<<16)
> but in that case I need to change other places in my program because
> dsee(target,DARK) does not mean the same thing.

Unfortunately, what you propose is not legal C. However,
you can do it in C++ using templates if every use of |dsee|
feeds it LIGHT or DARK as a literal value. But using a
macro (just as you have at present) or an inline function
should give just as good results, unless your compiler is
rather dim. (Which I don't think it is.)

So I suspect that there's no speed improvement to be had here
by special-casing the possible values of |side|. But don't trust
me: measure it.

--
g



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.