xref: /freebsd/lib/libc/i386/_fpmath.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
18cf5ed51SMike Barcroft /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3d915a14eSPedro F. Giffuni  *
4f154b03bSDavid Schultz  * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
58cf5ed51SMike Barcroft  * All rights reserved.
68cf5ed51SMike Barcroft  *
78cf5ed51SMike Barcroft  * Redistribution and use in source and binary forms, with or without
88cf5ed51SMike Barcroft  * modification, are permitted provided that the following conditions
98cf5ed51SMike Barcroft  * are met:
108cf5ed51SMike Barcroft  * 1. Redistributions of source code must retain the above copyright
118cf5ed51SMike Barcroft  *    notice, this list of conditions and the following disclaimer.
128cf5ed51SMike Barcroft  * 2. Redistributions in binary form must reproduce the above copyright
138cf5ed51SMike Barcroft  *    notice, this list of conditions and the following disclaimer in the
148cf5ed51SMike Barcroft  *    documentation and/or other materials provided with the distribution.
158cf5ed51SMike Barcroft  *
168cf5ed51SMike Barcroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
178cf5ed51SMike Barcroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
188cf5ed51SMike Barcroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
198cf5ed51SMike Barcroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
208cf5ed51SMike Barcroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
218cf5ed51SMike Barcroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
228cf5ed51SMike Barcroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
238cf5ed51SMike Barcroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
248cf5ed51SMike Barcroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
258cf5ed51SMike Barcroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
268cf5ed51SMike Barcroft  * SUCH DAMAGE.
278cf5ed51SMike Barcroft  */
288cf5ed51SMike Barcroft 
298cf5ed51SMike Barcroft union IEEEl2bits {
308cf5ed51SMike Barcroft 	long double	e;
318cf5ed51SMike Barcroft 	struct {
328cf5ed51SMike Barcroft 		unsigned int	manl	:32;
338cf5ed51SMike Barcroft 		unsigned int	manh	:32;
348cf5ed51SMike Barcroft 		unsigned int	exp	:15;
358cf5ed51SMike Barcroft 		unsigned int	sign	:1;
368cf5ed51SMike Barcroft 		unsigned int	junk	:16;
378cf5ed51SMike Barcroft 	} bits;
38d2012f33SBruce Evans 	struct {
39d2012f33SBruce Evans 		unsigned long long man	:64;
40d2012f33SBruce Evans 		unsigned int 	expsign	:16;
41d2012f33SBruce Evans 		unsigned int	junk	:16;
42d2012f33SBruce Evans 	} xbits;
438cf5ed51SMike Barcroft };
448cf5ed51SMike Barcroft 
451dfab5edSDavid Schultz #define	LDBL_NBIT	0x80000000
461dfab5edSDavid Schultz #define	mask_nbit_l(u)	((u).bits.manh &= ~LDBL_NBIT)
4792b93b37SDavid Schultz 
48a8cb7ccaSDavid Schultz #define	LDBL_MANH_SIZE	32
49a8cb7ccaSDavid Schultz #define	LDBL_MANL_SIZE	32
50a8cb7ccaSDavid Schultz 
5192b93b37SDavid Schultz #define	LDBL_TO_ARRAY32(u, a) do {			\
5292b93b37SDavid Schultz 	(a)[0] = (uint32_t)(u).bits.manl;		\
5392b93b37SDavid Schultz 	(a)[1] = (uint32_t)(u).bits.manh;		\
5492b93b37SDavid Schultz } while (0)
55