]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/generated/matmul_l4.c
Update copyright years in libgfortran.
[thirdparty/gcc.git] / libgfortran / generated / matmul_l4.c
CommitLineData
6de9cd9a 1/* Implementation of the MATMUL intrinsic
e3c063ce 2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
6de9cd9a
DN
3 Contributed by Paul Brook <paul@nowt.org>
4
21d1335b 5This file is part of the GNU Fortran runtime library (libgfortran).
6de9cd9a
DN
6
7Libgfortran is free software; you can redistribute it and/or
57dea9f6 8modify it under the terms of the GNU General Public
6de9cd9a 9License as published by the Free Software Foundation; either
748086b7 10version 3 of the License, or (at your option) any later version.
6de9cd9a
DN
11
12Libgfortran is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57dea9f6 15GNU General Public License for more details.
6de9cd9a 16
748086b7
JJ
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24<http://www.gnu.org/licenses/>. */
6de9cd9a 25
36ae8a61 26#include "libgfortran.h"
6de9cd9a
DN
27#include <stdlib.h>
28#include <assert.h>
36ae8a61 29
6de9cd9a 30
644cb69f
FXC
31#if defined (HAVE_GFC_LOGICAL_4)
32
6de9cd9a
DN
33/* Dimensions: retarray(x,y) a(x, count) b(count,y).
34 Either a or b can be rank 1. In this case x or y is 1. */
7d7b8bfe 35
85206901 36extern void matmul_l4 (gfc_array_l4 * const restrict,
28dc6b33 37 gfc_array_l1 * const restrict, gfc_array_l1 * const restrict);
7f68c75f 38export_proto(matmul_l4);
7d7b8bfe 39
6de9cd9a 40void
85206901 41matmul_l4 (gfc_array_l4 * const restrict retarray,
28dc6b33 42 gfc_array_l1 * const restrict a, gfc_array_l1 * const restrict b)
6de9cd9a 43{
28dc6b33
TK
44 const GFC_LOGICAL_1 * restrict abase;
45 const GFC_LOGICAL_1 * restrict bbase;
85206901 46 GFC_LOGICAL_4 * restrict dest;
6de9cd9a
DN
47 index_type rxstride;
48 index_type rystride;
49 index_type xcount;
50 index_type ycount;
51 index_type xstride;
52 index_type ystride;
53 index_type x;
54 index_type y;
28dc6b33
TK
55 int a_kind;
56 int b_kind;
6de9cd9a 57
28dc6b33
TK
58 const GFC_LOGICAL_1 * restrict pa;
59 const GFC_LOGICAL_1 * restrict pb;
6de9cd9a
DN
60 index_type astride;
61 index_type bstride;
62 index_type count;
63 index_type n;
64
65 assert (GFC_DESCRIPTOR_RANK (a) == 2
66 || GFC_DESCRIPTOR_RANK (b) == 2);
883c9d4d 67
21d1335b 68 if (retarray->base_addr == NULL)
883c9d4d
VL
69 {
70 if (GFC_DESCRIPTOR_RANK (a) == 1)
71 {
dfb55fdc
TK
72 GFC_DIMENSION_SET(retarray->dim[0], 0,
73 GFC_DESCRIPTOR_EXTENT(b,1) - 1, 1);
883c9d4d
VL
74 }
75 else if (GFC_DESCRIPTOR_RANK (b) == 1)
76 {
dfb55fdc
TK
77 GFC_DIMENSION_SET(retarray->dim[0], 0,
78 GFC_DESCRIPTOR_EXTENT(a,0) - 1, 1);
883c9d4d
VL
79 }
80 else
81 {
dfb55fdc
TK
82 GFC_DIMENSION_SET(retarray->dim[0], 0,
83 GFC_DESCRIPTOR_EXTENT(a,0) - 1, 1);
84
85 GFC_DIMENSION_SET(retarray->dim[1], 0,
86 GFC_DESCRIPTOR_EXTENT(b,1) - 1,
87 GFC_DESCRIPTOR_EXTENT(retarray,0));
883c9d4d 88 }
efd4dc1a 89
21d1335b 90 retarray->base_addr
1a0fd3d3 91 = xmalloc (sizeof (GFC_LOGICAL_4) * size0 ((array_t *) retarray));
efd4dc1a 92 retarray->offset = 0;
883c9d4d 93 }
9731c4a3 94 else if (unlikely (compile_options.bounds_check))
9ad13e91
TK
95 {
96 index_type ret_extent, arg_extent;
97
98 if (GFC_DESCRIPTOR_RANK (a) == 1)
99 {
dfb55fdc
TK
100 arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
101 ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
9ad13e91
TK
102 if (arg_extent != ret_extent)
103 runtime_error ("Incorrect extent in return array in"
104 " MATMUL intrinsic: is %ld, should be %ld",
105 (long int) ret_extent, (long int) arg_extent);
106 }
107 else if (GFC_DESCRIPTOR_RANK (b) == 1)
108 {
dfb55fdc
TK
109 arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
110 ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
9ad13e91
TK
111 if (arg_extent != ret_extent)
112 runtime_error ("Incorrect extent in return array in"
113 " MATMUL intrinsic: is %ld, should be %ld",
114 (long int) ret_extent, (long int) arg_extent);
115 }
116 else
117 {
dfb55fdc
TK
118 arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
119 ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
9ad13e91
TK
120 if (arg_extent != ret_extent)
121 runtime_error ("Incorrect extent in return array in"
122 " MATMUL intrinsic for dimension 1:"
123 " is %ld, should be %ld",
124 (long int) ret_extent, (long int) arg_extent);
125
dfb55fdc
TK
126 arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
127 ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,1);
9ad13e91
TK
128 if (arg_extent != ret_extent)
129 runtime_error ("Incorrect extent in return array in"
130 " MATMUL intrinsic for dimension 2:"
131 " is %ld, should be %ld",
132 (long int) ret_extent, (long int) arg_extent);
133 }
134 }
883c9d4d 135
21d1335b 136 abase = a->base_addr;
28dc6b33
TK
137 a_kind = GFC_DESCRIPTOR_SIZE (a);
138
139 if (a_kind == 1 || a_kind == 2 || a_kind == 4 || a_kind == 8
140#ifdef HAVE_GFC_LOGICAL_16
141 || a_kind == 16
142#endif
143 )
144 abase = GFOR_POINTER_TO_L1 (abase, a_kind);
145 else
146 internal_error (NULL, "Funny sized logical array");
147
21d1335b 148 bbase = b->base_addr;
28dc6b33
TK
149 b_kind = GFC_DESCRIPTOR_SIZE (b);
150
151 if (b_kind == 1 || b_kind == 2 || b_kind == 4 || b_kind == 8
152#ifdef HAVE_GFC_LOGICAL_16
153 || b_kind == 16
154#endif
155 )
156 bbase = GFOR_POINTER_TO_L1 (bbase, b_kind);
157 else
158 internal_error (NULL, "Funny sized logical array");
159
21d1335b 160 dest = retarray->base_addr;
6de9cd9a 161
6de9cd9a
DN
162
163 if (GFC_DESCRIPTOR_RANK (retarray) == 1)
164 {
dfb55fdc 165 rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
6de9cd9a
DN
166 rystride = rxstride;
167 }
168 else
169 {
dfb55fdc
TK
170 rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
171 rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
6de9cd9a
DN
172 }
173
174 /* If we have rank 1 parameters, zero the absent stride, and set the size to
175 one. */
176 if (GFC_DESCRIPTOR_RANK (a) == 1)
177 {
dfb55fdc
TK
178 astride = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
179 count = GFC_DESCRIPTOR_EXTENT(a,0);
6de9cd9a
DN
180 xstride = 0;
181 rxstride = 0;
182 xcount = 1;
183 }
184 else
185 {
dfb55fdc
TK
186 astride = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
187 count = GFC_DESCRIPTOR_EXTENT(a,1);
188 xstride = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
189 xcount = GFC_DESCRIPTOR_EXTENT(a,0);
6de9cd9a
DN
190 }
191 if (GFC_DESCRIPTOR_RANK (b) == 1)
192 {
dfb55fdc
TK
193 bstride = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
194 assert(count == GFC_DESCRIPTOR_EXTENT(b,0));
6de9cd9a
DN
195 ystride = 0;
196 rystride = 0;
197 ycount = 1;
198 }
199 else
200 {
dfb55fdc
TK
201 bstride = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
202 assert(count == GFC_DESCRIPTOR_EXTENT(b,0));
203 ystride = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
204 ycount = GFC_DESCRIPTOR_EXTENT(b,1);
6de9cd9a
DN
205 }
206
207 for (y = 0; y < ycount; y++)
208 {
209 for (x = 0; x < xcount; x++)
210 {
211 /* Do the summation for this element. For real and integer types
212 this is the same as DOT_PRODUCT. For complex types we use do
213 a*b, not conjg(a)*b. */
214 pa = abase;
215 pb = bbase;
216 *dest = 0;
217
218 for (n = 0; n < count; n++)
219 {
220 if (*pa && *pb)
221 {
222 *dest = 1;
223 break;
224 }
225 pa += astride;
226 pb += bstride;
227 }
228
229 dest += rxstride;
230 abase += xstride;
231 }
232 abase -= xstride * xcount;
233 bbase += ystride;
234 dest += rystride - (rxstride * xcount);
235 }
236}
644cb69f
FXC
237
238#endif
28dc6b33 239