I am studying some x86 ASM code and what the code really does, it's my understanding that a power function (x^y) internally works as a logarithm function. By internally I mean the CPU registers.
Why is this? What is the benefit? Is it a benefit that can be replicated and borrowed by other high level languages like C++?
You should take a look at this MATH,
What the answer says is that the log functions can be achieved through taylor series and a look-up table combined. If there is a look-up table, then it may be hashed and the look-up will be easier than pow which only can be obtained through computation.
so for xy you can write it as
y = log<sub>10</sub> x .
or
y = (ln x)/(ln 10);
now if there is no log implementation for pow then it should be achieved through Addition chain exponentiation Wiki which requires runtime computation which might take longer than finding log.
EDIT : Thanks to @harold exponentiation can be performed more optimally using Exponentiation by squaring.
See the answer to this question: How to: pow(real, real) in x86
Think back to your logarithm rules: the base of 2 cancels with log2(x) leaving just x^y.
Edit: We have an x86 instruction to calculate each of the components needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With