diff options
author | Ruiling Song <ruiling.song@intel.com> | 2014-09-15 11:14:05 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2014-09-15 12:04:06 +0800 |
commit | d1854ddacdf71bfe42a66e81713065d8d56035db (patch) | |
tree | 2a415354fb423050d0b7a8480ba43c0e9c548c1a | |
parent | 1c743b0e1262efa676950cbc27418a2210711801 (diff) |
GBE/libocl: Fix sub_sat corner case.
It seems that hw return wrong result when y is equal to 0x80000000
in sub_sat(int x, int y). So we re-write it as:
add_sat(add_sat(0x7fffffff, x), 1)
Also enable corresponding utest.
Signed-off-by: Ruiling Song <ruiling.song@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
-rw-r--r-- | backend/src/libocl/tmpl/ocl_integer.tmpl.cl | 2 | ||||
-rw-r--r-- | utests/compiler_saturate_sub.cpp | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/backend/src/libocl/tmpl/ocl_integer.tmpl.cl b/backend/src/libocl/tmpl/ocl_integer.tmpl.cl index d33d70e..9230604 100644 --- a/backend/src/libocl/tmpl/ocl_integer.tmpl.cl +++ b/backend/src/libocl/tmpl/ocl_integer.tmpl.cl @@ -100,7 +100,7 @@ OVERLOADABLE int ocl_sadd_sat(int x, int y); OVERLOADABLE int add_sat(int x, int y) { return ocl_sadd_sat(x, y); } OVERLOADABLE int ocl_ssub_sat(int x, int y); OVERLOADABLE int sub_sat(int x, int y) { - return (y == 0x80000000u) ? (x & 0x7FFFFFFF) : ocl_ssub_sat(x, y); + return (y == 0x80000000u) ? (ocl_sadd_sat(ocl_sadd_sat(0x7fffffff, x), 1)) : ocl_ssub_sat(x, y); } OVERLOADABLE long ocl_sadd_sat(long x, long y); OVERLOADABLE long add_sat(long x, long y) { diff --git a/utests/compiler_saturate_sub.cpp b/utests/compiler_saturate_sub.cpp index 48947b7..1c95e2d 100644 --- a/utests/compiler_saturate_sub.cpp +++ b/utests/compiler_saturate_sub.cpp @@ -108,7 +108,7 @@ compiler_saturate_sub(int8_t, test_char) compiler_saturate_sub(uint8_t, test_uchar) compiler_saturate_sub(int16_t, test_short) compiler_saturate_sub(uint16_t, test_ushort) -//compiler_saturate_sub(int32_t, test_int) // TODO due to the possible hardware bug, we disable this, uncomment it when it's done. +compiler_saturate_sub(int32_t, test_int) compiler_saturate_sub(uint32_t, test_uint) //compiler_saturate_sub(int64_t, test_long) //compiler_saturate_sub(uint64_t, test_ulong) |