sad_halfpel_inline.h revision f5af6314db25ff3bef9bd2eeba201bc6cc60805d
129a84457aed4c45bc900998b5e11c03023264208James Dong/* ------------------------------------------------------------------
229a84457aed4c45bc900998b5e11c03023264208James Dong * Copyright (C) 1998-2009 PacketVideo
329a84457aed4c45bc900998b5e11c03023264208James Dong *
429a84457aed4c45bc900998b5e11c03023264208James Dong * Licensed under the Apache License, Version 2.0 (the "License");
529a84457aed4c45bc900998b5e11c03023264208James Dong * you may not use this file except in compliance with the License.
629a84457aed4c45bc900998b5e11c03023264208James Dong * You may obtain a copy of the License at
729a84457aed4c45bc900998b5e11c03023264208James Dong *
829a84457aed4c45bc900998b5e11c03023264208James Dong *      http://www.apache.org/licenses/LICENSE-2.0
929a84457aed4c45bc900998b5e11c03023264208James Dong *
1029a84457aed4c45bc900998b5e11c03023264208James Dong * Unless required by applicable law or agreed to in writing, software
1129a84457aed4c45bc900998b5e11c03023264208James Dong * distributed under the License is distributed on an "AS IS" BASIS,
1229a84457aed4c45bc900998b5e11c03023264208James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
1329a84457aed4c45bc900998b5e11c03023264208James Dong * express or implied.
1429a84457aed4c45bc900998b5e11c03023264208James Dong * See the License for the specific language governing permissions
1529a84457aed4c45bc900998b5e11c03023264208James Dong * and limitations under the License.
1629a84457aed4c45bc900998b5e11c03023264208James Dong * -------------------------------------------------------------------
1729a84457aed4c45bc900998b5e11c03023264208James Dong */
1829a84457aed4c45bc900998b5e11c03023264208James Dong
1929a84457aed4c45bc900998b5e11c03023264208James Dong#ifndef _SAD_HALFPEL_INLINE_H_
2029a84457aed4c45bc900998b5e11c03023264208James Dong#define _SAD_HALFPEL_INLINE_H_
2129a84457aed4c45bc900998b5e11c03023264208James Dong
2229a84457aed4c45bc900998b5e11c03023264208James Dong#ifdef __cplusplus
2329a84457aed4c45bc900998b5e11c03023264208James Dongextern "C"
2429a84457aed4c45bc900998b5e11c03023264208James Dong{
2529a84457aed4c45bc900998b5e11c03023264208James Dong#endif
2629a84457aed4c45bc900998b5e11c03023264208James Dong
27f5af6314db25ff3bef9bd2eeba201bc6cc60805dMartin Storsjo/* Intentionally not using the gcc asm version, since it (if fixed so
28f5af6314db25ff3bef9bd2eeba201bc6cc60805dMartin Storsjo * as to not crash - the current register constraints are faulty) is
29f5af6314db25ff3bef9bd2eeba201bc6cc60805dMartin Storsjo * slightly slower than the plain C version on modern GCC versions. */
30f5af6314db25ff3bef9bd2eeba201bc6cc60805dMartin Storsjo#if !defined(__CC_ARM) /* Generic C version */
3129a84457aed4c45bc900998b5e11c03023264208James Dong
3229a84457aed4c45bc900998b5e11c03023264208James Dong    __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
3329a84457aed4c45bc900998b5e11c03023264208James Dong    {
3429a84457aed4c45bc900998b5e11c03023264208James Dong        tmp = (tmp2 >> 1) - tmp;
3529a84457aed4c45bc900998b5e11c03023264208James Dong        if (tmp > 0) sad += tmp;
3629a84457aed4c45bc900998b5e11c03023264208James Dong        else sad -= tmp;
3729a84457aed4c45bc900998b5e11c03023264208James Dong
3829a84457aed4c45bc900998b5e11c03023264208James Dong        return sad;
3929a84457aed4c45bc900998b5e11c03023264208James Dong    }
4029a84457aed4c45bc900998b5e11c03023264208James Dong
4129a84457aed4c45bc900998b5e11c03023264208James Dong    __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
4229a84457aed4c45bc900998b5e11c03023264208James Dong    {
4329a84457aed4c45bc900998b5e11c03023264208James Dong        tmp = (tmp >> 2) - tmp2;
4429a84457aed4c45bc900998b5e11c03023264208James Dong        if (tmp > 0) sad += tmp;
4529a84457aed4c45bc900998b5e11c03023264208James Dong        else sad -= tmp;
4629a84457aed4c45bc900998b5e11c03023264208James Dong
4729a84457aed4c45bc900998b5e11c03023264208James Dong        return sad;
4829a84457aed4c45bc900998b5e11c03023264208James Dong    }
4929a84457aed4c45bc900998b5e11c03023264208James Dong
5029a84457aed4c45bc900998b5e11c03023264208James Dong#elif defined(__CC_ARM)  /* only work with arm v5 */
5129a84457aed4c45bc900998b5e11c03023264208James Dong
5229a84457aed4c45bc900998b5e11c03023264208James Dong    __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
5329a84457aed4c45bc900998b5e11c03023264208James Dong    {
5429a84457aed4c45bc900998b5e11c03023264208James Dong        __asm
5529a84457aed4c45bc900998b5e11c03023264208James Dong        {
5629a84457aed4c45bc900998b5e11c03023264208James Dong            rsbs    tmp, tmp, tmp2, asr #1 ;
5729a84457aed4c45bc900998b5e11c03023264208James Dong            rsbmi   tmp, tmp, #0 ;
5829a84457aed4c45bc900998b5e11c03023264208James Dong            add     sad, sad, tmp ;
5929a84457aed4c45bc900998b5e11c03023264208James Dong        }
6029a84457aed4c45bc900998b5e11c03023264208James Dong
6129a84457aed4c45bc900998b5e11c03023264208James Dong        return sad;
6229a84457aed4c45bc900998b5e11c03023264208James Dong    }
6329a84457aed4c45bc900998b5e11c03023264208James Dong
6429a84457aed4c45bc900998b5e11c03023264208James Dong    __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
6529a84457aed4c45bc900998b5e11c03023264208James Dong    {
6629a84457aed4c45bc900998b5e11c03023264208James Dong        __asm
6729a84457aed4c45bc900998b5e11c03023264208James Dong        {
6829a84457aed4c45bc900998b5e11c03023264208James Dong            rsbs    tmp, tmp2, tmp, asr #2 ;
6929a84457aed4c45bc900998b5e11c03023264208James Dong            rsbmi   tmp, tmp, #0 ;
7029a84457aed4c45bc900998b5e11c03023264208James Dong            add     sad, sad, tmp ;
7129a84457aed4c45bc900998b5e11c03023264208James Dong        }
7229a84457aed4c45bc900998b5e11c03023264208James Dong
7329a84457aed4c45bc900998b5e11c03023264208James Dong        return sad;
7429a84457aed4c45bc900998b5e11c03023264208James Dong    }
7529a84457aed4c45bc900998b5e11c03023264208James Dong
7629a84457aed4c45bc900998b5e11c03023264208James Dong#elif defined(__GNUC__) && defined(__arm__) /* ARM GNU COMPILER  */
7729a84457aed4c45bc900998b5e11c03023264208James Dong
7829a84457aed4c45bc900998b5e11c03023264208James Dong    __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
7929a84457aed4c45bc900998b5e11c03023264208James Dong    {
8029a84457aed4c45bc900998b5e11c03023264208James Dong__asm__ volatile("rsbs	%1, %1, %2, asr #1\n\trsbmi %1, %1, #0\n\tadd  %0, %0, %1": "=r"(sad), "=r"(tmp): "r"(tmp2));
8129a84457aed4c45bc900998b5e11c03023264208James Dong
8229a84457aed4c45bc900998b5e11c03023264208James Dong        return sad;
8329a84457aed4c45bc900998b5e11c03023264208James Dong    }
8429a84457aed4c45bc900998b5e11c03023264208James Dong
8529a84457aed4c45bc900998b5e11c03023264208James Dong    __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
8629a84457aed4c45bc900998b5e11c03023264208James Dong    {
8729a84457aed4c45bc900998b5e11c03023264208James Dong__asm__ volatile("rsbs	%1, %2, %1, asr #2\n\trsbmi %1, %1, #0\n\tadd	%0, %0, %1": "=r"(sad), "=r"(tmp): "r"(tmp2));
8829a84457aed4c45bc900998b5e11c03023264208James Dong
8929a84457aed4c45bc900998b5e11c03023264208James Dong        return sad;
9029a84457aed4c45bc900998b5e11c03023264208James Dong    }
9129a84457aed4c45bc900998b5e11c03023264208James Dong
9229a84457aed4c45bc900998b5e11c03023264208James Dong#endif
9329a84457aed4c45bc900998b5e11c03023264208James Dong
9429a84457aed4c45bc900998b5e11c03023264208James Dong#ifdef __cplusplus
9529a84457aed4c45bc900998b5e11c03023264208James Dong}
9629a84457aed4c45bc900998b5e11c03023264208James Dong#endif
9729a84457aed4c45bc900998b5e11c03023264208James Dong
9829a84457aed4c45bc900998b5e11c03023264208James Dong#endif //_SAD_HALFPEL_INLINE_H_
9929a84457aed4c45bc900998b5e11c03023264208James Dong
100