[Beignet] [PATCH V2 2/9] Utest: Add as_float as_uint helper function

Xiuli Pan xiuli.pan at intel.com
Mon Aug 8 03:31:20 UTC 2016


From: Pan Xiuli <xiuli.pan at intel.com>

These functions are used with half float convert funcitons.

Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
---
 utests/utest_helper.cpp | 10 ++++++++++
 utests/utest_helper.hpp |  7 +++++++
 2 files changed, 17 insertions(+)

diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp
index 5a2ac6e..70a69cc 100644
--- a/utests/utest_helper.cpp
+++ b/utests/utest_helper.cpp
@@ -1046,3 +1046,13 @@ uint16_t __float_to_half(uint32_t x)
   bits += m & 1;
   return bits;
 }
+uint32_t as_uint(float f) {
+  union uint32_cast _tmp;
+  _tmp._float = f;
+  return _tmp._uint;
+}
+float as_float(uint32_t i) {
+  union uint32_cast _tmp;
+  _tmp._uint = i;
+  return _tmp._float;
+}
diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp
index 561c2c4..5f2fea6 100644
--- a/utests/utest_helper.hpp
+++ b/utests/utest_helper.hpp
@@ -52,6 +52,11 @@ extern EGLContext  eglContext;
 extern EGLSurface  eglSurface;
 #endif
 
+union uint32_cast {
+  uint32_t _uint;
+  float _float;
+};
+
 #define OCL_THROW_ERROR(FN, STATUS) \
   do { \
     char msg[2048]; \
@@ -306,4 +311,6 @@ extern int cl_check_half(void);
 /* Helper function for half type numbers */
 extern uint32_t __half_to_float(uint16_t h, bool* isInf = NULL, bool* infSign = NULL);
 extern uint16_t __float_to_half(uint32_t x);
+extern float as_float(uint32_t i);
+extern uint32_t as_uint(float f);
 #endif /* __UTEST_HELPER_HPP__ */
-- 
2.7.4



More information about the Beignet mailing list