2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include "quad.h"
2N/A
2N/A#ifdef __sparcv9
2N/A
2N/A/*
2N/A * _Qp_sub(pz, ox, oy) sets *pz = *ox - *oy.
2N/A */
2N/Avoid
2N/A_Qp_sub(union longdouble *pz, const union longdouble *ox,
2N/A const union longdouble *oy)
2N/A
2N/A#else
2N/A
2N/A/*
2N/A * _Q_sub(ox, oy) returns *ox - *oy.
2N/A */
2N/Aunion longdouble
2N/A_Q_sub(const union longdouble *ox, const union longdouble *oy)
2N/A
2N/A#endif /* __sparcv9 */
2N/A
2N/A{
2N/A union longdouble z;
2N/A const union longdouble *x, *y;
2N/A unsigned int xm, ym, tm, fsr;
2N/A int flip;
2N/A
2N/A /* sort so |x| >= |y| */
2N/A xm = ox->l.msw & 0x7fffffff;
2N/A ym = oy->l.msw & 0x7fffffff;
2N/A if (ym > xm || ym == xm && (oy->l.frac2 > ox->l.frac2 ||
2N/A oy->l.frac2 == ox->l.frac2 && (oy->l.frac3 > ox->l.frac3 ||
2N/A oy->l.frac3 == ox->l.frac3 && oy->l.frac4 > ox->l.frac4))) {
2N/A y = ox;
2N/A x = oy;
2N/A tm = xm;
2N/A xm = ym;
2N/A ym = tm;
2N/A flip = 0x80000000;
2N/A } else {
2N/A x = ox;
2N/A y = oy;
2N/A flip = 0;
2N/A }
2N/A
2N/A /* get the fsr */
2N/A __quad_getfsrp(&fsr);
2N/A
2N/A /* handle nan and inf cases */
2N/A if (xm >= 0x7fff0000) {
2N/A /* x is nan or inf */
2N/A if (ym >= 0x7fff0000) {
2N/A /* y is nan or inf */
2N/A if ((ym & 0xffff) | y->l.frac2 | y->l.frac3 |
2N/A y->l.frac4) {
2N/A /* y is nan; x must be nan too */
2N/A /* the following logic implements V9 app. B */
2N/A if (!(ym & 0x8000)) {
2N/A /* y is snan, signal invalid */
2N/A if (fsr & FSR_NVM) {
2N/A __quad_fsubq(ox, oy, &Z);
2N/A } else {
2N/A Z = (xm & 0x8000)? *y : *oy;
2N/A Z.l.msw |= 0x8000;
2N/A fsr = (fsr & ~FSR_CEXC) |
2N/A FSR_NVA | FSR_NVC;
2N/A __quad_setfsrp(&fsr);
2N/A }
2N/A QUAD_RETURN(Z);
2N/A }
2N/A /* x and y are both qnan */
2N/A Z = *oy;
2N/A QUAD_RETURN(Z);
2N/A }
2N/A if (!((xm & 0xffff) | x->l.frac2 | x->l.frac3 |
2N/A x->l.frac4)) {
2N/A /* x and y are both inf */
2N/A if (!((x->l.msw ^ y->l.msw) & 0x80000000)) {
2N/A /* inf - inf, signal invalid */
2N/A if (fsr & FSR_NVM) {
2N/A __quad_fsubq(ox, oy, &Z);
2N/A } else {
2N/A Z.l.msw = 0x7fffffff;
2N/A Z.l.frac2 = Z.l.frac3 =
2N/A Z.l.frac4 = 0xffffffff;
2N/A fsr = (fsr & ~FSR_CEXC) |
2N/A FSR_NVA | FSR_NVC;
2N/A __quad_setfsrp(&fsr);
2N/A }
2N/A QUAD_RETURN(Z);
2N/A }
2N/A /* inf + inf, return inf */
2N/A Z = *x;
2N/A Z.l.msw ^= flip;
2N/A QUAD_RETURN(Z);
2N/A }
2N/A }
2N/A if ((xm & 0xffff) | x->l.frac2 | x->l.frac3 | x->l.frac4) {
2N/A /* x is nan */
2N/A if (!(xm & 0x8000)) {
2N/A /* snan, signal invalid */
2N/A if (fsr & FSR_NVM) {
2N/A __quad_fsubq(ox, oy, &Z);
2N/A } else {
2N/A Z = *x;
2N/A Z.l.msw |= 0x8000;
2N/A fsr = (fsr & ~FSR_CEXC) | FSR_NVA |
2N/A FSR_NVC;
2N/A __quad_setfsrp(&fsr);
2N/A }
2N/A QUAD_RETURN(Z);
2N/A }
2N/A Z = *x;
2N/A QUAD_RETURN(Z);
2N/A }
2N/A /* x is inf */
2N/A Z = *x;
2N/A Z.l.msw ^= flip;
2N/A QUAD_RETURN(Z);
2N/A }
2N/A
2N/A /* now x and y are finite and |x| >= |y| */
2N/A fsr &= ~FSR_CEXC;
2N/A z.l.msw = (x->l.msw & 0x80000000) ^ flip;
2N/A if ((x->l.msw ^ y->l.msw) & 0x80000000)
2N/A __quad_mag_add(x, y, &z, &fsr);
2N/A else
2N/A __quad_mag_sub(x, y, &z, &fsr);
2N/A if ((fsr & FSR_CEXC) & (fsr >> 23)) {
2N/A __quad_setfsrp(&fsr);
2N/A __quad_fsubq(ox, oy, &Z);
2N/A } else {
2N/A Z = z;
2N/A fsr |= (fsr & 0x1f) << 5;
2N/A __quad_setfsrp(&fsr);
2N/A }
2N/A QUAD_RETURN(Z);
2N/A}