159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ------------------------------------------------------------------
259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Copyright (C) 1998-2009 PacketVideo
359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *
459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Licensed under the Apache License, Version 2.0 (the "License");
559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * you may not use this file except in compliance with the License.
659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * You may obtain a copy of the License at
759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *
859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *      http://www.apache.org/licenses/LICENSE-2.0
959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *
1059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Unless required by applicable law or agreed to in writing, software
1159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * distributed under the License is distributed on an "AS IS" BASIS,
1259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
1359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * express or implied.
1459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * See the License for the specific language governing permissions
1559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * and limitations under the License.
1659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * -------------------------------------------------------------------
1759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong */
1859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*********************************************************************************/
1959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*  Filename: fastquant_inline.h                                                        */
2059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*  Description: Implementation for in-line functions used in dct.cpp           */
2159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*  Modified:                                                                   */
2259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*********************************************************************************/
2359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef _FASTQUANT_INLINE_H_
2459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define _FASTQUANT_INLINE_H_
2559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
2659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "mp4def.h"
2759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
2859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#if !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) /* ARM GNU COMPILER  */
2959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
3059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 aan_scale(int32 q_value, int32 coeff, int32 round, int32 QPdiv2)
3159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
3259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    q_value = coeff * q_value + round;
3359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    coeff = q_value >> 16;
3459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if (coeff < 0)  coeff += QPdiv2;
3559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else            coeff -= QPdiv2;
3659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
3759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return coeff;
3859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
3959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
4059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
4159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_quant(int32 coeff, int32 q_scale, int32 shift)
4259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
4359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 q_value;
4459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
4559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    q_value = coeff * q_scale;      //q_value = -((-(coeff + QPdiv2)*q_scale)>>LSL);
4659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    q_value >>= shift;                  //q_value = (((coeff - QPdiv2)*q_scale)>>LSL );
4759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    q_value += ((UInt)q_value >> 31); /* add one if negative */
4859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
4959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
5059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
5159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
5259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32  coeff_clip(int32 q_value, int32 ac_clip)
5359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
5459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 coeff = q_value + ac_clip;
5559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
5659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if ((UInt)coeff > (UInt)(ac_clip << 1))
5759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        q_value = ac_clip ^(q_value >> 31);
5859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
5959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
6059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
6159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
6259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_dequant(int32 q_value, int32 QPx2, int32 Addition, int32 tmp)
6359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
6459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 coeff;
6559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
6659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    OSCL_UNUSED_ARG(tmp);
6759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
6859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if (q_value < 0)
6959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
7059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        coeff = q_value * QPx2 - Addition;
7159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (coeff < -2048)
7259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            coeff = -2048;
7359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
7459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else
7559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
7659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        coeff = q_value * QPx2 + Addition;
7759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (coeff > 2047)
7859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            coeff = 2047;
7959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
8059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return coeff;
8159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
8259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
8359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 smlabb(int32 q_value, int32 coeff, int32 round)
8459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
8559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    q_value = coeff * q_value + round;
8659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
8759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
8859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
8959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
9059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 smulbb(int32 q_scale, int32 coeff)
9159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
9259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 q_value;
9359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
9459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    q_value = coeff * q_scale;
9559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
9659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
9759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
9859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
9959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 aan_dc_scale(int32 coeff, int32 QP)
10059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
10159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
10259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if (coeff < 0)  coeff += (QP >> 1);
10359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else            coeff -= (QP >> 1);
10459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
10559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return coeff;
10659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
10759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
10859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 clip_2047(int32 q_value, int32 tmp)
10959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
11059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    OSCL_UNUSED_ARG(tmp);
11159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
11259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if (q_value < -2048)
11359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
11459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        q_value = -2048;
11559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
11659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else if (q_value > 2047)
11759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
11859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        q_value = 2047;
11959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
12059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
12159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
12259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
12359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
12459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_dequant_mpeg(int32 q_value, int32 stepsize, int32 QP, int32 tmp)
12559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
12659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 coeff;
12759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
12859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    OSCL_UNUSED_ARG(tmp);
12959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
13059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    coeff = q_value << 1;
13159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    stepsize *= QP;
13259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if (coeff > 0)
13359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
13459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        q_value = (coeff + 1) * stepsize;
13559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        q_value >>= 4;
13659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (q_value > 2047) q_value = 2047;
13759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
13859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else
13959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
14059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        q_value = (coeff - 1) * stepsize;
14159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        q_value += 15;
14259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        q_value >>= 4;
14359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (q_value < -2048)    q_value = -2048;
14459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
14559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
14659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
14759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
14859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
14959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_dequant_mpeg_intra(int32 q_value, int32 tmp)
15059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
15159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    OSCL_UNUSED_ARG(tmp);
15259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
15359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    q_value <<= 1;
15459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    if (q_value > 0)
15559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
15659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        q_value >>= 4;
15759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (q_value > 2047) q_value = 2047;
15859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
15959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    else
16059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
16159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        q_value += 15;
16259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        q_value >>= 4;
16359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (q_value < -2048) q_value = -2048;
16459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
16559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
16659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
16759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
16859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
16959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#elif defined(__CC_ARM)  /* only work with arm v5 */
17059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
17159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#if defined(__TARGET_ARCH_5TE)
17259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
17359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 aan_scale(int32 q_value, int32 coeff,
17459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         int32 round, int32 QPdiv2)
17559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
17659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
17759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
17859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        smlabb q_value, coeff, q_value, round
17959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        movs       coeff, q_value, asr #16
18059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        addle   coeff, coeff, QPdiv2
18159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subgt   coeff, coeff, QPdiv2
18259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
18359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
18459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return coeff;
18559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
18659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
18759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_quant(int32 coeff, int32 q_scale, int32 shift)
18859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
18959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 q_value;
19059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
19159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
19259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
19359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        smulbb  q_value, q_scale, coeff    /*mov    coeff, coeff, lsl #14*/
19459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        mov     coeff, q_value, asr shift   /*smull tmp, coeff, q_scale, coeff*/
19559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        add q_value, coeff, coeff, lsr #31
19659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
19759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
19859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
19959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
20059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
20159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
20259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_dequant(int32 q_value, int32 QPx2, int32 Addition, int32 tmp)
20359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
20459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 coeff;
20559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
20659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
20759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
20859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        cmp     q_value, #0
20959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        smulbb  coeff, q_value, QPx2
21059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        sublt   coeff, coeff, Addition
21159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        addge   coeff, coeff, Addition
21259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        add     q_value, coeff, tmp
21359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subs    q_value, q_value, #3840
21459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subcss  q_value, q_value, #254
21559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        eorhi   coeff, tmp, coeff, asr #31
21659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
21759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
21859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return coeff;
21959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
22059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
22159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 smlabb(int32 q_value, int32 coeff, int32 round)
22259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
22359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
22459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
22559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        smlabb q_value, coeff, q_value, round
22659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
22759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
22859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
22959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
23059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
23159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 smulbb(int32 q_scale, int32 coeff)
23259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
23359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 q_value;
23459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
23559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
23659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
23759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        smulbb  q_value, q_scale, coeff
23859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
23959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
24059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
24159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
24259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
24359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_dequant_mpeg(int32 q_value, int32 stepsize, int32 QP, int32 tmp)
24459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
24559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /* tmp must have value of 2047 */
24659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 coeff;
24759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
24859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
24959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        movs    coeff, q_value, lsl #1
25059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        smulbb  stepsize, stepsize, QP
25159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        addgt   coeff, coeff, #1
25259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        sublt   coeff, coeff, #1
25359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        smulbb  q_value, coeff, stepsize
25459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        addlt   q_value, q_value, #15
25559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        mov     q_value, q_value, asr #4
25659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        add     coeff, q_value, tmp
25759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subs    coeff, coeff, #0xf00
25859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subcss  coeff, coeff, #0xfe
25959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        eorhi   q_value, tmp, q_value, asr #31
26059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
26159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
26259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
26359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
26459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
26559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
26659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#else // not ARMV5TE
26759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
26859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 aan_scale(int32 q_value, int32 coeff,
26959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         int32 round, int32 QPdiv2)
27059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
27159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
27259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
27359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        mla q_value, coeff, q_value, round
27459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        movs       coeff, q_value, asr #16
27559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        addle   coeff, coeff, QPdiv2
27659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subgt   coeff, coeff, QPdiv2
27759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
27859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
27959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return coeff;
28059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
28159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
28259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_quant(int32 coeff, int32 q_scale, int32 shift)
28359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
28459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 q_value;
28559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
28659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
28759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
28859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        mul q_value, q_scale, coeff    /*mov    coeff, coeff, lsl #14*/
28959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        mov     coeff, q_value, asr shift   /*smull tmp, coeff, q_scale, coeff*/
29059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        add q_value, coeff, coeff, lsr #31
29159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
29259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
29359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
29459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
29559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
29659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
29759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
29859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_dequant(int32 q_value, int32 QPx2, int32 Addition, int32 tmp)
29959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
30059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 coeff;
30159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
30259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
30359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
30459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        cmp     q_value, #0
30559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        mul coeff, q_value, QPx2
30659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        sublt   coeff, coeff, Addition
30759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        addge   coeff, coeff, Addition
30859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        add     q_value, coeff, tmp
30959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subs    q_value, q_value, #3840
31059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subcss  q_value, q_value, #254
31159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        eorhi   coeff, tmp, coeff, asr #31
31259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
31359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
31459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return coeff;
31559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
31659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
31759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 smlabb(int32 q_value, int32 coeff, int32 round)
31859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
31959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
32059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
32159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        mla q_value, coeff, q_value, round
32259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
32359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
32459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
32559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
32659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
32759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 smulbb(int32 q_scale, int32 coeff)
32859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
32959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 q_value;
33059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
33159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
33259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
33359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        mul q_value, q_scale, coeff
33459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
33559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
33659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
33759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
33859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
33959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
34059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_dequant_mpeg(int32 q_value, int32 stepsize, int32 QP, int32 tmp)
34159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
34259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /* tmp must have value of 2047 */
34359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 coeff;
34459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
34559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
34659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        movs    coeff, q_value, lsl #1
34759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        mul  stepsize, stepsize, QP
34859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        addgt   coeff, coeff, #1
34959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        sublt   coeff, coeff, #1
35059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        mul q_value, coeff, stepsize
35159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        addlt   q_value, q_value, #15
35259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        mov     q_value, q_value, asr #4
35359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        add     coeff, q_value, tmp
35459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subs    coeff, coeff, #0xf00
35559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subcss  coeff, coeff, #0xfe
35659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        eorhi   q_value, tmp, q_value, asr #31
35759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
35859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
35959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
36059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
36159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
36259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
36359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif
36459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
36559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32  coeff_clip(int32 q_value, int32 ac_clip)
36659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
36759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 coeff;
36859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
36959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
37059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
37159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        add     coeff, q_value, ac_clip
37259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subs    coeff, coeff, ac_clip, lsl #1
37359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        eorhi   q_value, ac_clip, q_value, asr #31
37459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
37559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
37659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
37759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
37859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
37959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 aan_dc_scale(int32 coeff, int32 QP)
38059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
38159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
38259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
38359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
38459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        cmp   coeff, #0
38559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        addle   coeff, coeff, QP, asr #1
38659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subgt   coeff, coeff, QP, asr #1
38759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
38859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
38959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return coeff;
39059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
39159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
39259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 clip_2047(int32 q_value, int32 tmp)
39359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
39459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    /* tmp must have value of 2047 */
39559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 coeff;
39659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
39759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
39859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
39959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        add     coeff, q_value, tmp
40059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subs    coeff, coeff, #0xf00
40159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subcss  coeff, coeff, #0xfe
40259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        eorhi   q_value, tmp, q_value, asr #31
40359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
40459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
40559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
40659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
40759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
40859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_dequant_mpeg_intra(int32 q_value, int32 tmp)
40959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
41059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    int32 coeff;
41159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
41259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __asm
41359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
41459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        movs    q_value, q_value, lsl #1
41559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        addlt   q_value, q_value, #15
41659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        mov     q_value, q_value, asr #4
41759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        add     coeff, q_value, tmp
41859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subs    coeff, coeff, #0xf00
41959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        subcss  coeff, coeff, #0xfe
42059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        eorhi   q_value, tmp, q_value, asr #31
42159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
42259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
42359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
42459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
42559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
42659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#elif ( defined(PV_ARM_GCC_V4) || defined(PV_ARM_GCC_V5) ) /* ARM GNU COMPILER  */
42759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
42859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 aan_scale(int32 q_value, int32 coeff,
42959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         int32 round, int32 QPdiv2)
43059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
43159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 out;
43259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 qv = q_value;
43359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 cf = coeff;
43459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 rr = round;
43559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 qp = QPdiv2;
43659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
43759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    asm volatile("smlabb %0, %2, %1, %3\n\t"
43859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "movs %0, %0, asr #16\n\t"
43959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "addle %0, %0, %4\n\t"
44059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "subgt %0, %0, %4"
44159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong             : "=&r"(out)
44259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         : "r"(qv),
44359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(cf),
44459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(rr),
44559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(qp));
44659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return out;
44759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
44859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
44959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_quant(int32 coeff, int32 q_scale, int32 shift)
45059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
45159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 out;
45259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 temp1;
45359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 cc = coeff;
45459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 qs = q_scale;
45559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 ss = shift;
45659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
45759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    asm volatile("smulbb %0, %3, %2\n\t"
45859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "mov %1, %0, asr %4\n\t"
45959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "add %0, %1, %1, lsr #31"
46059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong             : "=&r"(out),
46159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "=&r"(temp1)
46259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         : "r"(cc),
46359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(qs),
46459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(ss));
46559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
46659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return out;
46759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
46859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
46959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_clip(int32 q_value, int32 ac_clip)
47059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
47159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 coeff;
47259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
47359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    asm volatile("add   %1, %0, %2\n\t"
47459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "subs  %1, %1, %2, lsl #1\n\t"
47559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "eorhi %0, %2, %0, asr #31"
47659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong             : "+r"(q_value),
47759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "=&r"(coeff)
47859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         : "r"(ac_clip));
47959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
48059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
48159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
48259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
48359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_dequant(int32 q_value, int32 QPx2, int32 Addition, int32 tmp)
48459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
48559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 out;
48659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 temp1;
48759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 qv = q_value;
48859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 qp = QPx2;
48959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 aa = Addition;
49059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 tt = tmp;
49159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
49259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    asm volatile("cmp    %2, #0\n\t"
49359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "mul    %0, %2, %3\n\t"
49459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "sublt  %0, %0, %4\n\t"
49559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "addge  %0, %0, %4\n\t"
49659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "add    %1, %0, %5\n\t"
49759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "subs   %1, %1, #3840\n\t"
49859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "subcss %1, %1, #254\n\t"
49959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "eorhi  %0, %5, %0, asr #31"
50059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong             : "=&r"(out),
50159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "=&r"(temp1)
50259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         : "r"(qv),
50359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(qp),
50459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(aa),
50559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(tt));
50659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
50759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return out;
50859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
50959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
51059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 smlabb(int32 q_value, int32 coeff, int32 round)
51159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
51259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 out;
51359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 aa = (int32)q_value;
51459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 bb = (int32)coeff;
51559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 cc = (int32)round;
51659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
51759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    asm volatile("smlabb %0, %1, %2, %3"
51859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong             : "=&r"(out)
51959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         : "r"(aa),
52059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(bb),
52159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(cc));
52259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return out;
52359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
52459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
52559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 smulbb(int32 q_scale, int32 coeff)
52659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
52759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 out;
52859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 aa = (int32)q_scale;
52959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 bb = (int32)coeff;
53059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
53159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    asm volatile("smulbb %0, %1, %2"
53259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong             : "=&r"(out)
53359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         : "r"(aa),
53459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(bb));
53559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return out;
53659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
53759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
53859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 aan_dc_scale(int32 coeff, int32 QP)
53959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
54059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 out;
54159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 cc = coeff;
54259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 qp = QP;
54359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
54459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    asm volatile("cmp %1, #0\n\t"
54559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "addle %0, %1, %2, asr #1\n\t"
54659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "subgt %0, %1, %2, asr #1"
54759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong             : "=&r"(out)
54859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         : "r"(cc),
54959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(qp));
55059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return out;
55159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
55259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
55359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 clip_2047(int32 q_value, int32 tmp)
55459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
55559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 coeff;
55659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    asm volatile("add    %1, %0, %2\n\t"
55759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "subs   %1, %1, #0xF00\n\t"
55859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "subcss %1, %1, #0xFE\n\t"
55959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "eorhi  %0, %2, %0, asr #31"
56059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong             : "+r"(q_value),
56159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "=&r"(coeff)
56259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         : "r"(tmp));
56359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
56459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return q_value;
56559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
56659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
56759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_dequant_mpeg(int32 q_value, int32 stepsize, int32 QP, int32 tmp)
56859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
56959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 out;
57059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 temp1;
57159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 qv = q_value;
57259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 ss = stepsize;
57359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 qp = QP;
57459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 tt = tmp;
57559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
57659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    asm volatile("movs    %1, %2, lsl #1\n\t"
57759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "mul     %0, %3, %4\n\t"
57859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "addgt   %1, %1, #1\n\t"
57959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "sublt   %1, %1, #1\n\t"
58059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "mul     %0, %1, %0\n\t"
58159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "addlt   %0, %0, #15\n\t"
58259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "mov     %0, %0, asr #4\n\t"
58359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "add     %1, %0, %5\n\t"
58459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "subs    %1, %1, #0xF00\n\t"
58559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "subcss  %1, %1, #0xFE\n\t"
58659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "eorhi   %0, %5, %0, asr #31"
58759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong             : "=&r"(out),
58859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "=&r"(temp1)
58959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         : "r"(qv),
59059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(ss),
59159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(qp),
59259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(tt));
59359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
59459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return out;
59559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
59659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
59759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
59859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong__inline int32 coeff_dequant_mpeg_intra(int32 q_value, int32 tmp)
59959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
60059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 out;
60159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 temp1;
60259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 qv = q_value;
60359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    register int32 tt = tmp;
60459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
60559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    asm volatile("movs    %1, %2, lsl #1\n\t"
60659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "addlt   %1, %1, #15\n\t"
60759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "mov     %0, %1, asr #4\n\t"
60859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "add     %1, %0, %3\n\t"
60959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "subs    %1, %1, #0xF00\n\t"
61059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "subcss  %1, %1, #0xFE\n\t"
61159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "eorhi   %0, %3, %0, asr #31"
61259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong             : "=&r"(out),
61359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                 "=&r"(temp1)
61459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         : "r"(qv),
61559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                         "r"(tt));
61659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    return out;
61759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
61859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
61959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
62059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif // Platform
62159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
62259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
62359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif //_FASTQUANT_INLINE_H_
62459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
62559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
626