OSDN Git Service

* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
[pf3gnuchains/gcc-fork.git] / libgfortran / m4 / transpose.m4
1 `/* Implementation of the TRANSPOSE intrinsic
2    Copyright 2003 Free Software Foundation, Inc.
3    Contributed by Tobias Schlüter
4
5 This file is part of the GNU Fortran 95 runtime library (libgfor).
6
7 Libgfor is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 Ligbfor is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with libgfor; see the file COPYING.LIB.  If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "config.h"
23 #include <assert.h>
24 #include "libgfortran.h"'
25 include(iparm.m4)dnl
26
27 extern void `__transpose_'rtype_kind (rtype * ret, rtype * source);
28 export_proto_np(`__transpose_'rtype_kind);
29
30 void
31 `__transpose_'rtype_kind (rtype * ret, rtype * source)
32 {
33   /* r.* indicates the return array.  */
34   index_type rxstride, rystride;
35   rtype_name *rptr;
36   /* s.* indicates the source array.  */
37   index_type sxstride, systride;
38   const rtype_name *sptr;
39
40   index_type xcount, ycount;
41   index_type x, y;
42
43   assert (GFC_DESCRIPTOR_RANK (source) == 2);
44
45   if (ret->data == NULL)
46     {
47       assert (GFC_DESCRIPTOR_RANK (ret) == 2);
48       assert (ret->dtype == source->dtype);
49
50       ret->dim[0].lbound = 0;
51       ret->dim[0].ubound = source->dim[1].ubound - source->dim[1].lbound;
52       ret->dim[0].stride = 1;
53
54       ret->dim[1].lbound = 0;
55       ret->dim[1].ubound = source->dim[0].ubound - source->dim[0].lbound;
56       ret->dim[1].stride = ret->dim[0].ubound+1;
57
58       ret->data = internal_malloc_size (sizeof (rtype_name) * size0 (ret));
59       ret->base = 0;
60     }
61
62   if (ret->dim[0].stride == 0)
63     ret->dim[0].stride = 1;
64   if (source->dim[0].stride == 0)
65     source->dim[0].stride = 1;
66
67   sxstride = source->dim[0].stride;
68   systride = source->dim[1].stride;
69   xcount = source->dim[0].ubound + 1 - source->dim[0].lbound;
70   ycount = source->dim[1].ubound + 1 - source->dim[1].lbound;
71
72   rxstride = ret->dim[0].stride;
73   rystride = ret->dim[1].stride;
74
75   rptr = ret->data;
76   sptr = source->data;
77
78   for (y=0; y < ycount; y++)
79     {
80       for (x=0; x < xcount; x++)
81         {
82           *rptr = *sptr;
83
84           sptr += sxstride;
85           rptr += rystride;
86         }
87         sptr += systride - (sxstride * xcount);
88         rptr += rxstride - (rystride * xcount);
89     }
90 }