Warning: This file is not a C or C++ file. It does not have highlighting.
1 | //===-- include/flang/Runtime/reduce.h --------------------------*- C++ -*-===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // Defines the API for implementations of the transformational intrinsic |
10 | // function REDUCE(); see F'2023 16.9.173. |
11 | // |
12 | // Similar to the definition of the APIs for SUM(), &c., in reduction.h, |
13 | // there are typed functions here like ReduceInteger4() for total reductions |
14 | // to scalars and void functions like ReduceInteger4Dim() for partial |
15 | // reductions to smaller arrays. |
16 | |
17 | #ifndef FORTRAN_RUNTIME_REDUCE_H_ |
18 | #define FORTRAN_RUNTIME_REDUCE_H_ |
19 | |
20 | #include "flang/Common/float128.h" |
21 | #include "flang/Common/uint128.h" |
22 | #include "flang/Runtime/cpp-type.h" |
23 | #include "flang/Runtime/entry-names.h" |
24 | #include <complex> |
25 | #include <cstdint> |
26 | |
27 | namespace Fortran::runtime { |
28 | |
29 | class Descriptor; |
30 | |
31 | template <typename T> using ReductionOperation = T (*)(const T *, const T *); |
32 | template <typename CHAR> |
33 | using ReductionCharOperation = void (*)(CHAR *hiddenResult, |
34 | std::size_t resultLen, const CHAR *x, const CHAR *y, std::size_t xLen, |
35 | std::size_t yLen); |
36 | using ReductionDerivedTypeOperation = void (*)( |
37 | void *hiddenResult, const void *x, const void *y); |
38 | |
39 | extern "C" { |
40 | |
41 | std::int8_t RTDECL(ReduceInteger1)(const Descriptor &, |
42 | ReductionOperation<std::int8_t>, const char *source, int line, int dim = 0, |
43 | const Descriptor *mask = nullptr, const std::int8_t *identity = nullptr, |
44 | bool ordered = true); |
45 | void RTDECL(ReduceInteger1Dim)(Descriptor &result, const Descriptor &array, |
46 | ReductionOperation<std::int8_t>, const char *source, int line, int dim, |
47 | const Descriptor *mask = nullptr, const std::int8_t *identity = nullptr, |
48 | bool ordered = true); |
49 | std::int16_t RTDECL(ReduceInteger2)(const Descriptor &, |
50 | ReductionOperation<std::int16_t>, const char *source, int line, int dim = 0, |
51 | const Descriptor *mask = nullptr, const std::int16_t *identity = nullptr, |
52 | bool ordered = true); |
53 | void RTDECL(ReduceInteger2Dim)(Descriptor &result, const Descriptor &array, |
54 | ReductionOperation<std::int16_t>, const char *source, int line, int dim, |
55 | const Descriptor *mask = nullptr, const std::int16_t *identity = nullptr, |
56 | bool ordered = true); |
57 | std::int32_t RTDECL(ReduceInteger4)(const Descriptor &, |
58 | ReductionOperation<std::int32_t>, const char *source, int line, int dim = 0, |
59 | const Descriptor *mask = nullptr, const std::int32_t *identity = nullptr, |
60 | bool ordered = true); |
61 | void RTDECL(ReduceInteger4Dim)(Descriptor &result, const Descriptor &array, |
62 | ReductionOperation<std::int32_t>, const char *source, int line, int dim, |
63 | const Descriptor *mask = nullptr, const std::int32_t *identity = nullptr, |
64 | bool ordered = true); |
65 | std::int64_t RTDECL(ReduceInteger8)(const Descriptor &, |
66 | ReductionOperation<std::int64_t>, const char *source, int line, int dim = 0, |
67 | const Descriptor *mask = nullptr, const std::int64_t *identity = nullptr, |
68 | bool ordered = true); |
69 | void RTDECL(ReduceInteger8Dim)(Descriptor &result, const Descriptor &array, |
70 | ReductionOperation<std::int64_t>, const char *source, int line, int dim, |
71 | const Descriptor *mask = nullptr, const std::int64_t *identity = nullptr, |
72 | bool ordered = true); |
73 | #ifdef __SIZEOF_INT128__ |
74 | common::int128_t RTDECL(ReduceInteger16)(const Descriptor &, |
75 | ReductionOperation<common::int128_t>, const char *source, int line, |
76 | int dim = 0, const Descriptor *mask = nullptr, |
77 | const common::int128_t *identity = nullptr, bool ordered = true); |
78 | void RTDECL(ReduceInteger16Dim)(Descriptor &result, const Descriptor &array, |
79 | ReductionOperation<common::int128_t>, const char *source, int line, int dim, |
80 | const Descriptor *mask = nullptr, |
81 | const common::int128_t *identity = nullptr, bool ordered = true); |
82 | #endif |
83 | |
84 | // REAL/COMPLEX(2 & 3) return 32-bit float results for the caller to downconvert |
85 | float RTDECL(ReduceReal2)(const Descriptor &, ReductionOperation<float>, |
86 | const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, |
87 | const float *identity = nullptr, bool ordered = true); |
88 | void RTDECL(ReduceReal2Dim)(Descriptor &result, const Descriptor &array, |
89 | ReductionOperation<float>, const char *source, int line, int dim, |
90 | const Descriptor *mask = nullptr, const float *identity = nullptr, |
91 | bool ordered = true); |
92 | float RTDECL(ReduceReal3)(const Descriptor &, ReductionOperation<float>, |
93 | const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, |
94 | const float *identity = nullptr, bool ordered = true); |
95 | void RTDECL(ReduceReal3Dim)(Descriptor &result, const Descriptor &array, |
96 | ReductionOperation<float>, const char *source, int line, int dim, |
97 | const Descriptor *mask = nullptr, const float *identity = nullptr, |
98 | bool ordered = true); |
99 | float RTDECL(ReduceReal4)(const Descriptor &, ReductionOperation<float>, |
100 | const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, |
101 | const float *identity = nullptr, bool ordered = true); |
102 | void RTDECL(ReduceReal4Dim)(Descriptor &result, const Descriptor &array, |
103 | ReductionOperation<float>, const char *source, int line, int dim, |
104 | const Descriptor *mask = nullptr, const float *identity = nullptr, |
105 | bool ordered = true); |
106 | double RTDECL(ReduceReal8)(const Descriptor &, ReductionOperation<double>, |
107 | const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, |
108 | const double *identity = nullptr, bool ordered = true); |
109 | void RTDECL(ReduceReal8Dim)(Descriptor &result, const Descriptor &array, |
110 | ReductionOperation<double>, const char *source, int line, int dim, |
111 | const Descriptor *mask = nullptr, const double *identity = nullptr, |
112 | bool ordered = true); |
113 | #if LDBL_MANT_DIG == 64 |
114 | long double RTDECL(ReduceReal10)(const Descriptor &, |
115 | ReductionOperation<long double>, const char *source, int line, int dim = 0, |
116 | const Descriptor *mask = nullptr, const long double *identity = nullptr, |
117 | bool ordered = true); |
118 | void RTDECL(ReduceReal10Dim)(Descriptor &result, const Descriptor &array, |
119 | ReductionOperation<long double>, const char *source, int line, int dim, |
120 | const Descriptor *mask = nullptr, const long double *identity = nullptr, |
121 | bool ordered = true); |
122 | #endif |
123 | #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 |
124 | CppFloat128Type RTDECL(ReduceReal16)(const Descriptor &, |
125 | ReductionOperation<CppFloat128Type>, const char *source, int line, |
126 | int dim = 0, const Descriptor *mask = nullptr, |
127 | const CppFloat128Type *identity = nullptr, bool ordered = true); |
128 | void RTDECL(ReduceReal16Dim)(Descriptor &result, const Descriptor &array, |
129 | ReductionOperation<CppFloat128Type>, const char *source, int line, int dim, |
130 | const Descriptor *mask = nullptr, const CppFloat128Type *identity = nullptr, |
131 | bool ordered = true); |
132 | #endif |
133 | |
134 | void RTDECL(CppReduceComplex2)(std::complex<float> &, const Descriptor &, |
135 | ReductionOperation<std::complex<float>>, const char *source, int line, |
136 | int dim = 0, const Descriptor *mask = nullptr, |
137 | const std::complex<float> *identity = nullptr, bool ordered = true); |
138 | void RTDECL(CppReduceComplex2Dim)(Descriptor &result, const Descriptor &array, |
139 | ReductionOperation<std::complex<float>>, const char *source, int line, |
140 | int dim, const Descriptor *mask = nullptr, |
141 | const std::complex<float> *identity = nullptr, bool ordered = true); |
142 | void RTDECL(CppReduceComplex3)(std::complex<float> &, const Descriptor &, |
143 | ReductionOperation<std::complex<float>>, const char *source, int line, |
144 | int dim = 0, const Descriptor *mask = nullptr, |
145 | const std::complex<float> *identity = nullptr, bool ordered = true); |
146 | void RTDECL(CppReduceComplex3Dim)(Descriptor &result, const Descriptor &array, |
147 | ReductionOperation<std::complex<float>>, const char *source, int line, |
148 | int dim, const Descriptor *mask = nullptr, |
149 | const std::complex<float> *identity = nullptr, bool ordered = true); |
150 | void RTDECL(CppReduceComplex4)(std::complex<float> &, const Descriptor &, |
151 | ReductionOperation<std::complex<float>>, const char *source, int line, |
152 | int dim = 0, const Descriptor *mask = nullptr, |
153 | const std::complex<float> *identity = nullptr, bool ordered = true); |
154 | void RTDECL(CppReduceComplex4Dim)(Descriptor &result, const Descriptor &array, |
155 | ReductionOperation<std::complex<float>>, const char *source, int line, |
156 | int dim, const Descriptor *mask = nullptr, |
157 | const std::complex<float> *identity = nullptr, bool ordered = true); |
158 | void RTDECL(CppReduceComplex8)(std::complex<double> &, const Descriptor &, |
159 | ReductionOperation<std::complex<double>>, const char *source, int line, |
160 | int dim = 0, const Descriptor *mask = nullptr, |
161 | const std::complex<double> *identity = nullptr, bool ordered = true); |
162 | void RTDECL(CppReduceComplex8Dim)(Descriptor &result, const Descriptor &array, |
163 | ReductionOperation<std::complex<double>>, const char *source, int line, |
164 | int dim, const Descriptor *mask = nullptr, |
165 | const std::complex<double> *identity = nullptr, bool ordered = true); |
166 | #if LDBL_MANT_DIG == 64 |
167 | void RTDECL(CppReduceComplex10)(std::complex<long double> &, const Descriptor &, |
168 | ReductionOperation<std::complex<long double>>, const char *source, int line, |
169 | int dim = 0, const Descriptor *mask = nullptr, |
170 | const std::complex<long double> *identity = nullptr, bool ordered = true); |
171 | void RTDECL(CppReduceComplex10Dim)(Descriptor &result, const Descriptor &array, |
172 | ReductionOperation<std::complex<long double>>, const char *source, int line, |
173 | int dim, const Descriptor *mask = nullptr, |
174 | const std::complex<long double> *identity = nullptr, bool ordered = true); |
175 | #endif |
176 | #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 |
177 | void RTDECL(CppReduceComplex16)(std::complex<CppFloat128Type> &, |
178 | const Descriptor &, ReductionOperation<std::complex<CppFloat128Type>>, |
179 | const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, |
180 | const std::complex<CppFloat128Type> *identity = nullptr, |
181 | bool ordered = true); |
182 | void RTDECL(CppReduceComplex16Dim)(Descriptor &result, const Descriptor &array, |
183 | ReductionOperation<std::complex<CppFloat128Type>>, const char *source, |
184 | int line, int dim, const Descriptor *mask = nullptr, |
185 | const std::complex<CppFloat128Type> *identity = nullptr, |
186 | bool ordered = true); |
187 | #endif |
188 | |
189 | bool RTDECL(ReduceLogical1)(const Descriptor &, ReductionOperation<std::int8_t>, |
190 | const char *source, int line, int dim = 0, const Descriptor *mask = nullptr, |
191 | const std::int8_t *identity = nullptr, bool ordered = true); |
192 | void RTDECL(ReduceLogical1Dim)(Descriptor &result, const Descriptor &array, |
193 | ReductionOperation<std::int8_t>, const char *source, int line, int dim, |
194 | const Descriptor *mask = nullptr, const std::int8_t *identity = nullptr, |
195 | bool ordered = true); |
196 | bool RTDECL(ReduceLogical2)(const Descriptor &, |
197 | ReductionOperation<std::int16_t>, const char *source, int line, int dim = 0, |
198 | const Descriptor *mask = nullptr, const std::int16_t *identity = nullptr, |
199 | bool ordered = true); |
200 | void RTDECL(ReduceLogical2Dim)(Descriptor &result, const Descriptor &array, |
201 | ReductionOperation<std::int16_t>, const char *source, int line, int dim, |
202 | const Descriptor *mask = nullptr, const std::int16_t *identity = nullptr, |
203 | bool ordered = true); |
204 | bool RTDECL(ReduceLogical4)(const Descriptor &, |
205 | ReductionOperation<std::int32_t>, const char *source, int line, int dim = 0, |
206 | const Descriptor *mask = nullptr, const std::int32_t *identity = nullptr, |
207 | bool ordered = true); |
208 | void RTDECL(ReduceLogical4Dim)(Descriptor &result, const Descriptor &array, |
209 | ReductionOperation<std::int32_t>, const char *source, int line, int dim, |
210 | const Descriptor *mask = nullptr, const std::int32_t *identity = nullptr, |
211 | bool ordered = true); |
212 | bool RTDECL(ReduceLogical8)(const Descriptor &, |
213 | ReductionOperation<std::int64_t>, const char *source, int line, int dim = 0, |
214 | const Descriptor *mask = nullptr, const std::int64_t *identity = nullptr, |
215 | bool ordered = true); |
216 | void RTDECL(ReduceLogical8Dim)(Descriptor &result, const Descriptor &array, |
217 | ReductionOperation<std::int64_t>, const char *source, int line, int dim, |
218 | const Descriptor *mask = nullptr, const std::int64_t *identity = nullptr, |
219 | bool ordered = true); |
220 | |
221 | void RTDECL(ReduceChar1)(char *result, const Descriptor &array, |
222 | ReductionCharOperation<char>, const char *source, int line, int dim = 0, |
223 | const Descriptor *mask = nullptr, const char *identity = nullptr, |
224 | bool ordered = true); |
225 | void RTDECL(ReduceCharacter1Dim)(Descriptor &result, const Descriptor &array, |
226 | ReductionCharOperation<char>, const char *source, int line, int dim, |
227 | const Descriptor *mask = nullptr, const char *identity = nullptr, |
228 | bool ordered = true); |
229 | void RTDECL(ReduceChar2)(char16_t *result, const Descriptor &array, |
230 | ReductionCharOperation<char16_t>, const char *source, int line, int dim = 0, |
231 | const Descriptor *mask = nullptr, const char16_t *identity = nullptr, |
232 | bool ordered = true); |
233 | void RTDECL(ReduceCharacter2Dim)(Descriptor &result, const Descriptor &array, |
234 | ReductionCharOperation<char16_t>, const char *source, int line, int dim, |
235 | const Descriptor *mask = nullptr, const char16_t *identity = nullptr, |
236 | bool ordered = true); |
237 | void RTDECL(ReduceChar4)(char32_t *result, const Descriptor &array, |
238 | ReductionCharOperation<char32_t>, const char *source, int line, int dim = 0, |
239 | const Descriptor *mask = nullptr, const char32_t *identity = nullptr, |
240 | bool ordered = true); |
241 | void RTDECL(ReduceCharacter4Dim)(Descriptor &result, const Descriptor &array, |
242 | ReductionCharOperation<char32_t>, const char *source, int line, int dim, |
243 | const Descriptor *mask = nullptr, const char32_t *identity = nullptr, |
244 | bool ordered = true); |
245 | |
246 | void RTDECL(ReduceDerivedType)(char *result, const Descriptor &array, |
247 | ReductionDerivedTypeOperation, const char *source, int line, int dim = 0, |
248 | const Descriptor *mask = nullptr, const char *identity = nullptr, |
249 | bool ordered = true); |
250 | void RTDECL(ReduceDerivedTypeDim)(Descriptor &result, const Descriptor &array, |
251 | ReductionDerivedTypeOperation, const char *source, int line, int dim, |
252 | const Descriptor *mask = nullptr, const char *identity = nullptr, |
253 | bool ordered = true); |
254 | |
255 | } // extern "C" |
256 | } // namespace Fortran::runtime |
257 | #endif // FORTRAN_RUNTIME_REDUCE_H_ |
258 |
Warning: This file is not a C or C++ file. It does not have highlighting.