Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: OK, now I see Re: Motion P1788/M0013.04 - Comparisons - Overflow / Infinity



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


Inactive hide details for Ralph Baker Kearfott ---09/21/2010 10:12:16 PM---Ian, Nate (and P-1788), Thank you for your perspectiRalph 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





Ian, Nate (and P-1788),

Thank you for your perspective.  That clarifies things indeed.

Of course, one possibility is to rescind motion 3, and define the arithmetic
over the extended reals, but we had already discussed the issue, including disadvantages
(e.g. serious overestimation in some cases) of using a model based on extended reals.
In any case, I'm hoping we can come to equitable solutions without adding too
much complexity.

Best regards,

Baker

On 9/21/2010 19:27, Nate Hayes wrote:
> Baker Kearfott wrote:
>
>> Ah, yes, now I remember. Even though we are working only
>> with real numbers, an interval can be bounded or not,
>> and we can distinguish that with a decoration. However,
>> a consequence of the fact we interpret [a,Infinity) to
>> be a set of real numbers is [a,Infinity)*0 = 0. Thus,
>> the question of the point product Infinity*0 does not
>> even arise.
>
> Right.
>
> ...although it _does_ arise when computing the endpoints of an interval. So it is relevant to the _implementation_ of interval arithmetic operations. I think this was Ian's main point (no pun intended).
>
> For example, _if_ IEEE 754 had made a distinction between Infinity and Overflow, then our interval arithmetic implementations would already have a fast floating-point operation Overflow*0=0 in hardware, which means computing the appropriate
> interval endpoint of the product:
> [1,Overflow]*[0,0]=[1*0,Overflow*0]=[0,0]
> would already be performed fast and cheaply in hardware.
>
> This would be good for all of our (currently slow) software implementations of interval arithmetic.
>
> This is in contrast to how IEEE 754 arithmetic hardware as it _actually_ exists today yields:
> [1,Infinity]*[0,0]=[1*0,Infinity*0]=[0,NaN]
> which according to Motion 5 is not the correct interval result. So it requires an expensive software routine to "fix" the [0,NaN] result and turn it into the correct [0,0] interval arithmetic result.
>
> Too bad for us interval practitioners.
>
> So it is a kind of wishful thinking about what "could have been" if IEEE 754 had done things differently. Perhaps it is then also natural to ask the question: is this a problem IEEE 1788 wants to fix?
>
> I don't know the answer to that question.
>
> Note that Ian's Overflow can simply be viewed as a decorated Infinity. Only in this case the "decoration" is for a floating-point value (Infinity) as opposed to an interval value, which is what we're normally used to thinking about since
> Motion 8.
>
> Nate
>
> P.S. Ian, feel free to jump in if I do not do justice to represent your point.
>
>
>
>>
>> Baker
>>
>> On 9/21/2010 04:25, Arnold Neumaier wrote:
>>> Ian McIntosh wrote:
>> .
>> .
>> .
>>> AN> We introduced in Motion 8 decorations to be able to distinguish the two
>>>> where necessary inninterval bounds by having the decoration IsBounded.
>> .
>> .
>> .
>>>> My only claims are that by distinguishing Overflow from Infinity you can
>>>> know whether multiplying whichever by zero gives zero or NaNQ in floating
>>>> point, and that if 754 already had that it would be helpful for interval
>>>> arithmetic.
>>>
>>
>> See my comment above.
>>
>>> The distiction can already be made with decorations.
>>> We do not need dubious mathematically indeterminate nunbers.
>>>
>>
>>
>> --
>>
>> ---------------------------------------------------------------
>> R. Baker Kearfott, rbk@xxxxxxxxxxxxx (337) 482-5346 (fax)
>> (337) 482-5270 (work) (337) 993-1827 (home)
>> URL:
http://interval.louisiana.edu/kearfott.html
>> Department of Mathematics, University of Louisiana at Lafayette
>> (Room 217 Maxim D. Doucet Hall, 1403 Johnston Street)
>> Box 4-1010, Lafayette, LA 70504-1010, USA
>> ---------------------------------------------------------------
>>
>
>


--

---------------------------------------------------------------
R. Baker Kearfott,    rbk@xxxxxxxxxxxxx   (337) 482-5346 (fax)
(337) 482-5270 (work)                     (337) 993-1827 (home)
URL:
http://interval.louisiana.edu/kearfott.html
Department of Mathematics, University of Louisiana at Lafayette
(Room 217 Maxim D. Doucet Hall, 1403 Johnston Street)
Box 4-1010, Lafayette, LA 70504-1010, USA
---------------------------------------------------------------