the work is derivative, and (2) the source code includes prominent notice with these four paragraphs for those parts of this code that are retained. =============================================================================*/ /*============================================================================ * Written for Bochs (x86 achitecture simulator) by * Stanislav Shwartsman [sshwarts at sourceforge net] * ==========================================================================*/ #define FLOAT128 #include "softfloatx80.h" #include "softfloat-round-pack.h" #include "fpu_constant.h" static const floatx80 floatx80_one = packFloatx80(0, 0x3fff, BX_CONST64(0x8000000000000000)); /* reduce trigonometric function argument using 128-bit precision M_PI approximation */ static Bit64u argument_reduction_kernel(Bit64u aSig0, int Exp, Bit64u *zSig0, Bit64u *zSig1) { Bit64u term0, term1, term2; Bit64u aSig1 = 0; shortShift128Left(aSig1, aSig0, Exp, &aSig1, &aSig0); Bit64u q = estimateDiv128To64(aSig1, aSig0, FLOAT_PI_HI); mul128By64To192(FLOAT_PI_HI, FLOAT_PI_LO, q, &term0, &term1, &term2); sub128(aSig1, aSig0, term0, term1, zSig1, zSig0); while ((Bit64s)(*zSig1) < 0) { --q; add192(*zSig1, *zSig0, term2, 0, FLOAT_PI_HI, FLOAT_PI_LO, zSig1, zSig0, &term2);
int ftan(floatx80 &a, float_status_t &status) { Bit64u aSig0, aSig1 = 0; Bit32s aExp, zExp, expDiff; int aSign, zSign; int q = 0; // handle unsupported extended double-precision floating encodings if (floatx80_is_unsupported(a)) { goto invalid; } aSig0 = extractFloatx80Frac(a); aExp = extractFloatx80Exp(a); aSign = extractFloatx80Sign(a); /* invalid argument */ if (aExp == 0x7FFF) { if ((Bit64u) (aSig0<<1)) { a = propagateFloatx80NaN(a, status); return 0; } invalid: float_raise(status, float_flag_invalid); a = floatx80_default_nan; return 0; } if (aExp == 0) { if (aSig0 == 0) return 0; float_raise(status, float_flag_denormal); /* handle pseudo denormals */ if (! (aSig0 & BX_CONST64(0x8000000000000000))) { float_raise(status, float_flag_inexact | float_flag_underflow); return 0; } normalizeFloatx80Subnormal(aSig0, &aExp, &aSig0); } zSign = aSign; zExp = EXP_BIAS; expDiff = aExp - zExp; /* argument is out-of-range */ if (expDiff >= 63) return -1; float_raise(status, float_flag_inexact); if (expDiff < -1) { // doesn't require reduction if (expDiff <= -68) { a = packFloatx80(aSign, aExp, aSig0); return 0; } zExp = aExp; } else { q = reduce_trig_arg(expDiff, zSign, aSig0, aSig1); } /* **************************** */ /* argument reduction completed */ /* **************************** */ /* using float128 for approximation */ float128 r = normalizeRoundAndPackFloat128(0, zExp-0x10, aSig0, aSig1, status); float128 sin_r = poly_sin(r, status); float128 cos_r = poly_cos(r, status); if (q & 0x1) { r = float128_div(cos_r, sin_r, status); zSign = ! zSign; } else { r = float128_div(sin_r, cos_r, status); } a = float128_to_floatx80(r, status); if (zSign) floatx80_chs(a); return 0; }
int floatx80_ftan(floatx80 &a) { UINT64 aSig0, aSig1 = 0; INT32 aExp, zExp, expDiff; int aSign, zSign; int q = 0; aSig0 = extractFloatx80Frac(a); aExp = extractFloatx80Exp(a); aSign = extractFloatx80Sign(a); /* invalid argument */ if (aExp == 0x7FFF) { if ((UINT64) (aSig0<<1)) { a = propagateFloatx80NaNOneArg(a); return 0; } float_raise(float_flag_invalid); a = floatx80_default_nan; return 0; } if (aExp == 0) { if (aSig0 == 0) return 0; // float_raise(float_flag_denormal); /* handle pseudo denormals */ if (! (aSig0 & U64(0x8000000000000000))) { float_raise(float_flag_inexact | float_flag_underflow); return 0; } normalizeFloatx80Subnormal(aSig0, &aExp, &aSig0); } zSign = aSign; zExp = EXP_BIAS; expDiff = aExp - zExp; /* argument is out-of-range */ if (expDiff >= 63) return -1; float_raise(float_flag_inexact); if (expDiff < -1) { // doesn't require reduction if (expDiff <= -68) { a = packFloatx80(aSign, aExp, aSig0); return 0; } zExp = aExp; } else { q = reduce_trig_arg(expDiff, zSign, aSig0, aSig1); } /* **************************** */ /* argument reduction completed */ /* **************************** */ /* using float128 for approximation */ float128 r = normalizeRoundAndPackFloat128(0, zExp-0x10, aSig0, aSig1); float128 sin_r = poly_sin(r); float128 cos_r = poly_cos(r); if (q & 0x1) { r = float128_div(cos_r, sin_r); zSign = ! zSign; } else { r = float128_div(sin_r, cos_r); } a = float128_to_floatx80(r); if (zSign) a = floatx80_chs(a); return 0; }
floatx80 floatx80_scale(floatx80 a, floatx80 b) { sbits32 aExp, bExp; bits64 aSig, bSig; // handle unsupported extended double-precision floating encodings /* if (floatx80_is_unsupported(a) || floatx80_is_unsupported(b)) { float_raise(float_flag_invalid); return floatx80_default_nan; }*/ aSig = extractFloatx80Frac(a); aExp = extractFloatx80Exp(a); int aSign = extractFloatx80Sign(a); bSig = extractFloatx80Frac(b); bExp = extractFloatx80Exp(b); int bSign = extractFloatx80Sign(b); if (aExp == 0x7FFF) { if ((bits64) (aSig<<1) || ((bExp == 0x7FFF) && (bits64) (bSig<<1))) { return propagateFloatx80NaN(a, b); } if ((bExp == 0x7FFF) && bSign) { float_raise(float_flag_invalid); return floatx80_default_nan; } if (bSig && (bExp == 0)) float_raise(float_flag_denormal); return a; } if (bExp == 0x7FFF) { if ((bits64) (bSig<<1)) return propagateFloatx80NaN(a, b); if ((aExp | aSig) == 0) { if (! bSign) { float_raise(float_flag_invalid); return floatx80_default_nan; } return a; } if (aSig && (aExp == 0)) float_raise(float_flag_denormal); if (bSign) return packFloatx80(aSign, 0, 0); return packFloatx80(aSign, 0x7FFF, U64(0x8000000000000000)); } if (aExp == 0) { if (aSig == 0) return a; float_raise(float_flag_denormal); normalizeFloatx80Subnormal(aSig, &aExp, &aSig); } if (bExp == 0) { if (bSig == 0) return a; float_raise(float_flag_denormal); normalizeFloatx80Subnormal(bSig, &bExp, &bSig); } if (bExp > 0x400E) { /* generate appropriate overflow/underflow */ return roundAndPackFloatx80(80, aSign, bSign ? -0x3FFF : 0x7FFF, aSig, 0); } if (bExp < 0x3FFF) return a; int shiftCount = 0x403E - bExp; bSig >>= shiftCount; sbits32 scale = bSig; if (bSign) scale = -scale; /* -32768..32767 */ return roundAndPackFloatx80(80, aSign, aExp+scale, aSig, 0); }
=============================================================================*/ /*============================================================================ * Written for Bochs (x86 achitecture simulator) by * Stanislav Shwartsman [sshwarts at sourceforge net] * ==========================================================================*/ #define FLOAT128 #define USE_estimateDiv128To64 #include "mamesf.h" #include "softfloat.h" //#include "softfloat-specialize" #include "fpu_constant.h" static const floatx80 floatx80_one = packFloatx80(0, 0x3fff, U64(0x8000000000000000)); static const floatx80 floatx80_default_nan = packFloatx80(0, 0xffff, U64(0xffffffffffffffff)); #define packFloat2x128m(zHi, zLo) {(zHi), (zLo)} #define PACK_FLOAT_128(hi,lo) packFloat2x128m(LIT64(hi),LIT64(lo)) #define EXP_BIAS 0x3FFF /*---------------------------------------------------------------------------- | Returns the fraction bits of the extended double-precision floating-point | value `a'. *----------------------------------------------------------------------------*/ INLINE bits64 extractFloatx80Frac( floatx80 a ) { return a.low;
int sf_fsincos(floatx80 a, floatx80 *sin_a, floatx80 *cos_a) { UINT64 aSig0, aSig1 = 0; INT32 aExp, zExp, expDiff; int aSign, zSign; int q = 0; aSig0 = extractFloatx80Frac(a); aExp = extractFloatx80Exp(a); aSign = extractFloatx80Sign(a); /* invalid argument */ if (aExp == 0x7FFF) { if ((UINT64) (aSig0<<1)) { sincos_invalid(sin_a, cos_a, propagateFloatx80NaNOneArg(a)); return 0; } float_raise(float_flag_invalid); sincos_invalid(sin_a, cos_a, floatx80_default_nan); return 0; } if (aExp == 0) { if (aSig0 == 0) { sincos_tiny_argument(sin_a, cos_a, a); return 0; } // float_raise(float_flag_denormal); /* handle pseudo denormals */ if (! (aSig0 & U64(0x8000000000000000))) { float_raise(float_flag_inexact); if (sin_a) float_raise(float_flag_underflow); sincos_tiny_argument(sin_a, cos_a, a); return 0; } normalizeFloatx80Subnormal(aSig0, &aExp, &aSig0); } zSign = aSign; zExp = EXP_BIAS; expDiff = aExp - zExp; /* argument is out-of-range */ if (expDiff >= 63) return -1; float_raise(float_flag_inexact); if (expDiff < -1) { // doesn't require reduction if (expDiff <= -68) { a = packFloatx80(aSign, aExp, aSig0); sincos_tiny_argument(sin_a, cos_a, a); return 0; } zExp = aExp; } else { q = reduce_trig_arg(expDiff, zSign, aSig0, aSig1); } /* **************************** */ /* argument reduction completed */ /* **************************** */ /* using float128 for approximation */ float128 r = normalizeRoundAndPackFloat128(0, zExp-0x10, aSig0, aSig1); if (aSign) q = -q; if (sin_a) *sin_a = sincos_approximation(zSign, r, q); if (cos_a) *cos_a = sincos_approximation(zSign, r, q+1); return 0; }
static floatx80 fyl2x(floatx80 a, floatx80 b) { UINT64 aSig = extractFloatx80Frac(a); INT32 aExp = extractFloatx80Exp(a); int aSign = extractFloatx80Sign(a); UINT64 bSig = extractFloatx80Frac(b); INT32 bExp = extractFloatx80Exp(b); int bSign = extractFloatx80Sign(b); int zSign = bSign ^ 1; if (aExp == 0x7FFF) { if ((UINT64) (aSig<<1) || ((bExp == 0x7FFF) && (UINT64) (bSig<<1))) { return propagateFloatx80NaN(a, b); } if (aSign) { invalid: float_raise(float_flag_invalid); return floatx80_default_nan; } else { if (bExp == 0) { if (bSig == 0) goto invalid; float_raise(float_flag_denormal); } return packFloatx80(bSign, 0x7FFF, U64(0x8000000000000000)); } } if (bExp == 0x7FFF) { if ((UINT64) (bSig<<1)) return propagateFloatx80NaN(a, b); if (aSign && (UINT64)(aExp | aSig)) goto invalid; if (aSig && (aExp == 0)) float_raise(float_flag_denormal); if (aExp < 0x3FFF) { return packFloatx80(zSign, 0x7FFF, U64(0x8000000000000000)); } if (aExp == 0x3FFF && ((UINT64) (aSig<<1) == 0)) goto invalid; return packFloatx80(bSign, 0x7FFF, U64(0x8000000000000000)); } if (aExp == 0) { if (aSig == 0) { if ((bExp | bSig) == 0) goto invalid; float_raise(float_flag_divbyzero); return packFloatx80(zSign, 0x7FFF, U64(0x8000000000000000)); } if (aSign) goto invalid; float_raise(float_flag_denormal); normalizeFloatx80Subnormal(aSig, &aExp, &aSig); } if (aSign) goto invalid; if (bExp == 0) { if (bSig == 0) { if (aExp < 0x3FFF) return packFloatx80(zSign, 0, 0); return packFloatx80(bSign, 0, 0); } float_raise(float_flag_denormal); normalizeFloatx80Subnormal(bSig, &bExp, &bSig); } if (aExp == 0x3FFF && ((UINT64) (aSig<<1) == 0)) return packFloatx80(bSign, 0, 0); float_raise(float_flag_inexact); int ExpDiff = aExp - 0x3FFF; aExp = 0; if (aSig >= SQRT2_HALF_SIG) { ExpDiff++; aExp--; } /* ******************************** */ /* using float128 for approximation */ /* ******************************** */ UINT64 zSig0, zSig1; shift128Right(aSig<<1, 0, 16, &zSig0, &zSig1); float128 x = packFloat128(0, aExp+0x3FFF, zSig0, zSig1); x = poly_l2(x); x = float128_add(x, int64_to_float128((INT64) ExpDiff)); return floatx80_mul(b, float128_to_floatx80(x)); }
floatx80 fyl2xp1(floatx80 a, floatx80 b) { INT32 aExp, bExp; UINT64 aSig, bSig, zSig0, zSig1, zSig2; int aSign, bSign; aSig = extractFloatx80Frac(a); aExp = extractFloatx80Exp(a); aSign = extractFloatx80Sign(a); bSig = extractFloatx80Frac(b); bExp = extractFloatx80Exp(b); bSign = extractFloatx80Sign(b); int zSign = aSign ^ bSign; if (aExp == 0x7FFF) { if ((UINT64) (aSig<<1) || ((bExp == 0x7FFF) && (UINT64) (bSig<<1))) { return propagateFloatx80NaN(a, b); } if (aSign) { invalid: float_raise(float_flag_invalid); return floatx80_default_nan; } else { if (bExp == 0) { if (bSig == 0) goto invalid; float_raise(float_flag_denormal); } return packFloatx80(bSign, 0x7FFF, U64(0x8000000000000000)); } } if (bExp == 0x7FFF) { if ((UINT64) (bSig<<1)) return propagateFloatx80NaN(a, b); if (aExp == 0) { if (aSig == 0) goto invalid; float_raise(float_flag_denormal); } return packFloatx80(zSign, 0x7FFF, U64(0x8000000000000000)); } if (aExp == 0) { if (aSig == 0) { if (bSig && (bExp == 0)) float_raise(float_flag_denormal); return packFloatx80(zSign, 0, 0); } float_raise(float_flag_denormal); normalizeFloatx80Subnormal(aSig, &aExp, &aSig); } if (bExp == 0) { if (bSig == 0) return packFloatx80(zSign, 0, 0); float_raise(float_flag_denormal); normalizeFloatx80Subnormal(bSig, &bExp, &bSig); } float_raise(float_flag_inexact); if (aSign && aExp >= 0x3FFF) return a; if (aExp >= 0x3FFC) // big argument { return fyl2x(floatx80_add(a, floatx80_one), b); } // handle tiny argument if (aExp < EXP_BIAS-70) { // first order approximation, return (a*b)/ln(2) INT32 zExp = aExp + FLOAT_LN2INV_EXP - 0x3FFE; mul128By64To192(FLOAT_LN2INV_HI, FLOAT_LN2INV_LO, aSig, &zSig0, &zSig1, &zSig2); if (0 < (INT64) zSig0) { shortShift128Left(zSig0, zSig1, 1, &zSig0, &zSig1); --zExp; } zExp = zExp + bExp - 0x3FFE; mul128By64To192(zSig0, zSig1, bSig, &zSig0, &zSig1, &zSig2); if (0 < (INT64) zSig0) { shortShift128Left(zSig0, zSig1, 1, &zSig0, &zSig1); --zExp; } return roundAndPackFloatx80(80, aSign ^ bSign, zExp, zSig0, zSig1); } /* ******************************** */ /* using float128 for approximation */ /* ******************************** */ shift128Right(aSig<<1, 0, 16, &zSig0, &zSig1); float128 x = packFloat128(aSign, aExp, zSig0, zSig1); x = poly_l2p1(x); return floatx80_mul(b, float128_to_floatx80(x)); }
* Stanislav Shwartsman [sshwarts at sourceforge net] * Adapted for lib/softfloat in MESS by Hans Ostermeyer (03/2012) * ==========================================================================*/ #define FLOAT128 #define USE_estimateDiv128To64 #include "mamesf.h" #include "softfloat.h" //#include "softfloat-specialize" #include "fpu_constant.h" // FIXME: #define float_flag_denormal float_flag_invalid static const floatx80 floatx80_log10_2 = packFloatx80(0, 0x3ffd, U64(0x9a209a84fbcff798)); static const floatx80 floatx80_ln_2 = packFloatx80(0, 0x3ffe, U64(0xb17217f7d1cf79ac)); static const floatx80 floatx80_one = packFloatx80(0, 0x3fff, U64(0x8000000000000000)); static const floatx80 floatx80_default_nan = packFloatx80(0, 0xffff, U64(0xffffffffffffffff)); #define packFloat_128(zHi, zLo) {(zHi), (zLo)} #define PACK_FLOAT_128(hi,lo) packFloat_128(LIT64(hi),LIT64(lo)) #define EXP_BIAS 0x3FFF /*---------------------------------------------------------------------------- | Returns the fraction bits of the extended double-precision floating-point | value `a'. *----------------------------------------------------------------------------*/ INLINE bits64 extractFloatx80Frac( floatx80 a )
floatx80 fpatan(floatx80 a, floatx80 b, float_status_t &status) { // handle unsupported extended double-precision floating encodings if (floatx80_is_unsupported(a) || floatx80_is_unsupported(b)) { float_raise(status, float_flag_invalid); return floatx80_default_nan; } Bit64u aSig = extractFloatx80Frac(a); Bit32s aExp = extractFloatx80Exp(a); int aSign = extractFloatx80Sign(a); Bit64u bSig = extractFloatx80Frac(b); Bit32s bExp = extractFloatx80Exp(b); int bSign = extractFloatx80Sign(b); int zSign = aSign ^ bSign; if (bExp == 0x7FFF) { if ((Bit64u) (bSig<<1)) return propagateFloatx80NaN(a, b, status); if (aExp == 0x7FFF) { if ((Bit64u) (aSig<<1)) return propagateFloatx80NaN(a, b, status); if (aSign) { /* return 3PI/4 */ return roundAndPackFloatx80(80, bSign, FLOATX80_3PI4_EXP, FLOAT_3PI4_HI, FLOAT_3PI4_LO, status); } else { /* return PI/4 */ return roundAndPackFloatx80(80, bSign, FLOATX80_PI4_EXP, FLOAT_PI_HI, FLOAT_PI_LO, status); } } if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); /* return PI/2 */ return roundAndPackFloatx80(80, bSign, FLOATX80_PI2_EXP, FLOAT_PI_HI, FLOAT_PI_LO, status); } if (aExp == 0x7FFF) { if ((Bit64u) (aSig<<1)) return propagateFloatx80NaN(a, b, status); if (bSig && (bExp == 0)) float_raise(status, float_flag_denormal); return_PI_or_ZERO: if (aSign) { /* return PI */ return roundAndPackFloatx80(80, bSign, FLOATX80_PI_EXP, FLOAT_PI_HI, FLOAT_PI_LO, status); } else { /* return 0 */ return packFloatx80(bSign, 0, 0); } } if (bExp == 0) { if (bSig == 0) { if (aSig && (aExp == 0)) float_raise(status, float_flag_denormal); goto return_PI_or_ZERO; } float_raise(status, float_flag_denormal); normalizeFloatx80Subnormal(bSig, &bExp, &bSig); } if (aExp == 0) { if (aSig == 0) /* return PI/2 */ return roundAndPackFloatx80(80, bSign, FLOATX80_PI2_EXP, FLOAT_PI_HI, FLOAT_PI_LO, status); float_raise(status, float_flag_denormal); normalizeFloatx80Subnormal(aSig, &aExp, &aSig); } float_raise(status, float_flag_inexact); /* |a| = |b| ==> return PI/4 */ if (aSig == bSig && aExp == bExp) return roundAndPackFloatx80(80, bSign, FLOATX80_PI4_EXP, FLOAT_PI_HI, FLOAT_PI_LO, status); /* ******************************** */ /* using float128 for approximation */ /* ******************************** */ float128 a128 = normalizeRoundAndPackFloat128(0, aExp-0x10, aSig, 0, status); float128 b128 = normalizeRoundAndPackFloat128(0, bExp-0x10, bSig, 0, status); float128 x; int swap = 0, add_pi6 = 0, add_pi4 = 0; if (aExp > bExp || (aExp == bExp && aSig > bSig)) { x = float128_div(b128, a128, status); } else { x = float128_div(a128, b128, status); swap = 1; } Bit32s xExp = extractFloat128Exp(x); if (xExp <= EXP_BIAS-40) goto approximation_completed; if (x.hi >= BX_CONST64(0x3ffe800000000000)) // 3/4 < x < 1 { /* arctan(x) = arctan((x-1)/(x+1)) + pi/4 */ float128 t1 = float128_sub(x, float128_one, status); float128 t2 = float128_add(x, float128_one, status); x = float128_div(t1, t2, status); add_pi4 = 1; } else { /* argument correction */ if (xExp >= 0x3FFD) // 1/4 < x < 3/4 { /* arctan(x) = arctan((x*sqrt(3)-1)/(x+sqrt(3))) + pi/6 */ float128 t1 = float128_mul(x, float128_sqrt3, status); float128 t2 = float128_add(x, float128_sqrt3, status); x = float128_sub(t1, float128_one, status); x = float128_div(x, t2, status); add_pi6 = 1; } } x = poly_atan(x, status); if (add_pi6) x = float128_add(x, float128_pi6, status); if (add_pi4) x = float128_add(x, float128_pi4, status); approximation_completed: if (swap) x = float128_sub(float128_pi2, x, status); floatx80 result = float128_to_floatx80(x, status); if (zSign) floatx80_chs(result); int rSign = extractFloatx80Sign(result); if (!bSign && rSign) return floatx80_add(result, floatx80_pi, status); if (bSign && !rSign) return floatx80_sub(result, floatx80_pi, status); return result; }
* ==========================================================================*/ #define FLOAT128 #include "softfloatx80.h" #include "softfloat-round-pack.h" #include "fpu_constant.h" #define FPATAN_ARR_SIZE 11 static const float128 float128_one = packFloat128(BX_CONST64(0x3fff000000000000), BX_CONST64(0x0000000000000000)); static const float128 float128_sqrt3 = packFloat128(BX_CONST64(0x3fffbb67ae8584ca), BX_CONST64(0xa73b25742d7078b8)); static const floatx80 floatx80_pi = packFloatx80(0, 0x4000, BX_CONST64(0xc90fdaa22168c235)); static const float128 float128_pi2 = packFloat128(BX_CONST64(0x3fff921fb54442d1), BX_CONST64(0x8469898CC5170416)); static const float128 float128_pi4 = packFloat128(BX_CONST64(0x3ffe921fb54442d1), BX_CONST64(0x8469898CC5170416)); static const float128 float128_pi6 = packFloat128(BX_CONST64(0x3ffe0c152382d736), BX_CONST64(0x58465BB32E0F580F)); static float128 atan_arr[FPATAN_ARR_SIZE] = { PACK_FLOAT_128(0x3fff000000000000, 0x0000000000000000), /* 1 */ PACK_FLOAT_128(0xbffd555555555555, 0x5555555555555555), /* 3 */ PACK_FLOAT_128(0x3ffc999999999999, 0x999999999999999a), /* 5 */ PACK_FLOAT_128(0xbffc249249249249, 0x2492492492492492), /* 7 */ PACK_FLOAT_128(0x3ffbc71c71c71c71, 0xc71c71c71c71c71c), /* 9 */
// You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ///////////////////////////////////////////////////////////////////////// #define NEED_CPU_REG_SHORTCUTS 1 #include "bochs.h" #include "cpu/cpu.h" #define LOG_THIS BX_CPU_THIS_PTR #if BX_SUPPORT_FPU #include "softfloatx80.h" const floatx80 Const_QNaN = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction); const floatx80 Const_Z = packFloatx80(0, 0x0000, 0); const floatx80 Const_1 = packFloatx80(0, 0x3fff, BX_CONST64(0x8000000000000000)); const floatx80 Const_L2T = packFloatx80(0, 0x4000, BX_CONST64(0xd49a784bcd1b8afe)); const floatx80 Const_L2E = packFloatx80(0, 0x3fff, BX_CONST64(0xb8aa3b295c17f0bc)); const floatx80 Const_PI = packFloatx80(0, 0x4000, BX_CONST64(0xc90fdaa22168c235)); const floatx80 Const_LG2 = packFloatx80(0, 0x3ffd, BX_CONST64(0x9a209a84fbcff799)); const floatx80 Const_LN2 = packFloatx80(0, 0x3ffe, BX_CONST64(0xb17217f7d1cf79ac)); const floatx80 Const_INF = packFloatx80(0, 0x7fff, BX_CONST64(0x8000000000000000)); /* A fast way to find out whether x is one of RC_DOWN or RC_CHOP (and not one of RC_RND or RC_UP). */ #define DOWN_OR_CHOP() (FPU_CONTROL_WORD & FPU_CW_RC & FPU_RC_DOWN) BX_CPP_INLINE floatx80 FPU_round_const(const floatx80 &a, int adj)
static floatx80 do_fprem(floatx80 a, floatx80 b, Bit64u &q, int rounding_mode, float_status_t &status) { Bit32s aExp, bExp, zExp, expDiff; Bit64u aSig0, aSig1, bSig; int aSign; q = 0; // handle unsupported extended double-precision floating encodings if (floatx80_is_unsupported(a) || floatx80_is_unsupported(b)) { float_raise(status, float_flag_invalid); return floatx80_default_nan; } aSig0 = extractFloatx80Frac(a); aExp = extractFloatx80Exp(a); aSign = extractFloatx80Sign(a); bSig = extractFloatx80Frac(b); bExp = extractFloatx80Exp(b); if (aExp == 0x7FFF) { if ((Bit64u) (aSig0<<1) || ((bExp == 0x7FFF) && (Bit64u) (bSig<<1))) { return propagateFloatx80NaN(a, b, status); } goto invalid; } if (bExp == 0x7FFF) { if ((Bit64u) (bSig<<1)) return propagateFloatx80NaN(a, b, status); return a; } if (bExp == 0) { if (bSig == 0) { invalid: float_raise(status, float_flag_invalid); return floatx80_default_nan; } float_raise(status, float_flag_denormal); normalizeFloatx80Subnormal(bSig, &bExp, &bSig); } if (aExp == 0) { if ((Bit64u) (aSig0<<1) == 0) return a; float_raise(status, float_flag_denormal); normalizeFloatx80Subnormal(aSig0, &aExp, &aSig0); } expDiff = aExp - bExp; aSig1 = 0; if (expDiff >= 64) { int n = (expDiff & 0x1f) | 0x20; remainder_kernel(aSig0, bSig, n, &aSig0, &aSig1); zExp = aExp - n; q = (Bit64u) -1; } else { zExp = bExp; if (expDiff < 0) { if (expDiff < -1) return (a.fraction & BX_CONST64(0x8000000000000000)) ? packFloatx80(aSign, aExp, aSig0) : a; shift128Right(aSig0, 0, 1, &aSig0, &aSig1); expDiff = 0; } if (expDiff > 0) { q = remainder_kernel(aSig0, bSig, expDiff, &aSig0, &aSig1); } else { if (bSig <= aSig0) { aSig0 -= bSig; q = 1; } } if (rounding_mode == float_round_nearest_even) { Bit64u term0, term1; shift128Right(bSig, 0, 1, &term0, &term1); if (! lt128(aSig0, aSig1, term0, term1)) { int lt = lt128(term0, term1, aSig0, aSig1); int eq = eq128(aSig0, aSig1, term0, term1); if ((eq && (q & 1)) || lt) { aSign = !aSign; ++q; } if (lt) sub128(bSig, 0, aSig0, aSig1, &aSig0, &aSig1); } } } return normalizeRoundAndPackFloatx80(80, aSign, zExp, aSig0, aSig1, status); }