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_cmp _Qp_cmp 31 #endif 32 33 /* 34 * _Q_cmp(x, y) returns the condition code that would result from 35 * fcmpq *x, *y (and raises the same exceptions). 36 */ 37 enum fcc_type 38 _Q_cmp(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 if ((QUAD_ISNAN(*x) && !(x->l.msw & 0x8000)) || 44 (QUAD_ISNAN(*y) && !(y->l.msw & 0x8000))) { 45 /* snan, signal invalid */ 46 __quad_getfsrp(&fsr); 47 if (fsr & FSR_NVM) { 48 __quad_fcmpq(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 } 55 return (fcc_unordered); 56 } 57 58 /* ignore sign of zero */ 59 xm = x->l.msw; 60 if (QUAD_ISZERO(*x)) 61 xm &= 0x7fffffff; 62 ym = y->l.msw; 63 if (QUAD_ISZERO(*y)) 64 ym &= 0x7fffffff; 65 66 if ((xm ^ ym) & 0x80000000) /* x and y have opposite signs */ 67 return ((ym & 0x80000000)? fcc_greater : fcc_less); 68 69 if (xm & 0x80000000) { 70 if (xm > ym) 71 return (fcc_less); 72 if (xm < ym) 73 return (fcc_greater); 74 if (x->l.frac2 > y->l.frac2) 75 return (fcc_less); 76 if (x->l.frac2 < y->l.frac2) 77 return (fcc_greater); 78 if (x->l.frac3 > y->l.frac3) 79 return (fcc_less); 80 if (x->l.frac3 < y->l.frac3) 81 return (fcc_greater); 82 if (x->l.frac4 > y->l.frac4) 83 return (fcc_less); 84 if (x->l.frac4 < y->l.frac4) 85 return (fcc_greater); 86 return (fcc_equal); 87 } 88 if (xm < ym) 89 return (fcc_less); 90 if (xm > ym) 91 return (fcc_greater); 92 if (x->l.frac2 < y->l.frac2) 93 return (fcc_less); 94 if (x->l.frac2 > y->l.frac2) 95 return (fcc_greater); 96 if (x->l.frac3 < y->l.frac3) 97 return (fcc_less); 98 if (x->l.frac3 > y->l.frac3) 99 return (fcc_greater); 100 if (x->l.frac4 < y->l.frac4) 101 return (fcc_less); 102 if (x->l.frac4 > y->l.frac4) 103 return (fcc_greater); 104 return (fcc_equal); 105 } 106