Skip to content

[SYCLCompat] Fix compare_mask implementations and test #16768

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

Merged
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
8 changes: 4 additions & 4 deletions sycl/include/syclcompat/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ template <typename ValueT, class BinaryOperation>
inline std::enable_if_t<ValueT::size() == 2, unsigned>
compare_mask(const ValueT a, const ValueT b, const BinaryOperation binary_op) {
// Since compare returns 0 or 1, -compare will be 0x00000000 or 0xFFFFFFFF
return ((-compare(a[0], b[0], binary_op)) << 16) |
((-compare(a[1], b[1], binary_op)) & 0xFFFF);
return ((-compare(a[0], b[0], binary_op)) & 0xFFFF) |
((-compare(a[1], b[1], binary_op)) << 16u);
}

/// Performs 2 elements unordered comparison, compare result of each element is
Expand All @@ -613,8 +613,8 @@ template <typename ValueT, class BinaryOperation>
inline std::enable_if_t<ValueT::size() == 2, unsigned>
unordered_compare_mask(const ValueT a, const ValueT b,
const BinaryOperation binary_op) {
return ((-unordered_compare(a[0], b[0], binary_op)) << 16) |
((-unordered_compare(a[1], b[1], binary_op)) & 0xFFFF);
return ((-unordered_compare(a[0], b[0], binary_op)) & 0xFFFF) |
((-unordered_compare(a[1], b[1], binary_op)) << 16);
}

/// Compute vectorized max for two values, with each value treated as a vector
Expand Down
8 changes: 4 additions & 4 deletions sycl/test-e2e/syclcompat/math/math_compare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ typename ValueT> void test_compare_mask() {
// 1.0 == 1.0, 2.0 == 3.0 -> 0xffff0000
BinaryOpTestLauncher<Container, Container, unsigned>(grid, threads)
.template launch_test<compare_mask_kernel<Container>>(op1, op3,
0xffff0000);
0x0000ffff);

// 1.0 == 3.0, 2.0 == 2.0 -> 0x0000ffff
BinaryOpTestLauncher<Container, Container, unsigned>(grid, threads)
.template launch_test<compare_mask_kernel<Container>>(op1, op4,
0x0000ffff);
0xffff0000);

// 1.0 == NaN, 2.0 == NaN -> 0x00000000
BinaryOpTestLauncher<Container, Container, unsigned>(grid, threads)
Expand Down Expand Up @@ -350,12 +350,12 @@ typename ValueT> void test_unordered_compare_mask() {
// 1.0 == 1.0, 2.0 == 3.0 -> 0xffff0000
BinaryOpTestLauncher<Container, Container, unsigned>(grid, threads)
.template launch_test<unordered_compare_mask_kernel<Container>>(
op1, op3, 0xffff0000);
op1, op3, 0x0000ffff);

// 1.0 == 3.0, 2.0 == 2.0 -> 0x0000ffff
BinaryOpTestLauncher<Container, Container, unsigned>(grid, threads)
.template launch_test<unordered_compare_mask_kernel<Container>>(
op1, op4, 0x0000ffff);
op1, op4, 0xffff0000);

// 1.0 == NaN, 2.0 == NaN -> 0xffffffff
BinaryOpTestLauncher<Container, Container, unsigned>(grid, threads)
Expand Down
Loading