1 `/* Implementation of the MATMUL intrinsic
2 Copyright 2002, 2005, 2006 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
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.
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
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.
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., 51 Franklin Street, Fifth Floor,
29 Boston, MA 02110-1301, USA. */
34 #include "libgfortran.h"'
37 `#if defined (HAVE_'rtype_name`)
39 /* Dimensions: retarray(x,y) a(x, count) b(count,y).
40 Either a or b can be rank 1. In this case x or y is 1. */
42 extern void matmul_'rtype_code` ('rtype` * const restrict,
43 gfc_array_l1 * const restrict, gfc_array_l1 * const restrict);
44 export_proto(matmul_'rtype_code`);
47 matmul_'rtype_code` ('rtype` * const restrict retarray,
48 gfc_array_l1 * const restrict a, gfc_array_l1 * const restrict b)
50 const GFC_LOGICAL_1 * restrict abase;
51 const GFC_LOGICAL_1 * restrict bbase;
52 'rtype_name` * restrict dest;
64 const GFC_LOGICAL_1 * restrict pa;
65 const GFC_LOGICAL_1 * restrict pb;
71 assert (GFC_DESCRIPTOR_RANK (a) == 2
72 || GFC_DESCRIPTOR_RANK (b) == 2);
74 if (retarray->data == NULL)
76 if (GFC_DESCRIPTOR_RANK (a) == 1)
78 retarray->dim[0].lbound = 0;
79 retarray->dim[0].ubound = b->dim[1].ubound - b->dim[1].lbound;
80 retarray->dim[0].stride = 1;
82 else if (GFC_DESCRIPTOR_RANK (b) == 1)
84 retarray->dim[0].lbound = 0;
85 retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
86 retarray->dim[0].stride = 1;
90 retarray->dim[0].lbound = 0;
91 retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
92 retarray->dim[0].stride = 1;
94 retarray->dim[1].lbound = 0;
95 retarray->dim[1].ubound = b->dim[1].ubound - b->dim[1].lbound;
96 retarray->dim[1].stride = retarray->dim[0].ubound+1;
100 = internal_malloc_size (sizeof ('rtype_name`) * size0 ((array_t *) retarray));
101 retarray->offset = 0;
105 a_kind = GFC_DESCRIPTOR_SIZE (a);
107 if (a_kind == 1 || a_kind == 2 || a_kind == 4 || a_kind == 8
108 #ifdef HAVE_GFC_LOGICAL_16
112 abase = GFOR_POINTER_TO_L1 (abase, a_kind);
114 internal_error (NULL, "Funny sized logical array");
117 b_kind = GFC_DESCRIPTOR_SIZE (b);
119 if (b_kind == 1 || b_kind == 2 || b_kind == 4 || b_kind == 8
120 #ifdef HAVE_GFC_LOGICAL_16
124 bbase = GFOR_POINTER_TO_L1 (bbase, b_kind);
126 internal_error (NULL, "Funny sized logical array");
128 dest = retarray->data;
130 sinclude(`matmul_asm_'rtype_code`.m4')dnl
132 if (GFC_DESCRIPTOR_RANK (retarray) == 1)
134 rxstride = retarray->dim[0].stride;
139 rxstride = retarray->dim[0].stride;
140 rystride = retarray->dim[1].stride;
143 /* If we have rank 1 parameters, zero the absent stride, and set the size to
145 if (GFC_DESCRIPTOR_RANK (a) == 1)
147 astride = a->dim[0].stride * a_kind;
148 count = a->dim[0].ubound + 1 - a->dim[0].lbound;
155 astride = a->dim[1].stride * a_kind;
156 count = a->dim[1].ubound + 1 - a->dim[1].lbound;
157 xstride = a->dim[0].stride;
158 xcount = a->dim[0].ubound + 1 - a->dim[0].lbound;
160 if (GFC_DESCRIPTOR_RANK (b) == 1)
162 bstride = b->dim[0].stride * b_kind;
163 assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
170 bstride = b->dim[0].stride * b_kind;
171 assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
172 ystride = b->dim[1].stride;
173 ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
176 for (y = 0; y < ycount; y++)
178 for (x = 0; x < xcount; x++)
180 /* Do the summation for this element. For real and integer types
181 this is the same as DOT_PRODUCT. For complex types we use do
182 a*b, not conjg(a)*b. */
187 for (n = 0; n < count; n++)
201 abase -= xstride * xcount;
203 dest += rystride - (rxstride * xcount);