This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
GNU C Library master sources branch master updated. glibc-2.18-679-g392dd2d
- From: siddhesh at sourceware dot org
- To: glibc-cvs at sourceware dot org
- Date: 20 Dec 2013 10:32:39 -0000
- Subject: GNU C Library master sources branch master updated. glibc-2.18-679-g392dd2d
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".
The branch, master has been updated
via 392dd2de03c054b1b32358561570be14f55e9ae9 (commit)
via 84ba214c2197586bc80631dd6d6110a3bbaab7bf (commit)
via 975195e4668575d5c53fbf5223501c26ee8dc20e (commit)
via 5ff8d60ef324b9666c92fc342d143e8074043cd1 (commit)
from 64a17f1adde4715bb6607f64decd73b2df9e6852 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=392dd2de03c054b1b32358561570be14f55e9ae9
commit 392dd2de03c054b1b32358561570be14f55e9ae9
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date: Fri Dec 20 16:01:03 2013 +0530
Consolidate code to compute sin and cos from lookup tables
This patch consolidates the multiple copies of code that looks up sin
and cos of a number from the lookup table and computes the final
value, into static functions. This does not have a noticeable
performance impact since the functions are inlined by gcc.
There is further scope for consolidation in the functions but they
cause a more noticable impact on performance (>5%) due to which I have
held back on them.
diff --git a/ChangeLog b/ChangeLog
index 260cd28..0ecde29 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2013-12-20 Siddhesh Poyarekar <siddhesh@redhat.com>
+ * sysdeps/ieee754/dbl-64/s_sin.c (do_cos, do_cos_slow, do_sin,
+ do_sin_slow): New functions.
+ (__sin, __cos, slow1, slow2, sloww1, sloww2, bsloww1, bsloww2,
+ cslow2, csloww1, csloww2): Use the new functions.
+
* sysdeps/ieee754/dbl-64/s_sin.c (sloww1): Add new argument M.
Use M to change sign of result instead of X. Assume X is
positive.
diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c
index 0033f94..bd2346c 100644
--- a/sysdeps/ieee754/dbl-64/s_sin.c
+++ b/sysdeps/ieee754/dbl-64/s_sin.c
@@ -145,6 +145,102 @@ static double csloww (double x, double dx, double orig);
static double csloww1 (double x, double dx, double orig, int m);
static double csloww2 (double x, double dx, double orig, int n);
+/* Given a number partitioned into U and X such that U is an index into the
+ sin/cos table, this macro computes the cosine of the number by combining
+ the sin and cos of X (as computed by a variation of the Taylor series) with
+ the values looked up from the sin/cos table to get the result in RES and a
+ correction value in COR. */
+static double
+do_cos (mynumber u, double x, double *corp)
+{
+ double xx, s, sn, ssn, c, cs, ccs, res, cor;
+ xx = x * x;
+ s = x + x * xx * (sn3 + xx * sn5);
+ c = xx * (cs2 + xx * (cs4 + xx * cs6));
+ SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
+ cor = (ccs - s * ssn - cs * c) - sn * s;
+ res = cs + cor;
+ cor = (cs - res) + cor;
+ *corp = cor;
+ return res;
+}
+
+/* A more precise variant of DO_COS where the number is partitioned into U, X
+ and DX. EPS is the adjustment to the correction COR. */
+static double
+do_cos_slow (mynumber u, double x, double dx, double eps, double *corp)
+{
+ double xx, y, x1, x2, e1, e2, res, cor;
+ double s, sn, ssn, c, cs, ccs;
+ xx = x * x;
+ s = x * xx * (sn3 + xx * sn5);
+ c = x * dx + xx * (cs2 + xx * (cs4 + xx * cs6));
+ SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
+ x1 = (x + t22) - t22;
+ x2 = (x - x1) + dx;
+ e1 = (sn + t22) - t22;
+ e2 = (sn - e1) + ssn;
+ cor = (ccs - cs * c - e1 * x2 - e2 * x) - sn * s;
+ y = cs - e1 * x1;
+ cor = cor + ((cs - y) - e1 * x1);
+ res = y + cor;
+ cor = (y - res) + cor;
+ if (cor > 0)
+ cor = 1.0005 * cor + eps;
+ else
+ cor = 1.0005 * cor - eps;
+ *corp = cor;
+ return res;
+}
+
+/* Given a number partitioned into U and X and DX such that U is an index into
+ the sin/cos table, this macro computes the sine of the number by combining
+ the sin and cos of X (as computed by a variation of the Taylor series) with
+ the values looked up from the sin/cos table to get the result in RES and a
+ correction value in COR. */
+static double
+do_sin (mynumber u, double x, double dx, double *corp)
+{
+ double xx, s, sn, ssn, c, cs, ccs, cor, res;
+ xx = x * x;
+ s = x + (dx + x * xx * (sn3 + xx * sn5));
+ c = x * dx + xx * (cs2 + xx * (cs4 + xx * cs6));
+ SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
+ cor = (ssn + s * ccs - sn * c) + cs * s;
+ res = sn + cor;
+ cor = (sn - res) + cor;
+ *corp = cor;
+ return res;
+}
+
+/* A more precise variant of res = do_sin where the number is partitioned into U, X
+ and DX. EPS is the adjustment to the correction COR. */
+static double
+do_sin_slow (mynumber u, double x, double dx, double eps, double *corp)
+{
+ double xx, y, x1, x2, c1, c2, res, cor;
+ double s, sn, ssn, c, cs, ccs;
+ xx = x * x;
+ s = x * xx * (sn3 + xx * sn5);
+ c = xx * (cs2 + xx * (cs4 + xx * cs6));
+ SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
+ x1 = (x + t22) - t22;
+ x2 = (x - x1) + dx;
+ c1 = (cs + t22) - t22;
+ c2 = (cs - c1) + ccs;
+ cor = (ssn + s * ccs + cs * s + c2 * x + c1 * x2 - sn * x * dx) - sn * c;
+ y = sn + c1 * x1;
+ cor = cor + ((sn - y) + c1 * x1);
+ res = y + cor;
+ cor = (y - res) + cor;
+ if (cor > 0)
+ cor = 1.0005 * cor + eps;
+ else
+ cor = 1.0005 * cor - eps;
+ *corp = cor;
+ return res;
+}
+
/* Reduce range of X and compute sin of a + da. K is the amount by which to
rotate the quadrants. This allows us to use the same routine to compute cos
by simply rotating the quadrants by 1. */
@@ -244,13 +340,7 @@ __sin (double x)
u.x = big - y;
y = (-hp1) - (y + (u.x - big));
}
- xx = y * y;
- s = y + y * xx * (sn3 + xx * sn5);
- c = xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- cor = (ccs - s * ssn - cs * c) - sn * s;
- res = cs + cor;
- cor = (cs - res) + cor;
+ res = do_cos (u, y, &cor);
retval = (res == res + 1.020 * cor) ? ((m > 0) ? res : -res) : slow2 (x);
} /* else if (k < 0x400368fd) */
@@ -296,13 +386,7 @@ __sin (double x)
}
u.x = big + a;
y = a - (u.x - big);
- xx = y * y;
- s = y + (da + y * xx * (sn3 + xx * sn5));
- c = y * da + xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- cor = (ssn + s * ccs - sn * c) + cs * s;
- res = sn + cor;
- cor = (sn - res) + cor;
+ res = do_sin (u, y, da, &cor);
cor = (cor > 0) ? 1.035 * cor + eps : 1.035 * cor - eps;
retval = ((res == res + cor) ? ((m) ? res : -res)
: sloww1 (a, da, x, m));
@@ -318,13 +402,7 @@ __sin (double x)
}
u.x = big + a;
y = a - (u.x - big) + da;
- xx = y * y;
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- s = y + y * xx * (sn3 + xx * sn5);
- c = xx * (cs2 + xx * (cs4 + xx * cs6));
- cor = (ccs - s * ssn - cs * c) - sn * s;
- res = cs + cor;
- cor = (cs - res) + cor;
+ res = do_cos (u, y, &cor);
cor = (cor > 0) ? 1.025 * cor + eps : 1.025 * cor - eps;
retval = ((res == res + cor) ? ((n & 2) ? -res : res)
: sloww2 (a, da, x, n));
@@ -382,13 +460,7 @@ __sin (double x)
}
u.x = big + a;
y = a - (u.x - big);
- xx = y * y;
- s = y + (db + y * xx * (sn3 + xx * sn5));
- c = y * db + xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- cor = (ssn + s * ccs - sn * c) + cs * s;
- res = sn + cor;
- cor = (sn - res) + cor;
+ res = do_sin (u, y, db, &cor);
cor = (cor > 0) ? 1.035 * cor + eps : 1.035 * cor - eps;
retval = ((res == res + cor) ? ((m) ? res : -res)
: bsloww1 (a, da, x, n));
@@ -404,13 +476,7 @@ __sin (double x)
}
u.x = big + a;
y = a - (u.x - big) + da;
- xx = y * y;
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- s = y + y * xx * (sn3 + xx * sn5);
- c = xx * (cs2 + xx * (cs4 + xx * cs6));
- cor = (ccs - s * ssn - cs * c) - sn * s;
- res = cs + cor;
- cor = (cs - res) + cor;
+ res = do_cos (u, y, &cor);
cor = (cor > 0) ? 1.025 * cor + eps : 1.025 * cor - eps;
retval = ((res == res + cor) ? ((n & 2) ? -res : res)
: bsloww2 (a, da, x, n));
@@ -443,7 +509,7 @@ double
SECTION
__cos (double x)
{
- double y, xx, res, t, cor, s, c, sn, ssn, cs, ccs, xn, a, da, db, eps, xn1,
+ double y, xx, res, t, cor, xn, a, da, db, eps, xn1,
xn2;
mynumber u, v;
int4 k, m, n;
@@ -465,13 +531,7 @@ __cos (double x)
y = ABS (x);
u.x = big + y;
y = y - (u.x - big);
- xx = y * y;
- s = y + y * xx * (sn3 + xx * sn5);
- c = xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- cor = (ccs - s * ssn - cs * c) - sn * s;
- res = cs + cor;
- cor = (cs - res) + cor;
+ res = do_cos (u, y, &cor);
retval = (res == res + 1.020 * cor) ? res : cslow2 (x);
} /* else if (k < 0x3feb6000) */
@@ -501,13 +561,7 @@ __cos (double x)
}
u.x = big + a;
y = a - (u.x - big);
- xx = y * y;
- s = y + (da + y * xx * (sn3 + xx * sn5));
- c = y * da + xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- cor = (ssn + s * ccs - sn * c) + cs * s;
- res = sn + cor;
- cor = (sn - res) + cor;
+ res = do_sin (u, y, da, &cor);
cor = (cor > 0) ? 1.035 * cor + 1.0e-31 : 1.035 * cor - 1.0e-31;
retval = ((res == res + cor) ? ((m) ? res : -res)
: csloww1 (a, da, x, m));
@@ -558,13 +612,7 @@ __cos (double x)
}
u.x = big + a;
y = a - (u.x - big);
- xx = y * y;
- s = y + (da + y * xx * (sn3 + xx * sn5));
- c = y * da + xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- cor = (ssn + s * ccs - sn * c) + cs * s;
- res = sn + cor;
- cor = (sn - res) + cor;
+ res = do_sin (u, y, da, &cor);
cor = (cor > 0) ? 1.035 * cor + eps : 1.035 * cor - eps;
retval = ((res == res + cor) ? ((m) ? res : -res)
: csloww1 (a, da, x, m));
@@ -580,13 +628,7 @@ __cos (double x)
}
u.x = big + a;
y = a - (u.x - big) + da;
- xx = y * y;
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- s = y + y * xx * (sn3 + xx * sn5);
- c = xx * (cs2 + xx * (cs4 + xx * cs6));
- cor = (ccs - s * ssn - cs * c) - sn * s;
- res = cs + cor;
- cor = (cs - res) + cor;
+ res = do_cos (u, y, &cor);
cor = (cor > 0) ? 1.025 * cor + eps : 1.025 * cor - eps;
retval = ((res == res + cor) ? ((n) ? -res : res)
: csloww2 (a, da, x, n));
@@ -642,13 +684,7 @@ __cos (double x)
}
u.x = big + a;
y = a - (u.x - big);
- xx = y * y;
- s = y + (db + y * xx * (sn3 + xx * sn5));
- c = y * db + xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- cor = (ssn + s * ccs - sn * c) + cs * s;
- res = sn + cor;
- cor = (sn - res) + cor;
+ res = do_sin (u, y, db, &cor);
cor = (cor > 0) ? 1.035 * cor + eps : 1.035 * cor - eps;
retval = ((res == res + cor) ? ((m) ? res : -res)
: bsloww1 (a, da, x, n));
@@ -664,13 +700,7 @@ __cos (double x)
}
u.x = big + a;
y = a - (u.x - big) + da;
- xx = y * y;
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- s = y + y * xx * (sn3 + xx * sn5);
- c = xx * (cs2 + xx * (cs4 + xx * cs6));
- cor = (ccs - s * ssn - cs * c) - sn * s;
- res = cs + cor;
- cor = (cs - res) + cor;
+ res = do_cos (u, y, &cor);
cor = (cor > 0) ? 1.025 * cor + eps : 1.025 * cor - eps;
retval = ((res == res + cor) ? ((n) ? -res : res)
: bsloww2 (a, da, x, n));
@@ -725,24 +755,12 @@ SECTION
slow1 (double x)
{
mynumber u;
- double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, c1, c2, xx, cor, res;
+ double w[2], y, cor, res;
y = ABS (x);
u.x = big + y;
y = y - (u.x - big);
- xx = y * y;
- s = y * xx * (sn3 + xx * sn5);
- c = xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- y1 = (y + t22) - t22;
- y2 = y - y1;
- c1 = (cs + t22) - t22;
- c2 = (cs - c1) + ccs;
- cor = (ssn + s * ccs + cs * s + c2 * y + c1 * y2) - sn * c;
- y = sn + c1 * y1;
- cor = cor + ((sn - y) + c1 * y1);
- res = y + cor;
- cor = (y - res) + cor;
- if (res == res + 1.0005 * cor)
+ res = do_sin_slow (u, y, 0, 0, &cor);
+ if (res == res + cor)
return (x > 0) ? res : -res;
else
{
@@ -763,7 +781,7 @@ SECTION
slow2 (double x)
{
mynumber u;
- double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, e1, e2, xx, cor, res, del;
+ double w[2], y, y1, y2, cor, res, del;
y = ABS (x);
y = hp0 - y;
@@ -779,20 +797,8 @@ slow2 (double x)
y = -(y + (u.x - big));
del = -hp1;
}
- xx = y * y;
- s = y * xx * (sn3 + xx * sn5);
- c = y * del + xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- y1 = (y + t22) - t22;
- y2 = (y - y1) + del;
- e1 = (sn + t22) - t22;
- e2 = (sn - e1) + ssn;
- cor = (ccs - cs * c - e1 * y2 - e2 * y) - sn * s;
- y = cs - e1 * y1;
- cor = cor + ((cs - y) - e1 * y1);
- res = y + cor;
- cor = (y - res) + cor;
- if (res == res + 1.0005 * cor)
+ res = do_cos_slow (u, y, del, 0, &cor);
+ if (res == res + cor)
return (x > 0) ? res : -res;
else
{
@@ -884,28 +890,11 @@ SECTION
sloww1 (double x, double dx, double orig, int m)
{
mynumber u;
- double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, c1, c2, xx, cor, res;
+ double w[2], y, cor, res;
u.x = big + x;
y = x - (u.x - big);
- xx = y * y;
- s = y * xx * (sn3 + xx * sn5);
- c = xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- y1 = (y + t22) - t22;
- y2 = (y - y1) + dx;
- c1 = (cs + t22) - t22;
- c2 = (cs - c1) + ccs;
- cor = (ssn + s * ccs + cs * s + c2 * y + c1 * y2 - sn * y * dx) - sn * c;
- y = sn + c1 * y1;
- cor = cor + ((sn - y) + c1 * y1);
- res = y + cor;
- cor = (y - res) + cor;
-
- if (cor > 0)
- cor = 1.0005 * cor + 3.1e-30 * ABS (orig);
- else
- cor = 1.0005 * cor - 3.1e-30 * ABS (orig);
+ res = do_sin_slow (u, y, dx, 3.1e-30 * ABS (orig), &cor);
if (res == res + cor)
return (m > 0) ? res : -res;
@@ -937,29 +926,11 @@ SECTION
sloww2 (double x, double dx, double orig, int n)
{
mynumber u;
- double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, e1, e2, xx, cor, res;
+ double w[2], y, cor, res;
u.x = big + x;
y = x - (u.x - big);
- xx = y * y;
- s = y * xx * (sn3 + xx * sn5);
- c = y * dx + xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
-
- y1 = (y + t22) - t22;
- y2 = (y - y1) + dx;
- e1 = (sn + t22) - t22;
- e2 = (sn - e1) + ssn;
- cor = (ccs - cs * c - e1 * y2 - e2 * y) - sn * s;
- y = cs - e1 * y1;
- cor = cor + ((cs - y) - e1 * y1);
- res = y + cor;
- cor = (y - res) + cor;
-
- if (cor > 0)
- cor = 1.0005 * cor + 3.1e-30 * ABS (orig);
- else
- cor = 1.0005 * cor - 3.1e-30 * ABS (orig);
+ res = do_cos_slow (u, y, dx, 3.1e-30 * ABS (orig), &cor);
if (res == res + cor)
return (n & 2) ? -res : res;
@@ -1023,26 +994,13 @@ SECTION
bsloww1 (double x, double dx, double orig, int n)
{
mynumber u;
- double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, c1, c2, xx, cor, res;
+ double w[2], y, cor, res;
y = ABS (x);
u.x = big + y;
y = y - (u.x - big);
dx = (x > 0) ? dx : -dx;
- xx = y * y;
- s = y * xx * (sn3 + xx * sn5);
- c = xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- y1 = (y + t22) - t22;
- y2 = (y - y1) + dx;
- c1 = (cs + t22) - t22;
- c2 = (cs - c1) + ccs;
- cor = (ssn + s * ccs + cs * s + c2 * y + c1 * y2 - sn * y * dx) - sn * c;
- y = sn + c1 * y1;
- cor = cor + ((sn - y) + c1 * y1);
- res = y + cor;
- cor = (y - res) + cor;
- cor = (cor > 0) ? 1.0005 * cor + 1.1e-24 : 1.0005 * cor - 1.1e-24;
+ res = do_sin_slow (u, y, dx, 1.1e-24, &cor);
if (res == res + cor)
return (x > 0) ? res : -res;
else
@@ -1073,27 +1031,13 @@ SECTION
bsloww2 (double x, double dx, double orig, int n)
{
mynumber u;
- double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, e1, e2, xx, cor, res;
+ double w[2], y, cor, res;
y = ABS (x);
u.x = big + y;
y = y - (u.x - big);
dx = (x > 0) ? dx : -dx;
- xx = y * y;
- s = y * xx * (sn3 + xx * sn5);
- c = y * dx + xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
-
- y1 = (y + t22) - t22;
- y2 = (y - y1) + dx;
- e1 = (sn + t22) - t22;
- e2 = (sn - e1) + ssn;
- cor = (ccs - cs * c - e1 * y2 - e2 * y) - sn * s;
- y = cs - e1 * y1;
- cor = cor + ((cs - y) - e1 * y1);
- res = y + cor;
- cor = (y - res) + cor;
- cor = (cor > 0) ? 1.0005 * cor + 1.1e-24 : 1.0005 * cor - 1.1e-24;
+ res = do_cos_slow (u, y, dx, 1.1e-24, &cor);
if (res == res + cor)
return (n & 2) ? -res : res;
else
@@ -1122,25 +1066,13 @@ SECTION
cslow2 (double x)
{
mynumber u;
- double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, e1, e2, xx, cor, res;
+ double w[2], y, cor, res;
y = ABS (x);
u.x = big + y;
y = y - (u.x - big);
- xx = y * y;
- s = y * xx * (sn3 + xx * sn5);
- c = xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- y1 = (y + t22) - t22;
- y2 = y - y1;
- e1 = (sn + t22) - t22;
- e2 = (sn - e1) + ssn;
- cor = (ccs - cs * c - e1 * y2 - e2 * y) - sn * s;
- y = cs - e1 * y1;
- cor = cor + ((cs - y) - e1 * y1);
- res = y + cor;
- cor = (y - res) + cor;
- if (res == res + 1.0005 * cor)
+ res = do_cos_slow (u, y, 0, 0, &cor);
+ if (res == res + cor)
return res;
else
{
@@ -1235,28 +1167,11 @@ SECTION
csloww1 (double x, double dx, double orig, int m)
{
mynumber u;
- double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, c1, c2, xx, cor, res;
+ double w[2], y, cor, res;
u.x = big + x;
y = x - (u.x - big);
- xx = y * y;
- s = y * xx * (sn3 + xx * sn5);
- c = xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
- y1 = (y + t22) - t22;
- y2 = (y - y1) + dx;
- c1 = (cs + t22) - t22;
- c2 = (cs - c1) + ccs;
- cor = (ssn + s * ccs + cs * s + c2 * y + c1 * y2 - sn * y * dx) - sn * c;
- y = sn + c1 * y1;
- cor = cor + ((sn - y) + c1 * y1);
- res = y + cor;
- cor = (y - res) + cor;
-
- if (cor > 0)
- cor = 1.0005 * cor + 3.1e-30 * ABS (orig);
- else
- cor = 1.0005 * cor - 3.1e-30 * ABS (orig);
+ res = do_sin_slow (u, y, dx, 3.1e-30 * ABS (orig), &cor);
if (res == res + cor)
return (m > 0) ? res : -res;
@@ -1287,29 +1202,11 @@ SECTION
csloww2 (double x, double dx, double orig, int n)
{
mynumber u;
- double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, e1, e2, xx, cor, res;
+ double w[2], y, cor, res;
u.x = big + x;
y = x - (u.x - big);
- xx = y * y;
- s = y * xx * (sn3 + xx * sn5);
- c = y * dx + xx * (cs2 + xx * (cs4 + xx * cs6));
- SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
-
- y1 = (y + t22) - t22;
- y2 = (y - y1) + dx;
- e1 = (sn + t22) - t22;
- e2 = (sn - e1) + ssn;
- cor = (ccs - cs * c - e1 * y2 - e2 * y) - sn * s;
- y = cs - e1 * y1;
- cor = cor + ((cs - y) - e1 * y1);
- res = y + cor;
- cor = (y - res) + cor;
-
- if (cor > 0)
- cor = 1.0005 * cor + 3.1e-30 * ABS (orig);
- else
- cor = 1.0005 * cor - 3.1e-30 * ABS (orig);
+ res = do_cos_slow (u, y, dx, 3.1e-30 * ABS (orig), &cor);
if (res == res + cor)
return (n) ? -res : res;
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=84ba214c2197586bc80631dd6d6110a3bbaab7bf
commit 84ba214c2197586bc80631dd6d6110a3bbaab7bf
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date: Fri Dec 20 15:58:19 2013 +0530
Remove more redundant computations in s_sin.c
Removed more redundant computations in the slow paths of the sin and
cos functions. The notable change is the passing of the most
significant bits of X to the slow functions to check if X is positive
so that just the absolute value of x can be passed and the repeated
ABS() operation is avoided.
diff --git a/ChangeLog b/ChangeLog
index 314ddd5..260cd28 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2013-12-20 Siddhesh Poyarekar <siddhesh@redhat.com>
+ * sysdeps/ieee754/dbl-64/s_sin.c (sloww1): Add new argument M.
+ Use M to change sign of result instead of X. Assume X is
+ positive.
+ (csloww1): Likewise.
+ (__sin): Adjust.
+ (__cos): Adjust.
+
* sysdeps/ieee754/dbl-64/s_sin.c (reduce_and_compute): Remove
arguments A and DA.
(__sin): Adjust.
diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c
index 48a26f5..0033f94 100644
--- a/sysdeps/ieee754/dbl-64/s_sin.c
+++ b/sysdeps/ieee754/dbl-64/s_sin.c
@@ -134,7 +134,7 @@ static double slow (double x);
static double slow1 (double x);
static double slow2 (double x);
static double sloww (double x, double dx, double orig);
-static double sloww1 (double x, double dx, double orig);
+static double sloww1 (double x, double dx, double orig, int m);
static double sloww2 (double x, double dx, double orig, int n);
static double bsloww (double x, double dx, double orig, int n);
static double bsloww1 (double x, double dx, double orig, int n);
@@ -142,7 +142,7 @@ static double bsloww2 (double x, double dx, double orig, int n);
int __branred (double x, double *a, double *aa);
static double cslow2 (double x);
static double csloww (double x, double dx, double orig);
-static double csloww1 (double x, double dx, double orig);
+static double csloww1 (double x, double dx, double orig, int m);
static double csloww2 (double x, double dx, double orig, int n);
/* Reduce range of X and compute sin of a + da. K is the amount by which to
@@ -287,18 +287,15 @@ __sin (double x)
else
{
if (a > 0)
- {
- m = 1;
- t = a;
- }
+ m = 1;
else
{
m = 0;
- t = -a;
+ a = -a;
da = -da;
}
- u.x = big + t;
- y = t - (u.x - big);
+ u.x = big + a;
+ y = a - (u.x - big);
xx = y * y;
s = y + (da + y * xx * (sn3 + xx * sn5));
c = y * da + xx * (cs2 + xx * (cs4 + xx * cs6));
@@ -308,7 +305,7 @@ __sin (double x)
cor = (sn - res) + cor;
cor = (cor > 0) ? 1.035 * cor + eps : 1.035 * cor - eps;
retval = ((res == res + cor) ? ((m) ? res : -res)
- : sloww1 (a, da, x));
+ : sloww1 (a, da, x, m));
}
break;
@@ -375,17 +372,16 @@ __sin (double x)
if (a > 0)
{
m = 1;
- t = a;
db = da;
}
else
{
m = 0;
- t = -a;
+ a = -a;
db = -da;
}
- u.x = big + t;
- y = t - (u.x - big);
+ u.x = big + a;
+ y = a - (u.x - big);
xx = y * y;
s = y + (db + y * xx * (sn3 + xx * sn5));
c = y * db + xx * (cs2 + xx * (cs4 + xx * cs6));
@@ -496,16 +492,15 @@ __cos (double x)
if (a > 0)
{
m = 1;
- t = a;
}
else
{
m = 0;
- t = -a;
+ a = -a;
da = -da;
}
- u.x = big + t;
- y = t - (u.x - big);
+ u.x = big + a;
+ y = a - (u.x - big);
xx = y * y;
s = y + (da + y * xx * (sn3 + xx * sn5));
c = y * da + xx * (cs2 + xx * (cs4 + xx * cs6));
@@ -515,7 +510,7 @@ __cos (double x)
cor = (sn - res) + cor;
cor = (cor > 0) ? 1.035 * cor + 1.0e-31 : 1.035 * cor - 1.0e-31;
retval = ((res == res + cor) ? ((m) ? res : -res)
- : csloww1 (a, da, x));
+ : csloww1 (a, da, x, m));
}
} /* else if (k < 0x400368fd) */
@@ -554,16 +549,15 @@ __cos (double x)
if (a > 0)
{
m = 1;
- t = a;
}
else
{
m = 0;
- t = -a;
+ a = -a;
da = -da;
}
- u.x = big + t;
- y = t - (u.x - big);
+ u.x = big + a;
+ y = a - (u.x - big);
xx = y * y;
s = y + (da + y * xx * (sn3 + xx * sn5));
c = y * da + xx * (cs2 + xx * (cs4 + xx * cs6));
@@ -573,7 +567,7 @@ __cos (double x)
cor = (sn - res) + cor;
cor = (cor > 0) ? 1.035 * cor + eps : 1.035 * cor - eps;
retval = ((res == res + cor) ? ((m) ? res : -res)
- : csloww1 (a, da, x));
+ : csloww1 (a, da, x, m));
}
break;
@@ -638,17 +632,16 @@ __cos (double x)
if (a > 0)
{
m = 1;
- t = a;
db = da;
}
else
{
m = 0;
- t = -a;
+ a = -a;
db = -da;
}
- u.x = big + t;
- y = t - (u.x - big);
+ u.x = big + a;
+ y = a - (u.x - big);
xx = y * y;
s = y + (db + y * xx * (sn3 + xx * sn5));
c = y * db + xx * (cs2 + xx * (cs4 + xx * cs6));
@@ -888,14 +881,13 @@ sloww (double x, double dx, double orig)
static double
SECTION
-sloww1 (double x, double dx, double orig)
+sloww1 (double x, double dx, double orig, int m)
{
mynumber u;
double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, c1, c2, xx, cor, res;
- y = ABS (x);
- u.x = big + y;
- y = y - (u.x - big);
+ u.x = big + x;
+ y = x - (u.x - big);
xx = y * y;
s = y * xx * (sn3 + xx * sn5);
c = xx * (cs2 + xx * (cs4 + xx * cs6));
@@ -916,10 +908,10 @@ sloww1 (double x, double dx, double orig)
cor = 1.0005 * cor - 3.1e-30 * ABS (orig);
if (res == res + cor)
- return (x > 0) ? res : -res;
+ return (m > 0) ? res : -res;
else
{
- __dubsin (ABS (x), dx, w);
+ __dubsin (x, dx, w);
if (w[1] > 0)
cor = 1.000000005 * w[1] + 1.1e-30 * ABS (orig);
@@ -927,7 +919,7 @@ sloww1 (double x, double dx, double orig)
cor = 1.000000005 * w[1] - 1.1e-30 * ABS (orig);
if (w[0] == w[0] + cor)
- return (x > 0) ? w[0] : -w[0];
+ return (m > 0) ? w[0] : -w[0];
else
return __mpsin (orig, 0, true);
}
@@ -1240,14 +1232,13 @@ csloww (double x, double dx, double orig)
static double
SECTION
-csloww1 (double x, double dx, double orig)
+csloww1 (double x, double dx, double orig, int m)
{
mynumber u;
double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, c1, c2, xx, cor, res;
- y = ABS (x);
- u.x = big + y;
- y = y - (u.x - big);
+ u.x = big + x;
+ y = x - (u.x - big);
xx = y * y;
s = y * xx * (sn3 + xx * sn5);
c = xx * (cs2 + xx * (cs4 + xx * cs6));
@@ -1268,16 +1259,16 @@ csloww1 (double x, double dx, double orig)
cor = 1.0005 * cor - 3.1e-30 * ABS (orig);
if (res == res + cor)
- return (x > 0) ? res : -res;
+ return (m > 0) ? res : -res;
else
{
- __dubsin (ABS (x), dx, w);
+ __dubsin (x, dx, w);
if (w[1] > 0)
cor = 1.000000005 * w[1] + 1.1e-30 * ABS (orig);
else
cor = 1.000000005 * w[1] - 1.1e-30 * ABS (orig);
if (w[0] == w[0] + cor)
- return (x > 0) ? w[0] : -w[0];
+ return (m > 0) ? w[0] : -w[0];
else
return __mpcos (orig, 0, true);
}
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=975195e4668575d5c53fbf5223501c26ee8dc20e
commit 975195e4668575d5c53fbf5223501c26ee8dc20e
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date: Fri Dec 20 15:56:21 2013 +0530
Remove redundant arguments in reduce_and_compute
The A and DA arguments in reduce_and_compute are useless and hence
have been removed.
diff --git a/ChangeLog b/ChangeLog
index a8dab6d..314ddd5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2013-12-20 Siddhesh Poyarekar <siddhesh@redhat.com>
+ * sysdeps/ieee754/dbl-64/s_sin.c (reduce_and_compute): Remove
+ arguments A and DA.
+ (__sin): Adjust.
+ (__cos): Likewise.
+
* sysdeps/ieee754/dbl-64/s_sin.c (__sin): Use DA directly.
(__cos): Likewise.
(sloww1): Don't adjust sign of DX.
diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c
index 4e2ac3d..48a26f5 100644
--- a/sysdeps/ieee754/dbl-64/s_sin.c
+++ b/sysdeps/ieee754/dbl-64/s_sin.c
@@ -150,9 +150,9 @@ static double csloww2 (double x, double dx, double orig, int n);
by simply rotating the quadrants by 1. */
static inline double
__always_inline
-reduce_and_compute (double x, double a, double da, unsigned int k)
+reduce_and_compute (double x, unsigned int k)
{
- double retval = 0;
+ double retval = 0, a, da;
unsigned int n = __branred (x, &a, &da);
k = (n + k) % 4;
switch (k)
@@ -424,7 +424,7 @@ __sin (double x)
/* -----------------281474976710656 <|x| <2^1024----------------------------*/
else if (k < 0x7ff00000)
- retval = reduce_and_compute (x, a, da, 0);
+ retval = reduce_and_compute (x, 0);
/*--------------------- |x| > 2^1024 ----------------------------------*/
else
@@ -687,7 +687,7 @@ __cos (double x)
/* 281474976710656 <|x| <2^1024 */
else if (k < 0x7ff00000)
- retval = reduce_and_compute (x, a, da, 1);
+ retval = reduce_and_compute (x, 1);
else
{
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=5ff8d60ef324b9666c92fc342d143e8074043cd1
commit 5ff8d60ef324b9666c92fc342d143e8074043cd1
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date: Fri Dec 20 15:55:34 2013 +0530
Remove some redundant computations in s_sin.c
There are multiple points in the code where the absolute value of a
number is computed multiple times or is computed even though the value
can only be positive. This change removes those redundant
computations. Tested on x86_64 to verify that there were no
regressions in the testsuite.
diff --git a/ChangeLog b/ChangeLog
index 9ebb675..a8dab6d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2013-12-20 Siddhesh Poyarekar <siddhesh@redhat.com>
+
+ * sysdeps/ieee754/dbl-64/s_sin.c (__sin): Use DA directly.
+ (__cos): Likewise.
+ (sloww1): Don't adjust sign of DX.
+ (csloww1): Likewise.
+ (sloww2): Use X directly and don't adjust sign of DX.
+ (csloww2): Likewise.
+
2013-12-19 Joseph Myers <joseph@codesourcery.com>
* math/auto-libm-test-in: Add tests of cabs and carg.
diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c
index 9066667..4e2ac3d 100644
--- a/sysdeps/ieee754/dbl-64/s_sin.c
+++ b/sysdeps/ieee754/dbl-64/s_sin.c
@@ -290,19 +290,18 @@ __sin (double x)
{
m = 1;
t = a;
- db = da;
}
else
{
m = 0;
t = -a;
- db = -da;
+ da = -da;
}
u.x = big + t;
y = t - (u.x - big);
xx = y * y;
- s = y + (db + y * xx * (sn3 + xx * sn5));
- c = y * db + xx * (cs2 + xx * (cs4 + xx * cs6));
+ s = y + (da + y * xx * (sn3 + xx * sn5));
+ c = y * da + xx * (cs2 + xx * (cs4 + xx * cs6));
SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
cor = (ssn + s * ccs - sn * c) + cs * s;
res = sn + cor;
@@ -498,19 +497,18 @@ __cos (double x)
{
m = 1;
t = a;
- db = da;
}
else
{
m = 0;
t = -a;
- db = -da;
+ da = -da;
}
u.x = big + t;
y = t - (u.x - big);
xx = y * y;
- s = y + (db + y * xx * (sn3 + xx * sn5));
- c = y * db + xx * (cs2 + xx * (cs4 + xx * cs6));
+ s = y + (da + y * xx * (sn3 + xx * sn5));
+ c = y * da + xx * (cs2 + xx * (cs4 + xx * cs6));
SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
cor = (ssn + s * ccs - sn * c) + cs * s;
res = sn + cor;
@@ -557,19 +555,18 @@ __cos (double x)
{
m = 1;
t = a;
- db = da;
}
else
{
m = 0;
t = -a;
- db = -da;
+ da = -da;
}
u.x = big + t;
y = t - (u.x - big);
xx = y * y;
- s = y + (db + y * xx * (sn3 + xx * sn5));
- c = y * db + xx * (cs2 + xx * (cs4 + xx * cs6));
+ s = y + (da + y * xx * (sn3 + xx * sn5));
+ c = y * da + xx * (cs2 + xx * (cs4 + xx * cs6));
SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
cor = (ssn + s * ccs - sn * c) + cs * s;
res = sn + cor;
@@ -899,7 +896,6 @@ sloww1 (double x, double dx, double orig)
y = ABS (x);
u.x = big + y;
y = y - (u.x - big);
- dx = (x > 0) ? dx : -dx;
xx = y * y;
s = y * xx * (sn3 + xx * sn5);
c = xx * (cs2 + xx * (cs4 + xx * cs6));
@@ -951,10 +947,8 @@ sloww2 (double x, double dx, double orig, int n)
mynumber u;
double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, e1, e2, xx, cor, res;
- y = ABS (x);
- u.x = big + y;
- y = y - (u.x - big);
- dx = (x > 0) ? dx : -dx;
+ u.x = big + x;
+ y = x - (u.x - big);
xx = y * y;
s = y * xx * (sn3 + xx * sn5);
c = y * dx + xx * (cs2 + xx * (cs4 + xx * cs6));
@@ -979,7 +973,7 @@ sloww2 (double x, double dx, double orig, int n)
return (n & 2) ? -res : res;
else
{
- __docos (ABS (x), dx, w);
+ __docos (x, dx, w);
if (w[1] > 0)
cor = 1.000000005 * w[1] + 1.1e-30 * ABS (orig);
@@ -1254,7 +1248,6 @@ csloww1 (double x, double dx, double orig)
y = ABS (x);
u.x = big + y;
y = y - (u.x - big);
- dx = (x > 0) ? dx : -dx;
xx = y * y;
s = y * xx * (sn3 + xx * sn5);
c = xx * (cs2 + xx * (cs4 + xx * cs6));
@@ -1305,10 +1298,8 @@ csloww2 (double x, double dx, double orig, int n)
mynumber u;
double sn, ssn, cs, ccs, s, c, w[2], y, y1, y2, e1, e2, xx, cor, res;
- y = ABS (x);
- u.x = big + y;
- y = y - (u.x - big);
- dx = (x > 0) ? dx : -dx;
+ u.x = big + x;
+ y = x - (u.x - big);
xx = y * y;
s = y * xx * (sn3 + xx * sn5);
c = y * dx + xx * (cs2 + xx * (cs4 + xx * cs6));
@@ -1333,7 +1324,7 @@ csloww2 (double x, double dx, double orig, int n)
return (n) ? -res : res;
else
{
- __docos (ABS (x), dx, w);
+ __docos (x, dx, w);
if (w[1] > 0)
cor = 1.000000005 * w[1] + 1.1e-30 * ABS (orig);
else
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 26 +++
sysdeps/ieee754/dbl-64/s_sin.c | 471 +++++++++++++++-------------------------
2 files changed, 201 insertions(+), 296 deletions(-)
hooks/post-receive
--
GNU C Library master sources