simplify x87 polinoms evaluation code

This commit is contained in:
Stanislav Shwartsman 2011-12-16 19:22:03 +00:00
parent 982064bc5a
commit 83cf658361
5 changed files with 14 additions and 30 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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);
}