FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 DEFFUNC(op,rnd,xy,sz,OP_N,avgfunc) \
237 static void op##_##rnd##_pixels##sz##_##xy (uint8_t * dest, const uint8_t * ref, \
238  const ptrdiff_t stride, int height) \
239 { \
240  switch((int)ref&3) { \
241  case 0:OP_N##0(sz,rnd##_##avgfunc); return; \
242  case 1:OP_N(1,sz,rnd##_##avgfunc); return; \
243  case 2:OP_N(2,sz,rnd##_##avgfunc); return; \
244  case 3:OP_N(3,sz,rnd##_##avgfunc); return; \
245  } \
246 }
247 
248 #define OP put
249 
250 DEFFUNC(put, rnd,o,8,OP_C,avg32)
251 DEFFUNC(put, rnd,x,8,OP_X,avg32)
252 DEFFUNC(put,no_rnd,x,8,OP_X,avg32)
253 DEFFUNC(put, rnd,y,8,OP_Y,avg32)
254 DEFFUNC(put,no_rnd,y,8,OP_Y,avg32)
255 DEFFUNC(put, rnd,xy,8,OP_XY,PACK)
256 DEFFUNC(put,no_rnd,xy,8,OP_XY,PACK)
257 DEFFUNC(put, rnd,o,16,OP_C,avg32)
258 DEFFUNC(put, rnd,x,16,OP_X,avg32)
259 DEFFUNC(put,no_rnd,x,16,OP_X,avg32)
260 DEFFUNC(put, rnd,y,16,OP_Y,avg32)
261 DEFFUNC(put,no_rnd,y,16,OP_Y,avg32)
262 DEFFUNC(put, rnd,xy,16,OP_XY,PACK)
263 DEFFUNC(put,no_rnd,xy,16,OP_XY,PACK)
264 
265 #undef OP
266 #define OP avg
267 
268 DEFFUNC(avg, rnd,o,8,OP_C,avg32)
269 DEFFUNC(avg, rnd,x,8,OP_X,avg32)
270 DEFFUNC(avg, rnd,y,8,OP_Y,avg32)
271 DEFFUNC(avg, rnd,xy,8,OP_XY,PACK)
272 DEFFUNC(avg, rnd,o,16,OP_C,avg32)
273 DEFFUNC(avg, rnd,x,16,OP_X,avg32)
274 DEFFUNC(avg,no_rnd,x,16,OP_X,avg32)
275 DEFFUNC(avg, rnd,y,16,OP_Y,avg32)
276 DEFFUNC(avg,no_rnd,y,16,OP_Y,avg32)
277 DEFFUNC(avg, rnd,xy,16,OP_XY,PACK)
278 DEFFUNC(avg,no_rnd,xy,16,OP_XY,PACK)
279 
280 #undef OP
281 
282 #define put_no_rnd_pixels8_o put_rnd_pixels8_o
283 #define put_no_rnd_pixels16_o put_rnd_pixels16_o
284 #define avg_no_rnd_pixels16_o avg_rnd_pixels16_o
285 
286 #define put_pixels8_c put_rnd_pixels8_o
287 #define put_pixels16_c put_rnd_pixels16_o
288 #define avg_pixels8_c avg_rnd_pixels8_o
289 #define avg_pixels16_c avg_rnd_pixels16_o
290 #define put_no_rnd_pixels8_c put_rnd_pixels8_o
291 #define put_no_rnd_pixels16_c put_rnd_pixels16_o
292 #define avg_no_rnd_pixels16_c avg_rnd_pixels16_o
293 
294 #define QPEL
295 
296 #ifdef QPEL
297 
298 #include "qpel.c"
299 
300 #endif
301 
303 {
304  const int high_bit_depth = avctx->bits_per_raw_sample > 8;
305 
306  if (!high_bit_depth) {
307  c->put_pixels_tab[0][0] = put_rnd_pixels16_o;
308  c->put_pixels_tab[0][1] = put_rnd_pixels16_x;
309  c->put_pixels_tab[0][2] = put_rnd_pixels16_y;
310  c->put_pixels_tab[0][3] = put_rnd_pixels16_xy;
311  c->put_pixels_tab[1][0] = put_rnd_pixels8_o;
312  c->put_pixels_tab[1][1] = put_rnd_pixels8_x;
313  c->put_pixels_tab[1][2] = put_rnd_pixels8_y;
314  c->put_pixels_tab[1][3] = put_rnd_pixels8_xy;
315 
317  c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x;
318  c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y;
319  c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy;
321  c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x;
322  c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y;
323  c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy;
324 
325  c->avg_pixels_tab[0][0] = avg_rnd_pixels16_o;
326  c->avg_pixels_tab[0][1] = avg_rnd_pixels16_x;
327  c->avg_pixels_tab[0][2] = avg_rnd_pixels16_y;
328  c->avg_pixels_tab[0][3] = avg_rnd_pixels16_xy;
329  c->avg_pixels_tab[1][0] = avg_rnd_pixels8_o;
330  c->avg_pixels_tab[1][1] = avg_rnd_pixels8_x;
331  c->avg_pixels_tab[1][2] = avg_rnd_pixels8_y;
332  c->avg_pixels_tab[1][3] = avg_rnd_pixels8_xy;
333 
335  c->avg_no_rnd_pixels_tab[1] = avg_no_rnd_pixels16_x;
336  c->avg_no_rnd_pixels_tab[2] = avg_no_rnd_pixels16_y;
337  c->avg_no_rnd_pixels_tab[3] = avg_no_rnd_pixels16_xy;
338  }
339 
340 #ifdef QPEL
341 
342 #define dspfunc(PFX, IDX, NUM) \
343  c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_sh4; \
344  c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_sh4; \
345  c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_sh4; \
346  c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_sh4; \
347  c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_sh4; \
348  c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_sh4; \
349  c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_sh4; \
350  c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_sh4; \
351  c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_sh4; \
352  c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_sh4; \
353  c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_sh4; \
354  c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_sh4; \
355  c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_sh4; \
356  c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_sh4; \
357  c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_sh4; \
358  c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_sh4
359 
360  dspfunc(put_qpel, 0, 16);
361  dspfunc(put_no_rnd_qpel, 0, 16);
362 
363  dspfunc(avg_qpel, 0, 16);
364  /* dspfunc(avg_no_rnd_qpel, 0, 16); */
365 
366  dspfunc(put_qpel, 1, 8);
367  dspfunc(put_no_rnd_qpel, 1, 8);
368 
369  dspfunc(avg_qpel, 1, 8);
370  /* dspfunc(avg_no_rnd_qpel, 1, 8); */
371 
372 #undef dspfunc
373 
382 
383  c->gmc1 = gmc1_c;
384 
385 #endif
386 }