Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: "Using de Bruijn Sequences to Index a 1 in a Computer Word"

Author: Angrim

Date: 15:49:49 02/11/02

Go up one level in this thread


On February 11, 2002 at 13:03:57, Eugene Nalimov wrote:
<snip>
>(3) They did not try to remove poorly predicted branch from their implementation
>of the LOOKUP algorithm. For example, on x86 there is no branches in the
>following variant:
>
>  extern unsigned char tab[256];
>
>  unsigned Lookup8 (unsigned i)
>  {
>      unsigned b, n;
>
>      b = ((i & 0xFFFF0000) != 0);
>      n = b * 16;
>      i >>= b * 16;
>      b = ((i & 0x0000FF00) != 0);
>      n += b * 8;
>      i >>= b * 8;
>      return n + tab[i];
>  }
>
>Eugene

Cool, your posts are a nice source to learn more about program
optimization.  I had thought that code like
 b= (i!=0);
would be the same as
 if(i!=0) b=1; else b=0;
but now I know that the compiler(even gcc) is smart enough to use
"test" and "setne" instructions to avoid branches here.

Now to glance through my engine a bit and see if I can find some
places that I can use this information.

Angrim



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.