transpose_c4.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Implementation of the TRANSPOSE intrinsic
  2. Copyright (C) 2003-2015 Free Software Foundation, Inc.
  3. Contributed by Tobias Schlüter
  4. This file is part of the GNU Fortran 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. Libgfortran 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 <assert.h>
  22. #if defined (HAVE_GFC_COMPLEX_4)
  23. extern void transpose_c4 (gfc_array_c4 * const restrict ret,
  24. gfc_array_c4 * const restrict source);
  25. export_proto(transpose_c4);
  26. void
  27. transpose_c4 (gfc_array_c4 * const restrict ret,
  28. gfc_array_c4 * const restrict source)
  29. {
  30. /* r.* indicates the return array. */
  31. index_type rxstride, rystride;
  32. GFC_COMPLEX_4 * restrict rptr;
  33. /* s.* indicates the source array. */
  34. index_type sxstride, systride;
  35. const GFC_COMPLEX_4 *sptr;
  36. index_type xcount, ycount;
  37. index_type x, y;
  38. assert (GFC_DESCRIPTOR_RANK (source) == 2);
  39. if (ret->base_addr == NULL)
  40. {
  41. assert (GFC_DESCRIPTOR_RANK (ret) == 2);
  42. assert (ret->dtype == source->dtype);
  43. GFC_DIMENSION_SET(ret->dim[0], 0, GFC_DESCRIPTOR_EXTENT(source,1) - 1,
  44. 1);
  45. GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
  46. GFC_DESCRIPTOR_EXTENT(source, 1));
  47. ret->base_addr = xmallocarray (size0 ((array_t *) ret),
  48. sizeof (GFC_COMPLEX_4));
  49. ret->offset = 0;
  50. } else if (unlikely (compile_options.bounds_check))
  51. {
  52. index_type ret_extent, src_extent;
  53. ret_extent = GFC_DESCRIPTOR_EXTENT(ret,0);
  54. src_extent = GFC_DESCRIPTOR_EXTENT(source,1);
  55. if (src_extent != ret_extent)
  56. runtime_error ("Incorrect extent in return value of TRANSPOSE"
  57. " intrinsic in dimension 1: is %ld,"
  58. " should be %ld", (long int) src_extent,
  59. (long int) ret_extent);
  60. ret_extent = GFC_DESCRIPTOR_EXTENT(ret,1);
  61. src_extent = GFC_DESCRIPTOR_EXTENT(source,0);
  62. if (src_extent != ret_extent)
  63. runtime_error ("Incorrect extent in return value of TRANSPOSE"
  64. " intrinsic in dimension 2: is %ld,"
  65. " should be %ld", (long int) src_extent,
  66. (long int) ret_extent);
  67. }
  68. sxstride = GFC_DESCRIPTOR_STRIDE(source,0);
  69. systride = GFC_DESCRIPTOR_STRIDE(source,1);
  70. xcount = GFC_DESCRIPTOR_EXTENT(source,0);
  71. ycount = GFC_DESCRIPTOR_EXTENT(source,1);
  72. rxstride = GFC_DESCRIPTOR_STRIDE(ret,0);
  73. rystride = GFC_DESCRIPTOR_STRIDE(ret,1);
  74. rptr = ret->base_addr;
  75. sptr = source->base_addr;
  76. for (y=0; y < ycount; y++)
  77. {
  78. for (x=0; x < xcount; x++)
  79. {
  80. *rptr = *sptr;
  81. sptr += sxstride;
  82. rptr += rystride;
  83. }
  84. sptr += systride - (sxstride * xcount);
  85. rptr += rxstride - (rystride * xcount);
  86. }
  87. }
  88. #endif