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 #include "quad.h" 28 29 #ifdef __sparcv9 30 #define _Q_cmpe _Qp_cmpe 31 #endif 32 33 /* 34 * _Q_cmpe(x, y) returns the condition code that would result from 35 * fcmpeq *x, *y (and raises the same exceptions). 36 */ 37 enum fcc_type 38 _Q_cmpe(const union longdouble *x, const union longdouble *y) 39 { 40 unsigned int xm, ym, fsr; 41 42 if (QUAD_ISNAN(*x) || QUAD_ISNAN(*y)) { 43 /* nan, signal invalid */ 44 __quad_getfsrp(&fsr); 45 if (fsr & FSR_NVM) { 46 __quad_fcmpeq(x, y, &fsr); 47 return ((fsr >> 10) & 3); 48 } else { 49 fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC; 50 __quad_setfsrp(&fsr); 51 } 52 return (fcc_unordered); 53 } 54 55 /* ignore sign of zero */ 56 xm = x->l.msw; 57 if (QUAD_ISZERO(*x)) 58 xm &= 0x7fffffff; 59 ym = y->l.msw; 60 if (QUAD_ISZERO(*y)) 61 ym &= 0x7fffffff; 62 63 if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */ 64 return ((ym & 0x80000000)? fcc_greater : fcc_less); 65 66 if (xm & 0x80000000) { 67 if (xm > ym) 68 return (fcc_less); 69 if (xm < ym) 70 return (fcc_greater); 71 if (x->l.frac2 > y->l.frac2) 72 return (fcc_less); 73 if (x->l.frac2 < y->l.frac2) 74 return (fcc_greater); 75 if (x->l.frac3 > y->l.frac3) 76 return (fcc_less); 77 if (x->l.frac3 < y->l.frac3) 78 return (fcc_greater); 79 if (x->l.frac4 > y->l.frac4) 80 return (fcc_less); 81 if (x->l.frac4 < y->l.frac4) 82 return (fcc_greater); 83 return (fcc_equal); 84 } 85 if (xm < ym) 86 return (fcc_less); 87 if (xm > ym) 88 return (fcc_greater); 89 if (x->l.frac2 < y->l.frac2) 90 return (fcc_less); 91 if (x->l.frac2 > y->l.frac2) 92 return (fcc_greater); 93 if (x->l.frac3 < y->l.frac3) 94 return (fcc_less); 95 if (x->l.frac3 > y->l.frac3) 96 return (fcc_greater); 97 if (x->l.frac4 < y->l.frac4) 98 return (fcc_less); 99 if (x->l.frac4 > y->l.frac4) 100 return (fcc_greater); 101 return (fcc_equal); 102 } 103