aacpsy_mips.h 11.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
/*
 * Copyright (c) 2012
 *      MIPS Technologies, Inc., California.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Author:  Bojan Zivkovic   (bojan@mips.com)
 *
 * AAC encoder psychoacoustic model routines optimized
 * for MIPS floating-point architecture
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/**
 * @file
 * Reference: libavcodec/aacpsy.c
 */

#ifndef AVCODEC_MIPS_AACPSY_MIPS_H
#define AVCODEC_MIPS_AACPSY_MIPS_H

59 60
#include "libavutil/mips/asmdefs.h"

61
#if HAVE_INLINE_ASM && HAVE_MIPSFPU && ( PSY_LAME_FIR_LEN == 21 )
62
#if !HAVE_MIPS32R6 && !HAVE_MIPS64R6
63 64
static void calc_thr_3gpp_mips(const FFPsyWindowInfo *wi, const int num_bands,
                               AacPsyChannel *pch, const uint8_t *band_sizes,
65
                               const float *coefs, const int cutoff)
66 67
{
    int i, w, g;
68
    int start = 0, wstart = 0;
69
    for (w = 0; w < wi->num_windows*16; w += 16) {
70
        wstart = 0;
71 72 73 74 75 76
        for (g = 0; g < num_bands; g++) {
            AacPsyBand *band = &pch->band[w+g];

            float form_factor = 0.0f;
            float Temp;
            band->energy = 0.0f;
77 78 79 80 81
            if (wstart < cutoff) {
                for (i = 0; i < band_sizes[g]; i+=4) {
                    float a, b, c, d;
                    float ax, bx, cx, dx;
                    float *cf = (float *)&coefs[start+i];
82

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
                    __asm__ volatile (
                        "lwc1   %[a],   0(%[cf])                \n\t"
                        "lwc1   %[b],   4(%[cf])                \n\t"
                        "lwc1   %[c],   8(%[cf])                \n\t"
                        "lwc1   %[d],   12(%[cf])               \n\t"
                        "abs.s  %[a],   %[a]                    \n\t"
                        "abs.s  %[b],   %[b]                    \n\t"
                        "abs.s  %[c],   %[c]                    \n\t"
                        "abs.s  %[d],   %[d]                    \n\t"
                        "sqrt.s %[ax],  %[a]                    \n\t"
                        "sqrt.s %[bx],  %[b]                    \n\t"
                        "sqrt.s %[cx],  %[c]                    \n\t"
                        "sqrt.s %[dx],  %[d]                    \n\t"
                        "madd.s %[e],   %[e],   %[a],   %[a]    \n\t"
                        "madd.s %[e],   %[e],   %[b],   %[b]    \n\t"
                        "madd.s %[e],   %[e],   %[c],   %[c]    \n\t"
                        "madd.s %[e],   %[e],   %[d],   %[d]    \n\t"
                        "add.s  %[f],   %[f],   %[ax]           \n\t"
                        "add.s  %[f],   %[f],   %[bx]           \n\t"
                        "add.s  %[f],   %[f],   %[cx]           \n\t"
                        "add.s  %[f],   %[f],   %[dx]           \n\t"
104

105 106 107 108 109 110 111 112 113
                        : [a]"=&f"(a), [b]"=&f"(b),
                          [c]"=&f"(c), [d]"=&f"(d),
                          [e]"+f"(band->energy), [f]"+f"(form_factor),
                          [ax]"=&f"(ax), [bx]"=&f"(bx),
                          [cx]"=&f"(cx), [dx]"=&f"(dx)
                        : [cf]"r"(cf)
                        : "memory"
                    );
                }
114 115 116 117 118 119
            }

            Temp = sqrtf((float)band_sizes[g] / band->energy);
            band->thr      = band->energy * 0.001258925f;
            band->nz_lines = form_factor * sqrtf(Temp);
            start += band_sizes[g];
120
            wstart += band_sizes[g];
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
        }
    }
}

