1/* ix87 specific frexp implementation for long double.
2   Copyright (C) 1997-2022 Free Software Foundation, Inc.
3   This file is part of the GNU C Library.
4
5   The GNU C Library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9
10   The GNU C Library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with the GNU C Library; if not, see
17   <https://www.gnu.org/licenses/>.  */
18
19#include <libm-alias-ldouble.h>
20#include <machine/asm.h>
21
22	.section .rodata
23
24	.align ALIGNARG(4)
25	.type two64,@object
26two64:	.byte 0, 0, 0, 0, 0, 0, 0xf0, 0x43
27	ASM_SIZE_DIRECTIVE(two64)
28
29#ifdef PIC
30#define MO(op) op##@GOTOFF(%edx)
31#else
32#define MO(op) op
33#endif
34
35#define PARMS	4		/* no space for saved regs */
36#define VAL0	PARMS
37#define VAL1	VAL0+4
38#define VAL2	VAL1+4
39#define EXPP	VAL2+4
40
41	.text
42ENTRY (__frexpl)
43
44	movl	VAL0(%esp), %ecx
45	movl	VAL2(%esp), %eax
46	orl	VAL1(%esp), %ecx
47	movl	%eax, %edx
48	andl	$0x7fff, %eax
49	orl	%eax, %ecx
50	jz	1f
51	xorl	%ecx, %ecx
52	cmpl	$0x7fff, %eax
53	je	3f
54
55	cmpl	$0, %eax
56	jne	2f
57
58	fldt	VAL0(%esp)
59#ifdef	PIC
60	LOAD_PIC_REG (dx)
61#endif
62
63	fmull	MO(two64)	/* It's not necessary to use a 80bit factor */
64	movl	$-64, %ecx
65	fstpt	VAL0(%esp)
66	fwait
67	movl	VAL2(%esp), %eax
68	movl	%eax, %edx
69	andl	$0x7fff, %eax
70
712:	andl	$0x8000, %edx
72	subl	$16382, %eax
73	orl	$0x3ffe, %edx
74	addl	%eax, %ecx
75	movl	%edx, VAL2(%esp)
76
77	/* Store %ecx in the variable pointed to by the second argument,
78	   get the factor from the stack and return.  */
791:	movl	EXPP(%esp), %eax
80	fldt	VAL0(%esp)
81	movl	%ecx, (%eax)
82
83	ret
84
85	/* Infinity or NaN; ensure signaling NaNs are quieted.  */
863:	movl	EXPP(%esp), %eax
87	fldt	VAL0(%esp)
88	fadd	%st
89	movl	%ecx, (%eax)
90	ret
91END (__frexpl)
92libm_alias_ldouble (__frexp, frexp)
93