xref: /titanic_41/usr/src/lib/libm/common/C/libm_macros.h (revision 5b2ba9d3d1e04dde804c89e9879f7dfc9bcebf61)
1*5b2ba9d3SPiotr Jasiukajtis /*
2*5b2ba9d3SPiotr Jasiukajtis  * CDDL HEADER START
3*5b2ba9d3SPiotr Jasiukajtis  *
4*5b2ba9d3SPiotr Jasiukajtis  * The contents of this file are subject to the terms of the
5*5b2ba9d3SPiotr Jasiukajtis  * Common Development and Distribution License (the "License").
6*5b2ba9d3SPiotr Jasiukajtis  * You may not use this file except in compliance with the License.
7*5b2ba9d3SPiotr Jasiukajtis  *
8*5b2ba9d3SPiotr Jasiukajtis  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5b2ba9d3SPiotr Jasiukajtis  * or http://www.opensolaris.org/os/licensing.
10*5b2ba9d3SPiotr Jasiukajtis  * See the License for the specific language governing permissions
11*5b2ba9d3SPiotr Jasiukajtis  * and limitations under the License.
12*5b2ba9d3SPiotr Jasiukajtis  *
13*5b2ba9d3SPiotr Jasiukajtis  * When distributing Covered Code, include this CDDL HEADER in each
14*5b2ba9d3SPiotr Jasiukajtis  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5b2ba9d3SPiotr Jasiukajtis  * If applicable, add the following below this CDDL HEADER, with the
16*5b2ba9d3SPiotr Jasiukajtis  * fields enclosed by brackets "[]" replaced with your own identifying
17*5b2ba9d3SPiotr Jasiukajtis  * information: Portions Copyright [yyyy] [name of copyright owner]
18*5b2ba9d3SPiotr Jasiukajtis  *
19*5b2ba9d3SPiotr Jasiukajtis  * CDDL HEADER END
20*5b2ba9d3SPiotr Jasiukajtis  */
21*5b2ba9d3SPiotr Jasiukajtis /*
22*5b2ba9d3SPiotr Jasiukajtis  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
23*5b2ba9d3SPiotr Jasiukajtis  */
24*5b2ba9d3SPiotr Jasiukajtis /*
25*5b2ba9d3SPiotr Jasiukajtis  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26*5b2ba9d3SPiotr Jasiukajtis  * Use is subject to license terms.
27*5b2ba9d3SPiotr Jasiukajtis  */
28*5b2ba9d3SPiotr Jasiukajtis 
29*5b2ba9d3SPiotr Jasiukajtis #ifndef _LIBM_MACROS_H
30*5b2ba9d3SPiotr Jasiukajtis #define	_LIBM_MACROS_H
31*5b2ba9d3SPiotr Jasiukajtis 
32*5b2ba9d3SPiotr Jasiukajtis #include <sys/isa_defs.h>
33*5b2ba9d3SPiotr Jasiukajtis 
34*5b2ba9d3SPiotr Jasiukajtis #if defined(__sparc)
35*5b2ba9d3SPiotr Jasiukajtis 
36*5b2ba9d3SPiotr Jasiukajtis #define	HIWORD		0
37*5b2ba9d3SPiotr Jasiukajtis #define	LOWORD		1
38*5b2ba9d3SPiotr Jasiukajtis #define	HIXWORD		0		/* index of int containing exponent */
39*5b2ba9d3SPiotr Jasiukajtis #define	XSGNMSK		0x80000000	/* exponent bit mask within the int */
40*5b2ba9d3SPiotr Jasiukajtis #define	XBIASED_EXP(x)	((((int *)&x)[HIXWORD] & ~0x80000000) >> 16)
41*5b2ba9d3SPiotr Jasiukajtis #define	ISZEROL(x)	(((((int *)&x)[0] & ~XSGNMSK) | ((int *)&x)[1] | \
42*5b2ba9d3SPiotr Jasiukajtis 				((int *)&x)[2] | ((int *)&x)[3]) == 0)
43*5b2ba9d3SPiotr Jasiukajtis 
44*5b2ba9d3SPiotr Jasiukajtis #elif defined(__x86)
45*5b2ba9d3SPiotr Jasiukajtis 
46*5b2ba9d3SPiotr Jasiukajtis #define	HIWORD		1
47*5b2ba9d3SPiotr Jasiukajtis #define	LOWORD		0
48*5b2ba9d3SPiotr Jasiukajtis #define	HIXWORD		2
49*5b2ba9d3SPiotr Jasiukajtis #define	XSGNMSK		0x8000
50*5b2ba9d3SPiotr Jasiukajtis #define	XBIASED_EXP(x)	(((int *)&x)[HIXWORD] & 0x7fff)
51*5b2ba9d3SPiotr Jasiukajtis #define	ISZEROL(x)	(x == 0.0L)
52*5b2ba9d3SPiotr Jasiukajtis 
53*5b2ba9d3SPiotr Jasiukajtis #define	HANDLE_UNSUPPORTED
54*5b2ba9d3SPiotr Jasiukajtis 
55*5b2ba9d3SPiotr Jasiukajtis /*
56*5b2ba9d3SPiotr Jasiukajtis  * "convert" the high-order 32 bits of a SPARC quad precision
57*5b2ba9d3SPiotr Jasiukajtis  * value ("I") to the sign, exponent, and high-order bits of an
58*5b2ba9d3SPiotr Jasiukajtis  * x86 extended double precision value ("E"); the low-order bits
59*5b2ba9d3SPiotr Jasiukajtis  * in the 12-byte quantity are left intact
60*5b2ba9d3SPiotr Jasiukajtis  */
61*5b2ba9d3SPiotr Jasiukajtis #define	ITOX(I, E)       \
62*5b2ba9d3SPiotr Jasiukajtis 		E[2] = 0xffff & ((I) >> 16); \
63*5b2ba9d3SPiotr Jasiukajtis 		E[1] = (((I) & 0x7fff0000) == 0)? \
64*5b2ba9d3SPiotr Jasiukajtis 		    (E[1] & 0x7fff) | (0x7fff8000 & ((I) << 15)) :\
65*5b2ba9d3SPiotr Jasiukajtis 		    0x80000000 | (E[1] & 0x7fff) | (0x7fff8000 & ((I) << 15))
66*5b2ba9d3SPiotr Jasiukajtis 
67*5b2ba9d3SPiotr Jasiukajtis /*
68*5b2ba9d3SPiotr Jasiukajtis  * "convert" the sign, exponent, and high-order bits of an x86
69*5b2ba9d3SPiotr Jasiukajtis  * extended double precision value ("E") to the high-order 32 bits
70*5b2ba9d3SPiotr Jasiukajtis  * of a SPARC quad precision value ("I")
71*5b2ba9d3SPiotr Jasiukajtis  */
72*5b2ba9d3SPiotr Jasiukajtis #define	XTOI(E, I)	\
73*5b2ba9d3SPiotr Jasiukajtis 		I = ((E[2]<<16) | (0xffff & (E[1]>>15)))
74*5b2ba9d3SPiotr Jasiukajtis 
75*5b2ba9d3SPiotr Jasiukajtis #else
76*5b2ba9d3SPiotr Jasiukajtis #error Unknown architecture
77*5b2ba9d3SPiotr Jasiukajtis #endif
78*5b2ba9d3SPiotr Jasiukajtis 
79*5b2ba9d3SPiotr Jasiukajtis #endif	/* _LIBM_MACROS_H */
80