-
Notifications
You must be signed in to change notification settings - Fork 82
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
Do not check for undefined behavior in abs_diff #842
Do not check for undefined behavior in abs_diff #842
Conversation
Similar to sycl::abs, sycl::abs_diff now has undefined behavior for unrepresentable results. This patch changes the generated tests for abs_diff to avoid UB, similar to how it was done for abs in KhronosGroup#831. Signed-off-by: Larsen, Steffen <[email protected]>
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.
This sounds complicated. Would it not possible to do like the unsigned case but casting first to unsigned and adding a bias of - [ ] -min() on each element first?
I worry we would run into the same problem causing this problem when computing |
I mean for auto au = static_cast<U>(a) + 0x80;
auto bu = static_cast<U>(b) + 0x80;
auto h = (au > bu) ? au : bu;
auto l = (au <= bu) ? au : bu;
return h - l; So technically |
Is something like https://godbolt.org/z/ejbK9qPdj what you are thinking? |
T h = (a > b) ? a : b; | ||
T l = (a <= b) ? a : b; | ||
return h - l; | ||
// Using two's-complement and that unsigned integer underflow is defined as | ||
// modulo 2^n we get the result by computing the distance based on signed |
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.
Thanks, now I understand the code. :-)
But is it signed? It looks like it uses unsigned comparison.
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.
I'm not sure why Steffen says "signed", but would it be enough to just drop this word from the comment to merge it?
P.S. Steffen is on vacation, but we need this PR.
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.
Great!
We can always bike-shed the comment later. ;-)
Similar to sycl::abs, sycl::abs_diff now has undefined behavior for unrepresentable results. This patch changes the generated tests for abs_diff to avoid UB, similar to how it was done for abs in #831.