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#ifdef __ELF__
14	.section .rodata
15#else
16	.text
17#endif
18	.align ALIGNARG(4)
19	/* The fyl2xp1 can only be used for values in
20		-1 + sqrt(2) / 2 <= x <= 1 - sqrt(2) / 2
21	   0.29 is a safe value.
22	*/
23limit:	.tfloat 0.29
24	/* Please note:	 we use a double value here.  Since 1.0 has
25	   an exact representation this does not effect the accuracy
26	   but it helps to optimize the code.  */
27one:	.double 1.0
28
29/*
30 * Use the fyl2xp1 function when the argument is in the range -0.29 to 0.29,
31 * otherwise fyl2x with the needed extra computation.
32 */
33#ifdef PIC
34#define MO(op) op##(%rip)
35#else
36#define MO(op) op
37#endif
38
39	.text
40ENTRY(__log1pl)
41	fldln2
42
43	fldt	8(%rsp)
44
45	fxam
46	fnstsw
47	fld	%st
48	testb	$1, %ah
49	jnz	3f		// in case x is NaN or �Inf
504:
51	fabs
52	fldt	MO(limit)
53	fcompp
54	fnstsw
55	andb	$1,%ah
56	jz	2f
57
58	faddl	MO(one)
59	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	ret
70
71END (__log1pl)
72weak_alias (__log1pl, log1pl)
73