Vector Optimized Library of Kernels  3.0.0
Architecture-tuned implementations of math kernels
volk_complex.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2010, 2011, 2015, 2018, 2020, 2021 Free Software Foundation, Inc.
4  *
5  * This file is part of VOLK
6  *
7  * SPDX-License-Identifier: LGPL-3.0-or-later
8  */
9 
10 #ifndef INCLUDED_VOLK_COMPLEX_H
11 #define INCLUDED_VOLK_COMPLEX_H
12 
29 #ifdef __cplusplus
30 
31 #include <stdint.h>
32 #include <complex>
33 
34 typedef std::complex<int8_t> lv_8sc_t;
35 typedef std::complex<int16_t> lv_16sc_t;
36 typedef std::complex<int32_t> lv_32sc_t;
37 typedef std::complex<int64_t> lv_64sc_t;
38 typedef std::complex<float> lv_32fc_t;
39 typedef std::complex<double> lv_64fc_t;
40 
41 template <typename T>
42 inline std::complex<T> lv_cmake(const T& r, const T& i)
43 {
44  return std::complex<T>(r, i);
45 }
46 
47 template <typename T>
48 inline typename T::value_type lv_creal(const T& x)
49 {
50  return x.real();
51 }
52 
53 template <typename T>
54 inline typename T::value_type lv_cimag(const T& x)
55 {
56  return x.imag();
57 }
58 
59 template <typename T>
60 inline T lv_conj(const T& x)
61 {
62  return std::conj(x);
63 }
64 
65 #else /* __cplusplus */
66 
67 #include <complex.h>
68 #include <tgmath.h>
69 
70 typedef char complex lv_8sc_t;
71 typedef short complex lv_16sc_t;
72 typedef long complex lv_32sc_t;
73 typedef long long complex lv_64sc_t;
74 typedef float complex lv_32fc_t;
75 typedef double complex lv_64fc_t;
76 
77 #define lv_cmake(r, i) ((r) + _Complex_I * (i))
78 
79 // When GNUC is available, use the complex extensions.
80 // The extensions always return the correct value type.
81 // http://gcc.gnu.org/onlinedocs/gcc/Complex.html
82 #ifdef __GNUC__
83 
84 #define lv_creal(x) (__real__(x))
85 
86 #define lv_cimag(x) (__imag__(x))
87 
88 #define lv_conj(x) (~(x))
89 
90 // When not available, use the c99 complex function family,
91 // which always returns double regardless of the input type,
92 // unless we have C99 and thus tgmath.h overriding functions
93 // with type-generic versions.
94 #else /* __GNUC__ */
95 
96 #define lv_creal(x) (creal(x))
97 
98 #define lv_cimag(x) (cimag(x))
99 
100 #define lv_conj(x) (conj(x))
101 
102 #endif /* __GNUC__ */
103 
104 #endif /* __cplusplus */
105 
106 #endif /* INCLUDE_VOLK_COMPLEX_H */
#define lv_cimag(x)
Definition: volk_complex.h:98
#define lv_conj(x)
Definition: volk_complex.h:100
#define lv_cmake(r, i)
Definition: volk_complex.h:77
char complex lv_8sc_t
Provide typedefs and operators for all complex types in C and C++.
Definition: volk_complex.h:70
long complex lv_32sc_t
Definition: volk_complex.h:72
double complex lv_64fc_t
Definition: volk_complex.h:75
#define lv_creal(x)
Definition: volk_complex.h:96
float complex lv_32fc_t
Definition: volk_complex.h:74
short complex lv_16sc_t
Definition: volk_complex.h:71
long long complex lv_64sc_t
Definition: volk_complex.h:73
for i
Definition: volk_config_fixed.tmpl.h:13