Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: ASM/Optimization

Author: Mathieu Pagé

Date: 09:43:24 12/06/05

Go up one level in this thread


On December 05, 2005 at 23:24:52, Zappa wrote:

>I am getting really, really tired of coding all my evaluation twice (once for
>white and once for black).  However, one of the things that is keeping me from
>switching to a for(i < 2) loop is that I can't do a shift!
>
>For example, if I have some pattern based on (pawns << 8) for white, than that
>is (pawns >> 8) for black, and you can't do a negative shift in IA32.

Hi,

I never tested the idea i'm about to propose, I just thought of it while reading
your post, but it seem to make sense for me. This require that you code in C++,
I don't know if it's the case.

In every cases i'd like to have somes opinions from you guys.

here is a sample function :

template <int color>
void eval()
{
  // do some stuff

  if (color == white)
  {
    result = pawns >> 8;
  }
  else
  {
    result = pawns << 8;
  }

  // do some stuff with result

  return;
}

Then you can cal your evaluation function like this

if (colorToMove == white)
{
  x = eval<WHITE>();
}
else
{
  x = eval<BLACK>();
}

This way you can write only one evaluation function with IFs where the code is
different for the whites and blacks, but since the color is passed as a template
parameter, the conditional jump are resolved at the link time (resulting in two
function being compiled) causing no overhead.

What do you think of this idea ?

Mathieu



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.