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
2742d515121f11389df082dd02319904c99dd50cd6Martin Storsjo/* Intentionally not using the gcc asm version, since it is
28f5af6314db25ff3bef9bd2eeba201bc6cc60805dMartin Storsjo * slightly slower than the plain C version on modern GCC versions. */
29f5af6314db25ff3bef9bd2eeba201bc6cc60805dMartin Storsjo#if !defined(__CC_ARM) /* Generic C version */
3029a84457aed4c45bc900998b5e11c03023264208James Dong
3129a84457aed4c45bc900998b5e11c03023264208James Dong    __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
3229a84457aed4c45bc900998b5e11c03023264208James Dong    {
3329a84457aed4c45bc900998b5e11c03023264208James Dong        tmp = (tmp2 >> 1) - tmp;
3429a84457aed4c45bc900998b5e11c03023264208James Dong        if (tmp > 0) sad += tmp;
3529a84457aed4c45bc900998b5e11c03023264208James Dong        else sad -= tmp;
3629a84457aed4c45bc900998b5e11c03023264208James Dong
3729a84457aed4c45bc900998b5e11c03023264208James Dong        return sad;
3829a84457aed4c45bc900998b5e11c03023264208James Dong    }
3929a84457aed4c45bc900998b5e11c03023264208James Dong
4029a84457aed4c45bc900998b5e11c03023264208James Dong    __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
4129a84457aed4c45bc900998b5e11c03023264208James Dong    {
4229a84457aed4c45bc900998b5e11c03023264208James Dong        tmp = (tmp >> 2) - tmp2;
4329a84457aed4c45bc900998b5e11c03023264208James Dong        if (tmp > 0) sad += tmp;
4429a84457aed4c45bc900998b5e11c03023264208James Dong        else sad -= tmp;
4529a84457aed4c45bc900998b5e11c03023264208James Dong
4629a84457aed4c45bc900998b5e11c03023264208James Dong        return sad;
4729a84457aed4c45bc900998b5e11c03023264208James Dong    }
4829a84457aed4c45bc900998b5e11c03023264208James Dong
4929a84457aed4c45bc900998b5e11c03023264208James Dong#elif defined(__CC_ARM)  /* only work with arm v5 */
5029a84457aed4c45bc900998b5e11c03023264208James Dong
5129a84457aed4c45bc900998b5e11c03023264208James Dong    __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
5229a84457aed4c45bc900998b5e11c03023264208James Dong    {
5329a84457aed4c45bc900998b5e11c03023264208James Dong        __asm
5429a84457aed4c45bc900998b5e11c03023264208James Dong        {
5529a84457aed4c45bc900998b5e11c03023264208James Dong            rsbs    tmp, tmp, tmp2, asr #1 ;
5629a84457aed4c45bc900998b5e11c03023264208James Dong            rsbmi   tmp, tmp, #0 ;
5729a84457aed4c45bc900998b5e11c03023264208James Dong            add     sad, sad, tmp ;
5829a84457aed4c45bc900998b5e11c03023264208James Dong        }
5929a84457aed4c45bc900998b5e11c03023264208James Dong
6029a84457aed4c45bc900998b5e11c03023264208James Dong        return sad;
6129a84457aed4c45bc900998b5e11c03023264208James Dong    }
6229a84457aed4c45bc900998b5e11c03023264208James Dong
6329a84457aed4c45bc900998b5e11c03023264208James Dong    __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
6429a84457aed4c45bc900998b5e11c03023264208James Dong    {
6529a84457aed4c45bc900998b5e11c03023264208James Dong        __asm
6629a84457aed4c45bc900998b5e11c03023264208James Dong        {
6729a84457aed4c45bc900998b5e11c03023264208James Dong            rsbs    tmp, tmp2, tmp, asr #2 ;
6829a84457aed4c45bc900998b5e11c03023264208James Dong            rsbmi   tmp, tmp, #0 ;
6929a84457aed4c45bc900998b5e11c03023264208James Dong            add     sad, sad, tmp ;
7029a84457aed4c45bc900998b5e11c03023264208James Dong        }
7129a84457aed4c45bc900998b5e11c03023264208James Dong
7229a84457aed4c45bc900998b5e11c03023264208James Dong        return sad;
7329a84457aed4c45bc900998b5e11c03023264208James Dong    }
7429a84457aed4c45bc900998b5e11c03023264208James Dong
7529a84457aed4c45bc900998b5e11c03023264208James Dong#elif defined(__GNUC__) && defined(__arm__) /* ARM GNU COMPILER  */
7629a84457aed4c45bc900998b5e11c03023264208James Dong
7729a84457aed4c45bc900998b5e11c03023264208James Dong    __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
7829a84457aed4c45bc900998b5e11c03023264208James Dong    {
79ccde1257952d2c073e51ecba6180060570ffa41fMartin Storsjo        __asm__ volatile(
80ccde1257952d2c073e51ecba6180060570ffa41fMartin Storsjo            "rsbs       %1, %1, %2, asr #1\n\t"
81ccde1257952d2c073e51ecba6180060570ffa41fMartin Storsjo            "rsbmi      %1, %1, #0\n\t"
82ccde1257952d2c073e51ecba6180060570ffa41fMartin Storsjo            "add        %0, %0, %1"
833fdb405597f0e062a9bb8af20199c5e67f0f764cMartin Storsjo            : "+r"(sad), "+r"(tmp)
84ccde1257952d2c073e51ecba6180060570ffa41fMartin Storsjo            : "r"(tmp2)
85ccde1257952d2c073e51ecba6180060570ffa41fMartin Storsjo        );
8629a84457aed4c45bc900998b5e11c03023264208James Dong
8729a84457aed4c45bc900998b5e11c03023264208James Dong        return sad;
8829a84457aed4c45bc900998b5e11c03023264208James Dong    }
8929a84457aed4c45bc900998b5e11c03023264208James Dong
9029a84457aed4c45bc900998b5e11c03023264208James Dong    __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
9129a84457aed4c45bc900998b5e11c03023264208James Dong    {
92ccde1257952d2c073e51ecba6180060570ffa41fMartin Storsjo        __asm__ volatile(
93ccde1257952d2c073e51ecba6180060570ffa41fMartin Storsjo            "rsbs       %1, %2, %1, asr #2\n\t"
94ccde1257952d2c073e51ecba6180060570ffa41fMartin Storsjo            "rsbmi      %1, %1, #0\n\t"
95ccde1257952d2c073e51ecba6180060570ffa41fMartin Storsjo            "add        %0, %0, %1"
963fdb405597f0e062a9bb8af20199c5e67f0f764cMartin Storsjo            : "+r"(sad), "+r"(tmp)
97ccde1257952d2c073e51ecba6180060570ffa41fMartin Storsjo            : "r"(tmp2)
98ccde1257952d2c073e51ecba6180060570ffa41fMartin Storsjo        );
9929a84457aed4c45bc900998b5e11c03023264208James Dong
10029a84457aed4c45bc900998b5e11c03023264208James Dong        return sad;
10129a84457aed4c45bc900998b5e11c03023264208James Dong    }
10229a84457aed4c45bc900998b5e11c03023264208James Dong
10329a84457aed4c45bc900998b5e11c03023264208James Dong#endif
10429a84457aed4c45bc900998b5e11c03023264208James Dong
10529a84457aed4c45bc900998b5e11c03023264208James Dong#ifdef __cplusplus
10629a84457aed4c45bc900998b5e11c03023264208James Dong}
10729a84457aed4c45bc900998b5e11c03023264208James Dong#endif
10829a84457aed4c45bc900998b5e11c03023264208James Dong
10929a84457aed4c45bc900998b5e11c03023264208James Dong#endif //_SAD_HALFPEL_INLINE_H_
11029a84457aed4c45bc900998b5e11c03023264208James Dong
111