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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgfortran/] [m4/] [in_unpack.m4] - Blame information for rev 756

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

Line No. Rev Author Line
1 733 jeremybenn
`/* Helper function for repacking arrays.
2
   Copyright 2003, 2006, 2007, 2009 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 3 of the License, or (at your option) any later version.
11
 
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.
16
 
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.
20
 
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/>.  */
25
 
26
#include "libgfortran.h"
27
#include <stdlib.h>
28
#include <assert.h>
29
#include <string.h>'
30
 
31
include(iparm.m4)dnl
32
 
33
`#if defined (HAVE_'rtype_name`)'
34
 
35
dnl Only the kind (ie size) is used to name the function for integers,
36
dnl reals and logicals.  For complex, it's c4 and c8.
37
`void
38
internal_unpack_'rtype_ccode` ('rtype` * d, const 'rtype_name` * src)
39
{
40
  index_type count[GFC_MAX_DIMENSIONS];
41
  index_type extent[GFC_MAX_DIMENSIONS];
42
  index_type stride[GFC_MAX_DIMENSIONS];
43
  index_type stride0;
44
  index_type dim;
45
  index_type dsize;
46
  'rtype_name` * restrict dest;
47
  int n;
48
 
49
  dest = d->data;
50
  if (src == dest || !src)
51
    return;
52
 
53
  dim = GFC_DESCRIPTOR_RANK (d);
54
  dsize = 1;
55
  for (n = 0; n < dim; n++)
56
    {
57
      count[n] = 0;
58
      stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
59
      extent[n] = GFC_DESCRIPTOR_EXTENT(d,n);
60
      if (extent[n] <= 0)
61
        return;
62
 
63
      if (dsize == stride[n])
64
        dsize *= extent[n];
65
      else
66
        dsize = 0;
67
    }
68
 
69
  if (dsize != 0)
70
    {
71
      memcpy (dest, src, dsize * sizeof ('rtype_name`));
72
      return;
73
    }
74
 
75
  stride0 = stride[0];
76
 
77
  while (dest)
78
    {
79
      /* Copy the data.  */
80
      *dest = *(src++);
81
      /* Advance to the next element.  */
82
      dest += stride0;
83
      count[0]++;
84
      /* Advance to the next source element.  */
85
      n = 0;
86
      while (count[n] == extent[n])
87
        {
88
          /* When we get to the end of a dimension, reset it and increment
89
             the next dimension.  */
90
          count[n] = 0;
91
          /* We could precalculate these products, but this is a less
92
             frequently used path so probably not worth it.  */
93
          dest -= stride[n] * extent[n];
94
          n++;
95
          if (n == dim)
96
            {
97
              dest = NULL;
98
              break;
99
            }
100
          else
101
            {
102
              count[n]++;
103
              dest += stride[n];
104
            }
105
        }
106
    }
107
}
108
 
109
#endif
110
'

powered by: WebSVN 2.1.0

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