OSDN Git Service

2008-10-21 Thomas Koenig <tkoenig@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / libgfortran / generated / transpose_c8.c
1 /* Implementation of the TRANSPOSE intrinsic
2    Copyright 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
3    Contributed by Tobias Schlüter
4
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file.  (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
19 executable.)
20
21 Libgfortran is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public
27 License along with libgfortran; see the file COPYING.  If not,
28 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 Boston, MA 02110-1301, USA.  */
30
31 #include "libgfortran.h"
32 #include <assert.h>
33
34
35 #if defined (HAVE_GFC_COMPLEX_8)
36
37 extern void transpose_c8 (gfc_array_c8 * const restrict ret, 
38         gfc_array_c8 * const restrict source);
39 export_proto(transpose_c8);
40
41 void
42 transpose_c8 (gfc_array_c8 * const restrict ret, 
43         gfc_array_c8 * const restrict source)
44 {
45   /* r.* indicates the return array.  */
46   index_type rxstride, rystride;
47   GFC_COMPLEX_8 * restrict rptr;
48   /* s.* indicates the source array.  */
49   index_type sxstride, systride;
50   const GFC_COMPLEX_8 *sptr;
51
52   index_type xcount, ycount;
53   index_type x, y;
54
55   assert (GFC_DESCRIPTOR_RANK (source) == 2);
56
57   if (ret->data == NULL)
58     {
59       assert (GFC_DESCRIPTOR_RANK (ret) == 2);
60       assert (ret->dtype == source->dtype);
61
62       ret->dim[0].lbound = 0;
63       ret->dim[0].ubound = source->dim[1].ubound - source->dim[1].lbound;
64       ret->dim[0].stride = 1;
65
66       ret->dim[1].lbound = 0;
67       ret->dim[1].ubound = source->dim[0].ubound - source->dim[0].lbound;
68       ret->dim[1].stride = ret->dim[0].ubound+1;
69
70       ret->data = internal_malloc_size (sizeof (GFC_COMPLEX_8) * size0 ((array_t *) ret));
71       ret->offset = 0;
72     } else if (unlikely (compile_options.bounds_check))
73     {
74       index_type ret_extent, src_extent;
75
76       ret_extent = ret->dim[0].ubound + 1 - ret->dim[0].lbound;
77       src_extent = source->dim[1].ubound + 1 - source->dim[1].lbound;
78
79       if (src_extent != ret_extent)
80         runtime_error ("Incorrect extent in return value of TRANSPOSE"
81                        " intrinsic in dimension 1: is %ld,"
82                        " should be %ld", (long int) src_extent,
83                        (long int) ret_extent);
84
85       ret_extent = ret->dim[1].ubound + 1 - ret->dim[1].lbound;
86       src_extent = source->dim[0].ubound + 1 - source->dim[0].lbound;
87
88       if (src_extent != ret_extent)
89         runtime_error ("Incorrect extent in return value of TRANSPOSE"
90                        " intrinsic in dimension 2: is %ld,"
91                        " should be %ld", (long int) src_extent,
92                        (long int) ret_extent);
93
94     }
95
96   sxstride = source->dim[0].stride;
97   systride = source->dim[1].stride;
98   xcount = source->dim[0].ubound + 1 - source->dim[0].lbound;
99   ycount = source->dim[1].ubound + 1 - source->dim[1].lbound;
100
101   rxstride = ret->dim[0].stride;
102   rystride = ret->dim[1].stride;
103
104   rptr = ret->data;
105   sptr = source->data;
106
107   for (y=0; y < ycount; y++)
108     {
109       for (x=0; x < xcount; x++)
110         {
111           *rptr = *sptr;
112
113           sptr += sxstride;
114           rptr += rystride;
115         }
116         sptr += systride - (sxstride * xcount);
117         rptr += rxstride - (rystride * xcount);
118     }
119 }
120
121 #endif