compute_antialias_fixed.h 15 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
/*
 * 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)
 *
 * Compute antialias function optimised for MIPS fixed-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/mpegaudiodec.c
 */

#ifndef AVCODEC_MIPS_COMPUTE_ANTIALIAS_FIXED_H
#define AVCODEC_MIPS_COMPUTE_ANTIALIAS_FIXED_H

58
#if HAVE_INLINE_ASM
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
static void compute_antialias_mips_fixed(MPADecodeContext *s,
                                        GranuleDef *g)
{
    int32_t *ptr, *csa;
    int n, i;
    int MAX_lo = 0xffffffff;

    /* we antialias only "long" bands */
    if (g->block_type == 2) {
        if (!g->switch_point)
            return;
        /* XXX: check this for 8000Hz case */
        n = 1;
    } else {
        n = SBLIMIT - 1;
    }


    ptr = g->sb_hybrid + 18;

    for(i = n;i > 0;i--) {
        int tmp0, tmp1, tmp2, tmp00, tmp11;
        int temp_reg1, temp_reg2, temp_reg3, temp_reg4, temp_reg5, temp_reg6;
        csa = &csa_table[0][0];

        /**
         * instructions are scheduled to minimize pipeline stall.
         */
87
        __asm__ volatile (
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
            "lw   %[tmp0],      -1*4(%[ptr])                            \n\t"
            "lw   %[tmp1],      0*4(%[ptr])                             \n\t"
            "lw   %[temp_reg1], 0*4(%[csa])                             \n\t"
            "lw   %[temp_reg2], 2*4(%[csa])                             \n\t"
            "add  %[tmp2],      %[tmp0],      %[tmp1]                   \n\t"
            "lw   %[temp_reg3], 3*4(%[csa])                             \n\t"
            "mult $ac0,         %[tmp2],      %[temp_reg1]              \n\t"
            "mult $ac1,         %[tmp2],      %[temp_reg1]              \n\t"
            "lw   %[tmp00],     -2*4(%[ptr])                            \n\t"
            "lw   %[tmp11],     1*4(%[ptr])                             \n\t"
            "lw   %[temp_reg4], 4*4(%[csa])                             \n\t"
            "mtlo %[MAX_lo],    $ac0                                    \n\t"
            "mtlo $zero,        $ac1                                    \n\t"
            "msub $ac0,         %[tmp1],      %[temp_reg2]              \n\t"
            "madd $ac1,         %[tmp0],      %[temp_reg3]              \n\t"
            "add  %[tmp2],      %[tmp00],     %[tmp11]                  \n\t"
            "lw   %[temp_reg5], 6*4(%[csa])                             \n\t"
            "mult $ac2,         %[tmp2],      %[temp_reg4]              \n\t"
            "mult $ac3,         %[tmp2],      %[temp_reg4]              \n\t"
            "mfhi %[temp_reg1], $ac0                                    \n\t"
            "mfhi %[temp_reg2], $ac1                                    \n\t"
            "lw   %[temp_reg6], 7*4(%[csa])                             \n\t"
            "mtlo %[MAX_lo],    $ac2                                    \n\t"
            "msub $ac2,         %[tmp11],     %[temp_reg5]              \n\t"
            "mtlo $zero,        $ac3                                    \n\t"
            "madd $ac3,         %[tmp00],     %[temp_reg6]              \n\t"
            "sll  %[temp_reg1], %[temp_reg1], 2                         \n\t"
            "sw   %[temp_reg1], -1*4(%[ptr])                            \n\t"
            "mfhi %[temp_reg4], $ac2                                    \n\t"
            "sll  %[temp_reg2], %[temp_reg2], 2                         \n\t"
            "mfhi %[temp_reg5], $ac3                                    \n\t"
            "sw   %[temp_reg2], 0*4(%[ptr])                             \n\t"
            "lw   %[tmp0],      -3*4(%[ptr])                            \n\t"
            "lw   %[tmp1],      2*4(%[ptr])                             \n\t"
            "lw   %[temp_reg1], 8*4(%[csa])                             \n\t"
            "sll  %[temp_reg4], %[temp_reg4], 2                         \n\t"
            "add  %[tmp2],      %[tmp0],      %[tmp1]                   \n\t"
            "sll  %[temp_reg5], %[temp_reg5], 2                         \n\t"
            "mult $ac0,         %[tmp2],      %[temp_reg1]              \n\t"
            "mult $ac1,         %[tmp2],      %[temp_reg1]              \n\t"
            "sw   %[temp_reg4], -2*4(%[ptr])                            \n\t"
            "sw   %[temp_reg5], 1*4(%[ptr])                             \n\t"
            "lw   %[temp_reg2], 10*4(%[csa])                            \n\t"
            "mtlo %[MAX_lo],    $ac0                                    \n\t"
            "lw   %[temp_reg3], 11*4(%[csa])                            \n\t"
            "msub $ac0,         %[tmp1],      %[temp_reg2]              \n\t"
            "mtlo $zero,        $ac1                                    \n\t"
            "madd $ac1,         %[tmp0],      %[temp_reg3]              \n\t"
            "lw   %[tmp00],     -4*4(%[ptr])                            \n\t"
            "lw   %[tmp11],     3*4(%[ptr])                             \n\t"
            "mfhi %[temp_reg1], $ac0                                    \n\t"
            "lw   %[temp_reg4], 12*4(%[csa])                            \n\t"
            "mfhi %[temp_reg2], $ac1                                    \n\t"
            "add  %[tmp2],      %[tmp00],     %[tmp11]                  \n\t"
            "mult $ac2,         %[tmp2],      %[temp_reg4]              \n\t"
            "mult $ac3,         %[tmp2],      %[temp_reg4]              \n\t"
            "lw   %[temp_reg5], 14*4(%[csa])                            \n\t"
            "lw   %[temp_reg6], 15*4(%[csa])                            \n\t"
            "sll  %[temp_reg1], %[temp_reg1], 2                         \n\t"
            "mtlo %[MAX_lo],    $ac2                                    \n\t"
            "msub $ac2,         %[tmp11],     %[temp_reg5]              \n\t"
            "mtlo $zero,        $ac3                                    \n\t"
            "madd $ac3,         %[tmp00],     %[temp_reg6]              \n\t"
            "sll  %[temp_reg2], %[temp_reg2], 2                         \n\t"
            "sw   %[temp_reg1], -3*4(%[ptr])                            \n\t"
            "mfhi %[temp_reg4], $ac2                                    \n\t"
            "sw   %[temp_reg2], 2*4(%[ptr])                             \n\t"
            "mfhi %[temp_reg5], $ac3                                    \n\t"
            "lw   %[tmp0],      -5*4(%[ptr])                            \n\t"
            "lw   %[tmp1],      4*4(%[ptr])                             \n\t"
            "lw   %[temp_reg1], 16*4(%[csa])                            \n\t"
            "lw   %[temp_reg2], 18*4(%[csa])                            \n\t"
            "add  %[tmp2],      %[tmp0],      %[tmp1]                   \n\t"
            "lw   %[temp_reg3], 19*4(%[csa])                            \n\t"
            "mult $ac0,         %[tmp2],      %[temp_reg1]              \n\t"
            "mult $ac1,         %[tmp2],      %[temp_reg1]              \n\t"
            "sll  %[temp_reg4], %[temp_reg4], 2                         \n\t"
            "sll  %[temp_reg5], %[temp_reg5], 2                         \n\t"
            "sw   %[temp_reg4], -4*4(%[ptr])                            \n\t"
            "mtlo %[MAX_lo],    $ac0                                    \n\t"
            "msub $ac0,         %[tmp1],      %[temp_reg2]              \n\t"
            "mtlo $zero,        $ac1                                    \n\t"
            "madd $ac1,         %[tmp0],      %[temp_reg3]              \n\t"
            "sw   %[temp_reg5], 3*4(%[ptr])                             \n\t"
            "lw   %[tmp00],     -6*4(%[ptr])                            \n\t"
            "mfhi %[temp_reg1], $ac0                                    \n\t"
            "lw   %[tmp11],     5*4(%[ptr])                             \n\t"
            "mfhi %[temp_reg2], $ac1                                    \n\t"
            "lw   %[temp_reg4], 20*4(%[csa])                            \n\t"
            "add  %[tmp2],      %[tmp00],     %[tmp11]                  \n\t"
            "lw   %[temp_reg5], 22*4(%[csa])                            \n\t"
            "mult $ac2,         %[tmp2],      %[temp_reg4]              \n\t"
            "mult $ac3,         %[tmp2],      %[temp_reg4]              \n\t"
            "lw   %[temp_reg6], 23*4(%[csa])                            \n\t"
            "sll  %[temp_reg1], %[temp_reg1], 2                         \n\t"
            "sll  %[temp_reg2], %[temp_reg2], 2                         \n\t"
            "mtlo %[MAX_lo],    $ac2                                    \n\t"
            "msub $ac2,         %[tmp11],     %[temp_reg5]              \n\t"
            "mtlo $zero,        $ac3                                    \n\t"
            "madd $ac3,         %[tmp00],     %[temp_reg6]              \n\t"
            "sw   %[temp_reg1], -5*4(%[ptr])                            \n\t"
            "sw   %[temp_reg2], 4*4(%[ptr])                             \n\t"
            "mfhi %[temp_reg4], $ac2                                    \n\t"
            "lw   %[tmp0],      -7*4(%[ptr])                            \n\t"
            "mfhi %[temp_reg5], $ac3                                    \n\t"
            "lw   %[tmp1],      6*4(%[ptr])                             \n\t"
            "lw   %[temp_reg1], 24*4(%[csa])                            \n\t"
            "lw   %[temp_reg2], 26*4(%[csa])                            \n\t"
            "add  %[tmp2],      %[tmp0],      %[tmp1]                   \n\t"
            "lw   %[temp_reg3], 27*4(%[csa])                            \n\t"
            "mult $ac0,         %[tmp2],      %[temp_reg1]              \n\t"
            "mult $ac1,         %[tmp2],      %[temp_reg1]              \n\t"
            "sll  %[temp_reg4], %[temp_reg4], 2                         \n\t"
            "sll  %[temp_reg5], %[temp_reg5], 2                         \n\t"
            "sw   %[temp_reg4], -6*4(%[ptr])                            \n\t"
            "mtlo %[MAX_lo],    $ac0                                    \n\t"
            "msub $ac0,         %[tmp1],      %[temp_reg2]              \n\t"
            "mtlo $zero,        $ac1                                    \n\t"
            "madd $ac1,         %[tmp0],      %[temp_reg3]              \n\t"
            "sw   %[temp_reg5], 5*4(%[ptr])                             \n\t"
            "lw   %[tmp00],     -8*4(%[ptr])                            \n\t"
            "mfhi %[temp_reg1], $ac0                                    \n\t"
            "lw   %[tmp11],     7*4(%[ptr])                             \n\t"
            "mfhi %[temp_reg2], $ac1                                    \n\t"
            "lw   %[temp_reg4], 28*4(%[csa])                            \n\t"
            "add  %[tmp2],      %[tmp00],     %[tmp11]                  \n\t"
            "lw   %[temp_reg5], 30*4(%[csa])                            \n\t"
            "mult $ac2,         %[tmp2],      %[temp_reg4]              \n\t"
            "mult $ac3,         %[tmp2],      %[temp_reg4]              \n\t"
            "lw   %[temp_reg6], 31*4(%[csa])                            \n\t"
            "sll  %[temp_reg1], %[temp_reg1], 2                         \n\t"
            "sll  %[temp_reg2], %[temp_reg2], 2                         \n\t"
            "mtlo %[MAX_lo],    $ac2                                    \n\t"
            "msub $ac2,         %[tmp11],     %[temp_reg5]              \n\t"
            "mtlo $zero,        $ac3                                    \n\t"
            "madd $ac3,         %[tmp00],     %[temp_reg6]              \n\t"
            "sw   %[temp_reg1], -7*4(%[ptr])                            \n\t"
            "sw   %[temp_reg2], 6*4(%[ptr])                             \n\t"
            "mfhi %[temp_reg4], $ac2                                    \n\t"
            "mfhi %[temp_reg5], $ac3                                    \n\t"
            "sll  %[temp_reg4], %[temp_reg4], 2                         \n\t"
            "sll  %[temp_reg5], %[temp_reg5], 2                         \n\t"
            "sw   %[temp_reg4], -8*4(%[ptr])                            \n\t"
            "sw   %[temp_reg5], 7*4(%[ptr])                             \n\t"

            : [tmp0] "=&r" (tmp0), [tmp1] "=&r" (tmp1), [tmp2] "=&r" (tmp2),
              [tmp00] "=&r" (tmp00), [tmp11] "=&r" (tmp11),
              [temp_reg1] "=&r" (temp_reg1), [temp_reg2] "=&r" (temp_reg2),
              [temp_reg3] "=&r" (temp_reg3), [temp_reg4] "=&r" (temp_reg4),
              [temp_reg5] "=&r" (temp_reg5), [temp_reg6] "=&r" (temp_reg6)
            : [csa] "r" (csa), [ptr] "r" (ptr),
              [MAX_lo] "r" (MAX_lo)
240 241
            : "memory", "hi", "lo", "$ac1hi", "$ac1lo", "$ac2hi", "$ac2lo",
              "$ac3hi", "$ac3lo"
242 243 244 245 246 247
         );

        ptr += 18;
    }
}
#define compute_antialias compute_antialias_mips_fixed
248
#endif /* HAVE_INLINE_ASM */
249 250

#endif /* AVCODEC_MIPS_COMPUTE_ANTIALIAS_FIXED_H */