OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libgfortran/] [m4/] [in_pack.m4] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
`/* Helper function for repacking arrays.
2
   Copyright 2003 Free Software Foundation, Inc.
3
   Contributed by Paul Brook <paul@nowt.org>
4
 
5
This file is part of the GNU Fortran 95 runtime library (libgfortran).
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
10
version 2 of the License, or (at your option) any later version.
11
 
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.)
20
 
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.
25
 
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., 51 Franklin Street, Fifth Floor,
29
Boston, MA 02110-1301, USA.  */
30
 
31
#include "config.h"
32
#include <stdlib.h>
33
#include <assert.h>
34
#include "libgfortran.h"'
35
include(iparm.m4)dnl
36
 
37
`#if defined (HAVE_'rtype_name`)'
38
 
39
/* Allocates a block of memory with internal_malloc if the array needs
40
   repacking.  */
41
 
42
dnl The kind (ie size) is used to name the function for logicals, integers
43
dnl and reals.  For complex, it's c4 or c8.
44
rtype_name *
45
`internal_pack_'rtype_ccode (rtype * source)
46
{
47
  index_type count[GFC_MAX_DIMENSIONS];
48
  index_type extent[GFC_MAX_DIMENSIONS];
49
  index_type stride[GFC_MAX_DIMENSIONS];
50
  index_type stride0;
51
  index_type dim;
52
  index_type ssize;
53
  const rtype_name *src;
54
  rtype_name *dest;
55
  rtype_name *destptr;
56
  int n;
57
  int packed;
58
 
59
  if (source->dim[0].stride == 0)
60
    {
61
      source->dim[0].stride = 1;
62
      return source->data;
63
    }
64
 
65
  dim = GFC_DESCRIPTOR_RANK (source);
66
  ssize = 1;
67
  packed = 1;
68
  for (n = 0; n < dim; n++)
69
    {
70
      count[n] = 0;
71
      stride[n] = source->dim[n].stride;
72
      extent[n] = source->dim[n].ubound + 1 - source->dim[n].lbound;
73
      if (extent[n] <= 0)
74
        {
75
          /* Do nothing.  */
76
          packed = 1;
77
          break;
78
        }
79
 
80
      if (ssize != stride[n])
81
        packed = 0;
82
 
83
      ssize *= extent[n];
84
    }
85
 
86
  if (packed)
87
    return source->data;
88
 
89
  /* Allocate storage for the destination.  */
90
  destptr = (rtype_name *)internal_malloc_size (ssize * sizeof (rtype_name));
91
  dest = destptr;
92
  src = source->data;
93
  stride0 = stride[0];
94
 
95
 
96
  while (src)
97
    {
98
      /* Copy the data.  */
99
      *(dest++) = *src;
100
      /* Advance to the next element.  */
101
      src += stride0;
102
      count[0]++;
103
      /* Advance to the next source element.  */
104
      n = 0;
105
      while (count[n] == extent[n])
106
        {
107
          /* When we get to the end of a dimension, reset it and increment
108
             the next dimension.  */
109
          count[n] = 0;
110
          /* We could precalculate these products, but this is a less
111
             frequently used path so proabably not worth it.  */
112
          src -= stride[n] * extent[n];
113
          n++;
114
          if (n == dim)
115
            {
116
              src = NULL;
117
              break;
118
            }
119
          else
120
            {
121
              count[n]++;
122
              src += stride[n];
123
            }
124
        }
125
    }
126
  return destptr;
127
}
128
 
129
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.