about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@redhat.com>2013-01-14 21:36:58 +0530
committerSiddhesh Poyarekar <siddhesh@redhat.com>2013-01-14 21:53:48 +0530
commit2a91b5735ac1bc65ce5c2a3646d75ba7208e26e9 (patch)
treead53b95348dcd3e65fbcd9176cddfdb07e6ec2e1
parent1066a53440d2744566e97c59bcd0d422186b3e90 (diff)
downloadglibc-2a91b5735ac1bc65ce5c2a3646d75ba7208e26e9.tar.gz
glibc-2a91b5735ac1bc65ce5c2a3646d75ba7208e26e9.tar.xz
glibc-2a91b5735ac1bc65ce5c2a3646d75ba7208e26e9.zip
Minor tweak to mp multiplication
Add a local variable to remove extra copies to/from memory in the Z
array.
-rw-r--r--ChangeLog3
-rw-r--r--sysdeps/ieee754/dbl-64/mpa.c28
2 files changed, 18 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 55ca83c5b3..21fb09b937 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2013-01-14  Siddhesh Poyarekar  <siddhesh@redhat.com>
 
+	* sysdeps/ieee754/dbl-64/mpa.c (__mul): Add a local variable
+	to optimize copies.
+
 	* sysdeps/ieee754/dbl-64/mpa.c: Fix formatting.
 	* sysdeps/powerpc/powerpc32/power4/fpu/mpa.c: Likewise.
 	* sysdeps/powerpc/powerpc64/power4/fpu/mpa.c: Likewise.
diff --git a/sysdeps/ieee754/dbl-64/mpa.c b/sysdeps/ieee754/dbl-64/mpa.c
index b3bfa6c0fe..c882c8bc2c 100644
--- a/sysdeps/ieee754/dbl-64/mpa.c
+++ b/sysdeps/ieee754/dbl-64/mpa.c
@@ -606,7 +606,7 @@ SECTION
 __mul (const mp_no *x, const mp_no *y, mp_no *z, int p)
 {
   int i, j, k, k2;
-  double u;
+  double u, zk;
 
   /* Is z=0?  */
   if (__glibc_unlikely (X[0] * Y[0] == ZERO))
@@ -617,31 +617,33 @@ __mul (const mp_no *x, const mp_no *y, mp_no *z, int p)
 
   /* Multiply, add and carry.  */
   k2 = (__glibc_unlikely (p < 3)) ? p + p : p + 3;
-  Z[k2] = ZERO;
+  zk = Z[k2] = ZERO;
 
-  for (k = k2; k > p;)
+  for (k = k2; k > p; k--)
     {
       for (i = k - p, j = p; i < p + 1; i++, j--)
-	Z[k] += X[i] * Y[j];
+	zk += X[i] * Y[j];
 
-      u = (Z[k] + CUTTER) - CUTTER;
-      if (u > Z[k])
+      u = (zk + CUTTER) - CUTTER;
+      if (u > zk)
 	u -= RADIX;
-      Z[k] -= u;
-      Z[--k] = u * RADIXI;
+      Z[k] = zk - u;
+      zk = u * RADIXI;
     }
 
   while (k > 1)
     {
       for (i = 1, j = k - 1; i < k; i++, j--)
-	Z[k] += X[i] * Y[j];
+	zk += X[i] * Y[j];
 
-      u = (Z[k] + CUTTER) - CUTTER;
-      if (u > Z[k])
+      u = (zk + CUTTER) - CUTTER;
+      if (u > zk)
 	u -= RADIX;
-      Z[k] -= u;
-      Z[--k] = u * RADIXI;
+      Z[k] = zk - u;
+      zk = u * RADIXI;
+      k--;
     }
+  Z[k] = zk;
 
   EZ = EX + EY;
   /* Is there a carry beyond the most significant digit?  */