xref: /illumos-gate/usr/src/lib/libc/sparc/fp/_Q_cmpe.c (revision 942c5e3c2dd127463517e5cc1694ee94ca45e021)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1994-1997, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include "quad.h"
30 
31 #ifdef __sparcv9
32 #define	_Q_cmpe	_Qp_cmpe
33 #endif
34 
35 /*
36  * _Q_cmpe(x, y) returns the condition code that would result from
37  * fcmpeq *x, *y (and raises the same exceptions).
38  */
39 enum fcc_type
40 _Q_cmpe(const union longdouble *x, const union longdouble *y)
41 {
42 	unsigned int	xm, ym, fsr;
43 
44 	if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) {
45 		/* nan, signal invalid */
46 		__quad_getfsrp(&fsr);
47 		if (fsr & FSR_NVM) {
48 			__quad_fcmpeq(x, y, &fsr);
49 			return ((fsr >> 10) & 3);
50 		} else {
51 			fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
52 			__quad_setfsrp(&fsr);
53 		}
54 		return (fcc_unordered);
55 	}
56 
57 	/* ignore sign of zero */
58 	xm = x->l.msw;
59 	if (QUAD_ISZERO(*x))
60 		xm &= 0x7fffffff;
61 	ym = y->l.msw;
62 	if (QUAD_ISZERO(*y))
63 		ym &= 0x7fffffff;
64 
65 	if ((xm ^ ym) & 0x80000000)	/* x and y have opposite signs */
66 		return ((ym & 0x80000000)? fcc_greater : fcc_less);
67 
68 	if (xm & 0x80000000) {
69 		if (xm > ym)
70 			return (fcc_less);
71 		if (xm < ym)
72 			return (fcc_greater);
73 		if (x->l.frac2 > y->l.frac2)
74 			return (fcc_less);
75 		if (x->l.frac2 < y->l.frac2)
76 			return (fcc_greater);
77 		if (x->l.frac3 > y->l.frac3)
78 			return (fcc_less);
79 		if (x->l.frac3 < y->l.frac3)
80 			return (fcc_greater);
81 		if (x->l.frac4 > y->l.frac4)
82 			return (fcc_less);
83 		if (x->l.frac4 < y->l.frac4)
84 			return (fcc_greater);
85 		return (fcc_equal);
86 	}
87 	if (xm < ym)
88 		return (fcc_less);
89 	if (xm > ym)
90 		return (fcc_greater);
91 	if (x->l.frac2 < y->l.frac2)
92 		return (fcc_less);
93 	if (x->l.frac2 > y->l.frac2)
94 		return (fcc_greater);
95 	if (x->l.frac3 < y->l.frac3)
96 		return (fcc_less);
97 	if (x->l.frac3 > y->l.frac3)
98 		return (fcc_greater);
99 	if (x->l.frac4 < y->l.frac4)
100 		return (fcc_less);
101 	if (x->l.frac4 > y->l.frac4)
102 		return (fcc_greater);
103 	return (fcc_equal);
104 }
105