1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 1994-1997, by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate * All rights reserved.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include "quad.h"
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate #ifdef __sparcv9
32*0Sstevel@tonic-gate #define _Q_feq _Qp_feq
33*0Sstevel@tonic-gate #define _Q_fne _Qp_fne
34*0Sstevel@tonic-gate #define _Q_flt _Qp_flt
35*0Sstevel@tonic-gate #define _Q_fle _Qp_fle
36*0Sstevel@tonic-gate #define _Q_fgt _Qp_fgt
37*0Sstevel@tonic-gate #define _Q_fge _Qp_fge
38*0Sstevel@tonic-gate #endif
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate /*
41*0Sstevel@tonic-gate * _Q_feq(x, y) returns nonzero if *x == *y and zero otherwise.
42*0Sstevel@tonic-gate * If either *x or *y is a signaling NaN, the invalid operation
43*0Sstevel@tonic-gate * exception is raised.
44*0Sstevel@tonic-gate */
45*0Sstevel@tonic-gate int
_Q_feq(const union longdouble * x,const union longdouble * y)46*0Sstevel@tonic-gate _Q_feq(const union longdouble *x, const union longdouble *y)
47*0Sstevel@tonic-gate {
48*0Sstevel@tonic-gate unsigned int fsr;
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gate if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
51*0Sstevel@tonic-gate if ((QUAD_ISNAN(*x) && !(x->l.msw & 0x8000)) ||
52*0Sstevel@tonic-gate (QUAD_ISNAN(*y) && !(y->l.msw & 0x8000))) {
53*0Sstevel@tonic-gate /* snan, signal invalid */
54*0Sstevel@tonic-gate __quad_getfsrp(&fsr);
55*0Sstevel@tonic-gate if (fsr & FSR_NVM) {
56*0Sstevel@tonic-gate __quad_fcmpq(x, y, &fsr);
57*0Sstevel@tonic-gate return (((fsr >> 10) & 3) == fcc_equal);
58*0Sstevel@tonic-gate } else {
59*0Sstevel@tonic-gate fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
60*0Sstevel@tonic-gate __quad_setfsrp(&fsr);
61*0Sstevel@tonic-gate }
62*0Sstevel@tonic-gate }
63*0Sstevel@tonic-gate return (0);
64*0Sstevel@tonic-gate }
65*0Sstevel@tonic-gate if (QUAD_ISZERO(*x) && QUAD_ISZERO(*y))
66*0Sstevel@tonic-gate return (1);
67*0Sstevel@tonic-gate return ((x->l.msw ^ y->l.msw | x->l.frac2 ^ y->l.frac2 |
68*0Sstevel@tonic-gate x->l.frac3 ^ y->l.frac3 | x->l.frac4 ^ y->l.frac4) == 0);
69*0Sstevel@tonic-gate }
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gate /*
72*0Sstevel@tonic-gate * _Q_fne(x, y) returns nonzero if *x != *y and zero otherwise.
73*0Sstevel@tonic-gate * If either *x or *y is a signaling NaN, the invalid operation
74*0Sstevel@tonic-gate * exception is raised.
75*0Sstevel@tonic-gate */
76*0Sstevel@tonic-gate int
_Q_fne(const union longdouble * x,const union longdouble * y)77*0Sstevel@tonic-gate _Q_fne(const union longdouble *x, const union longdouble *y)
78*0Sstevel@tonic-gate {
79*0Sstevel@tonic-gate unsigned int fsr;
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
82*0Sstevel@tonic-gate if ((QUAD_ISNAN(*x) && !(x->l.msw & 0x8000)) ||
83*0Sstevel@tonic-gate (QUAD_ISNAN(*y) && !(y->l.msw & 0x8000))) {
84*0Sstevel@tonic-gate /* snan, signal invalid */
85*0Sstevel@tonic-gate __quad_getfsrp(&fsr);
86*0Sstevel@tonic-gate if (fsr & FSR_NVM) {
87*0Sstevel@tonic-gate __quad_fcmpq(x, y, &fsr);
88*0Sstevel@tonic-gate return (((fsr >> 10) & 3) != fcc_equal);
89*0Sstevel@tonic-gate } else {
90*0Sstevel@tonic-gate fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
91*0Sstevel@tonic-gate __quad_setfsrp(&fsr);
92*0Sstevel@tonic-gate }
93*0Sstevel@tonic-gate }
94*0Sstevel@tonic-gate return (1); /* x != y is TRUE if x or y is NaN */
95*0Sstevel@tonic-gate }
96*0Sstevel@tonic-gate if (QUAD_ISZERO(*x) && QUAD_ISZERO(*y))
97*0Sstevel@tonic-gate return (0);
98*0Sstevel@tonic-gate return ((x->l.msw ^ y->l.msw | x->l.frac2 ^ y->l.frac2 |
99*0Sstevel@tonic-gate x->l.frac3 ^ y->l.frac3 | x->l.frac4 ^ y->l.frac4) != 0);
100*0Sstevel@tonic-gate }
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gate /*
103*0Sstevel@tonic-gate * _Q_flt(x, y) returns nonzero if *x < *y and zero otherwise. If
104*0Sstevel@tonic-gate * either *x or *y is NaN, the invalid operation exception is raised.
105*0Sstevel@tonic-gate */
106*0Sstevel@tonic-gate int
_Q_flt(const union longdouble * x,const union longdouble * y)107*0Sstevel@tonic-gate _Q_flt(const union longdouble *x, const union longdouble *y)
108*0Sstevel@tonic-gate {
109*0Sstevel@tonic-gate unsigned int xm, ym, fsr;
110*0Sstevel@tonic-gate
111*0Sstevel@tonic-gate if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
112*0Sstevel@tonic-gate /* nan, signal invalid */
113*0Sstevel@tonic-gate __quad_getfsrp(&fsr);
114*0Sstevel@tonic-gate if (fsr & FSR_NVM) {
115*0Sstevel@tonic-gate __quad_fcmpeq(x, y, &fsr);
116*0Sstevel@tonic-gate return (((fsr >> 10) & 3) == fcc_less);
117*0Sstevel@tonic-gate } else {
118*0Sstevel@tonic-gate fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
119*0Sstevel@tonic-gate __quad_setfsrp(&fsr);
120*0Sstevel@tonic-gate }
121*0Sstevel@tonic-gate return (0);
122*0Sstevel@tonic-gate }
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate /* ignore sign of zero */
125*0Sstevel@tonic-gate xm = x->l.msw;
126*0Sstevel@tonic-gate if (QUAD_ISZERO(*x))
127*0Sstevel@tonic-gate xm &= 0x7fffffff;
128*0Sstevel@tonic-gate ym = y->l.msw;
129*0Sstevel@tonic-gate if (QUAD_ISZERO(*y))
130*0Sstevel@tonic-gate ym &= 0x7fffffff;
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gate if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */
133*0Sstevel@tonic-gate return ((ym & 0x80000000) == 0);
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate if (xm & 0x80000000) {
136*0Sstevel@tonic-gate return (xm > ym || xm == ym && (x->l.frac2 > y->l.frac2 ||
137*0Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 > y->l.frac3 ||
138*0Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 > y->l.frac4)));
139*0Sstevel@tonic-gate }
140*0Sstevel@tonic-gate return (xm < ym || xm == ym && (x->l.frac2 < y->l.frac2 ||
141*0Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 < y->l.frac3 ||
142*0Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 < y->l.frac4)));
143*0Sstevel@tonic-gate }
144*0Sstevel@tonic-gate
145*0Sstevel@tonic-gate /*
146*0Sstevel@tonic-gate * _Q_fle(x, y) returns nonzero if *x <= *y and zero otherwise. If
147*0Sstevel@tonic-gate * either *x or *y is NaN, the invalid operation exception is raised.
148*0Sstevel@tonic-gate */
149*0Sstevel@tonic-gate int
_Q_fle(const union longdouble * x,const union longdouble * y)150*0Sstevel@tonic-gate _Q_fle(const union longdouble *x, const union longdouble *y)
151*0Sstevel@tonic-gate {
152*0Sstevel@tonic-gate unsigned int xm, ym, fsr;
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
155*0Sstevel@tonic-gate /* nan, signal invalid */
156*0Sstevel@tonic-gate __quad_getfsrp(&fsr);
157*0Sstevel@tonic-gate if (fsr & FSR_NVM) {
158*0Sstevel@tonic-gate __quad_fcmpeq(x, y, &fsr);
159*0Sstevel@tonic-gate fsr = (fsr >> 10) & 3;
160*0Sstevel@tonic-gate return (fsr == fcc_less || fsr == fcc_equal);
161*0Sstevel@tonic-gate } else {
162*0Sstevel@tonic-gate fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
163*0Sstevel@tonic-gate __quad_setfsrp(&fsr);
164*0Sstevel@tonic-gate }
165*0Sstevel@tonic-gate return (0);
166*0Sstevel@tonic-gate }
167*0Sstevel@tonic-gate
168*0Sstevel@tonic-gate /* ignore sign of zero */
169*0Sstevel@tonic-gate xm = x->l.msw;
170*0Sstevel@tonic-gate if (QUAD_ISZERO(*x))
171*0Sstevel@tonic-gate xm &= 0x7fffffff;
172*0Sstevel@tonic-gate ym = y->l.msw;
173*0Sstevel@tonic-gate if (QUAD_ISZERO(*y))
174*0Sstevel@tonic-gate ym &= 0x7fffffff;
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */
177*0Sstevel@tonic-gate return ((ym & 0x80000000) == 0);
178*0Sstevel@tonic-gate
179*0Sstevel@tonic-gate if (xm & 0x80000000) {
180*0Sstevel@tonic-gate return (xm > ym || xm == ym && (x->l.frac2 > y->l.frac2 ||
181*0Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 > y->l.frac3 ||
182*0Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 >= y->l.frac4)));
183*0Sstevel@tonic-gate }
184*0Sstevel@tonic-gate return (xm < ym || xm == ym && (x->l.frac2 < y->l.frac2 ||
185*0Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 < y->l.frac3 ||
186*0Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 <= y->l.frac4)));
187*0Sstevel@tonic-gate }
188*0Sstevel@tonic-gate
189*0Sstevel@tonic-gate /*
190*0Sstevel@tonic-gate * _Q_fgt(x, y) returns nonzero if *x > *y and zero otherwise. If
191*0Sstevel@tonic-gate * either *x or *y is NaN, the invalid operation exception is raised.
192*0Sstevel@tonic-gate */
193*0Sstevel@tonic-gate int
_Q_fgt(const union longdouble * x,const union longdouble * y)194*0Sstevel@tonic-gate _Q_fgt(const union longdouble *x, const union longdouble *y)
195*0Sstevel@tonic-gate {
196*0Sstevel@tonic-gate unsigned int xm, ym, fsr;
197*0Sstevel@tonic-gate
198*0Sstevel@tonic-gate if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
199*0Sstevel@tonic-gate /* nan, signal invalid */
200*0Sstevel@tonic-gate __quad_getfsrp(&fsr);
201*0Sstevel@tonic-gate if (fsr & FSR_NVM) {
202*0Sstevel@tonic-gate __quad_fcmpeq(x, y, &fsr);
203*0Sstevel@tonic-gate return (((fsr >> 10) & 3) == fcc_greater);
204*0Sstevel@tonic-gate } else {
205*0Sstevel@tonic-gate fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
206*0Sstevel@tonic-gate __quad_setfsrp(&fsr);
207*0Sstevel@tonic-gate }
208*0Sstevel@tonic-gate return (0);
209*0Sstevel@tonic-gate }
210*0Sstevel@tonic-gate
211*0Sstevel@tonic-gate /* ignore sign of zero */
212*0Sstevel@tonic-gate xm = x->l.msw;
213*0Sstevel@tonic-gate if (QUAD_ISZERO(*x))
214*0Sstevel@tonic-gate xm &= 0x7fffffff;
215*0Sstevel@tonic-gate ym = y->l.msw;
216*0Sstevel@tonic-gate if (QUAD_ISZERO(*y))
217*0Sstevel@tonic-gate ym &= 0x7fffffff;
218*0Sstevel@tonic-gate
219*0Sstevel@tonic-gate if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */
220*0Sstevel@tonic-gate return ((ym & 0x80000000) != 0);
221*0Sstevel@tonic-gate
222*0Sstevel@tonic-gate if (xm & 0x80000000) {
223*0Sstevel@tonic-gate return (xm < ym || xm == ym && (x->l.frac2 < y->l.frac2 ||
224*0Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 < y->l.frac3 ||
225*0Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 < y->l.frac4)));
226*0Sstevel@tonic-gate }
227*0Sstevel@tonic-gate return (xm > ym || xm == ym && (x->l.frac2 > y->l.frac2 ||
228*0Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 > y->l.frac3 ||
229*0Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 > y->l.frac4)));
230*0Sstevel@tonic-gate }
231*0Sstevel@tonic-gate
232*0Sstevel@tonic-gate /*
233*0Sstevel@tonic-gate * _Q_fge(x, y) returns nonzero if *x >= *y and zero otherwise. If
234*0Sstevel@tonic-gate * either *x or *y is NaN, the invalid operation exception is raised.
235*0Sstevel@tonic-gate */
236*0Sstevel@tonic-gate int
_Q_fge(const union longdouble * x,const union longdouble * y)237*0Sstevel@tonic-gate _Q_fge(const union longdouble *x, const union longdouble *y)
238*0Sstevel@tonic-gate {
239*0Sstevel@tonic-gate unsigned int xm, ym, fsr;
240*0Sstevel@tonic-gate
241*0Sstevel@tonic-gate if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
242*0Sstevel@tonic-gate /* nan, signal invalid */
243*0Sstevel@tonic-gate __quad_getfsrp(&fsr);
244*0Sstevel@tonic-gate if (fsr & FSR_NVM) {
245*0Sstevel@tonic-gate __quad_fcmpeq(x, y, &fsr);
246*0Sstevel@tonic-gate fsr = (fsr >> 10) & 3;
247*0Sstevel@tonic-gate return (fsr == fcc_greater || fsr == fcc_equal);
248*0Sstevel@tonic-gate } else {
249*0Sstevel@tonic-gate fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
250*0Sstevel@tonic-gate __quad_setfsrp(&fsr);
251*0Sstevel@tonic-gate }
252*0Sstevel@tonic-gate return (0);
253*0Sstevel@tonic-gate }
254*0Sstevel@tonic-gate
255*0Sstevel@tonic-gate /* ignore sign of zero */
256*0Sstevel@tonic-gate xm = x->l.msw;
257*0Sstevel@tonic-gate if (QUAD_ISZERO(*x))
258*0Sstevel@tonic-gate xm &= 0x7fffffff;
259*0Sstevel@tonic-gate ym = y->l.msw;
260*0Sstevel@tonic-gate if (QUAD_ISZERO(*y))
261*0Sstevel@tonic-gate ym &= 0x7fffffff;
262*0Sstevel@tonic-gate
263*0Sstevel@tonic-gate if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */
264*0Sstevel@tonic-gate return ((ym & 0x80000000) != 0);
265*0Sstevel@tonic-gate
266*0Sstevel@tonic-gate if (xm & 0x80000000) {
267*0Sstevel@tonic-gate return (xm < ym || xm == ym && (x->l.frac2 < y->l.frac2 ||
268*0Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 < y->l.frac3 ||
269*0Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 <= y->l.frac4)));
270*0Sstevel@tonic-gate }
271*0Sstevel@tonic-gate return (xm > ym || xm == ym && (x->l.frac2 > y->l.frac2 ||
272*0Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 > y->l.frac3 ||
273*0Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 >= y->l.frac4)));
274*0Sstevel@tonic-gate }
275