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

source code of flang-rt/lib/runtime/complex-reduction.h