Author: Dann Corbit
Date: 16:27:10 09/06/05
Go up one level in this thread
On September 06, 2005 at 19:18:40, Pham Hong Nguyen wrote:
>I have been studying the bitboard code of Crafty. I found the code for popcnt,
>first_one, last_one... but did not find out the code of implementing
>64-bit-shift, plus, minus instructions for 32 bit computer.
>
>Could someone show me what I am missing? Thanks.
It is in the assembly files and the C file.
Here is the AMD inline include file:
/*
AMD Opteron inline functions for FirstOne(), LastOne() and
PopCnt(). Note that these are 64 bit functions and they use
64 bit (quad-word) X86-64 instructions.
*/
int static __inline__ FirstOne(long word)
{
long dummy, dummy2;
asm(" bsrq %0, %1" "\n\t"
" jnz 1f" "\n\t"
" movq $-1, %1" "\n\t"
"1: movq $63, %0" "\n\t"
" subq %1, %0" "\n\t"
:"=r&"(dummy), "=r&" (dummy2)
:"0"((long) (word))
:"cc");
return (dummy);
}
int static __inline__ LastOne(long word)
{
long dummy, dummy2;
asm(" bsfq %0, %1" "\n\t"
" jnz 1f" "\n\t"
" movq $-1, %1" "\n\t"
"1: movq $63, %0" "\n\t"
" subq %1, %0" "\n\t"
:"=r&"(dummy), "=r&" (dummy2)
:"0"((long) (word))
:"cc");
return (dummy);
}
int static __inline__ PopCnt(long word)
{
long dummy, dummy2, dummy3;
asm(" xorq %0, %0" "\n\t"
" testq %1, %1" "\n\t"
" jz 2f" "\n\t"
"1: leaq -1(%1),%2" "\n\t"
" incq %0" "\n\t"
" andq %2, %1" "\n\t"
" jnz 1b" "\n\t"
"2: " "\n\t"
:"=r&"(dummy), "=r&"(dummy2), "=r&" (dummy3)
:"1"((long) (word))
:"cc");
return (dummy);
}
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.