Mercurial > libavutil.hg
comparison common.h @ 481:f4187c1c15a6 libavutil
Reapply r12489: Add pure, const and malloc attributes to proper functions
in libavutil.
Fix a compilation failure in r12489.
author | zuxy |
---|---|
date | Wed, 19 Mar 2008 06:17:43 +0000 |
parents | 8d2c05ebf5f1 |
children | 2e4747b3d034 |
comparison
equal
deleted
inserted
replaced
480:c4ce55ea2c04 | 481:f4187c1c15a6 |
---|---|
55 #else | 55 #else |
56 # define av_noinline | 56 # define av_noinline |
57 #endif | 57 #endif |
58 #endif | 58 #endif |
59 | 59 |
60 #ifndef av_pure | |
61 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) | |
62 # define av_pure __attribute__((pure)) | |
63 #else | |
64 # define av_pure | |
65 #endif | |
66 #endif | |
67 | |
68 #ifndef av_const | |
69 #if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ > 5) | |
70 # define av_const __attribute__((const)) | |
71 #else | |
72 # define av_const | |
73 #endif | |
74 #endif | |
75 | |
60 #ifdef HAVE_AV_CONFIG_H | 76 #ifdef HAVE_AV_CONFIG_H |
61 # include "internal.h" | 77 # include "internal.h" |
62 #endif /* HAVE_AV_CONFIG_H */ | 78 #endif /* HAVE_AV_CONFIG_H */ |
63 | 79 |
64 #ifndef attribute_deprecated | 80 #ifndef attribute_deprecated |
92 #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) | 108 #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) |
93 | 109 |
94 /* misc math functions */ | 110 /* misc math functions */ |
95 extern const uint8_t ff_log2_tab[256]; | 111 extern const uint8_t ff_log2_tab[256]; |
96 | 112 |
97 static inline int av_log2(unsigned int v) | 113 static inline av_const int av_log2(unsigned int v) |
98 { | 114 { |
99 int n = 0; | 115 int n = 0; |
100 if (v & 0xffff0000) { | 116 if (v & 0xffff0000) { |
101 v >>= 16; | 117 v >>= 16; |
102 n += 16; | 118 n += 16; |
108 n += ff_log2_tab[v]; | 124 n += ff_log2_tab[v]; |
109 | 125 |
110 return n; | 126 return n; |
111 } | 127 } |
112 | 128 |
113 static inline int av_log2_16bit(unsigned int v) | 129 static inline av_const int av_log2_16bit(unsigned int v) |
114 { | 130 { |
115 int n = 0; | 131 int n = 0; |
116 if (v & 0xff00) { | 132 if (v & 0xff00) { |
117 v >>= 8; | 133 v >>= 8; |
118 n += 8; | 134 n += 8; |
121 | 137 |
122 return n; | 138 return n; |
123 } | 139 } |
124 | 140 |
125 /* median of 3 */ | 141 /* median of 3 */ |
126 static inline int mid_pred(int a, int b, int c) | 142 static inline av_const int mid_pred(int a, int b, int c) |
127 { | 143 { |
128 #ifdef HAVE_CMOV | 144 #ifdef HAVE_CMOV |
129 int i=b; | 145 int i=b; |
130 asm volatile( | 146 asm volatile( |
131 "cmp %2, %1 \n\t" | 147 "cmp %2, %1 \n\t" |
168 * @param a value to clip | 184 * @param a value to clip |
169 * @param amin minimum value of the clip range | 185 * @param amin minimum value of the clip range |
170 * @param amax maximum value of the clip range | 186 * @param amax maximum value of the clip range |
171 * @return clipped value | 187 * @return clipped value |
172 */ | 188 */ |
173 static inline int av_clip(int a, int amin, int amax) | 189 static inline av_const int av_clip(int a, int amin, int amax) |
174 { | 190 { |
175 if (a < amin) return amin; | 191 if (a < amin) return amin; |
176 else if (a > amax) return amax; | 192 else if (a > amax) return amax; |
177 else return a; | 193 else return a; |
178 } | 194 } |
180 /** | 196 /** |
181 * clip a signed integer value into the 0-255 range | 197 * clip a signed integer value into the 0-255 range |
182 * @param a value to clip | 198 * @param a value to clip |
183 * @return clipped value | 199 * @return clipped value |
184 */ | 200 */ |
185 static inline uint8_t av_clip_uint8(int a) | 201 static inline av_const uint8_t av_clip_uint8(int a) |
186 { | 202 { |
187 if (a&(~255)) return (-a)>>31; | 203 if (a&(~255)) return (-a)>>31; |
188 else return a; | 204 else return a; |
189 } | 205 } |
190 | 206 |
191 /** | 207 /** |
192 * clip a signed integer value into the -32768,32767 range | 208 * clip a signed integer value into the -32768,32767 range |
193 * @param a value to clip | 209 * @param a value to clip |
194 * @return clipped value | 210 * @return clipped value |
195 */ | 211 */ |
196 static inline int16_t av_clip_int16(int a) | 212 static inline av_const int16_t av_clip_int16(int a) |
197 { | 213 { |
198 if ((a+32768) & ~65535) return (a>>31) ^ 32767; | 214 if ((a+32768) & ~65535) return (a>>31) ^ 32767; |
199 else return a; | 215 else return a; |
200 } | 216 } |
201 | 217 |
202 /* math */ | 218 /* math */ |
203 int64_t ff_gcd(int64_t a, int64_t b); | 219 int64_t av_const ff_gcd(int64_t a, int64_t b); |
204 | 220 |
205 /** | 221 /** |
206 * converts fourcc string to int | 222 * converts fourcc string to int |
207 */ | 223 */ |
208 static inline int ff_get_fourcc(const char *s){ | 224 static inline av_pure int ff_get_fourcc(const char *s){ |
209 #ifdef HAVE_AV_CONFIG_H | 225 #ifdef HAVE_AV_CONFIG_H |
210 assert( strlen(s)==4 ); | 226 assert( strlen(s)==4 ); |
211 #endif | 227 #endif |
212 | 228 |
213 return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24); | 229 return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24); |