Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6424 | siemargl | 1 | |
2 | include 'proc32.inc' |
||
3 | section '.text' executable |
||
4 | |||
5 | |||
6 | public exp2_ as "exp2" |
||
7 | |||
8 | |||
9 | MaskedCW dw ? |
||
10 | |||
11 | |||
12 | ; We can easily compute 2**int(x) with fscale and |
||
13 | ; 2**frac(x) using f2xm1. |
||
14 | exp2_int: |
||
15 | fstcw [SaveCW] |
||
16 | |||
17 | |||
18 | |||
19 | |||
20 | or byte ptr MaskedCW + 1, 1100b |
||
21 | fldcw [MaskedCW] |
||
22 | |||
23 | |||
24 | fld st0 |
||
25 | frndint ;Compute integer portion. |
||
26 | |||
27 | |||
28 | fsub st0, st1 ;Compute fractional part. |
||
29 | |||
30 | |||
31 | fld1 |
||
32 | faddp st1, st0 ;Compute 2**frac(x). |
||
33 | |||
34 | |||
35 | fld1 ;Compute 1*2**int(x). |
||
36 | fscale |
||
37 | fstp st1 ;Remove st(1) (which is 1). |
||
38 | |||
39 | |||
40 | fstp st1 ;Remove st1 |
||
41 | |||
42 | |||
43 | ret |
||
44 | |||
45 | |||
46 | ; exp(x) = 2**(x * lg(e)) |
||
47 | |||
48 | |||
49 | fldl2e ;Put lg(e) onto the stack. |
||
50 | fmulp st1, st0 ;Compute x*lg(e). |
||
51 | call exp2_int;Compute 2**(x * lg(e)) |
||
52 | ret |
||
53 | |||
54 | |||
55 | fld qword[esp+4] |
||
56 | call exp2_int;Compute 2 ** x |
||
57 | ret |
||
58 |