Vector Optimized Library of Kernels  2.1
Architecture-tuned implementations of math kernels
volk_common.h
Go to the documentation of this file.
1 #ifndef INCLUDED_LIBVOLK_COMMON_H
2 #define INCLUDED_LIBVOLK_COMMON_H
3 
5 // Cross-platform attribute macros
7 #if defined __clang__
8 // AppleClang also defines __GNUC__, so do this check first. These
9 // will probably be the same as for __GNUC__, but let's keep them
10 // separate just to be safe.
11 # define __VOLK_ATTR_ALIGNED(x) __attribute__((aligned(x)))
12 # define __VOLK_ATTR_UNUSED __attribute__((unused))
13 # define __VOLK_ATTR_INLINE __attribute__((always_inline))
14 # define __VOLK_ATTR_DEPRECATED __attribute__((deprecated))
15 # define __VOLK_ASM __asm__
16 # define __VOLK_VOLATILE __volatile__
17 # define __VOLK_ATTR_EXPORT __attribute__((visibility("default")))
18 # define __VOLK_ATTR_IMPORT __attribute__((visibility("default")))
19 # define __VOLK_PREFETCH(addr) __builtin_prefetch(addr)
20 #elif defined __GNUC__
21 # define __VOLK_ATTR_ALIGNED(x) __attribute__((aligned(x)))
22 # define __VOLK_ATTR_UNUSED __attribute__((unused))
23 # define __VOLK_ATTR_INLINE __attribute__((always_inline))
24 # define __VOLK_ATTR_DEPRECATED __attribute__((deprecated))
25 # define __VOLK_ASM __asm__
26 # define __VOLK_VOLATILE __volatile__
27 # if __GNUC__ >= 4
28 # define __VOLK_ATTR_EXPORT __attribute__((visibility("default")))
29 # define __VOLK_ATTR_IMPORT __attribute__((visibility("default")))
30 # else
31 # define __VOLK_ATTR_EXPORT
32 # define __VOLK_ATTR_IMPORT
33 # endif
34 # define __VOLK_PREFETCH(addr) __builtin_prefetch(addr)
35 #elif _MSC_VER
36 # define __VOLK_ATTR_ALIGNED(x) __declspec(align(x))
37 # define __VOLK_ATTR_UNUSED
38 # define __VOLK_ATTR_INLINE __forceinline
39 # define __VOLK_ATTR_DEPRECATED __declspec(deprecated)
40 # define __VOLK_ATTR_EXPORT __declspec(dllexport)
41 # define __VOLK_ATTR_IMPORT __declspec(dllimport)
42 # define __VOLK_PREFETCH(addr)
43 # define __VOLK_ASM __asm
44 # define __VOLK_VOLATILE
45 #else
46 # define __VOLK_ATTR_ALIGNED(x)
47 # define __VOLK_ATTR_UNUSED
48 # define __VOLK_ATTR_INLINE
49 # define __VOLK_ATTR_DEPRECATED
50 # define __VOLK_ATTR_EXPORT
51 # define __VOLK_ATTR_IMPORT
52 # define __VOLK_PREFETCH(addr)
53 # define __VOLK_ASM __asm__
54 # define __VOLK_VOLATILE __volatile__
55 #endif
56 
58 // Ignore annoying warnings in MSVC
60 #if defined(_MSC_VER)
61 # pragma warning(disable: 4244) //'conversion' conversion from 'type1' to 'type2', possible loss of data
62 # pragma warning(disable: 4305) //'identifier' : truncation from 'type1' to 'type2'
63 #endif
64 
66 // C-linkage declaration macros
67 // FIXME: due to the usage of complex.h, require gcc for c-linkage
69 #if defined(__cplusplus) && (__GNUC__)
70 # define __VOLK_DECL_BEGIN extern "C" {
71 # define __VOLK_DECL_END }
72 #else
73 # define __VOLK_DECL_BEGIN
74 # define __VOLK_DECL_END
75 #endif
76 
78 // Define VOLK_API for library symbols
79 // http://gcc.gnu.org/wiki/Visibility
81 #ifdef volk_EXPORTS
82 # define VOLK_API __VOLK_ATTR_EXPORT
83 #else
84 # define VOLK_API __VOLK_ATTR_IMPORT
85 #endif
86 
88 // The bit128 union used by some
90 #include <inttypes.h>
91 
92 #ifdef LV_HAVE_SSE
93 #ifdef _WIN32
94 #include <intrin.h>
95 #else
96 #include <x86intrin.h>
97 #endif
98 #endif
99 
100 union bit128{
101  uint8_t i8[16];
102  uint16_t i16[8];
103  uint32_t i[4];
104  float f[4];
105  double d[2];
106 
107  #ifdef LV_HAVE_SSE
108  __m128 float_vec;
109  #endif
110 
111  #ifdef LV_HAVE_SSE2
112  __m128i int_vec;
113  __m128d double_vec;
114  #endif
115 };
116 
117 union bit256{
118  uint8_t i8[32];
119  uint16_t i16[16];
120  uint32_t i[8];
121  float f[8];
122  double d[4];
123 
124  #ifdef LV_HAVE_AVX
125  __m256 float_vec;
126  __m256i int_vec;
127  __m256d double_vec;
128  #endif
129 };
130 
131 #define bit128_p(x) ((union bit128 *)(x))
132 #define bit256_p(x) ((union bit256 *)(x))
133 
134 #endif /*INCLUDED_LIBVOLK_COMMON_H*/
uint8_t i8[16]
Definition: volk_common.h:101
uint16_t i16[8]
Definition: volk_common.h:102
__m256d double_vec
Definition: volk_common.h:127
__m256i int_vec
Definition: volk_common.h:126
__m128i int_vec
Definition: volk_common.h:112
__m128d double_vec
Definition: volk_common.h:113
Definition: volk_common.h:117
__m128 float_vec
Definition: volk_common.h:108
__m256 float_vec
Definition: volk_common.h:125
double d[2]
Definition: volk_common.h:105
float f[4]
Definition: volk_common.h:104
Definition: volk_common.h:100
uint32_t i[4]
Definition: volk_common.h:103