xref: /illumos-gate/usr/src/lib/libc/sparc/fp/quad.h (revision 1da57d55)
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 (c) 1994-1997, by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _QUAD_H
28*7c478bd9Sstevel@tonic-gate #define	_QUAD_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
31*7c478bd9Sstevel@tonic-gate extern "C" {
32*7c478bd9Sstevel@tonic-gate #endif
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate /*
35*7c478bd9Sstevel@tonic-gate  * Common definitions for quadruple precision emulation routines
36*7c478bd9Sstevel@tonic-gate  * (SPARC only)
37*7c478bd9Sstevel@tonic-gate  */
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate /* macros to simplify dealing with the diferences between V8 and V9 */
40*7c478bd9Sstevel@tonic-gate #ifdef __sparcv9
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #define	Z		(*pz)
43*7c478bd9Sstevel@tonic-gate #define	QUAD_RETURN(x)	return
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #else
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate #define	Z		z
48*7c478bd9Sstevel@tonic-gate #define	QUAD_RETURN(x)	return (x)
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #endif
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate /* fsr definitions */
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate /* current exception bits */
55*7c478bd9Sstevel@tonic-gate #define	FSR_NXC		0x1
56*7c478bd9Sstevel@tonic-gate #define	FSR_DZC		0x2
57*7c478bd9Sstevel@tonic-gate #define	FSR_UFC		0x4
58*7c478bd9Sstevel@tonic-gate #define	FSR_OFC		0x8
59*7c478bd9Sstevel@tonic-gate #define	FSR_NVC		0x10
60*7c478bd9Sstevel@tonic-gate #define	FSR_CEXC	0x1f	/* mask for all cexc bits */
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate /* accrued exception bits */
63*7c478bd9Sstevel@tonic-gate #define	FSR_NXA		0x20
64*7c478bd9Sstevel@tonic-gate #define	FSR_DZA		0x40
65*7c478bd9Sstevel@tonic-gate #define	FSR_UFA		0x80
66*7c478bd9Sstevel@tonic-gate #define	FSR_OFA		0x100
67*7c478bd9Sstevel@tonic-gate #define	FSR_NVA		0x200
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate /* trap enable bits */
70*7c478bd9Sstevel@tonic-gate #define	FSR_NXM		0x00800000
71*7c478bd9Sstevel@tonic-gate #define	FSR_DZM		0x01000000
72*7c478bd9Sstevel@tonic-gate #define	FSR_UFM		0x02000000
73*7c478bd9Sstevel@tonic-gate #define	FSR_OFM		0x04000000
74*7c478bd9Sstevel@tonic-gate #define	FSR_NVM		0x08000000
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate /* rounding directions (shifted) */
77*7c478bd9Sstevel@tonic-gate #define	FSR_RN		0
78*7c478bd9Sstevel@tonic-gate #define	FSR_RZ		1
79*7c478bd9Sstevel@tonic-gate #define	FSR_RP		2
80*7c478bd9Sstevel@tonic-gate #define	FSR_RM		3
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate /*
83*7c478bd9Sstevel@tonic-gate  * in struct longdouble, msw implicitly consists of
84*7c478bd9Sstevel@tonic-gate  *	unsigned short	sign:1;
85*7c478bd9Sstevel@tonic-gate  *	unsigned short	exponent:15;
86*7c478bd9Sstevel@tonic-gate  *	unsigned short	frac1:16;
87*7c478bd9Sstevel@tonic-gate  */
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate /* structure used to access words within a quad */
90*7c478bd9Sstevel@tonic-gate union longdouble {
91*7c478bd9Sstevel@tonic-gate 	struct {
92*7c478bd9Sstevel@tonic-gate 		unsigned int	msw;
93*7c478bd9Sstevel@tonic-gate 		unsigned int	frac2;
94*7c478bd9Sstevel@tonic-gate 		unsigned int	frac3;
95*7c478bd9Sstevel@tonic-gate 		unsigned int	frac4;
96*7c478bd9Sstevel@tonic-gate 	} l;
97*7c478bd9Sstevel@tonic-gate 	long double	d;	/* unused; just guarantees correct alignment */
98*7c478bd9Sstevel@tonic-gate };
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate /* macros used internally for readability */
101*7c478bd9Sstevel@tonic-gate #define	QUAD_ISNAN(x) \
102*7c478bd9Sstevel@tonic-gate 	(((x).l.msw & 0x7fff0000) == 0x7fff0000 && \
103*7c478bd9Sstevel@tonic-gate 	(((x).l.msw & 0xffff) | (x).l.frac2 | (x).l.frac3 | (x).l.frac4))
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate #define	QUAD_ISZERO(x) \
106*7c478bd9Sstevel@tonic-gate 	(!(((x).l.msw & 0x7fffffff) | (x).l.frac2 | (x).l.frac3 | (x).l.frac4))
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate /* structure used to access words within a double */
109*7c478bd9Sstevel@tonic-gate union xdouble {
110*7c478bd9Sstevel@tonic-gate 	struct {
111*7c478bd9Sstevel@tonic-gate 		unsigned int	hi;
112*7c478bd9Sstevel@tonic-gate 		unsigned int	lo;
113*7c478bd9Sstevel@tonic-gate 	} l;
114*7c478bd9Sstevel@tonic-gate 	double			d;
115*7c478bd9Sstevel@tonic-gate };
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate /* relationships returned by _Q_cmp and _Q_cmpe */
118*7c478bd9Sstevel@tonic-gate enum fcc_type {
119*7c478bd9Sstevel@tonic-gate 	fcc_equal	= 0,
120*7c478bd9Sstevel@tonic-gate 	fcc_less	= 1,
121*7c478bd9Sstevel@tonic-gate 	fcc_greater	= 2,
122*7c478bd9Sstevel@tonic-gate 	fcc_unordered	= 3
123*7c478bd9Sstevel@tonic-gate };
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate /* internal routines */
126*7c478bd9Sstevel@tonic-gate extern void __quad_mag_add(const union longdouble *,
127*7c478bd9Sstevel@tonic-gate 	const union longdouble *, union longdouble *, unsigned int *);
128*7c478bd9Sstevel@tonic-gate extern void __quad_mag_sub(const union longdouble *,
129*7c478bd9Sstevel@tonic-gate 	const union longdouble *, union longdouble *, unsigned int *);
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate /* inline templates */
132*7c478bd9Sstevel@tonic-gate extern void __quad_getfsrp(unsigned int *);
133*7c478bd9Sstevel@tonic-gate extern void __quad_setfsrp(const unsigned int *);
134*7c478bd9Sstevel@tonic-gate extern double __quad_dp_sqrt(double *);
135*7c478bd9Sstevel@tonic-gate extern void __quad_faddq(const union longdouble *, const union longdouble *,
136*7c478bd9Sstevel@tonic-gate 	union longdouble *);
137*7c478bd9Sstevel@tonic-gate extern void __quad_fsubq(const union longdouble *, const union longdouble *,
138*7c478bd9Sstevel@tonic-gate 	union longdouble *);
139*7c478bd9Sstevel@tonic-gate extern void __quad_fmulq(const union longdouble *, const union longdouble *,
140*7c478bd9Sstevel@tonic-gate 	union longdouble *);
141*7c478bd9Sstevel@tonic-gate extern void __quad_fdivq(const union longdouble *, const union longdouble *,
142*7c478bd9Sstevel@tonic-gate 	union longdouble *);
143*7c478bd9Sstevel@tonic-gate extern void __quad_fsqrtq(const union longdouble *, union longdouble *);
144*7c478bd9Sstevel@tonic-gate extern void __quad_fcmpq(const union longdouble *, const union longdouble *,
145*7c478bd9Sstevel@tonic-gate 	unsigned int *);
146*7c478bd9Sstevel@tonic-gate extern void __quad_fcmpeq(const union longdouble *, const union longdouble *,
147*7c478bd9Sstevel@tonic-gate 	unsigned int *);
148*7c478bd9Sstevel@tonic-gate extern void __quad_fstoq(const float *, union longdouble *);
149*7c478bd9Sstevel@tonic-gate extern void __quad_fdtoq(const double *, union longdouble *);
150*7c478bd9Sstevel@tonic-gate extern void __quad_fqtoi(const union longdouble *, int *);
151*7c478bd9Sstevel@tonic-gate extern void __quad_fqtos(const union longdouble *, float *);
152*7c478bd9Sstevel@tonic-gate extern void __quad_fqtod(const union longdouble *, double *);
153*7c478bd9Sstevel@tonic-gate #ifdef __sparcv9
154*7c478bd9Sstevel@tonic-gate extern void __quad_fqtox(const union longdouble *, long *);
155*7c478bd9Sstevel@tonic-gate #endif
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
158*7c478bd9Sstevel@tonic-gate }
159*7c478bd9Sstevel@tonic-gate #endif
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate #endif	/* _QUAD_H */
162