OSDN Git Service

Correct previous ChangeLog entry.
[pf3gnuchains/gcc-fork.git] / libgfortran / generated / matmul_l4.c
1 /* Implementation of the MATMUL 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 (libgfor).
6
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 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 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with libgfor; see the file COPYING.LIB.  If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "config.h"
23 #include <stdlib.h>
24 #include <assert.h>
25 #include "libgfortran.h"
26
27 /* Dimensions: retarray(x,y) a(x, count) b(count,y).
28    Either a or b can be rank 1.  In this case x or y is 1.  */
29 void
30 __matmul_l4 (gfc_array_l4 * retarray, gfc_array_l4 * a, gfc_array_l4 * b)
31 {
32   GFC_INTEGER_4 *abase;
33   GFC_INTEGER_4 *bbase;
34   GFC_LOGICAL_4 *dest;
35   index_type rxstride;
36   index_type rystride;
37   index_type xcount;
38   index_type ycount;
39   index_type xstride;
40   index_type ystride;
41   index_type x;
42   index_type y;
43
44   GFC_INTEGER_4 *pa;
45   GFC_INTEGER_4 *pb;
46   index_type astride;
47   index_type bstride;
48   index_type count;
49   index_type n;
50
51   assert (GFC_DESCRIPTOR_RANK (a) == 2
52           || GFC_DESCRIPTOR_RANK (b) == 2);
53   abase = a->data;
54   if (GFC_DESCRIPTOR_SIZE (a) != 4)
55     {
56       assert (GFC_DESCRIPTOR_SIZE (a) == 8);
57       abase = GFOR_POINTER_L8_TO_L4 (abase);
58       astride <<= 1;
59     }
60   bbase = b->data;
61   if (GFC_DESCRIPTOR_SIZE (b) != 4)
62     {
63       assert (GFC_DESCRIPTOR_SIZE (b) == 8);
64       bbase = GFOR_POINTER_L8_TO_L4 (bbase);
65       bstride <<= 1;
66     }
67   dest = retarray->data;
68
69   if (retarray->dim[0].stride == 0)
70     retarray->dim[0].stride = 1;
71   if (a->dim[0].stride == 0)
72     a->dim[0].stride = 1;
73   if (b->dim[0].stride == 0)
74     b->dim[0].stride = 1;
75
76
77   if (GFC_DESCRIPTOR_RANK (retarray) == 1)
78     {
79       rxstride = retarray->dim[0].stride;
80       rystride = rxstride;
81     }
82   else
83     {
84       rxstride = retarray->dim[0].stride;
85       rystride = retarray->dim[1].stride;
86     }
87
88   /* If we have rank 1 parameters, zero the absent stride, and set the size to
89      one.  */
90   if (GFC_DESCRIPTOR_RANK (a) == 1)
91     {
92       astride = a->dim[0].stride;
93       count = a->dim[0].ubound + 1 - a->dim[0].lbound;
94       xstride = 0;
95       rxstride = 0;
96       xcount = 1;
97     }
98   else
99     {
100       astride = a->dim[1].stride;
101       count = a->dim[1].ubound + 1 - a->dim[1].lbound;
102       xstride = a->dim[0].stride;
103       xcount = a->dim[0].ubound + 1 - a->dim[0].lbound;
104     }
105   if (GFC_DESCRIPTOR_RANK (b) == 1)
106     {
107       bstride = b->dim[0].stride;
108       assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
109       ystride = 0;
110       rystride = 0;
111       ycount = 1;
112     }
113   else
114     {
115       bstride = b->dim[0].stride;
116       assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
117       ystride = b->dim[1].stride;
118       ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
119     }
120
121   for (y = 0; y < ycount; y++)
122     {
123       for (x = 0; x < xcount; x++)
124         {
125           /* Do the summation for this element.  For real and integer types
126              this is the same as DOT_PRODUCT.  For complex types we use do
127              a*b, not conjg(a)*b.  */
128           pa = abase;
129           pb = bbase;
130           *dest = 0;
131
132           for (n = 0; n < count; n++)
133             {
134               if (*pa && *pb)
135                 {
136                   *dest = 1;
137                   break;
138                 }
139               pa += astride;
140               pb += bstride;
141             }
142
143           dest += rxstride;
144           abase += xstride;
145         }
146       abase -= xstride * xcount;
147       bbase += ystride;
148       dest += rystride - (rxstride * xcount);
149     }
150 }
151