| 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 | |
| 21 | struct CppDescriptor; /* dummy type name for Fortran::runtime::Descriptor */ |
| 22 | |
| 23 | #if defined(_MSC_VER) && !(defined(__clang_major__) && __clang_major__ >= 12) |
| 24 | typedef _Fcomplex float_Complex_t; |
| 25 | typedef _Dcomplex double_Complex_t; |
| 26 | typedef _Lcomplex long_double_Complex_t; |
| 27 | #else |
| 28 | typedef float _Complex float_Complex_t; |
| 29 | typedef double _Complex double_Complex_t; |
| 30 | typedef 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 | |
| 38 | float_Complex_t RTNAME(SumComplex2)(REDUCTION_ARGS); |
| 39 | float_Complex_t RTNAME(SumComplex3)(REDUCTION_ARGS); |
| 40 | float_Complex_t RTNAME(SumComplex4)(REDUCTION_ARGS); |
| 41 | double_Complex_t RTNAME(SumComplex8)(REDUCTION_ARGS); |
| 42 | long_double_Complex_t RTNAME(SumComplex10)(REDUCTION_ARGS); |
| 43 | #if HAS_LDBL128 || HAS_FLOAT128 |
| 44 | CFloat128ComplexType RTNAME(SumComplex16)(REDUCTION_ARGS); |
| 45 | #endif |
| 46 | |
| 47 | float_Complex_t RTNAME(ProductComplex2)(REDUCTION_ARGS); |
| 48 | float_Complex_t RTNAME(ProductComplex3)(REDUCTION_ARGS); |
| 49 | float_Complex_t RTNAME(ProductComplex4)(REDUCTION_ARGS); |
| 50 | double_Complex_t RTNAME(ProductComplex8)(REDUCTION_ARGS); |
| 51 | long_double_Complex_t RTNAME(ProductComplex10)(REDUCTION_ARGS); |
| 52 | #if HAS_LDBL128 || HAS_FLOAT128 |
| 53 | CFloat128ComplexType 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 | |
| 62 | float_Complex_t RTNAME(DotProductComplex2)(DOT_PRODUCT_ARGS); |
| 63 | float_Complex_t RTNAME(DotProductComplex3)(DOT_PRODUCT_ARGS); |
| 64 | float_Complex_t RTNAME(DotProductComplex4)(DOT_PRODUCT_ARGS); |
| 65 | double_Complex_t RTNAME(DotProductComplex8)(DOT_PRODUCT_ARGS); |
| 66 | long_double_Complex_t RTNAME(DotProductComplex10)(DOT_PRODUCT_ARGS); |
| 67 | #if HAS_LDBL128 || HAS_FLOAT128 |
| 68 | CFloat128ComplexType 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 | |
| 79 | typedef float_Complex_t (*float_Complex_t_ref_op)( |
| 80 | const float_Complex_t *, const float_Complex_t *); |
| 81 | typedef float_Complex_t (*float_Complex_t_value_op)( |
| 82 | float_Complex_t, float_Complex_t); |
| 83 | typedef double_Complex_t (*double_Complex_t_ref_op)( |
| 84 | const double_Complex_t *, const double_Complex_t *); |
| 85 | typedef double_Complex_t (*double_Complex_t_value_op)( |
| 86 | double_Complex_t, double_Complex_t); |
| 87 | typedef long_double_Complex_t (*long_double_Complex_t_ref_op)( |
| 88 | const long_double_Complex_t *, const long_double_Complex_t *); |
| 89 | typedef long_double_Complex_t (*long_double_Complex_t_value_op)( |
| 90 | long_double_Complex_t, long_double_Complex_t); |
| 91 | |
| 92 | float_Complex_t RTNAME(ReduceComplex2Ref)( |
| 93 | REDUCE_ARGS(float_Complex_t, float_Complex_t_ref_op)); |
| 94 | float_Complex_t RTNAME(ReduceComplex2Value)( |
| 95 | REDUCE_ARGS(float_Complex_t, float_Complex_t_value_op)); |
| 96 | float_Complex_t RTNAME(ReduceComplex3Ref)( |
| 97 | REDUCE_ARGS(float_Complex_t, float_Complex_t_ref_op)); |
| 98 | float_Complex_t RTNAME(ReduceComplex3Value)( |
| 99 | REDUCE_ARGS(float_Complex_t, float_Complex_t_value_op)); |
| 100 | float_Complex_t RTNAME(ReduceComplex4Ref)( |
| 101 | REDUCE_ARGS(float_Complex_t, float_Complex_t_ref_op)); |
| 102 | float_Complex_t RTNAME(ReduceComplex4Value)( |
| 103 | REDUCE_ARGS(float_Complex_t, float_Complex_t_value_op)); |
| 104 | double_Complex_t RTNAME(ReduceComplex8Ref)( |
| 105 | REDUCE_ARGS(double_Complex_t, double_Complex_t_ref_op)); |
| 106 | double_Complex_t RTNAME(ReduceComplex8Value)( |
| 107 | REDUCE_ARGS(double_Complex_t, double_Complex_t_value_op)); |
| 108 | long_double_Complex_t RTNAME(ReduceComplex10Ref)( |
| 109 | REDUCE_ARGS(long_double_Complex_t, long_double_Complex_t_ref_op)); |
| 110 | long_double_Complex_t RTNAME(ReduceComplex10Value)( |
| 111 | REDUCE_ARGS(long_double_Complex_t, long_double_Complex_t_value_op)); |
| 112 | #if HAS_LDBL128 || HAS_FLOAT128 |
| 113 | typedef CFloat128ComplexType (*CFloat128ComplexType_ref_op)( |
| 114 | const CFloat128ComplexType *, const CFloat128ComplexType *); |
| 115 | typedef CFloat128ComplexType (*CFloat128ComplexType_value_op)( |
| 116 | CFloat128ComplexType, CFloat128ComplexType); |
| 117 | CFloat128ComplexType RTNAME(ReduceComplex16Ref)( |
| 118 | REDUCE_ARGS(CFloat128ComplexType, CFloat128ComplexType_ref_op)); |
| 119 | CFloat128ComplexType 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 | |
| 131 | void RTNAME(ReduceComplex2DimRef)( |
| 132 | REDUCE_DIM_ARGS(float_Complex_t, float_Complex_t_ref_op)); |
| 133 | void RTNAME(ReduceComplex2DimValue)( |
| 134 | REDUCE_DIM_ARGS(float_Complex_t, float_Complex_t_value_op)); |
| 135 | void RTNAME(ReduceComplex3DimRef)( |
| 136 | REDUCE_DIM_ARGS(float_Complex_t, float_Complex_t_ref_op)); |
| 137 | void RTNAME(ReduceComplex3DimValue)( |
| 138 | REDUCE_DIM_ARGS(float_Complex_t, float_Complex_t_value_op)); |
| 139 | void RTNAME(ReduceComplex4DimRef)( |
| 140 | REDUCE_DIM_ARGS(float_Complex_t, float_Complex_t_ref_op)); |
| 141 | void RTNAME(ReduceComplex4DimValue)( |
| 142 | REDUCE_DIM_ARGS(float_Complex_t, float_Complex_t_value_op)); |
| 143 | void RTNAME(ReduceComplex8DimRef)( |
| 144 | REDUCE_DIM_ARGS(double_Complex_t, double_Complex_t_ref_op)); |
| 145 | void RTNAME(ReduceComplex8DimValue)( |
| 146 | REDUCE_DIM_ARGS(double_Complex_t, double_Complex_t_value_op)); |
| 147 | void RTNAME(ReduceComplex10DimRef)( |
| 148 | REDUCE_DIM_ARGS(long_double_Complex_t, long_double_Complex_t_ref_op)); |
| 149 | void RTNAME(ReduceComplex10DimValue)( |
| 150 | REDUCE_DIM_ARGS(long_double_Complex_t, long_double_Complex_t_value_op)); |
| 151 | #if HAS_LDBL128 || HAS_FLOAT128 |
| 152 | void RTNAME(ReduceComplex16DimRef)( |
| 153 | REDUCE_DIM_ARGS(CFloat128ComplexType, CFloat128ComplexType_ref_op)); |
| 154 | void RTNAME(ReduceComplex16DimValue)( |
| 155 | REDUCE_DIM_ARGS(CFloat128ComplexType, CFloat128ComplexType_value_op)); |
| 156 | #endif |
| 157 | |
| 158 | #endif // FLANG_RT_RUNTIME_COMPLEX_REDUCTION_H_ |
| 159 | |