Subversion Repositories Games.Chess Giants

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #if _MSC_VER >= 1200
  2. #  define FORCEINLINE __forceinline
  3. #else
  4. #  define FORCEINLINE __inline
  5. #endif
  6. FORCEINLINE int PopCnt(uint64_t a) {
  7. /* Because Crafty bitboards are typically sparsely populated, we use a
  8.    streamlined version of the boolean.c algorithm instead of the one in x86.s */
  9.   __asm {
  10.     mov ecx, dword ptr a xor eax, eax test ecx, ecx jz l1 l0:lea edx,[ecx - 1]
  11.     inc eax and ecx, edx jnz l0 l1:mov ecx, dword ptr a + 4 test ecx,
  12.         ecx jz l3 l2:lea edx,[ecx - 1]
  13. inc eax and ecx, edx jnz l2 l3:}} FORCEINLINE int MSB(uint64_t a) {
  14.   __asm {
  15. bsr edx, dword ptr a + 4 mov eax, 31 jnz l1 bsr edx, dword ptr a mov eax,
  16.         63 jnz l1 mov edx, -1 l1:sub eax,
  17.         edx}} FORCEINLINE int LSB(uint64_t a) {
  18.   __asm {
  19. bsf edx, dword ptr a mov eax, 63 jnz l1 bsf edx, dword ptr a + 4 mov eax,
  20.         31 jnz l1 mov edx, -33 l1:sub eax, edx}}
  21.