1/*===-- flang/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
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.
13 */
14
15#ifndef FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
16#define FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
17
18#include "flang/Common/float128.h"
19#include "flang/Runtime/entry-names.h"
20#include <complex.h>
21
22struct CppDescriptor; /* dummy type name for Fortran::runtime::Descriptor */
23
24#if defined(_MSC_VER) && !(defined(__clang_major__) && __clang_major__ >= 12)
25typedef _Fcomplex float_Complex_t;
26typedef _Dcomplex double_Complex_t;
27typedef _Lcomplex long_double_Complex_t;
28#else
29typedef float _Complex float_Complex_t;
30typedef double _Complex double_Complex_t;
31typedef long double _Complex long_double_Complex_t;
32#endif
33
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
38
39float_Complex_t RTNAME(SumComplex2)(REDUCTION_ARGS);
40float_Complex_t RTNAME(SumComplex3)(REDUCTION_ARGS);
41float_Complex_t RTNAME(SumComplex4)(REDUCTION_ARGS);
42double_Complex_t RTNAME(SumComplex8)(REDUCTION_ARGS);
43long_double_Complex_t RTNAME(SumComplex10)(REDUCTION_ARGS);
44#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
45CFloat128ComplexType RTNAME(SumComplex16)(REDUCTION_ARGS);
46#endif
47
48float_Complex_t RTNAME(ProductComplex2)(REDUCTION_ARGS);
49float_Complex_t RTNAME(ProductComplex3)(REDUCTION_ARGS);
50float_Complex_t RTNAME(ProductComplex4)(REDUCTION_ARGS);
51double_Complex_t RTNAME(ProductComplex8)(REDUCTION_ARGS);
52long_double_Complex_t RTNAME(ProductComplex10)(REDUCTION_ARGS);
53#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
54CFloat128ComplexType RTNAME(ProductComplex16)(REDUCTION_ARGS);
55#endif
56
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
62
63float_Complex_t RTNAME(DotProductComplex2)(DOT_PRODUCT_ARGS);
64float_Complex_t RTNAME(DotProductComplex3)(DOT_PRODUCT_ARGS);
65float_Complex_t RTNAME(DotProductComplex4)(DOT_PRODUCT_ARGS);
66double_Complex_t RTNAME(DotProductComplex8)(DOT_PRODUCT_ARGS);
67long_double_Complex_t RTNAME(DotProductComplex10)(DOT_PRODUCT_ARGS);
68#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
69CFloat128ComplexType RTNAME(DotProductComplex16)(DOT_PRODUCT_ARGS);
70#endif
71
72#define REDUCE_ARGS(T) \
73 T##_op operation, const struct CppDescriptor *x, \
74 const struct CppDescriptor *y, const char *source, int line, \
75 int dim /*=0*/, const struct CppDescriptor *mask /*=NULL*/, \
76 const T *identity /*=NULL*/, _Bool ordered /*=true*/
77#define REDUCE_ARG_NAMES \
78 operation, x, y, source, line, dim, mask, identity, ordered
79
80typedef float_Complex_t (*float_Complex_t_op)(
81 const float_Complex_t *, const float_Complex_t *);
82typedef double_Complex_t (*double_Complex_t_op)(
83 const double_Complex_t *, const double_Complex_t *);
84typedef long_double_Complex_t (*long_double_Complex_t_op)(
85 const long_double_Complex_t *, const long_double_Complex_t *);
86
87float_Complex_t RTNAME(ReduceComplex2)(REDUCE_ARGS(float_Complex_t));
88float_Complex_t RTNAME(ReduceComplex3)(REDUCE_ARGS(float_Complex_t));
89float_Complex_t RTNAME(ReduceComplex4)(REDUCE_ARGS(float_Complex_t));
90double_Complex_t RTNAME(ReduceComplex8)(REDUCE_ARGS(double_Complex_t));
91long_double_Complex_t RTNAME(ReduceComplex10)(
92 REDUCE_ARGS(long_double_Complex_t));
93#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
94typedef CFloat128ComplexType (*CFloat128ComplexType_op)(
95 const CFloat128ComplexType *, const CFloat128ComplexType *);
96CFloat128ComplexType RTNAME(ReduceComplex16)(REDUCE_ARGS(CFloat128ComplexType));
97#endif
98
99#define REDUCE_DIM_ARGS(T) \
100 struct CppDescriptor *result, T##_op operation, \
101 const struct CppDescriptor *x, const struct CppDescriptor *y, \
102 const char *source, int line, int dim, \
103 const struct CppDescriptor *mask /*=NULL*/, const T *identity /*=NULL*/, \
104 _Bool ordered /*=true*/
105#define REDUCE_DIM_ARG_NAMES \
106 result, operation, x, y, source, line, dim, mask, identity, ordered
107
108void RTNAME(ReduceComplex2Dim)(REDUCE_DIM_ARGS(float_Complex_t));
109void RTNAME(ReduceComplex3Dim)(REDUCE_DIM_ARGS(float_Complex_t));
110void RTNAME(ReduceComplex4Dim)(REDUCE_DIM_ARGS(float_Complex_t));
111void RTNAME(ReduceComplex8Dim)(REDUCE_DIM_ARGS(double_Complex_t));
112void RTNAME(ReduceComplex10Dim)(REDUCE_DIM_ARGS(long_double_Complex_t));
113#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
114void RTNAME(ReduceComplex16Dim)(REDUCE_DIM_ARGS(CFloat128ComplexType));
115#endif
116
117#endif // FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
118

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