/**
* @file common.h
- * common internal and external api header.
+ * common internal and external API header
*/
-#ifndef COMMON_H
-#define COMMON_H
+#ifndef FFMPEG_COMMON_H
+#define FFMPEG_COMMON_H
#include <inttypes.h>
#ifndef av_always_inline
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
# define av_always_inline __attribute__((always_inline)) inline
-# define av_noinline __attribute__((noinline))
#else
# define av_always_inline inline
+#endif
+#endif
+
+#ifndef av_noinline
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+# define av_noinline __attribute__((noinline))
+#else
# define av_noinline
#endif
#endif
+#ifndef av_pure
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+# define av_pure __attribute__((pure))
+#else
+# define av_pure
+#endif
+#endif
+
+#ifndef av_const
+#if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ > 5)
+# define av_const __attribute__((const))
+#else
+# define av_const
+#endif
+#endif
+
+#ifndef av_cold
+#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 2)
+# define av_cold __attribute__((cold))
+#else
+# define av_cold
+#endif
+#endif
+
#ifdef HAVE_AV_CONFIG_H
# include "internal.h"
#endif /* HAVE_AV_CONFIG_H */
#define FFSIGN(a) ((a) > 0 ? 1 : -1)
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
+#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
+#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
/* misc math functions */
extern const uint8_t ff_log2_tab[256];
-static inline int av_log2(unsigned int v)
+static inline av_const int av_log2(unsigned int v)
{
- int n;
-
- n = 0;
+ int n = 0;
if (v & 0xffff0000) {
v >>= 16;
n += 16;
return n;
}
-static inline int av_log2_16bit(unsigned int v)
+static inline av_const int av_log2_16bit(unsigned int v)
{
- int n;
-
- n = 0;
+ int n = 0;
if (v & 0xff00) {
v >>= 8;
n += 8;
}
/* median of 3 */
-static inline int mid_pred(int a, int b, int c)
+static inline av_const int mid_pred(int a, int b, int c)
{
#ifdef HAVE_CMOV
int i=b;
* @param amax maximum value of the clip range
* @return clipped value
*/
-static inline int av_clip(int a, int amin, int amax)
+static inline av_const int av_clip(int a, int amin, int amax)
{
- if (a < amin) return amin;
+ if (a < amin) return amin;
else if (a > amax) return amax;
else return a;
}
* @param a value to clip
* @return clipped value
*/
-static inline uint8_t av_clip_uint8(int a)
+static inline av_const uint8_t av_clip_uint8(int a)
{
if (a&(~255)) return (-a)>>31;
else return a;
}
+/**
+ * clip a signed integer value into the -32768,32767 range
+ * @param a value to clip
+ * @return clipped value
+ */
+static inline av_const int16_t av_clip_int16(int a)
+{
+ if ((a+32768) & ~65535) return (a>>31) ^ 32767;
+ else return a;
+}
+
/* math */
-int64_t ff_gcd(int64_t a, int64_t b);
+int64_t av_const ff_gcd(int64_t a, int64_t b);
/**
* converts fourcc string to int
*/
-static inline int ff_get_fourcc(const char *s){
+static inline av_pure int ff_get_fourcc(const char *s){
#ifdef HAVE_AV_CONFIG_H
assert( strlen(s)==4 );
#endif
}
#if defined(ARCH_X86) || defined(ARCH_POWERPC) || defined(ARCH_BFIN)
+#define AV_READ_TIME read_time
#if defined(ARCH_X86_64)
static inline uint64_t read_time(void)
{
- uint64_t a, d;
- asm volatile( "rdtsc\n\t"
- : "=a" (a), "=d" (d)
- );
- return (d << 32) | (a & 0xffffffff);
+ uint64_t a, d;
+ asm volatile("rdtsc\n\t"
+ : "=a" (a), "=d" (d));
+ return (d << 32) | (a & 0xffffffff);
}
#elif defined(ARCH_X86_32)
static inline long long read_time(void)
{
- long long l;
- asm volatile( "rdtsc\n\t"
- : "=A" (l)
- );
- return l;
+ long long l;
+ asm volatile("rdtsc\n\t"
+ : "=A" (l));
+ return l;
}
#elif ARCH_BFIN
static inline uint64_t read_time(void)
uint32_t tbu, tbl, temp;
/* from section 2.2.1 of the 32-bit PowerPC PEM */
- __asm__ __volatile__(
+ asm volatile(
"1:\n"
"mftbu %2\n"
"mftb %0\n"
return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
}
#endif
+#elif defined(HAVE_GETHRTIME)
+#define AV_READ_TIME gethrtime
+#endif
+#ifdef AV_READ_TIME
#define START_TIMER \
uint64_t tend;\
-uint64_t tstart= read_time();\
+uint64_t tstart= AV_READ_TIME();\
#define STOP_TIMER(id) \
-tend= read_time();\
+tend= AV_READ_TIME();\
{\
- static uint64_t tsum=0;\
- static int tcount=0;\
- static int tskip_count=0;\
- if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\
- tsum+= tend - tstart;\
- tcount++;\
- }else\
- tskip_count++;\
- if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
- av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
- }\
+ static uint64_t tsum=0;\
+ static int tcount=0;\
+ static int tskip_count=0;\
+ if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\
+ tsum+= tend - tstart;\
+ tcount++;\
+ }else\
+ tskip_count++;\
+ if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
+ av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
+ tsum*10/tcount, id, tcount, tskip_count);\
+ }\
}
#else
#define START_TIMER
#define STOP_TIMER(id) {}
#endif
-#endif /* COMMON_H */
+#endif /* FFMPEG_COMMON_H */