| 1 |
/* SPDX-License-Identifier: MIT |
| 2 |
* |
| 3 |
* Permission is hereby granted, free of charge, to any person |
| 4 |
* obtaining a copy of this software and associated documentation |
| 5 |
* files (the "Software"), to deal in the Software without |
| 6 |
* restriction, including without limitation the rights to use, copy, |
| 7 |
* modify, merge, publish, distribute, sublicense, and/or sell copies |
| 8 |
* of the Software, and to permit persons to whom the Software is |
| 9 |
* furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be |
| 12 |
* included in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 15 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 17 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 18 |
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 19 |
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 20 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 |
* SOFTWARE. |
| 22 |
* |
| 23 |
* Copyright: |
| 24 |
* 2020-2021 Evan Nemerson <[email protected]> |
| 25 |
*/ |
| 26 |
|
| 27 |
/* Support for complex math. |
| 28 |
* |
| 29 |
* We try to avoid inculding <complex> (in C++ mode) since it pulls in |
| 30 |
* a *lot* of code. Unfortunately this only works for GNU modes (i.e., |
| 31 |
* -std=gnu++14 not -std=c++14) unless you pass -fext-numeric-literals, |
| 32 |
* but there is no way (AFAICT) to detect that flag so we have to rely |
| 33 |
* on __STRICT_ANSI__ to instead detect GNU mode. |
| 34 |
* |
| 35 |
* This header is separate from simde-math.h since there is a good |
| 36 |
* chance it will pull in <complex>, and most of the time we don't need |
| 37 |
* complex math (on x86 only SVML uses it). */ |
| 38 |
|
| 39 |
#if !defined(SIMDE_COMPLEX_H) |
| 40 |
#define SIMDE_COMPLEX_H 1 |
| 41 |
|
| 42 |
#include "simde-math.h" |
| 43 |
|
| 44 |
#if ( \ |
| 45 |
HEDLEY_HAS_BUILTIN(__builtin_creal) || \ |
| 46 |
HEDLEY_GCC_VERSION_CHECK(4,7,0) || \ |
| 47 |
HEDLEY_INTEL_VERSION_CHECK(13,0,0) \ |
| 48 |
) && (!defined(__cplusplus) && !defined(__STRICT_ANSI__)) |
| 49 |
HEDLEY_DIAGNOSTIC_PUSH |
| 50 |
SIMDE_DIAGNOSTIC_DISABLE_C99_EXTENSIONS_ |
| 51 |
typedef __complex__ float simde_cfloat32; |
| 52 |
typedef __complex__ double simde_cfloat64; |
| 53 |
HEDLEY_DIAGNOSTIC_POP |
| 54 |
#define SIMDE_MATH_CMPLX(x, y) (HEDLEY_STATIC_CAST(double, x) + HEDLEY_STATIC_CAST(double, y) * (__extension__ 1.0j)) |
| 55 |
#define SIMDE_MATH_CMPLXF(x, y) (HEDLEY_STATIC_CAST(float, x) + HEDLEY_STATIC_CAST(float, y) * (__extension__ 1.0fj)) |
| 56 |
|
| 57 |
#if !defined(simde_math_creal) |
| 58 |
#define simde_math_crealf(z) __builtin_crealf(z) |
| 59 |
#endif |
| 60 |
#if !defined(simde_math_crealf) |
| 61 |
#define simde_math_creal(z) __builtin_creal(z) |
| 62 |
#endif |
| 63 |
#if !defined(simde_math_cimag) |
| 64 |
#define simde_math_cimagf(z) __builtin_cimagf(z) |
| 65 |
#endif |
| 66 |
#if !defined(simde_math_cimagf) |
| 67 |
#define simde_math_cimag(z) __builtin_cimag(z) |
| 68 |
#endif |
| 69 |
#if !defined(simde_math_cexp) |
| 70 |
#define simde_math_cexp(z) __builtin_cexp(z) |
| 71 |
#endif |
| 72 |
#if !defined(simde_math_cexpf) |
| 73 |
#define simde_math_cexpf(z) __builtin_cexpf(z) |
| 74 |
#endif |
| 75 |
#elif !defined(__cplusplus) |
| 76 |
#include <complex.h> |
| 77 |
|
| 78 |
#if !defined(HEDLEY_MSVC_VERSION) |
| 79 |
typedef float _Complex simde_cfloat32; |
| 80 |
typedef double _Complex simde_cfloat64; |
| 81 |
#else |
| 82 |
typedef _Fcomplex simde_cfloat32; |
| 83 |
typedef _Dcomplex simde_cfloat64; |
| 84 |
#endif |
| 85 |
|
| 86 |
#if defined(HEDLEY_MSVC_VERSION) |
| 87 |
#define SIMDE_MATH_CMPLX(x, y) ((simde_cfloat64) { (x), (y) }) |
| 88 |
#define SIMDE_MATH_CMPLXF(x, y) ((simde_cfloat32) { (x), (y) }) |
| 89 |
#elif defined(CMPLX) && defined(CMPLXF) |
| 90 |
#define SIMDE_MATH_CMPLX(x, y) CMPLX(x, y) |
| 91 |
#define SIMDE_MATH_CMPLXF(x, y) CMPLXF(x, y) |
| 92 |
#else |
| 93 |
#define SIMDE_MATH_CMPLX(x, y) (HEDLEY_STATIC_CAST(double, x) + HEDLEY_STATIC_CAST(double, y) * I) |
| 94 |
#define SIMDE_MATH_CMPLXF(x, y) (HEDLEY_STATIC_CAST(float, x) + HEDLEY_STATIC_CAST(float, y) * I) |
| 95 |
#endif |
| 96 |
|
| 97 |
#if !defined(simde_math_creal) |
| 98 |
#define simde_math_creal(z) creal(z) |
| 99 |
#endif |
| 100 |
#if !defined(simde_math_crealf) |
| 101 |
#define simde_math_crealf(z) crealf(z) |
| 102 |
#endif |
| 103 |
#if !defined(simde_math_cimag) |
| 104 |
#define simde_math_cimag(z) cimag(z) |
| 105 |
#endif |
| 106 |
#if !defined(simde_math_cimagf) |
| 107 |
#define simde_math_cimagf(z) cimagf(z) |
| 108 |
#endif |
| 109 |
#if !defined(simde_math_cexp) |
| 110 |
#define simde_math_cexp(z) cexp(z) |
| 111 |
#endif |
| 112 |
#if !defined(simde_math_cexpf) |
| 113 |
#define simde_math_cexpf(z) cexpf(z) |
| 114 |
#endif |
| 115 |
#else |
| 116 |
HEDLEY_DIAGNOSTIC_PUSH |
| 117 |
#if defined(HEDLEY_MSVC_VERSION) |
| 118 |
#pragma warning(disable:4530) |
| 119 |
#endif |
| 120 |
#include <complex> |
| 121 |
HEDLEY_DIAGNOSTIC_POP |
| 122 |
|
| 123 |
typedef std::complex<float> simde_cfloat32; |
| 124 |
typedef std::complex<double> simde_cfloat64; |
| 125 |
#define SIMDE_MATH_CMPLX(x, y) (std::complex<double>(x, y)) |
| 126 |
#define SIMDE_MATH_CMPLXF(x, y) (std::complex<float>(x, y)) |
| 127 |
|
| 128 |
#if !defined(simde_math_creal) |
| 129 |
#define simde_math_creal(z) ((z).real()) |
| 130 |
#endif |
| 131 |
#if !defined(simde_math_crealf) |
| 132 |
#define simde_math_crealf(z) ((z).real()) |
| 133 |
#endif |
| 134 |
#if !defined(simde_math_cimag) |
| 135 |
#define simde_math_cimag(z) ((z).imag()) |
| 136 |
#endif |
| 137 |
#if !defined(simde_math_cimagf) |
| 138 |
#define simde_math_cimagf(z) ((z).imag()) |
| 139 |
#endif |
| 140 |
#if !defined(simde_math_cexp) |
| 141 |
#define simde_math_cexp(z) std::exp(z) |
| 142 |
#endif |
| 143 |
#if !defined(simde_math_cexpf) |
| 144 |
#define simde_math_cexpf(z) std::exp(z) |
| 145 |
#endif |
| 146 |
#endif |
| 147 |
|
| 148 |
#endif /* !defined(SIMDE_COMPLEX_H) */ |