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 | */ |
10 | |
11 | #include <machine/asm.h> |
12 | |
13 | .section .rodata.cst8,"aM" ,@progbits,8 |
14 | |
15 | .p2align 3 |
16 | .type one,@object |
17 | one: .double 1.0 |
18 | ASM_SIZE_DIRECTIVE(one) |
19 | /* It is not important that this constant is precise. It is only |
20 | a value which is known to be on the safe side for using the |
21 | fyl2xp1 instruction. */ |
22 | .type limit,@object |
23 | limit: .double 0.29 |
24 | ASM_SIZE_DIRECTIVE(limit) |
25 | |
26 | |
27 | #ifdef PIC |
28 | # define MO(op) op##(%rip) |
29 | #else |
30 | # define MO(op) op |
31 | #endif |
32 | |
33 | .text |
34 | ENTRY(__ieee754_log10l) |
35 | fldlg2 // log10(2) |
36 | fldt 8(%rsp) // x : log10(2) |
37 | fxam |
38 | fnstsw |
39 | fld %st // x : x : log10(2) |
40 | testb $1, %ah |
41 | jnz 3f // in case x is NaN or ħInf |
42 | 4: fsubl MO(one) // x-1 : x : log10(2) |
43 | fld %st // x-1 : x-1 : x : log10(2) |
44 | fabs // |x-1| : x-1 : x : log10(2) |
45 | fcompl MO(limit) // x-1 : x : log10(2) |
46 | fnstsw // x-1 : x : log10(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 // log10(1) is +0 in all rounding modes. |
55 | 5: fstp %st(1) // x-1 : log10(2) |
56 | fyl2xp1 // log10(x) |
57 | ret |
58 | |
59 | 2: fstp %st(0) // x : log10(2) |
60 | fyl2x // log10(x) |
61 | ret |
62 | |
63 | 3: testb $4, %ah |
64 | jnz 4b // in case x is ħInf |
65 | fstp %st(1) |
66 | fstp %st(1) |
67 | ret |
68 | END(__ieee754_log10l) |
69 | |
70 | |
71 | ENTRY(__log10l_finite) |
72 | fldlg2 // log10(2) |
73 | fldt 8(%rsp) // x : log10(2) |
74 | fld %st // x : x : log10(2) |
75 | 4: fsubl MO(one) // x-1 : x : log10(2) |
76 | fld %st // x-1 : x-1 : x : log10(2) |
77 | fabs // |x-1| : x-1 : x : log10(2) |
78 | fcompl MO(limit) // x-1 : x : log10(2) |
79 | fnstsw // x-1 : x : log10(2) |
80 | andb $0x45, %ah |
81 | jz 2b |
82 | fxam |
83 | fnstsw |
84 | andb $0x45, %ah |
85 | cmpb $0x40, %ah |
86 | jne 6f |
87 | fabs // log10(1) is +0 in all rounding modes. |
88 | 6: fstp %st(1) // x-1 : log10(2) |
89 | fyl2xp1 // log10(x) |
90 | ret |
91 | END(__log10l_finite) |
92 | |