Exponential operator
bearophile
bearophileHUGS at lycos.com
Fri Aug 7 12:33:05 PDT 2009
Jimbob Wrote:
>bearophile:
> > And A^^3 may be faster than A*A*A when A isn't a simple number, so always
> > replacing the
> > power with mults may be bad.
>
> It wont be on x86. Multiplication has a latency of around 4 cycles whether
> int or float, so x*x*x will clock around 12 cycles. The main instruction
> needed for pow, F2XM1, costs anywhere from 50 cycles to 120, depending on
> the cpu. And then you need to do a bunch of other stuff to make F2XM1 handle
> different bases.
I don't understand what you mean.
But "when A isn't a simple number" means for example when A is a matrix. In such case the algorithm of A^3 may be faster than doing two matrix multiplications, and even if it's not faster it may be better numerically, etc. In such cases I'd like to leave to the matrix power algorithm the decision regarding what do to and I don't think rewriting the power is good.
This means the rewriting rules I have shown (x^^2 => x*x, x^^3 => x*x*x, and maybe x^^4 => y=x*x;y*y) have to be used only when x is a built-in datum.
Bye,
bearophile
More information about the Digitalmars-d
mailing list