bit.h
Go to the documentation of this file.
1 
11 #ifndef EDAX_BIT_H
12 #define EDAX_BIT_H
13 
14 #include <stdio.h>
15 
16 #ifdef DLL_BUILD
17 #define DLL_API __declspec(dllexport)
18 #else
19 #define DLL_API
20 #endif
21 
22 struct Random;
23 
24 /* declaration */
25 DLL_API int bit_count(unsigned long long);
26 int bit_weighted_count(const unsigned long long);
27 DLL_API int first_bit(unsigned long long);
28 int next_bit(unsigned long long*);
29 DLL_API int last_bit(unsigned long long);
30 void bitboard_write(const unsigned long long, FILE*);
31 unsigned long long transpose(unsigned long long);
32 unsigned long long vertical_mirror(unsigned long long);
33 unsigned long long horizontal_mirror(unsigned long long);
34 unsigned int bswap_int(unsigned int);
35 unsigned short bswap_short(unsigned short);
36 int get_rand_bit(unsigned long long, struct Random*);
37 
39 #define foreach_bit(i, b) for (i = first_bit(b); b; i = next_bit(&b))
40 
41 extern const unsigned long long X_TO_BIT[];
43 #define x_to_bit(x) X_TO_BIT[x]
44 
45 //#define x_to_bit(x) (1ULL << (x)) // 1% slower on Sandy Bridge
46 
47 #endif
48 
void bitboard_write(const unsigned long long, FILE *)
Print an unsigned long long as a board.
Definition: bit.c:435
Definition: util.h:87
unsigned short bswap_short(unsigned short)
Swap bytes of a short (little <-> big endian).
Definition: bit.c:391
unsigned long long transpose(unsigned long long)
Transpose the unsigned long long (symetry % A1-H8 diagonal).
Definition: bit.c:345
int bit_weighted_count(const unsigned long long)
count the number of discs, counting the corners twice.
Definition: bit.c:143
DLL_API int first_bit(unsigned long long)
Search the first bit set.
Definition: bit.c:173
const unsigned long long X_TO_BIT[]
Definition: bit.c:18
int get_rand_bit(unsigned long long, struct Random *)
Get a random set bit index.
Definition: bit.c:415
int next_bit(unsigned long long *)
Search the next bit set.
Definition: bit.c:248
unsigned int bswap_int(unsigned int)
Mirror the unsigned int (little <-> big endian).
Definition: bit.c:401
unsigned long long horizontal_mirror(unsigned long long)
Mirror the unsigned long long (exchange the line 1 - 8, 2 - 7, 3 - 6 & 4 - 5).
Definition: bit.c:377
unsigned long long vertical_mirror(unsigned long long)
Mirror the unsigned long long (exchange the lines A - H, B - G, C - F & D - E.).
Definition: bit.c:364
#define DLL_API
Definition: bit.h:19
DLL_API int bit_count(unsigned long long)
Count the number of bits set to one in an unsigned long long.
Definition: bit.c:72
DLL_API int last_bit(unsigned long long)
Search the last bit set (same as log2()).
Definition: bit.c:264