static void psy_hp_filter_mips(const float *firbuf, float *hpfsmpl, const float * psy_fir_coeffs)
{
    float sum1, sum2, sum3, sum4;
    float *fb = (float*)firbuf;
    float *fb_end = fb + AAC_BLOCK_SIZE_LONG;
    float *hp = hpfsmpl;

    float coeff0 = psy_fir_coeffs[1];
    float coeff1 = psy_fir_coeffs[3];
    float coeff2 = psy_fir_coeffs[5];
    float coeff3 = psy_fir_coeffs[7];
    float coeff4 = psy_fir_coeffs[9];

    __asm__ volatile (
        ".set push                                          \n\t"
        ".set noreorder                                     \n\t"

        "li.s   $f12,       32768                           \n\t"
        "1:                                                 \n\t"
        "lwc1   $f0,        40(%[fb])                       \n\t"
        "lwc1   $f1,        4(%[fb])                        \n\t"
        "lwc1   $f2,        80(%[fb])                       \n\t"
        "lwc1   $f3,        44(%[fb])                       \n\t"
        "lwc1   $f4,        8(%[fb])                        \n\t"
        "madd.s %[sum1],    $f0,        $f1,    %[coeff0]   \n\t"
        "lwc1   $f5,        84(%[fb])                       \n\t"
        "lwc1   $f6,        48(%[fb])                       \n\t"
        "madd.s %[sum2],    $f3,        $f4,    %[coeff0]   \n\t"
        "lwc1   $f7,        12(%[fb])                       \n\t"
        "madd.s %[sum1],    %[sum1],    $f2,    %[coeff0]   \n\t"
        "lwc1   $f8,        88(%[fb])                       \n\t"
        "lwc1   $f9,        52(%[fb])                       \n\t"
        "madd.s %[sum2],    %[sum2],    $f5,    %[coeff0]   \n\t"
        "madd.s %[sum3],    $f6,        $f7,    %[coeff0]   \n\t"
        "lwc1   $f10,       16(%[fb])                       \n\t"
        "lwc1   $f11,       92(%[fb])                       \n\t"
        "madd.s %[sum1],    %[sum1],    $f7,    %[coeff1]   \n\t"
        "lwc1   $f1,        72(%[fb])                       \n\t"
        "madd.s %[sum3],    %[sum3],    $f8,    %[coeff0]   \n\t"
        "madd.s %[sum4],    $f9,        $f10,   %[coeff0]   \n\t"
        "madd.s %[sum2],    %[sum2],    $f10,   %[coeff1]   \n\t"
        "madd.s %[sum1],    %[sum1],    $f1,    %[coeff1]   \n\t"
        "lwc1   $f4,        76(%[fb])                       \n\t"
        "lwc1   $f8,        20(%[fb])                       \n\t"
        "madd.s %[sum4],    %[sum4],    $f11,   %[coeff0]   \n\t"
        "lwc1   $f11,       24(%[fb])                       \n\t"
        "madd.s %[sum2],    %[sum2],    $f4,    %[coeff1]   \n\t"
        "madd.s %[sum1],    %[sum1],    $f8,    %[coeff2]   \n\t"
        "madd.s %[sum3],    %[sum3],    $f8,    %[coeff1]   \n\t"
        "madd.s %[sum4],    %[sum4],    $f11,   %[coeff1]   \n\t"
        "lwc1   $f7,        64(%[fb])                       \n\t"
        "madd.s %[sum2],    %[sum2],    $f11,   %[coeff2]   \n\t"
        "lwc1   $f10,       68(%[fb])                       \n\t"
        "madd.s %[sum3],    %[sum3],    $f2,    %[coeff1]   \n\t"
        "madd.s %[sum4],    %[sum4],    $f5,    %[coeff1]   \n\t"
        "madd.s %[sum1],    %[sum1],    $f7,    %[coeff2]   \n\t"
        "madd.s %[sum2],    %[sum2],    $f10,   %[coeff2]   \n\t"
        "lwc1   $f2,        28(%[fb])                       \n\t"
        "lwc1   $f5,        32(%[fb])                       \n\t"
        "lwc1   $f8,        56(%[fb])                       \n\t"
        "lwc1   $f11,       60(%[fb])                       \n\t"
        "madd.s %[sum3],    %[sum3],    $f2,    %[coeff2]   \n\t"
        "madd.s %[sum4],    %[sum4],    $f5,    %[coeff2]   \n\t"
        "madd.s %[sum1],    %[sum1],    $f2,    %[coeff3]   \n\t"
        "madd.s %[sum2],    %[sum2],    $f5,    %[coeff3]   \n\t"
        "madd.s %[sum3],    %[sum3],    $f1,    %[coeff2]   \n\t"
        "madd.s %[sum4],    %[sum4],    $f4,    %[coeff2]   \n\t"
        "madd.s %[sum1],    %[sum1],    $f8,    %[coeff3]   \n\t"
        "madd.s %[sum2],    %[sum2],    $f11,   %[coeff3]   \n\t"
        "lwc1   $f1,        36(%[fb])                       \n\t"
195
        PTR_ADDIU "%[fb],   %[fb],      16                  \n\t"
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
        "madd.s %[sum4],    %[sum4],    $f0,    %[coeff3]   \n\t"
        "madd.s %[sum3],    %[sum3],    $f1,    %[coeff3]   \n\t"
        "madd.s %[sum1],    %[sum1],    $f1,    %[coeff4]   \n\t"
        "madd.s %[sum2],    %[sum2],    $f0,    %[coeff4]   \n\t"
        "madd.s %[sum4],    %[sum4],    $f10,   %[coeff3]   \n\t"
        "madd.s %[sum3],    %[sum3],    $f7,    %[coeff3]   \n\t"
        "madd.s %[sum1],    %[sum1],    $f6,    %[coeff4]   \n\t"
        "madd.s %[sum2],    %[sum2],    $f9,    %[coeff4]   \n\t"
        "madd.s %[sum4],    %[sum4],    $f6,    %[coeff4]   \n\t"
        "madd.s %[sum3],    %[sum3],    $f3,    %[coeff4]   \n\t"
        "mul.s  %[sum1],    %[sum1],    $f12                \n\t"
        "mul.s  %[sum2],    %[sum2],    $f12                \n\t"
        "madd.s %[sum4],    %[sum4],    $f11,   %[coeff4]   \n\t"
        "madd.s %[sum3],    %[sum3],    $f8,    %[coeff4]   \n\t"
        "swc1   %[sum1],    0(%[hp])                        \n\t"
        "swc1   %[sum2],    4(%[hp])                        \n\t"
        "mul.s  %[sum4],    %[sum4],    $f12                \n\t"
        "mul.s  %[sum3],    %[sum3],    $f12                \n\t"
        "swc1   %[sum4],    12(%[hp])                       \n\t"
        "swc1   %[sum3],    8(%[hp])                        \n\t"
        "bne    %[fb],      %[fb_end],  1b                  \n\t"
217
        PTR_ADDIU "%[hp],   %[hp],      16                  \n\t"
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235

        ".set pop                                           \n\t"

        : [sum1]"=&f"(sum1), [sum2]"=&f"(sum2),
          [sum3]"=&f"(sum3), [sum4]"=&f"(sum4),
          [fb]"+r"(fb), [hp]"+r"(hp)
        : [coeff0]"f"(coeff0), [coeff1]"f"(coeff1),
          [coeff2]"f"(coeff2), [coeff3]"f"(coeff3),
          [coeff4]"f"(coeff4), [fb_end]"r"(fb_end)
        : "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6",
          "$f7", "$f8", "$f9", "$f10", "$f11", "$f12",
          "memory"
    );
}

#define calc_thr_3gpp calc_thr_3gpp_mips
#define psy_hp_filter psy_hp_filter_mips

236
#endif /* !HAVE_MIPS32R6 && !HAVE_MIPS64R6 */
237 238
#endif /* HAVE_INLINE_ASM && HAVE_MIPSFPU */
#endif /* AVCODEC_MIPS_AACPSY_MIPS_H */