/* Implementation of the MINLOC intrinsic
- Copyright (C) 2002-2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2020 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran runtime library (libgfortran).
<http://www.gnu.org/licenses/>. */
#include "libgfortran.h"
+#include <assert.h>
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_8)
+#define HAVE_BACK_ARG 1
+
extern void minloc1_8_i1 (gfc_array_i8 * const restrict,
- gfc_array_i1 * const restrict, const index_type * const restrict);
+ gfc_array_i1 * const restrict, const index_type * const restrict, GFC_LOGICAL_4 back);
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)
+ const index_type * const restrict pdim, GFC_LOGICAL_4 back)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
}
retarray->offset = 0;
- GFC_DTYPE_COPY_SETRANK(retarray,array,rank);
+ retarray->dtype.rank = rank;
alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
*dest = 0;
else
{
+#if ! defined HAVE_BACK_ARG
for (n = 0; n < len; n++, src += delta)
{
+#endif
#if defined (GFC_INTEGER_1_QUIET_NAN)
+ for (n = 0; n < len; n++, src += delta)
+ {
if (*src <= minval)
{
minval = *src;
break;
}
}
- for (; n < len; n++, src += delta)
- {
+#else
+ n = 0;
#endif
- if (*src < minval)
- {
- minval = *src;
- result = (GFC_INTEGER_8)n + 1;
- }
+ if (back)
+ for (; n < len; n++, src += delta)
+ {
+ if (unlikely (*src <= minval))
+ {
+ minval = *src;
+ result = (GFC_INTEGER_8)n + 1;
+ }
+ }
+ else
+ for (; n < len; n++, src += delta)
+ {
+ if (unlikely (*src < minval))
+ {
+ minval = *src;
+ result = (GFC_INTEGER_8) n + 1;
+ }
}
*dest = result;
extern void mminloc1_8_i1 (gfc_array_i8 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
- gfc_array_l1 * const restrict);
+ gfc_array_l1 * const restrict, GFC_LOGICAL_4 back);
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_l1 * const restrict mask)
+ gfc_array_l1 * const restrict mask, GFC_LOGICAL_4 back)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type mdelta;
int mask_kind;
+ if (mask == NULL)
+ {
+#ifdef HAVE_BACK_ARG
+ minloc1_8_i1 (retarray, array, pdim, back);
+#else
+ minloc1_8_i1 (retarray, array, pdim);
+#endif
+ return;
+ }
+
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
retarray->offset = 0;
- GFC_DTYPE_COPY_SETRANK(retarray,array,rank);
+ retarray->dtype.rank = rank;
if (alloc_size == 0)
{
result = result2;
else
#endif
- for (; n < len; n++, src += delta, msrc += mdelta)
- {
- if (*msrc && *src < minval)
+ if (back)
+ for (; n < len; n++, src += delta, msrc += mdelta)
+ {
+ if (*msrc && unlikely (*src <= minval))
+ {
+ minval = *src;
+ result = (GFC_INTEGER_8)n + 1;
+ }
+ }
+ else
+ for (; n < len; n++, src += delta, msrc += mdelta)
{
- minval = *src;
- result = (GFC_INTEGER_8)n + 1;
- }
+ if (*msrc && unlikely (*src < minval))
+ {
+ minval = *src;
+ result = (GFC_INTEGER_8) n + 1;
+ }
}
*dest = result;
}
extern void sminloc1_8_i1 (gfc_array_i8 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
- GFC_LOGICAL_4 *);
+ GFC_LOGICAL_4 *, GFC_LOGICAL_4 back);
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)
+ GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type dim;
- if (*mask)
+ if (mask == NULL || *mask)
{
+#ifdef HAVE_BACK_ARG
+ minloc1_8_i1 (retarray, array, pdim, back);
+#else
minloc1_8_i1 (retarray, array, pdim);
+#endif
return;
}
/* Make dim zero based to avoid confusion. */
}
retarray->offset = 0;
- GFC_DTYPE_COPY_SETRANK(retarray,array,rank);
+ retarray->dtype.rank = rank;
alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];