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