xref: /netbsd-src/external/gpl3/gcc.old/dist/libgfortran/m4/minval.m4 (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1627f7eb2Smrg`/* Implementation of the MINVAL intrinsic
2*4c3eb207Smrg   Copyright (C) 2002-2020 Free Software Foundation, Inc.
3627f7eb2Smrg   Contributed by Paul Brook <paul@nowt.org>
4627f7eb2Smrg
5627f7eb2SmrgThis file is part of the GNU Fortran runtime library (libgfortran).
6627f7eb2Smrg
7627f7eb2SmrgLibgfortran is free software; you can redistribute it and/or
8627f7eb2Smrgmodify it under the terms of the GNU General Public
9627f7eb2SmrgLicense as published by the Free Software Foundation; either
10627f7eb2Smrgversion 3 of the License, or (at your option) any later version.
11627f7eb2Smrg
12627f7eb2SmrgLibgfortran is distributed in the hope that it will be useful,
13627f7eb2Smrgbut WITHOUT ANY WARRANTY; without even the implied warranty of
14627f7eb2SmrgMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15627f7eb2SmrgGNU General Public License for more details.
16627f7eb2Smrg
17627f7eb2SmrgUnder Section 7 of GPL version 3, you are granted additional
18627f7eb2Smrgpermissions described in the GCC Runtime Library Exception, version
19627f7eb2Smrg3.1, as published by the Free Software Foundation.
20627f7eb2Smrg
21627f7eb2SmrgYou should have received a copy of the GNU General Public License and
22627f7eb2Smrga copy of the GCC Runtime Library Exception along with this program;
23627f7eb2Smrgsee the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24627f7eb2Smrg<http://www.gnu.org/licenses/>.  */
25627f7eb2Smrg
26627f7eb2Smrg#include "libgfortran.h"'
27627f7eb2Smrg
28627f7eb2Smrginclude(iparm.m4)dnl
29627f7eb2Smrginclude(ifunction.m4)dnl
30627f7eb2Smrg
31627f7eb2Smrg`#if defined (HAVE_'atype_name`) && defined (HAVE_'rtype_name`)'
32627f7eb2Smrg
33627f7eb2SmrgARRAY_FUNCTION(atype_max,
34627f7eb2Smrg`#if defined ('atype_inf`)
35627f7eb2Smrg	result = atype_inf;
36627f7eb2Smrg#else
37627f7eb2Smrg	result = atype_max;
38627f7eb2Smrg#endif',
39627f7eb2Smrg`#if defined ('atype_nan`)
40627f7eb2Smrg		if (*src <= result)
41627f7eb2Smrg		  break;
42627f7eb2Smrg	      }
43627f7eb2Smrg	    if (unlikely (n >= len))
44627f7eb2Smrg	      result = atype_nan;
45627f7eb2Smrg	    else for (; n < len; n++, src += delta)
46627f7eb2Smrg	      {
47627f7eb2Smrg#endif
48627f7eb2Smrg		if (*src < result)
49627f7eb2Smrg		  result = *src;')
50627f7eb2Smrg
51627f7eb2SmrgMASKED_ARRAY_FUNCTION(atype_max,
52627f7eb2Smrg`#if defined ('atype_inf`)
53627f7eb2Smrg	result = atype_inf;
54627f7eb2Smrg#else
55627f7eb2Smrg	result = atype_max;
56627f7eb2Smrg#endif
57627f7eb2Smrg#if defined ('atype_nan`)
58627f7eb2Smrg	int non_empty_p = 0;
59627f7eb2Smrg#endif',
60627f7eb2Smrg`#if defined ('atype_inf`) || defined ('atype_nan`)
61627f7eb2Smrg		if (*msrc)
62627f7eb2Smrg		  {
63627f7eb2Smrg#if defined ('atype_nan`)
64627f7eb2Smrg		    non_empty_p = 1;
65627f7eb2Smrg		    if (*src <= result)
66627f7eb2Smrg#endif
67627f7eb2Smrg		      break;
68627f7eb2Smrg		  }
69627f7eb2Smrg	      }
70627f7eb2Smrg	    if (unlikely (n >= len))
71627f7eb2Smrg	      {
72627f7eb2Smrg#if defined ('atype_nan`)
73627f7eb2Smrg		result = non_empty_p ? atype_nan : atype_max;
74627f7eb2Smrg#else
75627f7eb2Smrg		result = atype_max;
76627f7eb2Smrg#endif
77627f7eb2Smrg	      }
78627f7eb2Smrg	    else for (; n < len; n++, src += delta, msrc += mdelta)
79627f7eb2Smrg	      {
80627f7eb2Smrg#endif
81627f7eb2Smrg		if (*msrc && *src < result)
82627f7eb2Smrg		  result = *src;', `')
83627f7eb2Smrg
84627f7eb2SmrgSCALAR_ARRAY_FUNCTION(atype_max)
85627f7eb2Smrg
86627f7eb2Smrg#endif
87