Vector Optimized Library of Kernels  2.4
Architecture-tuned implementations of math kernels
volk_complex.h
Go to the documentation of this file.
1 #ifndef INCLUDED_VOLK_COMPLEX_H
2 #define INCLUDED_VOLK_COMPLEX_H
3 
20 #ifdef __cplusplus
21 
22 #include <stdint.h>
23 #include <complex>
24 
25 typedef std::complex<int8_t> lv_8sc_t;
26 typedef std::complex<int16_t> lv_16sc_t;
27 typedef std::complex<int32_t> lv_32sc_t;
28 typedef std::complex<int64_t> lv_64sc_t;
29 typedef std::complex<float> lv_32fc_t;
30 typedef std::complex<double> lv_64fc_t;
31 
32 template <typename T>
33 inline std::complex<T> lv_cmake(const T& r, const T& i)
34 {
35  return std::complex<T>(r, i);
36 }
37 
38 template <typename T>
39 inline typename T::value_type lv_creal(const T& x)
40 {
41  return x.real();
42 }
43 
44 template <typename T>
45 inline typename T::value_type lv_cimag(const T& x)
46 {
47  return x.imag();
48 }
49 
50 template <typename T>
51 inline T lv_conj(const T& x)
52 {
53  return std::conj(x);
54 }
55 
56 #else /* __cplusplus */
57 
58 #if __STDC_VERSION__ >= 199901L /* C99 check */
59 /* this allows us to conj in lv_conj without the double detour for single-precision floats
60  */
61 #include <tgmath.h>
62 #endif /* C99 check */
63 
64 #include <complex.h>
65 
66 typedef char complex lv_8sc_t;
67 typedef short complex lv_16sc_t;
68 typedef long complex lv_32sc_t;
69 typedef long long complex lv_64sc_t;
70 typedef float complex lv_32fc_t;
71 typedef double complex lv_64fc_t;
72 
73 #define lv_cmake(r, i) ((r) + _Complex_I * (i))
74 
75 // When GNUC is available, use the complex extensions.
76 // The extensions always return the correct value type.
77 // http://gcc.gnu.org/onlinedocs/gcc/Complex.html
78 #ifdef __GNUC__
79 
80 #define lv_creal(x) (__real__(x))
81 
82 #define lv_cimag(x) (__imag__(x))
83 
84 #define lv_conj(x) (~(x))
85 
86 // When not available, use the c99 complex function family,
87 // which always returns double regardless of the input type,
88 // unless we have C99 and thus tgmath.h overriding functions
89 // with type-generic versions.
90 #else /* __GNUC__ */
91 
92 #define lv_creal(x) (creal(x))
93 
94 #define lv_cimag(x) (cimag(x))
95 
96 #define lv_conj(x) (conj(x))
97 
98 #endif /* __GNUC__ */
99 
100 #endif /* __cplusplus */
101 
102 #endif /* INCLUDE_VOLK_COMPLEX_H */
lv_cimag
#define lv_cimag(x)
Definition: volk_complex.h:94
lv_64sc_t
long long complex lv_64sc_t
Definition: volk_complex.h:69
lv_16sc_t
short complex lv_16sc_t
Definition: volk_complex.h:67
lv_conj
#define lv_conj(x)
Definition: volk_complex.h:96
i
for i
Definition: volk_config_fixed.tmpl.h:25
lv_cmake
#define lv_cmake(r, i)
Definition: volk_complex.h:73
lv_32sc_t
long complex lv_32sc_t
Definition: volk_complex.h:68
lv_32fc_t
float complex lv_32fc_t
Definition: volk_complex.h:70
lv_64fc_t
double complex lv_64fc_t
Definition: volk_complex.h:71
lv_creal
#define lv_creal(x)
Definition: volk_complex.h:92
lv_8sc_t
char complex lv_8sc_t
Provide typedefs and operators for all complex types in C and C++.
Definition: volk_complex.h:66