[FFmpeg-devel] [PATCH] Simplify checks for particular GCC versions.

Diego 'Flameeyes' Pettenò flameeyes
Fri Oct 3 20:42:38 CEST 2008


Instead of expanding the same check for GCC every time, create a macro
FF_GCC_ATLEAST that can be used to check for a particular GCC version.

The FF_GCC_ATLEAST test ignores whatever ICC provides, since it does
not support the full feature set of the GCC it fakes to provide.
---

 libavcodec/alpha/asm.h                |   14 ++++----------
 libavcodec/armv4l/mpegvideo_armv5te.c |    2 +-
 libavcodec/ppc/gcc_fixes.h            |    7 ++++---
 libavutil/common.h                    |   20 ++++++++++++++------
 libavutil/internal.h                  |    4 ++--
 libavutil/mem.h                       |    4 ++--
 6 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/libavcodec/alpha/asm.h b/libavcodec/alpha/asm.h
index 6fef165..4eb41a1 100644
--- a/libavcodec/alpha/asm.h
+++ b/libavcodec/alpha/asm.h
@@ -23,15 +23,9 @@
 #define AVCODEC_ALPHA_ASM_H
 
 #include <inttypes.h>
+#include "libavutil/common.h"
 
-#if defined __GNUC__
-# define GNUC_PREREQ(maj, min) \
-        ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
-#else
-# define GNUC_PREREQ(maj, min) 0
-#endif
-
-#if GNUC_PREREQ(2,96)
+#if FF_GCC_ATLEAST(2,96,0)
 # define likely(x)      __builtin_expect((x) != 0, 1)
 # define unlikely(x)    __builtin_expect((x) != 0, 0)
 #else
@@ -89,7 +83,7 @@ struct unaligned_long { uint64_t l; } __attribute__((packed));
 #define ldq_u(p)        (*(const uint64_t *) (((uint64_t) (p)) & ~7ul))
 #define uldq(a)         (((const struct unaligned_long *) (a))->l)
 
-#if GNUC_PREREQ(3,3)
+#if FF_GCC_ATLEAST(3,3,0)
 #define prefetch(p)     __builtin_prefetch((p), 0, 1)
 #define prefetch_en(p)  __builtin_prefetch((p), 0, 0)
 #define prefetch_m(p)   __builtin_prefetch((p), 1, 1)
@@ -121,7 +115,7 @@ struct unaligned_long { uint64_t l; } __attribute__((packed));
 #endif
 #define wh64(p) asm volatile("wh64 (%0)" : : "r"(p) : "memory")
 
-#if GNUC_PREREQ(3,3) && defined(__alpha_max__)
+#if FF_GCC_ATLEAST(3,3,0) && defined(__alpha_max__)
 #define minub8  __builtin_alpha_minub8
 #define minsb8  __builtin_alpha_minsb8
 #define minuw4  __builtin_alpha_minuw4
