minloc1.m4 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. `/* Implementation of the MINLOC intrinsic
  2. Copyright (C) 2002-2015 Free Software Foundation, Inc.
  3. Contributed by Paul Brook <paul@nowt.org>
  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 <stdlib.h>
  22. #include <assert.h>
  23. #include <limits.h>'
  24. include(iparm.m4)dnl
  25. include(ifunction.m4)dnl
  26. `#if defined (HAVE_'atype_name`) && defined (HAVE_'rtype_name`)'
  27. ARRAY_FUNCTION(0,
  28. ` atype_name minval;
  29. #if defined ('atype_inf`)
  30. minval = atype_inf;
  31. #else
  32. minval = atype_max;
  33. #endif
  34. result = 1;',
  35. `#if defined ('atype_nan`)
  36. if (*src <= minval)
  37. {
  38. minval = *src;
  39. result = (rtype_name)n + 1;
  40. break;
  41. }
  42. }
  43. for (; n < len; n++, src += delta)
  44. {
  45. #endif
  46. if (*src < minval)
  47. {
  48. minval = *src;
  49. result = (rtype_name)n + 1;
  50. }')
  51. MASKED_ARRAY_FUNCTION(0,
  52. ` atype_name minval;
  53. #if defined ('atype_inf`)
  54. minval = atype_inf;
  55. #else
  56. minval = atype_max;
  57. #endif
  58. #if defined ('atype_nan`)
  59. rtype_name result2 = 0;
  60. #endif
  61. result = 0;',
  62. ` if (*msrc)
  63. {
  64. #if defined ('atype_nan`)
  65. if (!result2)
  66. result2 = (rtype_name)n + 1;
  67. if (*src <= minval)
  68. #endif
  69. {
  70. minval = *src;
  71. result = (rtype_name)n + 1;
  72. break;
  73. }
  74. }
  75. }
  76. #if defined ('atype_nan`)
  77. if (unlikely (n >= len))
  78. result = result2;
  79. else
  80. #endif
  81. for (; n < len; n++, src += delta, msrc += mdelta)
  82. {
  83. if (*msrc && *src < minval)
  84. {
  85. minval = *src;
  86. result = (rtype_name)n + 1;
  87. }', `')
  88. SCALAR_ARRAY_FUNCTION(0)
  89. #endif