FFmpeg  2.8.17
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
mpegvideodsp.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "config.h"
20 #include "libavutil/attributes.h"
21 #include "libavutil/cpu.h"
22 #include "libavutil/x86/asm.h"
23 #include "libavutil/x86/cpu.h"
25 #include "libavcodec/videodsp.h"
26 
27 #if HAVE_INLINE_ASM
28 
29 static void gmc_mmx(uint8_t *dst, uint8_t *src,
30  int stride, int h, int ox, int oy,
31  int dxx, int dxy, int dyx, int dyy,
32  int shift, int r, int width, int height)
33 {
34  const int w = 8;
35  const int ix = ox >> (16 + shift);
36  const int iy = oy >> (16 + shift);
37  const int oxs = ox >> 4;
38  const int oys = oy >> 4;
39  const int dxxs = dxx >> 4;
40  const int dxys = dxy >> 4;
41  const int dyxs = dyx >> 4;
42  const int dyys = dyy >> 4;
43  const uint16_t r4[4] = { r, r, r, r };
44  const uint16_t dxy4[4] = { dxys, dxys, dxys, dxys };
45  const uint16_t dyy4[4] = { dyys, dyys, dyys, dyys };
46  const uint64_t shift2 = 2 * shift;
47 #define MAX_STRIDE 4096U
48 #define MAX_H 8U
49  uint8_t edge_buf[(MAX_H + 1) * MAX_STRIDE];
50  int x, y;
51 
52  const int dxw = (dxx - (1 << (16 + shift))) * (w - 1);
53  const int dyh = (dyy - (1 << (16 + shift))) * (h - 1);
54  const int dxh = dxy * (h - 1);
55  const int dyw = dyx * (w - 1);
56  int need_emu = (unsigned) ix >= width - w || width < w ||
57  (unsigned) iy >= height - h || height< h
58  ;
59 
60  if ( // non-constant fullpel offset (3% of blocks)
61  ((ox ^ (ox + dxw)) | (ox ^ (ox + dxh)) | (ox ^ (ox + dxw + dxh)) |
62  (oy ^ (oy + dyw)) | (oy ^ (oy + dyh)) | (oy ^ (oy + dyw + dyh))) >> (16 + shift) ||
63  // uses more than 16 bits of subpel mv (only at huge resolution)
64  (dxx | dxy | dyx | dyy) & 15 ||
65  (need_emu && (h > MAX_H || stride > MAX_STRIDE))) {
66  // FIXME could still use mmx for some of the rows
67  ff_gmc_c(dst, src, stride, h, ox, oy, dxx, dxy, dyx, dyy,
68  shift, r, width, height);
69  return;
70  }
71 
72  src += ix + iy * stride;
73  if (need_emu) {
74  ff_emulated_edge_mc_8(edge_buf, src, stride, stride, w + 1, h + 1, ix, iy, width, height);
75  src = edge_buf;
76  }
77 
78  __asm__ volatile (
79  "movd %0, %%mm6 \n\t"
80  "pxor %%mm7, %%mm7 \n\t"
81  "punpcklwd %%mm6, %%mm6 \n\t"
82  "punpcklwd %%mm6, %%mm6 \n\t"
83  :: "r" (1 << shift));
84 
85  for (x = 0; x < w; x += 4) {
86  uint16_t dx4[4] = { oxs - dxys + dxxs * (x + 0),
87  oxs - dxys + dxxs * (x + 1),
88  oxs - dxys + dxxs * (x + 2),
89  oxs - dxys + dxxs * (x + 3) };
90  uint16_t dy4[4] = { oys - dyys + dyxs * (x + 0),
91  oys - dyys + dyxs * (x + 1),
92  oys - dyys + dyxs * (x + 2),
93  oys - dyys + dyxs * (x + 3) };
94 
95  for (y = 0; y < h; y++) {
96  __asm__ volatile (
97  "movq %0, %%mm4 \n\t"
98  "movq %1, %%mm5 \n\t"
99  "paddw %2, %%mm4 \n\t"
100  "paddw %3, %%mm5 \n\t"
101  "movq %%mm4, %0 \n\t"
102  "movq %%mm5, %1 \n\t"
103  "psrlw $12, %%mm4 \n\t"
104  "psrlw $12, %%mm5 \n\t"
105  : "+m" (*dx4), "+m" (*dy4)
106  : "m" (*dxy4), "m" (*dyy4));
107 
108  __asm__ volatile (
109  "movq %%mm6, %%mm2 \n\t"
110  "movq %%mm6, %%mm1 \n\t"
111  "psubw %%mm4, %%mm2 \n\t"
112  "psubw %%mm5, %%mm1 \n\t"
113  "movq %%mm2, %%mm0 \n\t"
114  "movq %%mm4, %%mm3 \n\t"
115  "pmullw %%mm1, %%mm0 \n\t" // (s - dx) * (s - dy)
116  "pmullw %%mm5, %%mm3 \n\t" // dx * dy
117  "pmullw %%mm5, %%mm2 \n\t" // (s - dx) * dy
118  "pmullw %%mm4, %%mm1 \n\t" // dx * (s - dy)
119 
120  "movd %4, %%mm5 \n\t"
121  "movd %3, %%mm4 \n\t"
122  "punpcklbw %%mm7, %%mm5 \n\t"
123  "punpcklbw %%mm7, %%mm4 \n\t"
124  "pmullw %%mm5, %%mm3 \n\t" // src[1, 1] * dx * dy
125  "pmullw %%mm4, %%mm2 \n\t" // src[0, 1] * (s - dx) * dy
126 
127  "movd %2, %%mm5 \n\t"
128  "movd %1, %%mm4 \n\t"
129  "punpcklbw %%mm7, %%mm5 \n\t"
130  "punpcklbw %%mm7, %%mm4 \n\t"
131  "pmullw %%mm5, %%mm1 \n\t" // src[1, 0] * dx * (s - dy)
132  "pmullw %%mm4, %%mm0 \n\t" // src[0, 0] * (s - dx) * (s - dy)
133  "paddw %5, %%mm1 \n\t"
134  "paddw %%mm3, %%mm2 \n\t"
135  "paddw %%mm1, %%mm0 \n\t"
136  "paddw %%mm2, %%mm0 \n\t"
137 
138  "psrlw %6, %%mm0 \n\t"
139  "packuswb %%mm0, %%mm0 \n\t"
140  "movd %%mm0, %0 \n\t"
141 
142  : "=m" (dst[x + y * stride])
143  : "m" (src[0]), "m" (src[1]),
144  "m" (src[stride]), "m" (src[stride + 1]),
145  "m" (*r4), "m" (shift2));
146  src += stride;
147  }
148  src += 4 - h * stride;
149  }
150 }
151 
152 #endif /* HAVE_INLINE_ASM */
153 
155 {
156 #if HAVE_INLINE_ASM
157  int cpu_flags = av_get_cpu_flags();
158 
159  if (INLINE_MMX(cpu_flags))
160  c->gmc = gmc_mmx;
161 #endif /* HAVE_INLINE_ASM */
162 }
static int shift(int a, int b)
Definition: sonic.c:82
Macro definitions for various function/variable attributes.
uint8_t
#define av_cold
Definition: attributes.h:74
void(* gmc)(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy, int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
global motion compensation.
Definition: mpegvideodsp.h:37
#define INLINE_MMX(flags)
Definition: cpu.h:75
const char * r
Definition: vf_curves.c:107
av_cold void ff_mpegvideodsp_init_x86(MpegVideoDSPContext *c)
Definition: mpegvideodsp.c:154
void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy, int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
Definition: mpegvideodsp.c:47
float y
AVS_Value src
Definition: avisynth_c.h:482
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:76
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
static const int shift2[6]
Definition: dxa.c:51
static double c[64]
Core video DSP helper functions.
#define stride
static int width