videodsp_init.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Ronald S. Bultje
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "config.h"
22 #include "libavutil/common.h"
23 #include "libavutil/cpu.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/x86/asm.h"
26 #include "libavcodec/videodsp.h"
27 
28 #if HAVE_YASM
29 typedef void emu_edge_core_func(uint8_t *buf, const uint8_t *src,
30  x86_reg linesize, x86_reg start_y,
31  x86_reg end_y, x86_reg block_h,
32  x86_reg start_x, x86_reg end_x,
33  x86_reg block_w);
34 extern emu_edge_core_func ff_emu_edge_core_mmx;
35 extern emu_edge_core_func ff_emu_edge_core_sse;
36 
37 static av_always_inline void emulated_edge_mc(uint8_t *buf, const uint8_t *src,
38  ptrdiff_t linesize,
39  int block_w, int block_h,
40  int src_x, int src_y,
41  int w, int h,
42  emu_edge_core_func *core_fn)
43 {
44  int start_y, start_x, end_y, end_x, src_y_add = 0;
45 
46  if (src_y >= h) {
47  src_y_add = h - 1 - src_y;
48  src_y = h - 1;
49  } else if (src_y <= -block_h) {
50  src_y_add = 1 - block_h - src_y;
51  src_y = 1 - block_h;
52  }
53  if (src_x >= w) {
54  src += w - 1 - src_x;
55  src_x = w - 1;
56  } else if (src_x <= -block_w) {
57  src += 1 - block_w - src_x;
58  src_x = 1 - block_w;
59  }
60 
61  start_y = FFMAX(0, -src_y);
62  start_x = FFMAX(0, -src_x);
63  end_y = FFMIN(block_h, h-src_y);
64  end_x = FFMIN(block_w, w-src_x);
65  assert(start_x < end_x && block_w > 0);
66  assert(start_y < end_y && block_h > 0);
67 
68  // fill in the to-be-copied part plus all above/below
69  src += (src_y_add + start_y) * linesize + start_x;
70  buf += start_x;
71  core_fn(buf, src, linesize, start_y, end_y,
72  block_h, start_x, end_x, block_w);
73 }
74 
75 #if ARCH_X86_32
76 static av_noinline void emulated_edge_mc_mmx(uint8_t *buf, const uint8_t *src,
77  ptrdiff_t linesize,
78  int block_w, int block_h,
79  int src_x, int src_y, int w, int h)
80 {
81  emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
82  w, h, &ff_emu_edge_core_mmx);
83 }
84 #endif
85 
86 static av_noinline void emulated_edge_mc_sse(uint8_t *buf, const uint8_t *src,
87  ptrdiff_t linesize,
88  int block_w, int block_h,
89  int src_x, int src_y, int w, int h)
90 {
91  emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
92  w, h, &ff_emu_edge_core_sse);
93 }
94 #endif /* HAVE_YASM */
95 
96 void ff_prefetch_mmxext(uint8_t *buf, ptrdiff_t stride, int h);
97 void ff_prefetch_3dnow(uint8_t *buf, ptrdiff_t stride, int h);
98 
100 {
101 #if HAVE_YASM
102  int mm_flags = av_get_cpu_flags();
103 
104 #if ARCH_X86_32
105  if (bpc <= 8 && mm_flags & AV_CPU_FLAG_MMX) {
106  ctx->emulated_edge_mc = emulated_edge_mc_mmx;
107  }
108  if (mm_flags & AV_CPU_FLAG_3DNOW) {
110  }
111 #endif /* ARCH_X86_32 */
112  if (mm_flags & AV_CPU_FLAG_MMXEXT) {
114  }
115  if (bpc <= 8 && mm_flags & AV_CPU_FLAG_SSE) {
116  ctx->emulated_edge_mc = emulated_edge_mc_sse;
117  }
118 #endif /* HAVE_YASM */
119 }