]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/i386/fpu/e_log.S
Optimize libm
[thirdparty/glibc.git] / sysdeps / i386 / fpu / e_log.S
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 */
7
8 #include <machine/asm.h>
9
10 #ifdef __ELF__
11 .section .rodata.cst8,"aM",@progbits,8
12 #else
13 .text
14 #endif
15 .p2align 3
16 ASM_TYPE_DIRECTIVE(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 ASM_TYPE_DIRECTIVE(limit,@object)
23 limit: .double 0.29
24 ASM_SIZE_DIRECTIVE(limit)
25
26
27 #ifdef PIC
28 # define MO(op) op##@GOTOFF(%edx)
29 #else
30 # define MO(op) op
31 #endif
32
33 .text
34 ENTRY(__ieee754_log)
35 fldln2 // log(2)
36 fldl 4(%esp) // x : log(2)
37 fxam
38 fnstsw
39 #ifdef PIC
40 LOAD_PIC_REG (dx)
41 #endif
42 fld %st // x : x : log(2)
43 sahf
44 jc 3f // in case x is NaN or +-Inf
45 4: fsubl MO(one) // x-1 : x : log(2)
46 fld %st // x-1 : x-1 : x : log(2)
47 fabs // |x-1| : x-1 : x : log(2)
48 fcompl MO(limit) // x-1 : x : log(2)
49 fnstsw // x-1 : x : log(2)
50 andb $0x45, %ah
51 jz 2f
52 fstp %st(1) // x-1 : log(2)
53 fyl2xp1 // log(x)
54 ret
55
56 2: fstp %st(0) // x : log(2)
57 fyl2x // log(x)
58 ret
59
60 3: jp 4b // in case x is +-Inf
61 fstp %st(1)
62 fstp %st(1)
63 ret
64 END (__ieee754_log)
65 strong_alias (__ieee754_log, __log_finite)