aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/generated
diff options
context:
space:
mode:
Diffstat (limited to 'libgfortran/generated')
-rw-r--r--libgfortran/generated/matmul_i1.c339
-rw-r--r--libgfortran/generated/matmul_i2.c339
-rw-r--r--libgfortran/generated/maxloc0_16_i1.c326
-rw-r--r--libgfortran/generated/maxloc0_16_i2.c326
-rw-r--r--libgfortran/generated/maxloc0_4_i1.c326
-rw-r--r--libgfortran/generated/maxloc0_4_i2.c326
-rw-r--r--libgfortran/generated/maxloc0_8_i1.c326
-rw-r--r--libgfortran/generated/maxloc0_8_i2.c326
-rw-r--r--libgfortran/generated/maxloc1_16_i1.c421
-rw-r--r--libgfortran/generated/maxloc1_16_i2.c421
-rw-r--r--libgfortran/generated/maxloc1_4_i1.c421
-rw-r--r--libgfortran/generated/maxloc1_4_i2.c421
-rw-r--r--libgfortran/generated/maxloc1_8_i1.c421
-rw-r--r--libgfortran/generated/maxloc1_8_i2.c421
-rw-r--r--libgfortran/generated/maxval_i1.c410
-rw-r--r--libgfortran/generated/maxval_i2.c410
-rw-r--r--libgfortran/generated/minloc0_16_i1.c326
-rw-r--r--libgfortran/generated/minloc0_16_i2.c326
-rw-r--r--libgfortran/generated/minloc0_4_i1.c326
-rw-r--r--libgfortran/generated/minloc0_4_i2.c326
-rw-r--r--libgfortran/generated/minloc0_8_i1.c326
-rw-r--r--libgfortran/generated/minloc0_8_i2.c326
-rw-r--r--libgfortran/generated/minloc1_16_i1.c421
-rw-r--r--libgfortran/generated/minloc1_16_i2.c421
-rw-r--r--libgfortran/generated/minloc1_4_i1.c421
-rw-r--r--libgfortran/generated/minloc1_4_i2.c421
-rw-r--r--libgfortran/generated/minloc1_8_i1.c421
-rw-r--r--libgfortran/generated/minloc1_8_i2.c421
-rw-r--r--libgfortran/generated/minval_i1.c410
-rw-r--r--libgfortran/generated/minval_i2.c410
-rw-r--r--libgfortran/generated/product_i1.c408
-rw-r--r--libgfortran/generated/product_i2.c408
-rw-r--r--libgfortran/generated/sum_i1.c408
-rw-r--r--libgfortran/generated/sum_i2.c408
34 files changed, 12914 insertions, 0 deletions
diff --git a/libgfortran/generated/matmul_i1.c b/libgfortran/generated/matmul_i1.c
new file mode 100644
index 00000000000..ce98de17950
--- /dev/null
+++ b/libgfortran/generated/matmul_i1.c
@@ -0,0 +1,339 @@
+/* Implementation of the MATMUL intrinsic
+ Copyright 2002, 2005, 2006 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "libgfortran.h"
+
+#if defined (HAVE_GFC_INTEGER_1)
+
+/* Prototype for the BLAS ?gemm subroutine, a pointer to which can be
+ passed to us by the front-end, in which case we'll call it for large
+ matrices. */
+
+typedef void (*blas_call)(const char *, const char *, const int *, const int *,
+ const int *, const GFC_INTEGER_1 *, const GFC_INTEGER_1 *,
+ const int *, const GFC_INTEGER_1 *, const int *,
+ const GFC_INTEGER_1 *, GFC_INTEGER_1 *, const int *,
+ int, int);
+
+/* The order of loops is different in the case of plain matrix
+ multiplication C=MATMUL(A,B), and in the frequent special case where
+ the argument A is the temporary result of a TRANSPOSE intrinsic:
+ C=MATMUL(TRANSPOSE(A),B). Transposed temporaries are detected by
+ looking at their strides.
+
+ The equivalent Fortran pseudo-code is:
+
+ DIMENSION A(M,COUNT), B(COUNT,N), C(M,N)
+ IF (.NOT.IS_TRANSPOSED(A)) THEN
+ C = 0
+ DO J=1,N
+ DO K=1,COUNT
+ DO I=1,M
+ C(I,J) = C(I,J)+A(I,K)*B(K,J)
+ ELSE
+ DO J=1,N
+ DO I=1,M
+ S = 0
+ DO K=1,COUNT
+ S = S+A(I,K)*B(K,J)
+ C(I,J) = S
+ ENDIF
+*/
+
+/* If try_blas is set to a nonzero value, then the matmul function will
+ see if there is a way to perform the matrix multiplication by a call
+ to the BLAS gemm function. */
+
+extern void matmul_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict a, gfc_array_i1 * const restrict b, int try_blas,
+ int blas_limit, blas_call gemm);
+export_proto(matmul_i1);
+
+void
+matmul_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict a, gfc_array_i1 * const restrict b, int try_blas,
+ int blas_limit, blas_call gemm)
+{
+ const GFC_INTEGER_1 * restrict abase;
+ const GFC_INTEGER_1 * restrict bbase;
+ GFC_INTEGER_1 * restrict dest;
+
+ index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
+ index_type x, y, n, count, xcount, ycount;
+
+ assert (GFC_DESCRIPTOR_RANK (a) == 2
+ || GFC_DESCRIPTOR_RANK (b) == 2);
+
+/* C[xcount,ycount] = A[xcount, count] * B[count,ycount]
+
+ Either A or B (but not both) can be rank 1:
+
+ o One-dimensional argument A is implicitly treated as a row matrix
+ dimensioned [1,count], so xcount=1.
+
+ o One-dimensional argument B is implicitly treated as a column matrix
+ dimensioned [count, 1], so ycount=1.
+ */
+
+ if (retarray->data == NULL)
+ {
+ if (GFC_DESCRIPTOR_RANK (a) == 1)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = b->dim[1].ubound - b->dim[1].lbound;
+ retarray->dim[0].stride = 1;
+ }
+ else if (GFC_DESCRIPTOR_RANK (b) == 1)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
+ retarray->dim[0].stride = 1;
+ }
+ else
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
+ retarray->dim[0].stride = 1;
+
+ retarray->dim[1].lbound = 0;
+ retarray->dim[1].ubound = b->dim[1].ubound - b->dim[1].lbound;
+ retarray->dim[1].stride = retarray->dim[0].ubound+1;
+ }
+
+ retarray->data
+ = internal_malloc_size (sizeof (GFC_INTEGER_1) * size0 ((array_t *) retarray));
+ retarray->offset = 0;
+ }
+
+
+ if (GFC_DESCRIPTOR_RANK (retarray) == 1)
+ {
+ /* One-dimensional result may be addressed in the code below
+ either as a row or a column matrix. We want both cases to
+ work. */
+ rxstride = rystride = retarray->dim[0].stride;
+ }
+ else
+ {
+ rxstride = retarray->dim[0].stride;
+ rystride = retarray->dim[1].stride;
+ }
+
+
+ if (GFC_DESCRIPTOR_RANK (a) == 1)
+ {
+ /* Treat it as a a row matrix A[1,count]. */
+ axstride = a->dim[0].stride;
+ aystride = 1;
+
+ xcount = 1;
+ count = a->dim[0].ubound + 1 - a->dim[0].lbound;
+ }
+ else
+ {
+ axstride = a->dim[0].stride;
+ aystride = a->dim[1].stride;
+
+ count = a->dim[1].ubound + 1 - a->dim[1].lbound;
+ xcount = a->dim[0].ubound + 1 - a->dim[0].lbound;
+ }
+
+ assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
+
+ if (GFC_DESCRIPTOR_RANK (b) == 1)
+ {
+ /* Treat it as a column matrix B[count,1] */
+ bxstride = b->dim[0].stride;
+
+ /* bystride should never be used for 1-dimensional b.
+ in case it is we want it to cause a segfault, rather than
+ an incorrect result. */
+ bystride = 0xDEADBEEF;
+ ycount = 1;
+ }
+ else
+ {
+ bxstride = b->dim[0].stride;
+ bystride = b->dim[1].stride;
+ ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
+ }
+
+ abase = a->data;
+ bbase = b->data;
+ dest = retarray->data;
+
+
+ /* Now that everything is set up, we're performing the multiplication
+ itself. */
+
+#define POW3(x) (((float) (x)) * ((float) (x)) * ((float) (x)))
+
+ if (try_blas && rxstride == 1 && (axstride == 1 || aystride == 1)
+ && (bxstride == 1 || bystride == 1)
+ && (((float) xcount) * ((float) ycount) * ((float) count)
+ > POW3(blas_limit)))
+ {
+ const int m = xcount, n = ycount, k = count, ldc = rystride;
+ const GFC_INTEGER_1 one = 1, zero = 0;
+ const int lda = (axstride == 1) ? aystride : axstride,
+ ldb = (bxstride == 1) ? bystride : bxstride;
+
+ if (lda > 0 && ldb > 0 && ldc > 0 && m > 1 && n > 1 && k > 1)
+ {
+ assert (gemm != NULL);
+ gemm (axstride == 1 ? "N" : "T", bxstride == 1 ? "N" : "T", &m, &n, &k,
+ &one, abase, &lda, bbase, &ldb, &zero, dest, &ldc, 1, 1);
+ return;
+ }
+ }
+
+ if (rxstride == 1 && axstride == 1 && bxstride == 1)
+ {
+ const GFC_INTEGER_1 * restrict bbase_y;
+ GFC_INTEGER_1 * restrict dest_y;
+ const GFC_INTEGER_1 * restrict abase_n;
+ GFC_INTEGER_1 bbase_yn;
+
+ if (rystride == xcount)
+ memset (dest, 0, (sizeof (GFC_INTEGER_1) * xcount * ycount));
+ else
+ {
+ for (y = 0; y < ycount; y++)
+ for (x = 0; x < xcount; x++)
+ dest[x + y*rystride] = (GFC_INTEGER_1)0;
+ }
+
+ for (y = 0; y < ycount; y++)
+ {
+ bbase_y = bbase + y*bystride;
+ dest_y = dest + y*rystride;
+ for (n = 0; n < count; n++)
+ {
+ abase_n = abase + n*aystride;
+ bbase_yn = bbase_y[n];
+ for (x = 0; x < xcount; x++)
+ {
+ dest_y[x] += abase_n[x] * bbase_yn;
+ }
+ }
+ }
+ }
+ else if (rxstride == 1 && aystride == 1 && bxstride == 1)
+ {
+ if (GFC_DESCRIPTOR_RANK (a) != 1)
+ {
+ const GFC_INTEGER_1 *restrict abase_x;
+ const GFC_INTEGER_1 *restrict bbase_y;
+ GFC_INTEGER_1 *restrict dest_y;
+ GFC_INTEGER_1 s;
+
+ for (y = 0; y < ycount; y++)
+ {
+ bbase_y = &bbase[y*bystride];
+ dest_y = &dest[y*rystride];
+ for (x = 0; x < xcount; x++)
+ {
+ abase_x = &abase[x*axstride];
+ s = (GFC_INTEGER_1) 0;
+ for (n = 0; n < count; n++)
+ s += abase_x[n] * bbase_y[n];
+ dest_y[x] = s;
+ }
+ }
+ }
+ else
+ {
+ const GFC_INTEGER_1 *restrict bbase_y;
+ GFC_INTEGER_1 s;
+
+ for (y = 0; y < ycount; y++)
+ {
+ bbase_y = &bbase[y*bystride];
+ s = (GFC_INTEGER_1) 0;
+ for (n = 0; n < count; n++)
+ s += abase[n*axstride] * bbase_y[n];
+ dest[y*rystride] = s;
+ }
+ }
+ }
+ else if (axstride < aystride)
+ {
+ for (y = 0; y < ycount; y++)
+ for (x = 0; x < xcount; x++)
+ dest[x*rxstride + y*rystride] = (GFC_INTEGER_1)0;
+
+ for (y = 0; y < ycount; y++)
+ for (n = 0; n < count; n++)
+ for (x = 0; x < xcount; x++)
+ /* dest[x,y] += a[x,n] * b[n,y] */
+ dest[x*rxstride + y*rystride] += abase[x*axstride + n*aystride] * bbase[n*bxstride + y*bystride];
+ }
+ else if (GFC_DESCRIPTOR_RANK (a) == 1)
+ {
+ const GFC_INTEGER_1 *restrict bbase_y;
+ GFC_INTEGER_1 s;
+
+ for (y = 0; y < ycount; y++)
+ {
+ bbase_y = &bbase[y*bystride];
+ s = (GFC_INTEGER_1) 0;
+ for (n = 0; n < count; n++)
+ s += abase[n*axstride] * bbase_y[n*bxstride];
+ dest[y*rxstride] = s;
+ }
+ }
+ else
+ {
+ const GFC_INTEGER_1 *restrict abase_x;
+ const GFC_INTEGER_1 *restrict bbase_y;
+ GFC_INTEGER_1 *restrict dest_y;
+ GFC_INTEGER_1 s;
+
+ for (y = 0; y < ycount; y++)
+ {
+ bbase_y = &bbase[y*bystride];
+ dest_y = &dest[y*rystride];
+ for (x = 0; x < xcount; x++)
+ {
+ abase_x = &abase[x*axstride];
+ s = (GFC_INTEGER_1) 0;
+ for (n = 0; n < count; n++)
+ s += abase_x[n*aystride] * bbase_y[n*bxstride];
+ dest_y[x*rxstride] = s;
+ }
+ }
+ }
+}
+
+#endif
diff --git a/libgfortran/generated/matmul_i2.c b/libgfortran/generated/matmul_i2.c
new file mode 100644
index 00000000000..b86839e379b
--- /dev/null
+++ b/libgfortran/generated/matmul_i2.c
@@ -0,0 +1,339 @@
+/* Implementation of the MATMUL intrinsic
+ Copyright 2002, 2005, 2006 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "libgfortran.h"
+
+#if defined (HAVE_GFC_INTEGER_2)
+
+/* Prototype for the BLAS ?gemm subroutine, a pointer to which can be
+ passed to us by the front-end, in which case we'll call it for large
+ matrices. */
+
+typedef void (*blas_call)(const char *, const char *, const int *, const int *,
+ const int *, const GFC_INTEGER_2 *, const GFC_INTEGER_2 *,
+ const int *, const GFC_INTEGER_2 *, const int *,
+ const GFC_INTEGER_2 *, GFC_INTEGER_2 *, const int *,
+ int, int);
+
+/* The order of loops is different in the case of plain matrix
+ multiplication C=MATMUL(A,B), and in the frequent special case where
+ the argument A is the temporary result of a TRANSPOSE intrinsic:
+ C=MATMUL(TRANSPOSE(A),B). Transposed temporaries are detected by
+ looking at their strides.
+
+ The equivalent Fortran pseudo-code is:
+
+ DIMENSION A(M,COUNT), B(COUNT,N), C(M,N)
+ IF (.NOT.IS_TRANSPOSED(A)) THEN
+ C = 0
+ DO J=1,N
+ DO K=1,COUNT
+ DO I=1,M
+ C(I,J) = C(I,J)+A(I,K)*B(K,J)
+ ELSE
+ DO J=1,N
+ DO I=1,M
+ S = 0
+ DO K=1,COUNT
+ S = S+A(I,K)*B(K,J)
+ C(I,J) = S
+ ENDIF
+*/
+
+/* If try_blas is set to a nonzero value, then the matmul function will
+ see if there is a way to perform the matrix multiplication by a call
+ to the BLAS gemm function. */
+
+extern void matmul_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict a, gfc_array_i2 * const restrict b, int try_blas,
+ int blas_limit, blas_call gemm);
+export_proto(matmul_i2);
+
+void
+matmul_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict a, gfc_array_i2 * const restrict b, int try_blas,
+ int blas_limit, blas_call gemm)
+{
+ const GFC_INTEGER_2 * restrict abase;
+ const GFC_INTEGER_2 * restrict bbase;
+ GFC_INTEGER_2 * restrict dest;
+
+ index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
+ index_type x, y, n, count, xcount, ycount;
+
+ assert (GFC_DESCRIPTOR_RANK (a) == 2
+ || GFC_DESCRIPTOR_RANK (b) == 2);
+
+/* C[xcount,ycount] = A[xcount, count] * B[count,ycount]
+
+ Either A or B (but not both) can be rank 1:
+
+ o One-dimensional argument A is implicitly treated as a row matrix
+ dimensioned [1,count], so xcount=1.
+
+ o One-dimensional argument B is implicitly treated as a column matrix
+ dimensioned [count, 1], so ycount=1.
+ */
+
+ if (retarray->data == NULL)
+ {
+ if (GFC_DESCRIPTOR_RANK (a) == 1)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = b->dim[1].ubound - b->dim[1].lbound;
+ retarray->dim[0].stride = 1;
+ }
+ else if (GFC_DESCRIPTOR_RANK (b) == 1)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
+ retarray->dim[0].stride = 1;
+ }
+ else
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
+ retarray->dim[0].stride = 1;
+
+ retarray->dim[1].lbound = 0;
+ retarray->dim[1].ubound = b->dim[1].ubound - b->dim[1].lbound;
+ retarray->dim[1].stride = retarray->dim[0].ubound+1;
+ }
+
+ retarray->data
+ = internal_malloc_size (sizeof (GFC_INTEGER_2) * size0 ((array_t *) retarray));
+ retarray->offset = 0;
+ }
+
+
+ if (GFC_DESCRIPTOR_RANK (retarray) == 1)
+ {
+ /* One-dimensional result may be addressed in the code below
+ either as a row or a column matrix. We want both cases to
+ work. */
+ rxstride = rystride = retarray->dim[0].stride;
+ }
+ else
+ {
+ rxstride = retarray->dim[0].stride;
+ rystride = retarray->dim[1].stride;
+ }
+
+
+ if (GFC_DESCRIPTOR_RANK (a) == 1)
+ {
+ /* Treat it as a a row matrix A[1,count]. */
+ axstride = a->dim[0].stride;
+ aystride = 1;
+
+ xcount = 1;
+ count = a->dim[0].ubound + 1 - a->dim[0].lbound;
+ }
+ else
+ {
+ axstride = a->dim[0].stride;
+ aystride = a->dim[1].stride;
+
+ count = a->dim[1].ubound + 1 - a->dim[1].lbound;
+ xcount = a->dim[0].ubound + 1 - a->dim[0].lbound;
+ }
+
+ assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
+
+ if (GFC_DESCRIPTOR_RANK (b) == 1)
+ {
+ /* Treat it as a column matrix B[count,1] */
+ bxstride = b->dim[0].stride;
+
+ /* bystride should never be used for 1-dimensional b.
+ in case it is we want it to cause a segfault, rather than
+ an incorrect result. */
+ bystride = 0xDEADBEEF;
+ ycount = 1;
+ }
+ else
+ {
+ bxstride = b->dim[0].stride;
+ bystride = b->dim[1].stride;
+ ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
+ }
+
+ abase = a->data;
+ bbase = b->data;
+ dest = retarray->data;
+
+
+ /* Now that everything is set up, we're performing the multiplication
+ itself. */
+
+#define POW3(x) (((float) (x)) * ((float) (x)) * ((float) (x)))
+
+ if (try_blas && rxstride == 1 && (axstride == 1 || aystride == 1)
+ && (bxstride == 1 || bystride == 1)
+ && (((float) xcount) * ((float) ycount) * ((float) count)
+ > POW3(blas_limit)))
+ {
+ const int m = xcount, n = ycount, k = count, ldc = rystride;
+ const GFC_INTEGER_2 one = 1, zero = 0;
+ const int lda = (axstride == 1) ? aystride : axstride,
+ ldb = (bxstride == 1) ? bystride : bxstride;
+
+ if (lda > 0 && ldb > 0 && ldc > 0 && m > 1 && n > 1 && k > 1)
+ {
+ assert (gemm != NULL);
+ gemm (axstride == 1 ? "N" : "T", bxstride == 1 ? "N" : "T", &m, &n, &k,
+ &one, abase, &lda, bbase, &ldb, &zero, dest, &ldc, 1, 1);
+ return;
+ }
+ }
+
+ if (rxstride == 1 && axstride == 1 && bxstride == 1)
+ {
+ const GFC_INTEGER_2 * restrict bbase_y;
+ GFC_INTEGER_2 * restrict dest_y;
+ const GFC_INTEGER_2 * restrict abase_n;
+ GFC_INTEGER_2 bbase_yn;
+
+ if (rystride == xcount)
+ memset (dest, 0, (sizeof (GFC_INTEGER_2) * xcount * ycount));
+ else
+ {
+ for (y = 0; y < ycount; y++)
+ for (x = 0; x < xcount; x++)
+ dest[x + y*rystride] = (GFC_INTEGER_2)0;
+ }
+
+ for (y = 0; y < ycount; y++)
+ {
+ bbase_y = bbase + y*bystride;
+ dest_y = dest + y*rystride;
+ for (n = 0; n < count; n++)
+ {
+ abase_n = abase + n*aystride;
+ bbase_yn = bbase_y[n];
+ for (x = 0; x < xcount; x++)
+ {
+ dest_y[x] += abase_n[x] * bbase_yn;
+ }
+ }
+ }
+ }
+ else if (rxstride == 1 && aystride == 1 && bxstride == 1)
+ {
+ if (GFC_DESCRIPTOR_RANK (a) != 1)
+ {
+ const GFC_INTEGER_2 *restrict abase_x;
+ const GFC_INTEGER_2 *restrict bbase_y;
+ GFC_INTEGER_2 *restrict dest_y;
+ GFC_INTEGER_2 s;
+
+ for (y = 0; y < ycount; y++)
+ {
+ bbase_y = &bbase[y*bystride];
+ dest_y = &dest[y*rystride];
+ for (x = 0; x < xcount; x++)
+ {
+ abase_x = &abase[x*axstride];
+ s = (GFC_INTEGER_2) 0;
+ for (n = 0; n < count; n++)
+ s += abase_x[n] * bbase_y[n];
+ dest_y[x] = s;
+ }
+ }
+ }
+ else
+ {
+ const GFC_INTEGER_2 *restrict bbase_y;
+ GFC_INTEGER_2 s;
+
+ for (y = 0; y < ycount; y++)
+ {
+ bbase_y = &bbase[y*bystride];
+ s = (GFC_INTEGER_2) 0;
+ for (n = 0; n < count; n++)
+ s += abase[n*axstride] * bbase_y[n];
+ dest[y*rystride] = s;
+ }
+ }
+ }
+ else if (axstride < aystride)
+ {
+ for (y = 0; y < ycount; y++)
+ for (x = 0; x < xcount; x++)
+ dest[x*rxstride + y*rystride] = (GFC_INTEGER_2)0;
+
+ for (y = 0; y < ycount; y++)
+ for (n = 0; n < count; n++)
+ for (x = 0; x < xcount; x++)
+ /* dest[x,y] += a[x,n] * b[n,y] */
+ dest[x*rxstride + y*rystride] += abase[x*axstride + n*aystride] * bbase[n*bxstride + y*bystride];
+ }
+ else if (GFC_DESCRIPTOR_RANK (a) == 1)
+ {
+ const GFC_INTEGER_2 *restrict bbase_y;
+ GFC_INTEGER_2 s;
+
+ for (y = 0; y < ycount; y++)
+ {
+ bbase_y = &bbase[y*bystride];
+ s = (GFC_INTEGER_2) 0;
+ for (n = 0; n < count; n++)
+ s += abase[n*axstride] * bbase_y[n*bxstride];
+ dest[y*rxstride] = s;
+ }
+ }
+ else
+ {
+ const GFC_INTEGER_2 *restrict abase_x;
+ const GFC_INTEGER_2 *restrict bbase_y;
+ GFC_INTEGER_2 *restrict dest_y;
+ GFC_INTEGER_2 s;
+
+ for (y = 0; y < ycount; y++)
+ {
+ bbase_y = &bbase[y*bystride];
+ dest_y = &dest[y*rystride];
+ for (x = 0; x < xcount; x++)
+ {
+ abase_x = &abase[x*axstride];
+ s = (GFC_INTEGER_2) 0;
+ for (n = 0; n < count; n++)
+ s += abase_x[n*aystride] * bbase_y[n*bxstride];
+ dest_y[x*rxstride] = s;
+ }
+ }
+ }
+}
+
+#endif
diff --git a/libgfortran/generated/maxloc0_16_i1.c b/libgfortran/generated/maxloc0_16_i1.c
new file mode 100644
index 00000000000..29c5f84b2a2
--- /dev/null
+++ b/libgfortran/generated/maxloc0_16_i1.c
@@ -0,0 +1,326 @@
+/* Implementation of the MAXLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_16)
+
+
+extern void maxloc0_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array);
+export_proto(maxloc0_16_i1);
+
+void
+maxloc0_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ const GFC_INTEGER_1 *base;
+ GFC_INTEGER_16 *dest;
+ index_type rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_1 maxval;
+
+ maxval = (-GFC_INTEGER_1_HUGE-1);
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*base > maxval || !dest[0])
+ {
+ maxval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void mmaxloc0_16_i1 (gfc_array_i16 * const restrict,
+ gfc_array_i1 * const restrict, gfc_array_l4 * const restrict);
+export_proto(mmaxloc0_16_i1);
+
+void
+mmaxloc0_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ GFC_INTEGER_16 *dest;
+ const GFC_INTEGER_1 *base;
+ GFC_LOGICAL_4 *mbase;
+ int rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_1 maxval;
+
+ maxval = (-GFC_INTEGER_1_HUGE-1);
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*mbase && (*base > maxval || !dest[0]))
+ {
+ maxval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void smaxloc0_16_i1 (gfc_array_i16 * const restrict,
+ gfc_array_i1 * const restrict, GFC_LOGICAL_4 *);
+export_proto(smaxloc0_16_i1);
+
+void
+smaxloc0_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type dstride;
+ index_type n;
+ GFC_INTEGER_16 *dest;
+
+ if (*mask)
+ {
+ maxloc0_16_i1 (retarray, array);
+ return;
+ }
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n<rank; n++)
+ dest[n * dstride] = 0 ;
+}
+#endif
diff --git a/libgfortran/generated/maxloc0_16_i2.c b/libgfortran/generated/maxloc0_16_i2.c
new file mode 100644
index 00000000000..8cec214da8d
--- /dev/null
+++ b/libgfortran/generated/maxloc0_16_i2.c
@@ -0,0 +1,326 @@
+/* Implementation of the MAXLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_16)
+
+
+extern void maxloc0_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array);
+export_proto(maxloc0_16_i2);
+
+void
+maxloc0_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ const GFC_INTEGER_2 *base;
+ GFC_INTEGER_16 *dest;
+ index_type rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_2 maxval;
+
+ maxval = (-GFC_INTEGER_2_HUGE-1);
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*base > maxval || !dest[0])
+ {
+ maxval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void mmaxloc0_16_i2 (gfc_array_i16 * const restrict,
+ gfc_array_i2 * const restrict, gfc_array_l4 * const restrict);
+export_proto(mmaxloc0_16_i2);
+
+void
+mmaxloc0_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ GFC_INTEGER_16 *dest;
+ const GFC_INTEGER_2 *base;
+ GFC_LOGICAL_4 *mbase;
+ int rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_2 maxval;
+
+ maxval = (-GFC_INTEGER_2_HUGE-1);
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*mbase && (*base > maxval || !dest[0]))
+ {
+ maxval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void smaxloc0_16_i2 (gfc_array_i16 * const restrict,
+ gfc_array_i2 * const restrict, GFC_LOGICAL_4 *);
+export_proto(smaxloc0_16_i2);
+
+void
+smaxloc0_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type dstride;
+ index_type n;
+ GFC_INTEGER_16 *dest;
+
+ if (*mask)
+ {
+ maxloc0_16_i2 (retarray, array);
+ return;
+ }
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n<rank; n++)
+ dest[n * dstride] = 0 ;
+}
+#endif
diff --git a/libgfortran/generated/maxloc0_4_i1.c b/libgfortran/generated/maxloc0_4_i1.c
new file mode 100644
index 00000000000..33d576ccfcb
--- /dev/null
+++ b/libgfortran/generated/maxloc0_4_i1.c
@@ -0,0 +1,326 @@
+/* Implementation of the MAXLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_4)
+
+
+extern void maxloc0_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array);
+export_proto(maxloc0_4_i1);
+
+void
+maxloc0_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ const GFC_INTEGER_1 *base;
+ GFC_INTEGER_4 *dest;
+ index_type rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_1 maxval;
+
+ maxval = (-GFC_INTEGER_1_HUGE-1);
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*base > maxval || !dest[0])
+ {
+ maxval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void mmaxloc0_4_i1 (gfc_array_i4 * const restrict,
+ gfc_array_i1 * const restrict, gfc_array_l4 * const restrict);
+export_proto(mmaxloc0_4_i1);
+
+void
+mmaxloc0_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ GFC_INTEGER_4 *dest;
+ const GFC_INTEGER_1 *base;
+ GFC_LOGICAL_4 *mbase;
+ int rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_1 maxval;
+
+ maxval = (-GFC_INTEGER_1_HUGE-1);
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*mbase && (*base > maxval || !dest[0]))
+ {
+ maxval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void smaxloc0_4_i1 (gfc_array_i4 * const restrict,
+ gfc_array_i1 * const restrict, GFC_LOGICAL_4 *);
+export_proto(smaxloc0_4_i1);
+
+void
+smaxloc0_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type dstride;
+ index_type n;
+ GFC_INTEGER_4 *dest;
+
+ if (*mask)
+ {
+ maxloc0_4_i1 (retarray, array);
+ return;
+ }
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n<rank; n++)
+ dest[n * dstride] = 0 ;
+}
+#endif
diff --git a/libgfortran/generated/maxloc0_4_i2.c b/libgfortran/generated/maxloc0_4_i2.c
new file mode 100644
index 00000000000..548f769cfd8
--- /dev/null
+++ b/libgfortran/generated/maxloc0_4_i2.c
@@ -0,0 +1,326 @@
+/* Implementation of the MAXLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_4)
+
+
+extern void maxloc0_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array);
+export_proto(maxloc0_4_i2);
+
+void
+maxloc0_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ const GFC_INTEGER_2 *base;
+ GFC_INTEGER_4 *dest;
+ index_type rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_2 maxval;
+
+ maxval = (-GFC_INTEGER_2_HUGE-1);
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*base > maxval || !dest[0])
+ {
+ maxval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void mmaxloc0_4_i2 (gfc_array_i4 * const restrict,
+ gfc_array_i2 * const restrict, gfc_array_l4 * const restrict);
+export_proto(mmaxloc0_4_i2);
+
+void
+mmaxloc0_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ GFC_INTEGER_4 *dest;
+ const GFC_INTEGER_2 *base;
+ GFC_LOGICAL_4 *mbase;
+ int rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_2 maxval;
+
+ maxval = (-GFC_INTEGER_2_HUGE-1);
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*mbase && (*base > maxval || !dest[0]))
+ {
+ maxval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void smaxloc0_4_i2 (gfc_array_i4 * const restrict,
+ gfc_array_i2 * const restrict, GFC_LOGICAL_4 *);
+export_proto(smaxloc0_4_i2);
+
+void
+smaxloc0_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type dstride;
+ index_type n;
+ GFC_INTEGER_4 *dest;
+
+ if (*mask)
+ {
+ maxloc0_4_i2 (retarray, array);
+ return;
+ }
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n<rank; n++)
+ dest[n * dstride] = 0 ;
+}
+#endif
diff --git a/libgfortran/generated/maxloc0_8_i1.c b/libgfortran/generated/maxloc0_8_i1.c
new file mode 100644
index 00000000000..76ce6c6cb81
--- /dev/null
+++ b/libgfortran/generated/maxloc0_8_i1.c
@@ -0,0 +1,326 @@
+/* Implementation of the MAXLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_8)
+
+
+extern void maxloc0_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array);
+export_proto(maxloc0_8_i1);
+
+void
+maxloc0_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ const GFC_INTEGER_1 *base;
+ GFC_INTEGER_8 *dest;
+ index_type rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_1 maxval;
+
+ maxval = (-GFC_INTEGER_1_HUGE-1);
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*base > maxval || !dest[0])
+ {
+ maxval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void mmaxloc0_8_i1 (gfc_array_i8 * const restrict,
+ gfc_array_i1 * const restrict, gfc_array_l4 * const restrict);
+export_proto(mmaxloc0_8_i1);
+
+void
+mmaxloc0_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ GFC_INTEGER_8 *dest;
+ const GFC_INTEGER_1 *base;
+ GFC_LOGICAL_4 *mbase;
+ int rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_1 maxval;
+
+ maxval = (-GFC_INTEGER_1_HUGE-1);
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*mbase && (*base > maxval || !dest[0]))
+ {
+ maxval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void smaxloc0_8_i1 (gfc_array_i8 * const restrict,
+ gfc_array_i1 * const restrict, GFC_LOGICAL_4 *);
+export_proto(smaxloc0_8_i1);
+
+void
+smaxloc0_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type dstride;
+ index_type n;
+ GFC_INTEGER_8 *dest;
+
+ if (*mask)
+ {
+ maxloc0_8_i1 (retarray, array);
+ return;
+ }
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n<rank; n++)
+ dest[n * dstride] = 0 ;
+}
+#endif
diff --git a/libgfortran/generated/maxloc0_8_i2.c b/libgfortran/generated/maxloc0_8_i2.c
new file mode 100644
index 00000000000..d6eaf04dd01
--- /dev/null
+++ b/libgfortran/generated/maxloc0_8_i2.c
@@ -0,0 +1,326 @@
+/* Implementation of the MAXLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_8)
+
+
+extern void maxloc0_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array);
+export_proto(maxloc0_8_i2);
+
+void
+maxloc0_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ const GFC_INTEGER_2 *base;
+ GFC_INTEGER_8 *dest;
+ index_type rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_2 maxval;
+
+ maxval = (-GFC_INTEGER_2_HUGE-1);
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*base > maxval || !dest[0])
+ {
+ maxval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void mmaxloc0_8_i2 (gfc_array_i8 * const restrict,
+ gfc_array_i2 * const restrict, gfc_array_l4 * const restrict);
+export_proto(mmaxloc0_8_i2);
+
+void
+mmaxloc0_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ GFC_INTEGER_8 *dest;
+ const GFC_INTEGER_2 *base;
+ GFC_LOGICAL_4 *mbase;
+ int rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_2 maxval;
+
+ maxval = (-GFC_INTEGER_2_HUGE-1);
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*mbase && (*base > maxval || !dest[0]))
+ {
+ maxval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void smaxloc0_8_i2 (gfc_array_i8 * const restrict,
+ gfc_array_i2 * const restrict, GFC_LOGICAL_4 *);
+export_proto(smaxloc0_8_i2);
+
+void
+smaxloc0_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type dstride;
+ index_type n;
+ GFC_INTEGER_8 *dest;
+
+ if (*mask)
+ {
+ maxloc0_8_i2 (retarray, array);
+ return;
+ }
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n<rank; n++)
+ dest[n * dstride] = 0 ;
+}
+#endif
diff --git a/libgfortran/generated/maxloc1_16_i1.c b/libgfortran/generated/maxloc1_16_i1.c
new file mode 100644
index 00000000000..faa8d8539db
--- /dev/null
+++ b/libgfortran/generated/maxloc1_16_i1.c
@@ -0,0 +1,421 @@
+/* Implementation of the MAXLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_16)
+
+
+extern void maxloc1_16_i1 (gfc_array_i16 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict);
+export_proto(maxloc1_16_i1);
+
+void
+maxloc1_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_1 * restrict base;
+ GFC_INTEGER_16 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ GFC_INTEGER_16 result;
+ src = base;
+ {
+
+ GFC_INTEGER_1 maxval;
+ maxval = (-GFC_INTEGER_1_HUGE-1);
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src > maxval || !result)
+ {
+ maxval = *src;
+ result = (GFC_INTEGER_16)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mmaxloc1_16_i1 (gfc_array_i16 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mmaxloc1_16_i1);
+
+void
+mmaxloc1_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_16 * restrict dest;
+ const GFC_INTEGER_1 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_16 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ GFC_INTEGER_1 maxval;
+ maxval = (-GFC_INTEGER_1_HUGE-1);
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && (*src > maxval || !result))
+ {
+ maxval = *src;
+ result = (GFC_INTEGER_16)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void smaxloc1_16_i1 (gfc_array_i16 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(smaxloc1_16_i1);
+
+void
+smaxloc1_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_16 *dest;
+
+ if (*mask)
+ {
+ maxloc1_16_i1 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/maxloc1_16_i2.c b/libgfortran/generated/maxloc1_16_i2.c
new file mode 100644
index 00000000000..2bbaef5f70d
--- /dev/null
+++ b/libgfortran/generated/maxloc1_16_i2.c
@@ -0,0 +1,421 @@
+/* Implementation of the MAXLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_16)
+
+
+extern void maxloc1_16_i2 (gfc_array_i16 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict);
+export_proto(maxloc1_16_i2);
+
+void
+maxloc1_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_2 * restrict base;
+ GFC_INTEGER_16 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ GFC_INTEGER_16 result;
+ src = base;
+ {
+
+ GFC_INTEGER_2 maxval;
+ maxval = (-GFC_INTEGER_2_HUGE-1);
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src > maxval || !result)
+ {
+ maxval = *src;
+ result = (GFC_INTEGER_16)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mmaxloc1_16_i2 (gfc_array_i16 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mmaxloc1_16_i2);
+
+void
+mmaxloc1_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_16 * restrict dest;
+ const GFC_INTEGER_2 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_16 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ GFC_INTEGER_2 maxval;
+ maxval = (-GFC_INTEGER_2_HUGE-1);
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && (*src > maxval || !result))
+ {
+ maxval = *src;
+ result = (GFC_INTEGER_16)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void smaxloc1_16_i2 (gfc_array_i16 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(smaxloc1_16_i2);
+
+void
+smaxloc1_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_16 *dest;
+
+ if (*mask)
+ {
+ maxloc1_16_i2 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/maxloc1_4_i1.c b/libgfortran/generated/maxloc1_4_i1.c
new file mode 100644
index 00000000000..f441d7b0df8
--- /dev/null
+++ b/libgfortran/generated/maxloc1_4_i1.c
@@ -0,0 +1,421 @@
+/* Implementation of the MAXLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_4)
+
+
+extern void maxloc1_4_i1 (gfc_array_i4 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict);
+export_proto(maxloc1_4_i1);
+
+void
+maxloc1_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_1 * restrict base;
+ GFC_INTEGER_4 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ GFC_INTEGER_4 result;
+ src = base;
+ {
+
+ GFC_INTEGER_1 maxval;
+ maxval = (-GFC_INTEGER_1_HUGE-1);
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src > maxval || !result)
+ {
+ maxval = *src;
+ result = (GFC_INTEGER_4)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mmaxloc1_4_i1 (gfc_array_i4 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mmaxloc1_4_i1);
+
+void
+mmaxloc1_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_4 * restrict dest;
+ const GFC_INTEGER_1 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_4 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ GFC_INTEGER_1 maxval;
+ maxval = (-GFC_INTEGER_1_HUGE-1);
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && (*src > maxval || !result))
+ {
+ maxval = *src;
+ result = (GFC_INTEGER_4)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void smaxloc1_4_i1 (gfc_array_i4 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(smaxloc1_4_i1);
+
+void
+smaxloc1_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_4 *dest;
+
+ if (*mask)
+ {
+ maxloc1_4_i1 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/maxloc1_4_i2.c b/libgfortran/generated/maxloc1_4_i2.c
new file mode 100644
index 00000000000..40b66bb655a
--- /dev/null
+++ b/libgfortran/generated/maxloc1_4_i2.c
@@ -0,0 +1,421 @@
+/* Implementation of the MAXLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_4)
+
+
+extern void maxloc1_4_i2 (gfc_array_i4 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict);
+export_proto(maxloc1_4_i2);
+
+void
+maxloc1_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_2 * restrict base;
+ GFC_INTEGER_4 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ GFC_INTEGER_4 result;
+ src = base;
+ {
+
+ GFC_INTEGER_2 maxval;
+ maxval = (-GFC_INTEGER_2_HUGE-1);
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src > maxval || !result)
+ {
+ maxval = *src;
+ result = (GFC_INTEGER_4)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mmaxloc1_4_i2 (gfc_array_i4 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mmaxloc1_4_i2);
+
+void
+mmaxloc1_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_4 * restrict dest;
+ const GFC_INTEGER_2 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_4 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ GFC_INTEGER_2 maxval;
+ maxval = (-GFC_INTEGER_2_HUGE-1);
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && (*src > maxval || !result))
+ {
+ maxval = *src;
+ result = (GFC_INTEGER_4)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void smaxloc1_4_i2 (gfc_array_i4 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(smaxloc1_4_i2);
+
+void
+smaxloc1_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_4 *dest;
+
+ if (*mask)
+ {
+ maxloc1_4_i2 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/maxloc1_8_i1.c b/libgfortran/generated/maxloc1_8_i1.c
new file mode 100644
index 00000000000..f103083c34a
--- /dev/null
+++ b/libgfortran/generated/maxloc1_8_i1.c
@@ -0,0 +1,421 @@
+/* Implementation of the MAXLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_8)
+
+
+extern void maxloc1_8_i1 (gfc_array_i8 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict);
+export_proto(maxloc1_8_i1);
+
+void
+maxloc1_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_1 * restrict base;
+ GFC_INTEGER_8 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ GFC_INTEGER_8 result;
+ src = base;
+ {
+
+ GFC_INTEGER_1 maxval;
+ maxval = (-GFC_INTEGER_1_HUGE-1);
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src > maxval || !result)
+ {
+ maxval = *src;
+ result = (GFC_INTEGER_8)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mmaxloc1_8_i1 (gfc_array_i8 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mmaxloc1_8_i1);
+
+void
+mmaxloc1_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_8 * restrict dest;
+ const GFC_INTEGER_1 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_8 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ GFC_INTEGER_1 maxval;
+ maxval = (-GFC_INTEGER_1_HUGE-1);
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && (*src > maxval || !result))
+ {
+ maxval = *src;
+ result = (GFC_INTEGER_8)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void smaxloc1_8_i1 (gfc_array_i8 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(smaxloc1_8_i1);
+
+void
+smaxloc1_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_8 *dest;
+
+ if (*mask)
+ {
+ maxloc1_8_i1 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/maxloc1_8_i2.c b/libgfortran/generated/maxloc1_8_i2.c
new file mode 100644
index 00000000000..9c0c6350cfd
--- /dev/null
+++ b/libgfortran/generated/maxloc1_8_i2.c
@@ -0,0 +1,421 @@
+/* Implementation of the MAXLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_8)
+
+
+extern void maxloc1_8_i2 (gfc_array_i8 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict);
+export_proto(maxloc1_8_i2);
+
+void
+maxloc1_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_2 * restrict base;
+ GFC_INTEGER_8 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ GFC_INTEGER_8 result;
+ src = base;
+ {
+
+ GFC_INTEGER_2 maxval;
+ maxval = (-GFC_INTEGER_2_HUGE-1);
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src > maxval || !result)
+ {
+ maxval = *src;
+ result = (GFC_INTEGER_8)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mmaxloc1_8_i2 (gfc_array_i8 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mmaxloc1_8_i2);
+
+void
+mmaxloc1_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_8 * restrict dest;
+ const GFC_INTEGER_2 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_8 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ GFC_INTEGER_2 maxval;
+ maxval = (-GFC_INTEGER_2_HUGE-1);
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && (*src > maxval || !result))
+ {
+ maxval = *src;
+ result = (GFC_INTEGER_8)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void smaxloc1_8_i2 (gfc_array_i8 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(smaxloc1_8_i2);
+
+void
+smaxloc1_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_8 *dest;
+
+ if (*mask)
+ {
+ maxloc1_8_i2 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/maxval_i1.c b/libgfortran/generated/maxval_i1.c
new file mode 100644
index 00000000000..042e8ad9220
--- /dev/null
+++ b/libgfortran/generated/maxval_i1.c
@@ -0,0 +1,410 @@
+/* Implementation of the MAXVAL intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_1)
+
+
+extern void maxval_i1 (gfc_array_i1 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict);
+export_proto(maxval_i1);
+
+void
+maxval_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_1 * restrict base;
+ GFC_INTEGER_1 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ GFC_INTEGER_1 result;
+ src = base;
+ {
+
+ result = (-GFC_INTEGER_1_HUGE-1);
+ if (len <= 0)
+ *dest = (-GFC_INTEGER_1_HUGE-1);
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src > result)
+ result = *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mmaxval_i1 (gfc_array_i1 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mmaxval_i1);
+
+void
+mmaxval_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_1 * restrict dest;
+ const GFC_INTEGER_1 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_1 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ result = (-GFC_INTEGER_1_HUGE-1);
+ if (len <= 0)
+ *dest = (-GFC_INTEGER_1_HUGE-1);
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && *src > result)
+ result = *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void smaxval_i1 (gfc_array_i1 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(smaxval_i1);
+
+void
+smaxval_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_1 *dest;
+
+ if (*mask)
+ {
+ maxval_i1 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_1) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = (-GFC_INTEGER_1_HUGE-1) ;
+}
+
+#endif
diff --git a/libgfortran/generated/maxval_i2.c b/libgfortran/generated/maxval_i2.c
new file mode 100644
index 00000000000..53a090684c3
--- /dev/null
+++ b/libgfortran/generated/maxval_i2.c
@@ -0,0 +1,410 @@
+/* Implementation of the MAXVAL intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_2)
+
+
+extern void maxval_i2 (gfc_array_i2 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict);
+export_proto(maxval_i2);
+
+void
+maxval_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_2 * restrict base;
+ GFC_INTEGER_2 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ GFC_INTEGER_2 result;
+ src = base;
+ {
+
+ result = (-GFC_INTEGER_2_HUGE-1);
+ if (len <= 0)
+ *dest = (-GFC_INTEGER_2_HUGE-1);
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src > result)
+ result = *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mmaxval_i2 (gfc_array_i2 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mmaxval_i2);
+
+void
+mmaxval_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_2 * restrict dest;
+ const GFC_INTEGER_2 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_2 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ result = (-GFC_INTEGER_2_HUGE-1);
+ if (len <= 0)
+ *dest = (-GFC_INTEGER_2_HUGE-1);
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && *src > result)
+ result = *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void smaxval_i2 (gfc_array_i2 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(smaxval_i2);
+
+void
+smaxval_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_2 *dest;
+
+ if (*mask)
+ {
+ maxval_i2 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_2) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = (-GFC_INTEGER_2_HUGE-1) ;
+}
+
+#endif
diff --git a/libgfortran/generated/minloc0_16_i1.c b/libgfortran/generated/minloc0_16_i1.c
new file mode 100644
index 00000000000..963abdbd951
--- /dev/null
+++ b/libgfortran/generated/minloc0_16_i1.c
@@ -0,0 +1,326 @@
+/* Implementation of the MINLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_16)
+
+
+extern void minloc0_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array);
+export_proto(minloc0_16_i1);
+
+void
+minloc0_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ const GFC_INTEGER_1 *base;
+ GFC_INTEGER_16 *dest;
+ index_type rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_1 minval;
+
+ minval = GFC_INTEGER_1_HUGE;
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*base < minval || !dest[0])
+ {
+ minval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void mminloc0_16_i1 (gfc_array_i16 * const restrict,
+ gfc_array_i1 * const restrict, gfc_array_l4 * const restrict);
+export_proto(mminloc0_16_i1);
+
+void
+mminloc0_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ GFC_INTEGER_16 *dest;
+ const GFC_INTEGER_1 *base;
+ GFC_LOGICAL_4 *mbase;
+ int rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_1 minval;
+
+ minval = GFC_INTEGER_1_HUGE;
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*mbase && (*base < minval || !dest[0]))
+ {
+ minval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void sminloc0_16_i1 (gfc_array_i16 * const restrict,
+ gfc_array_i1 * const restrict, GFC_LOGICAL_4 *);
+export_proto(sminloc0_16_i1);
+
+void
+sminloc0_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type dstride;
+ index_type n;
+ GFC_INTEGER_16 *dest;
+
+ if (*mask)
+ {
+ minloc0_16_i1 (retarray, array);
+ return;
+ }
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n<rank; n++)
+ dest[n * dstride] = 0 ;
+}
+#endif
diff --git a/libgfortran/generated/minloc0_16_i2.c b/libgfortran/generated/minloc0_16_i2.c
new file mode 100644
index 00000000000..edf1c0408fc
--- /dev/null
+++ b/libgfortran/generated/minloc0_16_i2.c
@@ -0,0 +1,326 @@
+/* Implementation of the MINLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_16)
+
+
+extern void minloc0_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array);
+export_proto(minloc0_16_i2);
+
+void
+minloc0_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ const GFC_INTEGER_2 *base;
+ GFC_INTEGER_16 *dest;
+ index_type rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_2 minval;
+
+ minval = GFC_INTEGER_2_HUGE;
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*base < minval || !dest[0])
+ {
+ minval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void mminloc0_16_i2 (gfc_array_i16 * const restrict,
+ gfc_array_i2 * const restrict, gfc_array_l4 * const restrict);
+export_proto(mminloc0_16_i2);
+
+void
+mminloc0_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ GFC_INTEGER_16 *dest;
+ const GFC_INTEGER_2 *base;
+ GFC_LOGICAL_4 *mbase;
+ int rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_2 minval;
+
+ minval = GFC_INTEGER_2_HUGE;
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*mbase && (*base < minval || !dest[0]))
+ {
+ minval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void sminloc0_16_i2 (gfc_array_i16 * const restrict,
+ gfc_array_i2 * const restrict, GFC_LOGICAL_4 *);
+export_proto(sminloc0_16_i2);
+
+void
+sminloc0_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type dstride;
+ index_type n;
+ GFC_INTEGER_16 *dest;
+
+ if (*mask)
+ {
+ minloc0_16_i2 (retarray, array);
+ return;
+ }
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n<rank; n++)
+ dest[n * dstride] = 0 ;
+}
+#endif
diff --git a/libgfortran/generated/minloc0_4_i1.c b/libgfortran/generated/minloc0_4_i1.c
new file mode 100644
index 00000000000..c07ba80802d
--- /dev/null
+++ b/libgfortran/generated/minloc0_4_i1.c
@@ -0,0 +1,326 @@
+/* Implementation of the MINLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_4)
+
+
+extern void minloc0_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array);
+export_proto(minloc0_4_i1);
+
+void
+minloc0_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ const GFC_INTEGER_1 *base;
+ GFC_INTEGER_4 *dest;
+ index_type rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_1 minval;
+
+ minval = GFC_INTEGER_1_HUGE;
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*base < minval || !dest[0])
+ {
+ minval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void mminloc0_4_i1 (gfc_array_i4 * const restrict,
+ gfc_array_i1 * const restrict, gfc_array_l4 * const restrict);
+export_proto(mminloc0_4_i1);
+
+void
+mminloc0_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ GFC_INTEGER_4 *dest;
+ const GFC_INTEGER_1 *base;
+ GFC_LOGICAL_4 *mbase;
+ int rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_1 minval;
+
+ minval = GFC_INTEGER_1_HUGE;
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*mbase && (*base < minval || !dest[0]))
+ {
+ minval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void sminloc0_4_i1 (gfc_array_i4 * const restrict,
+ gfc_array_i1 * const restrict, GFC_LOGICAL_4 *);
+export_proto(sminloc0_4_i1);
+
+void
+sminloc0_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type dstride;
+ index_type n;
+ GFC_INTEGER_4 *dest;
+
+ if (*mask)
+ {
+ minloc0_4_i1 (retarray, array);
+ return;
+ }
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n<rank; n++)
+ dest[n * dstride] = 0 ;
+}
+#endif
diff --git a/libgfortran/generated/minloc0_4_i2.c b/libgfortran/generated/minloc0_4_i2.c
new file mode 100644
index 00000000000..398bf65492d
--- /dev/null
+++ b/libgfortran/generated/minloc0_4_i2.c
@@ -0,0 +1,326 @@
+/* Implementation of the MINLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_4)
+
+
+extern void minloc0_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array);
+export_proto(minloc0_4_i2);
+
+void
+minloc0_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ const GFC_INTEGER_2 *base;
+ GFC_INTEGER_4 *dest;
+ index_type rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_2 minval;
+
+ minval = GFC_INTEGER_2_HUGE;
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*base < minval || !dest[0])
+ {
+ minval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void mminloc0_4_i2 (gfc_array_i4 * const restrict,
+ gfc_array_i2 * const restrict, gfc_array_l4 * const restrict);
+export_proto(mminloc0_4_i2);
+
+void
+mminloc0_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ GFC_INTEGER_4 *dest;
+ const GFC_INTEGER_2 *base;
+ GFC_LOGICAL_4 *mbase;
+ int rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_2 minval;
+
+ minval = GFC_INTEGER_2_HUGE;
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*mbase && (*base < minval || !dest[0]))
+ {
+ minval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void sminloc0_4_i2 (gfc_array_i4 * const restrict,
+ gfc_array_i2 * const restrict, GFC_LOGICAL_4 *);
+export_proto(sminloc0_4_i2);
+
+void
+sminloc0_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type dstride;
+ index_type n;
+ GFC_INTEGER_4 *dest;
+
+ if (*mask)
+ {
+ minloc0_4_i2 (retarray, array);
+ return;
+ }
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n<rank; n++)
+ dest[n * dstride] = 0 ;
+}
+#endif
diff --git a/libgfortran/generated/minloc0_8_i1.c b/libgfortran/generated/minloc0_8_i1.c
new file mode 100644
index 00000000000..628e94025d9
--- /dev/null
+++ b/libgfortran/generated/minloc0_8_i1.c
@@ -0,0 +1,326 @@
+/* Implementation of the MINLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_8)
+
+
+extern void minloc0_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array);
+export_proto(minloc0_8_i1);
+
+void
+minloc0_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ const GFC_INTEGER_1 *base;
+ GFC_INTEGER_8 *dest;
+ index_type rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_1 minval;
+
+ minval = GFC_INTEGER_1_HUGE;
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*base < minval || !dest[0])
+ {
+ minval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void mminloc0_8_i1 (gfc_array_i8 * const restrict,
+ gfc_array_i1 * const restrict, gfc_array_l4 * const restrict);
+export_proto(mminloc0_8_i1);
+
+void
+mminloc0_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ GFC_INTEGER_8 *dest;
+ const GFC_INTEGER_1 *base;
+ GFC_LOGICAL_4 *mbase;
+ int rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_1 minval;
+
+ minval = GFC_INTEGER_1_HUGE;
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*mbase && (*base < minval || !dest[0]))
+ {
+ minval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void sminloc0_8_i1 (gfc_array_i8 * const restrict,
+ gfc_array_i1 * const restrict, GFC_LOGICAL_4 *);
+export_proto(sminloc0_8_i1);
+
+void
+sminloc0_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type dstride;
+ index_type n;
+ GFC_INTEGER_8 *dest;
+
+ if (*mask)
+ {
+ minloc0_8_i1 (retarray, array);
+ return;
+ }
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n<rank; n++)
+ dest[n * dstride] = 0 ;
+}
+#endif
diff --git a/libgfortran/generated/minloc0_8_i2.c b/libgfortran/generated/minloc0_8_i2.c
new file mode 100644
index 00000000000..9e03ee5dce1
--- /dev/null
+++ b/libgfortran/generated/minloc0_8_i2.c
@@ -0,0 +1,326 @@
+/* Implementation of the MINLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_8)
+
+
+extern void minloc0_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array);
+export_proto(minloc0_8_i2);
+
+void
+minloc0_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ const GFC_INTEGER_2 *base;
+ GFC_INTEGER_8 *dest;
+ index_type rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_2 minval;
+
+ minval = GFC_INTEGER_2_HUGE;
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*base < minval || !dest[0])
+ {
+ minval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void mminloc0_8_i2 (gfc_array_i8 * const restrict,
+ gfc_array_i2 * const restrict, gfc_array_l4 * const restrict);
+export_proto(mminloc0_8_i2);
+
+void
+mminloc0_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ index_type dstride;
+ GFC_INTEGER_8 *dest;
+ const GFC_INTEGER_2 *base;
+ GFC_LOGICAL_4 *mbase;
+ int rank;
+ index_type n;
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n < rank; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+ count[n] = 0;
+ if (extent[n] <= 0)
+ {
+ /* Set the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ return;
+ }
+ }
+
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+
+ /* Initialize the return value. */
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0;
+ {
+
+ GFC_INTEGER_2 minval;
+
+ minval = GFC_INTEGER_2_HUGE;
+
+ while (base)
+ {
+ {
+ /* Implementation start. */
+
+ if (*mbase && (*base < minval || !dest[0]))
+ {
+ minval = *base;
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = count[n] + 1;
+ }
+ /* Implementation end. */
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the loop. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ }
+ }
+ }
+ }
+}
+
+
+extern void sminloc0_8_i2 (gfc_array_i8 * const restrict,
+ gfc_array_i2 * const restrict, GFC_LOGICAL_4 *);
+export_proto(sminloc0_8_i2);
+
+void
+sminloc0_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type dstride;
+ index_type n;
+ GFC_INTEGER_8 *dest;
+
+ if (*mask)
+ {
+ minloc0_8_i2 (retarray, array);
+ return;
+ }
+
+ rank = GFC_DESCRIPTOR_RANK (array);
+
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+ for (n = 0; n<rank; n++)
+ dest[n * dstride] = 0 ;
+}
+#endif
diff --git a/libgfortran/generated/minloc1_16_i1.c b/libgfortran/generated/minloc1_16_i1.c
new file mode 100644
index 00000000000..9325b1f0863
--- /dev/null
+++ b/libgfortran/generated/minloc1_16_i1.c
@@ -0,0 +1,421 @@
+/* Implementation of the MINLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_16)
+
+
+extern void minloc1_16_i1 (gfc_array_i16 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict);
+export_proto(minloc1_16_i1);
+
+void
+minloc1_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_1 * restrict base;
+ GFC_INTEGER_16 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ GFC_INTEGER_16 result;
+ src = base;
+ {
+
+ GFC_INTEGER_1 minval;
+ minval = GFC_INTEGER_1_HUGE;
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src < minval || !result)
+ {
+ minval = *src;
+ result = (GFC_INTEGER_16)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mminloc1_16_i1 (gfc_array_i16 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mminloc1_16_i1);
+
+void
+mminloc1_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_16 * restrict dest;
+ const GFC_INTEGER_1 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_16 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ GFC_INTEGER_1 minval;
+ minval = GFC_INTEGER_1_HUGE;
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && (*src < minval || !result))
+ {
+ minval = *src;
+ result = (GFC_INTEGER_16)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void sminloc1_16_i1 (gfc_array_i16 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(sminloc1_16_i1);
+
+void
+sminloc1_16_i1 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_16 *dest;
+
+ if (*mask)
+ {
+ minloc1_16_i1 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/minloc1_16_i2.c b/libgfortran/generated/minloc1_16_i2.c
new file mode 100644
index 00000000000..0e8aa00f87c
--- /dev/null
+++ b/libgfortran/generated/minloc1_16_i2.c
@@ -0,0 +1,421 @@
+/* Implementation of the MINLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_16)
+
+
+extern void minloc1_16_i2 (gfc_array_i16 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict);
+export_proto(minloc1_16_i2);
+
+void
+minloc1_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_2 * restrict base;
+ GFC_INTEGER_16 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ GFC_INTEGER_16 result;
+ src = base;
+ {
+
+ GFC_INTEGER_2 minval;
+ minval = GFC_INTEGER_2_HUGE;
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src < minval || !result)
+ {
+ minval = *src;
+ result = (GFC_INTEGER_16)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mminloc1_16_i2 (gfc_array_i16 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mminloc1_16_i2);
+
+void
+mminloc1_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_16 * restrict dest;
+ const GFC_INTEGER_2 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_16 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ GFC_INTEGER_2 minval;
+ minval = GFC_INTEGER_2_HUGE;
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && (*src < minval || !result))
+ {
+ minval = *src;
+ result = (GFC_INTEGER_16)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void sminloc1_16_i2 (gfc_array_i16 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(sminloc1_16_i2);
+
+void
+sminloc1_16_i2 (gfc_array_i16 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_16 *dest;
+
+ if (*mask)
+ {
+ minloc1_16_i2 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/minloc1_4_i1.c b/libgfortran/generated/minloc1_4_i1.c
new file mode 100644
index 00000000000..4e0c4dd02bb
--- /dev/null
+++ b/libgfortran/generated/minloc1_4_i1.c
@@ -0,0 +1,421 @@
+/* Implementation of the MINLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_4)
+
+
+extern void minloc1_4_i1 (gfc_array_i4 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict);
+export_proto(minloc1_4_i1);
+
+void
+minloc1_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_1 * restrict base;
+ GFC_INTEGER_4 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ GFC_INTEGER_4 result;
+ src = base;
+ {
+
+ GFC_INTEGER_1 minval;
+ minval = GFC_INTEGER_1_HUGE;
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src < minval || !result)
+ {
+ minval = *src;
+ result = (GFC_INTEGER_4)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mminloc1_4_i1 (gfc_array_i4 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mminloc1_4_i1);
+
+void
+mminloc1_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_4 * restrict dest;
+ const GFC_INTEGER_1 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_4 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ GFC_INTEGER_1 minval;
+ minval = GFC_INTEGER_1_HUGE;
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && (*src < minval || !result))
+ {
+ minval = *src;
+ result = (GFC_INTEGER_4)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void sminloc1_4_i1 (gfc_array_i4 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(sminloc1_4_i1);
+
+void
+sminloc1_4_i1 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_4 *dest;
+
+ if (*mask)
+ {
+ minloc1_4_i1 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/minloc1_4_i2.c b/libgfortran/generated/minloc1_4_i2.c
new file mode 100644
index 00000000000..6c6ba8f9be9
--- /dev/null
+++ b/libgfortran/generated/minloc1_4_i2.c
@@ -0,0 +1,421 @@
+/* Implementation of the MINLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_4)
+
+
+extern void minloc1_4_i2 (gfc_array_i4 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict);
+export_proto(minloc1_4_i2);
+
+void
+minloc1_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_2 * restrict base;
+ GFC_INTEGER_4 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ GFC_INTEGER_4 result;
+ src = base;
+ {
+
+ GFC_INTEGER_2 minval;
+ minval = GFC_INTEGER_2_HUGE;
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src < minval || !result)
+ {
+ minval = *src;
+ result = (GFC_INTEGER_4)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mminloc1_4_i2 (gfc_array_i4 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mminloc1_4_i2);
+
+void
+mminloc1_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_4 * restrict dest;
+ const GFC_INTEGER_2 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_4 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ GFC_INTEGER_2 minval;
+ minval = GFC_INTEGER_2_HUGE;
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && (*src < minval || !result))
+ {
+ minval = *src;
+ result = (GFC_INTEGER_4)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void sminloc1_4_i2 (gfc_array_i4 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(sminloc1_4_i2);
+
+void
+sminloc1_4_i2 (gfc_array_i4 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_4 *dest;
+
+ if (*mask)
+ {
+ minloc1_4_i2 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/minloc1_8_i1.c b/libgfortran/generated/minloc1_8_i1.c
new file mode 100644
index 00000000000..187393aaef0
--- /dev/null
+++ b/libgfortran/generated/minloc1_8_i1.c
@@ -0,0 +1,421 @@
+/* Implementation of the MINLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_8)
+
+
+extern void minloc1_8_i1 (gfc_array_i8 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict);
+export_proto(minloc1_8_i1);
+
+void
+minloc1_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_1 * restrict base;
+ GFC_INTEGER_8 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ GFC_INTEGER_8 result;
+ src = base;
+ {
+
+ GFC_INTEGER_1 minval;
+ minval = GFC_INTEGER_1_HUGE;
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src < minval || !result)
+ {
+ minval = *src;
+ result = (GFC_INTEGER_8)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mminloc1_8_i1 (gfc_array_i8 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mminloc1_8_i1);
+
+void
+mminloc1_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_8 * restrict dest;
+ const GFC_INTEGER_1 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_8 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ GFC_INTEGER_1 minval;
+ minval = GFC_INTEGER_1_HUGE;
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && (*src < minval || !result))
+ {
+ minval = *src;
+ result = (GFC_INTEGER_8)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void sminloc1_8_i1 (gfc_array_i8 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(sminloc1_8_i1);
+
+void
+sminloc1_8_i1 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_8 *dest;
+
+ if (*mask)
+ {
+ minloc1_8_i1 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/minloc1_8_i2.c b/libgfortran/generated/minloc1_8_i2.c
new file mode 100644
index 00000000000..04c3618805e
--- /dev/null
+++ b/libgfortran/generated/minloc1_8_i2.c
@@ -0,0 +1,421 @@
+/* Implementation of the MINLOC intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include <limits.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_8)
+
+
+extern void minloc1_8_i2 (gfc_array_i8 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict);
+export_proto(minloc1_8_i2);
+
+void
+minloc1_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_2 * restrict base;
+ GFC_INTEGER_8 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ GFC_INTEGER_8 result;
+ src = base;
+ {
+
+ GFC_INTEGER_2 minval;
+ minval = GFC_INTEGER_2_HUGE;
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src < minval || !result)
+ {
+ minval = *src;
+ result = (GFC_INTEGER_8)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mminloc1_8_i2 (gfc_array_i8 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mminloc1_8_i2);
+
+void
+mminloc1_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_8 * restrict dest;
+ const GFC_INTEGER_2 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_8 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ GFC_INTEGER_2 minval;
+ minval = GFC_INTEGER_2_HUGE;
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && (*src < minval || !result))
+ {
+ minval = *src;
+ result = (GFC_INTEGER_8)n + 1;
+ }
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void sminloc1_8_i2 (gfc_array_i8 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(sminloc1_8_i2);
+
+void
+sminloc1_8_i2 (gfc_array_i8 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_8 *dest;
+
+ if (*mask)
+ {
+ minloc1_8_i2 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/minval_i1.c b/libgfortran/generated/minval_i1.c
new file mode 100644
index 00000000000..9959915493a
--- /dev/null
+++ b/libgfortran/generated/minval_i1.c
@@ -0,0 +1,410 @@
+/* Implementation of the MINVAL intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_1)
+
+
+extern void minval_i1 (gfc_array_i1 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict);
+export_proto(minval_i1);
+
+void
+minval_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_1 * restrict base;
+ GFC_INTEGER_1 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ GFC_INTEGER_1 result;
+ src = base;
+ {
+
+ result = GFC_INTEGER_1_HUGE;
+ if (len <= 0)
+ *dest = GFC_INTEGER_1_HUGE;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src < result)
+ result = *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mminval_i1 (gfc_array_i1 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mminval_i1);
+
+void
+mminval_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_1 * restrict dest;
+ const GFC_INTEGER_1 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_1 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ result = GFC_INTEGER_1_HUGE;
+ if (len <= 0)
+ *dest = GFC_INTEGER_1_HUGE;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && *src < result)
+ result = *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void sminval_i1 (gfc_array_i1 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(sminval_i1);
+
+void
+sminval_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_1 *dest;
+
+ if (*mask)
+ {
+ minval_i1 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_1) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = GFC_INTEGER_1_HUGE ;
+}
+
+#endif
diff --git a/libgfortran/generated/minval_i2.c b/libgfortran/generated/minval_i2.c
new file mode 100644
index 00000000000..e42c9f69be5
--- /dev/null
+++ b/libgfortran/generated/minval_i2.c
@@ -0,0 +1,410 @@
+/* Implementation of the MINVAL intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <float.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_2)
+
+
+extern void minval_i2 (gfc_array_i2 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict);
+export_proto(minval_i2);
+
+void
+minval_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_2 * restrict base;
+ GFC_INTEGER_2 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ GFC_INTEGER_2 result;
+ src = base;
+ {
+
+ result = GFC_INTEGER_2_HUGE;
+ if (len <= 0)
+ *dest = GFC_INTEGER_2_HUGE;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ if (*src < result)
+ result = *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mminval_i2 (gfc_array_i2 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mminval_i2);
+
+void
+mminval_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_2 * restrict dest;
+ const GFC_INTEGER_2 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_2 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ result = GFC_INTEGER_2_HUGE;
+ if (len <= 0)
+ *dest = GFC_INTEGER_2_HUGE;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc && *src < result)
+ result = *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void sminval_i2 (gfc_array_i2 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(sminval_i2);
+
+void
+sminval_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_2 *dest;
+
+ if (*mask)
+ {
+ minval_i2 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_2) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = GFC_INTEGER_2_HUGE ;
+}
+
+#endif
diff --git a/libgfortran/generated/product_i1.c b/libgfortran/generated/product_i1.c
new file mode 100644
index 00000000000..76427e4cbb7
--- /dev/null
+++ b/libgfortran/generated/product_i1.c
@@ -0,0 +1,408 @@
+/* Implementation of the PRODUCT intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_1)
+
+
+extern void product_i1 (gfc_array_i1 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict);
+export_proto(product_i1);
+
+void
+product_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_1 * restrict base;
+ GFC_INTEGER_1 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ GFC_INTEGER_1 result;
+ src = base;
+ {
+
+ result = 1;
+ if (len <= 0)
+ *dest = 1;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ result *= *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mproduct_i1 (gfc_array_i1 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mproduct_i1);
+
+void
+mproduct_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_1 * restrict dest;
+ const GFC_INTEGER_1 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_1 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ result = 1;
+ if (len <= 0)
+ *dest = 1;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc)
+ result *= *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void sproduct_i1 (gfc_array_i1 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(sproduct_i1);
+
+void
+sproduct_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_1 *dest;
+
+ if (*mask)
+ {
+ product_i1 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_1) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 1 ;
+}
+
+#endif
diff --git a/libgfortran/generated/product_i2.c b/libgfortran/generated/product_i2.c
new file mode 100644
index 00000000000..bdb51a65c52
--- /dev/null
+++ b/libgfortran/generated/product_i2.c
@@ -0,0 +1,408 @@
+/* Implementation of the PRODUCT intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_2)
+
+
+extern void product_i2 (gfc_array_i2 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict);
+export_proto(product_i2);
+
+void
+product_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_2 * restrict base;
+ GFC_INTEGER_2 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ GFC_INTEGER_2 result;
+ src = base;
+ {
+
+ result = 1;
+ if (len <= 0)
+ *dest = 1;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ result *= *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void mproduct_i2 (gfc_array_i2 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(mproduct_i2);
+
+void
+mproduct_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_2 * restrict dest;
+ const GFC_INTEGER_2 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_2 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ result = 1;
+ if (len <= 0)
+ *dest = 1;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc)
+ result *= *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void sproduct_i2 (gfc_array_i2 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(sproduct_i2);
+
+void
+sproduct_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_2 *dest;
+
+ if (*mask)
+ {
+ product_i2 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_2) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 1 ;
+}
+
+#endif
diff --git a/libgfortran/generated/sum_i1.c b/libgfortran/generated/sum_i1.c
new file mode 100644
index 00000000000..87205b8f716
--- /dev/null
+++ b/libgfortran/generated/sum_i1.c
@@ -0,0 +1,408 @@
+/* Implementation of the SUM intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_1)
+
+
+extern void sum_i1 (gfc_array_i1 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict);
+export_proto(sum_i1);
+
+void
+sum_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_1 * restrict base;
+ GFC_INTEGER_1 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ GFC_INTEGER_1 result;
+ src = base;
+ {
+
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ result += *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void msum_i1 (gfc_array_i1 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(msum_i1);
+
+void
+msum_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_1 * restrict dest;
+ const GFC_INTEGER_1 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_1 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_1 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc)
+ result += *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void ssum_i1 (gfc_array_i1 * const restrict,
+ gfc_array_i1 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(ssum_i1);
+
+void
+ssum_i1 (gfc_array_i1 * const restrict retarray,
+ gfc_array_i1 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_1 *dest;
+
+ if (*mask)
+ {
+ sum_i1 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_1) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif
diff --git a/libgfortran/generated/sum_i2.c b/libgfortran/generated/sum_i2.c
new file mode 100644
index 00000000000..c4452c3ce9d
--- /dev/null
+++ b/libgfortran/generated/sum_i2.c
@@ -0,0 +1,408 @@
+/* Implementation of the SUM intrinsic
+ Copyright 2002 Free Software Foundation, Inc.
+ Contributed by Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include <stdlib.h>
+#include <assert.h>
+#include "libgfortran.h"
+
+
+#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_2)
+
+
+extern void sum_i2 (gfc_array_i2 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict);
+export_proto(sum_i2);
+
+void
+sum_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ const GFC_INTEGER_2 * restrict base;
+ GFC_INTEGER_2 * restrict dest;
+ index_type rank;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type dim;
+
+ /* Make dim zero based to avoid confusion. */
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ delta = array->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ len = 0;
+ }
+
+ base = array->data;
+ dest = retarray->data;
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ GFC_INTEGER_2 result;
+ src = base;
+ {
+
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta)
+ {
+
+ result += *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void msum_i2 (gfc_array_i2 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
+export_proto(msum_i2);
+
+void
+msum_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
+{
+ index_type count[GFC_MAX_DIMENSIONS];
+ index_type extent[GFC_MAX_DIMENSIONS];
+ index_type sstride[GFC_MAX_DIMENSIONS];
+ index_type dstride[GFC_MAX_DIMENSIONS];
+ index_type mstride[GFC_MAX_DIMENSIONS];
+ GFC_INTEGER_2 * restrict dest;
+ const GFC_INTEGER_2 * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
+ int rank;
+ int dim;
+ index_type n;
+ index_type len;
+ index_type delta;
+ index_type mdelta;
+
+ dim = (*pdim) - 1;
+ rank = GFC_DESCRIPTOR_RANK (array) - 1;
+
+ len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
+ if (len <= 0)
+ return;
+ delta = array->dim[dim].stride;
+ mdelta = mask->dim[dim].stride;
+
+ for (n = 0; n < dim; n++)
+ {
+ sstride[n] = array->dim[n].stride;
+ mstride[n] = mask->dim[n].stride;
+ extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+
+ }
+ for (n = dim; n < rank; n++)
+ {
+ sstride[n] = array->dim[n + 1].stride;
+ mstride[n] = mask->dim[n + 1].stride;
+ extent[n] =
+ array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
+ }
+
+ if (retarray->data == NULL)
+ {
+ size_t alloc_size;
+
+ for (n = 0; n < rank; n++)
+ {
+ retarray->dim[n].lbound = 0;
+ retarray->dim[n].ubound = extent[n]-1;
+ if (n == 0)
+ retarray->dim[n].stride = 1;
+ else
+ retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
+ }
+
+ alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
+
+ }
+ else
+ {
+ if (rank != GFC_DESCRIPTOR_RANK (retarray))
+ runtime_error ("rank of return array incorrect");
+ }
+
+ for (n = 0; n < rank; n++)
+ {
+ count[n] = 0;
+ dstride[n] = retarray->dim[n].stride;
+ if (extent[n] <= 0)
+ return;
+ }
+
+ dest = retarray->data;
+ base = array->data;
+ mbase = mask->data;
+
+ if (GFC_DESCRIPTOR_SIZE (mask) != 4)
+ {
+ /* This allows the same loop to be used for all logical types. */
+ assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
+ for (n = 0; n < rank; n++)
+ mstride[n] <<= 1;
+ mdelta <<= 1;
+ mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
+ }
+
+ while (base)
+ {
+ const GFC_INTEGER_2 * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
+ GFC_INTEGER_2 result;
+ src = base;
+ msrc = mbase;
+ {
+
+ result = 0;
+ if (len <= 0)
+ *dest = 0;
+ else
+ {
+ for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+ {
+
+ if (*msrc)
+ result += *src;
+ }
+ *dest = result;
+ }
+ }
+ /* Advance to the next element. */
+ count[0]++;
+ base += sstride[0];
+ mbase += mstride[0];
+ dest += dstride[0];
+ n = 0;
+ while (count[n] == extent[n])
+ {
+ /* When we get to the end of a dimension, reset it and increment
+ the next dimension. */
+ count[n] = 0;
+ /* We could precalculate these products, but this is a less
+ frequently used path so probably not worth it. */
+ base -= sstride[n] * extent[n];
+ mbase -= mstride[n] * extent[n];
+ dest -= dstride[n] * extent[n];
+ n++;
+ if (n == rank)
+ {
+ /* Break out of the look. */
+ base = NULL;
+ break;
+ }
+ else
+ {
+ count[n]++;
+ base += sstride[n];
+ mbase += mstride[n];
+ dest += dstride[n];
+ }
+ }
+ }
+}
+
+
+extern void ssum_i2 (gfc_array_i2 * const restrict,
+ gfc_array_i2 * const restrict, const index_type * const restrict,
+ GFC_LOGICAL_4 *);
+export_proto(ssum_i2);
+
+void
+ssum_i2 (gfc_array_i2 * const restrict retarray,
+ gfc_array_i2 * const restrict array,
+ const index_type * const restrict pdim,
+ GFC_LOGICAL_4 * mask)
+{
+ index_type rank;
+ index_type n;
+ index_type dstride;
+ GFC_INTEGER_2 *dest;
+
+ if (*mask)
+ {
+ sum_i2 (retarray, array, pdim);
+ return;
+ }
+ rank = GFC_DESCRIPTOR_RANK (array);
+ if (rank <= 0)
+ runtime_error ("Rank of array needs to be > 0");
+
+ if (retarray->data == NULL)
+ {
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = rank-1;
+ retarray->dim[0].stride = 1;
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+ retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_2) * rank);
+ }
+ else
+ {
+ if (GFC_DESCRIPTOR_RANK (retarray) != 1)
+ runtime_error ("rank of return array does not equal 1");
+
+ if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
+ runtime_error ("dimension of return array incorrect");
+ }
+
+ dstride = retarray->dim[0].stride;
+ dest = retarray->data;
+
+ for (n = 0; n < rank; n++)
+ dest[n * dstride] = 0 ;
+}
+
+#endif