Thread Links | Date Links | ||||
---|---|---|---|---|---|
Thread Prev | Thread Next | Thread Index | Date Prev | Date Next | Date Index |
While we're on the topic of infinities, one other 754 implementation detail may cause us some annoyance.
I don't think we made a firm decision on how and where decorations are stored, but the general assumption seems to be that in 1788 implementations based on 754, they'd be stored in the payload of a 754 NaN. I like that idea a lot better than having a separate word, but it has consequences:
1. One we've discussed a little is that no existing hardware follows our decoration rules.
2. Unless we're careful, our rules will be awkward to implement with bitwise operations; for example, it's more efficient to just AND or OR two decoration words together than it is to have to extract the various parts so some can be ANDed, some can be ORed, and others manipulated with more complicated sequences.
3. Some architectures allow bitwise operations on floating point registers. Some do not. Some would require dozens of cycles to move the values through memory to general purpose registers, do the manipulation, and move them back (of course sometimes that can be optimized, and on some systems it's cheap or free). So two 754-based implementations may run at very different speeds.
4. Does anybody expect Infinities to be decorated? For example, the recent correct statement about Overflow versus Infinity that "We introduced in Motion 8 decorations to be able to distinguish the two where necessary in interval bounds by having the decoration IsBounded." indicates yes, but one aspect of 754 complicates that.
The number of bits in a value is small while the desired precision and exponent range is large, so bits are scarce. The 754 designers used three clever ideas:
a. The "hidden" bit gives normal values one extra bit of precision.
b. Zero and the subnormals share the same exponent. A value with the minimum exponent is either zero or a subnormal. If all the fraction bits are zero then it is zero. If any are non-zero then it is a subnormal.
c. Infinity, Quiet NaN and Signaling NaN share the same exponent. A value with the maximum exponent is either Infinity or a NaN. If all the fraction bits are zero then it is Infinity. If any are non-zero then it is a NaN. It is implementation defined how to tell a Quiet from a Signaling NaN, but the implementations I know use the upper fraction bit. They just don't agree on whether 0 means Quiet or 1 means Quiet.
Is the Overflow / Infinity decoration problem clear? You cannot have a decorated Infinity, because the moment you decorate an Infinity with non-zero decorations it becomes a NaN (you can have any colour Infinity you want, as long as it's black). So the IsBounded aspect of motion 8 is interesting to implement with 754. A finite value is obviously bounded so the decoration is redundant. Infinity cannot be decorated so the decoration can't be implemented in an obvious way.
And as soon as an endpoint is a NaN, it's an awkward end point. You might want to avoid Signaling ones because all operations on them raise exceptions (or you might need to count on that - see below). Arithmetic with Quiet NaNs will produce NaNs (0 * NaN = NaN when 1788 wants 0). Comparisons will not work as expected - a NaN is not greater than values within the interval. All comparisons to a Quiet NaN will give "unordered", not < or = or >. So trying to treat a Quiet NaN as an Infinity is at best challenging, and using a Signalling NaN can be expensive.
One possibility is to decorate the other endpoint of the interval. That restricts the values (eg, no [+oo, -oo]) and adds complexity and slowness so is not ideal.
In my hypothetical ideal dream world, a couple of bits beside the exponent would distinguish the values. The following values aren't my preference, but o keep it somewhat close to the real 754 bit meanings, it could be something like
0 x = Really Big
0 0 = Infinity
0 1 = Overflow
1 x = NaN
1 0 = Quiet NaN
1 1 = Signaling NaN
Then you could have a payload in any of them, you could distinguish Overflow from Infinity, and which NaN is which could be portable. A bonus is that the check that hardware must make to distinguish Infinity from NaN would only have to check 2 bits, not 52. 1788 could use the NaNs any way it wanted.
While we're being hypothetical, it would not be a drastic change to have a "754++ mode" providing this, solving both the decorated Infinity problem and the 0 * Overflow and related problems. (Yes, along with being hypothetical I'm being hypocritical because I said earlier I didn't expect new modes and they had costs. This is a "What if ?", not an "I expect !".)
What if you wanted to implement something like this in software running on stock 754 hardware? If you believe that operations involving Overflow or Infinity are uncommon, so that you can afford poor performance on them, then change the representation, for example:
fraction all zeros = 754 Infinity = 1788 Infinity.
fraction non-zero = 754 NaN = 1788 Overflow or NaN, depending on the bits
A Signaling NaN with some designated pattern would indicate Overflow, and it could have decoration bits. It should be Signaling not Quiet to cause an exception and software emulation of Overflow.
I know some will feel it's too early to be discussing implementation details, but decisions are being made and have already been made that affect it. Of course we have after discussion rejected having 754 as the underlying hardware being a requirement, but we should consider "What if it is ?" because at least initially it usually will be.
- Ian McIntosh IBM Canada Lab Compiler Back End Support and Development
Ralph Baker Kearfott ---09/21/2010 10:12:16 PM---Ian, Nate (and P-1788), Thank you for your perspective. That clarifies things indeed.
![]() From: | ![]() Ralph Baker Kearfott <rbk@xxxxxxxxxxxx> |
![]() To: | ![]() Ian McIntosh/Toronto/IBM@IBMCA |
![]() Date: | ![]() 09/21/2010 10:12 PM |
![]() Subject: | ![]() Re: OK, now I see Re: Motion P1788/M0013.04 - Comparisons - Overflow / Infinity |