Libav 0.7.1
|
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 Libav. 00007 * 00008 * Libav 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 * Libav 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 Libav; 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 #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 /* generic implementation */ 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 /* signed 16x16 -> 32 multiply add accumulate */ 00073 #ifndef MAC16 00074 # define MAC16(rt, ra, rb) rt += (ra) * (rb) 00075 #endif 00076 00077 /* signed 16x16 -> 32 multiply */ 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 /* median of 3 */ 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 return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits); 00120 } 00121 #endif 00122 00123 #ifndef zero_extend 00124 static inline av_const unsigned zero_extend(unsigned val, unsigned bits) 00125 { 00126 return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits); 00127 } 00128 #endif 00129 00130 #ifndef COPY3_IF_LT 00131 #define COPY3_IF_LT(x, y, a, b, c, d)\ 00132 if ((y) < (x)) {\ 00133 (x) = (y);\ 00134 (a) = (b);\ 00135 (c) = (d);\ 00136 } 00137 #endif 00138 00139 #ifndef NEG_SSR32 00140 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) 00141 #endif 00142 00143 #ifndef NEG_USR32 00144 # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) 00145 #endif 00146 00147 #if HAVE_BIGENDIAN 00148 # ifndef PACK_2U8 00149 # define PACK_2U8(a,b) (((a) << 8) | (b)) 00150 # endif 00151 # ifndef PACK_4U8 00152 # define PACK_4U8(a,b,c,d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) 00153 # endif 00154 # ifndef PACK_2U16 00155 # define PACK_2U16(a,b) (((a) << 16) | (b)) 00156 # endif 00157 #else 00158 # ifndef PACK_2U8 00159 # define PACK_2U8(a,b) (((b) << 8) | (a)) 00160 # endif 00161 # ifndef PACK_4U2 00162 # define PACK_4U8(a,b,c,d) (((d) << 24) | ((c) << 16) | ((b) << 8) | (a)) 00163 # endif 00164 # ifndef PACK_2U16 00165 # define PACK_2U16(a,b) (((b) << 16) | (a)) 00166 # endif 00167 #endif 00168 00169 #ifndef PACK_2S8 00170 # define PACK_2S8(a,b) PACK_2U8((a)&255, (b)&255) 00171 #endif 00172 #ifndef PACK_4S8 00173 # define PACK_4S8(a,b,c,d) PACK_4U8((a)&255, (b)&255, (c)&255, (d)&255) 00174 #endif 00175 #ifndef PACK_2S16 00176 # define PACK_2S16(a,b) PACK_2U16((a)&0xffff, (b)&0xffff) 00177 #endif 00178 00179 #endif /* AVCODEC_MATHOPS_H */ 00180