1/*
2 * Public domain.
3 *
4 */
5
6#include <machine/asm.h>
7
8RCSID("$NetBSD: s_log1p.S,v 1.7 1995/05/09 00:10:58 jtc Exp $")
9
10 .section .rodata
11
12 .align ALIGNARG(4)
13 /* The fyl2xp1 can only be used for values in
14 -1 + sqrt(2) / 2 <= x <= 1 - sqrt(2) / 2
15 0.29 is a safe value.
16 */
17limit: .quad 0x947ae147ae147ae1 /* 0.29 */
18 .short 0x3ffd
19 /* Please note: we use a double value here. Since 1.0 has
20 an exact representation this does not effect the accuracy
21 but it helps to optimize the code. */
22one: .double 1.0
23
24/*
25 * Use the fyl2xp1 function when the argument is in the range -0.29 to 0.29,
26 * otherwise fyl2x with the needed extra computation.
27 */
28#ifdef PIC
29#define MO(op) op##(%rip)
30#else
31#define MO(op) op
32#endif
33
34 .text
35ENTRY(__log1pl)
36 fldln2
37
38 fldt 8(%rsp)
39
40 fxam
41 fnstsw
42 fld %st
43 testb $1, %ah
44 jnz 3f // in case x is NaN or ħInf
454:
46 fabs
47 fldt MO(limit)
48 fcompp
49 fnstsw
50 andb $1,%ah
51 jz 2f
52
53 movzwl 8+8(%rsp), %eax
54 xorb $0x80, %ah
55 cmpl $0xc040, %eax
56 jae 5f
57
58 faddl MO(one)
595: fyl2x
60 ret
61
622: fyl2xp1
63 ret
64
653: testb $4, %ah
66 jnz 4b // in case x is ħInf
67 fstp %st(1)
68 fstp %st(1)
69 fadd %st(0)
70 ret
71
72END (__log1pl)
73

source code of glibc/sysdeps/x86_64/fpu/s_log1pl.S