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

Atomic cmpxchg note clarification #1909

Merged
merged 4 commits into from Feb 12, 2018
Merged

Conversation

jfbastien
Copy link
Contributor

We now have explicit floating-point specializations for atomic. We had cmpxchg for them before, but people are now looking at increased usage and are confused about what the behavior is for -0. with 0., as well as NaNs. I propose clarifying the note to make this extra clear. This is a note and is therefore purely editorial, and would be a waste of SG1's time.

We now have explicit floating-point specializations for atomic. We had cmpxchg for them before, but people are now looking at increased usage and are confused about what the behavior is for `-0.` with `0.`, as well as NaNs. I propose clarifying the note to make this extra clear. This is a note and is therefore purely editorial, and would be a waste of SG1's time.
@@ -931,7 +931,8 @@
\begin{note} The \tcode{memcpy} and \tcode{memcmp} semantics of the compare-and-exchange
operations may result in failed comparisons for values that compare equal with
\tcode{operator==} if the underlying type has padding bits, trap bits, or alternate
representations of the same value.\end{note}
representations of the same value. Notably, floating-point \tcode{-0.} and \tcode{0.}
Copy link
Member

Choose a reason for hiding this comment

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

Please use "-0.0" and "+0.0" for extra clarity.

@@ -931,7 +931,8 @@
\begin{note} The \tcode{memcpy} and \tcode{memcmp} semantics of the compare-and-exchange
operations may result in failed comparisons for values that compare equal with
\tcode{operator==} if the underlying type has padding bits, trap bits, or alternate
representations of the same value.\end{note}
representations of the same value. Notably, floating-point \tcode{-0.0} and \tcode{+0.0}
Copy link
Member

Choose a reason for hiding this comment

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

I think "will" is too strong here, given that the core language rules do not require 0.0 and -0.0 to be distinct values, and nor do they require NaNs to exist. Can you weaken this by using "may" or "will typically" or "on implementations conforming to ISO/IEC/IEEE 60559" or similar?

representations of the same value.\end{note}
representations of the same value. Notably, on implementations conforming to
ISO/IEC/IEEE 60559, floating-point \tcode{-0.0} and \tcode{+0.0}
will compare not-equal and NaNs with the same payload will compare equal.\end{note}
Copy link
Member

Choose a reason for hiding this comment

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

Reading through this again, there seems to be a mismatch in how "compare equal" is used in the first and second half of the note. In the first half, we talk about "compare equal with operator==", but when we say "compare not-equal" and "compare equal" in the second half, we're talking about the memcmp semantics.

At the risk of verbosity, how about:

\tcode{-0.0} and \tcode{+0.0} will not compare equal with \tcode{memcmp} but will compare equal with \tcode{operator==}, and NaNs with the same payload will compare equal with \tcode{memcmp} but will not compare equal with \tcode{operator==}.

SG1 loves notes.
@zygoloid zygoloid merged commit 2ee60f5 into cplusplus:master Feb 12, 2018
@jfbastien jfbastien deleted the patch-3 branch February 12, 2018 19:58
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

3 participants