0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "exception.h"
0015 #include "reg_constant.h"
0016 #include "fpu_emu.h"
0017 #include "fpu_system.h"
0018 #include "control_w.h"
0019 #include "poly.h"
0020
0021 #define HIPOWER 11
0022 static const unsigned long long lterms[HIPOWER] = {
0023 0x0000000000000000LL,
0024 0xf5fdeffc162c7543LL,
0025 0x1c6b08d704a0bfa6LL,
0026 0x0276556df749cc21LL,
0027 0x002bb0ffcf14f6b8LL,
0028 0x0002861225ef751cLL,
0029 0x00001ffcbfcd5422LL,
0030 0x00000162c005d5f1LL,
0031 0x0000000da96ccb1bLL,
0032 0x0000000078d1b897LL,
0033 0x000000000422b029LL
0034 };
0035
0036 static const Xsig hiterm = MK_XSIG(0xb17217f7, 0xd1cf79ab, 0xc8a39194);
0037
0038
0039
0040
0041 static const Xsig shiftterm0 = MK_XSIG(0, 0, 0);
0042 static const Xsig shiftterm1 = MK_XSIG(0x9837f051, 0x8db8a96f, 0x46ad2318);
0043 static const Xsig shiftterm2 = MK_XSIG(0xb504f333, 0xf9de6484, 0x597d89b3);
0044 static const Xsig shiftterm3 = MK_XSIG(0xd744fcca, 0xd69d6af4, 0x39a68bb9);
0045
0046 static const Xsig *shiftterm[] = { &shiftterm0, &shiftterm1,
0047 &shiftterm2, &shiftterm3
0048 };
0049
0050
0051
0052
0053 int poly_2xm1(u_char sign, FPU_REG *arg, FPU_REG *result)
0054 {
0055 long int exponent, shift;
0056 unsigned long long Xll;
0057 Xsig accumulator, Denom, argSignif;
0058 u_char tag;
0059
0060 exponent = exponent16(arg);
0061
0062 #ifdef PARANOID
0063 if (exponent >= 0) {
0064
0065 EXCEPTION(EX_INTERNAL | 0x127);
0066 return 1;
0067 }
0068 #endif
0069
0070 argSignif.lsw = 0;
0071 XSIG_LL(argSignif) = Xll = significand(arg);
0072
0073 if (exponent == -1) {
0074 shift = (argSignif.msw & 0x40000000) ? 3 : 2;
0075
0076 exponent -= 2;
0077 XSIG_LL(argSignif) <<= 2;
0078 Xll <<= 2;
0079 } else if (exponent == -2) {
0080 shift = 1;
0081
0082 exponent--;
0083 XSIG_LL(argSignif) <<= 1;
0084 Xll <<= 1;
0085 } else
0086 shift = 0;
0087
0088 if (exponent < -2) {
0089
0090 if (FPU_shrx(&Xll, -2 - exponent) >= 0x80000000U)
0091 Xll++;
0092 }
0093
0094 accumulator.lsw = accumulator.midw = accumulator.msw = 0;
0095 polynomial_Xsig(&accumulator, &Xll, lterms, HIPOWER - 1);
0096 mul_Xsig_Xsig(&accumulator, &argSignif);
0097 shr_Xsig(&accumulator, 3);
0098
0099 mul_Xsig_Xsig(&argSignif, &hiterm);
0100 add_two_Xsig(&accumulator, &argSignif, &exponent);
0101
0102 if (shift) {
0103
0104
0105
0106 shr_Xsig(&accumulator, -exponent);
0107 accumulator.msw |= 0x80000000;
0108 mul_Xsig_Xsig(&accumulator, shiftterm[shift]);
0109 accumulator.msw &= 0x3fffffff;
0110 exponent = 1;
0111 }
0112
0113 if (sign != SIGN_POS) {
0114
0115
0116
0117 Denom.lsw = accumulator.lsw;
0118 XSIG_LL(Denom) = XSIG_LL(accumulator);
0119 if (exponent < 0)
0120 shr_Xsig(&Denom, -exponent);
0121 else if (exponent > 0) {
0122
0123 XSIG_LL(Denom) <<= 1;
0124 if (Denom.lsw & 0x80000000)
0125 XSIG_LL(Denom) |= 1;
0126 (Denom.lsw) <<= 1;
0127 }
0128 Denom.msw |= 0x80000000;
0129 div_Xsig(&accumulator, &Denom, &accumulator);
0130 }
0131
0132
0133 exponent += round_Xsig(&accumulator);
0134
0135 result = &st(0);
0136 significand(result) = XSIG_LL(accumulator);
0137 setexponent16(result, exponent);
0138
0139 tag = FPU_round(result, 1, 0, FULL_PRECISION, sign);
0140
0141 setsign(result, sign);
0142 FPU_settag0(tag);
0143
0144 return 0;
0145
0146 }