Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Why there is no good commercial programs for OS/X ?

Author: Daniel Clausen

Date: 10:55:53 10/14/02

Go up one level in this thread


On October 14, 2002 at 03:46:55, Daniel Clausen wrote:

>I posted something about how the AltiVec could be used in a chess engine.
>Unfortunately I can't find it at the moment, since the search engine
>doesn't work. :( If you have all the CCC articles locally and a search
>tool, you should be able to find it though when using my name and
>"Altivec" and/or G4 in it.
>
>Sargon

Some kind soul did the search and came up with two posts. I quote them below.
Thanks Paul!

Sargon

=======================================================

Hi

On September 01, 1999 at 23:50:05, Tom Kerrigan wrote:

This looks like 5% technology improvement and 95% marketing hype.
I wouldn't rush out and buy a Mac just yet... (unless, of course, you plan to
run Linux on it :)
-Tom


I talked with a friend of mine about this Altivec unit and it
seems it could be really useful in chess programs.
Suppose the following problem: (at least I think I can use
that in the still-to-write eval function, especially when
using bitboards)


char value[16]; // Array filled with some values :) [*]
int  mask;      // Must be at least 16 bit :)
int  i;
int  sum;

for(i=result=0; i<16; i++)
   if(mask & (1<<i)) result += value[i];

[*] Just a note: ANSI-C doesn't specify whether a 'char' is
    unsigned or signed. This is implementation-defined. I say
    this because I had exactly this bug in my program, when I
    ran it under a different OS. :)

Or in other words: Sum all values in the value[] array for
indices where the corresponding big is set in the mask.


Altivec has instructions which enable you to calculate this
"partial sum" quite efficient. It has an instruction which can
sum up all 16 bytes (or 8 shorts, 4 ints, 4 floats) in a
vector. So you have to set all values to zero which you don't
want to sum up. You can do that when you "expand" the 16bit
mask in a 16 byte vector. (0bit -> 0x00, 1bit -> 0xff)
Then you AND this vector with the value vector. Tada.

Here's a summary what you would do:

 vector load    1 cycle
 expand         4 cycles
 and            1 cycle
 sum            1 cycle

 total          7 cycles


Of course, you can optimize the algorithm in the beginning as
well, but I doubt you can do the whole thing under 7 cycles.
(or even close to it)


Summary: I think, Altivec can be quite useful in chess
programming. I'm sure there are other possibilities to
use Altivec except for the above example. Now I would never
dare to say some crazy factors but I also wouldn't call
it a "total washout", as some other guy did.

Kind regards,
 -sargon

*****************************************************************************

Hi

On December 13, 1999 at 01:34:51, Richard A. Fowell (fowell@netcom.com) wrote:

When people compare computer program speeds across processors, the ratio
is definitely a function of the program and the compiler. In my HIARCS 7.0
benchmarks, it seems that the HIARCS 7.0 gained more relative benefit from
the Mac vs. the PII, about 46%. But it is definitely a function of the
chess software. I don't have any G4 numbers for HIARCS, but I would not
expect much difference between a G4 and a G3 for HIARCS - it wasn't
compiled for Altivec, and even if it were, the Altivec instructions
are mainly aimed at helping operations hardly ever used by chess, although
one chess programmer has told me there are some Altivec features that might
be useful to chess software.

I also think that G4's Altivec for the current chess programs wouldn't help
a lot. But one of the reasons is that current chess programs don't code in a
way that Altivec could be useful. If Altivec would be part of every CPU for
10 years, that most prolly would be different.

Some months ago I posted a code-snippet where Altivec would be of BIG
help. I can't find this posting at the moment, since I don't even know the
exact month I posted it. But the code snippet was approx the following:

#define And64(a, b)      ((a) & (b))
#define ShiftL64(a, b)   ((a) << (b))
#define TstBit64(a, b)   (!!And64((a), ShiftL64((BitBoard)1, (b))))

char     values[64];
BitBoard bitMask; // sizeof(long long) = 64
int      i, sum = 0;

for(i=0; i<64; i++)
{
   if(TstBit64(bitMask, i))
      sum += values[i];
}

So basically it calculates the sum of all entries in the values[] array,
if the corresponding bit in the bitMask is set. Altivec has a very good
support for this kind of things. Calculating piece-square-table values
is one example, where this would be very useful.

Kind regards,
 -sargon

*****************************************************************************




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.