[libc++][Android] Allow testing libc++ with clang-r536225 (#116149)
[llvm-project.git] / flang / runtime / complex-reduction.h
blob5ff2a828fb3eccb4843e16790801fe0172c59af3
1 /*===-- flang/runtime/complex-reduction.h ---------------------------*- C -*-===
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
7 * ===-----------------------------------------------------------------------===
8 */
10 /* Wraps the C++-coded complex-valued SUM and PRODUCT reductions with
11 * C-coded wrapper functions returning _Complex values, to avoid problems
12 * with C++ build compilers that don't support C's _Complex.
15 #ifndef FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
16 #define FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
18 #include "flang/Common/float128.h"
19 #include "flang/Runtime/entry-names.h"
20 #include <complex.h>
22 struct CppDescriptor; /* dummy type name for Fortran::runtime::Descriptor */
24 #if defined(_MSC_VER) && !(defined(__clang_major__) && __clang_major__ >= 12)
25 typedef _Fcomplex float_Complex_t;
26 typedef _Dcomplex double_Complex_t;
27 typedef _Lcomplex long_double_Complex_t;
28 #else
29 typedef float _Complex float_Complex_t;
30 typedef double _Complex double_Complex_t;
31 typedef long double _Complex long_double_Complex_t;
32 #endif
34 #define REDUCTION_ARGS \
35 const struct CppDescriptor *x, const char *source, int line, int dim /*=0*/, \
36 const struct CppDescriptor *mask /*=NULL*/
37 #define REDUCTION_ARG_NAMES x, source, line, dim, mask
39 float_Complex_t RTNAME(SumComplex2)(REDUCTION_ARGS);
40 float_Complex_t RTNAME(SumComplex3)(REDUCTION_ARGS);
41 float_Complex_t RTNAME(SumComplex4)(REDUCTION_ARGS);
42 double_Complex_t RTNAME(SumComplex8)(REDUCTION_ARGS);
43 long_double_Complex_t RTNAME(SumComplex10)(REDUCTION_ARGS);
44 #if HAS_LDBL128 || HAS_FLOAT128
45 CFloat128ComplexType RTNAME(SumComplex16)(REDUCTION_ARGS);
46 #endif
48 float_Complex_t RTNAME(ProductComplex2)(REDUCTION_ARGS);
49 float_Complex_t RTNAME(ProductComplex3)(REDUCTION_ARGS);
50 float_Complex_t RTNAME(ProductComplex4)(REDUCTION_ARGS);
51 double_Complex_t RTNAME(ProductComplex8)(REDUCTION_ARGS);
52 long_double_Complex_t RTNAME(ProductComplex10)(REDUCTION_ARGS);
53 #if HAS_LDBL128 || HAS_FLOAT128
54 CFloat128ComplexType RTNAME(ProductComplex16)(REDUCTION_ARGS);
55 #endif
57 #define DOT_PRODUCT_ARGS \
58 const struct CppDescriptor *x, const struct CppDescriptor *y, \
59 const char *source, int line, int dim /*=0*/, \
60 const struct CppDescriptor *mask /*=NULL*/
61 #define DOT_PRODUCT_ARG_NAMES x, y, source, line, dim, mask
63 float_Complex_t RTNAME(DotProductComplex2)(DOT_PRODUCT_ARGS);
64 float_Complex_t RTNAME(DotProductComplex3)(DOT_PRODUCT_ARGS);
65 float_Complex_t RTNAME(DotProductComplex4)(DOT_PRODUCT_ARGS);
66 double_Complex_t RTNAME(DotProductComplex8)(DOT_PRODUCT_ARGS);
67 long_double_Complex_t RTNAME(DotProductComplex10)(DOT_PRODUCT_ARGS);
68 #if HAS_LDBL128 || HAS_FLOAT128
69 CFloat128ComplexType RTNAME(DotProductComplex16)(DOT_PRODUCT_ARGS);
70 #endif
72 #define REDUCE_ARGS(T, OP) \
73 OP operation, const struct CppDescriptor *x, const struct CppDescriptor *y, \
74 const char *source, int line, int dim /*=0*/, \
75 const struct CppDescriptor *mask /*=NULL*/, const T *identity /*=NULL*/, \
76 _Bool ordered /*=true*/
77 #define REDUCE_ARG_NAMES \
78 operation, x, y, source, line, dim, mask, identity, ordered
80 typedef float_Complex_t (*float_Complex_t_ref_op)(
81 const float_Complex_t *, const float_Complex_t *);
82 typedef float_Complex_t (*float_Complex_t_value_op)(
83 float_Complex_t, float_Complex_t);
84 typedef double_Complex_t (*double_Complex_t_ref_op)(
85 const double_Complex_t *, const double_Complex_t *);
86 typedef double_Complex_t (*double_Complex_t_value_op)(
87 double_Complex_t, double_Complex_t);
88 typedef long_double_Complex_t (*long_double_Complex_t_ref_op)(
89 const long_double_Complex_t *, const long_double_Complex_t *);
90 typedef long_double_Complex_t (*long_double_Complex_t_value_op)(
91 long_double_Complex_t, long_double_Complex_t);
93 float_Complex_t RTNAME(ReduceComplex2Ref)(
94 REDUCE_ARGS(float_Complex_t, float_Complex_t_ref_op));
95 float_Complex_t RTNAME(ReduceComplex2Value)(
96 REDUCE_ARGS(float_Complex_t, float_Complex_t_value_op));
97 float_Complex_t RTNAME(ReduceComplex3Ref)(
98 REDUCE_ARGS(float_Complex_t, float_Complex_t_ref_op));
99 float_Complex_t RTNAME(ReduceComplex3Value)(
100 REDUCE_ARGS(float_Complex_t, float_Complex_t_value_op));
101 float_Complex_t RTNAME(ReduceComplex4Ref)(
102 REDUCE_ARGS(float_Complex_t, float_Complex_t_ref_op));
103 float_Complex_t RTNAME(ReduceComplex4Value)(
104 REDUCE_ARGS(float_Complex_t, float_Complex_t_value_op));
105 double_Complex_t RTNAME(ReduceComplex8Ref)(
106 REDUCE_ARGS(double_Complex_t, double_Complex_t_ref_op));
107 double_Complex_t RTNAME(ReduceComplex8Value)(
108 REDUCE_ARGS(double_Complex_t, double_Complex_t_value_op));
109 long_double_Complex_t RTNAME(ReduceComplex10Ref)(
110 REDUCE_ARGS(long_double_Complex_t, long_double_Complex_t_ref_op));
111 long_double_Complex_t RTNAME(ReduceComplex10Value)(
112 REDUCE_ARGS(long_double_Complex_t, long_double_Complex_t_value_op));
113 #if HAS_LDBL128 || HAS_FLOAT128
114 typedef CFloat128ComplexType (*CFloat128ComplexType_ref_op)(
115 const CFloat128ComplexType *, const CFloat128ComplexType *);
116 typedef CFloat128ComplexType (*CFloat128ComplexType_value_op)(
117 CFloat128ComplexType, CFloat128ComplexType);
118 CFloat128ComplexType RTNAME(ReduceComplex16Ref)(
119 REDUCE_ARGS(CFloat128ComplexType, CFloat128ComplexType_ref_op));
120 CFloat128ComplexType RTNAME(ReduceComplex16Value)(
121 REDUCE_ARGS(CFloat128ComplexType, CFloat128ComplexType_value_op));
122 #endif
124 #define REDUCE_DIM_ARGS(T, OP) \
125 struct CppDescriptor *result, OP operation, const struct CppDescriptor *x, \
126 const struct CppDescriptor *y, const char *source, int line, int dim, \
127 const struct CppDescriptor *mask /*=NULL*/, const T *identity /*=NULL*/, \
128 _Bool ordered /*=true*/
129 #define REDUCE_DIM_ARG_NAMES \
130 result, operation, x, y, source, line, dim, mask, identity, ordered
132 void RTNAME(ReduceComplex2DimRef)(
133 REDUCE_DIM_ARGS(float_Complex_t, float_Complex_t_ref_op));
134 void RTNAME(ReduceComplex2DimValue)(
135 REDUCE_DIM_ARGS(float_Complex_t, float_Complex_t_value_op));
136 void RTNAME(ReduceComplex3DimRef)(
137 REDUCE_DIM_ARGS(float_Complex_t, float_Complex_t_ref_op));
138 void RTNAME(ReduceComplex3DimValue)(
139 REDUCE_DIM_ARGS(float_Complex_t, float_Complex_t_value_op));
140 void RTNAME(ReduceComplex4DimRef)(
141 REDUCE_DIM_ARGS(float_Complex_t, float_Complex_t_ref_op));
142 void RTNAME(ReduceComplex4DimValue)(
143 REDUCE_DIM_ARGS(float_Complex_t, float_Complex_t_value_op));
144 void RTNAME(ReduceComplex8DimRef)(
145 REDUCE_DIM_ARGS(double_Complex_t, double_Complex_t_ref_op));
146 void RTNAME(ReduceComplex8DimValue)(
147 REDUCE_DIM_ARGS(double_Complex_t, double_Complex_t_value_op));
148 void RTNAME(ReduceComplex10DimRef)(
149 REDUCE_DIM_ARGS(long_double_Complex_t, long_double_Complex_t_ref_op));
150 void RTNAME(ReduceComplex10DimValue)(
151 REDUCE_DIM_ARGS(long_double_Complex_t, long_double_Complex_t_value_op));
152 #if HAS_LDBL128 || HAS_FLOAT128
153 void RTNAME(ReduceComplex16DimRef)(
154 REDUCE_DIM_ARGS(CFloat128ComplexType, CFloat128ComplexType_ref_op));
155 void RTNAME(ReduceComplex16DimValue)(
156 REDUCE_DIM_ARGS(CFloat128ComplexType, CFloat128ComplexType_value_op));
157 #endif
159 #endif // FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_