]>
Commit | Line | Data |
---|---|---|
8e1d7686 TK |
1 | /* Helper function for repacking arrays. |
2 | Copyright 2003, 2006, 2007 Free Software Foundation, Inc. | |
3 | Contributed by Paul Brook <paul@nowt.org> | |
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 <stdlib.h> | |
33 | #include <assert.h> | |
34 | #include <string.h> | |
35 | ||
36 | ||
37 | #if defined (HAVE_GFC_REAL_8) | |
38 | ||
39 | void | |
40 | internal_unpack_r8 (gfc_array_r8 * d, const GFC_REAL_8 * src) | |
41 | { | |
42 | index_type count[GFC_MAX_DIMENSIONS]; | |
43 | index_type extent[GFC_MAX_DIMENSIONS]; | |
44 | index_type stride[GFC_MAX_DIMENSIONS]; | |
45 | index_type stride0; | |
46 | index_type dim; | |
47 | index_type dsize; | |
5863aacf | 48 | GFC_REAL_8 * restrict dest; |
8e1d7686 TK |
49 | int n; |
50 | ||
51 | dest = d->data; | |
52 | if (src == dest || !src) | |
53 | return; | |
54 | ||
55 | dim = GFC_DESCRIPTOR_RANK (d); | |
56 | dsize = 1; | |
57 | for (n = 0; n < dim; n++) | |
58 | { | |
59 | count[n] = 0; | |
60 | stride[n] = d->dim[n].stride; | |
61 | extent[n] = d->dim[n].ubound + 1 - d->dim[n].lbound; | |
62 | if (extent[n] <= 0) | |
210879b8 | 63 | return; |
8e1d7686 TK |
64 | |
65 | if (dsize == stride[n]) | |
210879b8 | 66 | dsize *= extent[n]; |
8e1d7686 | 67 | else |
210879b8 | 68 | dsize = 0; |
8e1d7686 TK |
69 | } |
70 | ||
71 | if (dsize != 0) | |
72 | { | |
73 | memcpy (dest, src, dsize * sizeof (GFC_REAL_8)); | |
74 | return; | |
75 | } | |
76 | ||
77 | stride0 = stride[0]; | |
78 | ||
79 | while (dest) | |
80 | { | |
81 | /* Copy the data. */ | |
82 | *dest = *(src++); | |
83 | /* Advance to the next element. */ | |
84 | dest += stride0; | |
85 | count[0]++; | |
86 | /* Advance to the next source element. */ | |
87 | n = 0; | |
88 | while (count[n] == extent[n]) | |
89 | { | |
90 | /* When we get to the end of a dimension, reset it and increment | |
91 | the next dimension. */ | |
92 | count[n] = 0; | |
93 | /* We could precalculate these products, but this is a less | |
94 | frequently used path so probably not worth it. */ | |
95 | dest -= stride[n] * extent[n]; | |
96 | n++; | |
97 | if (n == dim) | |
98 | { | |
99 | dest = NULL; | |
100 | break; | |
101 | } | |
102 | else | |
103 | { | |
104 | count[n]++; | |
105 | dest += stride[n]; | |
106 | } | |
107 | } | |
108 | } | |
109 | } | |
110 | ||
111 | #endif | |
112 |