summaryrefslogtreecommitdiff
path: root/utests/compiler_overflow.cpp
diff options
context:
space:
mode:
authorLuo Xionghu <xionghu.luo@intel.com>2014-12-05 15:30:28 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-12-15 09:50:09 +0800
commit222030b4f30001679a7b19b1f8bad0653cc6be73 (patch)
tree9454812ca39fb40b556d317171d8d5164183eeeb /utests/compiler_overflow.cpp
parentf0540fca21021bcd0ef2c5a7c22d5b38ca1f366b (diff)
downloadbeignet-222030b4f30001679a7b19b1f8bad0653cc6be73.tar.gz
refine overflow utest to cover nsetc fail cases.
the original case only tested overflow when src1 is 1, add the test of src1 is max(this could trigger signed type uadd.with.overflow results incorrect, the fail was fixed in backend already, just update the utest.) 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.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/utests/compiler_overflow.cpp b/utests/compiler_overflow.cpp
index 1404cfea..5517b5a5 100644
--- a/utests/compiler_overflow.cpp
+++ b/utests/compiler_overflow.cpp
@@ -56,6 +56,9 @@ void test(const char *kernel_name, int func_type)
U max = get_max<U>();
+ // test add and sub overflow when src1 is 1:
+ // uadd.with.overflow: max + 1
+ // usub.with.overflow: 0 - 1
OCL_MAP_BUFFER(0);
for (uint32_t i = 0; i < n; ++i) {
if(func_type == 0) {
@@ -101,6 +104,55 @@ void test(const char *kernel_name, int func_type)
OCL_ASSERT(0);
}
OCL_UNMAP_BUFFER(2);
+
+ // test add and sub overflow when src1 is max:
+ // uadd.with.overflow: max + max
+ // usub.with.overflow: 0 - max
+ OCL_MAP_BUFFER(0);
+ for (uint32_t i = 0; i < n; ++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 = max;
+ ((T*)buf_data[1])[i].y = max;
+ ((T*)buf_data[1])[i].z = max;
+ ((T*)buf_data[1])[i].w = 1;
+ }
+ OCL_UNMAP_BUFFER(1);
+
+ globals[0] = n;
+ locals[0] = 16;
+ OCL_NDRANGE(1);
+ OCL_MAP_BUFFER(2);
+ for (uint32_t i = 0; i < 16; ++i) {
+ // 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 == max-1);
+ OCL_ASSERT(((T*)buf_data[2])[i].y == max);
+ OCL_ASSERT(((T*)buf_data[2])[i].z == max);
+ OCL_ASSERT(((T*)buf_data[2])[i].w == i+2);
+ }else if(func_type == 1) {
+ OCL_ASSERT(((T*)buf_data[2])[i].x == 1);
+ OCL_ASSERT(((T*)buf_data[2])[i].y == 0);
+ OCL_ASSERT(((T*)buf_data[2])[i].z == 0);
+ OCL_ASSERT(((T*)buf_data[2])[i].w == n-i);
+ }else
+ OCL_ASSERT(0);
+ }
+ OCL_UNMAP_BUFFER(2);
}
}