mpegvideo_mmi.c 26.1 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
/*
 * Loongson SIMD optimized mpegvideo
 *
 * Copyright (c) 2015 Loongson Technology Corporation Limited
 * Copyright (c) 2015 Zhou Xiaoyong <zhouxiaoyong@loongson.cn>
 *                    Zhang Shuangshuang <zhangshuangshuang@ict.ac.cn>
 *
 * 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
 */

#include "mpegvideo_mips.h"
26
#include "libavutil/mips/mmiutils.h"
27 28 29 30 31

void ff_dct_unquantize_h263_intra_mmi(MpegEncContext *s, int16_t *block,
        int n, int qscale)
{
    int64_t level, qmul, qadd, nCoeffs;
32 33
    double ftmp[6];
    mips_reg addr[1];
34
    DECLARE_VAR_ALL64;
35 36

    qmul = qscale << 1;
37
    av_assert2(s->block_last_index[n]>=0 || s->h263_aic);
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

    if (!s->h263_aic) {
        if (n<4)
            level = block[0] * s->y_dc_scale;
        else
            level = block[0] * s->c_dc_scale;
        qadd = (qscale-1) | 1;
    } else {
        qadd = 0;
        level = block[0];
    }

    if(s->ac_pred)
        nCoeffs = 63;
    else
        nCoeffs = s->inter_scantable.raster_end[s->block_last_index[n]];

    __asm__ volatile (
56 57 58 59 60 61 62 63
        "xor        %[ftmp0],   %[ftmp0],       %[ftmp0]                \n\t"
        "packsswh   %[qmul],    %[qmul],        %[qmul]                 \n\t"
        "packsswh   %[qmul],    %[qmul],        %[qmul]                 \n\t"
        "packsswh   %[qadd],    %[qadd],        %[qadd]                 \n\t"
        "packsswh   %[qadd],    %[qadd],        %[qadd]                 \n\t"
        "psubh      %[ftmp0],   %[ftmp0],       %[qadd]                 \n\t"
        "xor        %[ftmp5],   %[ftmp5],       %[ftmp5]                \n\t"
        ".p2align   4                                                   \n\t"
64

65 66
        "1:                                                             \n\t"
        PTR_ADDU   "%[addr0],   %[block],       %[nCoeffs]              \n\t"
67 68
        MMI_LDC1(%[ftmp1], %[addr0], 0x00)
        MMI_LDC1(%[ftmp2], %[addr0], 0x08)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
        "mov.d      %[ftmp3],   %[ftmp1]                                \n\t"
        "mov.d      %[ftmp4],   %[ftmp2]                                \n\t"
        "pmullh     %[ftmp1],   %[ftmp1],       %[qmul]                 \n\t"
        "pmullh     %[ftmp2],   %[ftmp2],       %[qmul]                 \n\t"
        "pcmpgth    %[ftmp3],   %[ftmp3],       %[ftmp5]                \n\t"
        "pcmpgth    %[ftmp4],   %[ftmp4],       %[ftmp5]                \n\t"
        "xor        %[ftmp1],   %[ftmp1],       %[ftmp3]                \n\t"
        "xor        %[ftmp2],   %[ftmp2],       %[ftmp4]                \n\t"
        "paddh      %[ftmp1],   %[ftmp1],       %[ftmp0]                \n\t"
        "paddh      %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
        "xor        %[ftmp3],   %[ftmp3],       %[ftmp1]                \n\t"
        "xor        %[ftmp4],   %[ftmp4],       %[ftmp2]                \n\t"
        "pcmpeqh    %[ftmp1],   %[ftmp1],       %[ftmp0]                \n\t"
        "pcmpeqh    %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
        "pandn      %[ftmp1],   %[ftmp1],       %[ftmp3]                \n\t"
        "pandn      %[ftmp2],   %[ftmp2],       %[ftmp4]                \n\t"
        PTR_ADDIU  "%[nCoeffs], %[nCoeffs],     0x10                    \n\t"
86 87
        MMI_SDC1(%[ftmp1], %[addr0], 0x00)
        MMI_SDC1(%[ftmp2], %[addr0], 0x08)
88 89 90 91
        "blez       %[nCoeffs], 1b                                      \n\t"
        : [ftmp0]"=&f"(ftmp[0]),            [ftmp1]"=&f"(ftmp[1]),
          [ftmp2]"=&f"(ftmp[2]),            [ftmp3]"=&f"(ftmp[3]),
          [ftmp4]"=&f"(ftmp[4]),            [ftmp5]"=&f"(ftmp[5]),
92
          RESTRICT_ASM_ALL64
93 94 95 96 97
          [addr0]"=&r"(addr[0])
        : [block]"r"((mips_reg)(block+nCoeffs)),
          [nCoeffs]"r"((mips_reg)(2*(-nCoeffs))),
          [qmul]"f"(qmul),                  [qadd]"f"(qadd)
        : "memory"
98 99 100 101 102 103 104 105 106
    );

    block[0] = level;
}

