summaryrefslogtreecommitdiff
path: root/utests/compiler_overflow.cpp
diff options
context:
space:
mode:
authorLuo Xionghu <xionghu.luo@intel.com>2014-11-03 05:22:04 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-11-03 17:25:24 +0800
commit9d0897633f8ff15c7c5d9fde2feeec700dddbf5a (patch)
tree5fefbfaf5a2e47ce49f6cc50906bee54b8624292 /utests/compiler_overflow.cpp
parent65a3d67bd06c480573d885c3c35919247685817c (diff)
downloadbeignet-9d0897633f8ff15c7c5d9fde2feeec700dddbf5a.tar.gz
add utest for llvm intrinsic call usub_with_overflow funtion.
as llvm couldn't recognize the pattern of usub overflow, this usub with is generated by calling the intrinsic function __builtin_usub_overflow; also this type of uadd intrinsic funtion couldn't support short/byte type overflow, we choose another way for the uadd kernel to generate short/byte overflow. will send patch to llvm later to fix the 2 issues. v2: split the patch. Signed-off-by: Luo Xionghu <xionghu.luo@intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'utests/compiler_overflow.cpp')
-rw-r--r--utests/compiler_overflow.cpp97
1 files changed, 77 insertions, 20 deletions
diff --git a/utests/compiler_overflow.cpp b/utests/compiler_overflow.cpp
index 1d3f53d1..1404cfea 100644
--- a/utests/compiler_overflow.cpp
+++ b/utests/compiler_overflow.cpp
@@ -3,6 +3,13 @@
namespace {
typedef struct {
+ unsigned long x;
+ unsigned long y;
+ unsigned long z;
+ unsigned long w;
+}ulong4;
+
+typedef struct {
uint32_t x;
uint32_t y;
uint32_t z;
@@ -23,8 +30,18 @@ typedef struct {
uint8_t w;
} uchar4;
-template<typename T>
-void test(const char *kernel_name, int s_type)
+template <typename U>
+U get_max()
+{
+ int shift_bit = sizeof(U)*8;
+ U u_max = 0;
+ for (int i = 0; i < shift_bit; i++)
+ u_max |= 1<<(shift_bit-i-1);
+ return u_max;
+}
+
+template<typename T, typename U>
+void test(const char *kernel_name, int func_type)
{
const size_t n = 16;
@@ -32,41 +49,81 @@ void test(const char *kernel_name, int s_type)
OCL_CREATE_KERNEL_FROM_FILE("compiler_overflow", kernel_name);
OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(T), NULL);
OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(T), NULL);
+ OCL_CREATE_BUFFER(buf[2], 0, n * sizeof(T), NULL);
OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+ OCL_SET_ARG(2, sizeof(cl_mem), &buf[2]);
+
+ U max = get_max<U>();
OCL_MAP_BUFFER(0);
for (uint32_t i = 0; i < n; ++i) {
- ((T*)buf_data[0])[i].x = s_type?CL_INT_MAX:CL_UINT_MAX;
- ((T*)buf_data[0])[i].y = s_type?CL_INT_MAX:CL_UINT_MAX;
- ((T*)buf_data[0])[i].z = s_type?CL_INT_MAX:CL_UINT_MAX;
- ((T*)buf_data[0])[i].w = i;
+ if(func_type == 0) {
+ ((T*)buf_data[0])[i].x = max;
+ ((T*)buf_data[0])[i].y = max;
+ ((T*)buf_data[0])[i].z = max;
+ ((T*)buf_data[0])[i].w = i;
+ }else if(func_type == 1) {
+ ((T*)buf_data[0])[i].x = 0;
+ ((T*)buf_data[0])[i].y = 0;
+ ((T*)buf_data[0])[i].z = 0;
+ ((T*)buf_data[0])[i].w = n+2-i;
+ }else
+ OCL_ASSERT(0);
}
OCL_UNMAP_BUFFER(0);
+ OCL_MAP_BUFFER(1);
+ for (uint32_t i = 0; i < n; ++i) {
+ ((T*)buf_data[1])[i].x = 1;
+ ((T*)buf_data[1])[i].y = 1;
+ ((T*)buf_data[1])[i].z = 1;
+ ((T*)buf_data[1])[i].w = 1;
+ }
+ OCL_UNMAP_BUFFER(1);
globals[0] = n;
locals[0] = 16;
OCL_NDRANGE(1);
-
- OCL_MAP_BUFFER(1);
+ OCL_MAP_BUFFER(2);
for (uint32_t i = 0; i < 16; ++i) {
- OCL_ASSERT(((T*)buf_data[1])[i].x == 0);
- OCL_ASSERT(((T*)buf_data[1])[i].y == 1);
- OCL_ASSERT(((T*)buf_data[1])[i].z == 1);
- OCL_ASSERT(((T*)buf_data[1])[i].w == i+2);
+ // printf("%u,%u,%u,%u\n", ((T*)buf_data[2])[i].x,((T*)buf_data[2])[i].y, ((T*)buf_data[2])[i].z, ((T*)buf_data[2])[i].w );
+ if(func_type == 0) {
+ OCL_ASSERT(((T*)buf_data[2])[i].x == 0);
+ OCL_ASSERT(((T*)buf_data[2])[i].y == 1);
+ OCL_ASSERT(((T*)buf_data[2])[i].z == 1);
+ OCL_ASSERT(((T*)buf_data[2])[i].w == i+2);
+ }else if(func_type == 1) {
+ OCL_ASSERT(((T*)buf_data[2])[i].x == max);
+ OCL_ASSERT(((T*)buf_data[2])[i].y == max-1);
+ OCL_ASSERT(((T*)buf_data[2])[i].z == max-1);
+ OCL_ASSERT(((T*)buf_data[2])[i].w == n-i);
+ }else
+ OCL_ASSERT(0);
}
- OCL_UNMAP_BUFFER(1);
+ OCL_UNMAP_BUFFER(2);
}
}
-#define compiler_overflow(type, kernel, s_type) \
-static void compiler_overflow_ ##type(void)\
+#define compiler_overflow_add(type, subtype, kernel, func_type) \
+static void compiler_overflow_add_ ##type(void)\
{\
- test<type>(# kernel, s_type);\
+ test<type, subtype>(# kernel, func_type);\
}\
-MAKE_UTEST_FROM_FUNCTION(compiler_overflow_ ## type);
+MAKE_UTEST_FROM_FUNCTION(compiler_overflow_add_ ## type);
+
+#define compiler_overflow_sub(type, subtype, kernel, func_type) \
+static void compiler_overflow_sub_ ##type(void)\
+{\
+ test<type, subtype>(# kernel, func_type);\
+}\
+MAKE_UTEST_FROM_FUNCTION(compiler_overflow_sub_ ## type);
+
+compiler_overflow_add(ulong4, unsigned long, compiler_overflow_ulong4_add, 0)
+compiler_overflow_add(uint4, uint32_t, compiler_overflow_uint4_add, 0)
+compiler_overflow_add(ushort4, uint16_t, compiler_overflow_ushort4_add, 0)
+compiler_overflow_add(uchar4, uint8_t, compiler_overflow_uchar4_add, 0)
-compiler_overflow(uint4, compiler_overflow_uint4, 0)
-compiler_overflow(ushort4, compiler_overflow_ushort4, 0)
-compiler_overflow(uchar4, compiler_overflow_uchar4, 0)
+// as llvm intrincs function doesn't support byte/short overflow,
+// we just test uint overflow here.
+compiler_overflow_sub(uint4, uint32_t, compiler_overflow_uint4_sub, 1)