]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/generated/matmul_l16.c
minloc1.m4: Update copyright year and ajust headers order.
[thirdparty/gcc.git] / libgfortran / generated / matmul_l16.c
CommitLineData
644cb69f 1/* Implementation of the MATMUL intrinsic
36ae8a61 2 Copyright 2002, 2005, 2006, 2007 Free Software Foundation, Inc.
644cb69f
FXC
3 Contributed by Paul Brook <paul@nowt.org>
4
5This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
7Libgfortran is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public
9License as published by the Free Software Foundation; either
10version 2 of the License, or (at your option) any later version.
11
12In addition to the permissions in the GNU General Public License, the
13Free Software Foundation gives you unlimited permission to link the
14compiled version of this file into combinations with other programs,
15and to distribute those combinations without any restriction coming
16from the use of this file. (The General Public License restrictions
17do apply in other respects; for example, they cover modification of
18the file, and distribution when not linked into a combine
19executable.)
20
21Libgfortran is distributed in the hope that it will be useful,
22but WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24GNU General Public License for more details.
25
26You should have received a copy of the GNU General Public
27License along with libgfortran; see the file COPYING. If not,
28write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29Boston, MA 02110-1301, USA. */
30
36ae8a61 31#include "libgfortran.h"
644cb69f
FXC
32#include <stdlib.h>
33#include <assert.h>
36ae8a61 34
644cb69f
FXC
35
36#if defined (HAVE_GFC_LOGICAL_16)
37
38/* Dimensions: retarray(x,y) a(x, count) b(count,y).
39 Either a or b can be rank 1. In this case x or y is 1. */
40
85206901 41extern void matmul_l16 (gfc_array_l16 * const restrict,
28dc6b33 42 gfc_array_l1 * const restrict, gfc_array_l1 * const restrict);
644cb69f
FXC
43export_proto(matmul_l16);
44
45void
85206901 46matmul_l16 (gfc_array_l16 * const restrict retarray,
28dc6b33 47 gfc_array_l1 * const restrict a, gfc_array_l1 * const restrict b)
644cb69f 48{
28dc6b33
TK
49 const GFC_LOGICAL_1 * restrict abase;
50 const GFC_LOGICAL_1 * restrict bbase;
85206901 51 GFC_LOGICAL_16 * restrict dest;
644cb69f
FXC
52 index_type rxstride;
53 index_type rystride;
54 index_type xcount;
55 index_type ycount;
56 index_type xstride;
57 index_type ystride;
58 index_type x;
59 index_type y;
28dc6b33
TK
60 int a_kind;
61 int b_kind;
644cb69f 62
28dc6b33
TK
63 const GFC_LOGICAL_1 * restrict pa;
64 const GFC_LOGICAL_1 * restrict pb;
644cb69f
FXC
65 index_type astride;
66 index_type bstride;
67 index_type count;
68 index_type n;
69
70 assert (GFC_DESCRIPTOR_RANK (a) == 2
71 || GFC_DESCRIPTOR_RANK (b) == 2);
72
73 if (retarray->data == NULL)
74 {
75 if (GFC_DESCRIPTOR_RANK (a) == 1)
76 {
77 retarray->dim[0].lbound = 0;
78 retarray->dim[0].ubound = b->dim[1].ubound - b->dim[1].lbound;
79 retarray->dim[0].stride = 1;
80 }
81 else if (GFC_DESCRIPTOR_RANK (b) == 1)
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 else
88 {
89 retarray->dim[0].lbound = 0;
90 retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
91 retarray->dim[0].stride = 1;
92
93 retarray->dim[1].lbound = 0;
94 retarray->dim[1].ubound = b->dim[1].ubound - b->dim[1].lbound;
95 retarray->dim[1].stride = retarray->dim[0].ubound+1;
96 }
97
98 retarray->data
99 = internal_malloc_size (sizeof (GFC_LOGICAL_16) * size0 ((array_t *) retarray));
100 retarray->offset = 0;
101 }
102
103 abase = a->data;
28dc6b33
TK
104 a_kind = GFC_DESCRIPTOR_SIZE (a);
105
106 if (a_kind == 1 || a_kind == 2 || a_kind == 4 || a_kind == 8
107#ifdef HAVE_GFC_LOGICAL_16
108 || a_kind == 16
109#endif
110 )
111 abase = GFOR_POINTER_TO_L1 (abase, a_kind);
112 else
113 internal_error (NULL, "Funny sized logical array");
114
644cb69f 115 bbase = b->data;
28dc6b33
TK
116 b_kind = GFC_DESCRIPTOR_SIZE (b);
117
118 if (b_kind == 1 || b_kind == 2 || b_kind == 4 || b_kind == 8
119#ifdef HAVE_GFC_LOGICAL_16
120 || b_kind == 16
121#endif
122 )
123 bbase = GFOR_POINTER_TO_L1 (bbase, b_kind);
124 else
125 internal_error (NULL, "Funny sized logical array");
126
644cb69f
FXC
127 dest = retarray->data;
128
644cb69f
FXC
129
130 if (GFC_DESCRIPTOR_RANK (retarray) == 1)
131 {
132 rxstride = retarray->dim[0].stride;
133 rystride = rxstride;
134 }
135 else
136 {
137 rxstride = retarray->dim[0].stride;
138 rystride = retarray->dim[1].stride;
139 }
140
141 /* If we have rank 1 parameters, zero the absent stride, and set the size to
142 one. */
143 if (GFC_DESCRIPTOR_RANK (a) == 1)
144 {
28dc6b33 145 astride = a->dim[0].stride * a_kind;
644cb69f
FXC
146 count = a->dim[0].ubound + 1 - a->dim[0].lbound;
147 xstride = 0;
148 rxstride = 0;
149 xcount = 1;
150 }
151 else
152 {
28dc6b33 153 astride = a->dim[1].stride * a_kind;
644cb69f
FXC
154 count = a->dim[1].ubound + 1 - a->dim[1].lbound;
155 xstride = a->dim[0].stride;
156 xcount = a->dim[0].ubound + 1 - a->dim[0].lbound;
157 }
158 if (GFC_DESCRIPTOR_RANK (b) == 1)
159 {
28dc6b33 160 bstride = b->dim[0].stride * b_kind;
644cb69f
FXC
161 assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
162 ystride = 0;
163 rystride = 0;
164 ycount = 1;
165 }
166 else
167 {
28dc6b33 168 bstride = b->dim[0].stride * b_kind;
644cb69f
FXC
169 assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
170 ystride = b->dim[1].stride;
171 ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
172 }
173
174 for (y = 0; y < ycount; y++)
175 {
176 for (x = 0; x < xcount; x++)
177 {
178 /* Do the summation for this element. For real and integer types
179 this is the same as DOT_PRODUCT. For complex types we use do
180 a*b, not conjg(a)*b. */
181 pa = abase;
182 pb = bbase;
183 *dest = 0;
184
185 for (n = 0; n < count; n++)
186 {
187 if (*pa && *pb)
188 {
189 *dest = 1;
190 break;
191 }
192 pa += astride;
193 pb += bstride;
194 }
195
196 dest += rxstride;
197 abase += xstride;
198 }
199 abase -= xstride * xcount;
200 bbase += ystride;
201 dest += rystride - (rxstride * xcount);
202 }
203}
204
205#endif
28dc6b33 206