nengel@2: /* nengel@2: * simple math operations nengel@2: * Copyright (c) 2001, 2002 Fabrice Bellard nengel@2: * Copyright (c) 2006 Michael Niedermayer et al nengel@2: * nengel@2: * This file is part of FFmpeg. nengel@2: * nengel@2: * FFmpeg is free software; you can redistribute it and/or nengel@2: * modify it under the terms of the GNU Lesser General Public nengel@2: * License as published by the Free Software Foundation; either nengel@2: * version 2.1 of the License, or (at your option) any later version. nengel@2: * nengel@2: * FFmpeg is distributed in the hope that it will be useful, nengel@2: * but WITHOUT ANY WARRANTY; without even the implied warranty of nengel@2: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU nengel@2: * Lesser General Public License for more details. nengel@2: * nengel@2: * You should have received a copy of the GNU Lesser General Public nengel@2: * License along with FFmpeg; if not, write to the Free Software nengel@2: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA nengel@2: */ nengel@2: #ifndef AVCODEC_MATHOPS_H nengel@2: #define AVCODEC_MATHOPS_H nengel@2: nengel@2: #include "libavutil/common.h" nengel@2: #include "libavutil/internal.h" nengel@2: nengel@2: #if ARCH_ARM nengel@2: # include "arm/mathops.h" nengel@2: #elif ARCH_PPC nengel@2: # include "ppc/mathops.h" nengel@2: #elif ARCH_X86 nengel@2: # include "x86/mathops.h" nengel@2: #endif nengel@2: nengel@2: /* generic implementation */ nengel@2: nengel@2: #ifndef MULL nengel@2: # define MULL(a,b,s) (((int64_t)(a) * (int64_t)(b)) >> (s)) nengel@2: #endif nengel@2: nengel@2: #ifndef MULH nengel@2: //gcc 3.4 creates an incredibly bloated mess out of this nengel@2: //# define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32) nengel@2: nengel@2: static av_always_inline int MULH(int a, int b){ nengel@2: return ((int64_t)(a) * (int64_t)(b))>>32; nengel@2: } nengel@2: #endif nengel@2: nengel@2: #ifndef UMULH nengel@2: static av_always_inline unsigned UMULH(unsigned a, unsigned b){ nengel@2: return ((uint64_t)(a) * (uint64_t)(b))>>32; nengel@2: } nengel@2: #endif nengel@2: nengel@2: #ifndef MUL64 nengel@2: # define MUL64(a,b) ((int64_t)(a) * (int64_t)(b)) nengel@2: #endif nengel@2: nengel@2: #ifndef MAC64 nengel@2: # define MAC64(d, a, b) ((d) += MUL64(a, b)) nengel@2: #endif nengel@2: nengel@2: #ifndef MLS64 nengel@2: # define MLS64(d, a, b) ((d) -= MUL64(a, b)) nengel@2: #endif nengel@2: nengel@2: /* signed 16x16 -> 32 multiply add accumulate */ nengel@2: #ifndef MAC16 nengel@2: # define MAC16(rt, ra, rb) rt += (ra) * (rb) nengel@2: #endif nengel@2: nengel@2: /* signed 16x16 -> 32 multiply */ nengel@2: #ifndef MUL16 nengel@2: # define MUL16(ra, rb) ((ra) * (rb)) nengel@2: #endif nengel@2: nengel@2: #ifndef MLS16 nengel@2: # define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb)) nengel@2: #endif nengel@2: nengel@2: /* median of 3 */ nengel@2: #ifndef mid_pred nengel@2: #define mid_pred mid_pred nengel@2: static inline av_const int mid_pred(int a, int b, int c) nengel@2: { nengel@2: #if 0 nengel@2: int t= (a-b)&((a-b)>>31); nengel@2: a-=t; nengel@2: b+=t; nengel@2: b-= (b-c)&((b-c)>>31); nengel@2: b+= (a-b)&((a-b)>>31); nengel@2: nengel@2: return b; nengel@2: #else nengel@2: if(a>b){ nengel@2: if(c>b){ nengel@2: if(c>a) b=a; nengel@2: else b=c; nengel@2: } nengel@2: }else{ nengel@2: if(b>c){ nengel@2: if(c>a) b=c; nengel@2: else b=a; nengel@2: } nengel@2: } nengel@2: return b; nengel@2: #endif nengel@2: } nengel@2: #endif nengel@2: nengel@2: #ifndef sign_extend nengel@2: static inline av_const int sign_extend(int val, unsigned bits) nengel@2: { nengel@2: return (val << (INT_BIT - bits)) >> (INT_BIT - bits); nengel@2: } nengel@2: #endif nengel@2: nengel@2: #ifndef zero_extend nengel@2: static inline av_const unsigned zero_extend(unsigned val, unsigned bits) nengel@2: { nengel@2: return (val << (INT_BIT - bits)) >> (INT_BIT - bits); nengel@2: } nengel@2: #endif nengel@2: nengel@2: #ifndef COPY3_IF_LT nengel@2: #define COPY3_IF_LT(x, y, a, b, c, d)\ nengel@2: if ((y) < (x)) {\ nengel@2: (x) = (y);\ nengel@2: (a) = (b);\ nengel@2: (c) = (d);\ nengel@2: } nengel@2: #endif nengel@2: nengel@2: #ifndef NEG_SSR32 nengel@2: # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) nengel@2: #endif nengel@2: nengel@2: #ifndef NEG_USR32 nengel@2: # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) nengel@2: #endif nengel@2: nengel@2: #endif /* AVCODEC_MATHOPS_H */ nengel@2: