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

libavcodec/ppc/fmtconvert_altivec.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006 Luca Barbato <lu_zero@gentoo.org>
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/fmtconvert.h"
00022 
00023 #include "dsputil_altivec.h"
00024 #include "util_altivec.h"
00025 
00026 static void int32_to_float_fmul_scalar_altivec(float *dst, const int *src, float mul, int len)
00027 {
00028     union {
00029         vector float v;
00030         float s[4];
00031     } mul_u;
00032     int i;
00033     vector float src1, src2, dst1, dst2, mul_v, zero;
00034 
00035     zero = (vector float)vec_splat_u32(0);
00036     mul_u.s[0] = mul;
00037     mul_v = vec_splat(mul_u.v, 0);
00038 
00039     for(i=0; i<len; i+=8) {
00040         src1 = vec_ctf(vec_ld(0,  src+i), 0);
00041         src2 = vec_ctf(vec_ld(16, src+i), 0);
00042         dst1 = vec_madd(src1, mul_v, zero);
00043         dst2 = vec_madd(src2, mul_v, zero);
00044         vec_st(dst1,  0, dst+i);
00045         vec_st(dst2, 16, dst+i);
00046     }
00047 }
00048 
00049 
00050 static vector signed short
00051 float_to_int16_one_altivec(const float *src)
00052 {
00053     vector float s0 = vec_ld(0, src);
00054     vector float s1 = vec_ld(16, src);
00055     vector signed int t0 = vec_cts(s0, 0);
00056     vector signed int t1 = vec_cts(s1, 0);
00057     return vec_packs(t0,t1);
00058 }
00059 
00060 static void float_to_int16_altivec(int16_t *dst, const float *src, long len)
00061 {
00062     int i;
00063     vector signed short d0, d1, d;
00064     vector unsigned char align;
00065     if(((long)dst)&15) //FIXME
00066     for(i=0; i<len-7; i+=8) {
00067         d0 = vec_ld(0, dst+i);
00068         d = float_to_int16_one_altivec(src+i);
00069         d1 = vec_ld(15, dst+i);
00070         d1 = vec_perm(d1, d0, vec_lvsl(0,dst+i));
00071         align = vec_lvsr(0, dst+i);
00072         d0 = vec_perm(d1, d, align);
00073         d1 = vec_perm(d, d1, align);
00074         vec_st(d0, 0, dst+i);
00075         vec_st(d1,15, dst+i);
00076     }
00077     else
00078     for(i=0; i<len-7; i+=8) {
00079         d = float_to_int16_one_altivec(src+i);
00080         vec_st(d, 0, dst+i);
00081     }
00082 }
00083 
00084 static void
00085 float_to_int16_interleave_altivec(int16_t *dst, const float **src,
00086                                   long len, int channels)
00087 {
00088     int i;
00089     vector signed short d0, d1, d2, c0, c1, t0, t1;
00090     vector unsigned char align;
00091     if(channels == 1)
00092         float_to_int16_altivec(dst, src[0], len);
00093     else
00094         if (channels == 2) {
00095         if(((long)dst)&15)
00096         for(i=0; i<len-7; i+=8) {
00097             d0 = vec_ld(0, dst + i);
00098             t0 = float_to_int16_one_altivec(src[0] + i);
00099             d1 = vec_ld(31, dst + i);
00100             t1 = float_to_int16_one_altivec(src[1] + i);
00101             c0 = vec_mergeh(t0, t1);
00102             c1 = vec_mergel(t0, t1);
00103             d2 = vec_perm(d1, d0, vec_lvsl(0, dst + i));
00104             align = vec_lvsr(0, dst + i);
00105             d0 = vec_perm(d2, c0, align);
00106             d1 = vec_perm(c0, c1, align);
00107             vec_st(d0,  0, dst + i);
00108             d0 = vec_perm(c1, d2, align);
00109             vec_st(d1, 15, dst + i);
00110             vec_st(d0, 31, dst + i);
00111             dst+=8;
00112         }
00113         else
00114         for(i=0; i<len-7; i+=8) {
00115             t0 = float_to_int16_one_altivec(src[0] + i);
00116             t1 = float_to_int16_one_altivec(src[1] + i);
00117             d0 = vec_mergeh(t0, t1);
00118             d1 = vec_mergel(t0, t1);
00119             vec_st(d0,  0, dst + i);
00120             vec_st(d1, 16, dst + i);
00121             dst+=8;
00122         }
00123     } else {
00124         DECLARE_ALIGNED(16, int16_t, tmp)[len];
00125         int c, j;
00126         for (c = 0; c < channels; c++) {
00127             float_to_int16_altivec(tmp, src[c], len);
00128             for (i = 0, j = c; i < len; i++, j+=channels) {
00129                 dst[j] = tmp[i];
00130             }
00131         }
00132    }
00133 }
00134 
00135 void ff_fmt_convert_init_altivec(FmtConvertContext *c, AVCodecContext *avctx)
00136 {
00137     c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_altivec;
00138     if(!(avctx->flags & CODEC_FLAG_BITEXACT)) {
00139         c->float_to_int16 = float_to_int16_altivec;
00140         c->float_to_int16_interleave = float_to_int16_interleave_altivec;
00141     }
00142 }
Generated on Fri Feb 1 2013 14:34:41 for FFmpeg by doxygen 1.7.1