summaryrefslogtreecommitdiff
path: root/lib/mesa/src/util/macros.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mesa/src/util/macros.h')
-rw-r--r--lib/mesa/src/util/macros.h41
1 files changed, 36 insertions, 5 deletions
diff --git a/lib/mesa/src/util/macros.h b/lib/mesa/src/util/macros.h
index 84e4f182b..efb896f4c 100644
--- a/lib/mesa/src/util/macros.h
+++ b/lib/mesa/src/util/macros.h
@@ -24,6 +24,10 @@
#ifndef UTIL_MACROS_H
#define UTIL_MACROS_H
+#include <assert.h>
+
+#include "c99_compat.h"
+
/* Compute the size of an array */
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
@@ -150,6 +154,12 @@ do { \
#define ATTRIBUTE_PURE
#endif
+#ifdef HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL
+#define ATTRIBUTE_RETURNS_NONNULL __attribute__((__returns_nonnull__))
+#else
+#define ATTRIBUTE_RETURNS_NONNULL
+#endif
+
#ifdef __cplusplus
/**
* Macro function that evaluates to true if T is a trivially
@@ -157,12 +167,12 @@ do { \
* performs no action and all member variables and base classes are
* trivially destructible themselves.
*/
-# if defined(__GNUC__)
-# if ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)))
+# if (defined(__clang__) && defined(__has_feature))
+# if __has_feature(has_trivial_destructor)
# define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T)
# endif
-# elif (defined(__clang__) && defined(__has_feature))
-# if __has_feature(has_trivial_destructor)
+# elif defined(__GNUC__)
+# if ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)))
# define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T)
# endif
# endif
@@ -184,7 +194,7 @@ do { \
* inline a static function that we later use in an alias. - ajax
*/
#ifndef PUBLIC
-# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
+# if defined(__GNUC__)
# define PUBLIC __attribute__((visibility("default")))
# define USED __attribute__((used))
# elif defined(_MSC_VER)
@@ -202,13 +212,34 @@ do { \
#define UNUSED
#endif
+#define MAYBE_UNUSED UNUSED
+
#ifdef HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT
#define MUST_CHECK __attribute__((warn_unused_result))
#else
#define MUST_CHECK
#endif
+#if defined(__GNUC__)
+#define ATTRIBUTE_NOINLINE __attribute__((noinline))
+#else
+#define ATTRIBUTE_NOINLINE
+#endif
+
/** Compute ceiling of integer quotient of A divided by B. */
#define DIV_ROUND_UP( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
+/** Clamp X to [MIN,MAX] */
+#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
+
+/** Minimum of two values: */
+#define MIN2( A, B ) ( (A)<(B) ? (A) : (B) )
+
+/** Maximum of two values: */
+#define MAX2( A, B ) ( (A)>(B) ? (A) : (B) )
+
+/** Minimum and maximum of three values: */
+#define MIN3( A, B, C ) ((A) < (B) ? MIN2(A, C) : MIN2(B, C))
+#define MAX3( A, B, C ) ((A) > (B) ? MAX2(A, C) : MAX2(B, C))
+
#endif /* UTIL_MACROS_H */