]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/generated/in_unpack_c10.c
minloc1.m4: Update copyright year and ajust headers order.
[thirdparty/gcc.git] / libgfortran / generated / in_unpack_c10.c
CommitLineData
644cb69f 1/* Helper function for repacking arrays.
36ae8a61 2 Copyright 2003, 2006, 2007 Free Software Foundation, Inc.
644cb69f
FXC
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,
28write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29Boston, MA 02110-1301, USA. */
30
36ae8a61 31#include "libgfortran.h"
644cb69f
FXC
32#include <stdlib.h>
33#include <assert.h>
34#include <string.h>
36ae8a61 35
644cb69f
FXC
36
37#if defined (HAVE_GFC_COMPLEX_10)
38
39void
40internal_unpack_c10 (gfc_array_c10 * d, const GFC_COMPLEX_10 * 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;
48 GFC_COMPLEX_10 *dest;
49 int n;
50
51 dest = d->data;
52 if (src == dest || !src)
53 return;
54
644cb69f
FXC
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)
63 abort ();
64
65 if (dsize == stride[n])
66 dsize *= extent[n];
67 else
68 dsize = 0;
69 }
70
71 if (dsize != 0)
72 {
73 memcpy (dest, src, dsize * sizeof (GFC_COMPLEX_10));
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
5d7adf7a 94 frequently used path so probably not worth it. */
644cb69f
FXC
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
36ae8a61 112