1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#include "chess.h"
#include "data.h"
/* last modified 01/16/09 */
/*
*******************************************************************************
* *
* This group of procedures provide the three basic bitboard operators, *
* MSB(x) that determines the Most Significant Bit, LSB(x) that determines *
* the Least Significant Bit, and PopCnt(x) which returns the number of one *
* bits set in the word. *
* *
* We prefer to use hardware facilities (such as intel BSF/BSR) when they *
* are available, otherwise we resort to C and table lookups to do this in *
* the most efficient way possible. *
* *
*******************************************************************************
*/
#if (!defined(INLINE32) && !defined(VC_INLINE32) && !defined(INLINE64))
# if defined (_M_IA64)
# ifdef __ICL
typedef unsigned long long __m64;
# elif _MSC_VER >= 1300
typedef union __declspec (intrin_type) __declspec(align(8)) __m64 {
unsigned __int64 m64_u64;
float m64_f32[2];
__int8 m64_i8[8];
__int16 m64_i16[4];
__int32 m64_i32[2];
__int64 m64_i64;
unsigned __int8 m64_u8[8];
unsigned __int16 m64_u16[4];
unsigned __int32 m64_u32[2];
} __m64;
# endif
__m64 __m64_popcnt(__m64);
# pragma intrinsic (__m64_popcnt)
int PopCnt(register BITBOARD a) {
# ifdef __ICL
return (int) __m64_popcnt(a);
# else
__m64 m;
m.m64_u64 = a;
m = __m64_popcnt(m);
return (int) m.m64_u64;
# endif
}
# else
# if !defined(INLINE32) && !defined(VC_INLINE32)
int PopCnt(register BITBOARD a) {
int c = 0;
while (a) {
c++;
a &= a - 1;
}
return (c);
}
# endif
# endif
# if defined (_M_AMD64) || defined (_M_IA64)
extern unsigned char _BitScanReverse64(unsigned long *, unsigned __int64);
# pragma intrinsic (_BitScanReverse64)
extern unsigned char _BitScanForward64(unsigned long *, unsigned __int64);
# pragma intrinsic (_BitScanForward64)
int MSB(BITBOARD arg1) {
unsigned long index;
if (_BitScanReverse64(&index, arg1))
return index;
else
return 64;
}
int LSB(BITBOARD arg1) {
unsigned long index;
if (_BitScanForward64(&index, arg1))
return index;
else
return 64;
}
# else
# if !defined(INLINE32) && !defined(VC_INLINE32)
int MSB(BITBOARD arg1) {
if (arg1 >> 48)
return (msb[arg1 >> 48] + 48);
if ((arg1 >> 32) & 65535)
return (msb[(arg1 >> 32) & 65535] + 32);
if ((arg1 >> 16) & 65535)
return (msb[(arg1 >> 16) & 65535] + 16);
return (msb[arg1 & 65535]);
}
int LSB(BITBOARD arg1) {
if (arg1 & 65535)
return (lsb[arg1 & 65535]);
if ((arg1 >> 16) & 65535)
return (lsb[(arg1 >> 16) & 65535] + 16);
if ((arg1 >> 32) & 65535)
return (lsb[(arg1 >> 32) & 65535] + 32);
return (lsb[arg1 >> 48] + 48);
}
# endif
# endif
#endif
|