* i386/i386.c (x86_builtin_vectorization_cost): Likewise.
[official-gcc.git] / libgfortran / generated / in_pack_c16.c
blobd742644eb518c3a3723467a3db75429092282796
1 /* Helper function for repacking arrays.
2 Copyright (C) 2003-2017 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
5 This file is part of the GNU Fortran 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 3 of the License, or (at your option) any later version.
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.
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.
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/>. */
26 #include "libgfortran.h"
29 #if defined (HAVE_GFC_COMPLEX_16)
31 /* Allocates a block of memory with internal_malloc if the array needs
32 repacking. */
34 GFC_COMPLEX_16 *
35 internal_pack_c16 (gfc_array_c16 * source)
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 ssize;
43 const GFC_COMPLEX_16 *src;
44 GFC_COMPLEX_16 * restrict dest;
45 GFC_COMPLEX_16 *destptr;
46 int n;
47 int packed;
49 /* TODO: Investigate how we can figure out if this is a temporary
50 since the stride=0 thing has been removed from the frontend. */
52 dim = GFC_DESCRIPTOR_RANK (source);
53 ssize = 1;
54 packed = 1;
55 for (n = 0; n < dim; n++)
57 count[n] = 0;
58 stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
59 extent[n] = GFC_DESCRIPTOR_EXTENT(source,n);
60 if (extent[n] <= 0)
62 /* Do nothing. */
63 packed = 1;
64 break;
67 if (ssize != stride[n])
68 packed = 0;
70 ssize *= extent[n];
73 if (packed)
74 return source->base_addr;
76 /* Allocate storage for the destination. */
77 destptr = xmallocarray (ssize, sizeof (GFC_COMPLEX_16));
78 dest = destptr;
79 src = source->base_addr;
80 stride0 = stride[0];
83 while (src)
85 /* Copy the data. */
86 *(dest++) = *src;
87 /* Advance to the next element. */
88 src += stride0;
89 count[0]++;
90 /* Advance to the next source element. */
91 n = 0;
92 while (count[n] == extent[n])
94 /* When we get to the end of a dimension, reset it and increment
95 the next dimension. */
96 count[n] = 0;
97 /* We could precalculate these products, but this is a less
98 frequently used path so probably not worth it. */
99 src -= stride[n] * extent[n];
100 n++;
101 if (n == dim)
103 src = NULL;
104 break;
106 else
108 count[n]++;
109 src += stride[n];
113 return destptr;
116 #endif