[FFmpeg-devel] [PATCH] Simplify checks for particular GCC versions.
Diego 'Flameeyes' Pettenò
flameeyes
Thu Oct 9 15:43:31 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.
This macro uses a "GCC combined version" that is represented by this
formula:
(MAJ << 24) + (MIN << 16) + MICRO
and is defined as FF_GCC_COMBVERSION macro.
This macro might be calculated right from __GNUC__ and the other
macros, or might be "faked" for a particular compiler to support.
In particular, ICC 10.1 (and later) fakes a GCC 4.1 version (rather
than the 4.3 that it fakes by itself, since it does not support the
cold, force_align_arg_pointer and alloc_size attributes), while older
version (which I cannot test) fakes GCC 3.0 to have at least some very
basic attribute support.
Further "faking" may be introduced if other compilers can accept a
(subset) of attributes.
All the files that use FF_GCC_ATLEAST are now checked so that they
include (directly or indirectly) libavutil/common.h where it is
defined.
---
libavcodec/alpha/asm.h | 14 ++++----------
libavcodec/armv4l/mpegvideo_armv5te.c | 2 +-
libavcodec/ppc/gcc_fixes.h | 7 ++++---
libavutil/common.h | 30 ++++++++++++++++++++++++------
libavutil/internal.h | 6 ++++--
libavutil/mem.h | 6 ++++--
6 files changed, 41 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..a397398 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -41,8 +41,26 @@
# include <math.h>
#endif /* HAVE_AV_CONFIG_H */
+/* Check ICC first since it'll appear as GCC otherwise */
+#if __ICC
+# if __ICC >= 1010
+ /* We know ICC 10.1 behaves like GCC 4.1 for us */
+# define FF_GCC_COMBVERSION ((4 << 24) + (1 << 16) + 0)
+# else
+# define FF_GCC_COMBVERSION ((4 << 24) + (0 << 16) + 0)
+# endif
+#elif defined(__GNUC__)
+# define FF_GCC_COMBVERSION \
+ ((__GNUC__ << 24) + (__GNUC_MINOR__ << 16) + __GNUC_PATCHLEVEL__)
+#else
+# define FF_GCC_COMBVERSION 0
+#endif
+
+#define FF_GCC_ATLEAST(maj,min,micro) \
+ FF_GCC_COMBVERSION >= ((maj << 24) + (min << 16) + micro)
+
#ifndef av_always_inline
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+#if FF_GCC_ATLEAST(3,1,0)
# define av_always_inline __attribute__((always_inline)) inline
#else
# define av_always_inline inline
@@ -50,7 +68,7 @@
#endif
#ifndef av_noinline
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+#if FF_GCC_ATLEAST(3,1,0)
# define av_noinline __attribute__((noinline))
#else
# define av_noinline
@@ -58,7 +76,7 @@
#endif
#ifndef av_pure
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+#if FF_GCC_ATLEAST(3,1,0)
# define av_pure __attribute__((pure))
#else
# define av_pure
@@ -66,7 +84,7 @@
#endif
#ifndef av_const
-#if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ > 5)
+#if FF_GCC_ATLEAST(2,6,0)
# define av_const __attribute__((const))
#else
# define av_const
@@ -74,7 +92,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 +104,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)
# define attribute_deprecated __attribute__((deprecated))
#else
# define attribute_deprecated
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 0eb25d5..fcf683c 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -34,8 +34,10 @@
#include <stddef.h>
#include <assert.h>
+#include "common.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 +45,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..5b57889 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -26,6 +26,8 @@
#ifndef AVUTIL_MEM_H
#define AVUTIL_MEM_H
+#include "common.h"
+
#if defined(__ICC) || defined(__SUNPRO_C)
#define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
#define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
@@ -42,13 +44,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)
#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