/* Generic implementation of the SPREAD intrinsic
- Copyright (C) 2002-2014 Free Software Foundation, Inc.
+ Copyright (C) 2002-2024 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 <stdlib.h>
-#include <assert.h>
#include <string.h>
static void
srank = GFC_DESCRIPTOR_RANK(source);
+ sstride[0] = 0; /* Avoid warnings if not initialized. */
+
rrank = srank + 1;
if (rrank > GFC_MAX_DIMENSIONS)
runtime_error ("return rank too large in spread()");
size_t ub, stride;
- ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rrank;
+ ret->dtype.rank = rrank;
+
dim = 0;
rs = 1;
for (n = 0; n < rrank; n++)
type_size = GFC_DTYPE_TYPE_SIZE(ret);
switch(type_size)
{
- case GFC_DTYPE_DERIVED_1:
case GFC_DTYPE_LOGICAL_1:
case GFC_DTYPE_INTEGER_1:
spread_i1 ((gfc_array_i1 *) ret, (gfc_array_i1 *) source,
/* FIXME: This here is a hack, which will have to be removed when
the array descriptor is reworked. Currently, we don't store the
kind value for the type, but only the size. Because on targets with
- __float128, we have sizeof(logn double) == sizeof(__float128),
+ _Float128, we have sizeof(long double) == sizeof(_Float128),
we cannot discriminate here and have to fall back to the generic
handling (which is suboptimal). */
#if !defined(GFC_REAL_16_IS_FLOAT128)
/* FIXME: This here is a hack, which will have to be removed when
the array descriptor is reworked. Currently, we don't store the
kind value for the type, but only the size. Because on targets with
- __float128, we have sizeof(logn double) == sizeof(__float128),
+ _Float128, we have sizeof(long double) == sizeof(_Float128),
we cannot discriminate here and have to fall back to the generic
handling (which is suboptimal). */
#if !defined(GFC_REAL_16_IS_FLOAT128)
# endif
#endif
- case GFC_DTYPE_DERIVED_2:
+ }
+
+ switch (GFC_DESCRIPTOR_SIZE (ret))
+ {
+ case 1:
+ spread_i1 ((gfc_array_i1 *) ret, (gfc_array_i1 *) source,
+ *along, *pncopies);
+ return;
+
+ case 2:
if (GFC_UNALIGNED_2(ret->base_addr) || GFC_UNALIGNED_2(source->base_addr))
break;
else
return;
}
- case GFC_DTYPE_DERIVED_4:
+ case 4:
if (GFC_UNALIGNED_4(ret->base_addr) || GFC_UNALIGNED_4(source->base_addr))
break;
else
return;
}
- case GFC_DTYPE_DERIVED_8:
+ case 8:
if (GFC_UNALIGNED_8(ret->base_addr) || GFC_UNALIGNED_8(source->base_addr))
break;
else
*along, *pncopies);
return;
}
-
#ifdef HAVE_GFC_INTEGER_16
- case GFC_DTYPE_DERIVED_16:
+ case 16:
if (GFC_UNALIGNED_16(ret->base_addr)
|| GFC_UNALIGNED_16(source->base_addr))
break;
spread_i16 ((gfc_array_i16 *) ret, (gfc_array_i16 *) source,
*along, *pncopies);
return;
- }
+ }
#endif
+
}
spread_internal (ret, source, along, pncopies);
{
index_type type_size;
- if (!ret->dtype)
+ if (GFC_DTYPE_IS_UNSET(ret))
runtime_error ("return array missing descriptor in spread()");
type_size = GFC_DTYPE_TYPE_SIZE(ret);
switch(type_size)
{
- case GFC_DTYPE_DERIVED_1:
case GFC_DTYPE_LOGICAL_1:
case GFC_DTYPE_INTEGER_1:
spread_scalar_i1 ((gfc_array_i1 *) ret, (GFC_INTEGER_1 *) source,
/* FIXME: This here is a hack, which will have to be removed when
the array descriptor is reworked. Currently, we don't store the
kind value for the type, but only the size. Because on targets with
- __float128, we have sizeof(logn double) == sizeof(__float128),
+ _Float128, we have sizeof(long double) == sizeof(_Float128),
we cannot discriminate here and have to fall back to the generic
handling (which is suboptimal). */
#if !defined(GFC_REAL_16_IS_FLOAT128)
/* FIXME: This here is a hack, which will have to be removed when
the array descriptor is reworked. Currently, we don't store the
kind value for the type, but only the size. Because on targets with
- __float128, we have sizeof(logn double) == sizeof(__float128),
+ _Float128, we have sizeof(long double) == sizeof(_Float128),
we cannot discriminate here and have to fall back to the generic
handling (which is suboptimal). */
#if !defined(GFC_REAL_16_IS_FLOAT128)
# endif
#endif
- case GFC_DTYPE_DERIVED_2:
+ }
+
+ switch (GFC_DESCRIPTOR_SIZE(ret))
+ {
+ case 1:
+ spread_scalar_i1 ((gfc_array_i1 *) ret, (GFC_INTEGER_1 *) source,
+ *along, *pncopies);
+ return;
+
+ case 2:
if (GFC_UNALIGNED_2(ret->base_addr) || GFC_UNALIGNED_2(source))
break;
else
return;
}
- case GFC_DTYPE_DERIVED_4:
+ case 4:
if (GFC_UNALIGNED_4(ret->base_addr) || GFC_UNALIGNED_4(source))
break;
else
return;
}
- case GFC_DTYPE_DERIVED_8:
+ case 8:
if (GFC_UNALIGNED_8(ret->base_addr) || GFC_UNALIGNED_8(source))
break;
else
return;
}
#ifdef HAVE_GFC_INTEGER_16
- case GFC_DTYPE_DERIVED_16:
+ case 16:
if (GFC_UNALIGNED_16(ret->base_addr) || GFC_UNALIGNED_16(source))
break;
else
return;
}
#endif
+ default:
+ break;
}
spread_internal_scalar (ret, source, along, pncopies);
const index_type *pncopies,
GFC_INTEGER_4 source_length __attribute__((unused)))
{
- if (!ret->dtype)
+ if (GFC_DTYPE_IS_UNSET(ret))
runtime_error ("return array missing descriptor in spread()");
spread_internal_scalar (ret, source, along, pncopies);
}
const index_type *pncopies,
GFC_INTEGER_4 source_length __attribute__((unused)))
{
- if (!ret->dtype)
+ if (GFC_DTYPE_IS_UNSET(ret))
runtime_error ("return array missing descriptor in spread()");
spread_internal_scalar (ret, source, along, pncopies);