FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dsputil_mmx.c
Go to the documentation of this file.
1 /*
2  * MMX optimized DSP utils
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg 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 GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
23  */
24 
25 #include "config.h"
26 #include "libavutil/avassert.h"
27 #include "libavutil/cpu.h"
28 #include "libavutil/x86/asm.h"
29 #include "libavcodec/videodsp.h"
30 #include "constants.h"
31 #include "dsputil_x86.h"
32 #include "diracdsp_mmx.h"
33 
34 #if HAVE_INLINE_ASM
35 
36 void ff_put_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels,
37  int line_size)
38 {
39  const int16_t *p;
40  uint8_t *pix;
41 
42  /* read the pixels */
43  p = block;
44  pix = pixels;
45  /* unrolled loop */
46  __asm__ volatile (
47  "movq (%3), %%mm0 \n\t"
48  "movq 8(%3), %%mm1 \n\t"
49  "movq 16(%3), %%mm2 \n\t"
50  "movq 24(%3), %%mm3 \n\t"
51  "movq 32(%3), %%mm4 \n\t"
52  "movq 40(%3), %%mm5 \n\t"
53  "movq 48(%3), %%mm6 \n\t"
54  "movq 56(%3), %%mm7 \n\t"
55  "packuswb %%mm1, %%mm0 \n\t"
56  "packuswb %%mm3, %%mm2 \n\t"
57  "packuswb %%mm5, %%mm4 \n\t"
58  "packuswb %%mm7, %%mm6 \n\t"
59  "movq %%mm0, (%0) \n\t"
60  "movq %%mm2, (%0, %1) \n\t"
61  "movq %%mm4, (%0, %1, 2) \n\t"
62  "movq %%mm6, (%0, %2) \n\t"
63  :: "r"(pix), "r"((x86_reg)line_size), "r"((x86_reg)line_size * 3),
64  "r"(p)
65  : "memory");
66  pix += line_size * 4;
67  p += 32;
68 
69  // if here would be an exact copy of the code above
70  // compiler would generate some very strange code
71  // thus using "r"
72  __asm__ volatile (
73  "movq (%3), %%mm0 \n\t"
74  "movq 8(%3), %%mm1 \n\t"
75  "movq 16(%3), %%mm2 \n\t"
76  "movq 24(%3), %%mm3 \n\t"
77  "movq 32(%3), %%mm4 \n\t"
78  "movq 40(%3), %%mm5 \n\t"
79  "movq 48(%3), %%mm6 \n\t"
80  "movq 56(%3), %%mm7 \n\t"
81  "packuswb %%mm1, %%mm0 \n\t"
82  "packuswb %%mm3, %%mm2 \n\t"
83  "packuswb %%mm5, %%mm4 \n\t"
84  "packuswb %%mm7, %%mm6 \n\t"
85  "movq %%mm0, (%0) \n\t"
86  "movq %%mm2, (%0, %1) \n\t"
87  "movq %%mm4, (%0, %1, 2) \n\t"
88  "movq %%mm6, (%0, %2) \n\t"
89  :: "r"(pix), "r"((x86_reg)line_size), "r"((x86_reg)line_size * 3), "r"(p)
90  : "memory");
91 }
92 
93 #define put_signed_pixels_clamped_mmx_half(off) \
94  "movq "#off"(%2), %%mm1 \n\t" \
95  "movq 16 + "#off"(%2), %%mm2 \n\t" \
96  "movq 32 + "#off"(%2), %%mm3 \n\t" \
97  "movq 48 + "#off"(%2), %%mm4 \n\t" \
98  "packsswb 8 + "#off"(%2), %%mm1 \n\t" \
99  "packsswb 24 + "#off"(%2), %%mm2 \n\t" \
100  "packsswb 40 + "#off"(%2), %%mm3 \n\t" \
101  "packsswb 56 + "#off"(%2), %%mm4 \n\t" \
102  "paddb %%mm0, %%mm1 \n\t" \
103  "paddb %%mm0, %%mm2 \n\t" \
104  "paddb %%mm0, %%mm3 \n\t" \
105  "paddb %%mm0, %%mm4 \n\t" \
106  "movq %%mm1, (%0) \n\t" \
107  "movq %%mm2, (%0, %3) \n\t" \
108  "movq %%mm3, (%0, %3, 2) \n\t" \
109  "movq %%mm4, (%0, %1) \n\t"
110 
111 void ff_put_signed_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels,
112  int line_size)
113 {
114  x86_reg line_skip = line_size;
115  x86_reg line_skip3;
116 
117  __asm__ volatile (
118  "movq "MANGLE(ff_pb_80)", %%mm0 \n\t"
119  "lea (%3, %3, 2), %1 \n\t"
120  put_signed_pixels_clamped_mmx_half(0)
121  "lea (%0, %3, 4), %0 \n\t"
122  put_signed_pixels_clamped_mmx_half(64)
123  : "+&r"(pixels), "=&r"(line_skip3)
124  : "r"(block), "r"(line_skip)
125  : "memory");
126 }
127 
128 void ff_add_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels,
129  int line_size)
130 {
131  const int16_t *p;
132  uint8_t *pix;
133  int i;
134 
135  /* read the pixels */
136  p = block;
137  pix = pixels;
138  MOVQ_ZERO(mm7);
139  i = 4;
140  do {
141  __asm__ volatile (
142  "movq (%2), %%mm0 \n\t"
143  "movq 8(%2), %%mm1 \n\t"
144  "movq 16(%2), %%mm2 \n\t"
145  "movq 24(%2), %%mm3 \n\t"
146  "movq %0, %%mm4 \n\t"
147  "movq %1, %%mm6 \n\t"
148  "movq %%mm4, %%mm5 \n\t"
149  "punpcklbw %%mm7, %%mm4 \n\t"
150  "punpckhbw %%mm7, %%mm5 \n\t"
151  "paddsw %%mm4, %%mm0 \n\t"
152  "paddsw %%mm5, %%mm1 \n\t"
153  "movq %%mm6, %%mm5 \n\t"
154  "punpcklbw %%mm7, %%mm6 \n\t"
155  "punpckhbw %%mm7, %%mm5 \n\t"
156  "paddsw %%mm6, %%mm2 \n\t"
157  "paddsw %%mm5, %%mm3 \n\t"
158  "packuswb %%mm1, %%mm0 \n\t"
159  "packuswb %%mm3, %%mm2 \n\t"
160  "movq %%mm0, %0 \n\t"
161  "movq %%mm2, %1 \n\t"
162  : "+m"(*pix), "+m"(*(pix + line_size))
163  : "r"(p)
164  : "memory");
165  pix += line_size * 2;
166  p += 16;
167  } while (--i);
168 }
169 
170 #define CLEAR_BLOCKS(name, n) \
171 void name(int16_t *blocks) \
172 { \
173  __asm__ volatile ( \
174  "pxor %%mm7, %%mm7 \n\t" \
175  "mov %1, %%"REG_a" \n\t" \
176  "1: \n\t" \
177  "movq %%mm7, (%0, %%"REG_a") \n\t" \
178  "movq %%mm7, 8(%0, %%"REG_a") \n\t" \
179  "movq %%mm7, 16(%0, %%"REG_a") \n\t" \
180  "movq %%mm7, 24(%0, %%"REG_a") \n\t" \
181  "add $32, %%"REG_a" \n\t" \
182  "js 1b \n\t" \
183  :: "r"(((uint8_t *)blocks) + 128 * n), \
184  "i"(-128 * n) \
185  : "%"REG_a \
186  ); \
187 }
188 CLEAR_BLOCKS(ff_clear_blocks_mmx, 6)
189 CLEAR_BLOCKS(ff_clear_block_mmx, 1)
190 
191 void ff_clear_block_sse(int16_t *block)
192 {
193  __asm__ volatile (
194  "xorps %%xmm0, %%xmm0 \n"
195  "movaps %%xmm0, (%0) \n"
196  "movaps %%xmm0, 16(%0) \n"
197  "movaps %%xmm0, 32(%0) \n"
198  "movaps %%xmm0, 48(%0) \n"
199  "movaps %%xmm0, 64(%0) \n"
200  "movaps %%xmm0, 80(%0) \n"
201  "movaps %%xmm0, 96(%0) \n"
202  "movaps %%xmm0, 112(%0) \n"
203  :: "r"(block)
204  : "memory"
205  );
206 }
207 
208 void ff_clear_blocks_sse(int16_t *blocks)
209 {
210  __asm__ volatile (
211  "xorps %%xmm0, %%xmm0 \n"
212  "mov %1, %%"REG_a" \n"
213  "1: \n"
214  "movaps %%xmm0, (%0, %%"REG_a") \n"
215  "movaps %%xmm0, 16(%0, %%"REG_a") \n"
216  "movaps %%xmm0, 32(%0, %%"REG_a") \n"
217  "movaps %%xmm0, 48(%0, %%"REG_a") \n"
218  "movaps %%xmm0, 64(%0, %%"REG_a") \n"
219  "movaps %%xmm0, 80(%0, %%"REG_a") \n"
220  "movaps %%xmm0, 96(%0, %%"REG_a") \n"
221  "movaps %%xmm0, 112(%0, %%"REG_a") \n"
222  "add $128, %%"REG_a" \n"
223  "js 1b \n"
224  :: "r"(((uint8_t *)blocks) + 128 * 6),
225  "i"(-128 * 6)
226  : "%"REG_a
227  );
228 }
229 
230 void ff_add_bytes_mmx(uint8_t *dst, uint8_t *src, int w)
231 {
232  x86_reg i = 0;
233  __asm__ volatile (
234  "jmp 2f \n\t"
235  "1: \n\t"
236  "movq (%1, %0), %%mm0 \n\t"
237  "movq (%2, %0), %%mm1 \n\t"
238  "paddb %%mm0, %%mm1 \n\t"
239  "movq %%mm1, (%2, %0) \n\t"
240  "movq 8(%1, %0), %%mm0 \n\t"
241  "movq 8(%2, %0), %%mm1 \n\t"
242  "paddb %%mm0, %%mm1 \n\t"
243  "movq %%mm1, 8(%2, %0) \n\t"
244  "add $16, %0 \n\t"
245  "2: \n\t"
246  "cmp %3, %0 \n\t"
247  "js 1b \n\t"
248  : "+r"(i)
249  : "r"(src), "r"(dst), "r"((x86_reg)w - 15)
250  );
251  for ( ; i < w; i++)
252  dst[i + 0] += src[i + 0];
253 }
254 
255 #if HAVE_7REGS
257  const uint8_t *diff, int w,
258  int *left, int *left_top)
259 {
260  x86_reg w2 = -w;
261  x86_reg x;
262  int l = *left & 0xff;
263  int tl = *left_top & 0xff;
264  int t;
265  __asm__ volatile (
266  "mov %7, %3 \n"
267  "1: \n"
268  "movzbl (%3, %4), %2 \n"
269  "mov %2, %k3 \n"
270  "sub %b1, %b3 \n"
271  "add %b0, %b3 \n"
272  "mov %2, %1 \n"
273  "cmp %0, %2 \n"
274  "cmovg %0, %2 \n"
275  "cmovg %1, %0 \n"
276  "cmp %k3, %0 \n"
277  "cmovg %k3, %0 \n"
278  "mov %7, %3 \n"
279  "cmp %2, %0 \n"
280  "cmovl %2, %0 \n"
281  "add (%6, %4), %b0 \n"
282  "mov %b0, (%5, %4) \n"
283  "inc %4 \n"
284  "jl 1b \n"
285  : "+&q"(l), "+&q"(tl), "=&r"(t), "=&q"(x), "+&r"(w2)
286  : "r"(dst + w), "r"(diff + w), "rm"(top + w)
287  );
288  *left = l;
289  *left_top = tl;
290 }
291 #endif
292 
293 /* Draw the edges of width 'w' of an image of size width, height
294  * this MMX version can only handle w == 8 || w == 16. */
295 void ff_draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
296  int w, int h, int sides)
297 {
298  uint8_t *ptr, *last_line;
299  int i;
300 
301  last_line = buf + (height - 1) * wrap;
302  /* left and right */
303  ptr = buf;
304  if (w == 8) {
305  __asm__ volatile (
306  "1: \n\t"
307  "movd (%0), %%mm0 \n\t"
308  "punpcklbw %%mm0, %%mm0 \n\t"
309  "punpcklwd %%mm0, %%mm0 \n\t"
310  "punpckldq %%mm0, %%mm0 \n\t"
311  "movq %%mm0, -8(%0) \n\t"
312  "movq -8(%0, %2), %%mm1 \n\t"
313  "punpckhbw %%mm1, %%mm1 \n\t"
314  "punpckhwd %%mm1, %%mm1 \n\t"
315  "punpckhdq %%mm1, %%mm1 \n\t"
316  "movq %%mm1, (%0, %2) \n\t"
317  "add %1, %0 \n\t"
318  "cmp %3, %0 \n\t"
319  "jb 1b \n\t"
320  : "+r"(ptr)
321  : "r"((x86_reg)wrap), "r"((x86_reg)width), "r"(ptr + wrap * height)
322  );
323  } else if(w==16){
324  __asm__ volatile (
325  "1: \n\t"
326  "movd (%0), %%mm0 \n\t"
327  "punpcklbw %%mm0, %%mm0 \n\t"
328  "punpcklwd %%mm0, %%mm0 \n\t"
329  "punpckldq %%mm0, %%mm0 \n\t"
330  "movq %%mm0, -8(%0) \n\t"
331  "movq %%mm0, -16(%0) \n\t"
332  "movq -8(%0, %2), %%mm1 \n\t"
333  "punpckhbw %%mm1, %%mm1 \n\t"
334  "punpckhwd %%mm1, %%mm1 \n\t"
335  "punpckhdq %%mm1, %%mm1 \n\t"
336  "movq %%mm1, (%0, %2) \n\t"
337  "movq %%mm1, 8(%0, %2) \n\t"
338  "add %1, %0 \n\t"
339  "cmp %3, %0 \n\t"
340  "jb 1b \n\t"
341  : "+r"(ptr)
342  : "r"((x86_reg)wrap), "r"((x86_reg)width), "r"(ptr + wrap * height)
343  );
344  } else {
345  av_assert1(w == 4);
346  __asm__ volatile (
347  "1: \n\t"
348  "movd (%0), %%mm0 \n\t"
349  "punpcklbw %%mm0, %%mm0 \n\t"
350  "punpcklwd %%mm0, %%mm0 \n\t"
351  "movd %%mm0, -4(%0) \n\t"
352  "movd -4(%0, %2), %%mm1 \n\t"
353  "punpcklbw %%mm1, %%mm1 \n\t"
354  "punpckhwd %%mm1, %%mm1 \n\t"
355  "punpckhdq %%mm1, %%mm1 \n\t"
356  "movd %%mm1, (%0, %2) \n\t"
357  "add %1, %0 \n\t"
358  "cmp %3, %0 \n\t"
359  "jb 1b \n\t"
360  : "+r"(ptr)
361  : "r"((x86_reg)wrap), "r"((x86_reg)width), "r"(ptr + wrap * height)
362  );
363  }
364 
365  /* top and bottom (and hopefully also the corners) */
366  if (sides & EDGE_TOP) {
367  for (i = 0; i < h; i += 4) {
368  ptr = buf - (i + 1) * wrap - w;
369  __asm__ volatile (
370  "1: \n\t"
371  "movq (%1, %0), %%mm0 \n\t"
372  "movq %%mm0, (%0) \n\t"
373  "movq %%mm0, (%0, %2) \n\t"
374  "movq %%mm0, (%0, %2, 2) \n\t"
375  "movq %%mm0, (%0, %3) \n\t"
376  "add $8, %0 \n\t"
377  "cmp %4, %0 \n\t"
378  "jb 1b \n\t"
379  : "+r"(ptr)
380  : "r"((x86_reg)buf - (x86_reg)ptr - w), "r"((x86_reg) -wrap),
381  "r"((x86_reg) -wrap * 3), "r"(ptr + width + 2 * w)
382  );
383  }
384  }
385 
386  if (sides & EDGE_BOTTOM) {
387  for (i = 0; i < h; i += 4) {
388  ptr = last_line + (i + 1) * wrap - w;
389  __asm__ volatile (
390  "1: \n\t"
391  "movq (%1, %0), %%mm0 \n\t"
392  "movq %%mm0, (%0) \n\t"
393  "movq %%mm0, (%0, %2) \n\t"
394  "movq %%mm0, (%0, %2, 2) \n\t"
395  "movq %%mm0, (%0, %3) \n\t"
396  "add $8, %0 \n\t"
397  "cmp %4, %0 \n\t"
398  "jb 1b \n\t"
399  : "+r"(ptr)
400  : "r"((x86_reg)last_line - (x86_reg)ptr - w),
401  "r"((x86_reg)wrap), "r"((x86_reg)wrap * 3),
402  "r"(ptr + width + 2 * w)
403  );
404  }
405  }
406 }
407 
408 typedef void emulated_edge_mc_func(uint8_t *dst, const uint8_t *src,
409  ptrdiff_t linesize, int block_w, int block_h,
410  int src_x, int src_y, int w, int h);
411 
412 static av_always_inline void gmc(uint8_t *dst, uint8_t *src,
413  int stride, int h, int ox, int oy,
414  int dxx, int dxy, int dyx, int dyy,
415  int shift, int r, int width, int height,
416  emulated_edge_mc_func *emu_edge_fn)
417 {
418  const int w = 8;
419  const int ix = ox >> (16 + shift);
420  const int iy = oy >> (16 + shift);
421  const int oxs = ox >> 4;
422  const int oys = oy >> 4;
423  const int dxxs = dxx >> 4;
424  const int dxys = dxy >> 4;
425  const int dyxs = dyx >> 4;
426  const int dyys = dyy >> 4;
427  const uint16_t r4[4] = { r, r, r, r };
428  const uint16_t dxy4[4] = { dxys, dxys, dxys, dxys };
429  const uint16_t dyy4[4] = { dyys, dyys, dyys, dyys };
430  const uint64_t shift2 = 2 * shift;
431 #define MAX_STRIDE 4096U
432 #define MAX_H 8U
433  uint8_t edge_buf[(MAX_H + 1) * MAX_STRIDE];
434  int x, y;
435 
436  const int dxw = (dxx - (1 << (16 + shift))) * (w - 1);
437  const int dyh = (dyy - (1 << (16 + shift))) * (h - 1);
438  const int dxh = dxy * (h - 1);
439  const int dyw = dyx * (w - 1);
440  int need_emu = (unsigned)ix >= width - w ||
441  (unsigned)iy >= height - h;
442 
443  if ( // non-constant fullpel offset (3% of blocks)
444  ((ox ^ (ox + dxw)) | (ox ^ (ox + dxh)) | (ox ^ (ox + dxw + dxh)) |
445  (oy ^ (oy + dyw)) | (oy ^ (oy + dyh)) | (oy ^ (oy + dyw + dyh))) >> (16 + shift)
446  // uses more than 16 bits of subpel mv (only at huge resolution)
447  || (dxx | dxy | dyx | dyy) & 15
448  || (need_emu && (h > MAX_H || stride > MAX_STRIDE))) {
449  // FIXME could still use mmx for some of the rows
450  ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy,
451  shift, r, width, height);
452  return;
453  }
454 
455  src += ix + iy * stride;
456  if (need_emu) {
457  emu_edge_fn(edge_buf, src, stride, w + 1, h + 1, ix, iy, width, height);
458  src = edge_buf;
459  }
460 
461  __asm__ volatile (
462  "movd %0, %%mm6 \n\t"
463  "pxor %%mm7, %%mm7 \n\t"
464  "punpcklwd %%mm6, %%mm6 \n\t"
465  "punpcklwd %%mm6, %%mm6 \n\t"
466  :: "r"(1<<shift)
467  );
468 
469  for (x = 0; x < w; x += 4) {
470  uint16_t dx4[4] = { oxs - dxys + dxxs * (x + 0),
471  oxs - dxys + dxxs * (x + 1),
472  oxs - dxys + dxxs * (x + 2),
473  oxs - dxys + dxxs * (x + 3) };
474  uint16_t dy4[4] = { oys - dyys + dyxs * (x + 0),
475  oys - dyys + dyxs * (x + 1),
476  oys - dyys + dyxs * (x + 2),
477  oys - dyys + dyxs * (x + 3) };
478 
479  for (y = 0; y < h; y++) {
480  __asm__ volatile (
481  "movq %0, %%mm4 \n\t"
482  "movq %1, %%mm5 \n\t"
483  "paddw %2, %%mm4 \n\t"
484  "paddw %3, %%mm5 \n\t"
485  "movq %%mm4, %0 \n\t"
486  "movq %%mm5, %1 \n\t"
487  "psrlw $12, %%mm4 \n\t"
488  "psrlw $12, %%mm5 \n\t"
489  : "+m"(*dx4), "+m"(*dy4)
490  : "m"(*dxy4), "m"(*dyy4)
491  );
492 
493  __asm__ volatile (
494  "movq %%mm6, %%mm2 \n\t"
495  "movq %%mm6, %%mm1 \n\t"
496  "psubw %%mm4, %%mm2 \n\t"
497  "psubw %%mm5, %%mm1 \n\t"
498  "movq %%mm2, %%mm0 \n\t"
499  "movq %%mm4, %%mm3 \n\t"
500  "pmullw %%mm1, %%mm0 \n\t" // (s - dx) * (s - dy)
501  "pmullw %%mm5, %%mm3 \n\t" // dx * dy
502  "pmullw %%mm5, %%mm2 \n\t" // (s - dx) * dy
503  "pmullw %%mm4, %%mm1 \n\t" // dx * (s - dy)
504 
505  "movd %4, %%mm5 \n\t"
506  "movd %3, %%mm4 \n\t"
507  "punpcklbw %%mm7, %%mm5 \n\t"
508  "punpcklbw %%mm7, %%mm4 \n\t"
509  "pmullw %%mm5, %%mm3 \n\t" // src[1, 1] * dx * dy
510  "pmullw %%mm4, %%mm2 \n\t" // src[0, 1] * (s - dx) * dy
511 
512  "movd %2, %%mm5 \n\t"
513  "movd %1, %%mm4 \n\t"
514  "punpcklbw %%mm7, %%mm5 \n\t"
515  "punpcklbw %%mm7, %%mm4 \n\t"
516  "pmullw %%mm5, %%mm1 \n\t" // src[1, 0] * dx * (s - dy)
517  "pmullw %%mm4, %%mm0 \n\t" // src[0, 0] * (s - dx) * (s - dy)
518  "paddw %5, %%mm1 \n\t"
519  "paddw %%mm3, %%mm2 \n\t"
520  "paddw %%mm1, %%mm0 \n\t"
521  "paddw %%mm2, %%mm0 \n\t"
522 
523  "psrlw %6, %%mm0 \n\t"
524  "packuswb %%mm0, %%mm0 \n\t"
525  "movd %%mm0, %0 \n\t"
526 
527  : "=m"(dst[x + y * stride])
528  : "m"(src[0]), "m"(src[1]),
529  "m"(src[stride]), "m"(src[stride + 1]),
530  "m"(*r4), "m"(shift2)
531  );
532  src += stride;
533  }
534  src += 4 - h * stride;
535  }
536 }
537 
538 #if CONFIG_VIDEODSP
539 #if HAVE_YASM
540 #if ARCH_X86_32
541 void ff_gmc_mmx(uint8_t *dst, uint8_t *src,
542  int stride, int h, int ox, int oy,
543  int dxx, int dxy, int dyx, int dyy,
544  int shift, int r, int width, int height)
545 {
546  gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
547  width, height, &ff_emulated_edge_mc_8);
548 }
549 #endif
550 void ff_gmc_sse(uint8_t *dst, uint8_t *src,
551  int stride, int h, int ox, int oy,
552  int dxx, int dxy, int dyx, int dyy,
553  int shift, int r, int width, int height)
554 {
555  gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
556  width, height, &ff_emulated_edge_mc_8);
557 }
558 #else
559 void ff_gmc_mmx(uint8_t *dst, uint8_t *src,
560  int stride, int h, int ox, int oy,
561  int dxx, int dxy, int dyx, int dyy,
562  int shift, int r, int width, int height)
563 {
564  gmc(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy, shift, r,
565  width, height, &ff_emulated_edge_mc_8);
566 }
567 #endif
568 #endif
569 
570 #if CONFIG_DIRAC_DECODER
571 #define DIRAC_PIXOP(OPNAME2, OPNAME, EXT)\
572 void ff_ ## OPNAME2 ## _dirac_pixels8_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
573 {\
574  if (h&3)\
575  ff_ ## OPNAME2 ## _dirac_pixels8_c(dst, src, stride, h);\
576  else\
577  OPNAME ## _pixels8_ ## EXT(dst, src[0], stride, h);\
578 }\
579 void ff_ ## OPNAME2 ## _dirac_pixels16_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
580 {\
581  if (h&3)\
582  ff_ ## OPNAME2 ## _dirac_pixels16_c(dst, src, stride, h);\
583  else\
584  OPNAME ## _pixels16_ ## EXT(dst, src[0], stride, h);\
585 }\
586 void ff_ ## OPNAME2 ## _dirac_pixels32_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
587 {\
588  if (h&3) {\
589  ff_ ## OPNAME2 ## _dirac_pixels32_c(dst, src, stride, h);\
590  } else {\
591  OPNAME ## _pixels16_ ## EXT(dst , src[0] , stride, h);\
592  OPNAME ## _pixels16_ ## EXT(dst+16, src[0]+16, stride, h);\
593  }\
594 }
595 
596 #if HAVE_MMX_INLINE
597 PIXELS16(static, ff_avg, , , _mmxext)
598 DIRAC_PIXOP(put, ff_put, mmx)
599 DIRAC_PIXOP(avg, ff_avg, mmx)
600 #endif
601 
602 #if HAVE_YASM
603 DIRAC_PIXOP(avg, ff_avg, mmxext)
604 
605 void ff_put_dirac_pixels16_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h)
606 {
607  if (h&3)
608  ff_put_dirac_pixels16_c(dst, src, stride, h);
609  else
610  ff_put_pixels16_sse2(dst, src[0], stride, h);
611 }
612 void ff_avg_dirac_pixels16_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h)
613 {
614  if (h&3)
615  ff_avg_dirac_pixels16_c(dst, src, stride, h);
616  else
617  ff_avg_pixels16_sse2(dst, src[0], stride, h);
618 }
619 void ff_put_dirac_pixels32_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h)
620 {
621  if (h&3) {
622  ff_put_dirac_pixels32_c(dst, src, stride, h);
623  } else {
624  ff_put_pixels16_sse2(dst , src[0] , stride, h);
625  ff_put_pixels16_sse2(dst+16, src[0]+16, stride, h);
626  }
627 }
628 void ff_avg_dirac_pixels32_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h)
629 {
630  if (h&3) {
631  ff_avg_dirac_pixels32_c(dst, src, stride, h);
632  } else {
633  ff_avg_pixels16_sse2(dst , src[0] , stride, h);
634  ff_avg_pixels16_sse2(dst+16, src[0]+16, stride, h);
635  }
636 }
637 #endif
638 #endif
639 
640 void ff_vector_clipf_sse(float *dst, const float *src,
641  float min, float max, int len)
642 {
643  x86_reg i = (len - 16) * 4;
644  __asm__ volatile (
645  "movss %3, %%xmm4 \n\t"
646  "movss %4, %%xmm5 \n\t"
647  "shufps $0, %%xmm4, %%xmm4 \n\t"
648  "shufps $0, %%xmm5, %%xmm5 \n\t"
649  "1: \n\t"
650  "movaps (%2, %0), %%xmm0 \n\t" // 3/1 on intel
651  "movaps 16(%2, %0), %%xmm1 \n\t"
652  "movaps 32(%2, %0), %%xmm2 \n\t"
653  "movaps 48(%2, %0), %%xmm3 \n\t"
654  "maxps %%xmm4, %%xmm0 \n\t"
655  "maxps %%xmm4, %%xmm1 \n\t"
656  "maxps %%xmm4, %%xmm2 \n\t"
657  "maxps %%xmm4, %%xmm3 \n\t"
658  "minps %%xmm5, %%xmm0 \n\t"
659  "minps %%xmm5, %%xmm1 \n\t"
660  "minps %%xmm5, %%xmm2 \n\t"
661  "minps %%xmm5, %%xmm3 \n\t"
662  "movaps %%xmm0, (%1, %0) \n\t"
663  "movaps %%xmm1, 16(%1, %0) \n\t"
664  "movaps %%xmm2, 32(%1, %0) \n\t"
665  "movaps %%xmm3, 48(%1, %0) \n\t"
666  "sub $64, %0 \n\t"
667  "jge 1b \n\t"
668  : "+&r"(i)
669  : "r"(dst), "r"(src), "m"(min), "m"(max)
670  : "memory"
671  );
672 }
673 
674 #endif /* HAVE_INLINE_ASM */