How to: pow(real, real) in x86

Maciej Ziarko picture Maciej Ziarko · Jan 9, 2011 · Viewed 25k times · Source

I'm looking for the implementation of pow(real, real) in x86 Assembly. Also I'd like to understand how the algorithm works.

Answer

Eugene Smith picture Eugene Smith · Jan 9, 2011

Just compute it as 2^(y*log2(x)).

There is a x86 instruction FYL2X to compute y*log2(x) and a x86 instruction F2XM1 to do exponentiation. F2XM1 requires an argument in [-1,1] range, so you'd have to add some code in between to extract the integer part and the remainder, exponentiate the remainder, use FSCALE to scale the result by an appropriate power of 2.