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