Convert diagnostics to use quoting flag q 4/n
[official-gcc.git] / libgfortran / m4 / matmull.m4
blob804127ec005527851ba388b0e7439582ffa7235c
1 `/* Implementation of the MATMUL intrinsic
2    Copyright 2002 Free Software Foundation, Inc.
3    Contributed by Paul Brook <paul@nowt.org>
5 This file is part of the GNU Fortran 95 runtime library (libgfor).
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.
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.
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.  */
22 #include "config.h"
23 #include <stdlib.h>
24 #include <assert.h>
25 #include "libgfortran.h"'
26 include(iparm.m4)dnl
28 /* Dimensions: retarray(x,y) a(x, count) b(count,y).
29    Either a or b can be rank 1.  In this case x or y is 1.  */
30 void
31 `__matmul_'rtype_code (rtype * retarray, gfc_array_l4 * a, gfc_array_l4 * b)
33   GFC_INTEGER_4 *abase;
34   GFC_INTEGER_4 *bbase;
35   rtype_name *dest;
36   index_type rxstride;
37   index_type rystride;
38   index_type xcount;
39   index_type ycount;
40   index_type xstride;
41   index_type ystride;
42   index_type x;
43   index_type y;
45   GFC_INTEGER_4 *pa;
46   GFC_INTEGER_4 *pb;
47   index_type astride;
48   index_type bstride;
49   index_type count;
50   index_type n;
52   assert (GFC_DESCRIPTOR_RANK (a) == 2
53           || GFC_DESCRIPTOR_RANK (b) == 2);
55   if (retarray->data == NULL)
56     {
57       if (GFC_DESCRIPTOR_RANK (a) == 1)
58         {
59           retarray->dim[0].lbound = 0;
60           retarray->dim[0].ubound = b->dim[1].ubound - b->dim[1].lbound;
61           retarray->dim[0].stride = 1;
62         }
63       else if (GFC_DESCRIPTOR_RANK (b) == 1)
64         {
65           retarray->dim[0].lbound = 0;
66           retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
67           retarray->dim[0].stride = 1;
68         }
69       else
70         {
71           retarray->dim[0].lbound = 0;
72           retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
73           retarray->dim[0].stride = 1;
74           
75           retarray->dim[1].lbound = 0;
76           retarray->dim[1].ubound = b->dim[1].ubound - b->dim[1].lbound;
77           retarray->dim[1].stride = retarray->dim[0].ubound+1;
78         }
79           
80       retarray->data = internal_malloc (sizeof (rtype_name) * size0 (retarray));
81       retarray->base = 0;
82     }
84   abase = a->data;
85   if (GFC_DESCRIPTOR_SIZE (a) != 4)
86     {
87       assert (GFC_DESCRIPTOR_SIZE (a) == 8);
88       abase = GFOR_POINTER_L8_TO_L4 (abase);
89       astride <<= 1;
90     }
91   bbase = b->data;
92   if (GFC_DESCRIPTOR_SIZE (b) != 4)
93     {
94       assert (GFC_DESCRIPTOR_SIZE (b) == 8);
95       bbase = GFOR_POINTER_L8_TO_L4 (bbase);
96       bstride <<= 1;
97     }
98   dest = retarray->data;
100   if (retarray->dim[0].stride == 0)
101     retarray->dim[0].stride = 1;
102   if (a->dim[0].stride == 0)
103     a->dim[0].stride = 1;
104   if (b->dim[0].stride == 0)
105     b->dim[0].stride = 1;
107 sinclude(`matmul_asm_'rtype_code`.m4')dnl
109   if (GFC_DESCRIPTOR_RANK (retarray) == 1)
110     {
111       rxstride = retarray->dim[0].stride;
112       rystride = rxstride;
113     }
114   else
115     {
116       rxstride = retarray->dim[0].stride;
117       rystride = retarray->dim[1].stride;
118     }
120   /* If we have rank 1 parameters, zero the absent stride, and set the size to
121      one.  */
122   if (GFC_DESCRIPTOR_RANK (a) == 1)
123     {
124       astride = a->dim[0].stride;
125       count = a->dim[0].ubound + 1 - a->dim[0].lbound;
126       xstride = 0;
127       rxstride = 0;
128       xcount = 1;
129     }
130   else
131     {
132       astride = a->dim[1].stride;
133       count = a->dim[1].ubound + 1 - a->dim[1].lbound;
134       xstride = a->dim[0].stride;
135       xcount = a->dim[0].ubound + 1 - a->dim[0].lbound;
136     }
137   if (GFC_DESCRIPTOR_RANK (b) == 1)
138     {
139       bstride = b->dim[0].stride;
140       assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
141       ystride = 0;
142       rystride = 0;
143       ycount = 1;
144     }
145   else
146     {
147       bstride = b->dim[0].stride;
148       assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
149       ystride = b->dim[1].stride;
150       ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
151     }
153   for (y = 0; y < ycount; y++)
154     {
155       for (x = 0; x < xcount; x++)
156         {
157           /* Do the summation for this element.  For real and integer types
158              this is the same as DOT_PRODUCT.  For complex types we use do
159              a*b, not conjg(a)*b.  */
160           pa = abase;
161           pb = bbase;
162           *dest = 0;
164           for (n = 0; n < count; n++)
165             {
166               if (*pa && *pb)
167                 {
168                   *dest = 1;
169                   break;
170                 }
171               pa += astride;
172               pb += bstride;
173             }
175           dest += rxstride;
176           abase += xstride;
177         }
178       abase -= xstride * xcount;
179       bbase += ystride;
180       dest += rystride - (rxstride * xcount);
181     }