aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/util')
-rw-r--r--mesalib/src/util/Makefile.sources3
-rw-r--r--mesalib/src/util/hash_table.c10
-rw-r--r--mesalib/src/util/macros.h18
-rw-r--r--mesalib/src/util/strtod.cpp75
-rw-r--r--mesalib/src/util/strtod.h46
5 files changed, 145 insertions, 7 deletions
diff --git a/mesalib/src/util/Makefile.sources b/mesalib/src/util/Makefile.sources
index 952b79905..9e274241d 100644
--- a/mesalib/src/util/Makefile.sources
+++ b/mesalib/src/util/Makefile.sources
@@ -3,7 +3,8 @@ MESA_UTIL_FILES := \
ralloc.c \
register_allocate.c \
register_allocate.h \
- rgtc.c
+ rgtc.c \
+ strtod.cpp
MESA_UTIL_GENERATED_FILES = \
format_srgb.c
diff --git a/mesalib/src/util/hash_table.c b/mesalib/src/util/hash_table.c
index 1b6726c79..920bdfd33 100644
--- a/mesalib/src/util/hash_table.c
+++ b/mesalib/src/util/hash_table.c
@@ -385,12 +385,12 @@ _mesa_hash_table_random_entry(struct hash_table *ht,
/**
- * Quick FNV-1 hash implementation based on:
+ * Quick FNV-1a hash implementation based on:
* http://www.isthe.com/chongo/tech/comp/fnv/
*
- * FNV-1 is not be the best hash out there -- Jenkins's lookup3 is supposed to
- * be quite good, and it probably beats FNV. But FNV has the advantage that
- * it involves almost no code. For an improvement on both, see Paul
+ * FNV-1a is not be the best hash out there -- Jenkins's lookup3 is supposed
+ * to be quite good, and it probably beats FNV. But FNV has the advantage
+ * that it involves almost no code. For an improvement on both, see Paul
* Hsieh's http://www.azillionmonkeys.com/qed/hash.html
*/
uint32_t
@@ -408,7 +408,7 @@ _mesa_hash_data(const void *data, size_t size)
return hash;
}
-/** FNV-1 string hash implementation */
+/** FNV-1a string hash implementation */
uint32_t
_mesa_hash_string(const char *key)
{
diff --git a/mesalib/src/util/macros.h b/mesalib/src/util/macros.h
index ff37a7d63..5fc672953 100644
--- a/mesalib/src/util/macros.h
+++ b/mesalib/src/util/macros.h
@@ -29,6 +29,10 @@
# define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
#endif
+/* For compatibility with Clang's __has_builtin() */
+#ifndef __has_builtin
+# define __has_builtin(x) 0
+#endif
/**
* __builtin_expect macros
@@ -69,6 +73,12 @@ do { \
assert(!str); \
__builtin_unreachable(); \
} while (0)
+#elif _MSC_VER >= 1200
+#define unreachable(str) \
+do { \
+ assert(!str); \
+ __assume(0); \
+} while (0)
#endif
#ifndef unreachable
@@ -79,7 +89,13 @@ do { \
* Assume macro. Useful for expressing our assumptions to the compiler,
* typically for purposes of silencing warnings.
*/
-#ifdef HAVE___BUILTIN_UNREACHABLE
+#if __has_builtin(__builtin_assume)
+#define assume(expr) \
+do { \
+ assert(expr); \
+ __builtin_assume(expr); \
+} while (0)
+#elif defined HAVE___BUILTIN_UNREACHABLE
#define assume(expr) ((expr) ? ((void) 0) \
: (assert(!"assumption failed"), \
__builtin_unreachable()))
diff --git a/mesalib/src/util/strtod.cpp b/mesalib/src/util/strtod.cpp
new file mode 100644
index 000000000..2b4dd982a
--- /dev/null
+++ b/mesalib/src/util/strtod.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
+ */
+
+
+#include <stdlib.h>
+
+#ifdef _GNU_SOURCE
+#include <locale.h>
+#ifdef HAVE_XLOCALE_H
+#include <xlocale.h>
+#endif
+#endif
+
+#include "strtod.h"
+
+
+#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
+static struct locale_initializer {
+ locale_initializer() { loc = newlocale(LC_CTYPE_MASK, "C", NULL); }
+ locale_t loc;
+} loc_init;
+#endif
+
+/**
+ * Wrapper around strtod which uses the "C" locale so the decimal
+ * point is always '.'
+ */
+double
+_mesa_strtod(const char *s, char **end)
+{
+#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
+ return strtod_l(s, end, loc_init.loc);
+#else
+ return strtod(s, end);
+#endif
+}
+
+
+/**
+ * Wrapper around strtof which uses the "C" locale so the decimal
+ * point is always '.'
+ */
+float
+_mesa_strtof(const char *s, char **end)
+{
+#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
+ return strtof_l(s, end, loc_init.loc);
+#elif defined(HAVE_STRTOF)
+ return strtof(s, end);
+#else
+ return (float) strtod(s, end);
+#endif
+}
diff --git a/mesalib/src/util/strtod.h b/mesalib/src/util/strtod.h
new file mode 100644
index 000000000..02c25ddb7
--- /dev/null
+++ b/mesalib/src/util/strtod.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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 STRTOD_H
+#define STRTOD_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern double
+_mesa_strtod(const char *s, char **end);
+
+extern float
+_mesa_strtof(const char *s, char **end);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif