Computer Chess Club Archives


Search

Terms

Messages

Subject: x86 programmers please read

Author: Rick Bischoff

Date: 13:46:57 07/31/03


Hi,

I am porting my engine to windows since my G4 is too slow :-) Anyway, I need a
suitable "extract bit and return position" function (preferably inline GCC
assembly with no table lookup).  I thereby donate my PowerPC assembly/C++
routine to the public domain for payment:

/* Extract first set bit from X and return position */
inline int exbit(u64& X) {

u32 high = X >> 32;
u32 low  = (u32)X;

int z;

/* Find out how many zeroes: */
if (high == 0) {

/* Step 1: Count the leading zeroes (this is a single instruction on the PPC)
    Step 2: Translate that into a bit position (i.e., 31-z)
    Step 3: Clear that bit in the word
    Step 4: return the result
*/

asm ( "cntlzw %0, %1" : "=r"(z) : "r"(low) );
z = 31 - z;
X = low ^ (1<<z);
return z;

} else {

asm ( "cntlzw %0, %1" : "=r"(z) : "r"(high) );
z = 31 - z;
X = (u64) (((u64)high ^ (1<<z)) << 32) | low;

return z|32;
}
}



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.