Apply an opimization for the kernels used by cexp(x) and cexpf(x) submitted

by Steve Kargl:

- Use sincos[f] instead of a call to cos[f] and a call to sin[f].

- While here, alphabetize declaration.

Submitted by:   sgk at troutmask.apl.washington.edu (Steve Kargl)
This commit is contained in:
Stefan Eßer 2020-09-20 05:32:53 +00:00
parent a67cc94327
commit fcce470c2b
2 changed files with 8 additions and 6 deletions

View File

@ -88,7 +88,7 @@ __ldexp_exp(double x, int expt)
double complex double complex
__ldexp_cexp(double complex z, int expt) __ldexp_cexp(double complex z, int expt)
{ {
double x, y, exp_x, scale1, scale2; double c, exp_x, s, scale1, scale2, x, y;
int ex_expt, half_expt; int ex_expt, half_expt;
x = creal(z); x = creal(z);
@ -105,6 +105,7 @@ __ldexp_cexp(double complex z, int expt)
half_expt = expt - half_expt; half_expt = expt - half_expt;
INSERT_WORDS(scale2, (0x3ff + half_expt) << 20, 0); INSERT_WORDS(scale2, (0x3ff + half_expt) << 20, 0);
return (CMPLX(cos(y) * exp_x * scale1 * scale2, sincos(y, &s, &c);
sin(y) * exp_x * scale1 * scale2)); return (CMPLX(c * exp_x * scale1 * scale2,
s * exp_x * scale1 * scale2));
} }

View File

@ -71,7 +71,7 @@ __ldexp_expf(float x, int expt)
float complex float complex
__ldexp_cexpf(float complex z, int expt) __ldexp_cexpf(float complex z, int expt)
{ {
float x, y, exp_x, scale1, scale2; float c, exp_x, s, scale1, scale2, x, y;
int ex_expt, half_expt; int ex_expt, half_expt;
x = crealf(z); x = crealf(z);
@ -84,6 +84,7 @@ __ldexp_cexpf(float complex z, int expt)
half_expt = expt - half_expt; half_expt = expt - half_expt;
SET_FLOAT_WORD(scale2, (0x7f + half_expt) << 23); SET_FLOAT_WORD(scale2, (0x7f + half_expt) << 23);
return (CMPLXF(cosf(y) * exp_x * scale1 * scale2, sincosf(y, &s, &c);
sinf(y) * exp_x * scale1 * scale2)); return (CMPLXF(c * exp_x * scale1 * scale2,
s * exp_x * scale1 * scale2));
} }