diff --git a/libavcodec/armv4l/mpegvideo_armv5te.c b/libavcodec/armv4l/mpegvideo_armv5te.c
index 721dee5..cdb87c5 100644
--- a/libavcodec/armv4l/mpegvideo_armv5te.c
+++ b/libavcodec/armv4l/mpegvideo_armv5te.c
@@ -48,7 +48,7 @@ static inline void dct_unquantize_h263_helper_c(DCTELEM *block, int qmul, int qa
 #endif
 
 /* GCC 3.1 or higher is required to support symbolic names in assembly code */
-#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
+#if FF_GCC_ATLEAST(3,1,0)
 
 /**
  * Special optimized version of dct_unquantize_h263_helper_c, it requires the block
diff --git a/libavcodec/ppc/gcc_fixes.h b/libavcodec/ppc/gcc_fixes.h
index 01b1c18..8021e99 100644
--- a/libavcodec/ppc/gcc_fixes.h
+++ b/libavcodec/ppc/gcc_fixes.h
@@ -24,18 +24,19 @@
 #define AVCODEC_PPC_GCC_FIXES_H
 
 #include "config.h"
+#include "libavutil/common.h"
 
 #ifdef HAVE_ALTIVEC_H
 #include <altivec.h>
 #endif
 
-#if (__GNUC__ < 4)
+#if FF_GCC_ATLEAST(4,0,0)
 # define REG_v(a)
 #else
 # define REG_v(a) asm ( #a )
 #endif
 
-#if (__GNUC__ == 3 && __GNUC_MINOR__ < 3)
+#if !FF_GCC_ATLEAST(3,3,0)
 
 /* This code was provided to me by Bartosch Pixa
  * as a separate header file (broken_mergel.h).
@@ -97,6 +98,6 @@ __ch (__bin_args_eq (vector unsigned int, (a1), vector unsigned int, (a2)), \
       ((vector unsigned int) ff_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
     __altivec_link_error_invalid_argument ())))))))
 
-#endif /* (__GNUC__ == 3 && __GNUC_MINOR__ < 3) */
+#endif /* !FF_GCC_ATLEAST(3,3,0) */
 
 #endif /* AVCODEC_PPC_GCC_FIXES_H */
diff --git a/libavutil/common.h b/libavutil/common.h
index 42fe951..827b187 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -41,8 +41,16 @@
 #    include <math.h>
 #endif /* HAVE_AV_CONFIG_H */
 
+#if defined(__ICC) || !defined(__GNUC__)
+# define FF_GCC_ATLEAST(maj,min,micro) 0
+#else
+# define FF_GCC_ATLEAST(maj,min,micro) (                                \
+  ((__GNUC__ << 24) + (__GNUC_MINOR__ << 16) + __GNUC_PATCHLEVEL__)     \
+  >= ((maj << 24 ) + (min << 16) + micro) )
+#endif
+
 #ifndef av_always_inline
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+#if FF_GCC_ATLEAST(3,1,0) || __ICC
 #    define av_always_inline __attribute__((always_inline)) inline
 #else
 #    define av_always_inline inline
@@ -50,7 +58,7 @@
 #endif
 
 #ifndef av_noinline
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+#if FF_GCC_ATLEAST(3,1,0) || __ICC
 #    define av_noinline __attribute__((noinline))
 #else
 #    define av_noinline
@@ -58,7 +66,7 @@
 #endif
 
 #ifndef av_pure
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+#if FF_GCC_ATLEAST(3,1,0) || __ICC
 #    define av_pure __attribute__((pure))
 #else
 #    define av_pure
@@ -66,7 +74,7 @@
 #endif
 
 #ifndef av_const
-#if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ > 5)
+#if FF_GCC_ATLEAST(2,6,0) || __ICC
 #    define av_const __attribute__((const))
 #else
 #    define av_const
@@ -74,7 +82,7 @@
 #endif
 
 #ifndef av_cold
-#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 2)
+#if FF_GCC_ATLEAST(4,3,0)
 #    define av_cold __attribute__((cold))
 #else
 #    define av_cold
@@ -86,7 +94,7 @@
 #endif /* HAVE_AV_CONFIG_H */
 
 #ifndef attribute_deprecated
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+#if FF_GCC_ATLEAST(3,1,0) || __ICC
 #    define attribute_deprecated __attribute__((deprecated))
 #else
 #    define attribute_deprecated
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 0eb25d5..9fc7875 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -35,7 +35,7 @@
 #include <assert.h>
 
 #ifndef attribute_align_arg
-#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__>1)
+#if FF_GCC_ATLEAST(4,2,0)
 #    define attribute_align_arg __attribute__((force_align_arg_pointer))
 #else
 #    define attribute_align_arg
@@ -43,7 +43,7 @@
 #endif
 
 #ifndef attribute_used
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+#if FF_GCC_ATLEAST(3,1,0)
 #    define attribute_used __attribute__((used))
 #else
 #    define attribute_used
diff --git a/libavutil/mem.h b/libavutil/mem.h
index a02c7e1..41e082f 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -42,13 +42,13 @@
     #define DECLARE_ASM_CONST(n,t,v)    static const t v
 #endif
 
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+#if FF_GCC_ATLEAST(3,1,0) || __ICC
     #define av_malloc_attrib __attribute__((__malloc__))
 #else
     #define av_malloc_attrib
 #endif
 
-#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 2)
+#if FF_GCC_ATLEAST(4,3,0)
     #define av_alloc_size(n) __attribute__((alloc_size(n)))
 #else
     #define av_alloc_size(n)





More information about the ffmpeg-devel mailing list