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 | |
22 | struct CppDescriptor; /* dummy type name for Fortran::runtime::Descriptor */ |
23 | |
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 |
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 | |
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 LDBL_MANT_DIG == 113 || HAS_FLOAT128 |
45 | CFloat128ComplexType RTNAME(SumComplex16)(REDUCTION_ARGS); |
46 | #endif |
47 | |
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 LDBL_MANT_DIG == 113 || HAS_FLOAT128 |
54 | CFloat128ComplexType 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 | |
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 LDBL_MANT_DIG == 113 || HAS_FLOAT128 |
69 | CFloat128ComplexType 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 | |
80 | typedef float_Complex_t (*float_Complex_t_op)( |
81 | const float_Complex_t *, const float_Complex_t *); |
82 | typedef double_Complex_t (*double_Complex_t_op)( |
83 | const double_Complex_t *, const double_Complex_t *); |
84 | typedef long_double_Complex_t (*long_double_Complex_t_op)( |
85 | const long_double_Complex_t *, const long_double_Complex_t *); |
86 | |
87 | float_Complex_t RTNAME(ReduceComplex2)(REDUCE_ARGS(float_Complex_t)); |
88 | float_Complex_t RTNAME(ReduceComplex3)(REDUCE_ARGS(float_Complex_t)); |
89 | float_Complex_t RTNAME(ReduceComplex4)(REDUCE_ARGS(float_Complex_t)); |
90 | double_Complex_t RTNAME(ReduceComplex8)(REDUCE_ARGS(double_Complex_t)); |
91 | long_double_Complex_t RTNAME(ReduceComplex10)( |
92 | REDUCE_ARGS(long_double_Complex_t)); |
93 | #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 |
94 | typedef CFloat128ComplexType (*CFloat128ComplexType_op)( |
95 | const CFloat128ComplexType *, const CFloat128ComplexType *); |
96 | CFloat128ComplexType 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 | |
108 | void RTNAME(ReduceComplex2Dim)(REDUCE_DIM_ARGS(float_Complex_t)); |
109 | void RTNAME(ReduceComplex3Dim)(REDUCE_DIM_ARGS(float_Complex_t)); |
110 | void RTNAME(ReduceComplex4Dim)(REDUCE_DIM_ARGS(float_Complex_t)); |
111 | void RTNAME(ReduceComplex8Dim)(REDUCE_DIM_ARGS(double_Complex_t)); |
112 | void RTNAME(ReduceComplex10Dim)(REDUCE_DIM_ARGS(long_double_Complex_t)); |
113 | #if LDBL_MANT_DIG == 113 || HAS_FLOAT128 |
114 | void RTNAME(ReduceComplex16Dim)(REDUCE_DIM_ARGS(CFloat128ComplexType)); |
115 | #endif |
116 | |
117 | #endif // FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_ |
118 | |