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 #include "quad.h"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate #ifdef __sparcv9
30*7c478bd9Sstevel@tonic-gate #define _Q_feq _Qp_feq
31*7c478bd9Sstevel@tonic-gate #define _Q_fne _Qp_fne
32*7c478bd9Sstevel@tonic-gate #define _Q_flt _Qp_flt
33*7c478bd9Sstevel@tonic-gate #define _Q_fle _Qp_fle
34*7c478bd9Sstevel@tonic-gate #define _Q_fgt _Qp_fgt
35*7c478bd9Sstevel@tonic-gate #define _Q_fge _Qp_fge
36*7c478bd9Sstevel@tonic-gate #endif
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate /*
39*7c478bd9Sstevel@tonic-gate * _Q_feq(x, y) returns nonzero if *x == *y and zero otherwise.
40*7c478bd9Sstevel@tonic-gate * If either *x or *y is a signaling NaN, the invalid operation
41*7c478bd9Sstevel@tonic-gate * exception is raised.
42*7c478bd9Sstevel@tonic-gate */
43*7c478bd9Sstevel@tonic-gate int
_Q_feq(const union longdouble * x,const union longdouble * y)44*7c478bd9Sstevel@tonic-gate _Q_feq(const union longdouble *x, const union longdouble *y)
45*7c478bd9Sstevel@tonic-gate {
46*7c478bd9Sstevel@tonic-gate unsigned int fsr;
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gate if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
49*7c478bd9Sstevel@tonic-gate if ((QUAD_ISNAN(*x) && !(x->l.msw & 0x8000)) ||
50*7c478bd9Sstevel@tonic-gate (QUAD_ISNAN(*y) && !(y->l.msw & 0x8000))) {
51*7c478bd9Sstevel@tonic-gate /* snan, signal invalid */
52*7c478bd9Sstevel@tonic-gate __quad_getfsrp(&fsr);
53*7c478bd9Sstevel@tonic-gate if (fsr & FSR_NVM) {
54*7c478bd9Sstevel@tonic-gate __quad_fcmpq(x, y, &fsr);
55*7c478bd9Sstevel@tonic-gate return (((fsr >> 10) & 3) == fcc_equal);
56*7c478bd9Sstevel@tonic-gate } else {
57*7c478bd9Sstevel@tonic-gate fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
58*7c478bd9Sstevel@tonic-gate __quad_setfsrp(&fsr);
59*7c478bd9Sstevel@tonic-gate }
60*7c478bd9Sstevel@tonic-gate }
61*7c478bd9Sstevel@tonic-gate return (0);
62*7c478bd9Sstevel@tonic-gate }
63*7c478bd9Sstevel@tonic-gate if (QUAD_ISZERO(*x) && QUAD_ISZERO(*y))
64*7c478bd9Sstevel@tonic-gate return (1);
65*7c478bd9Sstevel@tonic-gate return ((x->l.msw ^ y->l.msw | x->l.frac2 ^ y->l.frac2 |
66*7c478bd9Sstevel@tonic-gate x->l.frac3 ^ y->l.frac3 | x->l.frac4 ^ y->l.frac4) == 0);
67*7c478bd9Sstevel@tonic-gate }
68*7c478bd9Sstevel@tonic-gate
69*7c478bd9Sstevel@tonic-gate /*
70*7c478bd9Sstevel@tonic-gate * _Q_fne(x, y) returns nonzero if *x != *y and zero otherwise.
71*7c478bd9Sstevel@tonic-gate * If either *x or *y is a signaling NaN, the invalid operation
72*7c478bd9Sstevel@tonic-gate * exception is raised.
73*7c478bd9Sstevel@tonic-gate */
74*7c478bd9Sstevel@tonic-gate int
_Q_fne(const union longdouble * x,const union longdouble * y)75*7c478bd9Sstevel@tonic-gate _Q_fne(const union longdouble *x, const union longdouble *y)
76*7c478bd9Sstevel@tonic-gate {
77*7c478bd9Sstevel@tonic-gate unsigned int fsr;
78*7c478bd9Sstevel@tonic-gate
79*7c478bd9Sstevel@tonic-gate if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
80*7c478bd9Sstevel@tonic-gate if ((QUAD_ISNAN(*x) && !(x->l.msw & 0x8000)) ||
81*7c478bd9Sstevel@tonic-gate (QUAD_ISNAN(*y) && !(y->l.msw & 0x8000))) {
82*7c478bd9Sstevel@tonic-gate /* snan, signal invalid */
83*7c478bd9Sstevel@tonic-gate __quad_getfsrp(&fsr);
84*7c478bd9Sstevel@tonic-gate if (fsr & FSR_NVM) {
85*7c478bd9Sstevel@tonic-gate __quad_fcmpq(x, y, &fsr);
86*7c478bd9Sstevel@tonic-gate return (((fsr >> 10) & 3) != fcc_equal);
87*7c478bd9Sstevel@tonic-gate } else {
88*7c478bd9Sstevel@tonic-gate fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
89*7c478bd9Sstevel@tonic-gate __quad_setfsrp(&fsr);
90*7c478bd9Sstevel@tonic-gate }
91*7c478bd9Sstevel@tonic-gate }
92*7c478bd9Sstevel@tonic-gate return (1); /* x != y is TRUE if x or y is NaN */
93*7c478bd9Sstevel@tonic-gate }
94*7c478bd9Sstevel@tonic-gate if (QUAD_ISZERO(*x) && QUAD_ISZERO(*y))
95*7c478bd9Sstevel@tonic-gate return (0);
96*7c478bd9Sstevel@tonic-gate return ((x->l.msw ^ y->l.msw | x->l.frac2 ^ y->l.frac2 |
97*7c478bd9Sstevel@tonic-gate x->l.frac3 ^ y->l.frac3 | x->l.frac4 ^ y->l.frac4) != 0);
98*7c478bd9Sstevel@tonic-gate }
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate /*
101*7c478bd9Sstevel@tonic-gate * _Q_flt(x, y) returns nonzero if *x < *y and zero otherwise. If
102*7c478bd9Sstevel@tonic-gate * either *x or *y is NaN, the invalid operation exception is raised.
103*7c478bd9Sstevel@tonic-gate */
104*7c478bd9Sstevel@tonic-gate int
_Q_flt(const union longdouble * x,const union longdouble * y)105*7c478bd9Sstevel@tonic-gate _Q_flt(const union longdouble *x, const union longdouble *y)
106*7c478bd9Sstevel@tonic-gate {
107*7c478bd9Sstevel@tonic-gate unsigned int xm, ym, fsr;
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gate if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
110*7c478bd9Sstevel@tonic-gate /* nan, signal invalid */
111*7c478bd9Sstevel@tonic-gate __quad_getfsrp(&fsr);
112*7c478bd9Sstevel@tonic-gate if (fsr & FSR_NVM) {
113*7c478bd9Sstevel@tonic-gate __quad_fcmpeq(x, y, &fsr);
114*7c478bd9Sstevel@tonic-gate return (((fsr >> 10) & 3) == fcc_less);
115*7c478bd9Sstevel@tonic-gate } else {
116*7c478bd9Sstevel@tonic-gate fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
117*7c478bd9Sstevel@tonic-gate __quad_setfsrp(&fsr);
118*7c478bd9Sstevel@tonic-gate }
119*7c478bd9Sstevel@tonic-gate return (0);
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate /* ignore sign of zero */
123*7c478bd9Sstevel@tonic-gate xm = x->l.msw;
124*7c478bd9Sstevel@tonic-gate if (QUAD_ISZERO(*x))
125*7c478bd9Sstevel@tonic-gate xm &= 0x7fffffff;
126*7c478bd9Sstevel@tonic-gate ym = y->l.msw;
127*7c478bd9Sstevel@tonic-gate if (QUAD_ISZERO(*y))
128*7c478bd9Sstevel@tonic-gate ym &= 0x7fffffff;
129*7c478bd9Sstevel@tonic-gate
130*7c478bd9Sstevel@tonic-gate if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */
131*7c478bd9Sstevel@tonic-gate return ((ym & 0x80000000) == 0);
132*7c478bd9Sstevel@tonic-gate
133*7c478bd9Sstevel@tonic-gate if (xm & 0x80000000) {
134*7c478bd9Sstevel@tonic-gate return (xm > ym || xm == ym && (x->l.frac2 > y->l.frac2 ||
135*7c478bd9Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 > y->l.frac3 ||
136*7c478bd9Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 > y->l.frac4)));
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate return (xm < ym || xm == ym && (x->l.frac2 < y->l.frac2 ||
139*7c478bd9Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 < y->l.frac3 ||
140*7c478bd9Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 < y->l.frac4)));
141*7c478bd9Sstevel@tonic-gate }
142*7c478bd9Sstevel@tonic-gate
143*7c478bd9Sstevel@tonic-gate /*
144*7c478bd9Sstevel@tonic-gate * _Q_fle(x, y) returns nonzero if *x <= *y and zero otherwise. If
145*7c478bd9Sstevel@tonic-gate * either *x or *y is NaN, the invalid operation exception is raised.
146*7c478bd9Sstevel@tonic-gate */
147*7c478bd9Sstevel@tonic-gate int
_Q_fle(const union longdouble * x,const union longdouble * y)148*7c478bd9Sstevel@tonic-gate _Q_fle(const union longdouble *x, const union longdouble *y)
149*7c478bd9Sstevel@tonic-gate {
150*7c478bd9Sstevel@tonic-gate unsigned int xm, ym, fsr;
151*7c478bd9Sstevel@tonic-gate
152*7c478bd9Sstevel@tonic-gate if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
153*7c478bd9Sstevel@tonic-gate /* nan, signal invalid */
154*7c478bd9Sstevel@tonic-gate __quad_getfsrp(&fsr);
155*7c478bd9Sstevel@tonic-gate if (fsr & FSR_NVM) {
156*7c478bd9Sstevel@tonic-gate __quad_fcmpeq(x, y, &fsr);
157*7c478bd9Sstevel@tonic-gate fsr = (fsr >> 10) & 3;
158*7c478bd9Sstevel@tonic-gate return (fsr == fcc_less || fsr == fcc_equal);
159*7c478bd9Sstevel@tonic-gate } else {
160*7c478bd9Sstevel@tonic-gate fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
161*7c478bd9Sstevel@tonic-gate __quad_setfsrp(&fsr);
162*7c478bd9Sstevel@tonic-gate }
163*7c478bd9Sstevel@tonic-gate return (0);
164*7c478bd9Sstevel@tonic-gate }
165*7c478bd9Sstevel@tonic-gate
166*7c478bd9Sstevel@tonic-gate /* ignore sign of zero */
167*7c478bd9Sstevel@tonic-gate xm = x->l.msw;
168*7c478bd9Sstevel@tonic-gate if (QUAD_ISZERO(*x))
169*7c478bd9Sstevel@tonic-gate xm &= 0x7fffffff;
170*7c478bd9Sstevel@tonic-gate ym = y->l.msw;
171*7c478bd9Sstevel@tonic-gate if (QUAD_ISZERO(*y))
172*7c478bd9Sstevel@tonic-gate ym &= 0x7fffffff;
173*7c478bd9Sstevel@tonic-gate
174*7c478bd9Sstevel@tonic-gate if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */
175*7c478bd9Sstevel@tonic-gate return ((ym & 0x80000000) == 0);
176*7c478bd9Sstevel@tonic-gate
177*7c478bd9Sstevel@tonic-gate if (xm & 0x80000000) {
178*7c478bd9Sstevel@tonic-gate return (xm > ym || xm == ym && (x->l.frac2 > y->l.frac2 ||
179*7c478bd9Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 > y->l.frac3 ||
180*7c478bd9Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 >= y->l.frac4)));
181*7c478bd9Sstevel@tonic-gate }
182*7c478bd9Sstevel@tonic-gate return (xm < ym || xm == ym && (x->l.frac2 < y->l.frac2 ||
183*7c478bd9Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 < y->l.frac3 ||
184*7c478bd9Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 <= y->l.frac4)));
185*7c478bd9Sstevel@tonic-gate }
186*7c478bd9Sstevel@tonic-gate
187*7c478bd9Sstevel@tonic-gate /*
188*7c478bd9Sstevel@tonic-gate * _Q_fgt(x, y) returns nonzero if *x > *y and zero otherwise. If
189*7c478bd9Sstevel@tonic-gate * either *x or *y is NaN, the invalid operation exception is raised.
190*7c478bd9Sstevel@tonic-gate */
191*7c478bd9Sstevel@tonic-gate int
_Q_fgt(const union longdouble * x,const union longdouble * y)192*7c478bd9Sstevel@tonic-gate _Q_fgt(const union longdouble *x, const union longdouble *y)
193*7c478bd9Sstevel@tonic-gate {
194*7c478bd9Sstevel@tonic-gate unsigned int xm, ym, fsr;
195*7c478bd9Sstevel@tonic-gate
196*7c478bd9Sstevel@tonic-gate if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
197*7c478bd9Sstevel@tonic-gate /* nan, signal invalid */
198*7c478bd9Sstevel@tonic-gate __quad_getfsrp(&fsr);
199*7c478bd9Sstevel@tonic-gate if (fsr & FSR_NVM) {
200*7c478bd9Sstevel@tonic-gate __quad_fcmpeq(x, y, &fsr);
201*7c478bd9Sstevel@tonic-gate return (((fsr >> 10) & 3) == fcc_greater);
202*7c478bd9Sstevel@tonic-gate } else {
203*7c478bd9Sstevel@tonic-gate fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
204*7c478bd9Sstevel@tonic-gate __quad_setfsrp(&fsr);
205*7c478bd9Sstevel@tonic-gate }
206*7c478bd9Sstevel@tonic-gate return (0);
207*7c478bd9Sstevel@tonic-gate }
208*7c478bd9Sstevel@tonic-gate
209*7c478bd9Sstevel@tonic-gate /* ignore sign of zero */
210*7c478bd9Sstevel@tonic-gate xm = x->l.msw;
211*7c478bd9Sstevel@tonic-gate if (QUAD_ISZERO(*x))
212*7c478bd9Sstevel@tonic-gate xm &= 0x7fffffff;
213*7c478bd9Sstevel@tonic-gate ym = y->l.msw;
214*7c478bd9Sstevel@tonic-gate if (QUAD_ISZERO(*y))
215*7c478bd9Sstevel@tonic-gate ym &= 0x7fffffff;
216*7c478bd9Sstevel@tonic-gate
217*7c478bd9Sstevel@tonic-gate if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */
218*7c478bd9Sstevel@tonic-gate return ((ym & 0x80000000) != 0);
219*7c478bd9Sstevel@tonic-gate
220*7c478bd9Sstevel@tonic-gate if (xm & 0x80000000) {
221*7c478bd9Sstevel@tonic-gate return (xm < ym || xm == ym && (x->l.frac2 < y->l.frac2 ||
222*7c478bd9Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 < y->l.frac3 ||
223*7c478bd9Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 < y->l.frac4)));
224*7c478bd9Sstevel@tonic-gate }
225*7c478bd9Sstevel@tonic-gate return (xm > ym || xm == ym && (x->l.frac2 > y->l.frac2 ||
226*7c478bd9Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 > y->l.frac3 ||
227*7c478bd9Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 > y->l.frac4)));
228*7c478bd9Sstevel@tonic-gate }
229*7c478bd9Sstevel@tonic-gate
230*7c478bd9Sstevel@tonic-gate /*
231*7c478bd9Sstevel@tonic-gate * _Q_fge(x, y) returns nonzero if *x >= *y and zero otherwise. If
232*7c478bd9Sstevel@tonic-gate * either *x or *y is NaN, the invalid operation exception is raised.
233*7c478bd9Sstevel@tonic-gate */
234*7c478bd9Sstevel@tonic-gate int
_Q_fge(const union longdouble * x,const union longdouble * y)235*7c478bd9Sstevel@tonic-gate _Q_fge(const union longdouble *x, const union longdouble *y)
236*7c478bd9Sstevel@tonic-gate {
237*7c478bd9Sstevel@tonic-gate unsigned int xm, ym, fsr;
238*7c478bd9Sstevel@tonic-gate
239*7c478bd9Sstevel@tonic-gate if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
240*7c478bd9Sstevel@tonic-gate /* nan, signal invalid */
241*7c478bd9Sstevel@tonic-gate __quad_getfsrp(&fsr);
242*7c478bd9Sstevel@tonic-gate if (fsr & FSR_NVM) {
243*7c478bd9Sstevel@tonic-gate __quad_fcmpeq(x, y, &fsr);
244*7c478bd9Sstevel@tonic-gate fsr = (fsr >> 10) & 3;
245*7c478bd9Sstevel@tonic-gate return (fsr == fcc_greater || fsr == fcc_equal);
246*7c478bd9Sstevel@tonic-gate } else {
247*7c478bd9Sstevel@tonic-gate fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
248*7c478bd9Sstevel@tonic-gate __quad_setfsrp(&fsr);
249*7c478bd9Sstevel@tonic-gate }
250*7c478bd9Sstevel@tonic-gate return (0);
251*7c478bd9Sstevel@tonic-gate }
252*7c478bd9Sstevel@tonic-gate
253*7c478bd9Sstevel@tonic-gate /* ignore sign of zero */
254*7c478bd9Sstevel@tonic-gate xm = x->l.msw;
255*7c478bd9Sstevel@tonic-gate if (QUAD_ISZERO(*x))
256*7c478bd9Sstevel@tonic-gate xm &= 0x7fffffff;
257*7c478bd9Sstevel@tonic-gate ym = y->l.msw;
258*7c478bd9Sstevel@tonic-gate if (QUAD_ISZERO(*y))
259*7c478bd9Sstevel@tonic-gate ym &= 0x7fffffff;
260*7c478bd9Sstevel@tonic-gate
261*7c478bd9Sstevel@tonic-gate if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */
262*7c478bd9Sstevel@tonic-gate return ((ym & 0x80000000) != 0);
263*7c478bd9Sstevel@tonic-gate
264*7c478bd9Sstevel@tonic-gate if (xm & 0x80000000) {
265*7c478bd9Sstevel@tonic-gate return (xm < ym || xm == ym && (x->l.frac2 < y->l.frac2 ||
266*7c478bd9Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 < y->l.frac3 ||
267*7c478bd9Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 <= y->l.frac4)));
268*7c478bd9Sstevel@tonic-gate }
269*7c478bd9Sstevel@tonic-gate return (xm > ym || xm == ym && (x->l.frac2 > y->l.frac2 ||
270*7c478bd9Sstevel@tonic-gate x->l.frac2 == y->l.frac2 && (x->l.frac3 > y->l.frac3 ||
271*7c478bd9Sstevel@tonic-gate x->l.frac3 == y->l.frac3 && x->l.frac4 >= y->l.frac4)));
272*7c478bd9Sstevel@tonic-gate }
273