[m-rev.] diff: update float_consistency test

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Jun 12 22:15:25 AEST 2003


On 12-Jun-2003, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> On 12-Jun-2003, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > 
> > Estimated hours taken: 0.1
> > Branches: main, release
> > 
> > tests/hard_coded/float_consistency.m:
> > 	Change calls to float./ to float.unchecked_quotient.
> > 	This test case is meant to test compile-time evaluation
> > 	of builtins. float./ hasn't been builtin for a while.
> > 	This test case fails with --optimize-constant-propagation.
> 
> This wasn't right -- compiler/const_prop.m treats float./ as
> if it were a builtin.

Probably the best thing would be to test both.

> The cause of the failure appears to be different rounding
> behaviour on earth (with gcc 3.2) depending on whether the
> division is done inline or by a separate procedure.
> Passing `-ffloat-store' to gcc (which disables storing
> intermediate floats in registers) causes the test to pass.

Yes -- did you see my note in /home/mercury/public/test_mercury/logs/STATUS?

The problem is due to GCC computing one of the divisions on the
processor's floating point register stack, whose registers have extended
precision, and comparing that with the result of an earlier division
which was stored on the heap, with just the usual double precision.

> adding `MCFLAGS-float_consistency = --no-intermodule-optimization'
> to Mercury.options will fix the test failure,

I don't think that is a good idea.  Why bother running the test at all
if we're just going to disable it for the cases where it fails?

> but would it be better to make `-ffloat-store' the default?

Doing that might have pretty severe effects on performance for some programs.

Also, that would only work with GCC; other C compilers might not have
any equivalent option.  Unfortunately the C standard does not require
C implementations to be consistent in their treatment of floating point.

Also, even with GCC, using `-ffloat-store' is not necessarily enough
in general.  According to the GCC documentation, you also need to
"store all pertinent intermediate computations into variables".
The MLDS back-end does not guarantee that (for example, the
--eliminate-local-vars optimization will violate it) and AFAIK the LLDS
back-end doesn't guarantee it either (it might perhaps fall out that
way in the current implementation, but I think it used to fail when we
had the value numbering pass, for example).

So, I'm not sure what the best approach is.
Here's a few options:

	1. Document that floating point arithmetic might not be consistent.
	   Disable the test case, and add a comment explaining why the test
	   case is not valid (pointing to the part of the documentation
	   where it says that floating point arithmetic might not be
	   consistent).

	2. Add a new option, called say `--consistent-float', which causes
	   the Mercury implementation to pass `-ffloat-store' to GCC.
	   If the new option is enabled, also disable --eliminate-local-vars,
	   and add documentation to the MLDS and LLDS back-ends indicating
	   that they must preserve stores to floating point variables
	   if this option is enabled.
	   Use this new option for the float_consistency test case.
	   Document in the user's guide, library reference, and/or
	   language reference (maybe all three?) that floating point
	   arithmetic might not be consistent when C compilers other
	   than GCC are used or when this new `--consistent-float'
	   option is not enabled.

	3. Like 2, except with the default behaviour the other way around.
	   In other words:

	   Make `-ffloat-store' the default for GCC.
	   Add a new option, which causes the Mercury implementation to
	   not pass `-ffloat-store' to GCC.
	   Add documentation to the MLDS and LLDS back-ends indicating
	   that they must preserve stores to floating point variables
	   if this option is enabled.
	   Document for users that floating point arithmetic might not
	   be consistent when C compilers other than GCC are used or
	   when this new option is enabled.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list