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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libgfortran/] [generated/] [any_l4.c] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* Implementation of the ANY intrinsic
2
   Copyright 2002 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
 
36
 
37
#if defined (HAVE_GFC_LOGICAL_4) && defined (HAVE_GFC_LOGICAL_4)
38
 
39
 
40
extern void any_l4 (gfc_array_l4 *, gfc_array_l4 *, index_type *);
41
export_proto(any_l4);
42
 
43
void
44
any_l4 (gfc_array_l4 *retarray, gfc_array_l4 *array, index_type *pdim)
45
{
46
  index_type count[GFC_MAX_DIMENSIONS];
47
  index_type extent[GFC_MAX_DIMENSIONS];
48
  index_type sstride[GFC_MAX_DIMENSIONS];
49
  index_type dstride[GFC_MAX_DIMENSIONS];
50
  GFC_LOGICAL_4 *base;
51
  GFC_LOGICAL_4 *dest;
52
  index_type rank;
53
  index_type n;
54
  index_type len;
55
  index_type delta;
56
  index_type dim;
57
 
58
  /* Make dim zero based to avoid confusion.  */
59
  dim = (*pdim) - 1;
60
  rank = GFC_DESCRIPTOR_RANK (array) - 1;
61
 
62
  /* TODO:  It should be a front end job to correctly set the strides.  */
63
 
64
  if (array->dim[0].stride == 0)
65
    array->dim[0].stride = 1;
66
 
67
  len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
68
  delta = array->dim[dim].stride;
69
 
70
  for (n = 0; n < dim; n++)
71
    {
72
      sstride[n] = array->dim[n].stride;
73
      extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
74
    }
75
  for (n = dim; n < rank; n++)
76
    {
77
      sstride[n] = array->dim[n + 1].stride;
78
      extent[n] =
79
        array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
80
    }
81
 
82
  if (retarray->data == NULL)
83
    {
84
      for (n = 0; n < rank; n++)
85
        {
86
          retarray->dim[n].lbound = 0;
87
          retarray->dim[n].ubound = extent[n]-1;
88
          if (n == 0)
89
            retarray->dim[n].stride = 1;
90
          else
91
            retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
92
        }
93
 
94
      retarray->data
95
         = internal_malloc_size (sizeof (GFC_LOGICAL_4)
96
                                 * retarray->dim[rank-1].stride
97
                                 * extent[rank-1]);
98
      retarray->offset = 0;
99
      retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
100
    }
101
  else
102
    {
103
      if (retarray->dim[0].stride == 0)
104
        retarray->dim[0].stride = 1;
105
 
106
      if (rank != GFC_DESCRIPTOR_RANK (retarray))
107
        runtime_error ("rank of return array incorrect");
108
    }
109
 
110
  for (n = 0; n < rank; n++)
111
    {
112
      count[n] = 0;
113
      dstride[n] = retarray->dim[n].stride;
114
      if (extent[n] <= 0)
115
        len = 0;
116
    }
117
 
118
  base = array->data;
119
  dest = retarray->data;
120
 
121
  while (base)
122
    {
123
      GFC_LOGICAL_4 *src;
124
      GFC_LOGICAL_4 result;
125
      src = base;
126
      {
127
 
128
  result = 0;
129
        if (len <= 0)
130
          *dest = 0;
131
        else
132
          {
133
            for (n = 0; n < len; n++, src += delta)
134
              {
135
 
136
  /* Return true if any of the elements are set.  */
137
  if (*src)
138
    {
139
      result = 1;
140
      break;
141
    }
142
          }
143
            *dest = result;
144
          }
145
      }
146
      /* Advance to the next element.  */
147
      count[0]++;
148
      base += sstride[0];
149
      dest += dstride[0];
150
      n = 0;
151
      while (count[n] == extent[n])
152
        {
153
          /* When we get to the end of a dimension, reset it and increment
154
             the next dimension.  */
155
          count[n] = 0;
156
          /* We could precalculate these products, but this is a less
157
             frequently used path so proabably not worth it.  */
158
          base -= sstride[n] * extent[n];
159
          dest -= dstride[n] * extent[n];
160
          n++;
161
          if (n == rank)
162
            {
163
              /* Break out of the look.  */
164
              base = NULL;
165
              break;
166
            }
167
          else
168
            {
169
              count[n]++;
170
              base += sstride[n];
171
              dest += dstride[n];
172
            }
173
        }
174
    }
175
}
176
 
177
#endif

powered by: WebSVN 2.1.0

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