void ff_dct_unquantize_h263_inter_mmi(MpegEncContext *s, int16_t *block,
        int n, int qscale)
{
    int64_t qmul, qadd, nCoeffs;
107 108
    double ftmp[6];
    mips_reg addr[1];
109
    DECLARE_VAR_ALL64;
110 111 112

    qmul = qscale << 1;
    qadd = (qscale - 1) | 1;
113
    av_assert2(s->block_last_index[n]>=0 || s->h263_aic);
114 115 116
    nCoeffs = s->inter_scantable.raster_end[s->block_last_index[n]];

    __asm__ volatile (
117 118 119 120 121 122 123 124 125 126
        "packsswh   %[qmul],    %[qmul],        %[qmul]                 \n\t"
        "packsswh   %[qmul],    %[qmul],        %[qmul]                 \n\t"
        "xor        %[ftmp0],   %[ftmp0],       %[ftmp0]                \n\t"
        "packsswh   %[qadd],    %[qadd],        %[qadd]                 \n\t"
        "packsswh   %[qadd],    %[qadd],        %[qadd]                 \n\t"
        "psubh      %[ftmp0],   %[ftmp0],       %[qadd]                 \n\t"
        "xor        %[ftmp5],   %[ftmp5],       %[ftmp5]                \n\t"
        ".p2align   4                                                   \n\t"
        "1:                                                             \n\t"
        PTR_ADDU   "%[addr0],   %[block],       %[nCoeffs]              \n\t"
127 128
        MMI_LDC1(%[ftmp1], %[addr0], 0x00)
        MMI_LDC1(%[ftmp2], %[addr0], 0x08)
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
        "mov.d      %[ftmp3],   %[ftmp1]                                \n\t"
        "mov.d      %[ftmp4],   %[ftmp2]                                \n\t"
        "pmullh     %[ftmp1],   %[ftmp1],       %[qmul]                 \n\t"
        "pmullh     %[ftmp2],   %[ftmp2],       %[qmul]                 \n\t"
        "pcmpgth    %[ftmp3],   %[ftmp3],       %[ftmp5]                \n\t"
        "pcmpgth    %[ftmp4],   %[ftmp4],       %[ftmp5]                \n\t"
        "xor        %[ftmp1],   %[ftmp1],       %[ftmp3]                \n\t"
        "xor        %[ftmp2],   %[ftmp2],       %[ftmp4]                \n\t"
        "paddh      %[ftmp1],   %[ftmp1],       %[ftmp0]                \n\t"
        "paddh      %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
        "xor        %[ftmp3],   %[ftmp3],       %[ftmp1]                \n\t"
        "xor        %[ftmp4],   %[ftmp4],       %[ftmp2]                \n\t"
        "pcmpeqh    %[ftmp1],   %[ftmp1],       %[ftmp0]                \n\t"
        "pcmpeqh    %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
        "pandn      %[ftmp1],   %[ftmp1],       %[ftmp3]                \n\t"
        "pandn      %[ftmp2],   %[ftmp2],       %[ftmp4]                \n\t"
        PTR_ADDIU  "%[nCoeffs], %[nCoeffs],     0x10                    \n\t"
146 147
        MMI_SDC1(%[ftmp1], %[addr0], 0x00)
        MMI_SDC1(%[ftmp2], %[addr0], 0x08)
148 149 150 151
        "blez       %[nCoeffs], 1b                                      \n\t"
        : [ftmp0]"=&f"(ftmp[0]),            [ftmp1]"=&f"(ftmp[1]),
          [ftmp2]"=&f"(ftmp[2]),            [ftmp3]"=&f"(ftmp[3]),
          [ftmp4]"=&f"(ftmp[4]),            [ftmp5]"=&f"(ftmp[5]),
152
          RESTRICT_ASM_ALL64
153 154 155 156 157
          [addr0]"=&r"(addr[0])
        : [block]"r"((mips_reg)(block+nCoeffs)),
          [nCoeffs]"r"((mips_reg)(2*(-nCoeffs))),
          [qmul]"f"(qmul),                  [qadd]"f"(qadd)
        : "memory"
158 159 160 161 162 163 164 165 166
    );
}

