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

Add a few missing operators to id class #1018

Merged
merged 1 commit into from
Apr 25, 2023

Conversation

nilsfriess
Copy link
Collaborator

No description provided.

}

friend id operator-(const id& rhs) {
return -1*rhs;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does that make sense? id stores size_t, so an unsigned type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just added what's in the spec, but you're totally right, this makes no sense...
I will open an issue in the SYCL-Docs repo and ask about this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, reading up on this a bit, I think this might make sense or is at least well-defined. The C++ standard says

The negative of an unsigned quantity is computed by subtracting its value from $2^n$, where n is the number of bits in the promoted operand.

So I guess we can just keep it to be conformant

HIPSYCL_ID_BINARY_OP_SIZE_T(<)
HIPSYCL_ID_BINARY_OP_SIZE_T(>)
HIPSYCL_ID_BINARY_OP_SIZE_T(<=)
HIPSYCL_ID_BINARY_OP_SIZE_T(>=)
Copy link
Collaborator

Choose a reason for hiding this comment

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

These operators return bool. Do we need a static_cast to get it to return a size_t without warnings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The C++ standard defines what should happen when converting a bool to an integer type (false -> 0, true -> 1), so I think there will be no warnings here. And at least clang was happy

@illuhad illuhad merged commit 94b2bcd into AdaptiveCpp:develop Apr 25, 2023
14 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants