OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / libgfortran / generated / spread_r10.c
index 9d5afc2..3c3f197 100644 (file)
@@ -1,5 +1,5 @@
 /* Special implementation of the SPREAD intrinsic
-   Copyright 2008 Free Software Foundation, Inc.
+   Copyright 2008, 2009 Free Software Foundation, Inc.
    Contributed by Thomas Koenig <tkoenig@gcc.gnu.org>, based on
    spread_generic.c written by Paul Brook <paul@nowt.org>
 
@@ -8,26 +8,21 @@ This file is part of the GNU Fortran 95 runtime library (libgfortran).
 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 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.)
+version 3 of the License, or (at your option) any later version.
 
 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 General Public License for more details.
 
-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., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
 
 #include "libgfortran.h"
 #include <stdlib.h>
@@ -74,6 +69,9 @@ spread_r10 (gfc_array_r10 *ret, const gfc_array_r10 *source,
 
   if (ret->data == NULL)
     {
+
+      size_t ub, stride;
+
       /* The front end has signalled that we need to populate the
         return array descriptor.  */
       ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rrank;
@@ -81,26 +79,25 @@ spread_r10 (gfc_array_r10 *ret, const gfc_array_r10 *source,
       rs = 1;
       for (n = 0; n < rrank; n++)
        {
-         ret->dim[n].stride = rs;
-         ret->dim[n].lbound = 0;
+         stride = rs;
          if (n == along - 1)
            {
-             ret->dim[n].ubound = ncopies - 1;
+             ub = ncopies - 1;
              rdelta = rs;
              rs *= ncopies;
            }
          else
            {
              count[dim] = 0;
-             extent[dim] = source->dim[dim].ubound + 1
-               - source->dim[dim].lbound;
-             sstride[dim] = source->dim[dim].stride;
+             extent[dim] = GFC_DESCRIPTOR_EXTENT(source,dim);
+             sstride[dim] = GFC_DESCRIPTOR_STRIDE(source,dim);
              rstride[dim] = rs;
 
-             ret->dim[n].ubound = extent[dim]-1;
+             ub = extent[dim] - 1;
              rs *= extent[dim];
              dim++;
            }
+         GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride);
        }
       ret->offset = 0;
       if (rs > 0)
@@ -121,16 +118,16 @@ spread_r10 (gfc_array_r10 *ret, const gfc_array_r10 *source,
       if (GFC_DESCRIPTOR_RANK(ret) != rrank)
        runtime_error ("rank mismatch in spread()");
 
-      if (compile_options.bounds_check)
+      if (unlikely (compile_options.bounds_check))
        {
          for (n = 0; n < rrank; n++)
            {
              index_type ret_extent;
 
-             ret_extent = ret->dim[n].ubound + 1 - ret->dim[n].lbound;
+             ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
              if (n == along - 1)
                {
-                 rdelta = ret->dim[n].stride;
+                 rdelta = GFC_DESCRIPTOR_STRIDE(ret,n);
 
                  if (ret_extent != ncopies)
                    runtime_error("Incorrect extent in return value of SPREAD"
@@ -141,8 +138,7 @@ spread_r10 (gfc_array_r10 *ret, const gfc_array_r10 *source,
              else
                {
                  count[dim] = 0;
-                 extent[dim] = source->dim[dim].ubound + 1
-                   - source->dim[dim].lbound;
+                 extent[dim] = GFC_DESCRIPTOR_EXTENT(source,dim);
                  if (ret_extent != extent[dim])
                    runtime_error("Incorrect extent in return value of SPREAD"
                                  " intrinsic in dimension %ld: is %ld,"
@@ -152,8 +148,8 @@ spread_r10 (gfc_array_r10 *ret, const gfc_array_r10 *source,
                    
                  if (extent[dim] <= 0)
                    zero_sized = 1;
-                 sstride[dim] = source->dim[dim].stride;
-                 rstride[dim] = ret->dim[n].stride;
+                 sstride[dim] = GFC_DESCRIPTOR_STRIDE(source,dim);
+                 rstride[dim] = GFC_DESCRIPTOR_STRIDE(ret,n);
                  dim++;
                }
            }
@@ -164,17 +160,16 @@ spread_r10 (gfc_array_r10 *ret, const gfc_array_r10 *source,
            {
              if (n == along - 1)
                {
-                 rdelta = ret->dim[n].stride;
+                 rdelta = GFC_DESCRIPTOR_STRIDE(ret,n);
                }
              else
                {
                  count[dim] = 0;
-                 extent[dim] = source->dim[dim].ubound + 1
-                   - source->dim[dim].lbound;
+                 extent[dim] = GFC_DESCRIPTOR_EXTENT(source,dim);
                  if (extent[dim] <= 0)
                    zero_sized = 1;
-                 sstride[dim] = source->dim[dim].stride;
-                 rstride[dim] = ret->dim[n].stride;
+                 sstride[dim] = GFC_DESCRIPTOR_STRIDE(source,dim);
+                 rstride[dim] = GFC_DESCRIPTOR_STRIDE(ret,n);
                  dim++;
                }
            }
@@ -253,19 +248,17 @@ spread_scalar_r10 (gfc_array_r10 *ret, const GFC_REAL_10 *source,
     {
       ret->data = internal_malloc_size (ncopies * sizeof (GFC_REAL_10));
       ret->offset = 0;
-      ret->dim[0].stride = 1;
-      ret->dim[0].lbound = 0;
-      ret->dim[0].ubound = ncopies - 1;
+      GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
     }
   else
     {
-      if (ncopies - 1 > (ret->dim[0].ubound - ret->dim[0].lbound)
-                          / ret->dim[0].stride)
+      if (ncopies - 1 > (GFC_DESCRIPTOR_EXTENT(ret,0) - 1)
+                          / GFC_DESCRIPTOR_STRIDE(ret,0))
        runtime_error ("dim too large in spread()");
     }
 
   dest = ret->data;
-  stride = ret->dim[0].stride;
+  stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
   for (n = 0; n < ncopies; n++)
     {