File: vcinline.h

package info (click to toggle)
crafty 18.12-4
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 3,324 kB
  • ctags: 3,223
  • sloc: ansic: 28,032; cpp: 4,160; asm: 728; makefile: 362; sh: 97
file content (106 lines) | stat: -rw-r--r-- 2,506 bytes parent folder | download | duplicates (2)
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
extern unsigned char  first_ones[65536];
extern unsigned char  last_ones[65536];

#if _MSC_VER >= 1200
#define FORCEINLINE __forceinline
#else
#define FORCEINLINE __inline
#endif


FORCEINLINE int PopCnt(BITBOARD 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 FirstOne(BITBOARD a) {

#if _M_IX86 <= 500 /* on plain Pentiums, use boolean.c algorithm */  
  __asm {
        movzx   edx, word ptr a+6
        xor     eax, eax
        test    edx, edx
        jnz     l1
        mov     dx, word ptr a+4
        mov     eax, 16
        test    edx, edx
        jnz     l1
        mov     dx, word ptr a+2
        mov     eax, 32
        test    edx, edx
        jnz     l1
        mov     dx, word ptr a
        mov     eax, 48
  l1:   add     al, byte ptr first_ones[edx]
  }
#else /* BSF and BSR are *fast* instructions on PPro/PII */
  __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
  }
#endif /* _M_IX86 > 500 */
}

FORCEINLINE int LastOne(BITBOARD a) {

#if _M_IX86 <= 500 /* on plain Pentiums, use boolean.c algorithm */  
  __asm {
        movzx   edx, word ptr a
        mov     eax, 48
        test    edx, edx
        jnz     l1
        mov     dx, word ptr a+2
        mov     eax, 32
        test    edx, edx
        jnz     l1
        mov     dx, word ptr a+4
        mov     eax, 16
        test    edx, edx
        jnz     l1
        mov     dx, word ptr a+6
        xor     eax, eax
        test    edx, edx
        jnz     l1
        mov     eax, 48
l1:     add     al, byte ptr last_ones[edx] 
  }
#else /* BSF and BSR are *fast* instructions on PPro/PII */
  __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
  }
#endif /* _M_IX386 > 500 */
}