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

Avoid checking unsigned values for negativity #2997

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
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
13 changes: 8 additions & 5 deletions cub/cub/detail/fast_modulo_division.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,14 @@ multiply_extract_higher_bits(T value, R multiplier)
{
static_assert(supported_integral<T>::value, "unsupported type");
static_assert(supported_integral<R>::value, "unsupported type");
_CCCL_DIAG_PUSH
_CCCL_DIAG_SUPPRESS_ICC(186) // pointless comparison of unsigned integer with zero
_CCCL_ASSERT(value >= 0, "value must be non-negative");
_CCCL_ASSERT(multiplier >= 0, "multiplier must be non-negative");
_CCCL_DIAG_POP
_CCCL_IF_CONSTEXPR (_CCCL_TRAIT(is_signed, T))
{
_CCCL_DIAG_PUSH
_CCCL_DIAG_SUPPRESS_ICC(186) // pointless comparison of unsigned integer with zero
_CCCL_ASSERT(value >= 0, "value must be non-negative");
_CCCL_ASSERT(multiplier >= 0, "multiplier must be non-negative");
_CCCL_DIAG_POP
}
bernhardmgruber marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

@davebayer davebayer Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_CCCL_IF_CONSTEXPR (_CCCL_TRAIT(is_signed, T))
{
_CCCL_DIAG_PUSH
_CCCL_DIAG_SUPPRESS_ICC(186) // pointless comparison of unsigned integer with zero
_CCCL_ASSERT(value >= 0, "value must be non-negative");
_CCCL_ASSERT(multiplier >= 0, "multiplier must be non-negative");
_CCCL_DIAG_POP
}
_CCCL_ASSERT(_CUDA_VSTD::cmp_greater_equal(value, 0), "value must be non-negative");
_CCCL_ASSERT(_CUDA_VSTD::cmp_greater_equal(multiplier, 0), "multiplier must be non-negative");

When #2805 is merged, I think applying integer comparison functions should fix the warning.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would fix the warning but it would come at a cost.

We do not want a function call if we already know that the condition is statically satisfied

static constexpr int NumBits = sizeof(DivisorType) * CHAR_BIT;
using unsigned_t = unsigned_implicit_prom_t<DivisorType>;
using larger_t = larger_unsigned_type_t<DivisorType>;
Expand Down
Loading