OSDN Git Service

Remove extra whitespace.
[pf3gnuchains/gcc-fork.git] / libgfortran / generated / matmul_l4.c
1 /* Implementation of the MATMUL intrinsic
2    Copyright 2002, 2005 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 "libgfortran.h"
35
36 /* Dimensions: retarray(x,y) a(x, count) b(count,y).
37    Either a or b can be rank 1.  In this case x or y is 1.  */
38
39 extern void matmul_l4 (gfc_array_l4 *, gfc_array_l4 *, gfc_array_l4 *);
40 export_proto(matmul_l4);
41
42 void
43 matmul_l4 (gfc_array_l4 * retarray, gfc_array_l4 * a, gfc_array_l4 * b)
44 {
45   GFC_INTEGER_4 *abase;
46   GFC_INTEGER_4 *bbase;
47   GFC_LOGICAL_4 *dest;
48   index_type rxstride;
49   index_type rystride;
50   index_type xcount;
51   index_type ycount;
52   index_type xstride;
53   index_type ystride;
54   index_type x;
55   index_type y;
56
57   GFC_INTEGER_4 *pa;
58   GFC_INTEGER_4 *pb;
59   index_type astride;
60   index_type bstride;
61   index_type count;
62   index_type n;
63
64   assert (GFC_DESCRIPTOR_RANK (a) == 2
65           || GFC_DESCRIPTOR_RANK (b) == 2);
66
67   if (retarray->data == NULL)
68     {
69       if (GFC_DESCRIPTOR_RANK (a) == 1)
70         {
71           retarray->dim[0].lbound = 0;
72           retarray->dim[0].ubound = b->dim[1].ubound - b->dim[1].lbound;
73           retarray->dim[0].stride = 1;
74         }
75       else if (GFC_DESCRIPTOR_RANK (b) == 1)
76         {
77           retarray->dim[0].lbound = 0;
78           retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
79           retarray->dim[0].stride = 1;
80         }
81       else
82         {
83           retarray->dim[0].lbound = 0;
84           retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
85           retarray->dim[0].stride = 1;
86
87           retarray->dim[1].lbound = 0;
88           retarray->dim[1].ubound = b->dim[1].ubound - b->dim[1].lbound;
89           retarray->dim[1].stride = retarray->dim[0].ubound+1;
90         }
91
92       retarray->data
93         = internal_malloc_size (sizeof (GFC_LOGICAL_4) * size0 ((array_t *) retarray));
94       retarray->base = 0;
95     }
96
97   abase = a->data;
98   if (GFC_DESCRIPTOR_SIZE (a) != 4)
99     {
100       assert (GFC_DESCRIPTOR_SIZE (a) == 8);
101       abase = GFOR_POINTER_L8_TO_L4 (abase);
102     }
103   bbase = b->data;
104   if (GFC_DESCRIPTOR_SIZE (b) != 4)
105     {
106       assert (GFC_DESCRIPTOR_SIZE (b) == 8);
107       bbase = GFOR_POINTER_L8_TO_L4 (bbase);
108     }
109   dest = retarray->data;
110
111   if (retarray->dim[0].stride == 0)
112     retarray->dim[0].stride = 1;
113   if (a->dim[0].stride == 0)
114     a->dim[0].stride = 1;
115   if (b->dim[0].stride == 0)
116     b->dim[0].stride = 1;
117
118
119   if (GFC_DESCRIPTOR_RANK (retarray) == 1)
120     {
121       rxstride = retarray->dim[0].stride;
122       rystride = rxstride;
123     }
124   else
125     {
126       rxstride = retarray->dim[0].stride;
127       rystride = retarray->dim[1].stride;
128     }
129
130   /* If we have rank 1 parameters, zero the absent stride, and set the size to
131      one.  */
132   if (GFC_DESCRIPTOR_RANK (a) == 1)
133     {
134       astride = a->dim[0].stride;
135       count = a->dim[0].ubound + 1 - a->dim[0].lbound;
136       xstride = 0;
137       rxstride = 0;
138       xcount = 1;
139     }
140   else
141     {
142       astride = a->dim[1].stride;
143       count = a->dim[1].ubound + 1 - a->dim[1].lbound;
144       xstride = a->dim[0].stride;
145       xcount = a->dim[0].ubound + 1 - a->dim[0].lbound;
146     }
147   if (GFC_DESCRIPTOR_RANK (b) == 1)
148     {
149       bstride = b->dim[0].stride;
150       assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
151       ystride = 0;
152       rystride = 0;
153       ycount = 1;
154     }
155   else
156     {
157       bstride = b->dim[0].stride;
158       assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
159       ystride = b->dim[1].stride;
160       ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
161     }
162
163   for (y = 0; y < ycount; y++)
164     {
165       for (x = 0; x < xcount; x++)
166         {
167           /* Do the summation for this element.  For real and integer types
168              this is the same as DOT_PRODUCT.  For complex types we use do
169              a*b, not conjg(a)*b.  */
170           pa = abase;
171           pb = bbase;
172           *dest = 0;
173
174           for (n = 0; n < count; n++)
175             {
176               if (*pa && *pb)
177                 {
178                   *dest = 1;
179                   break;
180                 }
181               pa += astride;
182               pb += bstride;
183             }
184
185           dest += rxstride;
186           abase += xstride;
187         }
188       abase -= xstride * xcount;
189       bbase += ystride;
190       dest += rystride - (rxstride * xcount);
191     }
192 }