|
|
1.1 root 1: //////////
2: / /usr/src/libm/i387/pow87.s
3: / i387 mathematics library
4: / pow(x, y)
5: //////////
6:
7: RASIZE = 4
8:
9: .globl pow
10: .globl _pow
11: .globl _two
12: .globl _ylog2x
13: .globl _cfcc
14: .globl _tstcc
15: .globl _edomain
16:
17: //////////
18: / double
19: / pow(x, y)
20: / double x, y;
21: /
22: / _pow takes x, y on the NDP stack.
23: //////////
24: x = RASIZE / x arg offset
25: y = RASIZE+8 / y arg offset
26:
27: pow:
28: fldl y(%esp) / Load argument y.
29: fldl x(%esp) / Load argument x.
30:
31: _pow: / x, y
32: call _tstcc / Test if x == 0.
33: je ?0 / x is zero.
34: jb ?1 / x is negative.
35: subl %eax, %eax / x is positive, clear ZF flag
36: jmp ?4 / to indicate result sign positive.
37:
38: ?0:
39: fxch / y, 0
40: call _tstcc / Compare y to 0.
41: fstp %st / Pop y, leaving 0.
42: jbe ?2 / y <= 0, issue EDOM error and return 0.
43: ret / y > 0, return 0.
44:
45: ?1:
46: fld %st(1) / y, x, y with x negative.
47: call tstintp / Test if y is integral and pop.
48: je ?3 / y is integral.
49: fstp %st / y is nonintegral, pop x
50: ?2:
51: jmp _edomain / and issue EDOM error and return.
52:
53: ?3:
54: fchs / x is negative, force it positive.
55: fld1 / 1, x, y
56: fadd %st, %st / 2, x, y
57: fdivr %st, %st(2) / y/2, x, y
58: call tstintp / Test if y/2 is integral.
59:
60: / At 4:, ZF flag contains the desired result sign.
61: / The NDP stack contains abs(x), y.
62: ?4:
63: pushf / Save the flags.
64: call _ylog2x / y * log base 2 of x
65: call _two / 2 ^ (y * log base 2 of x) = x ^ y
66: popf / Restore the flags.
67: je ?5 / No sign change, done.
68: fchs / Flip the result sign.
69:
70: ?5:
71: ret
72:
73: //////////
74: / tstintp tests whether the NDP stacktop %st contains
75: / an integral value and sets ZF flag accordingly.
76: / It pops the NDP stack before returning.
77: / This works with any of the four NDP rounding modes.
78: //////////
79: tstintp: / x
80: fld %st / x, x
81: frndint / int(x), x
82: fcompp / Compare int(x) to x and pop both.
83: jmp _cfcc / Load condition codes and return.
84:
85: / end of pow87.s
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.