reshape_packed.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Implementation of the RESHAPE intrinsic for packed arrays
  2. Copyright (C) 2002-2022 Free Software Foundation, Inc.
  3. Contributed by Paul Brook <paul@nowt.org>
  4. This file is part of the GNU Fortran 95 runtime library (libgfortran).
  5. Libgfortran is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either
  8. version 3 of the License, or (at your option) any later version.
  9. Ligbfortran is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #include "libgfortran.h"
  21. #include <string.h>
  22. /* Reshape function where all arrays are packed. Basically just memcpy. */
  23. void
  24. reshape_packed (char * restrict ret, index_type rsize, const char * source,
  25. index_type ssize, const char * pad, index_type psize)
  26. {
  27. index_type size;
  28. size = (rsize > ssize) ? ssize : rsize;
  29. memcpy (ret, source, size);
  30. ret += size;
  31. rsize -= size;
  32. while (rsize > 0)
  33. {
  34. size = (rsize > psize) ? psize : rsize;
  35. memcpy (ret, pad, size);
  36. ret += size;
  37. rsize -= size;
  38. }
  39. }