Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: How to do the following in the fastest way?

Author: Gerd Isenberg

Date: 03:23:05 06/27/01

Go up one level in this thread


instead of

 int n = 0;
 for (int i=15; i>=0; --i)
    if (dirnow & (1 << i))
       directions[n++] = i;

you may try:

 int tmp  = dirnow & 0xffff;	// only 16 bits
 for (int n = 0; tmp; n++)
 {
   int lsbb = tmp & -tmp;	// get lsb
   tmp ^= lsb;			// reset bit
   directions[n] = ((((((( (lsb & 0xff00) != 0) ) << 1)
                       + ( (lsb & 0x0f0f) != 0) ) << 1)
                       + ( (lsb & 0xcccc) != 0) ) << 1)
                       + ( (lsb & 0xaaaa) != 0) ; // bit index
 }


best regards
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.