FloatMathPlugin in Squeak for Croquet compatability?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

FloatMathPlugin in Squeak for Croquet compatability?

Tapple Gao
Croquet (and thus Open Cobalt) requires that squeak images
perform floating point operations bit-identically across
machines, and the FloatMathPlugin was added to the VM to ensure
this is the case.

Now that OpenCobalt is nearly ready for debut onto the Squeak
trunk, I'm wondering if this should be enabled by default in
squeak images. FloatMathPlugin is included in standard VMs, but
is not used by non-Croquet images. I'm wondering if we should
change that.

I uploaded the code and test case for this feature at:

http://bugs.squeak.org/view.php?id=7583

--
Matthew Fulmer (a.k.a. Tapple)

Reply | Threaded
Open this post in threaded view
|

Re: FloatMathPlugin in Squeak for Croquet compatability?

Levente Uzonyi-2
On Mon, 13 Dec 2010, Matthew Fulmer wrote:

> Croquet (and thus Open Cobalt) requires that squeak images
> perform floating point operations bit-identically across
> machines, and the FloatMathPlugin was added to the VM to ensure
> this is the case.
>
> Now that OpenCobalt is nearly ready for debut onto the Squeak
> trunk, I'm wondering if this should be enabled by default in
> squeak images. FloatMathPlugin is included in standard VMs, but
> is not used by non-Croquet images. I'm wondering if we should
> change that.
>
> I uploaded the code and test case for this feature at:
>
> http://bugs.squeak.org/view.php?id=7583

