xref: /titanic_41/usr/src/lib/libc/port/fp/fpparts.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate  * Macros to pull apart parts of single and  double precision
35*7c478bd9Sstevel@tonic-gate  * floating point numbers in IEEE format
36*7c478bd9Sstevel@tonic-gate  * Be sure to include /usr/include/values.h before including
37*7c478bd9Sstevel@tonic-gate  * this file to get the required definition of _IEEE
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #if _IEEE
41*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
42*7c478bd9Sstevel@tonic-gate /* byte order with high order bits at lowest address */
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate /* double precision */
45*7c478bd9Sstevel@tonic-gate typedef  union {
46*7c478bd9Sstevel@tonic-gate 	struct {
47*7c478bd9Sstevel@tonic-gate 		unsigned  sign	:1;
48*7c478bd9Sstevel@tonic-gate 		unsigned  exp	:11;
49*7c478bd9Sstevel@tonic-gate 		unsigned  hi	:20;
50*7c478bd9Sstevel@tonic-gate 		unsigned  lo	:32;
51*7c478bd9Sstevel@tonic-gate 	} fparts;
52*7c478bd9Sstevel@tonic-gate 	struct {
53*7c478bd9Sstevel@tonic-gate 		unsigned  sign	:1;
54*7c478bd9Sstevel@tonic-gate 		unsigned  exp	:11;
55*7c478bd9Sstevel@tonic-gate 		unsigned  qnan_bit	:1;
56*7c478bd9Sstevel@tonic-gate 		unsigned  hi	:19;
57*7c478bd9Sstevel@tonic-gate 		unsigned  lo	:32;
58*7c478bd9Sstevel@tonic-gate 	} nparts;
59*7c478bd9Sstevel@tonic-gate 	struct {
60*7c478bd9Sstevel@tonic-gate 		unsigned hi;
61*7c478bd9Sstevel@tonic-gate 		unsigned lo;
62*7c478bd9Sstevel@tonic-gate 	} fwords;
63*7c478bd9Sstevel@tonic-gate 	double	d;
64*7c478bd9Sstevel@tonic-gate } _dval;
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate /* single precision */
67*7c478bd9Sstevel@tonic-gate typedef  union {
68*7c478bd9Sstevel@tonic-gate 	struct {
69*7c478bd9Sstevel@tonic-gate 		unsigned sign	:1;
70*7c478bd9Sstevel@tonic-gate 		unsigned exp	:8;
71*7c478bd9Sstevel@tonic-gate 		unsigned fract	:23;
72*7c478bd9Sstevel@tonic-gate 	} fparts;
73*7c478bd9Sstevel@tonic-gate 	struct {
74*7c478bd9Sstevel@tonic-gate 		unsigned sign	:1;
75*7c478bd9Sstevel@tonic-gate 		unsigned exp	:8;
76*7c478bd9Sstevel@tonic-gate 		unsigned qnan_bit	:1;
77*7c478bd9Sstevel@tonic-gate 		unsigned fract	:22;
78*7c478bd9Sstevel@tonic-gate 	} nparts;
79*7c478bd9Sstevel@tonic-gate 	unsigned long	fword;
80*7c478bd9Sstevel@tonic-gate 	float	f;
81*7c478bd9Sstevel@tonic-gate } _fval;
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate #elif defined(__i386) || defined(__amd64)
85*7c478bd9Sstevel@tonic-gate /* byte order with low order bits at lowest address */
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate /* double precision */
88*7c478bd9Sstevel@tonic-gate typedef  union {
89*7c478bd9Sstevel@tonic-gate 	struct {
90*7c478bd9Sstevel@tonic-gate 		unsigned  lo	:32;
91*7c478bd9Sstevel@tonic-gate 		unsigned  hi	:20;
92*7c478bd9Sstevel@tonic-gate 		unsigned  exp	:11;
93*7c478bd9Sstevel@tonic-gate 		unsigned  sign	:1;
94*7c478bd9Sstevel@tonic-gate 	} fparts;
95*7c478bd9Sstevel@tonic-gate 	struct {
96*7c478bd9Sstevel@tonic-gate 		unsigned  lo	:32;
97*7c478bd9Sstevel@tonic-gate 		unsigned  hi	:19;
98*7c478bd9Sstevel@tonic-gate 		unsigned  qnan_bit	:1;
99*7c478bd9Sstevel@tonic-gate 		unsigned  exp	:11;
100*7c478bd9Sstevel@tonic-gate 		unsigned  sign	:1;
101*7c478bd9Sstevel@tonic-gate 	} nparts;
102*7c478bd9Sstevel@tonic-gate 	struct {
103*7c478bd9Sstevel@tonic-gate 		unsigned  lo	:32;
104*7c478bd9Sstevel@tonic-gate 		unsigned  hi	:32;
105*7c478bd9Sstevel@tonic-gate 	} fwords;
106*7c478bd9Sstevel@tonic-gate 	double	d;
107*7c478bd9Sstevel@tonic-gate } _dval;
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate /* single precision */
110*7c478bd9Sstevel@tonic-gate typedef  union {
111*7c478bd9Sstevel@tonic-gate 	struct {
112*7c478bd9Sstevel@tonic-gate 		unsigned fract	:23;
113*7c478bd9Sstevel@tonic-gate 		unsigned exp	:8;
114*7c478bd9Sstevel@tonic-gate 		unsigned sign	:1;
115*7c478bd9Sstevel@tonic-gate 	} fparts;
116*7c478bd9Sstevel@tonic-gate 	struct {
117*7c478bd9Sstevel@tonic-gate 		unsigned fract	:22;
118*7c478bd9Sstevel@tonic-gate 		unsigned qnan_bit	:1;
119*7c478bd9Sstevel@tonic-gate 		unsigned exp	:8;
120*7c478bd9Sstevel@tonic-gate 		unsigned sign	:1;
121*7c478bd9Sstevel@tonic-gate 	} nparts;
122*7c478bd9Sstevel@tonic-gate 	unsigned long	fword;
123*7c478bd9Sstevel@tonic-gate 	float	f;
124*7c478bd9Sstevel@tonic-gate } _fval;
125*7c478bd9Sstevel@tonic-gate #endif
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate /* parts of a double precision floating point number */
128*7c478bd9Sstevel@tonic-gate #define	SIGNBIT(X)	(((_dval *)&(X))->fparts.sign)
129*7c478bd9Sstevel@tonic-gate #define	EXPONENT(X)	(((_dval *)&(X))->fparts.exp)
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate #define	HIFRACTION(X)	(((_dval *)&(X))->fparts.hi)
132*7c478bd9Sstevel@tonic-gate #define	LOFRACTION(X)	(((_dval *)&(X))->fparts.lo)
133*7c478bd9Sstevel@tonic-gate #define	QNANBIT(X)	(((_dval *)&(X))->nparts.qnan_bit)
134*7c478bd9Sstevel@tonic-gate #define	HIWORD(X)	(((_dval *)&(X))->fwords.hi)
135*7c478bd9Sstevel@tonic-gate #define	LOWORD(X)	(((_dval *)&(X))->fwords.lo)
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate #define	MAXEXP	0x7ff /* maximum exponent of double */
138*7c478bd9Sstevel@tonic-gate #define	ISMAXEXP(X)	((EXPONENT(X)) == MAXEXP)
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate /* macros used to create quiet NaNs as return values */
141*7c478bd9Sstevel@tonic-gate #define	SETQNAN(X)	((((_dval *)&(X))->nparts.qnan_bit) = 0x1)
142*7c478bd9Sstevel@tonic-gate #define	HIQNAN(X)	((HIWORD(X)) = 0x7ff80000)
143*7c478bd9Sstevel@tonic-gate #define	LOQNAN(X)	((((_dval *)&(X))->fwords.lo) = 0x0)
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate /* macros used to extract parts of single precision values */
146*7c478bd9Sstevel@tonic-gate #define	FSIGNBIT(X)	(((_fval *)&(X))->fparts.sign)
147*7c478bd9Sstevel@tonic-gate #define	FEXPONENT(X)	(((_fval *)&(X))->fparts.exp)
148*7c478bd9Sstevel@tonic-gate #define	FFRACTION(X)	(((_fval *)&(X))->fparts.fract)
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate #define	FWORD(X)	(((_fval *)&(X))->fword)
151*7c478bd9Sstevel@tonic-gate #define	FQNANBIT(X)	(((_fval *)&(X))->nparts.qnan_bit)
152*7c478bd9Sstevel@tonic-gate #define	MAXEXPF	255 /* maximum exponent of single */
153*7c478bd9Sstevel@tonic-gate #define	FISMAXEXP(X)	((FEXPONENT(X)) == MAXEXPF)
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate #endif  /* _IEEE */
156