1/*
2 * Written by J.T. Conklin <jtc@netbsd.org>.
3 * Adapted for use as log2 by Ulrich Drepper <drepper@cygnus.com>.
4 * Public domain.
5 *
6 * Changed to use fyl2xp1 for values near 1, <drepper@cygnus.com>.
7 * Adapted for x86-64 by Andreas Jaeger <aj@suse.de>.
8 */
9
10#include <machine/asm.h>
11#include <libm-alias-finite.h>
12
13 .section .rodata.cst8,"aM",@progbits,8
14
15 .p2align 3
16 .type one,@object
17one: .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
23limit: .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
34ENTRY(__ieee754_log2l)
35 fldl MO(one)
36 fldt 8(%rsp) // x : 1
37 fxam
38 fnstsw
39 fld %st // x : x : 1
40 testb $1, %ah
41 jnz 3f // in case x is NaN or ħInf
424: fsub %st(2), %st // x-1 : x : 1
43 fld %st // x-1 : x-1 : x : 1
44 fabs // |x-1| : x-1 : x : 1
45 fcompl MO(limit) // x-1 : x : 1
46 fnstsw // x-1 : x : 1
47 andb $0x45, %ah
48 jz 2f
49 fxam
50 fnstsw
51 andb $0x45, %ah
52 cmpb $0x40, %ah
53 jne 5f
54 fabs // log2(1) is +0 in all rounding modes.
555: fstp %st(1) // x-1 : 1
56 fyl2xp1 // log(x)
57 ret
58
592: fstp %st(0) // x : 1
60 fyl2x // log(x)
61 ret
62
633: testb $4, %ah
64 jnz 4b // in case x is ħInf
65 fstp %st(1)
66 fstp %st(1)
67 fadd %st(0)
68 ret
69END (__ieee754_log2l)
70
71
72ENTRY(__log2l_finite)
73 fldl MO(one)
74 fldt 8(%rsp) // x : 1
75 fld %st // x : x : 1
76 fsub %st(2), %st // x-1 : x : 1
77 fld %st // x-1 : x-1 : x : 1
78 fabs // |x-1| : x-1 : x : 1
79 fcompl MO(limit) // x-1 : x : 1
80 fnstsw // x-1 : x : 1
81 andb $0x45, %ah
82 jz 2b
83 fxam
84 fnstsw
85 andb $0x45, %ah
86 cmpb $0x40, %ah
87 jne 6f
88 fabs // log2(1) is +0 in all rounding modes.
896: fstp %st(1) // x-1 : 1
90 fyl2xp1 // log(x)
91 ret
92END (__log2l_finite)
93libm_alias_finite (__log2l_finite, __log2l)
94