[Mesa-dev] [PATCH 1.5/10] i965: Add unit test for float <-> VF conversions.

Matt Turner mattst88 at gmail.com
Fri Oct 24 11:45:36 PDT 2014


Using Eric's original VF -> float conversion code to initialize the table.
---
 src/mesa/drivers/dri/i965/Makefile.am              |  7 ++
 .../drivers/dri/i965/test_vf_float_conversions.cpp | 84 ++++++++++++++++++++++
 2 files changed, 91 insertions(+)
 create mode 100644 src/mesa/drivers/dri/i965/test_vf_float_conversions.cpp

diff --git a/src/mesa/drivers/dri/i965/Makefile.am b/src/mesa/drivers/dri/i965/Makefile.am
index 5809dc6..ad170fa 100644
--- a/src/mesa/drivers/dri/i965/Makefile.am
+++ b/src/mesa/drivers/dri/i965/Makefile.am
@@ -55,11 +55,18 @@ TEST_LIBS = \
 
 TESTS = \
         test_eu_compact \
+	test_vf_float_conversions \
         test_vec4_copy_propagation \
         test_vec4_register_coalesce
 
 check_PROGRAMS = $(TESTS)
 
+test_vf_float_conversions_SOURCES = \
+	test_vf_float_conversions.cpp
+test_vf_float_conversions_LDADD = \
+	$(TEST_LIBS) \
+	$(top_builddir)/src/gtest/libgtest.la
+
 test_vec4_register_coalesce_SOURCES = \
 	test_vec4_register_coalesce.cpp
 test_vec4_register_coalesce_LDADD = \
diff --git a/src/mesa/drivers/dri/i965/test_vf_float_conversions.cpp b/src/mesa/drivers/dri/i965/test_vf_float_conversions.cpp
new file mode 100644
index 0000000..6d71b9b
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/test_vf_float_conversions.cpp
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+
+#include <gtest/gtest.h>
+#include <math.h>
+#include "brw_reg.h"
+
+class vf_float_conversion_test : public ::testing::Test {
+   virtual void SetUp();
+
+public:
+   float vf_to_float[128];
+};
+
+void vf_float_conversion_test::SetUp() {
+   /* 0 is special cased. */
+   vf_to_float[0] = 0.0;
+
+   for (int vf = 1; vf < 128; vf++) {
+      int ebits = (vf >> 4) & 0x7;
+      int mbits = vf & 0xf;
+
+      int e = ebits - 3;
+
+      float value = 1.0f;
+
+      value += mbits / 16.0f;
+
+      value *= exp2f(e);
+
+      vf_to_float[vf] = value;
+   }
+}
+
+union fu {
+   float f;
+   unsigned u;
+};
+
+TEST_F(vf_float_conversion_test, test_vf_to_float)
+{
+   for (int vf = 0; vf < 256; vf++) {
+      union fu expected = { .f = vf_to_float[vf % 128] };
+      if (vf > 127)
+         expected.f = -expected.f;
+
+      union fu calculated = { .f = brw_vf_to_float(vf) };
+
+      EXPECT_EQ(calculated.u, expected.u);
+   }
+}
+
+TEST_F(vf_float_conversion_test, test_float_to_vf)
+{
+   for (int vf = 0; vf < 256; vf++) {
+      float f = vf_to_float[vf % 128];
+      if (vf > 127)
+         f = -f;
+
+      int calculated = brw_float_to_vf(f);
+
+      EXPECT_EQ(calculated, vf);
+   }
+}
-- 
2.0.4



More information about the mesa-dev mailing list