2.9
[glibc/nacl-glibc.git] / sysdeps / x86_64 / fpu / e_log10l.S
blob633234b74431c4f64e4c79958b97087a28761614
1 /*
2  * Written by J.T. Conklin <jtc@netbsd.org>.
3  * Public domain.
4  *
5  * Adapted for `long double' by Ulrich Drepper <drepper@cygnus.com>.
6  *
7  * Changed to use fyl2xp1 for values near 1, <drepper@cygnus.com>.
8  * Adapted for x86-64 by Andreas Jaeger <aj@suse.de>.
9  */
11 #include <machine/asm.h>
13 RCSID("$NetBSD: $")
15 #ifdef __ELF__
16         .section .rodata
17 #else
18         .text
19 #endif
20         .align ALIGNARG(4)
21         ASM_TYPE_DIRECTIVE(one,@object)
22 one:    .double 1.0
23         ASM_SIZE_DIRECTIVE(one)
24         /* It is not important that this constant is precise.  It is only
25            a value which is known to be on the safe side for using the
26            fyl2xp1 instruction.  */
27         ASM_TYPE_DIRECTIVE(limit,@object)
28 limit:  .double 0.29
29         ASM_SIZE_DIRECTIVE(limit)
32 #ifdef PIC
33 #define MO(op) op##(%rip)
34 #else
35 #define MO(op) op
36 #endif
38         .text
39 ENTRY(__ieee754_log10l)
40         fldlg2                  // log10(2)
41         fldt    8(%rsp)         // x : log10(2)
42         fxam
43         fnstsw
44         fld     %st             // x : x : log10(2)
45         testb   $1, %ah
46         jnz     3f              // in case x is NaN or ±Inf
47 4:      fsubl   MO(one)         // x-1 : x : log10(2)
48         fld     %st             // x-1 : x-1 : x : log10(2)
49         fabs                    // |x-1| : x-1 : x : log10(2)
50         fcompl  MO(limit)       // x-1 : x : log10(2)
51         fnstsw                  // x-1 : x : log10(2)
52         andb    $0x45, %ah
53         jz      2f
54         fstp    %st(1)          // x-1 : log10(2)
55         fyl2xp1                 // log10(x)
56         ret
58 2:      fstp    %st(0)          // x : log10(2)
59         fyl2x                   // log10(x)
60         ret
62 3:      testb   $4, %ah
63         jnz     4b              // in case x is ±Inf
64         fstp    %st(1)
65         fstp    %st(1)
66         ret
67 END(__ieee754_log10l)