7823229bc3
gcc/fortran/ PR target/19269 * iresolve.c (gfc_resolve_cshift, gfc_resolve_eoshift) (gfc_resolve_pack, gfc_resolve_reshape, gfc_resolve_spread) (gfc_resolve_transpose, gfc_resolve_unpack): Add "_char" to the name for character-based operations. (gfc_resolve_pack): Remove ATTRIBUTE_UNUSED from array argument. (gfc_resolve_unpack): Copy the whole typespec from the vector. * trans-array.c (gfc_conv_expr_descriptor): In the EXPR_FUNCTION case, get the string length from the scalarization state. libgfortran/ PR target/19269 * intrinsics/cshift0.c (cshift0): Add an extra size argument. (cshift0_1, cshift0_2, cshift0_4, cshift0_8): Replace explicit implementations with... (DEFINE_CSHIFT): ...this new macro. Define character versions too. * intrinsics/eoshift0.c (zeros): Delete. (eoshift0): Add extra size and filler arguments. Use memset if no bound is provided. (eoshift0_1, eoshift0_2, eoshift0_4, eoshift0_8): Replace explicit implementations with... (DEFINE_EOSHIFT): ...this new macro. Define character versions too. * intrinsics/eoshift2.c (zeros): Delete. (eoshift2): Add extra size and filler arguments. Use memset if no bound is provided. (eoshift2_1, eoshift2_2, eoshift2_4, eoshift2_8): Replace explicit implementations with... (DEFINE_EOSHIFT): ...this new macro. Define character versions too. * intrinsics/pack.c (pack_internal): New static function, reusing the contents of pack and adding an extra size argument. Change "mptr" rather than "m" when calculating the array size. (pack): Redefine as a forwarder to pack_internal. (pack_s_internal): New static function, reusing the contents of pack_s and adding an extra size argument. (pack_s): Redefine as a forwarder to pack_s_internal. (pack_char, pack_s_char): New functions. * intrinsics/reshape.c (reshape_internal): New static function, reusing the contents of reshape and adding an extra size argument. (reshape): Redefine as a forwarder to reshape_internal. (reshape_char): New function. * intrinsics/spread.c (spread_internal): New static function, reusing the contents of spread and adding an extra size argument. (spread): Redefine as a forwarder to spread_internal. (spread_char): New function. * intrinsics/transpose.c (transpose_internal): New static function, reusing the contents of transpose and adding an extra size argument. (transpose): Redefine as a forwarder to transpose_internal. (transpose_char): New function. * intrinsics/unpack.c (unpack_internal): New static function, reusing the contents of unpack1 and adding extra size and fsize arguments. (unpack1): Redefine as a forwarder to unpack_internal. (unpack0): Call unpack_internal instead of unpack1. (unpack1_char, unpack0_char): New functions. * m4/cshift1.m4 (cshift1): New static function, reusing the contents of cshift1_<kind> and adding an extra size argument. (cshift1_<kind>): Redefine as a forwarder to cshift1. (cshift1_<kind>_char): New function. * m4/eoshift1.m4 (zeros): Delete. (eoshift1): New static function, reusing the contents of eoshift1_<kind> and adding extra size and filler arguments. Fix calculation of hstride. Use memset if no bound is provided. (eoshift1_<kind>): Redefine as a forwarder to eoshift1. (eoshift1_<kind>_char): New function. * m4/eoshift3.m4 (zeros): Delete. (eoshift3): New static function, reusing the contents of eoshift3_<kind> and adding extra size and filler arguments. Use memset if no bound is provided. (eoshift3_<kind>): Redefine as a forwarder to eoshift3. (eoshift3_<kind>_char): New function. * generated/cshift1_4.c, generated/cshift1_8.c, * generated/eoshift1_4.c, generated/eoshift1_8.c, * generated/eoshift3_4.c, generated/eoshift3_8.c: Regenerate. From-SVN: r104217
122 lines
3.6 KiB
C
122 lines
3.6 KiB
C
/* Implementation of the TRANSPOSE intrinsic
|
|
Copyright 2003 Free Software Foundation, Inc.
|
|
Contributed by Tobias Schlüter
|
|
|
|
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"
|
|
|
|
extern void transpose (gfc_array_char *, gfc_array_char *);
|
|
export_proto(transpose);
|
|
|
|
static void
|
|
transpose_internal (gfc_array_char *ret, gfc_array_char *source,
|
|
index_type size)
|
|
{
|
|
/* r.* indicates the return array. */
|
|
index_type rxstride, rystride;
|
|
char *rptr;
|
|
/* s.* indicates the source array. */
|
|
index_type sxstride, systride;
|
|
const char *sptr;
|
|
|
|
index_type xcount, ycount;
|
|
index_type x, y;
|
|
|
|
assert (GFC_DESCRIPTOR_RANK (source) == 2
|
|
&& GFC_DESCRIPTOR_RANK (ret) == 2);
|
|
|
|
if (ret->data == NULL)
|
|
{
|
|
assert (ret->dtype == source->dtype);
|
|
|
|
ret->dim[0].lbound = 0;
|
|
ret->dim[0].ubound = source->dim[1].ubound - source->dim[1].lbound;
|
|
ret->dim[0].stride = 1;
|
|
|
|
ret->dim[1].lbound = 0;
|
|
ret->dim[1].ubound = source->dim[0].ubound - source->dim[0].lbound;
|
|
ret->dim[1].stride = ret->dim[0].ubound+1;
|
|
|
|
ret->data = internal_malloc_size (size * size0 ((array_t*)ret));
|
|
ret->offset = 0;
|
|
}
|
|
|
|
sxstride = source->dim[0].stride * size;
|
|
if (sxstride == 0)
|
|
sxstride = size;
|
|
systride = source->dim[1].stride * size;
|
|
xcount = source->dim[0].ubound + 1 - source->dim[0].lbound;
|
|
ycount = source->dim[1].ubound + 1 - source->dim[1].lbound;
|
|
|
|
rxstride = ret->dim[0].stride * size;
|
|
if (rxstride == 0)
|
|
rxstride = size;
|
|
rystride = ret->dim[1].stride * size;
|
|
|
|
rptr = ret->data;
|
|
sptr = source->data;
|
|
|
|
for (y = 0; y < ycount; y++)
|
|
{
|
|
for (x = 0; x < xcount; x++)
|
|
{
|
|
memcpy (rptr, sptr, size);
|
|
|
|
sptr += sxstride;
|
|
rptr += rystride;
|
|
}
|
|
sptr += systride - (sxstride * xcount);
|
|
rptr += rxstride - (rystride * xcount);
|
|
}
|
|
}
|
|
|
|
extern void transpose (gfc_array_char *, gfc_array_char *);
|
|
export_proto(transpose);
|
|
|
|
void
|
|
transpose (gfc_array_char *ret, gfc_array_char *source)
|
|
{
|
|
transpose_internal (ret, source, GFC_DESCRIPTOR_SIZE (source));
|
|
}
|
|
|
|
extern void transpose_char (gfc_array_char *, GFC_INTEGER_4,
|
|
gfc_array_char *, GFC_INTEGER_4);
|
|
export_proto(transpose_char);
|
|
|
|
void
|
|
transpose_char (gfc_array_char *ret,
|
|
GFC_INTEGER_4 ret_length __attribute__((unused)),
|
|
gfc_array_char *source, GFC_INTEGER_4 source_length)
|
|
{
|
|
transpose_internal (ret, source, source_length);
|
|
}
|