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