sh4: drop unused functions
[ffmpeg.git] / libavcodec / sh4 / dsputil_align.c
1 /*
2  * aligned/packed access motion
3  *
4  * Copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
5  *
6  * This file is part of Libav.
7  *
8  * Libav 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  * Libav 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 Libav; 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 "dsputil_sh4.h"
27
28
29 #define         LP(p)           *(uint32_t*)(p)
30 #define         LPC(p)          *(const uint32_t*)(p)
31
32
33 #define         UNPACK(ph,pl,tt0,tt1) do { \
34         uint32_t t0,t1; t0=tt0;t1=tt1; \
35         ph = ( (t0 & ~BYTE_VEC32(0x03))>>2) + ( (t1 & ~BYTE_VEC32(0x03))>>2); \
36         pl = (t0 & BYTE_VEC32(0x03)) + (t1 & BYTE_VEC32(0x03)); } while(0)
37
38 #define         rnd_PACK(ph,pl,nph,npl) ph + nph + (((pl + npl + BYTE_VEC32(0x02))>>2) & BYTE_VEC32(0x03))
39 #define         no_rnd_PACK(ph,pl,nph,npl)      ph + nph + (((pl + npl + BYTE_VEC32(0x01))>>2) & BYTE_VEC32(0x03))
40
41 /* little-endian */
42 #define         MERGE1(a,b,ofs) (ofs==0)?a:( ((a)>>(8*ofs))|((b)<<(32-8*ofs)) )
43 #define         MERGE2(a,b,ofs) (ofs==3)?b:( ((a)>>(8*(ofs+1)))|((b)<<(32-8*(ofs+1))) )
44 /* big
45 #define         MERGE1(a,b,ofs) (ofs==0)?a:( ((a)<<(8*ofs))|((b)>>(32-8*ofs)) )
46 #define         MERGE2(a,b,ofs) (ofs==3)?b:( ((a)<<(8+8*ofs))|((b)>>(32-8-8*ofs)) )
47 */
48
49
50 #define         put(d,s)        d = s
51 #define         avg(d,s)        d = rnd_avg32(s,d)
52
53 #define         OP_C4(ofs) \
54         ref-=ofs; \
55         do { \
56                 OP(LP(dest),MERGE1(LPC(ref),LPC(ref+4),ofs)); \
57                 ref+=stride; \
58                 dest+=stride; \
59         } while(--height)
60
61 #define        OP_C40() \
62         do { \
63                 OP(LP(dest),LPC(ref)); \
64                 ref+=stride; \
65                 dest+=stride; \
66         } while(--height)
67
68 #define         OP_C(ofs,sz,avg2) \
69 { \
70         ref-=ofs; \
71         do { \
72                 uint32_t        t0,t1; \
73                 t0 = LPC(ref+0); \
74                 t1 = LPC(ref+4); \
75                 OP(LP(dest+0), MERGE1(t0,t1,ofs)); \
76                 t0 = LPC(ref+8); \
77                 OP(LP(dest+4), MERGE1(t1,t0,ofs)); \
78 if (sz==16) { \
79                 t1 = LPC(ref+12); \
80                 OP(LP(dest+8), MERGE1(t0,t1,ofs)); \
81                 t0 = LPC(ref+16); \
82                 OP(LP(dest+12), MERGE1(t1,t0,ofs)); \
83 } \
84                 ref+=stride; \
85                 dest+= stride; \
86         } while(--height); \
87 }
88
89 /* aligned */
90 #define         OP_C0(sz,avg2) \
91 { \
92         do { \
93                 OP(LP(dest+0), LPC(ref+0)); \
94                 OP(LP(dest+4), LPC(ref+4)); \
95 if (sz==16) { \
96                 OP(LP(dest+8), LPC(ref+8)); \
97                 OP(LP(dest+12), LPC(ref+12)); \
98 } \
99                 ref+=stride; \
100                 dest+= stride; \
101         } while(--height); \
102 }
103
104 #define         OP_X(ofs,sz,avg2) \
105 { \
106         ref-=ofs; \
107         do { \
108                 uint32_t        t0,t1; \
109                 t0 = LPC(ref+0); \
110                 t1 = LPC(ref+4); \
111                 OP(LP(dest+0), avg2(MERGE1(t0,t1,ofs),MERGE2(t0,t1,ofs))); \
112                 t0 = LPC(ref+8); \
113                 OP(LP(dest+4), avg2(MERGE1(t1,t0,ofs),MERGE2(t1,t0,ofs))); \
114 if (sz==16) { \
115                 t1 = LPC(ref+12); \
116                 OP(LP(dest+8), avg2(MERGE1(t0,t1,ofs),MERGE2(t0,t1,ofs))); \
117                 t0 = LPC(ref+16); \
118                 OP(LP(dest+12), avg2(MERGE1(t1,t0,ofs),MERGE2(t1,t0,ofs))); \
119 } \
120                 ref+=stride; \
121                 dest+= stride; \
122         } while(--height); \
123 }
124
125 /* aligned */
126 #define         OP_Y0(sz,avg2) \
127 { \
128         uint32_t t0,t1,t2,t3,t; \
129 \
130         t0 = LPC(ref+0); \
131         t1 = LPC(ref+4); \
132 if (sz==16) { \
133         t2 = LPC(ref+8); \
134         t3 = LPC(ref+12); \
135 } \
136         do { \
137                 ref += stride; \
138 \
139                 t = LPC(ref+0); \
140                 OP(LP(dest+0), avg2(t0,t)); t0 = t; \
141                 t = LPC(ref+4); \
142                 OP(LP(dest+4), avg2(t1,t)); t1 = t; \
143 if (sz==16) { \
144                 t = LPC(ref+8); \
145                 OP(LP(dest+8), avg2(t2,t)); t2 = t; \
146                 t = LPC(ref+12); \
147                 OP(LP(dest+12), avg2(t3,t)); t3 = t; \
148 } \
149                 dest+= stride; \
150         } while(--height); \
151 }
152
153 #define         OP_Y(ofs,sz,avg2) \
154 { \
155         uint32_t t0,t1,t2,t3,t,w0,w1; \
156 \
157         ref-=ofs; \
158         w0 = LPC(ref+0); \
159         w1 = LPC(ref+4); \
160         t0 = MERGE1(w0,w1,ofs); \
161         w0 = LPC(ref+8); \
162         t1 = MERGE1(w1,w0,ofs); \
163 if (sz==16) { \
164         w1 = LPC(ref+12); \
165         t2 = MERGE1(w0,w1,ofs); \
166         w0 = LPC(ref+16); \
167         t3 = MERGE1(w1,w0,ofs); \
168 } \
169         do { \
170                 ref += stride; \
171 \
172                 w0 = LPC(ref+0); \
173                 w1 = LPC(ref+4); \
174                 t = MERGE1(w0,w1,ofs); \
175                 OP(LP(dest+0), avg2(t0,t)); t0 = t; \
176                 w0 = LPC(ref+8); \
177                 t = MERGE1(w1,w0,ofs); \
178                 OP(LP(dest+4), avg2(t1,t)); t1 = t; \
179 if (sz==16) { \
180                 w1 = LPC(ref+12); \
181                 t = MERGE1(w0,w1,ofs); \
182                 OP(LP(dest+8), avg2(t2,t)); t2 = t; \
183                 w0 = LPC(ref+16); \
184                 t = MERGE1(w1,w0,ofs); \
185                 OP(LP(dest+12), avg2(t3,t)); t3 = t; \
186 } \
187                 dest+=stride; \
188         } while(--height); \
189 }
190
191 #define OP_X0(sz,avg2) OP_X(0,sz,avg2)
192 #define OP_XY0(sz,PACK) OP_XY(0,sz,PACK)
193 #define         OP_XY(ofs,sz,PACK) \
194 { \
195         uint32_t        t2,t3,w0,w1; \
196         uint32_t        a0,a1,a2,a3,a4,a5,a6,a7; \
197 \
198         ref -= ofs; \
199         w0 = LPC(ref+0); \
200         w1 = LPC(ref+4); \
201         UNPACK(a0,a1,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
202         w0 = LPC(ref+8); \
203         UNPACK(a2,a3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
204 if (sz==16) { \
205         w1 = LPC(ref+12); \
206         UNPACK(a4,a5,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
207         w0 = LPC(ref+16); \
208         UNPACK(a6,a7,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
209 } \
210         do { \
211                 ref+=stride; \
212                 w0 = LPC(ref+0); \
213                 w1 = LPC(ref+4); \
214                 UNPACK(t2,t3,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
215                 OP(LP(dest+0),PACK(a0,a1,t2,t3)); \
216                 a0 = t2; a1 = t3; \
217                 w0 = LPC(ref+8); \
218                 UNPACK(t2,t3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
219                 OP(LP(dest+4),PACK(a2,a3,t2,t3)); \
220                 a2 = t2; a3 = t3; \
221 if (sz==16) { \
222                 w1 = LPC(ref+12); \
223                 UNPACK(t2,t3,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
224                 OP(LP(dest+8),PACK(a4,a5,t2,t3)); \
225                 a4 = t2; a5 = t3; \
226                 w0 = LPC(ref+16); \
227                 UNPACK(t2,t3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
228                 OP(LP(dest+12),PACK(a6,a7,t2,t3)); \
229                 a6 = t2; a7 = t3; \
230 } \
231                 dest+=stride; \
232         } while(--height); \
233 }
234
235 #define         DEFFUNC(op,rnd,xy,sz,OP_N,avgfunc) \
236 static void op##_##rnd##_pixels##sz##_##xy (uint8_t * dest, const uint8_t * ref, \
237                                 const ptrdiff_t stride, int height) \
238 { \
239         switch((int)ref&3) { \
240         case 0:OP_N##0(sz,rnd##_##avgfunc); return; \
241         case 1:OP_N(1,sz,rnd##_##avgfunc); return; \
242         case 2:OP_N(2,sz,rnd##_##avgfunc); return; \
243         case 3:OP_N(3,sz,rnd##_##avgfunc); return; \
244         } \
245 }
246
247 #define OP put
248
249 DEFFUNC(put,   rnd,o,8,OP_C,avg32)
250 DEFFUNC(put,   rnd,x,8,OP_X,avg32)
251 DEFFUNC(put,no_rnd,x,8,OP_X,avg32)
252 DEFFUNC(put,   rnd,y,8,OP_Y,avg32)
253 DEFFUNC(put,no_rnd,y,8,OP_Y,avg32)
254 DEFFUNC(put,   rnd,xy,8,OP_XY,PACK)
255 DEFFUNC(put,no_rnd,xy,8,OP_XY,PACK)
256 DEFFUNC(put,   rnd,o,16,OP_C,avg32)
257 DEFFUNC(put,   rnd,x,16,OP_X,avg32)
258 DEFFUNC(put,no_rnd,x,16,OP_X,avg32)
259 DEFFUNC(put,   rnd,y,16,OP_Y,avg32)
260 DEFFUNC(put,no_rnd,y,16,OP_Y,avg32)
261 DEFFUNC(put,   rnd,xy,16,OP_XY,PACK)
262 DEFFUNC(put,no_rnd,xy,16,OP_XY,PACK)
263
264 #undef OP
265 #define OP avg
266
267 DEFFUNC(avg,   rnd,o,8,OP_C,avg32)
268 DEFFUNC(avg,   rnd,x,8,OP_X,avg32)
269 DEFFUNC(avg,   rnd,y,8,OP_Y,avg32)
270 DEFFUNC(avg,   rnd,xy,8,OP_XY,PACK)
271 DEFFUNC(avg,   rnd,o,16,OP_C,avg32)
272 DEFFUNC(avg,   rnd,x,16,OP_X,avg32)
273 DEFFUNC(avg,no_rnd,x,16,OP_X,avg32)
274 DEFFUNC(avg,   rnd,y,16,OP_Y,avg32)
275 DEFFUNC(avg,no_rnd,y,16,OP_Y,avg32)
276 DEFFUNC(avg,   rnd,xy,16,OP_XY,PACK)
277 DEFFUNC(avg,no_rnd,xy,16,OP_XY,PACK)
278
279 #undef OP
280
281 #define         put_no_rnd_pixels8_o     put_rnd_pixels8_o
282 #define         put_no_rnd_pixels16_o    put_rnd_pixels16_o
283 #define         avg_no_rnd_pixels16_o    avg_rnd_pixels16_o
284
285 #define         put_pixels8_c            put_rnd_pixels8_o
286 #define         put_pixels16_c           put_rnd_pixels16_o
287 #define         avg_pixels8_c            avg_rnd_pixels8_o
288 #define         avg_pixels16_c           avg_rnd_pixels16_o
289 #define         put_no_rnd_pixels8_c     put_rnd_pixels8_o
290 #define         put_no_rnd_pixels16_c    put_rnd_pixels16_o
291 #define         avg_no_rnd_pixels16_c    avg_rnd_pixels16_o
292
293 #define         QPEL
294
295 #ifdef QPEL
296
297 #include "qpel.c"
298
299 #endif
300
301 av_cold void ff_dsputil_init_align(DSPContext *c, AVCodecContext *avctx)
302 {
303         const int high_bit_depth = avctx->bits_per_raw_sample > 8;
304
305         if (!high_bit_depth) {
306         c->put_pixels_tab[0][0] = put_rnd_pixels16_o;
307         c->put_pixels_tab[0][1] = put_rnd_pixels16_x;
308         c->put_pixels_tab[0][2] = put_rnd_pixels16_y;
309         c->put_pixels_tab[0][3] = put_rnd_pixels16_xy;
310         c->put_pixels_tab[1][0] = put_rnd_pixels8_o;
311         c->put_pixels_tab[1][1] = put_rnd_pixels8_x;
312         c->put_pixels_tab[1][2] = put_rnd_pixels8_y;
313         c->put_pixels_tab[1][3] = put_rnd_pixels8_xy;
314
315         c->put_no_rnd_pixels_tab[0][0] = put_no_rnd_pixels16_o;
316         c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x;
317         c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y;
318         c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy;
319         c->put_no_rnd_pixels_tab[1][0] = put_no_rnd_pixels8_o;
320         c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x;
321         c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y;
322         c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy;
323
324         c->avg_pixels_tab[0][0] = avg_rnd_pixels16_o;
325         c->avg_pixels_tab[0][1] = avg_rnd_pixels16_x;
326         c->avg_pixels_tab[0][2] = avg_rnd_pixels16_y;
327         c->avg_pixels_tab[0][3] = avg_rnd_pixels16_xy;
328         c->avg_pixels_tab[1][0] = avg_rnd_pixels8_o;
329         c->avg_pixels_tab[1][1] = avg_rnd_pixels8_x;
330         c->avg_pixels_tab[1][2] = avg_rnd_pixels8_y;
331         c->avg_pixels_tab[1][3] = avg_rnd_pixels8_xy;
332
333         c->avg_no_rnd_pixels_tab[0] = avg_no_rnd_pixels16_o;
334         c->avg_no_rnd_pixels_tab[1] = avg_no_rnd_pixels16_x;
335         c->avg_no_rnd_pixels_tab[2] = avg_no_rnd_pixels16_y;
336         c->avg_no_rnd_pixels_tab[3] = avg_no_rnd_pixels16_xy;
337         }
338
339 #ifdef QPEL
340
341 #define dspfunc(PFX, IDX, NUM) \
342     c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_sh4; \
343     c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_sh4; \
344     c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_sh4; \
345     c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_sh4; \
346     c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_sh4; \
347     c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_sh4; \
348     c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_sh4; \
349     c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_sh4; \
350     c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_sh4; \
351     c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_sh4; \
352     c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_sh4; \
353     c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_sh4; \
354     c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_sh4; \
355     c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_sh4; \
356     c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_sh4; \
357     c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_sh4
358
359     dspfunc(put_qpel, 0, 16);
360     dspfunc(put_no_rnd_qpel, 0, 16);
361
362     dspfunc(avg_qpel, 0, 16);
363     /* dspfunc(avg_no_rnd_qpel, 0, 16); */
364
365     dspfunc(put_qpel, 1, 8);
366     dspfunc(put_no_rnd_qpel, 1, 8);
367
368     dspfunc(avg_qpel, 1, 8);
369     /* dspfunc(avg_no_rnd_qpel, 1, 8); */
370
371 #undef dspfunc
372     if (!high_bit_depth) {
373     c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_sh4;
374     c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_sh4;
375     c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_sh4;
376     c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_sh4;
377     c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_sh4;
378     c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_sh4;
379     }
380
381     c->put_mspel_pixels_tab[0]= put_mspel8_mc00_sh4;
382     c->put_mspel_pixels_tab[1]= put_mspel8_mc10_sh4;
383     c->put_mspel_pixels_tab[2]= put_mspel8_mc20_sh4;
384     c->put_mspel_pixels_tab[3]= put_mspel8_mc30_sh4;
385     c->put_mspel_pixels_tab[4]= put_mspel8_mc02_sh4;
386     c->put_mspel_pixels_tab[5]= put_mspel8_mc12_sh4;
387     c->put_mspel_pixels_tab[6]= put_mspel8_mc22_sh4;
388     c->put_mspel_pixels_tab[7]= put_mspel8_mc32_sh4;
389
390     c->gmc1 = gmc1_c;
391
392 #endif
393 }