-
Notifications
You must be signed in to change notification settings - Fork 168
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
Conversation
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
b109a00
to
d74285c
Compare
_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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_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.
There was a problem hiding this comment.
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
_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 | ||
} |
There was a problem hiding this comment.
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
Co-authored-by: Michael Schellenberger Costa <[email protected]>
🟨 CI finished in 1h 35m: Pass: 99%/224 | Total: 4d 18h | Avg: 30m 41s | Max: 1h 15m | Hits: 91%/12288
|
Project | |
---|---|
CCCL Infrastructure | |
libcu++ | |
+/- | CUB |
Thrust | |
CUDA Experimental | |
python | |
CCCL C Parallel Library | |
Catch2Helper |
Modifications in project or dependencies?
Project | |
---|---|
CCCL Infrastructure | |
libcu++ | |
+/- | CUB |
+/- | Thrust |
CUDA Experimental | |
+/- | python |
+/- | CCCL C Parallel Library |
+/- | Catch2Helper |
🏃 Runner counts (total jobs: 224)
# | Runner |
---|---|
185 | linux-amd64-cpu16 |
16 | linux-arm64-cpu16 |
14 | linux-amd64-gpu-v100-latest-1 |
9 | windows-amd64-cpu16 |
🟩 CI finished in 2h 12m: Pass: 100%/224 | Total: 4d 18h | Avg: 30m 46s | Max: 1h 15m | Hits: 91%/12288
|
Project | |
---|---|
CCCL Infrastructure | |
libcu++ | |
+/- | CUB |
Thrust | |
CUDA Experimental | |
python | |
CCCL C Parallel Library | |
Catch2Helper |
Modifications in project or dependencies?
Project | |
---|---|
CCCL Infrastructure | |
libcu++ | |
+/- | CUB |
+/- | Thrust |
CUDA Experimental | |
+/- | python |
+/- | CCCL C Parallel Library |
+/- | Catch2Helper |
🏃 Runner counts (total jobs: 224)
# | Runner |
---|---|
185 | linux-amd64-cpu16 |
16 | linux-arm64-cpu16 |
14 | linux-amd64-gpu-v100-latest-1 |
9 | windows-amd64-cpu16 |
@bernhardmgruber @miscco what about if we introduce a function for that purpose? Instead of repeat the verbose pattern is_non_negative(value); // or
is_zero_or_positive(value); |
I was however considering a macro because those signed unsigned checks come up a ton |
Good suggestion! Feel free to go ahead and add one! |
Addresses post-merge review comment: #2987 (comment)