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