[Beignet] [PATCH] change behavior of mul24/mad24 when out of range

Guo Yejun yejun.guo at intel.com
Wed Feb 24 22:19:50 UTC 2016


mul24 and mad24 are supposed to be fast integer functions, but
the current implementation is slower. At least we should provide
same performance if not faster, so change the behavior when the
parameters are out of range since it is implementation-defined.

passed test: integer_ops of conformance test

Signed-off-by: Guo Yejun <yejun.guo at intel.com>
---
 backend/src/libocl/tmpl/ocl_integer.tmpl.cl | 4 ++--
 utests/compiler_mad24.cpp                   | 2 +-
 utests/compiler_mul24.cpp                   | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/backend/src/libocl/tmpl/ocl_integer.tmpl.cl b/backend/src/libocl/tmpl/ocl_integer.tmpl.cl
index 12408eb..7e7f4ae 100644
--- a/backend/src/libocl/tmpl/ocl_integer.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_integer.tmpl.cl
@@ -139,8 +139,8 @@ DEF(long)
 DEF(ulong)
 #undef DEF
 
-OVERLOADABLE int mul24(int a, int b) { return ((a << 8) >> 8) * ((b << 8) >> 8); }
-OVERLOADABLE uint mul24(uint a, uint b) { return (a & 0xFFFFFF) * (b & 0xFFFFFF); }
+OVERLOADABLE int mul24(int a, int b) { return a*b; }
+OVERLOADABLE uint mul24(uint a, uint b) { return a*b; }
 
 OVERLOADABLE int mad24(int a, int b, int c) { return mul24(a, b) + c; }
 OVERLOADABLE uint mad24(uint a, uint b, uint c) { return mul24(a, b) + c; }
diff --git a/utests/compiler_mad24.cpp b/utests/compiler_mad24.cpp
index a3890a1..ba2dcf6 100644
--- a/utests/compiler_mad24.cpp
+++ b/utests/compiler_mad24.cpp
@@ -34,7 +34,7 @@ void compiler_mad24(void)
 
   OCL_MAP_BUFFER(3);
   for (int i = 0; i < n; ++i)
-    OCL_ASSERT(((int*)buf_data[3])[i] == ((src1[i] << 8) >> 8) * ((src2[i] << 8) >> 8) + src3[i]);
+    OCL_ASSERT(((int*)buf_data[3])[i] == (src1[i]) * (src2[i]) + src3[i]);
   OCL_UNMAP_BUFFER(3);
 }
 
diff --git a/utests/compiler_mul24.cpp b/utests/compiler_mul24.cpp
index 8a36947..f1a9a40 100644
--- a/utests/compiler_mul24.cpp
+++ b/utests/compiler_mul24.cpp
@@ -29,7 +29,7 @@ void compiler_mul24(void)
 
   OCL_MAP_BUFFER(2);
   for (int i = 0; i < n; ++i)
-    OCL_ASSERT(((int*)buf_data[2])[i] == ((src1[i] << 8) >> 8) * ((src2[i] << 8) >> 8));
+    OCL_ASSERT(((int*)buf_data[2])[i] == (src1[i]) * (src2[i]));
   OCL_UNMAP_BUFFER(2);
 }
 
-- 
1.9.1



More information about the Beignet mailing list