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

libavcodec/ppc/vp3dsp_altivec.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 David Conrad
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #include "libavcodec/dsputil.h"
00022 #include "util_altivec.h"
00023 #include "types_altivec.h"
00024 #include "dsputil_altivec.h"
00025 
00026 static const vec_s16 constants =
00027     {0, 64277, 60547, 54491, 46341, 36410, 25080, 12785};
00028 static const vec_u8 interleave_high =
00029     {0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29};
00030 
00031 #define IDCT_START \
00032     vec_s16 A, B, C, D, Ad, Bd, Cd, Dd, E, F, G, H;\
00033     vec_s16 Ed, Gd, Add, Bdd, Fd, Hd;\
00034     vec_s16 eight = vec_splat_s16(8);\
00035     vec_u16 four = vec_splat_u16(4);\
00036 \
00037     vec_s16 C1 = vec_splat(constants, 1);\
00038     vec_s16 C2 = vec_splat(constants, 2);\
00039     vec_s16 C3 = vec_splat(constants, 3);\
00040     vec_s16 C4 = vec_splat(constants, 4);\
00041     vec_s16 C5 = vec_splat(constants, 5);\
00042     vec_s16 C6 = vec_splat(constants, 6);\
00043     vec_s16 C7 = vec_splat(constants, 7);\
00044 \
00045     vec_s16 b0 = vec_ld(0x00, block);\
00046     vec_s16 b1 = vec_ld(0x10, block);\
00047     vec_s16 b2 = vec_ld(0x20, block);\
00048     vec_s16 b3 = vec_ld(0x30, block);\
00049     vec_s16 b4 = vec_ld(0x40, block);\
00050     vec_s16 b5 = vec_ld(0x50, block);\
00051     vec_s16 b6 = vec_ld(0x60, block);\
00052     vec_s16 b7 = vec_ld(0x70, block);
00053 
00054 // these functions do (a*C)>>16
00055 // things are tricky because a is signed, but C unsigned.
00056 // M15 is used if C fits in 15 bit unsigned (C6,C7)
00057 // M16 is used if C requires 16 bits unsigned
00058 static inline vec_s16 M15(vec_s16 a, vec_s16 C)
00059 {
00060     return (vec_s16)vec_perm(vec_mule(a,C), vec_mulo(a,C), interleave_high);
00061 }
00062 static inline vec_s16 M16(vec_s16 a, vec_s16 C)
00063 {
00064     return vec_add(a, M15(a, C));
00065 }
00066 
00067 #define IDCT_1D(ADD, SHIFT)\
00068     A = vec_add(M16(b1, C1), M15(b7, C7));\
00069     B = vec_sub(M15(b1, C7), M16(b7, C1));\
00070     C = vec_add(M16(b3, C3), M16(b5, C5));\
00071     D = vec_sub(M16(b5, C3), M16(b3, C5));\
00072 \
00073     Ad = M16(vec_sub(A, C), C4);\
00074     Bd = M16(vec_sub(B, D), C4);\
00075 \
00076     Cd = vec_add(A, C);\
00077     Dd = vec_add(B, D);\
00078 \
00079     E = ADD(M16(vec_add(b0, b4), C4));\
00080     F = ADD(M16(vec_sub(b0, b4), C4));\
00081 \
00082     G = vec_add(M16(b2, C2), M15(b6, C6));\
00083     H = vec_sub(M15(b2, C6), M16(b6, C2));\
00084 \
00085     Ed = vec_sub(E, G);\
00086     Gd = vec_add(E, G);\
00087 \
00088     Add = vec_add(F, Ad);\
00089     Bdd = vec_sub(Bd, H);\
00090 \
00091     Fd = vec_sub(F, Ad);\
00092     Hd = vec_add(Bd, H);\
00093 \
00094     b0 = SHIFT(vec_add(Gd, Cd));\
00095     b7 = SHIFT(vec_sub(Gd, Cd));\
00096 \
00097     b1 = SHIFT(vec_add(Add, Hd));\
00098     b2 = SHIFT(vec_sub(Add, Hd));\
00099 \
00100     b3 = SHIFT(vec_add(Ed, Dd));\
00101     b4 = SHIFT(vec_sub(Ed, Dd));\
00102 \
00103     b5 = SHIFT(vec_add(Fd, Bdd));\
00104     b6 = SHIFT(vec_sub(Fd, Bdd));
00105 
00106 #define NOP(a) a
00107 #define ADD8(a) vec_add(a, eight)
00108 #define SHIFT4(a) vec_sra(a, four)
00109 
00110 void ff_vp3_idct_altivec(DCTELEM block[64])
00111 {
00112     IDCT_START
00113 
00114     IDCT_1D(NOP, NOP)
00115     TRANSPOSE8(b0, b1, b2, b3, b4, b5, b6, b7);
00116     IDCT_1D(ADD8, SHIFT4)
00117 
00118     vec_st(b0, 0x00, block);
00119     vec_st(b1, 0x10, block);
00120     vec_st(b2, 0x20, block);
00121     vec_st(b3, 0x30, block);
00122     vec_st(b4, 0x40, block);
00123     vec_st(b5, 0x50, block);
00124     vec_st(b6, 0x60, block);
00125     vec_st(b7, 0x70, block);
00126 }
00127 
00128 void ff_vp3_idct_put_altivec(uint8_t *dst, int stride, DCTELEM block[64])
00129 {
00130     vec_u8 t;
00131     IDCT_START
00132 
00133     // pixels are signed; so add 128*16 in addition to the normal 8
00134     vec_s16 v2048 = vec_sl(vec_splat_s16(1), vec_splat_u16(11));
00135     eight = vec_add(eight, v2048);
00136 
00137     IDCT_1D(NOP, NOP)
00138     TRANSPOSE8(b0, b1, b2, b3, b4, b5, b6, b7);
00139     IDCT_1D(ADD8, SHIFT4)
00140 
00141 #define PUT(a)\
00142     t = vec_packsu(a, a);\
00143     vec_ste((vec_u32)t, 0, (unsigned int *)dst);\
00144     vec_ste((vec_u32)t, 4, (unsigned int *)dst);
00145 
00146     PUT(b0)     dst += stride;
00147     PUT(b1)     dst += stride;
00148     PUT(b2)     dst += stride;
00149     PUT(b3)     dst += stride;
00150     PUT(b4)     dst += stride;
00151     PUT(b5)     dst += stride;
00152     PUT(b6)     dst += stride;
00153     PUT(b7)
00154 }
00155 
00156 void ff_vp3_idct_add_altivec(uint8_t *dst, int stride, DCTELEM block[64])
00157 {
00158     LOAD_ZERO;
00159     vec_u8 t, vdst;
00160     vec_s16 vdst_16;
00161     vec_u8 vdst_mask = vec_mergeh(vec_splat_u8(-1), vec_lvsl(0, dst));
00162 
00163     IDCT_START
00164 
00165     IDCT_1D(NOP, NOP)
00166     TRANSPOSE8(b0, b1, b2, b3, b4, b5, b6, b7);
00167     IDCT_1D(ADD8, SHIFT4)
00168 
00169 #define ADD(a)\
00170     vdst = vec_ld(0, dst);\
00171     vdst_16 = (vec_s16)vec_perm(vdst, zero_u8v, vdst_mask);\
00172     vdst_16 = vec_adds(a, vdst_16);\
00173     t = vec_packsu(vdst_16, vdst_16);\
00174     vec_ste((vec_u32)t, 0, (unsigned int *)dst);\
00175     vec_ste((vec_u32)t, 4, (unsigned int *)dst);
00176 
00177     ADD(b0)     dst += stride;
00178     ADD(b1)     dst += stride;
00179     ADD(b2)     dst += stride;
00180     ADD(b3)     dst += stride;
00181     ADD(b4)     dst += stride;
00182     ADD(b5)     dst += stride;
00183     ADD(b6)     dst += stride;
00184     ADD(b7)
00185 }

Generated on Fri Sep 16 2011 17:17:41 for FFmpeg by  doxygen 1.7.1