-
Notifications
You must be signed in to change notification settings - Fork 425
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
Comparison and Logical Operators or IEEE 754 Predicates #18629
Comments
Hi Damian —
I would say that it's because in cases where the naive assignment from x to y is expensive / O(n), I don't like requiring the user to hope that the compiler interprets the more complex tuple-based swap pattern as a swap rather than simply expressing the swap directly and knowing something reasonable will/can be done. Where a key case that we want to enable is the use of pointer swaps rather than O(n) deep copies to implement such expensive swaps when legal. You're right, though, that this could be expressed as However, note that even if we retired All that said, I don't find
I'd say that with the language being locked down, it's actually less likely that any of these will be gobbled up soon (and we can always add them later, as the goal is not to make breaking changes, not to stop making changes that improve things). The question as to whether adopting these would make
In asking this, I'm not doubting your veracity, but can you refer us to a recommendation like this that we could use to bolster the proposal? Thanks! |
See attached background document. It answers some of your questions. I will address the others later. |
My customized version of the compiler allows me to use the assignment operation |
In terms of the IEEE 754 comparison predicates
That said, I did need to change the I was not suggesting the work needs to be done now. But the symbols do need to be reserved. And I am not suggesting anything that is not already covered by the IEEE 754 standard although Kahan's document does fix any ambiguity issues in the symbols that occur current standard. So I am not proposing new symbols or a new meaning to a symbol. That said, a slight elaboration on my document would define the task and it could be offloaded to a student next year. |
The latest iteration of those first 6 new predicates (or boolean operators) has a minor change to the second thereof: ?? or unordered
!? or not unordered
!> or not greater than
!>= or not greater than or equal to
!< or not less than
!<= or not less than or equal to Having these would make the implementation of the maxima and minima operations of #20390 simpler? That said, this issue is not urgent, but is ultimately needed. Just thought I would mention it. |
The unordered and ordered predicates within the 2019 IEEE 754 standard (and the earlier 2008) are written in its Table 5.3 as ? unordered
<=> ordered Chapel already uses both of these so they are out of the question. At best, the closest approximation to the unordered concept, i.e. neither greater than, equal to, or less than, would be !>=< This notation is what Kahan used to use is some of his 1990s class notes, although by the millenium he had dropped this type of notation. And for me, not only it that too close to Chapel's swap operator for me but it is also too verbose at 4 characters long. And it already uses an exclamation mark so its negation is >=< which again is far too close to the swap operator (and is back to front anyway). I would like to keep ?? unordered
!? ordered because that pair of quiet predicates is symmetric with the other quiet predicates Also, there is the concept of a signalling equality predicate and its negation. That is a bit more challenging, so much so that the IEEE 754 standard has neither a symbolic or mneumonic form. We might discuss it further once we get the unordered/ordered quiet symbols bedded down. |
The concept of the unordered/ordered quiet predicates in the 2019 (and 2008) IEEE 754 standard are ? unordered
<=> ordered As Chapel uses both those already, that is never going to fly. Note that a quiet predicate (or comparison) is one which does not raise an INVALID exception in the presence of a quiet NaN. The concept of the unordered predicate is that of the negation of any of greater than, equal to, or less than, or what could be written as !>=< This is exactly what Kahan had preferred in 1997 although by 2002 he had gone back to a single question mark for unordered, and a negated question mark for ordered. I do not like that 4 character symbol because it too verbose and too close to the Chapel swap operator. Also, its negation is then Hence my preference for ?? unordered
!? ordered This choice means that I agree with Kahan on the second and I have achieved symmetry with the other quiet predicate, equal/unequal, i.e. We still have to worry about the signalling equals predicate. But let's leave than for now. |
Due to copyright, I cannot attach the IEEE 754 standards with the symbols. All of the symbols that I have proposed have at least 2 (or 3) decades of provenance. There is nothing new except for my use of the double question mark `??' which is necessary because Chapel is already using a single question mark. The attached Kahan papers from 1997 (IEEE754.PDF) and 2002 (Fclass.pdf) are more than adequate to explain the details of the predicates. The 2002 paper also details the mathematical heritage of most of those symbols including the single question mark. If you think it necessary, I will ask Kahan (through channels) if he has an earlier reference to these symbols. In working on #20390, I found myself needing the unordered predicates. It was interesting is how precisely (or imprecisely) CLANG and GCC optimize (or not) the use of |
Sorry @bradcray. I realized that I never replied succinctly to specific questions, despite my promises to do so. Quoting Kahan but with my use of a double question mark Note that silent (or quiet) The first question from @bradcray asked the difference between:
Extrapolating from Kahan, while The second (again altered) question from @bradcray asked the difference between:
While One of my tasks for the year is to make the Chapel compiler understand both
Can somebody point me at where I need to change the compiler please? No rush. Probably a job for April-June 2024. No rush. |
The "easy" part would be to add these new operators to the lexer and parser in And then the most challenging part would be to get consensus on introducing these new operators in order to merge the change to |
I looked at the "easy" part wnd was filled with dread. ...F......ar out!! The last time I messed with the compiler was nearly 10 years ago. It shows. Heaven help me with the "hard" part. As for the challenging part, What I am suggesting is not new. The operation has been part of the IEEE 754 standard since its early days and has been part of the C library's implementation of that standard for decades, albeit via the far less concise mechanism of a routine called isunordered instead of the mathematical symbol. Syntactically it is not new either, using the symbol pair ??/!? instead of the ?/!? original proposal due to a clash with Chapel's use of a ?. They predate IEEE 754, well the single question mark and its negation do. It makes writing a standards compliant routine line max or min simpler and faster, and should do similar things for the performance of a reduction using those operators. proc max(x : real(?w), y : real(w)) do return if x !? y then (if x > y then x else y) else x + y; The predicate pair Whether users or implementers actually care enough about IEEE 754 issues to result in its inclusion in main is another question. I am amazed at how many don't know much about it which is quite scary. But that is another problem. |
Currently, like most languages, Chapel implements the common predicates:
The first two never raise an exception if given an NaN.
The rest are implemented as calls to a routine or macro. This makes them hard to read.
We really need at least the following (none of which raise an IEEE exception). They have been recommended for the last 36 years but I have not seen them in any common language. It is about time that was rectified and Chapel can lead the way.
I took the liberty of changing the conventional ? for unordered because Chapel already uses a question mark as an operator.
There is also
although I am being a bit liberal in my symbol for this last one as some people use that as an alternative to
!=
ornot equal to
.Also the first is too close to the swap operator for my liking. In this era of optimizing compilers, I fail to see why swapping needs its own operator and cannot be done as the 58 year old concept of using a tuple for the task
(x, y) = (y, x)
I agree that
<=>
is extremely concise and makes optimization easier to implement. That said, for a generic language:is pretty tight and very clear and should work for objects of any type.
The reservation of the symbols is urgent before somebody else claims/hijacks them. Especially in this era of lock down the language. So the discussion needs to be had.
On the other hand, their implementation is not urgent. Note than many of those predicates in the second bunch are just a variant of one of the predicates in the first bunch, the difference being that they do not raise an IEEE 754 exception if given an NaN. I think that LLVM handles them several of them already. GCC also did, but that was caused by a bug which did not raise an exception when it was supposed to!
Comments please?
The text was updated successfully, but these errors were encountered: