Fraser Cormack 37a3de1e2e libclc: Fix signed integer underflow in abs_diff
We noticed this same issue in our own implementation of abs_diff, and
the same issue also came up in the abs_diff reference function in the
OpenCL CTS.

Reviewed By: rjodinchr

Differential Revision: https://reviews.llvm.org/D159275
2023-08-31 14:28:16 +01:00

6 lines
244 B
C++

_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE abs_diff(__CLC_GENTYPE x, __CLC_GENTYPE y) {
__CLC_U_GENTYPE ux = __builtin_astype(x, __CLC_U_GENTYPE);
__CLC_U_GENTYPE uy = __builtin_astype(y, __CLC_U_GENTYPE);
return x > y ? ux - uy : uy - ux;
}