1/*
2 * Public domain.
3 */
4
5#include <machine/asm.h>
6#include <libm-alias-finite.h>
7
8 .section .rodata.cst8,"aM",@progbits,8
9
10 .p2align 3
11 .type one,@object
12one: .double 1.0
13 ASM_SIZE_DIRECTIVE(one)
14 /* It is not important that this constant is precise. It is only
15 a value which is known to be on the safe side for using the
16 fyl2xp1 instruction. */
17 .type limit,@object
18limit: .double 0.29
19 ASM_SIZE_DIRECTIVE(limit)
20
21
22#ifdef PIC
23# define MO(op) op##@GOTOFF(%edx)
24#else
25# define MO(op) op
26#endif
27
28 .text
29ENTRY(__ieee754_log)
30 fldln2 // log(2)
31 fldl 4(%esp) // x : log(2)
32 fxam
33 fnstsw
34#ifdef PIC
35 LOAD_PIC_REG (dx)
36#endif
37 fld %st // x : x : log(2)
38 sahf
39 jc 3f // in case x is NaN or +-Inf
404: fsubl MO(one) // x-1 : x : log(2)
41 fld %st // x-1 : x-1 : x : log(2)
42 fabs // |x-1| : x-1 : x : log(2)
43 fcompl MO(limit) // x-1 : x : log(2)
44 fnstsw // x-1 : x : log(2)
45 andb $0x45, %ah
46 jz 2f
47 fxam
48 fnstsw
49 andb $0x45, %ah
50 cmpb $0x40, %ah
51 jne 5f
52 fabs // log(1) is +0 in all rounding modes.
535: fstp %st(1) // x-1 : log(2)
54 fyl2xp1 // log(x)
55 ret
56
572: fstp %st(0) // x : log(2)
58 fyl2x // log(x)
59 ret
60
613: jp 4b // in case x is +-Inf
62 fstp %st(1)
63 fstp %st(1)
64 ret
65END (__ieee754_log)
66
67ENTRY(__log_finite)
68 fldln2 // log(2)
69 fldl 4(%esp) // x : log(2)
70#ifdef PIC
71 LOAD_PIC_REG (dx)
72#endif
73 fld %st // x : x : log(2)
74 fsubl MO(one) // x-1 : x : log(2)
75 fld %st // x-1 : x-1 : x : log(2)
76 fabs // |x-1| : x-1 : x : log(2)
77 fcompl MO(limit) // x-1 : x : log(2)
78 fnstsw // x-1 : x : log(2)
79 andb $0x45, %ah
80 jz 2b
81 fxam
82 fnstsw
83 andb $0x45, %ah
84 cmpb $0x40, %ah
85 jne 6f
86 fabs // log(1) is +0 in all rounding modes.
876: fstp %st(1) // x-1 : log(2)
88 fyl2xp1 // log(x)
89 ret
90END(__log_finite)
91libm_alias_finite (__log_finite, __log)
92

source code of glibc/sysdeps/i386/fpu/e_log.S