void ff_dct_unquantize_mpeg1_intra_mmi(MpegEncContext *s, int16_t *block,
        int n, int qscale)
{
    int64_t nCoeffs;
    const uint16_t *quant_matrix;
    int block0;
167 168 169
    double ftmp[10];
    uint64_t tmp[1];
    mips_reg addr[1];
170 171
    DECLARE_VAR_ALL64;
    DECLARE_VAR_ADDRT;
172

173
    av_assert2(s->block_last_index[n]>=0);
174 175 176 177 178 179 180 181 182 183 184
    nCoeffs = s->intra_scantable.raster_end[s->block_last_index[n]] + 1;

    if (n<4)
        block0 = block[0] * s->y_dc_scale;
    else
        block0 = block[0] * s->c_dc_scale;

    /* XXX: only mpeg1 */
    quant_matrix = s->intra_matrix;

    __asm__ volatile (
185 186 187 188 189 190 191 192 193
        "dli        %[tmp0],    0x0f                                    \n\t"
        "pcmpeqh    %[ftmp0],   %[ftmp0],       %[ftmp0]                \n\t"
        "dmtc1      %[tmp0],    %[ftmp4]                                \n\t"
        "dmtc1      %[qscale],  %[ftmp1]                                \n\t"
        "psrlh      %[ftmp0],   %[ftmp0],       %[ftmp4]                \n\t"
        "packsswh   %[ftmp1],   %[ftmp1],       %[ftmp1]                \n\t"
        "packsswh   %[ftmp1],   %[ftmp1],       %[ftmp1]                \n\t"
        "or         %[addr0],   %[nCoeffs],     $0                      \n\t"
        ".p2align   4                                                   \n\t"
194

195
        "1:                                                             \n\t"
196 197
        MMI_LDXC1(%[ftmp2], %[addr0], %[block], 0x00)
        MMI_LDXC1(%[ftmp3], %[addr0], %[block], 0x08)
198 199
        "mov.d      %[ftmp4],   %[ftmp2]                                \n\t"
        "mov.d      %[ftmp5],   %[ftmp3]                                \n\t"
200 201
        MMI_LDXC1(%[ftmp6], %[addr0], %[quant], 0x00)
        MMI_LDXC1(%[ftmp7], %[addr0], %[quant], 0x08)
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
        "pmullh     %[ftmp6],   %[ftmp6],       %[ftmp1]                \n\t"
        "pmullh     %[ftmp7],   %[ftmp7],       %[ftmp1]                \n\t"
        "xor        %[ftmp8],   %[ftmp8],       %[ftmp8]                \n\t"
        "xor        %[ftmp9],   %[ftmp9],       %[ftmp9]                \n\t"
        "pcmpgth    %[ftmp8],   %[ftmp8],       %[ftmp2]                \n\t"
        "pcmpgth    %[ftmp9],   %[ftmp9],       %[ftmp3]                \n\t"
        "xor        %[ftmp2],   %[ftmp2],       %[ftmp8]                \n\t"
        "xor        %[ftmp3],   %[ftmp3],       %[ftmp9]                \n\t"
        "psubh      %[ftmp2],   %[ftmp2],       %[ftmp8]                \n\t"
        "psubh      %[ftmp3],   %[ftmp3],       %[ftmp9]                \n\t"
        "pmullh     %[ftmp2],   %[ftmp2],       %[ftmp6]                \n\t"
        "pmullh     %[ftmp3],   %[ftmp3],       %[ftmp7]                \n\t"
        "xor        %[ftmp6],   %[ftmp6],       %[ftmp6]                \n\t"
        "xor        %[ftmp7],   %[ftmp7],       %[ftmp7]                \n\t"
        "pcmpeqh    %[ftmp6],   %[ftmp6],       %[ftmp4]                \n\t"
        "dli        %[tmp0],    0x03                                    \n\t"
        "pcmpeqh    %[ftmp7],   %[ftmp7],       %[ftmp5]                \n\t"
        "dmtc1      %[tmp0],    %[ftmp4]                                \n\t"
        "psrah      %[ftmp2],   %[ftmp2],       %[ftmp4]                \n\t"
        "psrah      %[ftmp3],   %[ftmp3],       %[ftmp4]                \n\t"
        "psubh      %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
        "psubh      %[ftmp3],   %[ftmp3],       %[ftmp0]                \n\t"
        "or         %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
        "or         %[ftmp3],   %[ftmp3],       %[ftmp0]                \n\t"
        "xor        %[ftmp2],   %[ftmp2],       %[ftmp8]                \n\t"
        "xor        %[ftmp3],   %[ftmp3],       %[ftmp9]                \n\t"
        "psubh      %[ftmp2],   %[ftmp2],       %[ftmp8]                \n\t"
        "psubh      %[ftmp3],   %[ftmp3],       %[ftmp9]                \n\t"
        "pandn      %[ftmp6],   %[ftmp6],       %[ftmp2]                \n\t"
        "pandn      %[ftmp7],   %[ftmp7],       %[ftmp3]                \n\t"
232 233
        MMI_SDXC1(%[ftmp6], %[addr0], %[block], 0x00)
        MMI_SDXC1(%[ftmp7], %[addr0], %[block], 0x08)
234 235 236 237 238 239 240 241
        PTR_ADDIU  "%[addr0],   %[addr0],       0x10                    \n\t"
        "bltz       %[addr0],   1b                                      \n\t"
        : [ftmp0]"=&f"(ftmp[0]),            [ftmp1]"=&f"(ftmp[1]),
          [ftmp2]"=&f"(ftmp[2]),            [ftmp3]"=&f"(ftmp[3]),
          [ftmp4]"=&f"(ftmp[4]),            [ftmp5]"=&f"(ftmp[5]),
          [ftmp6]"=&f"(ftmp[6]),            [ftmp7]"=&f"(ftmp[7]),
          [ftmp8]"=&f"(ftmp[8]),            [ftmp9]"=&f"(ftmp[9]),
          [tmp0]"=&r"(tmp[0]),
242 243
          RESTRICT_ASM_ALL64
          RESTRICT_ASM_ADDRT
244 245 246 247 248 249
          [addr0]"=&r"(addr[0])
        : [block]"r"((mips_reg)(block+nCoeffs)),
          [quant]"r"((mips_reg)(quant_matrix+nCoeffs)),
          [nCoeffs]"r"((mips_reg)(2*(-nCoeffs))),
          [qscale]"r"(qscale)
        : "memory"
250 251 252 253 254 255 256 257 258 259
    );

    block[0] = block0;
}

