Rev 108 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
33 | pmbaty | 1 | #include "chess.h" |
2 | #include "data.h" |
||
3 | /* last modified 02/16/14 */ |
||
4 | /* |
||
5 | ******************************************************************************* |
||
6 | * * |
||
7 | * This group of procedures provide the three basic bitboard operators, * |
||
8 | * MSB(x) that determines the Most Significant Bit, LSB(x) that determines * |
||
9 | * the Least Significant Bit, and PopCnt(x) which returns the number of one * |
||
10 | * bits set in the word. * |
||
11 | * * |
||
12 | * We prefer to use hardware facilities (such as intel BSF/BSR) when they * |
||
13 | * are available, otherwise we resort to C and table lookups to do this in * |
||
14 | * the most efficient way possible. * |
||
15 | * * |
||
16 | ******************************************************************************* |
||
17 | */ |
||
18 | #if !defined(INLINEASM) |
||
19 | int MSB(uint64_t arg1) { |
||
20 | if (arg1 >> 48) |
||
21 | return msb[arg1 >> 48] + 48; |
||
22 | if (arg1 >> 32 & 65535) |
||
23 | return msb[arg1 >> 32 & 65535] + 32; |
||
24 | if (arg1 >> 16 & 65535) |
||
25 | return msb[arg1 >> 16 & 65535] + 16; |
||
26 | return msb[arg1 & 65535]; |
||
27 | } |
||
28 | |||
29 | int LSB(uint64_t arg1) { |
||
30 | if (arg1 & 65535) |
||
31 | return lsb[arg1 & 65535]; |
||
32 | if (arg1 >> 16 & 65535) |
||
33 | return lsb[arg1 >> 16 & 65535] + 16; |
||
34 | if (arg1 >> 32 & 65535) |
||
35 | return lsb[arg1 >> 32 & 65535] + 32; |
||
36 | return lsb[arg1 >> 48] + 48; |
||
37 | } |
||
38 | |||
39 | int PopCnt(uint64_t arg1) { |
||
108 | pmbaty | 40 | int c; |
41 | |||
154 | pmbaty | 42 | for (c = 0; arg1; c++) |
43 | arg1 &= arg1 - 1; |
||
33 | pmbaty | 44 | return c; |
45 | } |
||
46 | #endif |