diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2015-11-22 02:46:45 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2015-11-22 02:46:45 +0000 |
commit | 3e40341f9dcd7c1bbc9afb8ddb812304820396cf (patch) | |
tree | 274b3f522afe1da16ab2b5347758c908bc23fac4 /lib/mesa/src/util | |
parent | 7b644ad52b574bec410d557155d666ac17fdf51a (diff) |
import Mesa 11.0.6
Diffstat (limited to 'lib/mesa/src/util')
-rw-r--r-- | lib/mesa/src/util/Makefile.sources | 41 | ||||
-rw-r--r-- | lib/mesa/src/util/SConscript | 9 | ||||
-rw-r--r-- | lib/mesa/src/util/format_srgb.py | 1 | ||||
-rw-r--r-- | lib/mesa/src/util/list.h | 45 | ||||
-rw-r--r-- | lib/mesa/src/util/macros.h | 43 | ||||
-rw-r--r-- | lib/mesa/src/util/ralloc.c | 410 | ||||
-rw-r--r-- | lib/mesa/src/util/register_allocate.h | 6 |
7 files changed, 44 insertions, 511 deletions
diff --git a/lib/mesa/src/util/Makefile.sources b/lib/mesa/src/util/Makefile.sources index e9057343d..1f5386a00 100644 --- a/lib/mesa/src/util/Makefile.sources +++ b/lib/mesa/src/util/Makefile.sources @@ -1,32 +1,12 @@ -MESA_UTIL_FILES := \ - bitscan.c \ - bitscan.h \ +MESA_UTIL_FILES := \ bitset.h \ - build_id.c \ - build_id.h \ - crc32.c \ - crc32.h \ - debug.c \ - debug.h \ - disk_cache.c \ - disk_cache.h \ - format_r11g11b10f.h \ - format_rgb9e5.h \ format_srgb.h \ - half_float.c \ - half_float.h \ - hash_table.c \ + hash_table.c \ hash_table.h \ list.h \ macros.h \ - mesa-sha1.c \ - mesa-sha1.h \ - sha1/sha1.c \ - sha1/sha1.h \ ralloc.c \ ralloc.h \ - rand_xor.c \ - rand_xor.h \ register_allocate.c \ register_allocate.h \ rgtc.c \ @@ -35,25 +15,10 @@ MESA_UTIL_FILES := \ set.c \ set.h \ simple_list.h \ - slab.c \ - slab.h \ - string_to_uint_map.cpp \ - string_to_uint_map.h \ - strndup.h \ strtod.c \ strtod.h \ texcompress_rgtc_tmp.h \ - u_atomic.c \ - u_atomic.h \ - u_endian.h \ - u_queue.c \ - u_queue.h \ - u_string.h \ - u_thread.h \ - u_vector.c \ - u_vector.h \ - vk_alloc.h \ - vk_util.h + u_atomic.h MESA_UTIL_GENERATED_FILES = \ format_srgb.c diff --git a/lib/mesa/src/util/SConscript b/lib/mesa/src/util/SConscript index 7e447f6e0..bd8fb1727 100644 --- a/lib/mesa/src/util/SConscript +++ b/lib/mesa/src/util/SConscript @@ -6,7 +6,7 @@ from sys import executable as python_cmd env = env.Clone() -env.MSVC2013Compat() +env.MSVC2008Compat() env.Prepend(CPPPATH = [ '#include', @@ -42,14 +42,17 @@ env.Alias('mesautil', mesautil) Export('mesautil') +# http://www.scons.org/wiki/UnitTests u_atomic_test = env.Program( target = 'u_atomic_test', source = ['u_atomic_test.c'], ) -env.UnitTest("u_atomic_test", u_atomic_test) +alias = env.Alias("u_atomic_test", u_atomic_test, u_atomic_test[0].abspath) +AlwaysBuild(alias) roundeven_test = env.Program( target = 'roundeven_test', source = ['roundeven_test.c'], ) -env.UnitTest("roundeven_test", roundeven_test) +alias = env.Alias("roundeven_test", roundeven_test, roundeven_test[0].abspath) +AlwaysBuild(alias) diff --git a/lib/mesa/src/util/format_srgb.py b/lib/mesa/src/util/format_srgb.py index 44b35a061..d5cbcf764 100644 --- a/lib/mesa/src/util/format_srgb.py +++ b/lib/mesa/src/util/format_srgb.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python CopyRight = ''' /************************************************************************** diff --git a/lib/mesa/src/util/list.h b/lib/mesa/src/util/list.h index 6edb75011..b98ce59ff 100644 --- a/lib/mesa/src/util/list.h +++ b/lib/mesa/src/util/list.h @@ -41,7 +41,6 @@ #include <stdbool.h> #include <stddef.h> #include <assert.h> -#include "c99_compat.h" struct list_head @@ -72,18 +71,12 @@ static inline void list_addtail(struct list_head *item, struct list_head *list) list->prev = item; } -static inline bool list_empty(struct list_head *list); - static inline void list_replace(struct list_head *from, struct list_head *to) { - if (list_empty(from)) { - list_inithead(to); - } else { - to->prev = from->prev; - to->next = from->next; - from->next->prev = to; - from->prev->next = to; - } + to->prev = from->prev; + to->next = from->next; + from->next->prev = to; + from->prev->next = to; } static inline void list_del(struct list_head *item) @@ -106,14 +99,6 @@ static inline bool list_empty(struct list_head *list) return list->next == list; } -/** - * Returns whether the list has exactly one element. - */ -static inline bool list_is_singular(const struct list_head *list) -{ - return list->next != NULL && list->next != list && list->next->next == list; -} - static inline unsigned list_length(struct list_head *list) { struct list_head *node; @@ -123,28 +108,6 @@ static inline unsigned list_length(struct list_head *list) return length; } -static inline void list_splice(struct list_head *src, struct list_head *dst) -{ - if (list_empty(src)) - return; - - src->next->prev = dst; - src->prev->next = dst->next; - dst->next->prev = src->prev; - dst->next = src->next; -} - -static inline void list_splicetail(struct list_head *src, struct list_head *dst) -{ - if (list_empty(src)) - return; - - src->prev->next = dst; - src->next->prev = dst->prev; - dst->prev->next = src->next; - dst->prev = src->prev; -} - static inline void list_validate(struct list_head *list) { struct list_head *node; diff --git a/lib/mesa/src/util/macros.h b/lib/mesa/src/util/macros.h index 6f55ac667..84e4f182b 100644 --- a/lib/mesa/src/util/macros.h +++ b/lib/mesa/src/util/macros.h @@ -24,10 +24,6 @@ #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))) @@ -154,12 +150,6 @@ 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 @@ -167,16 +157,12 @@ do { \ * performs no action and all member variables and base classes are * trivially destructible themselves. */ -# if (defined(__clang__) && defined(__has_feature)) -# if __has_feature(has_trivial_destructor) -# define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) -# endif -# elif defined(__GNUC__) +# if defined(__GNUC__) # if ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))) # define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) # endif -# elif defined(_MSC_VER) && !defined(__INTEL_COMPILER) -# if _MSC_VER >= 1800 +# elif (defined(__clang__) && defined(__has_feature)) +# if __has_feature(has_trivial_destructor) # define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) # endif # endif @@ -198,7 +184,7 @@ do { \ * inline a static function that we later use in an alias. - ajax */ #ifndef PUBLIC -# if defined(__GNUC__) +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) # define PUBLIC __attribute__((visibility("default"))) # define USED __attribute__((used)) # elif defined(_MSC_VER) @@ -216,34 +202,13 @@ 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 */ diff --git a/lib/mesa/src/util/ralloc.c b/lib/mesa/src/util/ralloc.c index 7bf192e0d..01719c888 100644 --- a/lib/mesa/src/util/ralloc.c +++ b/lib/mesa/src/util/ralloc.c @@ -51,20 +51,7 @@ _CRTIMP int _vscprintf(const char *format, va_list argptr); #define CANARY 0x5A1106 -/* Align the header's size so that ralloc() allocations will return with the - * same alignment as a libc malloc would have (8 on 32-bit GLIBC, 16 on - * 64-bit), avoiding performance penalities on x86 and alignment faults on - * ARM. - */ -struct -#ifdef _MSC_VER - __declspec(align(8)) -#elif defined(__LP64__) - __attribute__((aligned(16))) -#else - __attribute__((aligned(8))) -#endif - ralloc_header +struct ralloc_header { #ifdef DEBUG /* A canary value used to determine whether a pointer is ralloc'd. */ @@ -123,24 +110,13 @@ ralloc_context(const void *ctx) void * ralloc_size(const void *ctx, size_t size) { - void *block = malloc(size + sizeof(ralloc_header)); + void *block = calloc(1, size + sizeof(ralloc_header)); ralloc_header *info; ralloc_header *parent; if (unlikely(block == NULL)) return NULL; - info = (ralloc_header *) block; - /* measurements have shown that calloc is slower (because of - * the multiplication overflow checking?), so clear things - * manually - */ - info->parent = NULL; - info->child = NULL; - info->prev = NULL; - info->next = NULL; - info->destructor = NULL; - parent = ctx != NULL ? get_header(ctx) : NULL; add_child(parent, info); @@ -156,10 +132,8 @@ void * rzalloc_size(const void *ctx, size_t size) { void *ptr = ralloc_size(ctx, size); - - if (likely(ptr)) + if (likely(ptr != NULL)) memset(ptr, 0, size); - return ptr; } @@ -319,7 +293,6 @@ ralloc_adopt(const void *new_ctx, void *old_ctx) /* Connect the two lists together; parent them to new_ctx; make old_ctx empty. */ child->next = new_info->child; - child->parent = new_info; new_info->child = old_info->child; old_info->child = NULL; } @@ -336,6 +309,24 @@ ralloc_parent(const void *ptr) return info->parent ? PTR_FROM_HEADER(info->parent) : NULL; } +static void *autofree_context = NULL; + +static void +autofree(void) +{ + ralloc_free(autofree_context); +} + +void * +ralloc_autofree_context(void) +{ + if (unlikely(autofree_context == NULL)) { + autofree_context = ralloc_context(NULL); + atexit(autofree); + } + return autofree_context; +} + void ralloc_set_destructor(const void *ptr, void(*destructor)(void *)) { @@ -368,7 +359,10 @@ ralloc_strndup(const void *ctx, const char *str, size_t max) if (unlikely(str == NULL)) return NULL; - n = strnlen(str, max); + n = strlen(str); + if (n > max) + n = max; + ptr = ralloc_array(ctx, char, n + 1); memcpy(ptr, str, n); ptr[n] = '\0'; @@ -508,7 +502,6 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt, if (unlikely(*str == NULL)) { // Assuming a NULL context is probably bad, but it's expected behavior. *str = ralloc_vasprintf(NULL, fmt, args); - *start = strlen(*str); return true; } @@ -523,356 +516,3 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt, *start += new_length; return true; } - -/*************************************************************************** - * Linear allocator for short-lived allocations. - *************************************************************************** - * - * The allocator consists of a parent node (2K buffer), which requires - * a ralloc parent, and child nodes (allocations). Child nodes can't be freed - * directly, because the parent doesn't track them. You have to release - * the parent node in order to release all its children. - * - * The allocator uses a fixed-sized buffer with a monotonically increasing - * offset after each allocation. If the buffer is all used, another buffer - * is allocated, sharing the same ralloc parent, so all buffers are at - * the same level in the ralloc hierarchy. - * - * The linear parent node is always the first buffer and keeps track of all - * other buffers. - */ - -#define ALIGN_POT(x, y) (((x) + (y) - 1) & ~((y) - 1)) - -#define MIN_LINEAR_BUFSIZE 2048 -#define SUBALLOC_ALIGNMENT sizeof(uintptr_t) -#define LMAGIC 0x87b9c7d3 - -struct linear_header { -#ifdef DEBUG - unsigned magic; /* for debugging */ -#endif - unsigned offset; /* points to the first unused byte in the buffer */ - unsigned size; /* size of the buffer */ - void *ralloc_parent; /* new buffers will use this */ - struct linear_header *next; /* next buffer if we have more */ - struct linear_header *latest; /* the only buffer that has free space */ - - /* After this structure, the buffer begins. - * Each suballocation consists of linear_size_chunk as its header followed - * by the suballocation, so it goes: - * - * - linear_size_chunk - * - allocated space - * - linear_size_chunk - * - allocated space - * etc. - * - * linear_size_chunk is only needed by linear_realloc. - */ -}; - -struct linear_size_chunk { - unsigned size; /* for realloc */ - unsigned _padding; -}; - -typedef struct linear_header linear_header; -typedef struct linear_size_chunk linear_size_chunk; - -#define LINEAR_PARENT_TO_HEADER(parent) \ - (linear_header*) \ - ((char*)(parent) - sizeof(linear_size_chunk) - sizeof(linear_header)) - -/* Allocate the linear buffer with its header. */ -static linear_header * -create_linear_node(void *ralloc_ctx, unsigned min_size) -{ - linear_header *node; - - min_size += sizeof(linear_size_chunk); - - if (likely(min_size < MIN_LINEAR_BUFSIZE)) - min_size = MIN_LINEAR_BUFSIZE; - - node = ralloc_size(ralloc_ctx, sizeof(linear_header) + min_size); - if (unlikely(!node)) - return NULL; - -#ifdef DEBUG - node->magic = LMAGIC; -#endif - node->offset = 0; - node->size = min_size; - node->ralloc_parent = ralloc_ctx; - node->next = NULL; - node->latest = node; - return node; -} - -void * -linear_alloc_child(void *parent, unsigned size) -{ - linear_header *first = LINEAR_PARENT_TO_HEADER(parent); - linear_header *latest = first->latest; - linear_header *new_node; - linear_size_chunk *ptr; - unsigned full_size; - - assert(first->magic == LMAGIC); - assert(!latest->next); - - size = ALIGN_POT(size, SUBALLOC_ALIGNMENT); - full_size = sizeof(linear_size_chunk) + size; - - if (unlikely(latest->offset + full_size > latest->size)) { - /* allocate a new node */ - new_node = create_linear_node(latest->ralloc_parent, size); - if (unlikely(!new_node)) - return NULL; - - first->latest = new_node; - latest->latest = new_node; - latest->next = new_node; - latest = new_node; - } - - ptr = (linear_size_chunk *)((char*)&latest[1] + latest->offset); - ptr->size = size; - latest->offset += full_size; - return &ptr[1]; -} - -void * -linear_alloc_parent(void *ralloc_ctx, unsigned size) -{ - linear_header *node; - - if (unlikely(!ralloc_ctx)) - return NULL; - - size = ALIGN_POT(size, SUBALLOC_ALIGNMENT); - - node = create_linear_node(ralloc_ctx, size); - if (unlikely(!node)) - return NULL; - - return linear_alloc_child((char*)node + - sizeof(linear_header) + - sizeof(linear_size_chunk), size); -} - -void * -linear_zalloc_child(void *parent, unsigned size) -{ - void *ptr = linear_alloc_child(parent, size); - - if (likely(ptr)) - memset(ptr, 0, size); - return ptr; -} - -void * -linear_zalloc_parent(void *parent, unsigned size) -{ - void *ptr = linear_alloc_parent(parent, size); - - if (likely(ptr)) - memset(ptr, 0, size); - return ptr; -} - -void -linear_free_parent(void *ptr) -{ - linear_header *node; - - if (unlikely(!ptr)) - return; - - node = LINEAR_PARENT_TO_HEADER(ptr); - assert(node->magic == LMAGIC); - - while (node) { - void *ptr = node; - - node = node->next; - ralloc_free(ptr); - } -} - -void -ralloc_steal_linear_parent(void *new_ralloc_ctx, void *ptr) -{ - linear_header *node; - - if (unlikely(!ptr)) - return; - - node = LINEAR_PARENT_TO_HEADER(ptr); - assert(node->magic == LMAGIC); - - while (node) { - ralloc_steal(new_ralloc_ctx, node); - node->ralloc_parent = new_ralloc_ctx; - node = node->next; - } -} - -void * -ralloc_parent_of_linear_parent(void *ptr) -{ - linear_header *node = LINEAR_PARENT_TO_HEADER(ptr); - assert(node->magic == LMAGIC); - return node->ralloc_parent; -} - -void * -linear_realloc(void *parent, void *old, unsigned new_size) -{ - unsigned old_size = 0; - ralloc_header *new_ptr; - - new_ptr = linear_alloc_child(parent, new_size); - - if (unlikely(!old)) - return new_ptr; - - old_size = ((linear_size_chunk*)old)[-1].size; - - if (likely(new_ptr && old_size)) - memcpy(new_ptr, old, MIN2(old_size, new_size)); - - return new_ptr; -} - -/* All code below is pretty much copied from ralloc and only the alloc - * calls are different. - */ - -char * -linear_strdup(void *parent, const char *str) -{ - unsigned n; - char *ptr; - - if (unlikely(!str)) - return NULL; - - n = strlen(str); - ptr = linear_alloc_child(parent, n + 1); - if (unlikely(!ptr)) - return NULL; - - memcpy(ptr, str, n); - ptr[n] = '\0'; - return ptr; -} - -char * -linear_asprintf(void *parent, const char *fmt, ...) -{ - char *ptr; - va_list args; - va_start(args, fmt); - ptr = linear_vasprintf(parent, fmt, args); - va_end(args); - return ptr; -} - -char * -linear_vasprintf(void *parent, const char *fmt, va_list args) -{ - unsigned size = printf_length(fmt, args) + 1; - - char *ptr = linear_alloc_child(parent, size); - if (ptr != NULL) - vsnprintf(ptr, size, fmt, args); - - return ptr; -} - -bool -linear_asprintf_append(void *parent, char **str, const char *fmt, ...) -{ - bool success; - va_list args; - va_start(args, fmt); - success = linear_vasprintf_append(parent, str, fmt, args); - va_end(args); - return success; -} - -bool -linear_vasprintf_append(void *parent, char **str, const char *fmt, va_list args) -{ - size_t existing_length; - assert(str != NULL); - existing_length = *str ? strlen(*str) : 0; - return linear_vasprintf_rewrite_tail(parent, str, &existing_length, fmt, args); -} - -bool -linear_asprintf_rewrite_tail(void *parent, char **str, size_t *start, - const char *fmt, ...) -{ - bool success; - va_list args; - va_start(args, fmt); - success = linear_vasprintf_rewrite_tail(parent, str, start, fmt, args); - va_end(args); - return success; -} - -bool -linear_vasprintf_rewrite_tail(void *parent, char **str, size_t *start, - const char *fmt, va_list args) -{ - size_t new_length; - char *ptr; - - assert(str != NULL); - - if (unlikely(*str == NULL)) { - *str = linear_vasprintf(parent, fmt, args); - *start = strlen(*str); - return true; - } - - new_length = printf_length(fmt, args); - - ptr = linear_realloc(parent, *str, *start + new_length + 1); - if (unlikely(ptr == NULL)) - return false; - - vsnprintf(ptr + *start, new_length + 1, fmt, args); - *str = ptr; - *start += new_length; - return true; -} - -/* helper routine for strcat/strncat - n is the exact amount to copy */ -static bool -linear_cat(void *parent, char **dest, const char *str, unsigned n) -{ - char *both; - unsigned existing_length; - assert(dest != NULL && *dest != NULL); - - existing_length = strlen(*dest); - both = linear_realloc(parent, *dest, existing_length + n + 1); - if (unlikely(both == NULL)) - return false; - - memcpy(both + existing_length, str, n); - both[existing_length + n] = '\0'; - - *dest = both; - return true; -} - -bool -linear_strcat(void *parent, char **dest, const char *str) -{ - return linear_cat(parent, dest, str, strlen(str)); -} diff --git a/lib/mesa/src/util/register_allocate.h b/lib/mesa/src/util/register_allocate.h index 6abb4e04d..628d2bbbc 100644 --- a/lib/mesa/src/util/register_allocate.h +++ b/lib/mesa/src/util/register_allocate.h @@ -25,11 +25,9 @@ * */ -#ifndef REGISTER_ALLOCATE_H -#define REGISTER_ALLOCATE_H - #include <stdbool.h> + #ifdef __cplusplus extern "C" { #endif @@ -91,5 +89,3 @@ int ra_get_best_spill_node(struct ra_graph *g); #ifdef __cplusplus } // extern "C" #endif - -#endif /* REGISTER_ALLOCATE_H */ |