]> git.sesse.net Git - vlc/commitdiff
Introduce VLC_GCC_VERSION macro, fix popcount and clz
authorRémi Denis-Courmont <remi@remlab.net>
Wed, 17 Aug 2011 15:28:25 +0000 (18:28 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Wed, 17 Aug 2011 15:21:32 +0000 (18:21 +0300)
This can be used as follows:

 #if VLC_GCC_VERSION(major,minor)
 ...
 #endif

There is nothing "VLC" about it. The prefix is only about namespacing.

include/vlc_common.h
include/vlc_plugin.h
include/vlc_threads.h

index cb0ce9424fcacbc59b3c8fed0acd8f4179a850c3..0c7966faa0de67dc4ec191a971d19fe40696dd32 100644 (file)
 # include <stdbool.h>
 #endif
 
+/* Helper for GCC version checks */
+#ifdef __GNUC__
+# define VLC_GCC_VERSION(maj,min) \
+    ((__GNUC__ > (maj)) || (__GNUC__ == (maj) && __GNUC_MINOR__ >= (min)))
+#else
+# define VLC_GCC_VERSION(maj,min) (0)
+#endif
+
 /* Try to fix format strings for all versions of mingw and mingw64 */
 #if defined( _WIN32 ) && defined( __USE_MINGW_ANSI_STDIO )
  #undef PRId64
  #define vsnprintf       __mingw_vsnprintf
 #endif
 
-/* Format string sanity checks */
+/* Function attributes for compiler warnings */
 #ifdef __GNUC__
-#   if defined( _WIN32 ) && (__GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 4 ) )
-#     define VLC_FORMAT(x,y) __attribute__ ((format(gnu_printf,x,y)))
-#   else
-#     define VLC_FORMAT(x,y) __attribute__ ((format(printf,x,y)))
-#   endif
-#   define VLC_FORMAT_ARG(x) __attribute__ ((format_arg(x)))
-#   if __GNUC__ > 3 || (__GNUC__ == 3 && (__GNUC_MINOR__ >= 4))
-#     define VLC_USED __attribute__ ((warn_unused_result))
-#   else
-#     define VLC_USED
-#   endif
-#   define VLC_MALLOC __attribute__ ((malloc))
+# define VLC_DEPRECATED __attribute__((deprecated))
+
+# if defined( _WIN32 ) && VLC_GCC_VERSION(4,4)
+#  define VLC_FORMAT(x,y) __attribute__ ((format(gnu_printf,x,y)))
+# else
+#  define VLC_FORMAT(x,y) __attribute__ ((format(printf,x,y)))
+# endif
+# define VLC_FORMAT_ARG(x) __attribute__ ((format_arg(x)))
+
+# define VLC_MALLOC __attribute__ ((malloc))
+
+# if VLC_GCC_VERSION(3,4)
+#  define VLC_USED __attribute__ ((warn_unused_result))
+# else
+#  define VLC_USED
+# endif
+
 #else
-#   define VLC_FORMAT(x,y)
-#   define VLC_FORMAT_ARG(x)
-#   define VLC_USED
-#   define VLC_MALLOC
+# define VLC_DEPRECATED
+# define VLC_FORMAT(x,y)
+# define VLC_FORMAT_ARG(x)
+# define VLC_MALLOC
+# define VLC_USED
 #endif
 
+
 /* Branch prediction */
 #ifdef __GNUC__
 #   define likely(p)   __builtin_expect(!!(p), 1)
 #   define unlikely(p) (!!(p))
 #endif
 
-#if defined(__GNUC__) && !defined __cplusplus
-# define VLC_DEPRECATED __attribute__((deprecated))
-#else
-# define VLC_DEPRECATED
-#endif
-
 /* Linkage */
 #ifdef __cplusplus
 # define VLC_EXTERN extern "C"
 
 #if defined (WIN32) && defined (DLL_EXPORT)
 # define VLC_EXPORT __declspec(dllexport)
-#elif defined (__GNUC__) && (__GNUC__ >= 4)
+#elif VLC_GCC_VERSION(4,0)
 # define VLC_EXPORT __attribute__((visibility("default")))
 #else
 # define VLC_EXPORT
@@ -505,7 +514,7 @@ typedef union
 /**@}*/                                                                     \
 
 /* VLC_OBJECT: attempt at doing a clever cast */
-#if defined( __GNUC__ ) && __GNUC__ > 3
+#if VLC_GCC_VERSION(4,0)
 # ifndef __cplusplus
 #  define VLC_OBJECT( x ) \
     __builtin_choose_expr( \
@@ -579,11 +588,11 @@ static inline uint8_t clip_uint8_vlc( int32_t a )
     else           return a;
 }
 
-/* Count leading zeroes */
+/** Count leading zeroes */
 VLC_USED
 static inline unsigned clz (unsigned x)
 {
-#ifdef __GNUC_
+#if VLC_GCC_VERSION(3,4)
     return __builtin_clz (x);
 #else
     unsigned i = sizeof (x) * 8;
@@ -602,11 +611,11 @@ static inline unsigned clz (unsigned x)
 /* XXX: this assumes that int is 32-bits or more */
 #define clz32( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint32_t)) * 8))
 
-/* Bit weight */
+/** Bit weight */
 VLC_USED
 static inline unsigned popcount (unsigned x)
 {
-#ifdef __GNUC_
+#if VLC_GCC_VERSION(3,4)
     return __builtin_popcount (x);
 #else
     unsigned count = 0;
index e88702d684ff5879b6513a6bfbd4fd3363bd0f0e..8a6a70b3d0551062f1f1d3526413853e6a7faa40 100644 (file)
@@ -138,7 +138,7 @@ enum vlc_module_properties
 #   define DLL_SYMBOL              __declspec(dllexport)
 #   undef CDECL_SYMBOL
 #   define CDECL_SYMBOL            __cdecl
-# elif defined (__GNUC__) && (__GNUC__ >= 4)
+# elif VLC_GCC_VERSION(4,0)
 #   define DLL_SYMBOL              __attribute__((visibility("default")))
 # else
 #  define DLL_SYMBOL
index 8b02e7cc4cc3fdb780a6b63d5b2cb710b9993a6d..f7a91a8f8b99e80da37d7e85347c084148d01c64 100644 (file)
@@ -207,8 +207,7 @@ VLC_API void msleep(mtime_t delay);
 #define VLC_HARD_MIN_SLEEP   10000 /* 10 milliseconds = 1 tick at 100Hz */
 #define VLC_SOFT_MIN_SLEEP 9000000 /* 9 seconds */
 
-#if defined (__GNUC__) \
- && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
+#if VLC_GCC_VERSION(4,3)
 /* Linux has 100, 250, 300 or 1000Hz
  *
  * HZ=100 by default on FreeBSD, but some architectures use a 1000Hz timer