This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Don't depend on LIM to determine loop end in __sqr
- From: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Thu, 14 Feb 2013 16:56:20 +0530
- Subject: [PATCH] Don't depend on LIM to determine loop end in __sqr
Hi,
This is yet another micro-optimization to the __sqr loop termination.
If we check the termination condition of the inner mantissa
calculation loop as the subscripts of X and Y crossing over, we don't
need the extra operations in LIM. This gives a roughly 2% improvement
in pow() in the worst case (768 bits). Built and tested on x86_64.
Will work on ppc changes separately. OK to commit?
Siddhesh
* sysdeps/ieee754/dbl-64/mpa.c (__sqr): Avoid using LIM in
loop termination condition.
diff --git a/sysdeps/ieee754/dbl-64/mpa.c b/sysdeps/ieee754/dbl-64/mpa.c
index bbe9648..6001f61 100644
--- a/sysdeps/ieee754/dbl-64/mpa.c
+++ b/sysdeps/ieee754/dbl-64/mpa.c
@@ -787,12 +787,9 @@ __sqr (const mp_no *x, mp_no *y, int p)
long lim = k / 2;
if (k % 2 == 0)
- {
- yk += X[lim] * X[lim];
- lim--;
- }
+ yk += X[lim] * X[lim];
- for (i = k - p, j = p; i <= lim; i++, j--)
+ for (i = k - p, j = p; i < j; i++, j--)
yk2 += X[i] * X[j];
yk += 2.0 * yk2;
@@ -810,12 +807,9 @@ __sqr (const mp_no *x, mp_no *y, int p)
long lim = k / 2;
if (k % 2 == 0)
- {
- yk += X[lim] * X[lim];
- lim--;
- }
+ yk += X[lim] * X[lim];
- for (i = 1, j = k - 1; i <= lim; i++, j--)
+ for (i = 1, j = k - 1; i < j; i++, j--)
yk2 += X[i] * X[j];
yk += 2.0 * yk2;