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>
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) {
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)