diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Makefile.am | 2 | ||||
-rw-r--r-- | src/util/SConscript | 2 | ||||
-rw-r--r-- | src/util/hash_table.c | 2 | ||||
-rw-r--r-- | src/util/hash_table.h | 4 | ||||
-rw-r--r-- | src/util/macros.h | 128 | ||||
-rw-r--r-- | src/util/ralloc.h | 3 |
6 files changed, 133 insertions, 8 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 0f9dcab6a59..a2aeafc703b 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -28,8 +28,6 @@ noinst_LTLIBRARIES = libmesautil.la libmesautil_la_CPPFLAGS = \ $(DEFINES) \ -I$(top_srcdir)/include \ - -I$(top_srcdir)/src/mapi \ - -I$(top_srcdir)/src/mesa \ $(VISIBILITY_CFLAGS) libmesautil_la_SOURCES = $(MESA_UTIL_FILES) diff --git a/src/util/SConscript b/src/util/SConscript index a36340deebf..8afeedaf5e9 100644 --- a/src/util/SConscript +++ b/src/util/SConscript @@ -8,8 +8,6 @@ env = env.Clone() env.Prepend(CPPPATH = [ '#include', - '#src/mapi', - '#src/mesa', '#src/util', ]) diff --git a/src/util/hash_table.c b/src/util/hash_table.c index f98a1a647ea..1b6726c79a9 100644 --- a/src/util/hash_table.c +++ b/src/util/hash_table.c @@ -44,8 +44,8 @@ #include <string.h> #include "hash_table.h" -#include "main/macros.h" #include "ralloc.h" +#include "macros.h" static const uint32_t deleted_key_value; diff --git a/src/util/hash_table.h b/src/util/hash_table.h index 5fa58991e30..9b67f05bec6 100644 --- a/src/util/hash_table.h +++ b/src/util/hash_table.h @@ -28,10 +28,10 @@ #ifndef _HASH_TABLE_H #define _HASH_TABLE_H +#include <stdlib.h> #include <inttypes.h> #include <stdbool.h> - -#include "main/compiler.h" +#include "macros.h" #ifdef __cplusplus extern "C" { diff --git a/src/util/macros.h b/src/util/macros.h new file mode 100644 index 00000000000..ee05e05a4a8 --- /dev/null +++ b/src/util/macros.h @@ -0,0 +1,128 @@ +/* + * Copyright © 2014 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef UTIL_MACROS_H +#define UTIL_MACROS_H + +/* Compute the size of an array */ +#ifndef ARRAY_SIZE +# define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) +#endif + + +/** + * __builtin_expect macros + */ +#if !defined(__GNUC__) +# define __builtin_expect(x, y) (x) +#endif + +#ifndef likely +# ifdef __GNUC__ +# define likely(x) __builtin_expect(!!(x), 1) +# define unlikely(x) __builtin_expect(!!(x), 0) +# else +# define likely(x) (x) +# define unlikely(x) (x) +# endif +#endif + + +/** + * Static (compile-time) assertion. + * Basically, use COND to dimension an array. If COND is false/zero the + * array size will be -1 and we'll get a compilation error. + */ +#define STATIC_ASSERT(COND) \ + do { \ + (void) sizeof(char [1 - 2*!(COND)]); \ + } while (0) + + +/** + * Unreachable macro. Useful for suppressing "control reaches end of non-void + * function" warnings. + */ +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 5 +#define unreachable(str) \ +do { \ + assert(!str); \ + __builtin_unreachable(); \ +} while (0) +#elif (defined(__clang__) && defined(__has_builtin)) +# if __has_builtin(__builtin_unreachable) +# define unreachable(str) \ +do { \ + assert(!str); \ + __builtin_unreachable(); \ +} while (0) +# endif +#endif + +#ifndef unreachable +#define unreachable(str) +#endif + + +#if (__GNUC__ >= 3) +#define PRINTFLIKE(f, a) __attribute__ ((format(__printf__, f, a))) +#else +#define PRINTFLIKE(f, a) +#endif + + +/* Used to optionally mark structures with misaligned elements or size as + * packed, to trade off performance for space. + */ +#if (__GNUC__ >= 3) +#define PACKED __attribute__((__packed__)) +#else +#define PACKED +#endif + + +#ifdef __cplusplus +/** + * Macro function that evaluates to true if T is a trivially + * destructible type -- that is, if its (non-virtual) destructor + * 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))) +# define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) +# endif +# elif (defined(__clang__) && defined(__has_feature)) +# if __has_feature(has_trivial_destructor) +# define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) +# endif +# endif +# ifndef HAS_TRIVIAL_DESTRUCTOR + /* It's always safe (if inefficient) to assume that a + * destructor is non-trivial. + */ +# define HAS_TRIVIAL_DESTRUCTOR(T) (false) +# endif +#endif + +#endif /* UTIL_MACROS_H */ diff --git a/src/util/ralloc.h b/src/util/ralloc.h index 1fe53573f0d..4b88f328665 100644 --- a/src/util/ralloc.h +++ b/src/util/ralloc.h @@ -53,7 +53,8 @@ extern "C" { #include <stddef.h> #include <stdarg.h> #include <stdbool.h> -#include "main/compiler.h" + +#include "macros.h" /** * \def ralloc(ctx, type) |