00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef AVCODEC_MATHOPS_H
00023 #define AVCODEC_MATHOPS_H
00024
00025 #include "libavutil/common.h"
00026 #include "config.h"
00027
00028 #if ARCH_ARM
00029 # include "arm/mathops.h"
00030 #elif ARCH_AVR32
00031 # include "avr32/mathops.h"
00032 #elif ARCH_BFIN
00033 # include "bfin/mathops.h"
00034 #elif ARCH_MIPS
00035 # include "mips/mathops.h"
00036 #elif ARCH_PPC
00037 # include "ppc/mathops.h"
00038 #elif ARCH_X86
00039 # include "x86/mathops.h"
00040 #endif
00041
00042
00043
00044 #ifndef MUL64
00045 # define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
00046 #endif
00047
00048 #ifndef MULL
00049 # define MULL(a,b,s) (MUL64(a, b) >> (s))
00050 #endif
00051
00052 #ifndef MULH
00053 static av_always_inline int MULH(int a, int b){
00054 return MUL64(a, b) >> 32;
00055 }
00056 #endif
00057
00058 #ifndef UMULH
00059 static av_always_inline unsigned UMULH(unsigned a, unsigned b){
00060 return ((uint64_t)(a) * (uint64_t)(b))>>32;
00061 }
00062 #endif
00063
00064 #ifndef MAC64
00065 # define MAC64(d, a, b) ((d) += MUL64(a, b))
00066 #endif
00067
00068 #ifndef MLS64
00069 # define MLS64(d, a, b) ((d) -= MUL64(a, b))
00070 #endif
00071
00072
00073 #ifndef MAC16
00074 # define MAC16(rt, ra, rb) rt += (ra) * (rb)
00075 #endif
00076
00077
00078 #ifndef MUL16
00079 # define MUL16(ra, rb) ((ra) * (rb))
00080 #endif
00081
00082 #ifndef MLS16
00083 # define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
00084 #endif
00085
00086
00087 #ifndef mid_pred
00088 #define mid_pred mid_pred
00089 static inline av_const int mid_pred(int a, int b, int c)
00090 {
00091 #if 0
00092 int t= (a-b)&((a-b)>>31);
00093 a-=t;
00094 b+=t;
00095 b-= (b-c)&((b-c)>>31);
00096 b+= (a-b)&((a-b)>>31);
00097
00098 return b;
00099 #else
00100 if(a>b){
00101 if(c>b){
00102 if(c>a) b=a;
00103 else b=c;
00104 }
00105 }else{
00106 if(b>c){
00107 if(c>a) b=c;
00108 else b=a;
00109 }
00110 }
00111 return b;
00112 #endif
00113 }
00114 #endif
00115
00116 #ifndef sign_extend
00117 static inline av_const int sign_extend(int val, unsigned bits)
00118 {
00119 unsigned shift = 8 * sizeof(int) - bits;
00120 union { unsigned u; int s; } v = { (unsigned) val << shift };
00121 return v.s >> shift;
00122 }
00123 #endif
00124
00125 #ifndef zero_extend
00126 static inline av_const unsigned zero_extend(unsigned val, unsigned bits)
00127 {
00128 return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - 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 #if HAVE_BIGENDIAN
00150 # ifndef PACK_2U8
00151 # define PACK_2U8(a,b) (((a) << 8) | (b))
00152 # endif
00153 # ifndef PACK_4U8
00154 # define PACK_4U8(a,b,c,d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
00155 # endif
00156 # ifndef PACK_2U16
00157 # define PACK_2U16(a,b) (((a) << 16) | (b))
00158 # endif
00159 #else
00160 # ifndef PACK_2U8
00161 # define PACK_2U8(a,b) (((b) << 8) | (a))
00162 # endif
00163 # ifndef PACK_4U2
00164 # define PACK_4U8(a,b,c,d) (((d) << 24) | ((c) << 16) | ((b) << 8) | (a))
00165 # endif
00166 # ifndef PACK_2U16
00167 # define PACK_2U16(a,b) (((b) << 16) | (a))
00168 # endif
00169 #endif
00170
00171 #ifndef PACK_2S8
00172 # define PACK_2S8(a,b) PACK_2U8((a)&255, (b)&255)
00173 #endif
00174 #ifndef PACK_4S8
00175 # define PACK_4S8(a,b,c,d) PACK_4U8((a)&255, (b)&255, (c)&255, (d)&255)
00176 #endif
00177 #ifndef PACK_2S16
00178 # define PACK_2S16(a,b) PACK_2U16((a)&0xffff, (b)&0xffff)
00179 #endif
00180
00181 #endif
00182