xref: /titanic_50/usr/src/uts/sparc/fpu/compare.c (revision 35a5a3587fd94b666239c157d3722745250ccbd7)
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) 1986 by Sun Microsystems, Inc.
24  */
25 #ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS-4.1 1.7 88/12/06 */
26 
27 #include <sys/fpu/fpu_simulator.h>
28 #include <sys/fpu/globals.h>
29 
30 enum fcc_type
31 _fp_compare(pfpsd, px, py, strict)
32 	fp_simd_type	*pfpsd;	/* simulator data */
33 	unpacked	*px, *py;
34 	int		strict;
35 				/*
36 				 * 0 if quiet NaN unexceptional, 1 if
37 				 * exceptional
38 				 */
39 {
40 	enum fcc_type   cc;
41 	int  n;
42 
43 	if ((px->fpclass == fp_quiet) || (py->fpclass == fp_quiet) ||
44 	    (px->fpclass == fp_signaling) || (py->fpclass == fp_signaling)) {
45 		if (strict)				/* NaN */
46 			fpu_set_exception(pfpsd, fp_invalid);
47 		cc = fcc_unordered;
48 	} else if ((px->fpclass == fp_zero) && (py->fpclass == fp_zero))
49 		cc = fcc_equal;
50 	/* both zeros */
51 	else if (px->sign < py->sign)
52 		cc = fcc_greater;
53 	else if (px->sign > py->sign)
54 		cc = fcc_less;
55 	else {			/* signs the same, compute magnitude cc */
56 		if ((int) px->fpclass > (int) py->fpclass)
57 			cc = fcc_greater;
58 		else if ((int) px->fpclass < (int) py->fpclass)
59 			cc = fcc_less;
60 		else
61 		/* same classes */ if (px->fpclass == fp_infinity)
62 			cc = fcc_equal;	/* same infinity */
63 		else if (px->exponent > py->exponent)
64 			cc = fcc_greater;
65 		else if (px->exponent < py->exponent)
66 			cc = fcc_less;
67 		else {	/* equal exponents */
68 			n = fpu_cmpli(px->significand, py->significand, 4);
69 			if (n > 0) cc = fcc_greater;
70 			else if (n < 0) cc = fcc_less;
71 			else cc = fcc_equal;
72 		}
73 		if (px->sign)
74 			switch (cc) {	/* negative numbers */
75 			case fcc_less:
76 				cc = fcc_greater;
77 				break;
78 			case fcc_greater:
79 				cc = fcc_less;
80 				break;
81 			}
82 	}
83 	return (cc);
84 }
85