Quantcast

FloatMathPlugin for Croquet

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

FloatMathPlugin for Croquet

Andreas.Raab
Hi Guys -

I've just committed the changes for the FloatMathPlugin which Croquet
uses to get bit-identical cross-platform floating point behavior (with a
big thanks to Sun for developing fdlibm ;-)

Getting FloatMathPlugin to compile should be simple; getting it to work
might be tricky. Because of this there are a bunch of tests with
extensive test data to ensure we truly have cross-platform behavior. For
efficiency, it's important to note that the "common" floating point
operations are not handled by fdlibm (it expects IEEE 754 conforming
behavior for the basic operations like add, subtract, multiply, divide)
but covers pretty much everything else.

What I have found playing with both PPC and Intel FPUs is the following:
Even if your FPU is IEEE754 compliant this means very little, as IEEE754
leaves lots of room for interpretation. Most importantly, make sure you
check the following two issues:

* Internal accuracy. Some FPUs (x87) have an internal accuracy that is
larger than 64bits (80bits on Intel). For compliance the FPU *MUST* be
set to treat all operations as 64bit (on x87 this means setting the
precision to 53 bits, e.g., _PC_53 in the control word).

* Fused multiply-add. Some FPUs (PPC) allow for so-called "fused"
multiply-add operations which compute the result of "a*b+c" with higher
internal accuracy. You must disable fused multiply-add *AT ALL COSTS*
(e.g., by using a global compiler switch if available) as the use of
fused multiply-add is both, subject to choice by the compiler (meaning
that even two different compilers might decide differently where to use
it) and is not generally supported on all FPUs.

The tests that I've provided come in two flavours: One flavour is just a
general compliance test which computes a bunch of numbers hashes them
(using MD5) and compares it with a precomputed value. This test is a
good quick way to check for compliance.

The second flavour uses pre-computed test data so you can actually look
at what is computed differently and where. The test data also comes in
two flavours, a small data set (10k entries) and a large data set (1000k
entries). The small one is a good one early on to find the problematic
cases quickly, the large one is good to check that with 1:1000000 chance
the code actually does compute the correct values. You need to drop the
data sets into the image directory for those tests to be run.

Since (so far) I have only tested this on x87 and PPC, I don't know if
other FPUs have other issues. If you encounter "wrong" results despite
checking for the above two issues you might want to read the manual for
your FPU to find out if there are any settings that may affect IEE754
compliance (like fused-madd, or internal accuracy).

Cheers,
   - Andreas

PS. And apologies for the temporary SVN mess - I wasn't aware that my
SVN client wouldn't interpret the directory I had clicked on as being
relative to the URL (and ended up with committing everything to the
Cross/plugins directory instead of Cross/plugins/FloatMathPlugin).
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FloatMathPlugin for Croquet

johnmci
LIkely you need to share your compiler options for x87 and ppc.

On 26-Mar-06, at 6:44 PM, Andreas Raab wrote:

> Hi Guys -
>
> I've just committed the changes for the FloatMathPlugin which  
> Croquet uses to get bit-identical cross-platform floating point  
> behavior (with a big thanks to Sun for developing fdlibm ;-)
>   - Andreas

--
========================================================================
===
John M. McIntosh <[hidden email]> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
========================================================================
===

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FloatMathPlugin for Croquet

Andreas.Raab
John M McIntosh wrote:
> LIkely you need to share your compiler options for x87 and ppc.

No compiler options on my end; I'm doing it at runtime via:

/* default fpu control word:
    _RC_NEAR: round to nearest
    _PC_53 :  double precision arithmetic (instead of extended)
    _EM_XXX: silent operations (no signals please)
*/
#define FPU_DEFAULT (_RC_NEAR + _PC_53 + _EM_INVALID + _EM_ZERODIVIDE +
_EM_OVERFLOW + _EM_UNDERFLOW + _EM_INEXACT + _EM_DENORMAL)


and then (before doing much else):

   /* set default fpu control word */
   _control87(FPU_DEFAULT, _MCW_EM | _MCW_RC | _MCW_PC | _MCW_IC);


Cheers,
   - Andreas
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FloatMathPlugin for Croquet

David T. Lewis
In reply to this post by Andreas.Raab
On Sun, Mar 26, 2006 at 06:44:15PM -0800, Andreas Raab wrote:
> Hi Guys -
>
> I've just committed the changes for the FloatMathPlugin which Croquet
> uses to get bit-identical cross-platform floating point behavior (with a
> big thanks to Sun for developing fdlibm ;-)

Hi Andreas,

I built a Unix VM with the FloatMathPlugin on an Intel Linux system.
FlaotMathPluginTests produces quite a few failures. I've attached a
screen dump to show the test runner output, and platform and version
information.

I won't pretend to have any expertise in the topic, but if there is
anything you would like me to test, I'll be happy to have a go at it.

Dave


FloatPluginOnLinux.png (61K) Download Attachment
Loading...