]>
Commit | Line | Data |
---|---|---|
98380129 | 1 | /* Helper function for repacking arrays. |
f1717362 | 2 | Copyright (C) 2003-2016 Free Software Foundation, Inc. |
98380129 | 3 | Contributed by Paul Brook <paul@nowt.org> |
4 | ||
553877d9 | 5 | This file is part of the GNU Fortran runtime library (libgfortran). |
98380129 | 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 | |
6bc9506f | 10 | version 3 of the License, or (at your option) any later version. |
98380129 | 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 | ||
6bc9506f | 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/>. */ | |
98380129 | 25 | |
26 | #include "libgfortran.h" | |
27 | #include <stdlib.h> | |
28 | #include <assert.h> | |
29 | #include <string.h> | |
30 | ||
31 | ||
32 | #if defined (HAVE_GFC_REAL_8) | |
33 | ||
34 | void | |
35 | internal_unpack_r8 (gfc_array_r8 * d, const GFC_REAL_8 * src) | |
36 | { | |
37 | index_type count[GFC_MAX_DIMENSIONS]; | |
38 | index_type extent[GFC_MAX_DIMENSIONS]; | |
39 | index_type stride[GFC_MAX_DIMENSIONS]; | |
40 | index_type stride0; | |
41 | index_type dim; | |
42 | index_type dsize; | |
9d259edf | 43 | GFC_REAL_8 * restrict dest; |
98380129 | 44 | int n; |
45 | ||
553877d9 | 46 | dest = d->base_addr; |
98380129 | 47 | if (src == dest || !src) |
48 | return; | |
49 | ||
50 | dim = GFC_DESCRIPTOR_RANK (d); | |
51 | dsize = 1; | |
52 | for (n = 0; n < dim; n++) | |
53 | { | |
54 | count[n] = 0; | |
827aef63 | 55 | stride[n] = GFC_DESCRIPTOR_STRIDE(d,n); |
56 | extent[n] = GFC_DESCRIPTOR_EXTENT(d,n); | |
98380129 | 57 | if (extent[n] <= 0) |
edfaa9e3 | 58 | return; |
98380129 | 59 | |
60 | if (dsize == stride[n]) | |
edfaa9e3 | 61 | dsize *= extent[n]; |
98380129 | 62 | else |
edfaa9e3 | 63 | dsize = 0; |
98380129 | 64 | } |
65 | ||
66 | if (dsize != 0) | |
67 | { | |
68 | memcpy (dest, src, dsize * sizeof (GFC_REAL_8)); | |
69 | return; | |
70 | } | |
71 | ||
72 | stride0 = stride[0]; | |
73 | ||
74 | while (dest) | |
75 | { | |
76 | /* Copy the data. */ | |
77 | *dest = *(src++); | |
78 | /* Advance to the next element. */ | |
79 | dest += stride0; | |
80 | count[0]++; | |
81 | /* Advance to the next source element. */ | |
82 | n = 0; | |
83 | while (count[n] == extent[n]) | |
84 | { | |
85 | /* When we get to the end of a dimension, reset it and increment | |
86 | the next dimension. */ | |
87 | count[n] = 0; | |
88 | /* We could precalculate these products, but this is a less | |
89 | frequently used path so probably not worth it. */ | |
90 | dest -= stride[n] * extent[n]; | |
91 | n++; | |
92 | if (n == dim) | |
93 | { | |
94 | dest = NULL; | |
95 | break; | |
96 | } | |
97 | else | |
98 | { | |
99 | count[n]++; | |
100 | dest += stride[n]; | |
101 | } | |
102 | } | |
103 | } | |
104 | } | |
105 | ||
106 | #endif | |
107 |