OSDN Git Service

* gcc.dg/const-elim-1.c: Remove xfail for xtensa-*-*.
[pf3gnuchains/gcc-fork.git] / libgfortran / generated / eoshift3_8.c
1 /* Implementation of the EOSHIFT 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., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA.  */
30
31 #include "config.h"
32 #include <stdlib.h>
33 #include <assert.h>
34 #include <string.h>
35 #include "libgfortran.h"
36
37 static const char zeros[16] =
38   {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
39
40 extern void eoshift3_8 (gfc_array_char *, gfc_array_char *,
41                                      gfc_array_i8 *, const gfc_array_char *,
42                                      GFC_INTEGER_8 *);
43 export_proto(eoshift3_8);
44
45 void
46 eoshift3_8 (gfc_array_char *ret, gfc_array_char *array,
47                        gfc_array_i8 *h, const gfc_array_char *bound,
48                        GFC_INTEGER_8 *pwhich)
49 {
50   /* r.* indicates the return array.  */
51   index_type rstride[GFC_MAX_DIMENSIONS];
52   index_type rstride0;
53   index_type roffset;
54   char *rptr;
55   char *dest;
56   /* s.* indicates the source array.  */
57   index_type sstride[GFC_MAX_DIMENSIONS];
58   index_type sstride0;
59   index_type soffset;
60   const char *sptr;
61   const char *src;
62   /* h.* indicates the shift array.  */
63   index_type hstride[GFC_MAX_DIMENSIONS];
64   index_type hstride0;
65   const GFC_INTEGER_8 *hptr;
66   /* b.* indicates the bound array.  */
67   index_type bstride[GFC_MAX_DIMENSIONS];
68   index_type bstride0;
69   const char *bptr;
70
71   index_type count[GFC_MAX_DIMENSIONS];
72   index_type extent[GFC_MAX_DIMENSIONS];
73   index_type dim;
74   index_type size;
75   index_type len;
76   index_type n;
77   int which;
78   GFC_INTEGER_8 sh;
79   GFC_INTEGER_8 delta;
80
81   if (pwhich)
82     which = *pwhich - 1;
83   else
84     which = 0;
85
86   size = GFC_DESCRIPTOR_SIZE (ret);
87
88   extent[0] = 1;
89   count[0] = 0;
90   size = GFC_DESCRIPTOR_SIZE (array);
91   n = 0;
92   for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
93     {
94       if (dim == which)
95         {
96           roffset = ret->dim[dim].stride * size;
97           if (roffset == 0)
98             roffset = size;
99           soffset = array->dim[dim].stride * size;
100           if (soffset == 0)
101             soffset = size;
102           len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
103         }
104       else
105         {
106           count[n] = 0;
107           extent[n] = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
108           rstride[n] = ret->dim[dim].stride * size;
109           sstride[n] = array->dim[dim].stride * size;
110
111           hstride[n] = h->dim[n].stride;
112           if (bound)
113             bstride[n] = bound->dim[n].stride;
114           else
115             bstride[n] = 0;
116           n++;
117         }
118     }
119   if (sstride[0] == 0)
120     sstride[0] = size;
121   if (rstride[0] == 0)
122     rstride[0] = size;
123   if (hstride[0] == 0)
124     hstride[0] = 1;
125   if (bound && bstride[0] == 0)
126     bstride[0] = size;
127
128   dim = GFC_DESCRIPTOR_RANK (array);
129   rstride0 = rstride[0];
130   sstride0 = sstride[0];
131   hstride0 = hstride[0];
132   bstride0 = bstride[0];
133   rptr = ret->data;
134   sptr = array->data;
135   hptr = h->data;
136   if (bound)
137     bptr = bound->data;
138   else
139     bptr = zeros;
140
141   while (rptr)
142     {
143       /* Do the shift for this dimension.  */
144       sh = *hptr;
145       delta = (sh >= 0) ? sh: -sh;
146       if (sh > 0)
147         {
148           src = &sptr[delta * soffset];
149           dest = rptr;
150         }
151       else
152         {
153           src = sptr;
154           dest = &rptr[delta * roffset];
155         }
156       for (n = 0; n < len - delta; n++)
157         {
158           memcpy (dest, src, size);
159           dest += roffset;
160           src += soffset;
161         }
162       if (sh < 0)
163         dest = rptr;
164       n = delta;
165
166       while (n--)
167         {
168           memcpy (dest, bptr, size);
169           dest += roffset;
170         }
171
172       /* Advance to the next section.  */
173       rptr += rstride0;
174       sptr += sstride0;
175       hptr += hstride0;
176       bptr += bstride0;
177       count[0]++;
178       n = 0;
179       while (count[n] == extent[n])
180         {
181           /* When we get to the end of a dimension, reset it and increment
182              the next dimension.  */
183           count[n] = 0;
184           /* We could precalculate these products, but this is a less
185              frequently used path so proabably not worth it.  */
186           rptr -= rstride[n] * extent[n];
187           sptr -= sstride[n] * extent[n];
188           hptr -= hstride[n] * extent[n];
189           bptr -= bstride[n] * extent[n];
190           n++;
191           if (n >= dim - 1)
192             {
193               /* Break out of the loop.  */
194               rptr = NULL;
195               break;
196             }
197           else
198             {
199               count[n]++;
200               rptr += rstride[n];
201               sptr += sstride[n];
202               hptr += hstride[n];
203               bptr += bstride[n];
204             }
205         }
206     }
207 }