void ff_dct_unquantize_mpeg1_inter_mmi(MpegEncContext *s, int16_t *block,
        int n, int qscale)
{
    int64_t nCoeffs;
    const uint16_t *quant_matrix;
260 261 262
    double ftmp[10];
    uint64_t tmp[1];
    mips_reg addr[1];
263 264
    DECLARE_VAR_ALL64;
    DECLARE_VAR_ADDRT;
265

266
    av_assert2(s->block_last_index[n] >= 0);
267 268 269 270
    nCoeffs = s->intra_scantable.raster_end[s->block_last_index[n]] + 1;
    quant_matrix = s->inter_matrix;

    __asm__ volatile (
271 272 273 274 275 276 277 278 279
        "dli        %[tmp0],    0x0f                                    \n\t"
        "pcmpeqh    %[ftmp0],   %[ftmp0],       %[ftmp0]                \n\t"
        "dmtc1      %[tmp0],    %[ftmp4]                                \n\t"
        "dmtc1      %[qscale],  %[ftmp1]                                \n\t"
        "psrlh      %[ftmp0],   %[ftmp0],       %[ftmp4]                \n\t"
        "packsswh   %[ftmp1],   %[ftmp1],       %[ftmp1]                \n\t"
        "packsswh   %[ftmp1],   %[ftmp1],       %[ftmp1]                \n\t"
        "or         %[addr0],   %[nCoeffs],     $0                      \n\t"
        ".p2align   4                                                   \n\t"
280

281
        "1:                                                             \n\t"
282 283
        MMI_LDXC1(%[ftmp2], %[addr0], %[block], 0x00)
        MMI_LDXC1(%[ftmp3], %[addr0], %[block], 0x08)
284 285
        "mov.d      %[ftmp4],   %[ftmp2]                                \n\t"
        "mov.d      %[ftmp5],   %[ftmp3]                                \n\t"
286 287
        MMI_LDXC1(%[ftmp6], %[addr0], %[quant], 0x00)
        MMI_LDXC1(%[ftmp7], %[addr0], %[quant], 0x08)
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
        "pmullh     %[ftmp6],   %[ftmp6],       %[ftmp1]                \n\t"
        "pmullh     %[ftmp7],   %[ftmp7],       %[ftmp1]                \n\t"
        "xor        %[ftmp8],   %[ftmp8],       %[ftmp8]                \n\t"
        "xor        %[ftmp9],   %[ftmp9],       %[ftmp9]                \n\t"
        "pcmpgth    %[ftmp8],   %[ftmp8],       %[ftmp2]                \n\t"
        "pcmpgth    %[ftmp9],   %[ftmp9],       %[ftmp3]                \n\t"
        "xor        %[ftmp2],   %[ftmp2],       %[ftmp8]                \n\t"
        "xor        %[ftmp3],   %[ftmp3],       %[ftmp9]                \n\t"
        "psubh      %[ftmp2],   %[ftmp2],       %[ftmp8]                \n\t"
        "psubh      %[ftmp3],   %[ftmp3],       %[ftmp9]                \n\t"
        "paddh      %[ftmp2],   %[ftmp2],       %[ftmp2]                \n\t"
        "paddh      %[ftmp3],   %[ftmp3],       %[ftmp3]                \n\t"
        "paddh      %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
        "paddh      %[ftmp3],   %[ftmp3],       %[ftmp0]                \n\t"
        "pmullh     %[ftmp2],   %[ftmp2],       %[ftmp6]                \n\t"
        "pmullh     %[ftmp3],   %[ftmp3],       %[ftmp7]                \n\t"
        "xor        %[ftmp6],   %[ftmp6],       %[ftmp6]                \n\t"
        "xor        %[ftmp7],   %[ftmp7],       %[ftmp7]                \n\t"
        "pcmpeqh    %[ftmp6],   %[ftmp6],       %[ftmp4]                \n\t"
        "dli        %[tmp0],    0x04                                    \n\t"
        "pcmpeqh    %[ftmp7],   %[ftmp7],       %[ftmp5]                \n\t"
        "dmtc1      %[tmp0],    %[ftmp4]                                \n\t"
        "psrah      %[ftmp2],   %[ftmp2],       %[ftmp4]                \n\t"
        "psrah      %[ftmp3],   %[ftmp3],       %[ftmp4]                \n\t"
        "psubh      %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
        "psubh      %[ftmp3],   %[ftmp3],       %[ftmp0]                \n\t"
        "or         %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
        "or         %[ftmp3],   %[ftmp3],       %[ftmp0]                \n\t"
        "xor        %[ftmp2],   %[ftmp2],       %[ftmp8]                \n\t"
        "xor        %[ftmp3],   %[ftmp3],       %[ftmp9]                \n\t"
        "psubh      %[ftmp2],   %[ftmp2],       %[ftmp8]                \n\t"
        "psubh      %[ftmp3],   %[ftmp3],       %[ftmp9]                \n\t"
        "pandn      %[ftmp6],   %[ftmp6],       %[ftmp2]                \n\t"
        "pandn      %[ftmp7],   %[ftmp7],       %[ftmp3]                \n\t"
322 323
        MMI_SDXC1(%[ftmp6], %[addr0], %[block], 0x00)
        MMI_SDXC1(%[ftmp7], %[addr0], %[block], 0x08)
324 325 326 327 328 329 330 331
        PTR_ADDIU  "%[addr0],   %[addr0],       0x10                    \n\t"
        "bltz       %[addr0],   1b                                      \n\t"
        : [ftmp0]"=&f"(ftmp[0]),            [ftmp1]"=&f"(ftmp[1]),
          [ftmp2]"=&f"(ftmp[2]),            [ftmp3]"=&f"(ftmp[3]),
          [ftmp4]"=&f"(ftmp[4]),            [ftmp5]"=&f"(ftmp[5]),
          [ftmp6]"=&f"(ftmp[6]),            [ftmp7]"=&f"(ftmp[7]),
          [ftmp8]"=&f"(ftmp[8]),            [ftmp9]"=&f"(ftmp[9]),
          [tmp0]"=&r"(tmp[0]),
332 333
          RESTRICT_ASM_ALL64
          RESTRICT_ASM_ADDRT
334 335 336 337 338 339
          [addr0]"=&r"(addr[0])
        : [block]"r"((mips_reg)(block+nCoeffs)),
          [quant]"r"((mips_reg)(quant_matrix+nCoeffs)),
          [nCoeffs]"r"((mips_reg)(2*(-nCoeffs))),
          [qscale]"r"(qscale)
        : "memory"
340 341 342 343 344 345 346 347 348
    );
}

