summaryrefslogtreecommitdiff
path: root/tests/util/piglit-util.h
diff options
context:
space:
mode:
authorAndres Gomez <agomez@igalia.com>2016-04-19 14:34:13 +0300
committerAntia Puentes <apuentes@igalia.com>2016-05-04 14:30:48 +0200
commit5088a9e73c62f5bd39d9a21390fa648c3a3f87b2 (patch)
tree598318af1d3044f2e7ec0e6d6c3a6e738a1a46e1 /tests/util/piglit-util.h
parent094cae4c8a0e2301958f90910a234393637f5c59 (diff)
util: Wrappers to load hex values for floats
For some cases we want to have shaders where we load an exact bit pattern into a float or double. We already have this in place for uniforms. Now, the methods have been refactorized so they can be used in VBOs too. Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com> Signed-off-by: Andres Gomez <agomez@igalia.com>
Diffstat (limited to 'tests/util/piglit-util.h')
-rw-r--r--tests/util/piglit-util.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 985ebbdac..1e5721517 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -221,6 +221,54 @@ strtod_inf(const char *nptr, char **endptr)
return strtod(nptr, endptr);
}
+/**
+ * Wrapper for strtod_inf() which allows using an exact hex bit
+ * pattern to generate a float value.
+ */
+static inline float
+strtof_hex(const char *nptr, char **endptr)
+{
+ /* skip spaces and tabs */
+ while (*nptr == ' ' || *nptr == '\t')
+ nptr++;
+
+ if (strncmp(nptr, "0x", 2) == 0) {
+ union {
+ uint32_t u;
+ float f;
+ } x;
+
+ x.u = strtoul(nptr, endptr, 16);
+ return x.f;
+ } else {
+ return strtod_inf(nptr, endptr);
+ }
+}
+
+/**
+ * Wrapper for strtod_inf() which allows using an exact hex bit
+ * pattern to generate a double value.
+ */
+static inline double
+strtod_hex(const char *nptr, char **endptr)
+{
+ /* skip spaces and tabs */
+ while (*nptr == ' ' || *nptr == '\t')
+ nptr++;
+
+ if (strncmp(nptr, "0x", 2) == 0) {
+ union {
+ uint64_t u64;
+ double d;
+ } x;
+
+ x.u64 = strtoull(nptr, endptr, 16);
+ return x.d;
+ } else {
+ return strtod_inf(nptr, endptr);
+ }
+}
+
#ifndef HAVE_STRCHRNUL
static inline char *
strchrnul(const char *s, int c)