OSDN Git Service

* intrinsics/pack_generic.c (pack): Remove unneeded calculation.
[pf3gnuchains/gcc-fork.git] / libgfortran / intrinsics / pack_generic.c
index 0332b79..06298bb 100644 (file)
@@ -1,21 +1,30 @@
 /* Generic implementation of the PACK intrinsic
-   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
-This file is part of the GNU Fortran 95 runtime library (libgfor).
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
 
-Libgfor is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
 License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-Ligbfor is distributed in the hope that it will be useful,
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file.  (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Ligbfortran is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU Lesser General Public License for more details.
+GNU General Public License for more details.
 
-You should have received a copy of the GNU Lesser General Public
-License along with libgfor; see the file COPYING.LIB.  If not,
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING.  If not,
 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
@@ -28,7 +37,7 @@ Boston, MA 02111-1307, USA.  */
 /* PACK is specified as follows:
 
    13.14.80 PACK (ARRAY, MASK, [VECTOR])
-   
+
    Description: Pack an array into an array of rank one under the
    control of a mask.
 
@@ -40,7 +49,7 @@ Boston, MA 02111-1307, USA.  */
       VECTOR  (optional) shall be of the same type and type parameters
               as ARRAY. VECTOR shall have at least as many elements as
               there are true elements in MASK. If MASK is a scalar
-              with the value true, VECTOR shall have at least as many 
+              with the value true, VECTOR shall have at least as many
               elements as there are in ARRAY.
 
    Result Characteristics: The result is an array of rank one with the
@@ -60,18 +69,18 @@ Boston, MA 02111-1307, USA.  */
    | 9 0 0 | may be "gathered" by the function PACK. The result of
    | 0 0 7 |
    PACK (M, MASK = M.NE.0) is [9,7] and the result of PACK (M, M.NE.0,
-   VECTOR = (/ 2,4,6,8,10,12 /)) is [9,7,6,8,10,12].  
+   VECTOR = (/ 2,4,6,8,10,12 /)) is [9,7,6,8,10,12].
 
 There are two variants of the PACK intrinsic: one, where MASK is
 array valued, and the other one where MASK is scalar.  */
 
-extern void __pack (gfc_array_char *, const gfc_array_char *,
-                   const gfc_array_l4 *, const gfc_array_char *);
-export_proto_np(__pack);
+extern void pack (gfc_array_char *, const gfc_array_char *,
+                 const gfc_array_l4 *, const gfc_array_char *);
+export_proto(pack);
 
 void
-__pack (gfc_array_char * ret, const gfc_array_char * array,
-       const gfc_array_l4 * mask, const gfc_array_char * vector)
+pack (gfc_array_char *ret, const gfc_array_char *array,
+      const gfc_array_l4 *mask, const gfc_array_char *vector)
 {
   /* r.* indicates the return array.  */
   index_type rstride0;
@@ -116,7 +125,6 @@ __pack (gfc_array_char * ret, const gfc_array_char * array,
         runtime_error ("Funny sized logical array");
       for (n = 0; n < dim; n++)
         mstride[n] <<= 1;
-      mstride0 <<= 1;
       mptr = GFOR_POINTER_L8_TO_L4 (mptr);
     }
 
@@ -125,15 +133,15 @@ __pack (gfc_array_char * ret, const gfc_array_char * array,
       /* Allocate the memory for the result.  */
       int total;
 
-      if (vector != NULL) 
-       { 
+      if (vector != NULL)
+       {
          /* The return array will have as many
-            elements as there are in VECTOR.  */ 
-         total = vector->dim[0].ubound + 1 - vector->dim[0].lbound; 
-       } 
-      else 
-       { 
-         /* We have to count the true elements in MASK.  */ 
+            elements as there are in VECTOR.  */
+         total = vector->dim[0].ubound + 1 - vector->dim[0].lbound;
+       }
+      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
@@ -143,7 +151,7 @@ __pack (gfc_array_char * ret, const gfc_array_char * array,
             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. 
+            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.  */
@@ -186,7 +194,7 @@ __pack (gfc_array_char * ret, const gfc_array_char * array,
                }
            }
        }
-      
+
       /* Setup the array descriptor.  */
       ret->dim[0].lbound = 0;
       ret->dim[0].ubound = total - 1;
@@ -269,13 +277,13 @@ __pack (gfc_array_char * ret, const gfc_array_char * array,
     }
 }
 
-extern void __pack_s (gfc_array_char *ret, const gfc_array_char *array,
-                     const GFC_LOGICAL_4 *, const gfc_array_char *);
-export_proto_np(__pack_s);
+extern void pack_s (gfc_array_char *ret, const gfc_array_char *array,
+                   const GFC_LOGICAL_4 *, const gfc_array_char *);
+export_proto(pack_s);
 
 void
-__pack_s (gfc_array_char * ret, const gfc_array_char * array,
-         const GFC_LOGICAL_4 * mask, const gfc_array_char * vector)
+pack_s (gfc_array_char *ret, const gfc_array_char *array,
+       const GFC_LOGICAL_4 *mask, const gfc_array_char *vector)
 {
   /* r.* indicates the return array.  */
   index_type rstride0;
@@ -335,7 +343,7 @@ __pack_s (gfc_array_char * ret, const gfc_array_char * array,
              ret->dim[0].stride = 1;
              ret->data = internal_malloc_size (0);
              ret->base = 0;
-             
+
              return;
            }
        }
@@ -354,7 +362,7 @@ __pack_s (gfc_array_char * ret, const gfc_array_char * array,
     rstride0 = size;
   rptr = ret->data;
 
-  /* The remaining possibilities are now: 
+  /* The remaining possibilities are now:
        If MASK is .TRUE., we have to copy the source array into the
      result array. We then have to fill it up with elements from VECTOR.
        If MASK is .FALSE., we have to copy VECTOR into the result
@@ -395,7 +403,7 @@ __pack_s (gfc_array_char * ret, const gfc_array_char * array,
            }
        }
     }
-  
+
   /* Add any remaining elements from VECTOR.  */
   if (vector)
     {