2009/7/28 Paul Khuong <pkhuong@...>:
>> * Convert (/ <float> <one>) to (+ <float> <zero>), and similarly for *.
> Multiplication and division by 1 preserve the sign of zeros, but addition
> doesn't. This one should probably depend on FLOAT-ACCURACY, converting the
> division to a multiplication, which always preserves signs in the default
> case. In fact, the optimisation could be generalised to division by any
> number that can be exactly reciprocated, using something like the following.
> (defun maybe-exact-reciprocal (x)
> If FLOAT-ACCURACY is 1, then (/ <float> <constant-float>) can be converted
> to (* float (/ <constant-float>)) if the above doesn't return NIL (if
> FLOAT-ACCURACY is 0, then multiplication by reciprocal would probably always
> make sense, with a direct elimination of (* <float> <+/- one>)). I'm fairly
> certain the transformation can be extended to complex floats without
> breaking anything that isn't already broken, and even for non-constant
> complex-real division.
I've implemented this (though not the extensions) in 126.96.36.199.
>> * Convert (/ <float> <minus-one>) to (+ (%negate <float>) <zero>), and
>> similarly for *.
> I don't see why that shouldn't be converted to (%negate <float>), which
> computes the sign of zeros correctly.
I mentioned this on IRC, but for the record: I did that to catch SNaNs.
> As for FLOAT-ACCURACY, since the "default" case is 1 and the minimal value
> 0, we're only left with a binary toggle... FLOAT-INACCURACY/-SPEED would
> give us a more useful range.
Actually, the default is --unintuitively-- 3, currently. The only
thing it affected prior to this commit was the setting of FPU control
word on x86 for alien calls: 53 bits for lisp, and 64 for C. (There's
a bug there, actually: if the foreign function unwinds, the FPU is
left in 64 bit mode for lisp.)
Christophe pointed this out: http://gcc.gnu.org/wiki/FloatingPointMath
I think most interesting toggles are:
treatment of signed zeros
For now these are all on F-A=0, but perhaps they should be separate qualities?