This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Use long wherever possible in mpa.c


Hi,

Here's another patch to sync up code between powrpc and generic mpa.c,
this time the change being in the generic code.  Using long throughout
like powerpc does is beneficial since it reduces the need to switch to
32-bit instructions.  It gives a very minor performance improvement
(~0.4%).  OK to commit?

Siddhesh

	* sysdeps/ieee754/dbl-64/mpa.c (mcr): Use long instead of int.
	(__acr): Likewise.
	(__cpy): Likewise.
	(norm): Likewise.
	(denorm): Likewise.
	(__dbl_mp): Likewise.
	(add_magnitudes): Likewise.
	(sub_magnitudes): Likewise.
	(__mul): Likewise.
	(__inv): Likewise.

diff --git a/sysdeps/ieee754/dbl-64/mpa.c b/sysdeps/ieee754/dbl-64/mpa.c
index 4593b8d..cad227a 100644
--- a/sysdeps/ieee754/dbl-64/mpa.c
+++ b/sysdeps/ieee754/dbl-64/mpa.c
@@ -60,8 +60,9 @@ const mp_no mptwo = {1, {1.0, 2.0}};
 static int
 mcr (const mp_no *x, const mp_no *y, int p)
 {
-  int i;
-  for (i = 1; i <= p; i++)
+  long i;
+  long p2 = p;
+  for (i = 1; i <= p2; i++)
     {
       if (X[i] == Y[i])
 	continue;
@@ -77,7 +78,7 @@ mcr (const mp_no *x, const mp_no *y, int p)
 int
 __acr (const mp_no *x, const mp_no *y, int p)
 {
-  int i;
+  long i;
 
   if (X[0] == ZERO)
     {
@@ -108,8 +109,10 @@ __acr (const mp_no *x, const mp_no *y, int p)
 void
 __cpy (const mp_no *x, mp_no *y, int p)
 {
+  long i;
+
   EY = EX;
-  for (int i = 0; i <= p; i++)
+  for (i = 0; i <= p; i++)
     Y[i] = X[i];
 }
 #endif
@@ -121,7 +124,7 @@ static void
 norm (const mp_no *x, double *y, int p)
 {
 #define R RADIXI
-  int i;
+  long i;
   double a, c, u, v, z[5];
   if (p < 5)
     {
@@ -195,7 +198,8 @@ norm (const mp_no *x, double *y, int p)
 static void
 denorm (const mp_no *x, double *y, int p)
 {
-  int i, k;
+  long i, k;
+  long p2 = p;
   double c, u, z[5];
 
 #define R RADIXI
@@ -205,7 +209,7 @@ denorm (const mp_no *x, double *y, int p)
       return;
     }
 
-  if (p == 1)
+  if (p2 == 1)
     {
       if (EX == -42)
 	{
@@ -229,7 +233,7 @@ denorm (const mp_no *x, double *y, int p)
 	  k = 1;
 	}
     }
-  else if (p == 2)
+  else if (p2 == 2)
     {
       if (EX == -42)
 	{
@@ -282,7 +286,7 @@ denorm (const mp_no *x, double *y, int p)
 
   if (u == z[3])
     {
-      for (i = k + 1; i <= p; i++)
+      for (i = k + 1; i <= p2; i++)
 	{
 	  if (X[i] == ZERO)
 	    continue;
@@ -324,7 +328,8 @@ void
 SECTION
 __dbl_mp (double x, mp_no *y, int p)
 {
-  int i, n;
+  long i, n;
+  long p2 = p;
   double u;
 
   /* Sign.  */
@@ -348,7 +353,7 @@ __dbl_mp (double x, mp_no *y, int p)
     x *= RADIX;
 
   /* Digits.  */
-  n = MIN (p, 4);
+  n = MIN (p2, 4);
   for (i = 1; i <= n; i++)
     {
       u = (x + TWO52) - TWO52;
@@ -358,7 +363,7 @@ __dbl_mp (double x, mp_no *y, int p)
       x -= u;
       x *= RADIX;
     }
-  for (; i <= p; i++)
+  for (; i <= p2; i++)
     Y[i] = ZERO;
 }
 
@@ -370,14 +375,15 @@ static void
 SECTION
 add_magnitudes (const mp_no *x, const mp_no *y, mp_no *z, int p)
 {
-  int i, j, k;
+  long i, j, k;
+  long p2 = p;
   double zk;
 
   EZ = EX;
 
-  i = p;
-  j = p + EY - EX;
-  k = p + 1;
+  i = p2;
+  j = p2 + EY - EX;
+  k = p2 + 1;
 
   if (__glibc_unlikely (j < 1))
     {
@@ -419,7 +425,7 @@ add_magnitudes (const mp_no *x, const mp_no *y, mp_no *z, int p)
 
   if (zk == ZERO)
     {
-      for (i = 1; i <= p; i++)
+      for (i = 1; i <= p2; i++)
 	Z[i] = Z[i + 1];
     }
   else
@@ -437,13 +443,14 @@ static void
 SECTION
 sub_magnitudes (const mp_no *x, const mp_no *y, mp_no *z, int p)
 {
-  int i, j, k;
+  long i, j, k;
+  long p2 = p;
   double zk;
 
   EZ = EX;
-  i = p;
-  j = p + EY - EX;
-  k = p;
+  i = p2;
+  j = p2 + EY - EX;
+  k = p2;
 
   /* Y is too small compared to X, copy X over to the result.  */
   if (__glibc_unlikely (j < 1))
@@ -454,7 +461,7 @@ sub_magnitudes (const mp_no *x, const mp_no *y, mp_no *z, int p)
 
   /* The relevant least significant digit in Y is non-zero, so we factor it in
      to enhance accuracy.  */
-  if (j < p && Y[j + 1] > ZERO)
+  if (j < p2 && Y[j + 1] > ZERO)
     {
       Z[k + 1] = RADIX - Y[j + 1];
       zk = MONE;
@@ -497,9 +504,9 @@ sub_magnitudes (const mp_no *x, const mp_no *y, mp_no *z, int p)
   /* Normalize.  */
   for (i = 1; Z[i] == ZERO; i++);
   EZ = EZ - i + 1;
-  for (k = 1; i <= p + 1;)
+  for (k = 1; i <= p2 + 1;)
     Z[k++] = Z[i++];
-  for (; k <= p;)
+  for (; k <= p2;)
     Z[k++] = ZERO;
 }
 
@@ -611,7 +618,8 @@ void
 SECTION
 __mul (const mp_no *x, const mp_no *y, mp_no *z, int p)
 {
-  int i, j, k, ip, ip2;
+  long i, j, k, ip, ip2;
+  long p2 = p;
   double u, zk;
   const mp_no *a;
   double *diag;
@@ -625,7 +633,7 @@ __mul (const mp_no *x, const mp_no *y, mp_no *z, int p)
 
   /* We need not iterate through all X's and Y's since it's pointless to
      multiply zeroes.  Here, both are zero...  */
-  for (ip2 = p; ip2 > 0; ip2--)
+  for (ip2 = p2; ip2 > 0; ip2--)
     if (X[ip2] != ZERO || Y[ip2] != ZERO)
       break;
 
@@ -662,7 +670,7 @@ __mul (const mp_no *x, const mp_no *y, mp_no *z, int p)
      'internal precision' of the input numbers, i.e. digits after ip and ip2
      are all ZERO.  */
 
-  k = (__glibc_unlikely (p < 3)) ? p + p : p + 3;
+  k = (__glibc_unlikely (p2 < 3)) ? p2 + p2 : p2 + 3;
 
   while (k > ip + ip2 + 1)
     Z[k--] = ZERO;
@@ -681,7 +689,7 @@ __mul (const mp_no *x, const mp_no *y, mp_no *z, int p)
   while (i < k)
     diag[i++] = d;
 
-  while (k > p)
+  while (k > p2)
     {
       int lim = k / 2;
 
@@ -690,7 +698,7 @@ __mul (const mp_no *x, const mp_no *y, mp_no *z, int p)
 	   of products above, we add twice.  */
         zk += 2 * X[lim] * Y[lim];
 
-      for (i = k - p, j = p; i < j; i++, j--)
+      for (i = k - p2, j = p2; i < j; i++, j--)
 	zk += (X[i] + X[j]) * (Y[i] + Y[j]);
 
       zk -= diag[k - 1];
@@ -745,7 +753,7 @@ __mul (const mp_no *x, const mp_no *y, mp_no *z, int p)
   /* Is there a carry beyond the most significant digit?  */
   if (__glibc_unlikely (Z[1] == ZERO))
     {
-      for (i = 1; i <= p; i++)
+      for (i = 1; i <= p2; i++)
 	Z[i] = Z[i + 1];
       e--;
     }
@@ -865,7 +873,7 @@ static void
 SECTION
 __inv (const mp_no *x, mp_no *y, int p)
 {
-  int i;
+  long i;
   double t;
   mp_no z, w;
   static const int np1[] =


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]