1 ;******************************************************************************
2 ;* Core video DSP functions
3 ;* Copyright (c) 2012 Ronald S. Bultje <rsbultje@gmail.com>
5 ;* This file is part of FFmpeg.
7 ;* FFmpeg is free software; you can redistribute it and/or
8 ;* modify it under the terms of the GNU Lesser General Public
9 ;* License as published by the Free Software Foundation; either
10 ;* version 2.1 of the License, or (at your option) any later version.
12 ;* FFmpeg is distributed in the hope that it will be useful,
13 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;* Lesser General Public License for more details.
17 ;* You should have received a copy of the GNU Lesser General Public
18 ;* License along with FFmpeg; if not, write to the Free Software
19 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 ;******************************************************************************
22 %include "libavutil/x86/x86util.asm"
26 ; slow vertical extension loop function. Works with variable-width, and
27 ; does per-line reading/writing of source data
29 %macro V_COPY_ROW 2 ; type (top/body/bottom), h
31 mov wq, r7mp ; initialize w (r7mp = wmp)
33 movu m0, [srcq+wq] ; m0 = read($mmsize)
34 movu [dstq+wq], m0 ; write(m0, $mmsize)
35 add wq, mmsize ; w -= $mmsize
36 cmp wq, -mmsize ; } while (w > $mmsize);
38 movu m0, [srcq-mmsize] ; m0 = read($mmsize)
39 movu [dstq-mmsize], m0 ; write(m0, $mmsize)
40 %ifidn %1, body ; if ($type == body) {
41 add srcq, src_strideq ; src += src_stride
43 add dstq, dst_strideq ; dst += dst_stride
44 dec %2 ; } while (--$h);
50 ; | | <- top is copied from first line in body of source
52 ; | | <- body is copied verbatim (line-by-line) from source
54 ; | | <- bottom is copied from last line in body of source
57 cglobal emu_edge_vvar, 7, 8, 1, dst, dst_stride, src, src_stride, \
60 cglobal emu_edge_vvar, 1, 6, 1, dst, src, start_y, end_y, bh, w
61 %define src_strideq r3mp
62 %define dst_strideq r1mp
68 sub bhq, end_yq ; bh -= end_q
69 sub end_yq, start_yq ; end_q -= start_q
70 add srcq, r7mp ; (r7mp = wmp)
71 add dstq, r7mp ; (r7mp = wmp)
72 neg r7mp ; (r7mp = wmp)
73 test start_yq, start_yq ; if (start_q) {
75 V_COPY_ROW top, start_yq ; v_copy_row(top, start_yq)
77 V_COPY_ROW body, end_yq ; v_copy_row(body, end_yq)
78 test bhq, bhq ; if (bh) {
80 sub srcq, src_strideq ; src -= src_stride
81 V_COPY_ROW bottom, bhq ; v_copy_row(bottom, bh)
95 cglobal emu_edge_hvar, 5, 6, 1, dst, dst_stride, start_x, n_words, h, w
96 lea dstq, [dstq+n_wordsq*2]
98 lea start_xq, [start_xq+n_wordsq*2]
100 ; FIXME also write a ssse3 version using pshufb
101 movzx wd, byte [dstq+start_xq] ; w = read(1)
102 imul wd, 0x01010101 ; w *= 0x01010101
104 mov wq, n_wordsq ; initialize w
106 pshufd m0, m0, q0000 ; splat
108 punpckldq m0, m0 ; splat
111 movu [dstq+wq*2], m0 ; write($reg, $mmsize)
112 add wq, mmsize/2 ; w -= $mmsize/2
113 cmp wq, -mmsize/2 ; } while (w > $mmsize/2)
115 movu [dstq-mmsize], m0 ; write($reg, $mmsize)
116 add dstq, dst_strideq ; dst += dst_stride
117 dec hq ; } while (h--)
130 ; macro to read/write a horizontal number of pixels (%2) to/from registers
131 ; on sse, - fills xmm0-15 for consecutive sets of 16 pixels
132 ; - if (%2 & 8) fills 8 bytes into xmm$next
133 ; - if (%2 & 4) fills 4 bytes into xmm$next
134 ; - if (%2 & 3) fills 1, 2 or 4 bytes in eax
135 ; on mmx, - fills mm0-7 for consecutive sets of 8 pixels
136 ; - if (%2 & 4) fills 4 bytes into mm$next
137 ; - if (%2 & 3) fills 1, 2 or 4 bytes in eax
138 ; writing data out is in the same way
139 %macro READ_NUM_BYTES 2
140 %assign %%off 0 ; offset in source buffer
141 %assign %%mmx_idx 0 ; mmx register index
142 %assign %%xmm_idx 0 ; xmm register index
146 movu xmm %+ %%xmm_idx, [srcq+%%off]
147 %assign %%xmm_idx %%xmm_idx+1
149 movu mm %+ %%mmx_idx, [srcq+%%off]
150 %assign %%mmx_idx %%mmx_idx+1
152 %assign %%off %%off+mmsize
157 %if %2 > 16 && (%2-%%off) > 8
158 movu xmm %+ %%xmm_idx, [srcq+%2-16]
159 %assign %%xmm_idx %%xmm_idx+1
162 movq mm %+ %%mmx_idx, [srcq+%%off]
163 %assign %%mmx_idx %%mmx_idx+1
164 %assign %%off %%off+8
166 %endif ; (%2-%%off) >= 8
170 %if %2 > 8 && (%2-%%off) > 4
171 movq mm %+ %%mmx_idx, [srcq+%2-8]
174 movd mm %+ %%mmx_idx, [srcq+%%off]
175 %assign %%off %%off+4
177 %assign %%mmx_idx %%mmx_idx+1
178 %endif ; (%2-%%off) >= 4
182 movd mm %+ %%mmx_idx, [srcq+%2-4]
183 %elif (%2-%%off) == 1
184 mov valb, [srcq+%2-1]
185 %elif (%2-%%off) == 2
186 mov valw, [srcq+%2-2]
188 mov vald, [srcq+%2-3]
190 movd mm %+ %%mmx_idx, [srcq+%2-3]
192 %endif ; (%2-%%off) >= 1
193 %endmacro ; READ_NUM_BYTES
195 %macro WRITE_NUM_BYTES 2
196 %assign %%off 0 ; offset in destination buffer
197 %assign %%mmx_idx 0 ; mmx register index
198 %assign %%xmm_idx 0 ; xmm register index
202 movu [dstq+%%off], xmm %+ %%xmm_idx
203 %assign %%xmm_idx %%xmm_idx+1
205 movu [dstq+%%off], mm %+ %%mmx_idx
206 %assign %%mmx_idx %%mmx_idx+1
208 %assign %%off %%off+mmsize
213 %if %2 > 16 && (%2-%%off) > 8
214 movu [dstq+%2-16], xmm %+ %%xmm_idx
215 %assign %%xmm_idx %%xmm_idx+1
218 movq [dstq+%%off], mm %+ %%mmx_idx
219 %assign %%mmx_idx %%mmx_idx+1
220 %assign %%off %%off+8
222 %endif ; (%2-%%off) >= 8
226 %if %2 > 8 && (%2-%%off) > 4
227 movq [dstq+%2-8], mm %+ %%mmx_idx
230 movd [dstq+%%off], mm %+ %%mmx_idx
231 %assign %%off %%off+4
233 %assign %%mmx_idx %%mmx_idx+1
234 %endif ; (%2-%%off) >= 4
238 movd [dstq+%2-4], mm %+ %%mmx_idx
239 %elif (%2-%%off) == 1
240 mov [dstq+%2-1], valb
241 %elif (%2-%%off) == 2
242 mov [dstq+%2-2], valw
244 mov [dstq+%2-3], valw
246 mov [dstq+%2-1], valb
248 movd vald, mm %+ %%mmx_idx
249 mov [dstq+%2-3], valw
251 mov [dstq+%2-1], valb
253 %endif ; (%2-%%off) >= 1
254 %endmacro ; WRITE_NUM_BYTES
256 ; vertical top/bottom extend and body copy fast loops
257 ; these are function pointers to set-width line copy functions, i.e.
258 ; they read a fixed number of pixels into set registers, and write
259 ; those out into the destination buffer
260 %macro VERTICAL_EXTEND 2
265 cglobal emu_edge_vfix %+ %%n, 6, 8, 0, dst, dst_stride, src, src_stride, \
266 start_y, end_y, val, bh
267 mov bhq, r6mp ; r6mp = bhmp
269 cglobal emu_edge_vfix %+ %%n, 0, 6, 0, val, dst, src, start_y, end_y, bh
275 %define dst_strideq r1mp
276 %define src_strideq r3mp
280 cglobal emu_edge_vfix %+ %%n, 7, 7, 1, dst, dst_stride, src, src_stride, \
283 cglobal emu_edge_vfix %+ %%n, 1, 5, 1, dst, src, start_y, end_y, bh
288 %define dst_strideq r1mp
289 %define src_strideq r3mp
292 ; FIXME move this to c wrapper?
293 sub bhq, end_yq ; bh -= end_y
294 sub end_yq, start_yq ; end_y -= start_y
296 ; extend pixels above body
297 test start_yq, start_yq ; if (start_y) {
299 READ_NUM_BYTES top, %%n ; $variable_regs = read($n)
301 WRITE_NUM_BYTES top, %%n ; write($variable_regs, $n)
302 add dstq, dst_strideq ; dst += linesize
303 dec start_yq ; } while (--start_y)
308 READ_NUM_BYTES body, %%n ; $variable_regs = read($n)
309 WRITE_NUM_BYTES body, %%n ; write($variable_regs, $n)
310 add dstq, dst_strideq ; dst += dst_stride
311 add srcq, src_strideq ; src += src_stride
312 dec end_yq ; } while (--end_y)
316 test bhq, bhq ; if (block_h) {
318 sub srcq, src_strideq ; src -= linesize
319 READ_NUM_BYTES bottom, %%n ; $variable_regs = read($n)
321 WRITE_NUM_BYTES bottom, %%n ; write($variable_regs, $n)
322 add dstq, dst_strideq ; dst += linesize
323 dec bhq ; } while (--bh)
330 %endmacro ; VERTICAL_EXTEND
333 VERTICAL_EXTEND 1, 15
335 VERTICAL_EXTEND 16, 22
339 VERTICAL_EXTEND 16, 22
341 ; left/right (horizontal) fast extend functions
342 ; these are essentially identical to the vertical extend ones above,
343 ; just left/right separated because number of pixels to extend is
344 ; obviously not the same on both sides.
346 %macro READ_V_PIXEL 2
348 imul vald, 0x01010101
355 %endif ; mmsize == 16
357 %endmacro ; READ_V_PIXEL
359 %macro WRITE_V_PIXEL 2
366 %assign %%off %%off+mmsize
371 %if %1 > 16 && %1-%%off > 8
376 %assign %%off %%off+8
378 %endif ; %1-%%off >= 8
379 %endif ; mmsize == 16
382 %if %1 > 8 && %1-%%off > 4
387 %assign %%off %%off+4
389 %endif ; %1-%%off >= 4
395 %assign %%off %%off+4
402 %endif ; (%1-%%off)/2
403 %endmacro ; WRITE_V_PIXEL
408 cglobal emu_edge_hfix %+ %%n, 4, 5, 1, dst, dst_stride, start_x, bh, val
410 READ_V_PIXEL %%n, [dstq+start_xq] ; $variable_regs = read($n)
411 WRITE_V_PIXEL %%n, dstq ; write($variable_regs, $n)
412 add dstq, dst_strideq ; dst += dst_stride
413 dec bhq ; } while (--bh)
417 %endrep ; 1+(%2-%1)/2
430 cglobal prefetch, 3, 3, 0, buf, stride, h
440 PREFETCH_FN prefetcht0