Linux: Consolidate typesizes.h
[glibc.git] / sysdeps / i386 / fpu / e_log.S
blob0d5752454d133199e3cf6a9f2cd9207637fb0943
1 /*
2  * Public domain.
3  */
5 #include <machine/asm.h>
6 #include <libm-alias-finite.h>
8         .section .rodata.cst8,"aM",@progbits,8
10         .p2align 3
11         .type one,@object
12 one:    .double 1.0
13         ASM_SIZE_DIRECTIVE(one)
14         /* It is not important that this constant is precise.  It is only
15            a value which is known to be on the safe side for using the
16            fyl2xp1 instruction.  */
17         .type limit,@object
18 limit:  .double 0.29
19         ASM_SIZE_DIRECTIVE(limit)
22 #ifdef PIC
23 # define MO(op) op##@GOTOFF(%edx)
24 #else
25 # define MO(op) op
26 #endif
28         .text
29 ENTRY(__ieee754_log)
30         fldln2                  // log(2)
31         fldl    4(%esp)         // x : log(2)
32         fxam
33         fnstsw
34 #ifdef PIC
35         LOAD_PIC_REG (dx)
36 #endif
37         fld     %st             // x : x : log(2)
38         sahf
39         jc      3f              // in case x is NaN or +-Inf
40 4:      fsubl   MO(one)         // x-1 : x : log(2)
41         fld     %st             // x-1 : x-1 : x : log(2)
42         fabs                    // |x-1| : x-1 : x : log(2)
43         fcompl  MO(limit)       // x-1 : x : log(2)
44         fnstsw                  // x-1 : x : log(2)
45         andb    $0x45, %ah
46         jz      2f
47         fxam
48         fnstsw
49         andb    $0x45, %ah
50         cmpb    $0x40, %ah
51         jne     5f
52         fabs                    // log(1) is +0 in all rounding modes.
53 5:      fstp    %st(1)          // x-1 : log(2)
54         fyl2xp1                 // log(x)
55         ret
57 2:      fstp    %st(0)          // x : log(2)
58         fyl2x                   // log(x)
59         ret
61 3:      jp      4b              // in case x is +-Inf
62         fstp    %st(1)
63         fstp    %st(1)
64         ret
65 END (__ieee754_log)
67 ENTRY(__log_finite)
68         fldln2                  // log(2)
69         fldl    4(%esp)         // x : log(2)
70 #ifdef PIC
71         LOAD_PIC_REG (dx)
72 #endif
73         fld     %st             // x : x : log(2)
74         fsubl   MO(one)         // x-1 : x : log(2)
75         fld     %st             // x-1 : x-1 : x : log(2)
76         fabs                    // |x-1| : x-1 : x : log(2)
77         fcompl  MO(limit)       // x-1 : x : log(2)
78         fnstsw                  // x-1 : x : log(2)
79         andb    $0x45, %ah
80         jz      2b
81         fxam
82         fnstsw
83         andb    $0x45, %ah
84         cmpb    $0x40, %ah
85         jne     6f
86         fabs                    // log(1) is +0 in all rounding modes.
87 6:      fstp    %st(1)          // x-1 : log(2)
88         fyl2xp1                 // log(x)
89         ret
90 END(__log_finite)
91 libm_alias_finite (__log_finite, __log)