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