diff libavcodec/ppc/idct_altivec.c @ 2:897f711a7157

rearrange to work with autoconf
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Tue, 25 Sep 2012 15:55:33 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libavcodec/ppc/idct_altivec.c	Tue Sep 25 15:55:33 2012 +0200
     1.3 @@ -0,0 +1,232 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001 Michel Lespinasse
     1.6 + *
     1.7 + * This file is part of FFmpeg.
     1.8 + *
     1.9 + * FFmpeg is free software; you can redistribute it and/or
    1.10 + * modify it under the terms of the GNU Lesser General Public
    1.11 + * License as published by the Free Software Foundation; either
    1.12 + * version 2.1 of the License, or (at your option) any later version.
    1.13 + *
    1.14 + * FFmpeg is distributed in the hope that it will be useful,
    1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.17 + * Lesser General Public License for more details.
    1.18 + *
    1.19 + * You should have received a copy of the GNU Lesser General Public
    1.20 + * License along with FFmpeg; if not, write to the Free Software
    1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
    1.22 + */
    1.23 +
    1.24 +/*
    1.25 + * NOTE: This code is based on GPL code from the libmpeg2 project.  The
    1.26 + * author, Michel Lespinasses, has given explicit permission to release
    1.27 + * under LGPL as part of FFmpeg.
    1.28 + */
    1.29 +
    1.30 +/*
    1.31 + * FFmpeg integration by Dieter Shirley
    1.32 + *
    1.33 + * This file is a direct copy of the AltiVec IDCT module from the libmpeg2
    1.34 + * project.  I've deleted all of the libmpeg2-specific code, renamed the
    1.35 + * functions and reordered the function parameters.  The only change to the
    1.36 + * IDCT function itself was to factor out the partial transposition, and to
    1.37 + * perform a full transpose at the end of the function.
    1.38 + */
    1.39 +
    1.40 +
    1.41 +#include <stdlib.h>                                      /* malloc(), free() */
    1.42 +#include <string.h>
    1.43 +#include "config.h"
    1.44 +#if HAVE_ALTIVEC_H
    1.45 +#include <altivec.h>
    1.46 +#endif
    1.47 +#include "libavcodec/dsputil.h"
    1.48 +#include "types_altivec.h"
    1.49 +#include "dsputil_ppc.h"
    1.50 +#include "dsputil_altivec.h"
    1.51 +
    1.52 +#define IDCT_HALF                                       \
    1.53 +    /* 1st stage */                                     \
    1.54 +    t1 = vec_mradds (a1, vx7, vx1 );                    \
    1.55 +    t8 = vec_mradds (a1, vx1, vec_subs (zero, vx7));    \
    1.56 +    t7 = vec_mradds (a2, vx5, vx3);                     \
    1.57 +    t3 = vec_mradds (ma2, vx3, vx5);                    \
    1.58 +                                                        \
    1.59 +    /* 2nd stage */                                     \
    1.60 +    t5 = vec_adds (vx0, vx4);                           \
    1.61 +    t0 = vec_subs (vx0, vx4);                           \
    1.62 +    t2 = vec_mradds (a0, vx6, vx2);                     \
    1.63 +    t4 = vec_mradds (a0, vx2, vec_subs (zero, vx6));    \
    1.64 +    t6 = vec_adds (t8, t3);                             \
    1.65 +    t3 = vec_subs (t8, t3);                             \
    1.66 +    t8 = vec_subs (t1, t7);                             \
    1.67 +    t1 = vec_adds (t1, t7);                             \
    1.68 +                                                        \
    1.69 +    /* 3rd stage */                                     \
    1.70 +    t7 = vec_adds (t5, t2);                             \
    1.71 +    t2 = vec_subs (t5, t2);                             \
    1.72 +    t5 = vec_adds (t0, t4);                             \
    1.73 +    t0 = vec_subs (t0, t4);                             \
    1.74 +    t4 = vec_subs (t8, t3);                             \
    1.75 +    t3 = vec_adds (t8, t3);                             \
    1.76 +                                                        \
    1.77 +    /* 4th stage */                                     \
    1.78 +    vy0 = vec_adds (t7, t1);                            \
    1.79 +    vy7 = vec_subs (t7, t1);                            \
    1.80 +    vy1 = vec_mradds (c4, t3, t5);                      \
    1.81 +    vy6 = vec_mradds (mc4, t3, t5);                     \
    1.82 +    vy2 = vec_mradds (c4, t4, t0);                      \
    1.83 +    vy5 = vec_mradds (mc4, t4, t0);                     \
    1.84 +    vy3 = vec_adds (t2, t6);                            \
    1.85 +    vy4 = vec_subs (t2, t6);
    1.86 +
    1.87 +
    1.88 +#define IDCT                                                            \
    1.89 +    vec_s16 vx0, vx1, vx2, vx3, vx4, vx5, vx6, vx7;                \
    1.90 +    vec_s16 vy0, vy1, vy2, vy3, vy4, vy5, vy6, vy7;                \
    1.91 +    vec_s16 a0, a1, a2, ma2, c4, mc4, zero, bias;                  \
    1.92 +    vec_s16 t0, t1, t2, t3, t4, t5, t6, t7, t8;                    \
    1.93 +    vec_u16 shift;                                                 \
    1.94 +                                                                        \
    1.95 +    c4 = vec_splat (constants[0], 0);                                   \
    1.96 +    a0 = vec_splat (constants[0], 1);                                   \
    1.97 +    a1 = vec_splat (constants[0], 2);                                   \
    1.98 +    a2 = vec_splat (constants[0], 3);                                   \
    1.99 +    mc4 = vec_splat (constants[0], 4);                                  \
   1.100 +    ma2 = vec_splat (constants[0], 5);                                  \
   1.101 +    bias = (vec_s16)vec_splat ((vec_s32)constants[0], 3);     \
   1.102 +                                                                        \
   1.103 +    zero = vec_splat_s16 (0);                                           \
   1.104 +    shift = vec_splat_u16 (4);                                          \
   1.105 +                                                                        \
   1.106 +    vx0 = vec_mradds (vec_sl (block[0], shift), constants[1], zero);    \
   1.107 +    vx1 = vec_mradds (vec_sl (block[1], shift), constants[2], zero);    \
   1.108 +    vx2 = vec_mradds (vec_sl (block[2], shift), constants[3], zero);    \
   1.109 +    vx3 = vec_mradds (vec_sl (block[3], shift), constants[4], zero);    \
   1.110 +    vx4 = vec_mradds (vec_sl (block[4], shift), constants[1], zero);    \
   1.111 +    vx5 = vec_mradds (vec_sl (block[5], shift), constants[4], zero);    \
   1.112 +    vx6 = vec_mradds (vec_sl (block[6], shift), constants[3], zero);    \
   1.113 +    vx7 = vec_mradds (vec_sl (block[7], shift), constants[2], zero);    \
   1.114 +                                                                        \
   1.115 +    IDCT_HALF                                                           \
   1.116 +                                                                        \
   1.117 +    vx0 = vec_mergeh (vy0, vy4);                                        \
   1.118 +    vx1 = vec_mergel (vy0, vy4);                                        \
   1.119 +    vx2 = vec_mergeh (vy1, vy5);                                        \
   1.120 +    vx3 = vec_mergel (vy1, vy5);                                        \
   1.121 +    vx4 = vec_mergeh (vy2, vy6);                                        \
   1.122 +    vx5 = vec_mergel (vy2, vy6);                                        \
   1.123 +    vx6 = vec_mergeh (vy3, vy7);                                        \
   1.124 +    vx7 = vec_mergel (vy3, vy7);                                        \
   1.125 +                                                                        \
   1.126 +    vy0 = vec_mergeh (vx0, vx4);                                        \
   1.127 +    vy1 = vec_mergel (vx0, vx4);                                        \
   1.128 +    vy2 = vec_mergeh (vx1, vx5);                                        \
   1.129 +    vy3 = vec_mergel (vx1, vx5);                                        \
   1.130 +    vy4 = vec_mergeh (vx2, vx6);                                        \
   1.131 +    vy5 = vec_mergel (vx2, vx6);                                        \
   1.132 +    vy6 = vec_mergeh (vx3, vx7);                                        \
   1.133 +    vy7 = vec_mergel (vx3, vx7);                                        \
   1.134 +                                                                        \
   1.135 +    vx0 = vec_adds (vec_mergeh (vy0, vy4), bias);                       \
   1.136 +    vx1 = vec_mergel (vy0, vy4);                                        \
   1.137 +    vx2 = vec_mergeh (vy1, vy5);                                        \
   1.138 +    vx3 = vec_mergel (vy1, vy5);                                        \
   1.139 +    vx4 = vec_mergeh (vy2, vy6);                                        \
   1.140 +    vx5 = vec_mergel (vy2, vy6);                                        \
   1.141 +    vx6 = vec_mergeh (vy3, vy7);                                        \
   1.142 +    vx7 = vec_mergel (vy3, vy7);                                        \
   1.143 +                                                                        \
   1.144 +    IDCT_HALF                                                           \
   1.145 +                                                                        \
   1.146 +    shift = vec_splat_u16 (6);                                          \
   1.147 +    vx0 = vec_sra (vy0, shift);                                         \
   1.148 +    vx1 = vec_sra (vy1, shift);                                         \
   1.149 +    vx2 = vec_sra (vy2, shift);                                         \
   1.150 +    vx3 = vec_sra (vy3, shift);                                         \
   1.151 +    vx4 = vec_sra (vy4, shift);                                         \
   1.152 +    vx5 = vec_sra (vy5, shift);                                         \
   1.153 +    vx6 = vec_sra (vy6, shift);                                         \
   1.154 +    vx7 = vec_sra (vy7, shift);
   1.155 +
   1.156 +
   1.157 +static const vec_s16 constants[5] = {
   1.158 +    {23170, 13573,  6518, 21895, -23170, -21895,    32,    31},
   1.159 +    {16384, 22725, 21407, 19266,  16384,  19266, 21407, 22725},
   1.160 +    {22725, 31521, 29692, 26722,  22725,  26722, 29692, 31521},
   1.161 +    {21407, 29692, 27969, 25172,  21407,  25172, 27969, 29692},
   1.162 +    {19266, 26722, 25172, 22654,  19266,  22654, 25172, 26722}
   1.163 +};
   1.164 +
   1.165 +void idct_put_altivec(uint8_t* dest, int stride, int16_t *blk)
   1.166 +{
   1.167 +POWERPC_PERF_DECLARE(altivec_idct_put_num, 1);
   1.168 +    vec_s16 *block = (vec_s16*)blk;
   1.169 +    vec_u8 tmp;
   1.170 +
   1.171 +#if CONFIG_POWERPC_PERF
   1.172 +POWERPC_PERF_START_COUNT(altivec_idct_put_num, 1);
   1.173 +#endif
   1.174 +    IDCT
   1.175 +
   1.176 +#define COPY(dest,src)                                          \
   1.177 +    tmp = vec_packsu (src, src);                                \
   1.178 +    vec_ste ((vec_u32)tmp, 0, (unsigned int *)dest);       \
   1.179 +    vec_ste ((vec_u32)tmp, 4, (unsigned int *)dest);
   1.180 +
   1.181 +    COPY (dest, vx0)    dest += stride;
   1.182 +    COPY (dest, vx1)    dest += stride;
   1.183 +    COPY (dest, vx2)    dest += stride;
   1.184 +    COPY (dest, vx3)    dest += stride;
   1.185 +    COPY (dest, vx4)    dest += stride;
   1.186 +    COPY (dest, vx5)    dest += stride;
   1.187 +    COPY (dest, vx6)    dest += stride;
   1.188 +    COPY (dest, vx7)
   1.189 +
   1.190 +POWERPC_PERF_STOP_COUNT(altivec_idct_put_num, 1);
   1.191 +}
   1.192 +
   1.193 +void idct_add_altivec(uint8_t* dest, int stride, int16_t *blk)
   1.194 +{
   1.195 +POWERPC_PERF_DECLARE(altivec_idct_add_num, 1);
   1.196 +    vec_s16 *block = (vec_s16*)blk;
   1.197 +    vec_u8 tmp;
   1.198 +    vec_s16 tmp2, tmp3;
   1.199 +    vec_u8 perm0;
   1.200 +    vec_u8 perm1;
   1.201 +    vec_u8 p0, p1, p;
   1.202 +
   1.203 +#if CONFIG_POWERPC_PERF
   1.204 +POWERPC_PERF_START_COUNT(altivec_idct_add_num, 1);
   1.205 +#endif
   1.206 +
   1.207 +    IDCT
   1.208 +
   1.209 +    p0 = vec_lvsl (0, dest);
   1.210 +    p1 = vec_lvsl (stride, dest);
   1.211 +    p = vec_splat_u8 (-1);
   1.212 +    perm0 = vec_mergeh (p, p0);
   1.213 +    perm1 = vec_mergeh (p, p1);
   1.214 +
   1.215 +#define ADD(dest,src,perm)                                              \
   1.216 +    /* *(uint64_t *)&tmp = *(uint64_t *)dest; */                        \
   1.217 +    tmp = vec_ld (0, dest);                                             \
   1.218 +    tmp2 = (vec_s16)vec_perm (tmp, (vec_u8)zero, perm);       \
   1.219 +    tmp3 = vec_adds (tmp2, src);                                        \
   1.220 +    tmp = vec_packsu (tmp3, tmp3);                                      \
   1.221 +    vec_ste ((vec_u32)tmp, 0, (unsigned int *)dest);               \
   1.222 +    vec_ste ((vec_u32)tmp, 4, (unsigned int *)dest);
   1.223 +
   1.224 +    ADD (dest, vx0, perm0)      dest += stride;
   1.225 +    ADD (dest, vx1, perm1)      dest += stride;
   1.226 +    ADD (dest, vx2, perm0)      dest += stride;
   1.227 +    ADD (dest, vx3, perm1)      dest += stride;
   1.228 +    ADD (dest, vx4, perm0)      dest += stride;
   1.229 +    ADD (dest, vx5, perm1)      dest += stride;
   1.230 +    ADD (dest, vx6, perm0)      dest += stride;
   1.231 +    ADD (dest, vx7, perm1)
   1.232 +
   1.233 +POWERPC_PERF_STOP_COUNT(altivec_idct_add_num, 1);
   1.234 +}
   1.235 +