[Piglit] [PATCH 1/2] cl: Split piglit_cl_probe_floating() into two functions

Tom Stellard tom at stellard.net
Wed Jul 31 19:16:53 PDT 2013


From: Tom Stellard <thomas.stellard at amd.com>

piglit_cl_probe_floating() now takes float arguments and the new
piglit_cl_probe_double() takes double arguments.  The error reporting
printf has also been fixed so that it prints the actual hex
representation of the floating-point number.  The previous code was
casting float to int and then printing the result which was leading to
confusing output.
---
 tests/util/piglit-util-cl.c | 54 +++++++++++++++++++++++++++++++++++++++------
 tests/util/piglit-util-cl.h |  8 ++++++-
 2 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/tests/util/piglit-util-cl.c b/tests/util/piglit-util-cl.c
index dc0fb3a..5b4267f 100644
--- a/tests/util/piglit-util-cl.c
+++ b/tests/util/piglit-util-cl.c
@@ -55,27 +55,67 @@ piglit_cl_probe_uinteger(uint64_t value, uint64_t expect, uint64_t tolerance)
 	return true;
 }
 
+# define probe_float_check_nan_inf(value, expect) \
+	((isnan(value) && isnan(expect)) || \
+	(isinf(value) && isinf(expect) && ((value > 0) == (expect > 0))))
+
+
+/* TODO: Tolerance should be specified in terms of ULP. */
 bool
-piglit_cl_probe_floating(double value, double expect, double tolerance)
+piglit_cl_probe_floating(float value, float expect,  float tolerance)
 {
-	double diff;
+	float diff;
+	union {
+		float f;
+		unsigned u;
+	} v, e, t;
+
+	v.f = value;
+	e.f = expect;
+	t.f = tolerance;
+	/* Treat infinity and nan seperately */
+	if (probe_float_check_nan_inf(value, expect)) {
+		return true;
+	}
+
+	diff = value > expect ? value-expect : expect-value;
+
+	if(diff > tolerance || isnan(value)) {
+		printf("Expecting %f (0x%x) with tolerance %f, but got %f (0x%x)\n",
+		       e.f, e.u, t.f, v.f, v.u);
+		return false;
+	}
+
+	return true;
+}
 
+bool
+piglit_cl_probe_double(double value, double expect, double tolerance)
+{
+	double diff;
+	union {
+		double f;
+		uint64_t u;
+	} v, e, t;
+
+	v.f = value;
+	e.f = expect;
+	t.f = tolerance;
 	/* Treat infinity and nan seperately */
-	if(   (isnan(value) && isnan(expect))
-	   || (isinf(value) && isinf(expect) && ((value > 0) == (expect > 0)))) {
+	if (probe_float_check_nan_inf(value, expect)) {
 		return true;
 	}
 
 	diff = value > expect ? value-expect : expect-value;
 
 	if(diff > tolerance || isnan(value)) {
-		printf("Expecting %f (0x%"PRIx64") with tolerance %f, but got %f (0x%"
-		       PRIx64")\n",
-		       expect, (uint64_t)expect, tolerance, value, (uint64_t)value);
+		printf("Expecting %f (0x%lx) with tolerance %f, but got %f (0x%lx)\n",
+		       e.f, e.u, t.f, v.f, v.u);
 		return false;
 	}
 
 	return true;
+
 }
 
 bool
diff --git a/tests/util/piglit-util-cl.h b/tests/util/piglit-util-cl.h
index 4420e32..90d0cd2 100644
--- a/tests/util/piglit-util-cl.h
+++ b/tests/util/piglit-util-cl.h
@@ -65,7 +65,13 @@ bool piglit_cl_probe_uinteger(uint64_t value,
  * \brief Probe floating-point \c value if it compares equal to \c expect with
  *        tolerance \c tolerance.
  */
-bool piglit_cl_probe_floating(double value, double expect, double tolerance);
+bool piglit_cl_probe_floating(float value, float expect, float tolerance);
+
+/**
+ * \brief Probe double \c value if it compares equal to \c expect with
+ *        tolerance \c tolerance.
+ */
+bool piglit_cl_probe_double(double value, double expect, double tolerance);
 
 /**
  * \brief Check for unexpected GL error and report it.
-- 
1.7.11.4



More information about the Piglit mailing list