]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/generated/in_unpack_c8.c
target-supports.exp (check_effective_target_vect_shift): Implement with result caching.
[thirdparty/gcc.git] / libgfortran / generated / in_unpack_c8.c
CommitLineData
39328081
TK
1/* Helper function for repacking arrays.
2 Copyright 2003 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
4
5This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
7Libgfortran is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public
9License as published by the Free Software Foundation; either
10version 2 of the License, or (at your option) any later version.
11
12In addition to the permissions in the GNU General Public License, the
13Free Software Foundation gives you unlimited permission to link the
14compiled version of this file into combinations with other programs,
15and to distribute those combinations without any restriction coming
16from the use of this file. (The General Public License restrictions
17do apply in other respects; for example, they cover modification of
18the file, and distribution when not linked into a combine
19executable.)
20
21Libgfortran is distributed in the hope that it will be useful,
22but WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24GNU General Public License for more details.
25
26You should have received a copy of the GNU General Public
27License along with libgfortran; see the file COPYING. If not,
fe2ae685
KC
28write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29Boston, MA 02110-1301, USA. */
39328081
TK
30
31#include "config.h"
32#include <stdlib.h>
33#include <assert.h>
34#include <string.h>
35#include "libgfortran.h"
36
37void
38internal_unpack_c8 (gfc_array_c8 * d, const GFC_COMPLEX_8 * src)
39{
40 index_type count[GFC_MAX_DIMENSIONS];
41 index_type extent[GFC_MAX_DIMENSIONS];
42 index_type stride[GFC_MAX_DIMENSIONS];
43 index_type stride0;
44 index_type dim;
45 index_type dsize;
46 GFC_COMPLEX_8 *dest;
47 int n;
48
49 dest = d->data;
50 if (src == dest || !src)
51 return;
52
53 if (d->dim[0].stride == 0)
54 d->dim[0].stride = 1;
55
56 dim = GFC_DESCRIPTOR_RANK (d);
57 dsize = 1;
58 for (n = 0; n < dim; n++)
59 {
60 count[n] = 0;
61 stride[n] = d->dim[n].stride;
62 extent[n] = d->dim[n].ubound + 1 - d->dim[n].lbound;
63 if (extent[n] <= 0)
64 abort ();
65
66 if (dsize == stride[n])
67 dsize *= extent[n];
68 else
69 dsize = 0;
70 }
71
72 if (dsize != 0)
73 {
74 memcpy (dest, src, dsize * sizeof (GFC_COMPLEX_8));
75 return;
76 }
77
78 stride0 = stride[0];
79
80 while (dest)
81 {
82 /* Copy the data. */
83 *dest = *(src++);
84 /* Advance to the next element. */
85 dest += stride0;
86 count[0]++;
87 /* Advance to the next source element. */
88 n = 0;
89 while (count[n] == extent[n])
90 {
91 /* When we get to the end of a dimension, reset it and increment
92 the next dimension. */
93 count[n] = 0;
94 /* We could precalculate these products, but this is a less
95 frequently used path so proabably not worth it. */
96 dest -= stride[n] * extent[n];
97 n++;
98 if (n == dim)
99 {
100 dest = NULL;
101 break;
102 }
103 else
104 {
105 count[n]++;
106 dest += stride[n];
107 }
108 }
109 }
110}
111