dsputil_align.c
Go to the documentation of this file.
1 /*
2  * aligned/packed access motion
3  *
4  * Copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
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 
23 #include "libavutil/attributes.h"
24 #include "libavcodec/avcodec.h"
25 #include "libavcodec/dsputil.h"
26 #include "libavcodec/rnd_avg.h"
27 #include "dsputil_sh4.h"
28 
29 
30 #define LP(p) *(uint32_t*)(p)
31 #define LPC(p) *(const uint32_t*)(p)
32 
33 
34 #define UNPACK(ph,pl,tt0,tt1) do { \
35  uint32_t t0,t1; t0=tt0;t1=tt1; \
36  ph = ( (t0 & ~BYTE_VEC32(0x03))>>2) + ( (t1 & ~BYTE_VEC32(0x03))>>2); \
37  pl = (t0 & BYTE_VEC32(0x03)) + (t1 & BYTE_VEC32(0x03)); } while(0)
38 
39 #define rnd_PACK(ph,pl,nph,npl) ph + nph + (((pl + npl + BYTE_VEC32(0x02))>>2) & BYTE_VEC32(0x03))
40 #define no_rnd_PACK(ph,pl,nph,npl) ph + nph + (((pl + npl + BYTE_VEC32(0x01))>>2) & BYTE_VEC32(0x03))
41 
42 /* little-endian */
43 #define MERGE1(a,b,ofs) (ofs==0)?a:( ((a)>>(8*ofs))|((b)<<(32-8*ofs)) )
44 #define MERGE2(a,b,ofs) (ofs==3)?b:( ((a)>>(8*(ofs+1)))|((b)<<(32-8*(ofs+1))) )
45 /* big
46 #define MERGE1(a,b,ofs) (ofs==0)?a:( ((a)<<(8*ofs))|((b)>>(32-8*ofs)) )
47 #define MERGE2(a,b,ofs) (ofs==3)?b:( ((a)<<(8+8*ofs))|((b)>>(32-8-8*ofs)) )
48 */
49 
50 
51 #define put(d,s) d = s
52 #define avg(d,s) d = rnd_avg32(s,d)
53 
54 #define OP_C4(ofs) \
55  ref-=ofs; \
56  do { \
57  OP(LP(dest),MERGE1(LPC(ref),LPC(ref+4),ofs)); \
58  ref+=stride; \
59  dest+=stride; \
60  } while(--height)
61 
62 #define OP_C40() \
63  do { \
64  OP(LP(dest),LPC(ref)); \
65  ref+=stride; \
66  dest+=stride; \
67  } while(--height)
68 
69 #define OP_C(ofs,sz,avg2) \
70 { \
71  ref-=ofs; \
72  do { \
73  uint32_t t0,t1; \
74  t0 = LPC(ref+0); \
75  t1 = LPC(ref+4); \
76  OP(LP(dest+0), MERGE1(t0,t1,ofs)); \
77  t0 = LPC(ref+8); \
78  OP(LP(dest+4), MERGE1(t1,t0,ofs)); \
79 if (sz==16) { \
80  t1 = LPC(ref+12); \
81  OP(LP(dest+8), MERGE1(t0,t1,ofs)); \
82  t0 = LPC(ref+16); \
83  OP(LP(dest+12), MERGE1(t1,t0,ofs)); \
84 } \
85  ref+=stride; \
86  dest+= stride; \
87  } while(--height); \
88 }
89 
90 /* aligned */
91 #define OP_C0(sz,avg2) \
92 { \
93  do { \
94  OP(LP(dest+0), LPC(ref+0)); \
95  OP(LP(dest+4), LPC(ref+4)); \
96 if (sz==16) { \
97  OP(LP(dest+8), LPC(ref+8)); \
98  OP(LP(dest+12), LPC(ref+12)); \
99 } \
100  ref+=stride; \
101  dest+= stride; \
102  } while(--height); \
103 }
104 
105 #define OP_X(ofs,sz,avg2) \
106 { \
107  ref-=ofs; \
108  do { \
109  uint32_t t0,t1; \
110  t0 = LPC(ref+0); \
111  t1 = LPC(ref+4); \
112  OP(LP(dest+0), avg2(MERGE1(t0,t1,ofs),MERGE2(t0,t1,ofs))); \
113  t0 = LPC(ref+8); \
114  OP(LP(dest+4), avg2(MERGE1(t1,t0,ofs),MERGE2(t1,t0,ofs))); \
115 if (sz==16) { \
116  t1 = LPC(ref+12); \
117  OP(LP(dest+8), avg2(MERGE1(t0,t1,ofs),MERGE2(t0,t1,ofs))); \
118  t0 = LPC(ref+16); \
119  OP(LP(dest+12), avg2(MERGE1(t1,t0,ofs),MERGE2(t1,t0,ofs))); \
120 } \
121  ref+=stride; \
122  dest+= stride; \
123  } while(--height); \
124 }
125 
126 /* aligned */
127 #define OP_Y0(sz,avg2) \
128 { \
129  uint32_t t0,t1,t2,t3,t; \
130 \
131  t0 = LPC(ref+0); \
132  t1 = LPC(ref+4); \
133 if (sz==16) { \
134  t2 = LPC(ref+8); \
135  t3 = LPC(ref+12); \
136 } \
137  do { \
138  ref += stride; \
139 \
140  t = LPC(ref+0); \
141  OP(LP(dest+0), avg2(t0,t)); t0 = t; \
142  t = LPC(ref+4); \
143  OP(LP(dest+4), avg2(t1,t)); t1 = t; \
144 if (sz==16) { \
145  t = LPC(ref+8); \
146  OP(LP(dest+8), avg2(t2,t)); t2 = t; \
147  t = LPC(ref+12); \
148  OP(LP(dest+12), avg2(t3,t)); t3 = t; \
149 } \
150  dest+= stride; \
151  } while(--height); \
152 }
153 
154 #define OP_Y(ofs,sz,avg2) \
155 { \
156  uint32_t t0,t1,t2,t3,t,w0,w1; \
157 \
158  ref-=ofs; \
159  w0 = LPC(ref+0); \
160  w1 = LPC(ref+4); \
161  t0 = MERGE1(w0,w1,ofs); \
162  w0 = LPC(ref+8); \
163  t1 = MERGE1(w1,w0,ofs); \
164 if (sz==16) { \
165  w1 = LPC(ref+12); \
166  t2 = MERGE1(w0,w1,ofs); \
167  w0 = LPC(ref+16); \
168  t3 = MERGE1(w1,w0,ofs); \
169 } \
170  do { \
171  ref += stride; \
172 \
173  w0 = LPC(ref+0); \
174  w1 = LPC(ref+4); \
175  t = MERGE1(w0,w1,ofs); \
176  OP(LP(dest+0), avg2(t0,t)); t0 = t; \
177  w0 = LPC(ref+8); \
178  t = MERGE1(w1,w0,ofs); \
179  OP(LP(dest+4), avg2(t1,t)); t1 = t; \
180 if (sz==16) { \
181  w1 = LPC(ref+12); \
182  t = MERGE1(w0,w1,ofs); \
183  OP(LP(dest+8), avg2(t2,t)); t2 = t; \
184  w0 = LPC(ref+16); \
185  t = MERGE1(w1,w0,ofs); \
186  OP(LP(dest+12), avg2(t3,t)); t3 = t; \
187 } \
188  dest+=stride; \
189  } while(--height); \
190 }
191 
192 #define OP_X0(sz,avg2) OP_X(0,sz,avg2)
193 #define OP_XY0(sz,PACK) OP_XY(0,sz,PACK)
194 #define OP_XY(ofs,sz,PACK) \
195 { \
196  uint32_t t2,t3,w0,w1; \
197  uint32_t a0,a1,a2,a3,a4,a5,a6,a7; \
198 \
199  ref -= ofs; \
200  w0 = LPC(ref+0); \
201  w1 = LPC(ref+4); \
202  UNPACK(a0,a1,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
203  w0 = LPC(ref+8); \
204  UNPACK(a2,a3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
205 if (sz==16) { \
206  w1 = LPC(ref+12); \
207  UNPACK(a4,a5,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
208  w0 = LPC(ref+16); \
209  UNPACK(a6,a7,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
210 } \
211  do { \
212  ref+=stride; \
213  w0 = LPC(ref+0); \
214  w1 = LPC(ref+4); \
215  UNPACK(t2,t3,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
216  OP(LP(dest+0),PACK(a0,a1,t2,t3)); \
217  a0 = t2; a1 = t3; \
218  w0 = LPC(ref+8); \
219  UNPACK(t2,t3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
220  OP(LP(dest+4),PACK(a2,a3,t2,t3)); \
221  a2 = t2; a3 = t3; \
222 if (sz==16) { \
223  w1 = LPC(ref+12); \
224  UNPACK(t2,t3,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
225  OP(LP(dest+8),PACK(a4,a5,t2,t3)); \
226  a4 = t2; a5 = t3; \
227  w0 = LPC(ref+16); \
228  UNPACK(t2,t3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
229  OP(LP(dest+12),PACK(a6,a7,t2,t3)); \
230  a6 = t2; a7 = t3; \
231 } \
232  dest+=stride; \
233  } while(--height); \
234 }
235 
236 #define put_pixels8_c ff_put_rnd_pixels8_o
237 #define put_pixels16_c ff_put_rnd_pixels16_o
238 #define avg_pixels8_c ff_avg_rnd_pixels8_o
239 #define avg_pixels16_c ff_avg_rnd_pixels16_o
240 #define put_no_rnd_pixels8_c ff_put_rnd_pixels8_o
241 #define put_no_rnd_pixels16_c ff_put_rnd_pixels16_o
242 #define avg_no_rnd_pixels16_c ff_avg_rnd_pixels16_o
243 
244 #if CONFIG_HPELDSP
245 
246 #include "qpel.c"
247 
248 #endif
249 
251 {
252 #if CONFIG_HPELDSP
253 
254 #define dspfunc(PFX, IDX, NUM) \
255  c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_sh4; \
256  c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_sh4; \
257  c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_sh4; \
258  c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_sh4; \
259  c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_sh4; \
260  c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_sh4; \
261  c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_sh4; \
262  c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_sh4; \
263  c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_sh4; \
264  c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_sh4; \
265  c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_sh4; \
266  c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_sh4; \
267  c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_sh4; \
268  c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_sh4; \
269  c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_sh4; \
270  c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_sh4
271 
272  dspfunc(put_qpel, 0, 16);
273  dspfunc(put_no_rnd_qpel, 0, 16);
274 
275  dspfunc(avg_qpel, 0, 16);
276  /* dspfunc(avg_no_rnd_qpel, 0, 16); */
277 
278  dspfunc(put_qpel, 1, 8);
279  dspfunc(put_no_rnd_qpel, 1, 8);
280 
281  dspfunc(avg_qpel, 1, 8);
282  /* dspfunc(avg_no_rnd_qpel, 1, 8); */
283 
284 #undef dspfunc
285 
294 
295  c->gmc1 = gmc1_c;
296 
297 #endif
298 }
void(* gmc1)(uint8_t *dst, uint8_t *src, int srcStride, int h, int x16, int y16, int rounder)
translational global motion compensation.
Definition: dsputil.h:139
static void put_mspel8_mc22_sh4(uint8_t *dst, uint8_t *src, int stride)
Definition: qpel.c:858
static void put_mspel8_mc20_sh4(uint8_t *dst, uint8_t *src, int stride)
Definition: qpel.c:826
static void put_mspel8_mc32_sh4(uint8_t *dst, uint8_t *src, int stride)
Definition: qpel.c:849
static void put_mspel8_mc30_sh4(uint8_t *dst, uint8_t *src, int stride)
Definition: qpel.c:830
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:78
qpel_mc_func put_mspel_pixels_tab[8]
Definition: dsputil.h:192
external API header
static void put_mspel8_mc02_sh4(uint8_t *dst, uint8_t *src, int stride)
Definition: qpel.c:836
static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
Definition: dsputil.c:523
static void put_mspel8_mc10_sh4(uint8_t *dst, uint8_t *src, int stride)
Definition: qpel.c:820
av_cold void ff_dsputil_init_align(DSPContext *c, AVCodecContext *avctx)
static void put_mspel8_mc12_sh4(uint8_t *dst, uint8_t *src, int stride)
Definition: qpel.c:840
#define dspfunc(PFX, IDX, NUM)
main external API structure.
static void put_mspel8_mc00_sh4(uint8_t *dst, uint8_t *src, int stride)
Definition: qpel.c:816
static double c[64]
DSP utils.
DSPContext.
Definition: dsputil.h:127