Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to: pow(real, real) in x86

Tags:

x86

assembly

pow

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

like image 275
Maciej Ziarko Avatar asked Jan 09 '11 09:01

Maciej Ziarko


People also ask

What is pow () function?

The pow() function computes the power of a number. The pow() function takes two arguments (base value and power value) and, returns the power raised to the base number. For example, [Mathematics] xy = pow(x, y) [In programming] The pow() function is defined in math. h header file.


1 Answers

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.

like image 190
Eugene Smith Avatar answered Oct 07 '22 01:10

Eugene Smith