void ff_dct_unquantize_mpeg2_intra_mmi(MpegEncContext *s, int16_t *block,
        int n, int qscale)
{
    uint64_t nCoeffs;
    const uint16_t *quant_matrix;
    int block0;
349 350 351
    double ftmp[10];
    uint64_t tmp[1];
    mips_reg addr[1];
352 353
    DECLARE_VAR_ALL64;
    DECLARE_VAR_ADDRT;
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369

    assert(s->block_last_index[n]>=0);

    if (s->alternate_scan)
        nCoeffs = 63;
    else
        nCoeffs = s->intra_scantable.raster_end[s->block_last_index[n]];

    if (n < 4)
        block0 = block[0] * s->y_dc_scale;
    else
        block0 = block[0] * s->c_dc_scale;

    quant_matrix = s->intra_matrix;

    __asm__ volatile (
370 371 372 373 374 375 376 377 378
        "dli        %[tmp0],    0x0f                                    \n\t"
        "pcmpeqh    %[ftmp0],   %[ftmp0],       %[ftmp0]                \n\t"
        "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
        "mtc1       %[qscale],  %[ftmp9]                                \n\t"
        "psrlh      %[ftmp0],   %[ftmp0],       %[ftmp3]                \n\t"
        "packsswh   %[ftmp9],   %[ftmp9],       %[ftmp9]                \n\t"
        "packsswh   %[ftmp9],   %[ftmp9],       %[ftmp9]                \n\t"
        "or         %[addr0],   %[nCoeffs],     $0                      \n\t"
        ".p2align   4                                                   \n\t"
379

380
        "1:                                                             \n\t"
381 382
        MMI_LDXC1(%[ftmp1], %[addr0], %[block], 0x00)
        MMI_LDXC1(%[ftmp2], %[addr0], %[block], 0x08)
383 384
        "mov.d      %[ftmp3],   %[ftmp1]                                \n\t"
        "mov.d      %[ftmp4],   %[ftmp2]                                \n\t"
385 386
        MMI_LDXC1(%[ftmp5], %[addr0], %[quant], 0x00)
        MMI_LDXC1(%[ftmp6], %[addr0], %[quant], 0x08)
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
        "pmullh     %[ftmp5],   %[ftmp5],       %[ftmp9]                \n\t"
        "pmullh     %[ftmp6],   %[ftmp6],       %[ftmp9]                \n\t"
        "xor        %[ftmp7],   %[ftmp7],       %[ftmp7]                \n\t"
        "xor        %[ftmp8],   %[ftmp8],       %[ftmp8]                \n\t"
        "pcmpgth    %[ftmp7],   %[ftmp7],       %[ftmp1]                \n\t"
        "pcmpgth    %[ftmp8],   %[ftmp8],       %[ftmp2]                \n\t"
        "xor        %[ftmp1],   %[ftmp1],       %[ftmp7]                \n\t"
        "xor        %[ftmp2],   %[ftmp2],       %[ftmp8]                \n\t"
        "psubh      %[ftmp1],   %[ftmp1],       %[ftmp7]                \n\t"
        "psubh      %[ftmp2],   %[ftmp2],       %[ftmp8]                \n\t"
        "pmullh     %[ftmp1],   %[ftmp1],       %[ftmp5]                \n\t"
        "pmullh     %[ftmp2],   %[ftmp2],       %[ftmp6]                \n\t"
        "xor        %[ftmp5],   %[ftmp5],       %[ftmp5]                \n\t"
        "xor        %[ftmp6],   %[ftmp6],       %[ftmp6]                \n\t"
        "pcmpeqh    %[ftmp5],   %[ftmp5],       %[ftmp3]                \n\t"
        "dli        %[tmp0],    0x03                                    \n\t"
        "pcmpeqh    %[ftmp6] ,  %[ftmp6],       %[ftmp4]                \n\t"
        "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
        "psrah      %[ftmp1],   %[ftmp1],       %[ftmp3]                \n\t"
        "psrah      %[ftmp2],   %[ftmp2],       %[ftmp3]                \n\t"
        "xor        %[ftmp1],   %[ftmp1],       %[ftmp7]                \n\t"
        "xor        %[ftmp2],   %[ftmp2],       %[ftmp8]                \n\t"
        "psubh      %[ftmp1],   %[ftmp1],       %[ftmp7]                \n\t"
        "psubh      %[ftmp2],   %[ftmp2],       %[ftmp8]                \n\t"
        "pandn      %[ftmp5],   %[ftmp5],       %[ftmp1]                \n\t"
        "pandn      %[ftmp6],   %[ftmp6],       %[ftmp2]                \n\t"
        PTR_ADDIU  "%[addr0],   %[addr0],       0x10                    \n\t"
414 415
        MMI_SDXC1(%[ftmp5], %[addr0], %[block], 0x00)
        MMI_SDXC1(%[ftmp6], %[addr0], %[block], 0x08)
416 417 418 419 420 421 422
        "blez       %[addr0],   1b                                      \n\t"
        : [ftmp0]"=&f"(ftmp[0]),            [ftmp1]"=&f"(ftmp[1]),
          [ftmp2]"=&f"(ftmp[2]),            [ftmp3]"=&f"(ftmp[3]),
          [ftmp4]"=&f"(ftmp[4]),            [ftmp5]"=&f"(ftmp[5]),
          [ftmp6]"=&f"(ftmp[6]),            [ftmp7]"=&f"(ftmp[7]),
          [ftmp8]"=&f"(ftmp[8]),            [ftmp9]"=&f"(ftmp[9]),
          [tmp0]"=&r"(tmp[0]),
423 424
          RESTRICT_ASM_ALL64
          RESTRICT_ASM_ADDRT
425 426 427 428 429 430
          [addr0]"=&r"(addr[0])
        : [block]"r"((mips_reg)(block+nCoeffs)),
          [quant]"r"((mips_reg)(quant_matrix+nCoeffs)),
          [nCoeffs]"r"((mips_reg)(2*(-nCoeffs))),
          [qscale]"r"(qscale)
        : "memory"
431 432 433 434
    );

    block[0]= block0;
}
435 436 437 438 439 440 441 442

