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