Update codebase to remove clang warnings (and a couple of legit errors
[typhoon.git] / src / x64.asm
1 %ifdef _X64_
2 [BITS 64]
3
4 [SEGMENT .data]
5
6 [EXTERN _g_VectorDelta]
7 [EXTERN _g_PieceData]
8
9 %ifdef OSX
10 ;;; Note: The reason for this OSX stuff is that there is a bug in the mac
11 ;;; version of nasm.  See comments in data.c for more details.
12        
13 [GLOBAL g_NasmVectorDelta]
14 [GLOBAL _g_NasmVectorDelta]
15 g_NasmVectorDelta:
16 _g_NasmVectorDelta: 
17     alignb 32, db 0
18     times 256 * 4 db 0
19
20 [GLOBAL g_NasmPieceData]
21 [GLOBAL _g_NasmPieceData]
22 g_NasmPieceData:
23 _g_NasmPieceData:               
24     alignb 32, db 0
25     times 4 * 4 * 8 db 0
26 %else
27 [EXTERN _g_VectorDelta]
28 [EXTERN _g_PieceData]
29 %endif
30         
31 [SEGMENT .text]
32
33 %ifndef CROUTINES        
34 [GLOBAL LastBit]
35 [GLOBAL _LastBit]
36         ;; 
37         ;; ULONGLONG CDECL
38         ;; LastBit(BITBOARD bb)
39         ;; 
40 LastBit:
41 _LastBit:
42         int 3
43         bsr rax, rcx
44         jnz .found
45         xor rax, rax
46         ret
47 .found: add rax, 1
48         ret
49         int 3
50
51 [GLOBAL FirstBit]
52 [GLOBAL _FirstBit]
53         ;; 
54         ;; ULONGLONG CDECL
55         ;; FirstBit(BITBOARD bb)
56         ;; 
57 FirstBit:
58 _FirstBit:
59         ;movq rcx, [rsp+8]
60         bsf rax, rcx
61         jnz .found
62         xor rax, rax
63         ret
64 .found: add rax, 1
65         ret
66         int 3
67
68 [GLOBAL CountBits]
69 [GLOBAL _CountBits]
70         ;; 
71         ;; ULONGLONG CDECL
72         ;; CountBits(BITBOARD bb)
73         ;; 
74 CountBits:     
75 _CountBits:
76         xor rax, rax
77         mov rcx, [esp+8]
78         test rcx, rcx
79         jz .done
80 .again: add rax, 1
81         mov rdx, rcx
82         sub rdx, 1
83         and rcx, rdx
84         jnz .again
85 .done:  ret
86         int 3
87
88 [GLOBAL GetAttacks]
89 [GLOBAL _GetAttacks]
90
91         db 43h,30h,50h,56h,72h,31h,47h,34h,54h,20h,32h,30h,30h
92         db 36h,20h,53h,63h,30h,74h,74h,20h,47h,61h,73h,63h,34h
93         
94 iDelta  dd -17
95         dd +15
96
97 %define uSide    ebp+0x14
98 %define cSquare  ebp+0x10
99 %define pos      ebp+0xC
100 %define pList    ebp+8
101 ;;      retaddr  ebp+4
102 ;;      old ebp  ebp
103 ;;      old ebx  ebp-4
104 ;;      old esi  ebp-8
105 ;;      old edi  ebp-0xC
106 %define pOldList ebp-0x10
107 %define c        ebp-0x14
108 %define x        ebp-0x18
109
110 %define _cNonPawns     0x478
111 %define _uNonPawnCount 0x500
112 %define _rgSquare      0x0
113                         
114         ;; 
115         ;; void CDECL
116         ;; GetAttacks(SEE_LIST *pList,  ; ebp + 8
117         ;;            POSITION *pos,    ; ebp + 0xC
118         ;;            COOR cSquare,     ; ebp + 0x10
119         ;;            ULONG uSide)      ; ebp + 0x14
120         ;; 
121 GetAttacks:
122 _GetAttacks:
123         int 3
124 %endif ; !CROUTINES
125
126 [GLOBAL LockCompareExchange]
127 [GLOBAL _LockCompareExchange]
128 %define uComp esp+0xC
129 %define uExch esp+8
130 %define pDest esp+4
131         ;; 
132         ;; ULONG CDECL
133         ;; LockCompareExchange(void *dest, ; esp + 4
134         ;;                     ULONG exch, ; esp + 8
135         ;;                     ULONG comp) ; esp + C
136         ;; 
137 LockCompareExchange:
138 _LockCompareExchange:
139         mov ecx, [pDest]
140         mov edx, [uExch]
141         mov eax, [uComp]
142         lock cmpxchg dword [ecx], edx
143         ret
144         int 3
145
146 [GLOBAL LockIncrement]
147 [GLOBAL _LockIncrement]
148         ;;
149         ;; ULONG CDECL
150         ;; LockIncrement(ULONG *pDest)
151         ;; 
152 LockIncrement:
153 _LockIncrement:
154         mov ecx, [pDest]
155         mov eax, 1
156         lock xadd [ecx], eax
157         add eax, 1
158         ret
159         int 3
160
161 [GLOBAL LockDecrement]
162 [GLOBAL _LockDecrement]
163         ;;
164         ;; ULONG CDECL
165         ;; LockDecrement(ULONG *pDest)
166         ;; 
167 LockDecrement:
168 _LockDecrement:
169         mov ecx, [pDest]
170         mov eax, -1
171         lock xadd [ecx], eax
172         add eax, -1
173         ret
174         int 3
175
176 %endif ; X64