There were plans about using the primitives during the developement of
Squeak 4.1. They also give a nice speed up if you're using SqueakVM, but
some of them (#sin, #cos, etc.) are slower with CogVM.
In Kernel-mtf.527 the behavior of the methods is different if the receiver
is NaN.


Levente

>
> --
> Matthew Fulmer (a.k.a. Tapple)
>
>

Reply | Threaded
Open this post in threaded view
|

Re: FloatMathPlugin in Squeak for Croquet compatability?

Andreas.Raab
On 12/13/2010 5:35 PM, Levente Uzonyi wrote:
> There were plans about using the primitives during the developement of
> Squeak 4.1. They also give a nice speed up if you're using SqueakVM, but
> some of them (#sin, #cos, etc.) are slower with CogVM.
> In Kernel-mtf.527 the behavior of the methods is different if the
> receiver is NaN.

Yes. NaNs are -as the name says- not numbers and these operations are
defined for numbers only, so all the float math plugin primitives fail
for NaN. If you want to introduce NaNs silently you could do that in the
primitive fallback code, but from my point of view, I found that raising
an exception causes potential problems to show at a much earlier stage
and not when you're trying to do an operation like truncate, round or
whatnot (which sooner or later you will do).

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: FloatMathPlugin in Squeak for Croquet compatability?

Nicolas Cellier
In reply to this post by Levente Uzonyi-2
The squeak implementation is awfully inexact, even worse than Intel !
With this respect, I prefer the FloatMathPlugin.

For example:
(Float pi / 2) cos
  -> 1.224606353822377e-16
((Float pi / 2) asArbitraryPrecisionFloatNumBits: 53) cos
  -> (ArbitraryPrecisionFloat readFrom: '6.123233995736766e-17'
readStream numBits: 53)

A factor 2... That's many ULP !

Nicolas

2010/12/14 Levente Uzonyi <[hidden email]>:

> On Mon, 13 Dec 2010, Matthew Fulmer wrote:
>
>> Croquet (and thus Open Cobalt) requires that squeak images
>> perform floating point operations bit-identically across
>> machines, and the FloatMathPlugin was added to the VM to ensure
>> this is the case.
>>
>> Now that OpenCobalt is nearly ready for debut onto the Squeak
>> trunk, I'm wondering if this should be enabled by default in
>> squeak images. FloatMathPlugin is included in standard VMs, but
>> is not used by non-Croquet images. I'm wondering if we should
>> change that.
>>
>> I uploaded the code and test case for this feature at:
>>
>> http://bugs.squeak.org/view.php?id=7583
>
> There were plans about using the primitives during the developement of
> Squeak 4.1. They also give a nice speed up if you're using SqueakVM, but
> some of them (#sin, #cos, etc.) are slower with CogVM.
> In Kernel-mtf.527 the behavior of the methods is different if the receiver
> is NaN.
>
>
> Levente
>
>>
>> --
>> Matthew Fulmer (a.k.a. Tapple)
>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: FloatMathPlugin in Squeak for Croquet compatability?

Levente Uzonyi-2
In reply to this post by Andreas.Raab
On Mon, 13 Dec 2010, Andreas Raab wrote:

> On 12/13/2010 5:35 PM, Levente Uzonyi wrote:
>> There were plans about using the primitives during the developement of
>> Squeak 4.1. They also give a nice speed up if you're using SqueakVM, but
>> some of them (#sin, #cos, etc.) are slower with CogVM.
>> In Kernel-mtf.527 the behavior of the methods is different if the
>> receiver is NaN.
>
> Yes. NaNs are -as the name says- not numbers and these operations are defined
> for numbers only, so all the float math plugin primitives fail for NaN. If
> you want to introduce NaNs silently you could do that in the primitive
> fallback code, but from my point of view, I found that raising an exception
> causes potential problems to show at a much earlier stage and not when you're
> trying to do an operation like truncate, round or whatnot (which sooner or
> later you will do).

The current implementation defines them as: return NaN if the operand is
NaN, while the new implementation raises an error. This may break existing
code, so it should be mentioned in the release notes.


Levente

>
> Cheers,
>  - Andreas
>
>

Reply | Threaded
Open this post in threaded view
|

Re: FloatMathPlugin in Squeak for Croquet compatability?

Andreas.Raab
On 12/13/2010 7:42 PM, Levente Uzonyi wrote:

> On Mon, 13 Dec 2010, Andreas Raab wrote:
>
>> On 12/13/2010 5:35 PM, Levente Uzonyi wrote:
>>> There were plans about using the primitives during the developement of
>>> Squeak 4.1. They also give a nice speed up if you're using SqueakVM, but
>>> some of them (#sin, #cos, etc.) are slower with CogVM.
>>> In Kernel-mtf.527 the behavior of the methods is different if the
>>> receiver is NaN.
>>
>> Yes. NaNs are -as the name says- not numbers and these operations are
>> defined for numbers only, so all the float math plugin primitives fail
>> for NaN. If you want to introduce NaNs silently you could do that in
>> the primitive fallback code, but from my point of view, I found that
>> raising an exception causes potential problems to show at a much
>> earlier stage and not when you're trying to do an operation like
>> truncate, round or whatnot (which sooner or later you will do).
>
> The current implementation defines them as: return NaN if the operand is
> NaN, while the new implementation raises an error. This may break
> existing code, so it should be mentioned in the release notes.

True. We could also have a class var indicating whether to use signaling
vs. non-signaling NaNs. Virtually no code will care and but if it does
you can flip the switch for compatibility.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: FloatMathPlugin in Squeak for Croquet compatability?

Andreas.Raab
On 12/13/2010 9:07 PM, Andreas Raab wrote:
> True. We could also have a class var indicating whether to use signaling
> vs. non-signaling NaNs. Virtually no code will care and but if it does
> you can flip the switch for compatibility.

I've posted a version of this into the inbox for people to look at. I
think it's actually a quite reasonable tradeoff; let me know what you think.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: FloatMathPlugin in Squeak for Croquet compatability?

Tapple Gao
On Tue, Dec 14, 2010 at 12:17:14AM -0800, Andreas Raab wrote:
> On 12/13/2010 9:07 PM, Andreas Raab wrote:
> > True. We could also have a class var indicating whether to use signaling
> > vs. non-signaling NaNs. Virtually no code will care and but if it does
> > you can flip the switch for compatibility.
>
> I've posted a version of this into the inbox for people to look at. I
> think it's actually a quite reasonable tradeoff; let me know what you think.

I noticed you deleted the infinity check for cos but not for
sin.

--
Matthew Fulmer (a.k.a. Tapple)

Reply | Threaded
Open this post in threaded view
|

Re: FloatMathPlugin in Squeak for Croquet compatability?

Aleksej Saushev-2
In reply to this post by Tapple Gao
Matthew Fulmer <[hidden email]> writes:

> Croquet (and thus Open Cobalt) requires that squeak images
> perform floating point operations bit-identically across
> machines

This paper is must read:

http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf


--
HE CE3OH...


Reply | Threaded
Open this post in threaded view
|

Re: FloatMathPlugin in Squeak for Croquet compatability?

Andreas.Raab
In reply to this post by Tapple Gao
On 12/14/2010 6:06 AM, Matthew Fulmer wrote:

> On Tue, Dec 14, 2010 at 12:17:14AM -0800, Andreas Raab wrote:
>> On 12/13/2010 9:07 PM, Andreas Raab wrote:
>>> True. We could also have a class var indicating whether to use signaling
>>> vs. non-signaling NaNs. Virtually no code will care and but if it does
>>> you can flip the switch for compatibility.
>>
>> I've posted a version of this into the inbox for people to look at. I
>> think it's actually a quite reasonable tradeoff; let me know what you think.
>
> I noticed you deleted the infinity check for cos but not for
> sin.

Copy&Paste error (too much code selected :-)

Cheers,
   - Andreas


Reply | Threaded
Open this post in threaded view
|

Re: FloatMathPlugin in Squeak for Croquet compatability?

Andreas.Raab
In reply to this post by Aleksej Saushev-2
On 12/14/2010 6:48 AM, Aleksej Saushev wrote:
> Matthew Fulmer<[hidden email]>  writes:
>
>> Croquet (and thus Open Cobalt) requires that squeak images
>> perform floating point operations bit-identically across
>> machines
>
> This paper is must read:
>
> http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf

Not for Croquet. This paper is just one of the longest rants in a long
series complaining about "ZOMG, Java doesn't expose all the control
required in IEEE 754, how *dare* they claim to be IEEE compliant???".
Croquet's requirements are much simpler - Croquet doesn't require IEEE
754 compliance, it merely requires the same results across all platforms
(whether IEEE 754 or not).

The paper does contain some valuable information for a language
designer. But unfortunately the good bits are buried in about a hundred
pages of ranting making it hard to actually find the essence of what
they say should be done.

Cheers,
   - Andreas