mpegvideo_mmi.c 2.92 KB
Newer Older
1
/*
2
 * Copyright (c) 2000,2001 Fabrice Bellard
3
 *
4 5
 * MMI optimization by Leon van Stuivenberg
 *
6
 * This file is part of Libav.
7
 *
8
 * Libav is free software; you can redistribute it and/or
9 10
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * Libav is distributed in the hope that it will be useful,
14 15 16 17 18
 * 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
19
 * License along with Libav; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

23 24 25
#include "libavcodec/avcodec.h"
#include "libavcodec/dsputil.h"
#include "libavcodec/mpegvideo.h"
26

27
static void dct_unquantize_h263_mmi(MpegEncContext *s,
28 29 30 31
                                  DCTELEM *block, int n, int qscale)
{
    int level=0, qmul, qadd;
    int nCoeffs;
32

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

35 36
    qadd = (qscale - 1) | 1;
    qmul = qscale << 1;
37

38 39
    if (s->mb_intra) {
        if (!s->h263_aic) {
40
            if (n < 4)
41 42 43 44 45
                level = block[0] * s->y_dc_scale;
            else
                level = block[0] * s->c_dc_scale;
        }else {
            qadd = 0;
46
            level = block[0];
47
        }
Diego Biurrun's avatar
Diego Biurrun committed
48
        nCoeffs= 63; //does not always use zigzag table
49 50 51 52
    } else {
        nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
    }

53
    __asm__ volatile(
54 55 56 57 58
        "add    $14, $0, %3     \n\t"
        "pcpyld $8, %0, %0      \n\t"
        "pcpyh  $8, $8          \n\t"   //r8 = qmul
        "pcpyld $9, %1, %1      \n\t"
        "pcpyh  $9, $9          \n\t"   //r9 = qadd
59
        ".p2align 2             \n\t"
60 61 62 63 64 65 66 67 68
        "1:                     \n\t"
        "lq     $10, 0($14)     \n\t"   //r10 = level
        "addi   $14, $14, 16    \n\t"   //block+=8
        "addi   %2, %2, -8      \n\t"
        "pcgth  $11, $0, $10    \n\t"   //r11 = level < 0 ? -1 : 0
        "pcgth  $12, $10, $0    \n\t"   //r12 = level > 0 ? -1 : 0
        "por    $12, $11, $12   \n\t"
        "pmulth $10, $10, $8    \n\t"
        "paddh  $13, $9, $11    \n\t"
69
        "pxor   $13, $13, $11   \n\t"   //r13 = level < 0 ? -qadd : qadd
70 71 72
        "pmfhl.uw $11           \n\t"
        "pinteh $10, $11, $10   \n\t"   //r10 = level * qmul
        "paddh  $10, $10, $13   \n\t"
73
        "pand   $10, $10, $12   \n\t"
74 75 76
        "sq     $10, -16($14)   \n\t"
        "bgez   %2, 1b          \n\t"
        :: "r"(qmul), "r" (qadd), "r" (nCoeffs), "r" (block) : "$8", "$9", "$10", "$11", "$12", "$13", "$14", "memory" );
77 78 79 80 81 82 83 84

    if(s->mb_intra)
        block[0]= level;
}


void MPV_common_init_mmi(MpegEncContext *s)
{
85
    s->dct_unquantize_h263_intra =
Michael Niedermayer's avatar
Michael Niedermayer committed
86
    s->dct_unquantize_h263_inter = dct_unquantize_h263_mmi;
87 88 89
}