1 | /* |
2 | * Public domain. |
3 | */ |
4 | |
5 | #include <machine/asm.h> |
6 | #include <i386-math-asm.h> |
7 | #include <libm-alias-finite.h> |
8 | |
9 | .section .rodata |
10 | |
11 | .align ALIGNARG(4) |
12 | .type zero_nan,@object |
13 | zero_nan: |
14 | .double 0.0 |
15 | nan: .byte 0, 0, 0, 0, 0, 0, 0xff, 0x7f |
16 | .byte 0, 0, 0, 0, 0, 0, 0, 0x80 |
17 | .byte 0, 0, 0, 0, 0, 0, 0xff, 0x7f |
18 | ASM_SIZE_DIRECTIVE(zero_nan) |
19 | |
20 | |
21 | #ifdef PIC |
22 | # define MO(op) op##@GOTOFF(%ecx) |
23 | # define MOX(op,x,f) op##@GOTOFF(%ecx,x,f) |
24 | #else |
25 | # define MO(op) op |
26 | # define MOX(op,x,f) op(,x,f) |
27 | #endif |
28 | |
29 | |
30 | .text |
31 | ENTRY(__ieee754_scalbf) |
32 | flds 8(%esp) |
33 | fxam |
34 | fnstsw |
35 | flds 4(%esp) |
36 | andl $0x4700, %eax |
37 | cmpl $0x0700, %eax |
38 | je 1f |
39 | andl $0x4500, %eax |
40 | cmpl $0x0100, %eax |
41 | je 2f |
42 | fxam |
43 | fnstsw |
44 | andl $0x4500, %eax |
45 | cmpl $0x0100, %eax |
46 | je 3f |
47 | fld %st(1) |
48 | frndint |
49 | fcomp %st(2) |
50 | fnstsw |
51 | sahf |
52 | jne 4f |
53 | fscale |
54 | fstp %st(1) |
55 | FLT_NARROW_EVAL |
56 | ret |
57 | |
58 | /* y is -inf */ |
59 | 1: fxam |
60 | #ifdef PIC |
61 | LOAD_PIC_REG (cx) |
62 | #endif |
63 | fnstsw |
64 | movl 4(%esp), %edx |
65 | shrl $5, %eax |
66 | fstp %st |
67 | fstp %st |
68 | andl $0x80000000, %edx |
69 | andl $0x0228, %eax |
70 | cmpl $0x0028, %eax |
71 | je 4f |
72 | andl $8, %eax |
73 | shrl $27, %edx |
74 | addl %edx, %eax |
75 | fldl MOX(zero_nan, %eax, 1) |
76 | ret |
77 | |
78 | /* The result is NaN, but we must not raise an exception. |
79 | So use a variable. */ |
80 | 2: fstp %st |
81 | fstp %st |
82 | #ifdef PIC |
83 | LOAD_PIC_REG (cx) |
84 | #endif |
85 | fldl MO(nan) |
86 | ret |
87 | |
88 | /* The first parameter is a NaN. Return it. */ |
89 | 3: fstp %st(1) |
90 | ret |
91 | |
92 | /* Return NaN and raise the invalid exception. */ |
93 | 4: fstp %st |
94 | fstp %st |
95 | fldz |
96 | fdiv %st |
97 | ret |
98 | END(__ieee754_scalbf) |
99 | libm_alias_finite (__ieee754_scalbf, __scalbf) |
100 | |