On Wed, 31 Mar 2010, Vincent Lefevre wrote:

On 2010-03-30 20:36:04 +0200, Jeroen Van Der Bossche wrote:
> The if statement is there exactly to address under- and overflow and
> nothing else. It's not because it looks simple that I didn't think
> it through. I know exactly how floating point multiplication works,
> and this implementation of *(2^c) doesn't violate under/overflow,
> denormalisation when e=0, rounding rules or rules about
> NaN/infinity.

However, extracting the exponent, and putting the new exponent back
to the floating-point number probably takes significant time (not
even mentioning the tests on the exponent) compared to what is done
entirely in hardware. I think that before anyone looks at this, you
should post benchmarks.

Also, the pipeline can stall due to the "if". Perhaps not in your
case. But a compiler cannot know that (the other branch is taken
when the value is 0, and this should not be regarded as rare).

IMHO this transformation mostly makes sense for the -ffinite-math-only case where you can replace: "put a constant and multiply/divide" by "put a constant and add/sub" and never care about extracting the exponent, overflowing, or anything else. And in that case, it does look like a nice optimization.

Otherwise, some old machines do have a slow enough multiplication that a soft-float implementation of /2^n can beat it, so it seems likely that some recent processors have the same characteristic, but it may indeed not be worth the trouble.


--
Marc Glisse

Reply via email to