]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
pack.m4 (pack_'rtype_code`): Use count_0 for counting true values in a logical array.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 30 Aug 2009 09:02:01 +0000 (09:02 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 30 Aug 2009 09:02:01 +0000 (09:02 +0000)
2009-08-30  Thomas Koenig  <tkoenig@gcc.gnu.org>

* m4/pack.m4 (pack_'rtype_code`): Use count_0 for counting true
values in a logical array.  Mark bounds checking tests as
unlikely.
* intrinsics/pack_generic.c (pack_internal): Likewise.
* runtime/bounds.c (count_0):  Fix off-by-one error in detecting
empty arrays.
* generated/pack_c4.c: Regenerated.
* generated/pack_c8.c: Regenerated.
* generated/pack_c10.c: Regenerated.
* generated/pack_c16.c: Regenerated.
* generated/pack_i1.c: Regenerated.
* generated/pack_i16.c: Regenerated.
* generated/pack_i2.c: Regenerated.
* generated/pack_i4.c: Regenerated.
* generated/pack_i8.c: Regenerated.
* generated/pack_r4.c: Regenerated.
* generated/pack_r8.c: Regenerated.
* generated/pack_r10.c: Regenerated.
* generated/pack_r16.c: Regenerated.

From-SVN: r151225

17 files changed:
libgfortran/ChangeLog
libgfortran/generated/pack_c10.c
libgfortran/generated/pack_c16.c
libgfortran/generated/pack_c4.c
libgfortran/generated/pack_c8.c
libgfortran/generated/pack_i1.c
libgfortran/generated/pack_i16.c
libgfortran/generated/pack_i2.c
libgfortran/generated/pack_i4.c
libgfortran/generated/pack_i8.c
libgfortran/generated/pack_r10.c
libgfortran/generated/pack_r16.c
libgfortran/generated/pack_r4.c
libgfortran/generated/pack_r8.c
libgfortran/intrinsics/pack_generic.c
libgfortran/m4/pack.m4
libgfortran/runtime/bounds.c

index 8ef88c0d02558d262845136fefce977c83aee762..f1ac312833b6bba84e759ffecd338ba73cbed815 100644 (file)
@@ -1,3 +1,25 @@
+2009-08-30  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       * m4/pack.m4 (pack_'rtype_code`): Use count_0 for counting true
+       values in a logical array.  Mark bounds checking tests as
+       unlikely.
+       * intrinsics/pack_generic.c (pack_internal): Likewise.
+       * runtime/bounds.c (count_0):  Fix off-by-one error in detecting
+       empty arrays.
+       * generated/pack_c4.c: Regenerated.
+       * generated/pack_c8.c: Regenerated.
+       * generated/pack_c10.c: Regenerated.
+       * generated/pack_c16.c: Regenerated.
+       * generated/pack_i1.c: Regenerated.
+       * generated/pack_i16.c: Regenerated.
+       * generated/pack_i2.c: Regenerated.
+       * generated/pack_i4.c: Regenerated.
+       * generated/pack_i8.c: Regenerated.
+       * generated/pack_r4.c: Regenerated.
+       * generated/pack_r8.c: Regenerated.
+       * generated/pack_r10.c: Regenerated.
+       * generated/pack_r16.c: Regenerated.
+
 2009-08-25  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR libfortran/34670
index 008fb5c9236875d4e9ebb261197d8273ee51ee47..cc66c538e1c065e2fc80d4522e663bc1978fd49c 100644 (file)
@@ -138,7 +138,7 @@ pack_c10 (gfc_array_c10 *ret, const gfc_array_c10 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_c10 (gfc_array_c10 *ret, const gfc_array_c10 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index e7d039f5becfe7b827dcaa1792fa03f269a7e9cc..9397262dd06d698f0bbb015e1db6239a78a80b15 100644 (file)
@@ -138,7 +138,7 @@ pack_c16 (gfc_array_c16 *ret, const gfc_array_c16 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_c16 (gfc_array_c16 *ret, const gfc_array_c16 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index fe1f68d4225343f3b31f0976a572ca8a5ac5c174..093bdcc9a1d00c021d260ca2019a1a6b071b2457 100644 (file)
@@ -138,7 +138,7 @@ pack_c4 (gfc_array_c4 *ret, const gfc_array_c4 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_c4 (gfc_array_c4 *ret, const gfc_array_c4 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index f5a27eca6f51827294f955849e5abb06c34861f5..7971e2ba1358f53d678405ef207e919ea48d69bd 100644 (file)
@@ -138,7 +138,7 @@ pack_c8 (gfc_array_c8 *ret, const gfc_array_c8 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_c8 (gfc_array_c8 *ret, const gfc_array_c8 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index edc895082a469e33e4e75ac1e7a421af974ddd7b..3e4647dbd5595a8fbcbdd773375fa75b51ede09c 100644 (file)
@@ -138,7 +138,7 @@ pack_i1 (gfc_array_i1 *ret, const gfc_array_i1 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_i1 (gfc_array_i1 *ret, const gfc_array_i1 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index 8f38a2747ec06db676880abb81219a5312b555ae..99d3491c38f2859b8e5ff05a9cc2a606cfd32899 100644 (file)
@@ -138,7 +138,7 @@ pack_i16 (gfc_array_i16 *ret, const gfc_array_i16 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_i16 (gfc_array_i16 *ret, const gfc_array_i16 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index 149e9f6f67d5a51108dd4da85cfd2cbe4a974908..e796d169f76f199f62afbd7708c42654677cd153 100644 (file)
@@ -138,7 +138,7 @@ pack_i2 (gfc_array_i2 *ret, const gfc_array_i2 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_i2 (gfc_array_i2 *ret, const gfc_array_i2 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index dad10d62d46a869ea615eb99c3dd9272d8b2360f..91ce99fe4fd46fc146b635c014b605de36955a81 100644 (file)
@@ -138,7 +138,7 @@ pack_i4 (gfc_array_i4 *ret, const gfc_array_i4 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_i4 (gfc_array_i4 *ret, const gfc_array_i4 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index 0a23aa5b72fb284f7acb5c1cfb7b96267540fd42..e49d8c29e95be438401838561e2a8f90aa8ec422 100644 (file)
@@ -138,7 +138,7 @@ pack_i8 (gfc_array_i8 *ret, const gfc_array_i8 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_i8 (gfc_array_i8 *ret, const gfc_array_i8 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index e4bbe6fabcf3cbb1b1632d011480382f50ba1d0d..f70c932640e1a849ca8fc82b5eb08c49cf45282b 100644 (file)
@@ -138,7 +138,7 @@ pack_r10 (gfc_array_r10 *ret, const gfc_array_r10 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_r10 (gfc_array_r10 *ret, const gfc_array_r10 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index 7dff30b70068be7f8950a854c9cfb7cf2ba71401..ff2ad6e7eed654b88b7a663f8dbb6ad851327246 100644 (file)
@@ -138,7 +138,7 @@ pack_r16 (gfc_array_r16 *ret, const gfc_array_r16 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_r16 (gfc_array_r16 *ret, const gfc_array_r16 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index 51d46a2721821d4bb2758ec2909e3c81fde5f358..0c08b8c8c94d32a4f8c1f0607051e4adeb8cd088 100644 (file)
@@ -138,7 +138,7 @@ pack_r4 (gfc_array_r4 *ret, const gfc_array_r4 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_r4 (gfc_array_r4 *ret, const gfc_array_r4 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index 582c2b9aeb1606bc618fa93f47841af827e5b500..2b307e29a2b7e8fe9dbe5c7bac903cbde3bc4f81 100644 (file)
@@ -138,7 +138,7 @@ pack_r8 (gfc_array_r8 *ret, const gfc_array_r8 *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -155,62 +155,10 @@ pack_r8 (gfc_array_r8 *ret, const gfc_array_r8 *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index b611d7771019477b14ff848b5b23d51ac96c82d5..eb52f069d407a01bc9213168574e5f4c590d46b6 100644 (file)
@@ -132,7 +132,7 @@ pack_internal (gfc_array_char *ret, const gfc_array_char *array,
   if (mstride[0] == 0)
     mstride[0] = mask_kind;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -147,58 +147,7 @@ pack_internal (gfc_array_char *ret, const gfc_array_char *array,
        {
          /* We have to count the true elements in MASK.  */
 
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
+         total = count_0 (mask);
        }
 
       if (ret->data == NULL)
index 910ffdcaac178d265f5b67a7a9e7cba4689d7ea2..c5fd2fd817d05da60719170e1502a634bdfbad5f 100644 (file)
@@ -139,7 +139,7 @@ pack_'rtype_code` ('rtype` *ret, const 'rtype` *array,
   else
     sptr = array->data;
 
-  if (ret->data == NULL || compile_options.bounds_check)
+  if (ret->data == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or
         for bounds checking.  */
@@ -156,62 +156,10 @@ pack_'rtype_code` ('rtype` *ret, const 'rtype` *array,
            }
        }
       else
-       {
-         /* We have to count the true elements in MASK.  */
-
-         /* TODO: We could speed up pack easily in the case of only
-            few .TRUE. entries in MASK, by keeping track of where we
-            would be in the source array during the initial traversal
-            of MASK, and caching the pointers to those elements. Then,
-            supposed the number of elements is small enough, we would
-            only have to traverse the list, and copy those elements
-            into the result array. In the case of datatypes which fit
-            in one of the integer types we could also cache the
-            value instead of a pointer to it.
-            This approach might be bad from the point of view of
-            cache behavior in the case where our cache is not big
-            enough to hold all elements that have to be copied.  */
-
-         const GFC_LOGICAL_1 *m = mptr;
-
-         total = 0;
-         if (zero_sized)
-           m = NULL;
-
-         while (m)
-           {
-             /* Test this element.  */
-             if (*m)
-               total++;
-
-             /* Advance to the next element.  */
-             m += mstride[0];
-             count[0]++;
-             n = 0;
-             while (count[n] == extent[n])
-               {
-                 /* When we get to the end of a dimension, reset it
-                    and increment the next dimension.  */
-                 count[n] = 0;
-                 /* We could precalculate this product, but this is a
-                    less frequently used path so probably not worth
-                    it.  */
-                 m -= mstride[n] * extent[n];
-                 n++;
-                 if (n >= dim)
-                   {
-                     /* Break out of the loop.  */
-                     m = NULL;
-                     break;
-                   }
-                 else
-                   {
-                     count[n]++;
-                     m += mstride[n];
-                   }
-               }
-           }
-       }
+        {
+         /* We have to count the true elements in MASK.  */
+         total = count_0 (mask);
+        }
 
       if (ret->data == NULL)
        {
index 2d2ed76e6b833b48665b42b6e1129b238d91b426..35bfa1e2a465177c548e75dcc1ac24455a6d87c5 100644 (file)
@@ -237,7 +237,7 @@ index_type count_0 (const gfc_array_l1 * array)
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
       count[n] = 0;
 
-      if (extent[n] < 0)
+      if (extent[n] <= 0)
        return 0;
     }