void ff_denoise_dct_mmi(MpegEncContext *s, int16_t *block)
{
    const int intra = s->mb_intra;
    int *sum = s->dct_error_sum[intra];
    uint16_t *offset = s->dct_offset[intra];
    double ftmp[8];
    mips_reg addr[1];
443
    DECLARE_VAR_ALL64;
444 445 446 447 448 449

    s->dct_count[intra]++;

    __asm__ volatile(
        "xor        %[ftmp0],   %[ftmp0],       %[ftmp0]                \n\t"
        "1:                                                             \n\t"
450
        MMI_LDC1(%[ftmp1], %[block], 0x00)
451
        "xor        %[ftmp2],   %[ftmp2],       %[ftmp2]                \n\t"
452
        MMI_LDC1(%[ftmp3], %[block], 0x08)
453 454 455 456 457 458 459
        "xor        %[ftmp4],   %[ftmp4],       %[ftmp4]                \n\t"
        "pcmpgth    %[ftmp2],   %[ftmp2],       %[ftmp1]                \n\t"
        "pcmpgth    %[ftmp4],   %[ftmp4],       %[ftmp3]                \n\t"
        "xor        %[ftmp1],   %[ftmp1],       %[ftmp2]                \n\t"
        "xor        %[ftmp3],   %[ftmp3],       %[ftmp4]                \n\t"
        "psubh      %[ftmp1],   %[ftmp1],       %[ftmp2]                \n\t"
        "psubh      %[ftmp3],   %[ftmp3],       %[ftmp4]                \n\t"
460
        MMI_LDC1(%[ftmp6], %[offset], 0x00)
461 462
        "mov.d      %[ftmp5],   %[ftmp1]                                \n\t"
        "psubush    %[ftmp1],   %[ftmp1],       %[ftmp6]                \n\t"
463
        MMI_LDC1(%[ftmp6], %[offset], 0x08)
464 465 466 467 468 469
        "mov.d      %[ftmp7],   %[ftmp3]                                \n\t"
        "psubush    %[ftmp3],   %[ftmp3],       %[ftmp6]                \n\t"
        "xor        %[ftmp1],   %[ftmp1],       %[ftmp2]                \n\t"
        "xor        %[ftmp3],   %[ftmp3],       %[ftmp4]                \n\t"
        "psubh      %[ftmp1],   %[ftmp1],       %[ftmp2]                \n\t"
        "psubh      %[ftmp3],   %[ftmp3],       %[ftmp4]                \n\t"
470 471
        MMI_SDC1(%[ftmp1], %[block], 0x00)
        MMI_SDC1(%[ftmp3], %[block], 0x08)
472 473 474 475 476 477
        "mov.d      %[ftmp1],   %[ftmp5]                                \n\t"
        "mov.d      %[ftmp3],   %[ftmp7]                                \n\t"
        "punpcklhw  %[ftmp5],   %[ftmp5],       %[ftmp0]                \n\t"
        "punpckhhw  %[ftmp1],   %[ftmp1],       %[ftmp0]                \n\t"
        "punpcklhw  %[ftmp7],   %[ftmp7],       %[ftmp0]                \n\t"
        "punpckhhw  %[ftmp3],   %[ftmp3],       %[ftmp0]                \n\t"
478
        MMI_LDC1(%[ftmp2], %[sum], 0x00)
479
        "paddw      %[ftmp5],   %[ftmp5],       %[ftmp2]                \n\t"
480
        MMI_LDC1(%[ftmp2], %[sum], 0x08)
481
        "paddw      %[ftmp1],   %[ftmp1],       %[ftmp2]                \n\t"
482
        MMI_LDC1(%[ftmp2], %[sum], 0x10)
483
        "paddw      %[ftmp7],   %[ftmp7],       %[ftmp2]                \n\t"
484
        MMI_LDC1(%[ftmp2], %[sum], 0x18)
485
        "paddw      %[ftmp3],   %[ftmp3],       %[ftmp2]                \n\t"
486 487 488 489
        MMI_SDC1(%[ftmp5], %[sum], 0x00)
        MMI_SDC1(%[ftmp1], %[sum], 0x08)
        MMI_SDC1(%[ftmp7], %[sum], 0x10)
        MMI_SDC1(%[ftmp3], %[sum], 0x18)
490 491 492 493 494 495 496 497 498
        PTR_ADDIU  "%[block],   %[block],       0x10                    \n\t"
        PTR_ADDIU  "%[sum],     %[sum],         0x20                    \n\t"
        PTR_SUBU   "%[addr0],   %[block1],      %[block]                \n\t"
        PTR_ADDIU  "%[offset],  %[offset],      0x10                    \n\t"
        "bgtz       %[addr0],   1b                                      \n\t"
        : [ftmp0]"=&f"(ftmp[0]),            [ftmp1]"=&f"(ftmp[1]),
          [ftmp2]"=&f"(ftmp[2]),            [ftmp3]"=&f"(ftmp[3]),
          [ftmp4]"=&f"(ftmp[4]),            [ftmp5]"=&f"(ftmp[5]),
          [ftmp6]"=&f"(ftmp[6]),            [ftmp7]"=&f"(ftmp[7]),
499
          RESTRICT_ASM_ALL64
500 501 502 503 504 505 506
          [addr0]"=&r"(addr[0]),
          [block]"+&r"(block),              [sum]"+&r"(sum),
          [offset]"+&r"(offset)
        : [block1]"r"(block+64)
        : "memory"
    );
}