• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/mathops.h

Go to the documentation of this file.
00001 /*
00002  * simple math operations
00003  * Copyright (c) 2001, 2002 Fabrice Bellard
00004  * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 #ifndef AVCODEC_MATHOPS_H
00023 #define AVCODEC_MATHOPS_H
00024 
00025 #include "libavutil/common.h"
00026 
00027 #if   ARCH_ARM
00028 #   include "arm/mathops.h"
00029 #elif ARCH_AVR32
00030 #   include "avr32/mathops.h"
00031 #elif ARCH_BFIN
00032 #   include "bfin/mathops.h"
00033 #elif ARCH_MIPS
00034 #   include "mips/mathops.h"
00035 #elif ARCH_PPC
00036 #   include "ppc/mathops.h"
00037 #elif ARCH_X86
00038 #   include "x86/mathops.h"
00039 #endif
00040 
00041 /* generic implementation */
00042 
00043 #ifndef MULL
00044 #   define MULL(a,b,s) (((int64_t)(a) * (int64_t)(b)) >> (s))
00045 #endif
00046 
00047 #ifndef MULH
00048 //gcc 3.4 creates an incredibly bloated mess out of this
00049 //#    define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32)
00050 
00051 static av_always_inline int MULH(int a, int b){
00052     return ((int64_t)(a) * (int64_t)(b))>>32;
00053 }
00054 #endif
00055 
00056 #ifndef UMULH
00057 static av_always_inline unsigned UMULH(unsigned a, unsigned b){
00058     return ((uint64_t)(a) * (uint64_t)(b))>>32;
00059 }
00060 #endif
00061 
00062 #ifndef MUL64
00063 #   define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
00064 #endif
00065 
00066 #ifndef MAC64
00067 #   define MAC64(d, a, b) ((d) += MUL64(a, b))
00068 #endif
00069 
00070 #ifndef MLS64
00071 #   define MLS64(d, a, b) ((d) -= MUL64(a, b))
00072 #endif
00073 
00074 /* signed 16x16 -> 32 multiply add accumulate */
00075 #ifndef MAC16
00076 #   define MAC16(rt, ra, rb) rt += (ra) * (rb)
00077 #endif
00078 
00079 /* signed 16x16 -> 32 multiply */
00080 #ifndef MUL16
00081 #   define MUL16(ra, rb) ((ra) * (rb))
00082 #endif
00083 
00084 #ifndef MLS16
00085 #   define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
00086 #endif
00087 
00088 /* median of 3 */
00089 #ifndef mid_pred
00090 #define mid_pred mid_pred
00091 static inline av_const int mid_pred(int a, int b, int c)
00092 {
00093 #if 0
00094     int t= (a-b)&((a-b)>>31);
00095     a-=t;
00096     b+=t;
00097     b-= (b-c)&((b-c)>>31);
00098     b+= (a-b)&((a-b)>>31);
00099 
00100     return b;
00101 #else
00102     if(a>b){
00103         if(c>b){
00104             if(c>a) b=a;
00105             else    b=c;
00106         }
00107     }else{
00108         if(b>c){
00109             if(c>a) b=c;
00110             else    b=a;
00111         }
00112     }
00113     return b;
00114 #endif
00115 }
00116 #endif
00117 
00118 #ifndef sign_extend
00119 static inline av_const int sign_extend(int val, unsigned bits)
00120 {
00121     return (val << (INT_BIT - bits)) >> (INT_BIT - bits);
00122 }
00123 #endif
00124 
00125 #ifndef zero_extend
00126 static inline av_const unsigned zero_extend(unsigned val, unsigned bits)
00127 {
00128     return (val << (INT_BIT - bits)) >> (INT_BIT - bits);
00129 }
00130 #endif
00131 
00132 #ifndef COPY3_IF_LT
00133 #define COPY3_IF_LT(x, y, a, b, c, d)\
00134 if ((y) < (x)) {\
00135     (x) = (y);\
00136     (a) = (b);\
00137     (c) = (d);\
00138 }
00139 #endif
00140 
00141 #ifndef NEG_SSR32
00142 #   define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
00143 #endif
00144 
00145 #ifndef NEG_USR32
00146 #   define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
00147 #endif
00148 
00149 #endif /* AVCODEC_MATHOPS_H */
00150 

Generated on Fri Sep 16 2011 17:17:34 for FFmpeg by  doxygen 1.7.1