diff --git a/bochs/fpu/f2xm1.cc b/bochs/fpu/f2xm1.cc index e5904ea3e..dc8becdd6 100644 --- a/bochs/fpu/f2xm1.cc +++ b/bochs/fpu/f2xm1.cc @@ -66,7 +66,7 @@ static float128 exp_arr[EXP_ARR_SIZE] = PACK_FLOAT_128(0x3fd6ae7f3e733b81, 0xf11d8656b0ee8cb0) /* 15 */ }; -extern float128 EvalPoly(float128 x, float128 *arr, unsigned n, float_status_t &status); +extern float128 EvalPoly(float128 x, float128 *arr, int n, float_status_t &status); /* required -1 < x < 1 */ static float128 poly_exp(float128 x, float_status_t &status) diff --git a/bochs/fpu/fpatan.cc b/bochs/fpu/fpatan.cc index 60ef35202..c6047f4ac 100644 --- a/bochs/fpu/fpatan.cc +++ b/bochs/fpu/fpatan.cc @@ -60,7 +60,7 @@ static float128 atan_arr[FPATAN_ARR_SIZE] = PACK_FLOAT_128(0x3ffa861861861861, 0x8618618618618618) /* 21 */ }; -extern float128 OddPoly(float128 x, float128 *arr, unsigned n, float_status_t &status); +extern float128 OddPoly(float128 x, float128 *arr, int n, float_status_t &status); /* |x| < 1/4 */ static float128 poly_atan(float128 x1, float_status_t &status) diff --git a/bochs/fpu/fsincos.cc b/bochs/fpu/fsincos.cc index 089ed402c..7db2c4b78 100644 --- a/bochs/fpu/fsincos.cc +++ b/bochs/fpu/fsincos.cc @@ -118,7 +118,7 @@ static float128 cos_arr[COS_ARR_SIZE] = PACK_FLOAT_128(0x3fc1e542ba402022, 0x507a9cad2bf8f0bb) /* 20 */ }; -extern float128 OddPoly (float128 x, float128 *arr, unsigned n, float_status_t &status); +extern float128 OddPoly (float128 x, float128 *arr, int n, float_status_t &status); /* 0 <= x <= pi/4 */ BX_CPP_INLINE float128 poly_sin(float128 x, float_status_t &status) @@ -146,7 +146,7 @@ BX_CPP_INLINE float128 poly_sin(float128 x, float_status_t &status) return OddPoly(x, sin_arr, SIN_ARR_SIZE, status); } -extern float128 EvenPoly(float128 x, float128 *arr, unsigned n, float_status_t &status); +extern float128 EvenPoly(float128 x, float128 *arr, int n, float_status_t &status); /* 0 <= x <= pi/4 */ BX_CPP_INLINE float128 poly_cos(float128 x, float_status_t &status) diff --git a/bochs/fpu/fyl2x.cc b/bochs/fpu/fyl2x.cc index d24c21141..598da6bdf 100644 --- a/bochs/fpu/fyl2x.cc +++ b/bochs/fpu/fyl2x.cc @@ -42,7 +42,7 @@ static const float128 float128_ln2inv2 = #define SQRT2_HALF_SIG BX_CONST64(0xb504f333f9de6484) -extern float128 OddPoly(float128 x, float128 *arr, unsigned n, float_status_t &status); +extern float128 OddPoly(float128 x, float128 *arr, int n, float_status_t &status); #define L2_ARR_SIZE 9 diff --git a/bochs/fpu/poly.cc b/bochs/fpu/poly.cc index 9926ee01a..555af9361 100644 --- a/bochs/fpu/poly.cc +++ b/bochs/fpu/poly.cc @@ -39,32 +39,16 @@ these four paragraphs for those parts of this code that are retained. // f(x) ~ [ p(x) + x * q(x) ] // -float128 EvalPoly(float128 x, float128 *arr, unsigned n, float_status_t &status) +float128 EvalPoly(float128 x, float128 *arr, int n, float_status_t &status) { - float128 x2 = float128_mul(x, x, status); - unsigned i; + float128 r = arr[--n]; - assert(n > 1); + do { + r = float128_mul(r, x, status); + r = float128_add(r, arr[--n], status); + } while (n > 0); - float128 r1 = arr[--n]; - i = n; - while(i >= 2) { - r1 = float128_mul(r1, x2, status); - i -= 2; - r1 = float128_add(r1, arr[i], status); - } - if (i) r1 = float128_mul(r1, x, status); - - float128 r2 = arr[--n]; - i = n; - while(i >= 2) { - r2 = float128_mul(r2, x2, status); - i -= 2; - r2 = float128_add(r2, arr[i], status); - } - if (i) r2 = float128_mul(r2, x, status); - - return float128_add(r1, r2, status); + return r; } // 2 4 6 8 2n @@ -79,7 +63,7 @@ float128 EvalPoly(float128 x, float128 *arr, unsigned n, float_status_t &status) // f(x) ~ [ p(x) + x * q(x) ] // -float128 EvenPoly(float128 x, float128 *arr, unsigned n, float_status_t &status) +float128 EvenPoly(float128 x, float128 *arr, int n, float_status_t &status) { return EvalPoly(float128_mul(x, x, status), arr, n, status); } @@ -99,7 +83,7 @@ float128 EvenPoly(float128 x, float128 *arr, unsigned n, float_status_t &status) // f(x) ~ x * [ p(x) + x * q(x) ] // -float128 OddPoly(float128 x, float128 *arr, unsigned n, float_status_t &status) +float128 OddPoly(float128 x, float128 *arr, int n, float_status_t &status) { return float128_mul(x, EvenPoly(x, arr, n, status), status); }