Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL] Fix abs_diff host implementation #12859

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions sycl/source/builtins/integer_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ BUILTIN_GENINT(ONE_ARG, abs, [](auto x) -> decltype(x) {
})

BUILTIN_GENINT_SU(TWO_ARGS, abs_diff, [](auto x, auto y) -> decltype(x) {
// From SYCL 2020 revision 8:
//
// > The subtraction is done without modulo overflow. The behavior is
// > undefined if the result cannot be represented by the return type.
return sycl::abs(x - y);
if constexpr (std::is_signed_v<decltype(x)>)
if ((x < 0) != (y < 0))
return std::abs(x) + std::abs(y);

return std::max(x, y) - std::min(x, y);
})

BUILTIN_GENINT_SU(TWO_ARGS, add_sat, [](auto x, auto y) -> decltype(x) {
Expand Down
7 changes: 7 additions & 0 deletions sycl/test-e2e/Basic/built-ins/marray_integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,12 @@ int main() {
marray<uint8_t, 2>{3, 2});
}

{
// Test abs_diff:
auto AbsDiff = [](auto... xs) { return abs_diff(xs...); };
Test(AbsDiff, marray<unsigned, 2>{1, 1}, marray<unsigned, 2>{0, 1},
marray<unsigned, 2>{1, 0});
}

return 0;
}
Loading