• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/sh4/dsputil_align.c

Go to the documentation of this file.
00001 /*
00002  * aligned/packed access motion
00003  *
00004  * Copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 
00024 #include "libavcodec/avcodec.h"
00025 #include "libavcodec/dsputil.h"
00026 
00027 
00028 #define         LP(p)           *(uint32_t*)(p)
00029 
00030 
00031 #define         UNPACK(ph,pl,tt0,tt1) do { \
00032         uint32_t t0,t1; t0=tt0;t1=tt1; \
00033         ph = ( (t0 & ~BYTE_VEC32(0x03))>>2) + ( (t1 & ~BYTE_VEC32(0x03))>>2); \
00034         pl = (t0 & BYTE_VEC32(0x03)) + (t1 & BYTE_VEC32(0x03)); } while(0)
00035 
00036 #define         rnd_PACK(ph,pl,nph,npl) ph + nph + (((pl + npl + BYTE_VEC32(0x02))>>2) & BYTE_VEC32(0x03))
00037 #define         no_rnd_PACK(ph,pl,nph,npl)      ph + nph + (((pl + npl + BYTE_VEC32(0x01))>>2) & BYTE_VEC32(0x03))
00038 
00039 /* little endian */
00040 #define         MERGE1(a,b,ofs) (ofs==0)?a:( ((a)>>(8*ofs))|((b)<<(32-8*ofs)) )
00041 #define         MERGE2(a,b,ofs) (ofs==3)?b:( ((a)>>(8*(ofs+1)))|((b)<<(32-8*(ofs+1))) )
00042 /* big
00043 #define         MERGE1(a,b,ofs) (ofs==0)?a:( ((a)<<(8*ofs))|((b)>>(32-8*ofs)) )
00044 #define         MERGE2(a,b,ofs) (ofs==3)?b:( ((a)<<(8+8*ofs))|((b)>>(32-8-8*ofs)) )
00045 */
00046 
00047 
00048 #define         put(d,s)        d = s
00049 #define         avg(d,s)        d = rnd_avg32(s,d)
00050 
00051 #define         OP_C4(ofs) \
00052         ref-=ofs; \
00053         do { \
00054                 OP(LP(dest),MERGE1(LP(ref),LP(ref+4),ofs)); \
00055                 ref+=stride; \
00056                 dest+=stride; \
00057         } while(--height)
00058 
00059 #define        OP_C40() \
00060         do { \
00061                 OP(LP(dest),LP(ref)); \
00062                 ref+=stride; \
00063                 dest+=stride; \
00064         } while(--height)
00065 
00066 
00067 #define         OP      put
00068 
00069 static void put_pixels4_c(uint8_t *dest,const uint8_t *ref, const int stride,int height)
00070 {
00071         switch((int)ref&3){
00072         case 0: OP_C40(); return;
00073         case 1: OP_C4(1); return;
00074         case 2: OP_C4(2); return;
00075         case 3: OP_C4(3); return;
00076         }
00077 }
00078 
00079 #undef          OP
00080 #define         OP      avg
00081 
00082 static void avg_pixels4_c(uint8_t *dest,const uint8_t *ref, const int stride,int height)
00083 {
00084         switch((int)ref&3){
00085         case 0: OP_C40(); return;
00086         case 1: OP_C4(1); return;
00087         case 2: OP_C4(2); return;
00088         case 3: OP_C4(3); return;
00089         }
00090 }
00091 
00092 #undef          OP
00093 
00094 #define         OP_C(ofs,sz,avg2) \
00095 { \
00096         ref-=ofs; \
00097         do { \
00098                 uint32_t        t0,t1; \
00099                 t0 = LP(ref+0); \
00100                 t1 = LP(ref+4); \
00101                 OP(LP(dest+0), MERGE1(t0,t1,ofs)); \
00102                 t0 = LP(ref+8); \
00103                 OP(LP(dest+4), MERGE1(t1,t0,ofs)); \
00104 if (sz==16) { \
00105                 t1 = LP(ref+12); \
00106                 OP(LP(dest+8), MERGE1(t0,t1,ofs)); \
00107                 t0 = LP(ref+16); \
00108                 OP(LP(dest+12), MERGE1(t1,t0,ofs)); \
00109 } \
00110                 ref+=stride; \
00111                 dest+= stride; \
00112         } while(--height); \
00113 }
00114 
00115 /* aligned */
00116 #define         OP_C0(sz,avg2) \
00117 { \
00118         do { \
00119                 OP(LP(dest+0), LP(ref+0)); \
00120                 OP(LP(dest+4), LP(ref+4)); \
00121 if (sz==16) { \
00122                 OP(LP(dest+8), LP(ref+8)); \
00123                 OP(LP(dest+12), LP(ref+12)); \
00124 } \
00125                 ref+=stride; \
00126                 dest+= stride; \
00127         } while(--height); \
00128 }
00129 
00130 #define         OP_X(ofs,sz,avg2) \
00131 { \
00132         ref-=ofs; \
00133         do { \
00134                 uint32_t        t0,t1; \
00135                 t0 = LP(ref+0); \
00136                 t1 = LP(ref+4); \
00137                 OP(LP(dest+0), avg2(MERGE1(t0,t1,ofs),MERGE2(t0,t1,ofs))); \
00138                 t0 = LP(ref+8); \
00139                 OP(LP(dest+4), avg2(MERGE1(t1,t0,ofs),MERGE2(t1,t0,ofs))); \
00140 if (sz==16) { \
00141                 t1 = LP(ref+12); \
00142                 OP(LP(dest+8), avg2(MERGE1(t0,t1,ofs),MERGE2(t0,t1,ofs))); \
00143                 t0 = LP(ref+16); \
00144                 OP(LP(dest+12), avg2(MERGE1(t1,t0,ofs),MERGE2(t1,t0,ofs))); \
00145 } \
00146                 ref+=stride; \
00147                 dest+= stride; \
00148         } while(--height); \
00149 }
00150 
00151 /* aligned */
00152 #define         OP_Y0(sz,avg2) \
00153 { \
00154         uint32_t t0,t1,t2,t3,t; \
00155 \
00156         t0 = LP(ref+0); \
00157         t1 = LP(ref+4); \
00158 if (sz==16) { \
00159         t2 = LP(ref+8); \
00160         t3 = LP(ref+12); \
00161 } \
00162         do { \
00163                 ref += stride; \
00164 \
00165                 t = LP(ref+0); \
00166                 OP(LP(dest+0), avg2(t0,t)); t0 = t; \
00167                 t = LP(ref+4); \
00168                 OP(LP(dest+4), avg2(t1,t)); t1 = t; \
00169 if (sz==16) { \
00170                 t = LP(ref+8); \
00171                 OP(LP(dest+8), avg2(t2,t)); t2 = t; \
00172                 t = LP(ref+12); \
00173                 OP(LP(dest+12), avg2(t3,t)); t3 = t; \
00174 } \
00175                 dest+= stride; \
00176         } while(--height); \
00177 }
00178 
00179 #define         OP_Y(ofs,sz,avg2) \
00180 { \
00181         uint32_t t0,t1,t2,t3,t,w0,w1; \
00182 \
00183         ref-=ofs; \
00184         w0 = LP(ref+0); \
00185         w1 = LP(ref+4); \
00186         t0 = MERGE1(w0,w1,ofs); \
00187         w0 = LP(ref+8); \
00188         t1 = MERGE1(w1,w0,ofs); \
00189 if (sz==16) { \
00190         w1 = LP(ref+12); \
00191         t2 = MERGE1(w0,w1,ofs); \
00192         w0 = LP(ref+16); \
00193         t3 = MERGE1(w1,w0,ofs); \
00194 } \
00195         do { \
00196                 ref += stride; \
00197 \
00198                 w0 = LP(ref+0); \
00199                 w1 = LP(ref+4); \
00200                 t = MERGE1(w0,w1,ofs); \
00201                 OP(LP(dest+0), avg2(t0,t)); t0 = t; \
00202                 w0 = LP(ref+8); \
00203                 t = MERGE1(w1,w0,ofs); \
00204                 OP(LP(dest+4), avg2(t1,t)); t1 = t; \
00205 if (sz==16) { \
00206                 w1 = LP(ref+12); \
00207                 t = MERGE1(w0,w1,ofs); \
00208                 OP(LP(dest+8), avg2(t2,t)); t2 = t; \
00209                 w0 = LP(ref+16); \
00210                 t = MERGE1(w1,w0,ofs); \
00211                 OP(LP(dest+12), avg2(t3,t)); t3 = t; \
00212 } \
00213                 dest+=stride; \
00214         } while(--height); \
00215 }
00216 
00217 #define OP_X0(sz,avg2) OP_X(0,sz,avg2)
00218 #define OP_XY0(sz,PACK) OP_XY(0,sz,PACK)
00219 #define         OP_XY(ofs,sz,PACK) \
00220 { \
00221         uint32_t        t2,t3,w0,w1; \
00222         uint32_t        a0,a1,a2,a3,a4,a5,a6,a7; \
00223 \
00224         ref -= ofs; \
00225         w0 = LP(ref+0); \
00226         w1 = LP(ref+4); \
00227         UNPACK(a0,a1,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
00228         w0 = LP(ref+8); \
00229         UNPACK(a2,a3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
00230 if (sz==16) { \
00231         w1 = LP(ref+12); \
00232         UNPACK(a4,a5,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
00233         w0 = LP(ref+16); \
00234         UNPACK(a6,a7,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
00235 } \
00236         do { \
00237                 ref+=stride; \
00238                 w0 = LP(ref+0); \
00239                 w1 = LP(ref+4); \
00240                 UNPACK(t2,t3,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
00241                 OP(LP(dest+0),PACK(a0,a1,t2,t3)); \
00242                 a0 = t2; a1 = t3; \
00243                 w0 = LP(ref+8); \
00244                 UNPACK(t2,t3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
00245                 OP(LP(dest+4),PACK(a2,a3,t2,t3)); \
00246                 a2 = t2; a3 = t3; \
00247 if (sz==16) { \
00248                 w1 = LP(ref+12); \
00249                 UNPACK(t2,t3,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
00250                 OP(LP(dest+8),PACK(a4,a5,t2,t3)); \
00251                 a4 = t2; a5 = t3; \
00252                 w0 = LP(ref+16); \
00253                 UNPACK(t2,t3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
00254                 OP(LP(dest+12),PACK(a6,a7,t2,t3)); \
00255                 a6 = t2; a7 = t3; \
00256 } \
00257                 dest+=stride; \
00258         } while(--height); \
00259 }
00260 
00261 #define         DEFFUNC(op,rnd,xy,sz,OP_N,avgfunc) \
00262 static void op##_##rnd##_pixels##sz##_##xy (uint8_t * dest, const uint8_t * ref, \
00263                                 const int stride, int height) \
00264 { \
00265         switch((int)ref&3) { \
00266         case 0:OP_N##0(sz,rnd##_##avgfunc); return; \
00267         case 1:OP_N(1,sz,rnd##_##avgfunc); return; \
00268         case 2:OP_N(2,sz,rnd##_##avgfunc); return; \
00269         case 3:OP_N(3,sz,rnd##_##avgfunc); return; \
00270         } \
00271 }
00272 
00273 #define OP put
00274 
00275 DEFFUNC(put,   rnd,o,8,OP_C,avg32)
00276 DEFFUNC(put,   rnd,x,8,OP_X,avg32)
00277 DEFFUNC(put,no_rnd,x,8,OP_X,avg32)
00278 DEFFUNC(put,   rnd,y,8,OP_Y,avg32)
00279 DEFFUNC(put,no_rnd,y,8,OP_Y,avg32)
00280 DEFFUNC(put,   rnd,xy,8,OP_XY,PACK)
00281 DEFFUNC(put,no_rnd,xy,8,OP_XY,PACK)
00282 DEFFUNC(put,   rnd,o,16,OP_C,avg32)
00283 DEFFUNC(put,   rnd,x,16,OP_X,avg32)
00284 DEFFUNC(put,no_rnd,x,16,OP_X,avg32)
00285 DEFFUNC(put,   rnd,y,16,OP_Y,avg32)
00286 DEFFUNC(put,no_rnd,y,16,OP_Y,avg32)
00287 DEFFUNC(put,   rnd,xy,16,OP_XY,PACK)
00288 DEFFUNC(put,no_rnd,xy,16,OP_XY,PACK)
00289 
00290 #undef OP
00291 #define OP avg
00292 
00293 DEFFUNC(avg,   rnd,o,8,OP_C,avg32)
00294 DEFFUNC(avg,   rnd,x,8,OP_X,avg32)
00295 DEFFUNC(avg,no_rnd,x,8,OP_X,avg32)
00296 DEFFUNC(avg,   rnd,y,8,OP_Y,avg32)
00297 DEFFUNC(avg,no_rnd,y,8,OP_Y,avg32)
00298 DEFFUNC(avg,   rnd,xy,8,OP_XY,PACK)
00299 DEFFUNC(avg,no_rnd,xy,8,OP_XY,PACK)
00300 DEFFUNC(avg,   rnd,o,16,OP_C,avg32)
00301 DEFFUNC(avg,   rnd,x,16,OP_X,avg32)
00302 DEFFUNC(avg,no_rnd,x,16,OP_X,avg32)
00303 DEFFUNC(avg,   rnd,y,16,OP_Y,avg32)
00304 DEFFUNC(avg,no_rnd,y,16,OP_Y,avg32)
00305 DEFFUNC(avg,   rnd,xy,16,OP_XY,PACK)
00306 DEFFUNC(avg,no_rnd,xy,16,OP_XY,PACK)
00307 
00308 #undef OP
00309 
00310 #define         put_no_rnd_pixels8_o     put_rnd_pixels8_o
00311 #define         put_no_rnd_pixels16_o    put_rnd_pixels16_o
00312 #define         avg_no_rnd_pixels8_o     avg_rnd_pixels8_o
00313 #define         avg_no_rnd_pixels16_o    avg_rnd_pixels16_o
00314 
00315 #define         put_pixels8_c            put_rnd_pixels8_o
00316 #define         put_pixels16_c           put_rnd_pixels16_o
00317 #define         avg_pixels8_c            avg_rnd_pixels8_o
00318 #define         avg_pixels16_c           avg_rnd_pixels16_o
00319 #define         put_no_rnd_pixels8_c     put_rnd_pixels8_o
00320 #define         put_no_rnd_pixels16_c    put_rnd_pixels16_o
00321 #define         avg_no_rnd_pixels8_c     avg_rnd_pixels8_o
00322 #define         avg_no_rnd_pixels16_c    avg_rnd_pixels16_o
00323 
00324 #define         QPEL
00325 
00326 #ifdef QPEL
00327 
00328 #include "qpel.c"
00329 
00330 #endif
00331 
00332 void dsputil_init_align(DSPContext* c, AVCodecContext *avctx)
00333 {
00334         c->put_pixels_tab[0][0] = put_rnd_pixels16_o;
00335         c->put_pixels_tab[0][1] = put_rnd_pixels16_x;
00336         c->put_pixels_tab[0][2] = put_rnd_pixels16_y;
00337         c->put_pixels_tab[0][3] = put_rnd_pixels16_xy;
00338         c->put_pixels_tab[1][0] = put_rnd_pixels8_o;
00339         c->put_pixels_tab[1][1] = put_rnd_pixels8_x;
00340         c->put_pixels_tab[1][2] = put_rnd_pixels8_y;
00341         c->put_pixels_tab[1][3] = put_rnd_pixels8_xy;
00342 
00343         c->put_no_rnd_pixels_tab[0][0] = put_no_rnd_pixels16_o;
00344         c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x;
00345         c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y;
00346         c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy;
00347         c->put_no_rnd_pixels_tab[1][0] = put_no_rnd_pixels8_o;
00348         c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x;
00349         c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y;
00350         c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy;
00351 
00352         c->avg_pixels_tab[0][0] = avg_rnd_pixels16_o;
00353         c->avg_pixels_tab[0][1] = avg_rnd_pixels16_x;
00354         c->avg_pixels_tab[0][2] = avg_rnd_pixels16_y;
00355         c->avg_pixels_tab[0][3] = avg_rnd_pixels16_xy;
00356         c->avg_pixels_tab[1][0] = avg_rnd_pixels8_o;
00357         c->avg_pixels_tab[1][1] = avg_rnd_pixels8_x;
00358         c->avg_pixels_tab[1][2] = avg_rnd_pixels8_y;
00359         c->avg_pixels_tab[1][3] = avg_rnd_pixels8_xy;
00360 
00361         c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_o;
00362         c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x;
00363         c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y;
00364         c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy;
00365         c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_o;
00366         c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x;
00367         c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y;
00368         c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy;
00369 
00370 #ifdef QPEL
00371 
00372 #define dspfunc(PFX, IDX, NUM) \
00373     c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_sh4; \
00374     c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_sh4; \
00375     c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_sh4; \
00376     c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_sh4; \
00377     c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_sh4; \
00378     c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_sh4; \
00379     c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_sh4; \
00380     c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_sh4; \
00381     c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_sh4; \
00382     c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_sh4; \
00383     c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_sh4; \
00384     c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_sh4; \
00385     c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_sh4; \
00386     c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_sh4; \
00387     c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_sh4; \
00388     c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_sh4
00389 
00390     dspfunc(put_qpel, 0, 16);
00391     dspfunc(put_no_rnd_qpel, 0, 16);
00392 
00393     dspfunc(avg_qpel, 0, 16);
00394     /* dspfunc(avg_no_rnd_qpel, 0, 16); */
00395 
00396     dspfunc(put_qpel, 1, 8);
00397     dspfunc(put_no_rnd_qpel, 1, 8);
00398 
00399     dspfunc(avg_qpel, 1, 8);
00400     /* dspfunc(avg_no_rnd_qpel, 1, 8); */
00401 
00402     dspfunc(put_h264_qpel, 0, 16);
00403     dspfunc(put_h264_qpel, 1, 8);
00404     dspfunc(put_h264_qpel, 2, 4);
00405     dspfunc(avg_h264_qpel, 0, 16);
00406     dspfunc(avg_h264_qpel, 1, 8);
00407     dspfunc(avg_h264_qpel, 2, 4);
00408 
00409 #undef dspfunc
00410     c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_sh4;
00411     c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_sh4;
00412     c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_sh4;
00413     c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_sh4;
00414     c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_sh4;
00415     c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_sh4;
00416 
00417     c->put_mspel_pixels_tab[0]= put_mspel8_mc00_sh4;
00418     c->put_mspel_pixels_tab[1]= put_mspel8_mc10_sh4;
00419     c->put_mspel_pixels_tab[2]= put_mspel8_mc20_sh4;
00420     c->put_mspel_pixels_tab[3]= put_mspel8_mc30_sh4;
00421     c->put_mspel_pixels_tab[4]= put_mspel8_mc02_sh4;
00422     c->put_mspel_pixels_tab[5]= put_mspel8_mc12_sh4;
00423     c->put_mspel_pixels_tab[6]= put_mspel8_mc22_sh4;
00424     c->put_mspel_pixels_tab[7]= put_mspel8_mc32_sh4;
00425 
00426     c->gmc1 = gmc1_c;
00427     c->gmc = gmc_c;
00428 
00429 #endif
00430 }

Generated on Sat Feb 16 2013 09:23:13 for ffmpeg by  doxygen 1.7.1