1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6#include <_mingw_mac.h>
7
8	.file	"log2l.S"
9	.text
10#ifdef __x86_64__
11	.align 8
12#else
13	.align 4
14#endif
15one:	.double 1.0
16	/* It is not important that this constant is precise.  It is only
17	   a value which is known to be on the safe side for using the
18	   fyl2xp1 instruction.  */
19limit:	.double 0.29
20
21.globl __MINGW_USYMBOL(log2l)
22	.def	__MINGW_USYMBOL(log2l);	.scl	2;	.type	32;	.endef
23__MINGW_USYMBOL(log2l):
24#ifdef __x86_64__
25	fldl	one(%rip)
26	fldt	(%rdx)		// x : 1
27	fxam
28	fnstsw
29	fld	%st		// x : x : 1
30	sahf
31	jc	3f		// in case x is NaN or �Inf
324:	fsub	%st(2), %st	// x-1 : x : 1
33	fld	%st		// x-1 : x-1 : x : 1
34	fabs			// |x-1| : x-1 : x : 1
35	fcompl	limit(%rip)	// x-1 : x : 1
36	fnstsw			// x-1 : x : 1
37	andb	$0x45, %ah
38	jz	2f
39	fstp	%st(1)		// x-1 : 1
40	fyl2xp1			// log(x)
41	movq	%rcx,%rax
42	movq	$0,8(%rcx)
43	fstpt	(%rcx)
44	ret
45
462:	fstp	%st(0)		// x : 1
47	fyl2x			// log(x)
48	movq	%rcx,%rax
49	movq	$0,8(%rcx)
50	fstpt	(%rcx)
51	ret
52
533:	jp	4b		// in case x is �Inf
54	fstp	%st(1)
55	fstp	%st(1)
56	movq	%rcx,%rax
57	movq	$0,8(%rcx)
58	fstpt	(%rcx)
59	ret
60#else
61	fldl	one
62	fldt	4(%esp)		// x : 1
63	fxam
64	fnstsw
65	fld	%st		// x : x : 1
66	sahf
67	jc	3f		// in case x is NaN or �Inf
684:	fsub	%st(2), %st	// x-1 : x : 1
69	fld	%st		// x-1 : x-1 : x : 1
70	fabs			// |x-1| : x-1 : x : 1
71	fcompl	limit		// x-1 : x : 1
72	fnstsw			// x-1 : x : 1
73	andb	$0x45, %ah
74	jz	2f
75	fstp	%st(1)		// x-1 : 1
76	fyl2xp1			// log(x)
77	ret
78
792:	fstp	%st(0)		// x : 1
80	fyl2x			// log(x)
81	ret
82
833:	jp	4b		// in case x is �Inf
84	fstp	%st(1)
85	fstp	%st(1)
86	ret
87#endif
88