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: sad_halfpel_inline.h                                                      */
2059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*  Description: Implementation for in-line functions used in dct.cpp           */
2159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*  Modified:                                                                   */
2259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*********************************************************************************/
2359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
2459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef _SAD_HALFPEL_INLINE_H_
2559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define _SAD_HALFPEL_INLINE_H_
2659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
2759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifdef __cplusplus
2859f566c4ec3dfc097ad8163523e522280b27e5c3James Dongextern "C"
2959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
3059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif
3159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
3259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#if !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) /* ARM GNU COMPILER  */
3359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
3459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
3559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
3659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        tmp = (tmp2 >> 1) - tmp;
3759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (tmp > 0) sad += tmp;
3859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        else sad -= tmp;
3959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
4059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        return sad;
4159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
4259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
4359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
4459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
4559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        tmp = (tmp >> 2) - tmp2;
4659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        if (tmp > 0) sad += tmp;
4759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        else sad -= tmp;
4859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
4959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        return sad;
5059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
5159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
5259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#elif defined(__CC_ARM)  /* only work with arm v5 */
5359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
5459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
5559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
5659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        __asm
5759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
5859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            rsbs    tmp, tmp, tmp2, asr #1 ;
5959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            rsbmi   tmp, tmp, #0 ;
6059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            add     sad, sad, tmp ;
6159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
6259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
6359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        return sad;
6459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
6559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
6659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
6759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
6859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        __asm
6959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        {
7059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            rsbs    tmp, tmp2, tmp, asr #2 ;
7159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            rsbmi   tmp, tmp, #0 ;
7259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong            add     sad, sad, tmp ;
7359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        }
7459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
7559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        return sad;
7659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
7759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
7859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#elif ( defined(PV_ARM_GCC_V5) || defined(PV_ARM_GCC_V4) ) /* ARM GNU COMPILER  */
7959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
8059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
8159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
8259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    {
8359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        register int32 out;
8459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        register int32 temp1;
8559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        register int32 ss = sad;
8659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        register int32 tt = tmp;
8759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        register int32 uu = tmp2;
8859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
8959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        asm volatile("rsbs	%1, %3, %4, asr #1\n\t"
9059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                     "rsbmi %1, %1, #0\n\t"
9159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                     "add  %0, %2, %1"
9259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong             : "=&r"(out),
9359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                     "=&r"(temp1)
9459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                             : "r"(ss),
9559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                             "r"(tt),
9659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                             "r"(uu));
9759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        return out;
9859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
9959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
10059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
10159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
10259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{
10359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        register int32 out;
10459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        register int32 temp1;
10559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        register int32 ss = sad;
10659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        register int32 tt = tmp;
10759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        register int32 uu = tmp2;
10859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
10959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        asm volatile("rsbs      %1, %4, %3, asr #2\n\t"
11059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                     "rsbmi %1, %1, #0\n\t"
11159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                     "add  %0, %2, %1"
11259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong             : "=&r"(out),
11359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                     "=&r"(temp1)
11459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                             : "r"(ss),
11559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                             "r"(tt),
11659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong                             "r"(uu));
11759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong        return out;
11859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong    }
11959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
12059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
12159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif // Diff OS
12259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
12359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
12459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
12559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifdef __cplusplus
12659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}
12759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif
12859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
12959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif //_SAD_HALFPEL_INLINE_H_
13059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong
131