]> git.sesse.net Git - x264/blob - common/amd64/amd64inc.asm
Windows 64bit asm.
[x264] / common / amd64 / amd64inc.asm
1 ;*****************************************************************************
2 ;* amd64inc.asm: h264 encoder library
3 ;*****************************************************************************
4 ;* Copyright (C) 2005 x264 project
5 ;*
6 ;* Authors: Andrew Dunstan
7 ;*
8 ;* This program is free software; you can redistribute it and/or modify
9 ;* it under the terms of the GNU General Public License as published by
10 ;* the Free Software Foundation; either version 2 of the License, or
11 ;* (at your option) any later version.
12 ;*
13 ;* This program is distributed in the hope that it will be useful,
14 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;* GNU General Public License for more details.
17 ;*
18 ;* You should have received a copy of the GNU General Public License
19 ;* along with this program; if not, write to the Free Software
20 ;* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21 ;*****************************************************************************
22
23 BITS 64
24
25 ; FIXME: All of the 64bit asm functions that take a stride as an argument
26 ; via register, assume that the high dword of that register is filled with 0.
27 ; This is true in practice (since we never do any 64bit arithmetic on strides),
28 ; but is not guaranteed by the ABI.
29
30 %macro cglobal 1
31     %ifdef PREFIX
32         global _%1
33         %define %1 _%1
34     %else
35         global %1
36     %endif
37 %ifdef WIN64
38     %define %1 pad %1
39 %endif
40 %endmacro
41
42 %macro pad 1
43     %undef %1
44     %ifdef PREFIX
45         %define %1 _%1
46     %endif
47     %ifdef WIN64
48         times 6 nop
49         align 16
50         %1
51         .startfunc
52         %assign unwindcount 0
53         %assign framereg 0
54     %else
55         align 16
56         %1
57     %endif
58 %endmacro
59
60 %ifdef WIN64
61
62 %define __PIC__
63
64 %define parm1q rcx
65 %define parm2q rdx
66 %define parm3q r8
67 %define parm4q r9
68 %define parm5q [rsp+40]
69 %define parm6q [rsp+48]
70 %define parm7q [rsp+56]
71 %define parm8q [rsp+64]
72 %define parm1d ecx
73 %define parm2d edx
74 %define parm3d r8d
75 %define parm4d r9d
76 %define parm5d dword parm5q
77 %define parm6d dword parm6q
78 %define parm7d dword parm7q
79 %define parm8d dword parm8q
80
81 %macro firstpush 1
82     db 0x48
83     push %1
84 %endmacro
85
86 %define unwindcode(count, code) .unwind %+ count EQU code
87
88 %define regcoderax 0
89 %define regcodercx 1
90 %define regcoderdx 2
91 %define regcoderbx 3
92 %define regcodersp 4
93 %define regcoderbp 5
94 %define regcodersi 6
95 %define regcoderdi 7
96 %define regcoder8 8
97 %define regcoder9 9
98 %define regcoder10 10
99 %define regcoder11 11
100 %define regcoder12 12
101 %define regcoder13 13
102 %define regcoder14 14
103 %define regcoder15 15
104 %define regcodexmm0 0
105 %define regcodexmm1 1
106 %define regcodexmm2 2
107 %define regcodexmm3 3
108 %define regcodexmm4 4
109 %define regcodexmm5 5
110 %define regcodexmm6 6
111 %define regcodexmm7 7
112 %define regcodexmm8 8
113 %define regcodexmm9 9
114 %define regcodexmm10 10
115 %define regcodexmm11 11
116 %define regcodexmm12 12
117 %define regcodexmm13 13
118 %define regcodexmm14 14
119 %define regcodexmm15 15
120
121 %macro allocstack 1
122     %if %1 < 8
123         %error Stack Allocation must be at least 8 bytes.
124     %elif %1 < 129
125         %assign unwindcount unwindcount+1
126         unwindcode(unwindcount, $-.startfunc + 0x200 + (((%1-8)/8)<<12))
127     %elif %1 < 524288
128         %assign unwindcount unwindcount+1
129         unwindcode(unwindcount, %1/8)
130         %assign unwindcount unwindcount+1
131         unwindcode(unwindcount, $-.startfunc + 0x100)
132     %else
133         %assign unwindcount unwindcount+1
134         unwindcode(unwindcount, %1>>16)
135         %assign unwindcount unwindcount+1
136         unwindcode(unwindcount, %1 & 0x0000FFFF)
137         %assign unwindcount unwindcount+1
138         unwindcode(unwindcount, $-.startfunc + 0x1100)
139     %endif
140 %endmacro
141
142 %macro pushreg 1
143     %assign unwindcount unwindcount+1
144     unwindcode(unwindcount, $-.startfunc + 0 + (regcode%1 << 12))
145 %endmacro
146
147 %macro setframe 2
148     %if ((%2 % 16) | (%2 > 240) | (%2 < 0))
149         %error Frame offset must be a multiple of 16 between 0 and 240.
150     %endif
151     %assign unwindcount unwindcount+1
152     unwindcode(unwindcount, $-.startfunc + (3 << 8 )+ (regcode%1 << 12))
153     %assign framereg regcode%1 + %2
154 %endmacro
155
156 %macro savereg 2
157     %if ((%2 % 8) | (%2 < 0))
158         %error Offset must be a positive multiple of 8.
159     %endif
160     %if (%2 < 64504)
161         %assign unwindcount unwindcount+1
162         unwindcode(unwindcount, %2/8)
163         %assign unwindcount unwindcount +1
164         unwindcode(unwindcount, $-.startfunc + (4 << 8) + (regcode%1 << 12))
165     %else
166         %assign unwindcount unwindcount+1
167         unwindcode(unwindcount, %2 >> 16)
168         %assign unwindcount unwindcount+1
169         unwindcode(unwindcount, %2 & 0x0000FFFF)
170         %assign unwindcount unwindcount+1
171         unwindcode(unwindcount, $-.startfunc + (5 << 8) + (regcode%1 << 12))
172     %endif
173 %endmacro
174
175 %macro savexmm128 2
176     %if ((%2 % 16) | (%2 < 0))
177         %error Offset must be a positive multiple of 16.
178     %endif
179     %if (%2 < 64512)
180         %assign unwindcount unwindcount+1
181         unwindcode(unwindcount, %2/16)
182         %assign unwindcount unwindcount +1
183         unwindcode(unwindcount, $-.startfunc + (8 << 8) + (regcode%1 << 12))
184     %else
185         %assign unwindcount unwindcount+1
186         unwindcode(unwindcount, %2 >> 16)
187         %assign unwindcount unwindcount+1
188         unwindcode(unwindcount, %2 & 0x0000FFFF)
189         %assign unwindcount unwindcount+1
190         unwindcode(unwindcount, $-.startfunc + (9 << 8) + (regcode%1 << 12))
191     %endif
192 %endmacro
193
194 %macro endprolog 0
195 .endprolog
196 SECTION .xdata
197 .unwindinfo
198     db 0x01
199     db .endprolog-.startfunc
200     db unwindcount
201     db framereg
202     %rep unwindcount
203         dw .unwind %+ unwindcount
204         %assign unwindcount unwindcount-1
205     %endrep
206 align 4,db 0
207 SECTION .text
208 %endmacro
209
210 %macro endfunc 0
211 .endfunc
212 SECTION .pdata
213     dd .startfunc
214     dd .endfunc
215     dd .unwindinfo
216 SECTION .text
217 %endmacro
218
219 %else ;linux
220 %define parm1q rdi
221 %define parm2q rsi
222 %define parm3q rdx
223 %define parm4q rcx
224 %define parm5q r8
225 %define parm6q r9
226 %define parm7q [rsp+8]
227 %define parm8q [rsp+16]
228 %define parm1d edi
229 %define parm2d esi
230 %define parm3d edx
231 %define parm4d ecx
232 %define parm5d r8d
233 %define parm6d r9d
234 %define parm7d dword parm7q
235 %define parm8d dword parm8q
236
237 %macro allocstack 1
238 %endmacro
239
240 %macro firstpush 1
241     push %1
242 %endmacro
243
244 %macro pushreg 1
245 %endmacro
246
247 %macro setframe 2
248 %endmacro
249
250 %macro savereg 2
251 %endmacro
252
253 %macro savexmm128 2
254 %endmacro
255
256 %define endprolog
257 %define endfunc
258
259 %endif ;linux
260
261 %ifdef __PIC__
262     %define GLOBAL wrt rip
263 %else
264     %define GLOBAL
265 %endif
266