2.9
[glibc/nacl-glibc.git] / sysdeps / i386 / fpu / e_log.S
blobce55b72292ecccee37e977640d8e956edb81630c
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 RCSID("$NetBSD: e_log.S,v 1.4 1995/05/08 23:48:39 jtc Exp $")
12 #ifdef __ELF__
13         .section .rodata
14 #else
15         .text
16 #endif
17         .align ALIGNARG(4)
18         ASM_TYPE_DIRECTIVE(one,@object)
19 one:    .double 1.0
20         ASM_SIZE_DIRECTIVE(one)
21         /* It is not important that this constant is precise.  It is only
22            a value which is known to be on the safe side for using the
23            fyl2xp1 instruction.  */
24         ASM_TYPE_DIRECTIVE(limit,@object)
25 limit:  .double 0.29
26         ASM_SIZE_DIRECTIVE(limit)
29 #ifdef PIC
30 #define MO(op) op##@GOTOFF(%edx)
31 #else
32 #define MO(op) op
33 #endif
35         .text
36 ENTRY(__ieee754_log)
37         fldln2                  // log(2)
38         fldl    4(%esp)         // x : log(2)
39         fxam
40         fnstsw
41 #ifdef PIC
42         LOAD_PIC_REG (dx)
43 #endif
44         fld     %st             // x : x : log(2)
45         sahf
46         jc      3f              // in case x is NaN or +-Inf
47 4:      fsubl   MO(one)         // x-1 : x : log(2)
48         fld     %st             // x-1 : x-1 : x : log(2)
49         fabs                    // |x-1| : x-1 : x : log(2)
50         fcompl  MO(limit)       // x-1 : x : log(2)
51         fnstsw                  // x-1 : x : log(2)
52         andb    $0x45, %ah
53         jz      2f
54         fstp    %st(1)          // x-1 : log(2)
55         fyl2xp1                 // log(x)
56         ret
58 2:      fstp    %st(0)          // x : log(2)
59         fyl2x                   // log(x)
60         ret
62 3:      jp      4b              // in case x is +-Inf
63         fstp    %st(1)
64         fstp    %st(1)
65         ret
66 END (__ieee754_log)