]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libgfortran/lib/contrib/m4/transpose.m4
update
[l4.git] / l4 / pkg / libgfortran / lib / contrib / m4 / transpose.m4
1 `/* Implementation of the TRANSPOSE intrinsic
2    Copyright 2003, 2005, 2006, 2007, 2009 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 3 of the License, or (at your option) any later version.
11
12 Libgfortran 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 General Public License for more details.
16
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
20
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24 <http://www.gnu.org/licenses/>.  */
25
26 #include "libgfortran.h"
27 #include <assert.h>'
28
29 include(iparm.m4)dnl
30
31 `#if defined (HAVE_'rtype_name`)
32
33 extern void transpose_'rtype_code` ('rtype` * const restrict ret, 
34         'rtype` * const restrict source);
35 export_proto(transpose_'rtype_code`);
36
37 void
38 transpose_'rtype_code` ('rtype` * const restrict ret, 
39         'rtype` * const restrict source)
40 {
41   /* r.* indicates the return array.  */
42   index_type rxstride, rystride;
43   'rtype_name` * restrict rptr;
44   /* s.* indicates the source array.  */
45   index_type sxstride, systride;
46   const 'rtype_name` *sptr;
47
48   index_type xcount, ycount;
49   index_type x, y;
50
51   assert (GFC_DESCRIPTOR_RANK (source) == 2);
52
53   if (ret->data == NULL)
54     {
55       assert (GFC_DESCRIPTOR_RANK (ret) == 2);
56       assert (ret->dtype == source->dtype);
57
58       GFC_DIMENSION_SET(ret->dim[0], 0, GFC_DESCRIPTOR_EXTENT(source,1) - 1,
59                         1);
60
61       GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
62                         GFC_DESCRIPTOR_EXTENT(source, 1));
63
64       ret->data = internal_malloc_size (sizeof ('rtype_name`) * size0 ((array_t *) ret));
65       ret->offset = 0;
66     } else if (unlikely (compile_options.bounds_check))
67     {
68       index_type ret_extent, src_extent;
69
70       ret_extent = GFC_DESCRIPTOR_EXTENT(ret,0);
71       src_extent = GFC_DESCRIPTOR_EXTENT(source,1);
72
73       if (src_extent != ret_extent)
74         runtime_error ("Incorrect extent in return value of TRANSPOSE"
75                        " intrinsic in dimension 1: is %ld,"
76                        " should be %ld", (long int) src_extent,
77                        (long int) ret_extent);
78
79       ret_extent = GFC_DESCRIPTOR_EXTENT(ret,1);
80       src_extent = GFC_DESCRIPTOR_EXTENT(source,0);
81
82       if (src_extent != ret_extent)
83         runtime_error ("Incorrect extent in return value of TRANSPOSE"
84                        " intrinsic in dimension 2: is %ld,"
85                        " should be %ld", (long int) src_extent,
86                        (long int) ret_extent);
87
88     }
89
90   sxstride = GFC_DESCRIPTOR_STRIDE(source,0);
91   systride = GFC_DESCRIPTOR_STRIDE(source,1);
92   xcount = GFC_DESCRIPTOR_EXTENT(source,0);
93   ycount = GFC_DESCRIPTOR_EXTENT(source,1);
94
95   rxstride = GFC_DESCRIPTOR_STRIDE(ret,0);
96   rystride = GFC_DESCRIPTOR_STRIDE(ret,1);
97
98   rptr = ret->data;
99   sptr = source->data;
100
101   for (y=0; y < ycount; y++)
102     {
103       for (x=0; x < xcount; x++)
104         {
105           *rptr = *sptr;
106
107           sptr += sxstride;
108           rptr += rystride;
109         }
110         sptr += systride - (sxstride * xcount);
111         rptr += rxstride - (rystride * xcount);
112     }
113 }
114
115 #endif'