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. */
25 #include "libgfortran.h"'
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. */
31 `__matmul_'rtype_code (rtype * retarray, gfc_array_l4 * a, gfc_array_l4 * b)
52 assert (GFC_DESCRIPTOR_RANK (a) == 2
53 || GFC_DESCRIPTOR_RANK (b) == 2);
55 if (GFC_DESCRIPTOR_SIZE (a) != 4)
57 assert (GFC_DESCRIPTOR_SIZE (a) == 8);
58 abase = GFOR_POINTER_L8_TO_L4 (abase);
62 if (GFC_DESCRIPTOR_SIZE (b) != 4)
64 assert (GFC_DESCRIPTOR_SIZE (b) == 8);
65 bbase = GFOR_POINTER_L8_TO_L4 (bbase);
68 dest = retarray->data;
70 if (retarray->dim[0].stride == 0)
71 retarray->dim[0].stride = 1;
72 if (a->dim[0].stride == 0)
74 if (b->dim[0].stride == 0)
77 sinclude(`matmul_asm_'rtype_code`.m4')dnl
79 if (GFC_DESCRIPTOR_RANK (retarray) == 1)
81 rxstride = retarray->dim[0].stride;
86 rxstride = retarray->dim[0].stride;
87 rystride = retarray->dim[1].stride;
90 /* If we have rank 1 parameters, zero the absent stride, and set the size to
92 if (GFC_DESCRIPTOR_RANK (a) == 1)
94 astride = a->dim[0].stride;
95 count = a->dim[0].ubound + 1 - a->dim[0].lbound;
102 astride = a->dim[1].stride;
103 count = a->dim[1].ubound + 1 - a->dim[1].lbound;
104 xstride = a->dim[0].stride;
105 xcount = a->dim[0].ubound + 1 - a->dim[0].lbound;
107 if (GFC_DESCRIPTOR_RANK (b) == 1)
109 bstride = b->dim[0].stride;
110 assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
117 bstride = b->dim[0].stride;
118 assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
119 ystride = b->dim[1].stride;
120 ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
123 for (y = 0; y < ycount; y++)
125 for (x = 0; x < xcount; x++)
127 /* Do the summation for this element. For real and integer types
128 this is the same as DOT_PRODUCT. For complex types we use do
129 a*b, not conjg(a)*b. */
134 for (n = 0; n < count; n++)
148 abase -= xstride * xcount;
150 dest += rystride - (rxstride * xcount);