* cfg.c (connect_src, connect_dest, disconnect_src,
[official-gcc.git] / libgfortran / generated / in_unpack_i4.c
blob87861006ef3eb11d3d532ab9de8cb8471b1199b2
1 /* Helper function for repacking arrays.
2 Copyright 2003 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
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.
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.)
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.
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., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. */
31 #include "config.h"
32 #include <stdlib.h>
33 #include <assert.h>
34 #include <string.h>
35 #include "libgfortran.h"
37 void
38 internal_unpack_4 (gfc_array_i4 * d, const GFC_INTEGER_4 * src)
40 index_type count[GFC_MAX_DIMENSIONS - 1];
41 index_type extent[GFC_MAX_DIMENSIONS - 1];
42 index_type stride[GFC_MAX_DIMENSIONS - 1];
43 index_type stride0;
44 index_type dim;
45 index_type dsize;
46 GFC_INTEGER_4 *dest;
47 int n;
49 dest = d->data;
50 if (src == dest || !src)
51 return;
53 if (d->dim[0].stride == 0)
54 d->dim[0].stride = 1;
56 dim = GFC_DESCRIPTOR_RANK (d);
57 dsize = 1;
58 for (n = 0; n < dim; n++)
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 ();
66 if (dsize == stride[n])
67 dsize *= extent[n];
68 else
69 dsize = 0;
72 if (dsize != 0)
74 memcpy (dest, src, dsize * 4);
75 return;
78 stride0 = stride[0];
80 while (dest)
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])
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)
100 dest = NULL;
101 break;
103 else
105 count[n]++;
106 dest += stride[n];