1*660662f8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * Linux/PA-RISC Project (http://www.parisc-linux.org/)
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Floating-point emulation code
61da177e4SLinus Torvalds * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
71da177e4SLinus Torvalds */
81da177e4SLinus Torvalds /*
91da177e4SLinus Torvalds * BEGIN_DESC
101da177e4SLinus Torvalds *
111da177e4SLinus Torvalds * File:
121da177e4SLinus Torvalds * @(#) pa/spmath/dfdiv.c $Revision: 1.1 $
131da177e4SLinus Torvalds *
141da177e4SLinus Torvalds * Purpose:
151da177e4SLinus Torvalds * Double Precision Floating-point Divide
161da177e4SLinus Torvalds *
171da177e4SLinus Torvalds * External Interfaces:
181da177e4SLinus Torvalds * dbl_fdiv(srcptr1,srcptr2,dstptr,status)
191da177e4SLinus Torvalds *
201da177e4SLinus Torvalds * Internal Interfaces:
211da177e4SLinus Torvalds *
221da177e4SLinus Torvalds * Theory:
231da177e4SLinus Torvalds * <<please update with a overview of the operation of this file>>
241da177e4SLinus Torvalds *
251da177e4SLinus Torvalds * END_DESC
261da177e4SLinus Torvalds */
271da177e4SLinus Torvalds
281da177e4SLinus Torvalds
291da177e4SLinus Torvalds #include "float.h"
301da177e4SLinus Torvalds #include "dbl_float.h"
311da177e4SLinus Torvalds
321da177e4SLinus Torvalds /*
331da177e4SLinus Torvalds * Double Precision Floating-point Divide
341da177e4SLinus Torvalds */
351da177e4SLinus Torvalds
361da177e4SLinus Torvalds int
dbl_fdiv(dbl_floating_point * srcptr1,dbl_floating_point * srcptr2,dbl_floating_point * dstptr,unsigned int * status)371da177e4SLinus Torvalds dbl_fdiv (dbl_floating_point * srcptr1, dbl_floating_point * srcptr2,
381da177e4SLinus Torvalds dbl_floating_point * dstptr, unsigned int *status)
391da177e4SLinus Torvalds {
401da177e4SLinus Torvalds register unsigned int opnd1p1, opnd1p2, opnd2p1, opnd2p2;
411da177e4SLinus Torvalds register unsigned int opnd3p1, opnd3p2, resultp1, resultp2;
421da177e4SLinus Torvalds register int dest_exponent, count;
431da177e4SLinus Torvalds register boolean inexact = FALSE, guardbit = FALSE, stickybit = FALSE;
441da177e4SLinus Torvalds boolean is_tiny;
451da177e4SLinus Torvalds
461da177e4SLinus Torvalds Dbl_copyfromptr(srcptr1,opnd1p1,opnd1p2);
471da177e4SLinus Torvalds Dbl_copyfromptr(srcptr2,opnd2p1,opnd2p2);
481da177e4SLinus Torvalds /*
491da177e4SLinus Torvalds * set sign bit of result
501da177e4SLinus Torvalds */
511da177e4SLinus Torvalds if (Dbl_sign(opnd1p1) ^ Dbl_sign(opnd2p1))
521da177e4SLinus Torvalds Dbl_setnegativezerop1(resultp1);
531da177e4SLinus Torvalds else Dbl_setzerop1(resultp1);
541da177e4SLinus Torvalds /*
551da177e4SLinus Torvalds * check first operand for NaN's or infinity
561da177e4SLinus Torvalds */
571da177e4SLinus Torvalds if (Dbl_isinfinity_exponent(opnd1p1)) {
581da177e4SLinus Torvalds if (Dbl_iszero_mantissa(opnd1p1,opnd1p2)) {
591da177e4SLinus Torvalds if (Dbl_isnotnan(opnd2p1,opnd2p2)) {
601da177e4SLinus Torvalds if (Dbl_isinfinity(opnd2p1,opnd2p2)) {
611da177e4SLinus Torvalds /*
621da177e4SLinus Torvalds * invalid since both operands
631da177e4SLinus Torvalds * are infinity
641da177e4SLinus Torvalds */
651da177e4SLinus Torvalds if (Is_invalidtrap_enabled())
661da177e4SLinus Torvalds return(INVALIDEXCEPTION);
671da177e4SLinus Torvalds Set_invalidflag();
681da177e4SLinus Torvalds Dbl_makequietnan(resultp1,resultp2);
691da177e4SLinus Torvalds Dbl_copytoptr(resultp1,resultp2,dstptr);
701da177e4SLinus Torvalds return(NOEXCEPTION);
711da177e4SLinus Torvalds }
721da177e4SLinus Torvalds /*
731da177e4SLinus Torvalds * return infinity
741da177e4SLinus Torvalds */
751da177e4SLinus Torvalds Dbl_setinfinity_exponentmantissa(resultp1,resultp2);
761da177e4SLinus Torvalds Dbl_copytoptr(resultp1,resultp2,dstptr);
771da177e4SLinus Torvalds return(NOEXCEPTION);
781da177e4SLinus Torvalds }
791da177e4SLinus Torvalds }
801da177e4SLinus Torvalds else {
811da177e4SLinus Torvalds /*
821da177e4SLinus Torvalds * is NaN; signaling or quiet?
831da177e4SLinus Torvalds */
841da177e4SLinus Torvalds if (Dbl_isone_signaling(opnd1p1)) {
851da177e4SLinus Torvalds /* trap if INVALIDTRAP enabled */
861da177e4SLinus Torvalds if (Is_invalidtrap_enabled())
871da177e4SLinus Torvalds return(INVALIDEXCEPTION);
881da177e4SLinus Torvalds /* make NaN quiet */
891da177e4SLinus Torvalds Set_invalidflag();
901da177e4SLinus Torvalds Dbl_set_quiet(opnd1p1);
911da177e4SLinus Torvalds }
921da177e4SLinus Torvalds /*
931da177e4SLinus Torvalds * is second operand a signaling NaN?
941da177e4SLinus Torvalds */
951da177e4SLinus Torvalds else if (Dbl_is_signalingnan(opnd2p1)) {
961da177e4SLinus Torvalds /* trap if INVALIDTRAP enabled */
971da177e4SLinus Torvalds if (Is_invalidtrap_enabled())
981da177e4SLinus Torvalds return(INVALIDEXCEPTION);
991da177e4SLinus Torvalds /* make NaN quiet */
1001da177e4SLinus Torvalds Set_invalidflag();
1011da177e4SLinus Torvalds Dbl_set_quiet(opnd2p1);
1021da177e4SLinus Torvalds Dbl_copytoptr(opnd2p1,opnd2p2,dstptr);
1031da177e4SLinus Torvalds return(NOEXCEPTION);
1041da177e4SLinus Torvalds }
1051da177e4SLinus Torvalds /*
1061da177e4SLinus Torvalds * return quiet NaN
1071da177e4SLinus Torvalds */
1081da177e4SLinus Torvalds Dbl_copytoptr(opnd1p1,opnd1p2,dstptr);
1091da177e4SLinus Torvalds return(NOEXCEPTION);
1101da177e4SLinus Torvalds }
1111da177e4SLinus Torvalds }
1121da177e4SLinus Torvalds /*
1131da177e4SLinus Torvalds * check second operand for NaN's or infinity
1141da177e4SLinus Torvalds */
1151da177e4SLinus Torvalds if (Dbl_isinfinity_exponent(opnd2p1)) {
1161da177e4SLinus Torvalds if (Dbl_iszero_mantissa(opnd2p1,opnd2p2)) {
1171da177e4SLinus Torvalds /*
1181da177e4SLinus Torvalds * return zero
1191da177e4SLinus Torvalds */
1201da177e4SLinus Torvalds Dbl_setzero_exponentmantissa(resultp1,resultp2);
1211da177e4SLinus Torvalds Dbl_copytoptr(resultp1,resultp2,dstptr);
1221da177e4SLinus Torvalds return(NOEXCEPTION);
1231da177e4SLinus Torvalds }
1241da177e4SLinus Torvalds /*
1251da177e4SLinus Torvalds * is NaN; signaling or quiet?
1261da177e4SLinus Torvalds */
1271da177e4SLinus Torvalds if (Dbl_isone_signaling(opnd2p1)) {
1281da177e4SLinus Torvalds /* trap if INVALIDTRAP enabled */
1291da177e4SLinus Torvalds if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
1301da177e4SLinus Torvalds /* make NaN quiet */
1311da177e4SLinus Torvalds Set_invalidflag();
1321da177e4SLinus Torvalds Dbl_set_quiet(opnd2p1);
1331da177e4SLinus Torvalds }
1341da177e4SLinus Torvalds /*
1351da177e4SLinus Torvalds * return quiet NaN
1361da177e4SLinus Torvalds */
1371da177e4SLinus Torvalds Dbl_copytoptr(opnd2p1,opnd2p2,dstptr);
1381da177e4SLinus Torvalds return(NOEXCEPTION);
1391da177e4SLinus Torvalds }
1401da177e4SLinus Torvalds /*
1411da177e4SLinus Torvalds * check for division by zero
1421da177e4SLinus Torvalds */
1431da177e4SLinus Torvalds if (Dbl_iszero_exponentmantissa(opnd2p1,opnd2p2)) {
1441da177e4SLinus Torvalds if (Dbl_iszero_exponentmantissa(opnd1p1,opnd1p2)) {
1451da177e4SLinus Torvalds /* invalid since both operands are zero */
1461da177e4SLinus Torvalds if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
1471da177e4SLinus Torvalds Set_invalidflag();
1481da177e4SLinus Torvalds Dbl_makequietnan(resultp1,resultp2);
1491da177e4SLinus Torvalds Dbl_copytoptr(resultp1,resultp2,dstptr);
1501da177e4SLinus Torvalds return(NOEXCEPTION);
1511da177e4SLinus Torvalds }
1521da177e4SLinus Torvalds if (Is_divisionbyzerotrap_enabled())
1531da177e4SLinus Torvalds return(DIVISIONBYZEROEXCEPTION);
1541da177e4SLinus Torvalds Set_divisionbyzeroflag();
1551da177e4SLinus Torvalds Dbl_setinfinity_exponentmantissa(resultp1,resultp2);
1561da177e4SLinus Torvalds Dbl_copytoptr(resultp1,resultp2,dstptr);
1571da177e4SLinus Torvalds return(NOEXCEPTION);
1581da177e4SLinus Torvalds }
1591da177e4SLinus Torvalds /*
1601da177e4SLinus Torvalds * Generate exponent
1611da177e4SLinus Torvalds */
1621da177e4SLinus Torvalds dest_exponent = Dbl_exponent(opnd1p1) - Dbl_exponent(opnd2p1) + DBL_BIAS;
1631da177e4SLinus Torvalds
1641da177e4SLinus Torvalds /*
1651da177e4SLinus Torvalds * Generate mantissa
1661da177e4SLinus Torvalds */
1671da177e4SLinus Torvalds if (Dbl_isnotzero_exponent(opnd1p1)) {
1681da177e4SLinus Torvalds /* set hidden bit */
1691da177e4SLinus Torvalds Dbl_clear_signexponent_set_hidden(opnd1p1);
1701da177e4SLinus Torvalds }
1711da177e4SLinus Torvalds else {
1721da177e4SLinus Torvalds /* check for zero */
1731da177e4SLinus Torvalds if (Dbl_iszero_mantissa(opnd1p1,opnd1p2)) {
1741da177e4SLinus Torvalds Dbl_setzero_exponentmantissa(resultp1,resultp2);
1751da177e4SLinus Torvalds Dbl_copytoptr(resultp1,resultp2,dstptr);
1761da177e4SLinus Torvalds return(NOEXCEPTION);
1771da177e4SLinus Torvalds }
1781da177e4SLinus Torvalds /* is denormalized, want to normalize */
1791da177e4SLinus Torvalds Dbl_clear_signexponent(opnd1p1);
1801da177e4SLinus Torvalds Dbl_leftshiftby1(opnd1p1,opnd1p2);
1811da177e4SLinus Torvalds Dbl_normalize(opnd1p1,opnd1p2,dest_exponent);
1821da177e4SLinus Torvalds }
1831da177e4SLinus Torvalds /* opnd2 needs to have hidden bit set with msb in hidden bit */
1841da177e4SLinus Torvalds if (Dbl_isnotzero_exponent(opnd2p1)) {
1851da177e4SLinus Torvalds Dbl_clear_signexponent_set_hidden(opnd2p1);
1861da177e4SLinus Torvalds }
1871da177e4SLinus Torvalds else {
1881da177e4SLinus Torvalds /* is denormalized; want to normalize */
1891da177e4SLinus Torvalds Dbl_clear_signexponent(opnd2p1);
1901da177e4SLinus Torvalds Dbl_leftshiftby1(opnd2p1,opnd2p2);
1911da177e4SLinus Torvalds while (Dbl_iszero_hiddenhigh7mantissa(opnd2p1)) {
1921da177e4SLinus Torvalds dest_exponent+=8;
1931da177e4SLinus Torvalds Dbl_leftshiftby8(opnd2p1,opnd2p2);
1941da177e4SLinus Torvalds }
1951da177e4SLinus Torvalds if (Dbl_iszero_hiddenhigh3mantissa(opnd2p1)) {
1961da177e4SLinus Torvalds dest_exponent+=4;
1971da177e4SLinus Torvalds Dbl_leftshiftby4(opnd2p1,opnd2p2);
1981da177e4SLinus Torvalds }
1991da177e4SLinus Torvalds while (Dbl_iszero_hidden(opnd2p1)) {
2001da177e4SLinus Torvalds dest_exponent++;
2011da177e4SLinus Torvalds Dbl_leftshiftby1(opnd2p1,opnd2p2);
2021da177e4SLinus Torvalds }
2031da177e4SLinus Torvalds }
2041da177e4SLinus Torvalds
2051da177e4SLinus Torvalds /* Divide the source mantissas */
2061da177e4SLinus Torvalds
2071da177e4SLinus Torvalds /*
2081da177e4SLinus Torvalds * A non-restoring divide algorithm is used.
2091da177e4SLinus Torvalds */
2101da177e4SLinus Torvalds Twoword_subtract(opnd1p1,opnd1p2,opnd2p1,opnd2p2);
2111da177e4SLinus Torvalds Dbl_setzero(opnd3p1,opnd3p2);
2121da177e4SLinus Torvalds for (count=1; count <= DBL_P && (opnd1p1 || opnd1p2); count++) {
2131da177e4SLinus Torvalds Dbl_leftshiftby1(opnd1p1,opnd1p2);
2141da177e4SLinus Torvalds Dbl_leftshiftby1(opnd3p1,opnd3p2);
2151da177e4SLinus Torvalds if (Dbl_iszero_sign(opnd1p1)) {
2161da177e4SLinus Torvalds Dbl_setone_lowmantissap2(opnd3p2);
2171da177e4SLinus Torvalds Twoword_subtract(opnd1p1,opnd1p2,opnd2p1,opnd2p2);
2181da177e4SLinus Torvalds }
2191da177e4SLinus Torvalds else {
2201da177e4SLinus Torvalds Twoword_add(opnd1p1, opnd1p2, opnd2p1, opnd2p2);
2211da177e4SLinus Torvalds }
2221da177e4SLinus Torvalds }
2231da177e4SLinus Torvalds if (count <= DBL_P) {
2241da177e4SLinus Torvalds Dbl_leftshiftby1(opnd3p1,opnd3p2);
2251da177e4SLinus Torvalds Dbl_setone_lowmantissap2(opnd3p2);
2261da177e4SLinus Torvalds Dbl_leftshift(opnd3p1,opnd3p2,(DBL_P-count));
2271da177e4SLinus Torvalds if (Dbl_iszero_hidden(opnd3p1)) {
2281da177e4SLinus Torvalds Dbl_leftshiftby1(opnd3p1,opnd3p2);
2291da177e4SLinus Torvalds dest_exponent--;
2301da177e4SLinus Torvalds }
2311da177e4SLinus Torvalds }
2321da177e4SLinus Torvalds else {
2331da177e4SLinus Torvalds if (Dbl_iszero_hidden(opnd3p1)) {
2341da177e4SLinus Torvalds /* need to get one more bit of result */
2351da177e4SLinus Torvalds Dbl_leftshiftby1(opnd1p1,opnd1p2);
2361da177e4SLinus Torvalds Dbl_leftshiftby1(opnd3p1,opnd3p2);
2371da177e4SLinus Torvalds if (Dbl_iszero_sign(opnd1p1)) {
2381da177e4SLinus Torvalds Dbl_setone_lowmantissap2(opnd3p2);
2391da177e4SLinus Torvalds Twoword_subtract(opnd1p1,opnd1p2,opnd2p1,opnd2p2);
2401da177e4SLinus Torvalds }
2411da177e4SLinus Torvalds else {
2421da177e4SLinus Torvalds Twoword_add(opnd1p1,opnd1p2,opnd2p1,opnd2p2);
2431da177e4SLinus Torvalds }
2441da177e4SLinus Torvalds dest_exponent--;
2451da177e4SLinus Torvalds }
2461da177e4SLinus Torvalds if (Dbl_iszero_sign(opnd1p1)) guardbit = TRUE;
2471da177e4SLinus Torvalds stickybit = Dbl_allp1(opnd1p1) || Dbl_allp2(opnd1p2);
2481da177e4SLinus Torvalds }
2491da177e4SLinus Torvalds inexact = guardbit | stickybit;
2501da177e4SLinus Torvalds
2511da177e4SLinus Torvalds /*
2521da177e4SLinus Torvalds * round result
2531da177e4SLinus Torvalds */
2541da177e4SLinus Torvalds if (inexact && (dest_exponent > 0 || Is_underflowtrap_enabled())) {
2551da177e4SLinus Torvalds Dbl_clear_signexponent(opnd3p1);
2561da177e4SLinus Torvalds switch (Rounding_mode()) {
2571da177e4SLinus Torvalds case ROUNDPLUS:
2581da177e4SLinus Torvalds if (Dbl_iszero_sign(resultp1))
2591da177e4SLinus Torvalds Dbl_increment(opnd3p1,opnd3p2);
2601da177e4SLinus Torvalds break;
2611da177e4SLinus Torvalds case ROUNDMINUS:
2621da177e4SLinus Torvalds if (Dbl_isone_sign(resultp1))
2631da177e4SLinus Torvalds Dbl_increment(opnd3p1,opnd3p2);
2641da177e4SLinus Torvalds break;
2651da177e4SLinus Torvalds case ROUNDNEAREST:
2661da177e4SLinus Torvalds if (guardbit && (stickybit ||
2671da177e4SLinus Torvalds Dbl_isone_lowmantissap2(opnd3p2))) {
2681da177e4SLinus Torvalds Dbl_increment(opnd3p1,opnd3p2);
2691da177e4SLinus Torvalds }
2701da177e4SLinus Torvalds }
2711da177e4SLinus Torvalds if (Dbl_isone_hidden(opnd3p1)) dest_exponent++;
2721da177e4SLinus Torvalds }
2731da177e4SLinus Torvalds Dbl_set_mantissa(resultp1,resultp2,opnd3p1,opnd3p2);
2741da177e4SLinus Torvalds
2751da177e4SLinus Torvalds /*
2761da177e4SLinus Torvalds * Test for overflow
2771da177e4SLinus Torvalds */
2781da177e4SLinus Torvalds if (dest_exponent >= DBL_INFINITY_EXPONENT) {
2791da177e4SLinus Torvalds /* trap if OVERFLOWTRAP enabled */
2801da177e4SLinus Torvalds if (Is_overflowtrap_enabled()) {
2811da177e4SLinus Torvalds /*
2821da177e4SLinus Torvalds * Adjust bias of result
2831da177e4SLinus Torvalds */
2841da177e4SLinus Torvalds Dbl_setwrapped_exponent(resultp1,dest_exponent,ovfl);
2851da177e4SLinus Torvalds Dbl_copytoptr(resultp1,resultp2,dstptr);
2861da177e4SLinus Torvalds if (inexact)
2871da177e4SLinus Torvalds if (Is_inexacttrap_enabled())
2881da177e4SLinus Torvalds return(OVERFLOWEXCEPTION | INEXACTEXCEPTION);
2891da177e4SLinus Torvalds else Set_inexactflag();
2901da177e4SLinus Torvalds return(OVERFLOWEXCEPTION);
2911da177e4SLinus Torvalds }
2921da177e4SLinus Torvalds Set_overflowflag();
2931da177e4SLinus Torvalds /* set result to infinity or largest number */
2941da177e4SLinus Torvalds Dbl_setoverflow(resultp1,resultp2);
2951da177e4SLinus Torvalds inexact = TRUE;
2961da177e4SLinus Torvalds }
2971da177e4SLinus Torvalds /*
2981da177e4SLinus Torvalds * Test for underflow
2991da177e4SLinus Torvalds */
3001da177e4SLinus Torvalds else if (dest_exponent <= 0) {
3011da177e4SLinus Torvalds /* trap if UNDERFLOWTRAP enabled */
3021da177e4SLinus Torvalds if (Is_underflowtrap_enabled()) {
3031da177e4SLinus Torvalds /*
3041da177e4SLinus Torvalds * Adjust bias of result
3051da177e4SLinus Torvalds */
3061da177e4SLinus Torvalds Dbl_setwrapped_exponent(resultp1,dest_exponent,unfl);
3071da177e4SLinus Torvalds Dbl_copytoptr(resultp1,resultp2,dstptr);
3081da177e4SLinus Torvalds if (inexact)
3091da177e4SLinus Torvalds if (Is_inexacttrap_enabled())
3101da177e4SLinus Torvalds return(UNDERFLOWEXCEPTION | INEXACTEXCEPTION);
3111da177e4SLinus Torvalds else Set_inexactflag();
3121da177e4SLinus Torvalds return(UNDERFLOWEXCEPTION);
3131da177e4SLinus Torvalds }
3141da177e4SLinus Torvalds
3151da177e4SLinus Torvalds /* Determine if should set underflow flag */
3161da177e4SLinus Torvalds is_tiny = TRUE;
3171da177e4SLinus Torvalds if (dest_exponent == 0 && inexact) {
3181da177e4SLinus Torvalds switch (Rounding_mode()) {
3191da177e4SLinus Torvalds case ROUNDPLUS:
3201da177e4SLinus Torvalds if (Dbl_iszero_sign(resultp1)) {
3211da177e4SLinus Torvalds Dbl_increment(opnd3p1,opnd3p2);
3221da177e4SLinus Torvalds if (Dbl_isone_hiddenoverflow(opnd3p1))
3231da177e4SLinus Torvalds is_tiny = FALSE;
3241da177e4SLinus Torvalds Dbl_decrement(opnd3p1,opnd3p2);
3251da177e4SLinus Torvalds }
3261da177e4SLinus Torvalds break;
3271da177e4SLinus Torvalds case ROUNDMINUS:
3281da177e4SLinus Torvalds if (Dbl_isone_sign(resultp1)) {
3291da177e4SLinus Torvalds Dbl_increment(opnd3p1,opnd3p2);
3301da177e4SLinus Torvalds if (Dbl_isone_hiddenoverflow(opnd3p1))
3311da177e4SLinus Torvalds is_tiny = FALSE;
3321da177e4SLinus Torvalds Dbl_decrement(opnd3p1,opnd3p2);
3331da177e4SLinus Torvalds }
3341da177e4SLinus Torvalds break;
3351da177e4SLinus Torvalds case ROUNDNEAREST:
3361da177e4SLinus Torvalds if (guardbit && (stickybit ||
3371da177e4SLinus Torvalds Dbl_isone_lowmantissap2(opnd3p2))) {
3381da177e4SLinus Torvalds Dbl_increment(opnd3p1,opnd3p2);
3391da177e4SLinus Torvalds if (Dbl_isone_hiddenoverflow(opnd3p1))
3401da177e4SLinus Torvalds is_tiny = FALSE;
3411da177e4SLinus Torvalds Dbl_decrement(opnd3p1,opnd3p2);
3421da177e4SLinus Torvalds }
3431da177e4SLinus Torvalds break;
3441da177e4SLinus Torvalds }
3451da177e4SLinus Torvalds }
3461da177e4SLinus Torvalds
3471da177e4SLinus Torvalds /*
3481da177e4SLinus Torvalds * denormalize result or set to signed zero
3491da177e4SLinus Torvalds */
3501da177e4SLinus Torvalds stickybit = inexact;
3511da177e4SLinus Torvalds Dbl_denormalize(opnd3p1,opnd3p2,dest_exponent,guardbit,
3521da177e4SLinus Torvalds stickybit,inexact);
3531da177e4SLinus Torvalds
3541da177e4SLinus Torvalds /* return rounded number */
3551da177e4SLinus Torvalds if (inexact) {
3561da177e4SLinus Torvalds switch (Rounding_mode()) {
3571da177e4SLinus Torvalds case ROUNDPLUS:
3581da177e4SLinus Torvalds if (Dbl_iszero_sign(resultp1)) {
3591da177e4SLinus Torvalds Dbl_increment(opnd3p1,opnd3p2);
3601da177e4SLinus Torvalds }
3611da177e4SLinus Torvalds break;
3621da177e4SLinus Torvalds case ROUNDMINUS:
3631da177e4SLinus Torvalds if (Dbl_isone_sign(resultp1)) {
3641da177e4SLinus Torvalds Dbl_increment(opnd3p1,opnd3p2);
3651da177e4SLinus Torvalds }
3661da177e4SLinus Torvalds break;
3671da177e4SLinus Torvalds case ROUNDNEAREST:
3681da177e4SLinus Torvalds if (guardbit && (stickybit ||
3691da177e4SLinus Torvalds Dbl_isone_lowmantissap2(opnd3p2))) {
3701da177e4SLinus Torvalds Dbl_increment(opnd3p1,opnd3p2);
3711da177e4SLinus Torvalds }
3721da177e4SLinus Torvalds break;
3731da177e4SLinus Torvalds }
3741da177e4SLinus Torvalds if (is_tiny) Set_underflowflag();
3751da177e4SLinus Torvalds }
3761da177e4SLinus Torvalds Dbl_set_exponentmantissa(resultp1,resultp2,opnd3p1,opnd3p2);
3771da177e4SLinus Torvalds }
3781da177e4SLinus Torvalds else Dbl_set_exponent(resultp1,dest_exponent);
3791da177e4SLinus Torvalds Dbl_copytoptr(resultp1,resultp2,dstptr);
3801da177e4SLinus Torvalds
3811da177e4SLinus Torvalds /* check for inexact */
3821da177e4SLinus Torvalds if (inexact) {
3831da177e4SLinus Torvalds if (Is_inexacttrap_enabled()) return(INEXACTEXCEPTION);
3841da177e4SLinus Torvalds else Set_inexactflag();
3851da177e4SLinus Torvalds }
3861da177e4SLinus Torvalds return(NOEXCEPTION);
3871da177e4SLinus Torvalds }
388