44
44
#ifndef av_always_inline
45
45
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
46
46
# define av_always_inline __attribute__((always_inline)) inline
48
# define av_always_inline inline
53
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
47
54
# define av_noinline __attribute__((noinline))
49
# define av_always_inline inline
50
56
# define av_noinline
61
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
62
# define av_pure __attribute__((pure))
69
#if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ > 5)
70
# define av_const __attribute__((const))
77
#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 2)
78
# define av_cold __attribute__((cold))
54
84
#ifdef HAVE_AV_CONFIG_H
55
85
# include "internal.h"
56
86
#endif /* HAVE_AV_CONFIG_H */
71
111
#define FFSIGN(a) ((a) > 0 ? 1 : -1)
73
113
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
114
#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
74
115
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
116
#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
76
118
#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
78
120
/* misc math functions */
79
121
extern const uint8_t ff_log2_tab[256];
81
static inline int av_log2(unsigned int v)
123
static inline av_const int av_log2(unsigned int v)
86
126
if (v & 0xffff0000) {
158
196
* @param amax maximum value of the clip range
159
197
* @return clipped value
161
static inline int av_clip(int a, int amin, int amax)
199
static inline av_const int av_clip(int a, int amin, int amax)
163
if (a < amin) return amin;
201
if (a < amin) return amin;
164
202
else if (a > amax) return amax;
170
208
* @param a value to clip
171
209
* @return clipped value
173
static inline uint8_t av_clip_uint8(int a)
211
static inline av_const uint8_t av_clip_uint8(int a)
175
213
if (a&(~255)) return (-a)>>31;
218
* clip a signed integer value into the -32768,32767 range
219
* @param a value to clip
220
* @return clipped value
222
static inline av_const int16_t av_clip_int16(int a)
224
if ((a+32768) & ~65535) return (a>>31) ^ 32767;
180
int64_t ff_gcd(int64_t a, int64_t b);
229
int64_t av_const ff_gcd(int64_t a, int64_t b);
183
232
* converts fourcc string to int
185
static inline int ff_get_fourcc(const char *s){
234
static inline av_pure int ff_get_fourcc(const char *s){
186
235
#ifdef HAVE_AV_CONFIG_H
187
236
assert( strlen(s)==4 );
197
246
* \def GET_UTF8(val, GET_BYTE, ERROR)
198
* converts a utf-8 character (up to 4 bytes long) to its 32-bit ucs-4 encoded form
247
* converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form
199
248
* \param val is the output and should be of type uint32_t. It holds the converted
200
* ucs-4 character and should be a left value.
201
* \param GET_BYTE gets utf-8 encoded bytes from any proper source. It can be
249
* UCS-4 character and should be a left value.
250
* \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be
202
251
* a function or a statement whose return value or evaluated value is of type
203
* uint8_t. It will be executed up to 4 times for values in the valid utf-8 range,
252
* uint8_t. It will be executed up to 4 times for values in the valid UTF-8 range,
204
253
* and up to 7 times in the general case.
205
* \param ERROR action that should be taken when an invalid utf-8 byte is returned
254
* \param ERROR action that should be taken when an invalid UTF-8 byte is returned
206
255
* from GET_BYTE. It should be a statement that jumps out of the macro,
207
256
* like exit(), goto, return, break, or continue.
225
274
* \def PUT_UTF8(val, tmp, PUT_BYTE)
226
* converts a 32-bit unicode character to its utf-8 encoded form (up to 4 bytes long).
275
* converts a 32-bit unicode character to its UTF-8 encoded form (up to 4 bytes long).
227
276
* \param val is an input only argument and should be of type uint32_t. It holds
228
* a ucs4 encoded unicode character that is to be converted to utf-8. If
277
* a ucs4 encoded unicode character that is to be converted to UTF-8. If
229
278
* val is given as a function it's executed only once.
230
279
* \param tmp is a temporary variable and should be of type uint8_t. It
231
280
* represents an intermediate value during conversion that is to be
232
281
* outputted by PUT_BYTE.
233
* \param PUT_BYTE writes the converted utf-8 bytes to any proper destination.
282
* \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination.
234
283
* It could be a function or a statement, and uses tmp as the input byte.
235
284
* For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be
236
* executed up to 4 times for values in the valid utf-8 range and up to
285
* executed up to 4 times for values in the valid UTF-8 range and up to
237
286
* 7 times in the general case, depending on the length of the converted
238
287
* unicode character.
260
#if defined(ARCH_X86) || defined(ARCH_POWERPC)
309
#if defined(ARCH_X86) || defined(ARCH_POWERPC) || defined(ARCH_BFIN)
310
#define AV_READ_TIME read_time
261
311
#if defined(ARCH_X86_64)
262
312
static inline uint64_t read_time(void)
265
asm volatile( "rdtsc\n\t"
268
return (d << 32) | (a & 0xffffffff);
315
asm volatile("rdtsc\n\t"
316
: "=a" (a), "=d" (d));
317
return (d << 32) | (a & 0xffffffff);
270
319
#elif defined(ARCH_X86_32)
271
320
static inline long long read_time(void)
274
asm volatile( "rdtsc\n\t"
323
asm volatile("rdtsc\n\t"
328
static inline uint64_t read_time(void)
335
unsigned long long c;
337
asm volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
279
340
#else //FIXME check ppc64
280
341
static inline uint64_t read_time(void)
296
357
return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
360
#elif defined(HAVE_GETHRTIME)
361
#define AV_READ_TIME gethrtime
300
365
#define START_TIMER \
302
uint64_t tstart= read_time();\
367
uint64_t tstart= AV_READ_TIME();\
304
369
#define STOP_TIMER(id) \
370
tend= AV_READ_TIME();\
307
static uint64_t tsum=0;\
308
static int tcount=0;\
309
static int tskip_count=0;\
310
if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\
311
tsum+= tend - tstart;\
315
if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
316
av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
372
static uint64_t tsum=0;\
373
static int tcount=0;\
374
static int tskip_count=0;\
375
if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\
376
tsum+= tend - tstart;\
380
if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
381
av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
382
tsum*10/tcount, id, tcount, tskip_count);\
320
386
#define START_TIMER
321
387
#define STOP_TIMER(id) {}
327
#define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
329
#define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
333
void *av_malloc(unsigned int size);
334
void *av_realloc(void *ptr, unsigned int size);
335
void av_free(void *ptr);
337
void *av_mallocz(unsigned int size);
338
char *av_strdup(const char *s);
339
void av_freep(void *ptr);
341
#endif /* COMMON_H */
390
#endif /* FFMPEG_COMMON_H */